winecoreaudio: Remove some unused structure fields.
[wine] / dlls / wininet / cookie.c
1 /*
2  * Wininet - cookie handling stuff
3  *
4  * Copyright 2002 TransGaming Technologies Inc.
5  *
6  * David Hammerton
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #if defined(__MINGW32__) || defined (_MSC_VER)
27 #include <ws2tcpip.h>
28 #endif
29
30 #include <stdarg.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #ifdef HAVE_UNISTD_H
35 # include <unistd.h>
36 #endif
37
38 #include "windef.h"
39 #include "winbase.h"
40 #include "wininet.h"
41 #include "winerror.h"
42
43 #include "wine/debug.h"
44 #include "internet.h"
45
46 #define RESPONSE_TIMEOUT        30            /* FROM internet.c */
47
48
49 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
50
51 /* FIXME
52  *     Cookies are currently memory only.
53  *     Cookies are NOT THREAD SAFE
54  *     Cookies could use A LOT OF MEMORY. We need some kind of memory management here!
55  */
56
57 typedef struct _cookie_domain cookie_domain;
58 typedef struct _cookie cookie;
59
60 struct _cookie
61 {
62     struct list entry;
63
64     struct _cookie_domain *parent;
65
66     LPWSTR lpCookieName;
67     LPWSTR lpCookieData;
68     FILETIME expiry;
69 };
70
71 struct _cookie_domain
72 {
73     struct list entry;
74
75     LPWSTR lpCookieDomain;
76     LPWSTR lpCookiePath;
77     struct list cookie_list;
78 };
79
80 static struct list domain_list = LIST_INIT(domain_list);
81
82 static cookie *COOKIE_addCookie(cookie_domain *domain, LPCWSTR name, LPCWSTR data, FILETIME expiry);
83 static cookie *COOKIE_findCookie(cookie_domain *domain, LPCWSTR lpszCookieName);
84 static void COOKIE_deleteCookie(cookie *deadCookie, BOOL deleteDomain);
85 static cookie_domain *COOKIE_addDomain(LPCWSTR domain, LPCWSTR path);
86 static void COOKIE_deleteDomain(cookie_domain *deadDomain);
87
88
89 /* adds a cookie to the domain */
90 static cookie *COOKIE_addCookie(cookie_domain *domain, LPCWSTR name, LPCWSTR data, FILETIME expiry)
91 {
92     cookie *newCookie = HeapAlloc(GetProcessHeap(), 0, sizeof(cookie));
93
94     list_init(&newCookie->entry);
95     newCookie->lpCookieName = NULL;
96     newCookie->lpCookieData = NULL;
97     newCookie->expiry = expiry;
98     newCookie->lpCookieName = heap_strdupW(name);
99     newCookie->lpCookieData = heap_strdupW(data);
100
101     TRACE("added cookie %p (data is %s)\n", newCookie, debugstr_w(data) );
102
103     list_add_tail(&domain->cookie_list, &newCookie->entry);
104     newCookie->parent = domain;
105     return newCookie;
106 }
107
108
109 /* finds a cookie in the domain matching the cookie name */
110 static cookie *COOKIE_findCookie(cookie_domain *domain, LPCWSTR lpszCookieName)
111 {
112     struct list * cursor;
113     TRACE("(%p, %s)\n", domain, debugstr_w(lpszCookieName));
114
115     LIST_FOR_EACH(cursor, &domain->cookie_list)
116     {
117         cookie *searchCookie = LIST_ENTRY(cursor, cookie, entry);
118         BOOL candidate = TRUE;
119         if (candidate && lpszCookieName)
120         {
121             if (candidate && !searchCookie->lpCookieName)
122                 candidate = FALSE;
123             if (candidate && strcmpW(lpszCookieName, searchCookie->lpCookieName) != 0)
124                 candidate = FALSE;
125         }
126         if (candidate)
127             return searchCookie;
128     }
129     return NULL;
130 }
131
132 /* removes a cookie from the list, if its the last cookie we also remove the domain */
133 static void COOKIE_deleteCookie(cookie *deadCookie, BOOL deleteDomain)
134 {
135     HeapFree(GetProcessHeap(), 0, deadCookie->lpCookieName);
136     HeapFree(GetProcessHeap(), 0, deadCookie->lpCookieData);
137     list_remove(&deadCookie->entry);
138
139     /* special case: last cookie, lets remove the domain to save memory */
140     if (list_empty(&deadCookie->parent->cookie_list) && deleteDomain)
141         COOKIE_deleteDomain(deadCookie->parent);
142     HeapFree(GetProcessHeap(), 0, deadCookie);
143 }
144
145 /* allocates a domain and adds it to the end */
146 static cookie_domain *COOKIE_addDomain(LPCWSTR domain, LPCWSTR path)
147 {
148     cookie_domain *newDomain = HeapAlloc(GetProcessHeap(), 0, sizeof(cookie_domain));
149
150     list_init(&newDomain->entry);
151     list_init(&newDomain->cookie_list);
152     newDomain->lpCookieDomain = NULL;
153     newDomain->lpCookiePath = NULL;
154     newDomain->lpCookieDomain = heap_strdupW(domain);
155     newDomain->lpCookiePath = heap_strdupW(path);
156
157     list_add_tail(&domain_list, &newDomain->entry);
158
159     TRACE("Adding domain: %p\n", newDomain);
160     return newDomain;
161 }
162
163 static BOOL COOKIE_crackUrlSimple(LPCWSTR lpszUrl, LPWSTR hostName, int hostNameLen, LPWSTR path, int pathLen)
164 {
165     URL_COMPONENTSW UrlComponents;
166     BOOL rc;
167
168     UrlComponents.lpszExtraInfo = NULL;
169     UrlComponents.lpszPassword = NULL;
170     UrlComponents.lpszScheme = NULL;
171     UrlComponents.lpszUrlPath = path;
172     UrlComponents.lpszUserName = NULL;
173     UrlComponents.lpszHostName = hostName;
174     UrlComponents.dwExtraInfoLength = 0;
175     UrlComponents.dwPasswordLength = 0;
176     UrlComponents.dwSchemeLength = 0;
177     UrlComponents.dwUserNameLength = 0;
178     UrlComponents.dwHostNameLength = hostNameLen;
179     UrlComponents.dwUrlPathLength = pathLen;
180
181     rc = InternetCrackUrlW(lpszUrl, 0, 0, &UrlComponents);
182
183     /* discard the webpage off the end of the path */
184     if (pathLen > 0 && path[pathLen-1] != '/')
185     {
186         LPWSTR ptr;
187         ptr = strrchrW(path,'/');
188         if (ptr)
189             *(++ptr) = 0;
190         else
191         {
192             path[0] = '/';
193             path[1] = 0;
194         }
195     }
196     return rc;
197 }
198
199 /* match a domain. domain must match if the domain is not NULL. path must match if the path is not NULL */
200 static BOOL COOKIE_matchDomain(LPCWSTR lpszCookieDomain, LPCWSTR lpszCookiePath,
201                                cookie_domain *searchDomain, BOOL allow_partial)
202 {
203     TRACE("searching on domain %p\n", searchDomain);
204         if (lpszCookieDomain)
205         {
206             if (!searchDomain->lpCookieDomain)
207             return FALSE;
208
209             TRACE("comparing domain %s with %s\n", 
210             debugstr_w(lpszCookieDomain), 
211             debugstr_w(searchDomain->lpCookieDomain));
212
213         if (allow_partial && !strstrW(lpszCookieDomain, searchDomain->lpCookieDomain))
214             return FALSE;
215         else if (!allow_partial && lstrcmpW(lpszCookieDomain, searchDomain->lpCookieDomain) != 0)
216             return FALSE;
217         }
218     if (lpszCookiePath)
219     {
220         INT len;
221         TRACE("comparing paths: %s with %s\n", debugstr_w(lpszCookiePath), debugstr_w(searchDomain->lpCookiePath));
222         /* paths match at the beginning.  so a path of  /foo would match
223          * /foobar and /foo/bar
224          */
225         if (!searchDomain->lpCookiePath)
226             return FALSE;
227         if (allow_partial)
228         {
229             len = lstrlenW(searchDomain->lpCookiePath);
230             if (strncmpiW(searchDomain->lpCookiePath, lpszCookiePath, len)!=0)
231                 return FALSE;
232         }
233         else if (strcmpW(lpszCookiePath, searchDomain->lpCookiePath))
234             return FALSE;
235
236         }
237         return TRUE;
238 }
239
240 /* remove a domain from the list and delete it */
241 static void COOKIE_deleteDomain(cookie_domain *deadDomain)
242 {
243     struct list * cursor;
244     while ((cursor = list_tail(&deadDomain->cookie_list)))
245     {
246         COOKIE_deleteCookie(LIST_ENTRY(cursor, cookie, entry), FALSE);
247         list_remove(cursor);
248     }
249
250     HeapFree(GetProcessHeap(), 0, deadDomain->lpCookieDomain);
251     HeapFree(GetProcessHeap(), 0, deadDomain->lpCookiePath);
252
253     list_remove(&deadDomain->entry);
254
255     HeapFree(GetProcessHeap(), 0, deadDomain);
256 }
257
258 /***********************************************************************
259  *           InternetGetCookieW (WININET.@)
260  *
261  * Retrieve cookie from the specified url
262  *
263  *  It should be noted that on windows the lpszCookieName parameter is "not implemented".
264  *    So it won't be implemented here.
265  *
266  * RETURNS
267  *    TRUE  on success
268  *    FALSE on failure
269  *
270  */
271 BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
272     LPWSTR lpCookieData, LPDWORD lpdwSize)
273 {
274     BOOL ret;
275     struct list * cursor;
276     unsigned int cnt = 0, domain_count = 0, cookie_count = 0;
277     WCHAR hostName[2048], path[2048];
278     FILETIME tm;
279
280     TRACE("(%s, %s, %p, %p)\n", debugstr_w(lpszUrl),debugstr_w(lpszCookieName),
281           lpCookieData, lpdwSize);
282
283     if (!lpszUrl)
284     {
285         SetLastError(ERROR_INVALID_PARAMETER);
286         return FALSE;
287     }
288
289     hostName[0] = 0;
290     ret = COOKIE_crackUrlSimple(lpszUrl, hostName, sizeof(hostName)/sizeof(hostName[0]), path, sizeof(path)/sizeof(path[0]));
291     if (!ret || !hostName[0]) return FALSE;
292
293     GetSystemTimeAsFileTime(&tm);
294
295     LIST_FOR_EACH(cursor, &domain_list)
296     {
297         cookie_domain *cookiesDomain = LIST_ENTRY(cursor, cookie_domain, entry);
298         if (COOKIE_matchDomain(hostName, path, cookiesDomain, TRUE))
299         {
300             struct list * cursor;
301             domain_count++;
302             TRACE("found domain %p\n", cookiesDomain);
303     
304             LIST_FOR_EACH(cursor, &cookiesDomain->cookie_list)
305             {
306                 cookie *thisCookie = LIST_ENTRY(cursor, cookie, entry);
307                 /* check for expiry */
308                 if ((thisCookie->expiry.dwLowDateTime != 0 || thisCookie->expiry.dwHighDateTime != 0) && CompareFileTime(&tm,&thisCookie->expiry)  > 0)
309                 {
310                     TRACE("Found expired cookie. deleting\n");
311                     COOKIE_deleteCookie(thisCookie, FALSE);
312                     continue;
313                 }
314
315                 if (lpCookieData == NULL) /* return the size of the buffer required to lpdwSize */
316                 {
317                     unsigned int len;
318
319                     if (cookie_count) cnt += 2; /* '; ' */
320                     cnt += strlenW(thisCookie->lpCookieName);
321                     if ((len = strlenW(thisCookie->lpCookieData)))
322                     {
323                         cnt += 1; /* = */
324                         cnt += len;
325                     }
326                 }
327                 else
328                 {
329                     static const WCHAR szsc[] = { ';',' ',0 };
330                     static const WCHAR szname[] = { '%','s',0 };
331                     static const WCHAR szdata[] = { '=','%','s',0 };
332
333                     if (cookie_count) cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szsc);
334                     cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szname, thisCookie->lpCookieName);
335
336                     if (thisCookie->lpCookieData[0])
337                         cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szdata, thisCookie->lpCookieData);
338
339                     TRACE("Cookie: %s\n", debugstr_w(lpCookieData));
340                 }
341                 cookie_count++;
342             }
343         }
344     }
345
346     if (!domain_count)
347     {
348         TRACE("no cookies found for %s\n", debugstr_w(hostName));
349         SetLastError(ERROR_NO_MORE_ITEMS);
350         return FALSE;
351     }
352
353     if (lpCookieData == NULL)
354     {
355         *lpdwSize = (cnt + 1) * sizeof(WCHAR);
356         TRACE("returning %u\n", *lpdwSize);
357         return TRUE;
358     }
359
360     *lpdwSize = cnt + 1;
361
362     TRACE("Returning %u (from %u domains): %s\n", cnt, domain_count,
363            debugstr_w(lpCookieData));
364
365     return (cnt ? TRUE : FALSE);
366 }
367
368
369 /***********************************************************************
370  *           InternetGetCookieA (WININET.@)
371  *
372  * Retrieve cookie from the specified url
373  *
374  * RETURNS
375  *    TRUE  on success
376  *    FALSE on failure
377  *
378  */
379 BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
380     LPSTR lpCookieData, LPDWORD lpdwSize)
381 {
382     DWORD len;
383     LPWSTR szCookieData = NULL, url, name;
384     BOOL r;
385
386     TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl), debugstr_a(lpszCookieName),
387         lpCookieData);
388
389     url = heap_strdupAtoW(lpszUrl);
390     name = heap_strdupAtoW(lpszCookieName);
391
392     r = InternetGetCookieW( url, name, NULL, &len );
393     if( r )
394     {
395         szCookieData = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
396         if( !szCookieData )
397         {
398             r = FALSE;
399         }
400         else
401         {
402             r = InternetGetCookieW( url, name, szCookieData, &len );
403
404             *lpdwSize = WideCharToMultiByte( CP_ACP, 0, szCookieData, len,
405                                     lpCookieData, *lpdwSize, NULL, NULL );
406         }
407     }
408
409     HeapFree( GetProcessHeap(), 0, szCookieData );
410     HeapFree( GetProcessHeap(), 0, name );
411     HeapFree( GetProcessHeap(), 0, url );
412
413     return r;
414 }
415
416 static BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWSTR cookie_data)
417 {
418     cookie_domain *thisCookieDomain = NULL;
419     cookie *thisCookie;
420     struct list *cursor;
421     LPWSTR data, value;
422     WCHAR *ptr;
423     FILETIME expiry;
424     BOOL expired = FALSE;
425
426     value = data = heap_strdupW(cookie_data);
427     if (!data)
428     {
429         ERR("could not allocate %zu bytes for the cookie data buffer\n", (strlenW(cookie_data) + 1) * sizeof(WCHAR));
430         return FALSE;
431     }
432
433     memset(&expiry,0,sizeof(expiry));
434
435     /* lots of information can be parsed out of the cookie value */
436
437     ptr = data;
438     for (;;)
439     {
440         static const WCHAR szDomain[] = {'d','o','m','a','i','n','=',0};
441         static const WCHAR szPath[] = {'p','a','t','h','=',0};
442         static const WCHAR szExpires[] = {'e','x','p','i','r','e','s','=',0};
443         static const WCHAR szSecure[] = {'s','e','c','u','r','e',0};
444         static const WCHAR szHttpOnly[] = {'h','t','t','p','o','n','l','y',0};
445
446         if (!(ptr = strchrW(ptr,';'))) break;
447         *ptr++ = 0;
448
449         if (value != data)
450             HeapFree(GetProcessHeap(), 0, value);
451         value = HeapAlloc(GetProcessHeap(), 0, (ptr - data) * sizeof(WCHAR));
452         if (value == NULL)
453         {
454             HeapFree(GetProcessHeap(), 0, data);
455             ERR("could not allocate %zu bytes for the cookie value buffer\n", (ptr - data) * sizeof(WCHAR));
456             return FALSE;
457         }
458         strcpyW(value, data);
459
460         while (*ptr == ' ') ptr++; /* whitespace */
461
462         if (strncmpiW(ptr, szDomain, 7) == 0)
463         {
464             ptr+=strlenW(szDomain);
465             domain = ptr;
466             TRACE("Parsing new domain %s\n",debugstr_w(domain));
467         }
468         else if (strncmpiW(ptr, szPath, 5) == 0)
469         {
470             ptr+=strlenW(szPath);
471             path = ptr;
472             TRACE("Parsing new path %s\n",debugstr_w(path));
473         }
474         else if (strncmpiW(ptr, szExpires, 8) == 0)
475         {
476             FILETIME ft;
477             SYSTEMTIME st;
478             FIXME("persistent cookies not handled (%s)\n",debugstr_w(ptr));
479             ptr+=strlenW(szExpires);
480             if (InternetTimeToSystemTimeW(ptr, &st, 0))
481             {
482                 SystemTimeToFileTime(&st, &expiry);
483                 GetSystemTimeAsFileTime(&ft);
484
485                 if (CompareFileTime(&ft,&expiry) > 0)
486                 {
487                     TRACE("Cookie already expired.\n");
488                     expired = TRUE;
489                 }
490             }
491         }
492         else if (strncmpiW(ptr, szSecure, 6) == 0)
493         {
494             FIXME("secure not handled (%s)\n",debugstr_w(ptr));
495             ptr += strlenW(szSecure);
496         }
497         else if (strncmpiW(ptr, szHttpOnly, 8) == 0)
498         {
499             FIXME("httponly not handled (%s)\n",debugstr_w(ptr));
500             ptr += strlenW(szHttpOnly);
501         }
502         else if (*ptr)
503         {
504             FIXME("Unknown additional option %s\n",debugstr_w(ptr));
505             break;
506         }
507     }
508
509     LIST_FOR_EACH(cursor, &domain_list)
510     {
511         thisCookieDomain = LIST_ENTRY(cursor, cookie_domain, entry);
512         if (COOKIE_matchDomain(domain, path, thisCookieDomain, FALSE))
513             break;
514         thisCookieDomain = NULL;
515     }
516
517     if (!thisCookieDomain)
518     {
519         if (!expired)
520             thisCookieDomain = COOKIE_addDomain(domain, path);
521         else
522         {
523             HeapFree(GetProcessHeap(),0,data);
524             if (value != data) HeapFree(GetProcessHeap(), 0, value);
525             return TRUE;
526         }
527     }
528
529     if ((thisCookie = COOKIE_findCookie(thisCookieDomain, cookie_name)))
530         COOKIE_deleteCookie(thisCookie, FALSE);
531
532     TRACE("setting cookie %s=%s for domain %s path %s\n", debugstr_w(cookie_name),
533           debugstr_w(value), debugstr_w(thisCookieDomain->lpCookieDomain),debugstr_w(thisCookieDomain->lpCookiePath));
534
535     if (!expired && !COOKIE_addCookie(thisCookieDomain, cookie_name, value, expiry))
536     {
537         HeapFree(GetProcessHeap(),0,data);
538         if (value != data) HeapFree(GetProcessHeap(), 0, value);
539         return FALSE;
540     }
541
542     HeapFree(GetProcessHeap(),0,data);
543     if (value != data) HeapFree(GetProcessHeap(), 0, value);
544     return TRUE;
545 }
546
547 /***********************************************************************
548  *           InternetSetCookieW (WININET.@)
549  *
550  * Sets cookie for the specified url
551  *
552  * RETURNS
553  *    TRUE  on success
554  *    FALSE on failure
555  *
556  */
557 BOOL WINAPI InternetSetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
558     LPCWSTR lpCookieData)
559 {
560     BOOL ret;
561     WCHAR hostName[2048], path[2048];
562
563     TRACE("(%s,%s,%s)\n", debugstr_w(lpszUrl),
564         debugstr_w(lpszCookieName), debugstr_w(lpCookieData));
565
566     if (!lpszUrl || !lpCookieData)
567     {
568         SetLastError(ERROR_INVALID_PARAMETER);
569         return FALSE;
570     }
571
572     hostName[0] = path[0] = 0;
573     ret = COOKIE_crackUrlSimple(lpszUrl, hostName, sizeof(hostName)/sizeof(hostName[0]), path, sizeof(path)/sizeof(path[0]));
574     if (!ret || !hostName[0]) return FALSE;
575
576     if (!lpszCookieName)
577     {
578         WCHAR *cookie, *data;
579
580         cookie = heap_strdupW(lpCookieData);
581         if (!cookie)
582         {
583             SetLastError(ERROR_OUTOFMEMORY);
584             return FALSE;
585         }
586
587         /* some apps (or is it us??) try to add a cookie with no cookie name, but
588          * the cookie data in the form of name[=data].
589          */
590         if (!(data = strchrW(cookie, '='))) data = cookie + strlenW(cookie);
591         else *data++ = 0;
592
593         ret = set_cookie(hostName, path, cookie, data);
594
595         HeapFree(GetProcessHeap(), 0, cookie);
596         return ret;
597     }
598     return set_cookie(hostName, path, lpszCookieName, lpCookieData);
599 }
600
601
602 /***********************************************************************
603  *           InternetSetCookieA (WININET.@)
604  *
605  * Sets cookie for the specified url
606  *
607  * RETURNS
608  *    TRUE  on success
609  *    FALSE on failure
610  *
611  */
612 BOOL WINAPI InternetSetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
613     LPCSTR lpCookieData)
614 {
615     LPWSTR data, url, name;
616     BOOL r;
617
618     TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
619         debugstr_a(lpszCookieName), debugstr_a(lpCookieData));
620
621     url = heap_strdupAtoW(lpszUrl);
622     name = heap_strdupAtoW(lpszCookieName);
623     data = heap_strdupAtoW(lpCookieData);
624
625     r = InternetSetCookieW( url, name, data );
626
627     HeapFree( GetProcessHeap(), 0, data );
628     HeapFree( GetProcessHeap(), 0, name );
629     HeapFree( GetProcessHeap(), 0, url );
630
631     return r;
632 }
633
634 /***********************************************************************
635  *           InternetSetCookieExA (WININET.@)
636  *
637  * See InternetSetCookieExW.
638  */
639 DWORD WINAPI InternetSetCookieExA( LPCSTR lpszURL, LPCSTR lpszCookieName, LPCSTR lpszCookieData,
640                                    DWORD dwFlags, DWORD_PTR dwReserved)
641 {
642     TRACE("(%s, %s, %s, 0x%08x, 0x%08lx)\n",
643           debugstr_a(lpszURL), debugstr_a(lpszCookieName), debugstr_a(lpszCookieData),
644           dwFlags, dwReserved);
645
646     if (dwFlags) FIXME("flags 0x%08x not supported\n", dwFlags);
647     return InternetSetCookieA(lpszURL, lpszCookieName, lpszCookieData);
648 }
649
650 /***********************************************************************
651  *           InternetSetCookieExW (WININET.@)
652  *
653  * Sets a cookie for the specified URL.
654  *
655  * RETURNS
656  *    TRUE  on success
657  *    FALSE on failure
658  *
659  */
660 DWORD WINAPI InternetSetCookieExW( LPCWSTR lpszURL, LPCWSTR lpszCookieName, LPCWSTR lpszCookieData,
661                                    DWORD dwFlags, DWORD_PTR dwReserved)
662 {
663     TRACE("(%s, %s, %s, 0x%08x, 0x%08lx)\n",
664           debugstr_w(lpszURL), debugstr_w(lpszCookieName), debugstr_w(lpszCookieData),
665           dwFlags, dwReserved);
666
667     if (dwFlags) FIXME("flags 0x%08x not supported\n", dwFlags);
668     return InternetSetCookieW(lpszURL, lpszCookieName, lpszCookieData);
669 }
670
671 /***********************************************************************
672  *           InternetGetCookieExA (WININET.@)
673  *
674  * See InternetGetCookieExW.
675  */
676 BOOL WINAPI InternetGetCookieExA( LPCSTR pchURL, LPCSTR pchCookieName, LPSTR pchCookieData,
677                                   LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
678 {
679     TRACE("(%s, %s, %s, %p, 0x%08x, %p)\n",
680           debugstr_a(pchURL), debugstr_a(pchCookieName), debugstr_a(pchCookieData),
681           pcchCookieData, dwFlags, lpReserved);
682
683     if (dwFlags) FIXME("flags 0x%08x not supported\n", dwFlags);
684     return InternetGetCookieA(pchURL, pchCookieName, pchCookieData, pcchCookieData);
685 }
686
687 /***********************************************************************
688  *           InternetGetCookieExW (WININET.@)
689  *
690  * Retrieve cookie for the specified URL.
691  *
692  * RETURNS
693  *    TRUE  on success
694  *    FALSE on failure
695  *
696  */
697 BOOL WINAPI InternetGetCookieExW( LPCWSTR pchURL, LPCWSTR pchCookieName, LPWSTR pchCookieData,
698                                   LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
699 {
700     TRACE("(%s, %s, %s, %p, 0x%08x, %p)\n",
701           debugstr_w(pchURL), debugstr_w(pchCookieName), debugstr_w(pchCookieData),
702           pcchCookieData, dwFlags, lpReserved);
703
704     if (dwFlags) FIXME("flags 0x%08x not supported\n", dwFlags);
705     return InternetGetCookieW(pchURL, pchCookieName, pchCookieData, pcchCookieData);
706 }
707
708 /***********************************************************************
709  *           InternetClearAllPerSiteCookieDecisions (WININET.@)
710  *
711  * Clears all per-site decisions about cookies.
712  *
713  * RETURNS
714  *    TRUE  on success
715  *    FALSE on failure
716  *
717  */
718 BOOL WINAPI InternetClearAllPerSiteCookieDecisions( VOID )
719 {
720     FIXME("stub\n");
721     return TRUE;
722 }
723
724 /***********************************************************************
725  *           InternetEnumPerSiteCookieDecisionA (WININET.@)
726  *
727  * See InternetEnumPerSiteCookieDecisionW.
728  */
729 BOOL WINAPI InternetEnumPerSiteCookieDecisionA( LPSTR pszSiteName, ULONG *pcSiteNameSize,
730                                                 ULONG *pdwDecision, ULONG dwIndex )
731 {
732     FIXME("(%s, %p, %p, 0x%08x) stub\n",
733           debugstr_a(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
734     return FALSE;
735 }
736
737 /***********************************************************************
738  *           InternetEnumPerSiteCookieDecisionW (WININET.@)
739  *
740  * Enumerates all per-site decisions about cookies.
741  *
742  * RETURNS
743  *    TRUE  on success
744  *    FALSE on failure
745  *
746  */
747 BOOL WINAPI InternetEnumPerSiteCookieDecisionW( LPWSTR pszSiteName, ULONG *pcSiteNameSize,
748                                                 ULONG *pdwDecision, ULONG dwIndex )
749 {
750     FIXME("(%s, %p, %p, 0x%08x) stub\n",
751           debugstr_w(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
752     return FALSE;
753 }
754
755 /***********************************************************************
756  *           InternetGetPerSiteCookieDecisionA (WININET.@)
757  */
758 BOOL WINAPI InternetGetPerSiteCookieDecisionA( LPCSTR pwchHostName, ULONG *pResult )
759 {
760     FIXME("(%s, %p) stub\n", debugstr_a(pwchHostName), pResult);
761     return FALSE;
762 }
763
764 /***********************************************************************
765  *           InternetGetPerSiteCookieDecisionW (WININET.@)
766  */
767 BOOL WINAPI InternetGetPerSiteCookieDecisionW( LPCWSTR pwchHostName, ULONG *pResult )
768 {
769     FIXME("(%s, %p) stub\n", debugstr_w(pwchHostName), pResult);
770     return FALSE;
771 }
772
773 /***********************************************************************
774  *           InternetSetPerSiteCookieDecisionA (WININET.@)
775  */
776 BOOL WINAPI InternetSetPerSiteCookieDecisionA( LPCSTR pchHostName, DWORD dwDecision )
777 {
778     FIXME("(%s, 0x%08x) stub\n", debugstr_a(pchHostName), dwDecision);
779     return FALSE;
780 }
781
782 /***********************************************************************
783  *           InternetSetPerSiteCookieDecisionW (WININET.@)
784  */
785 BOOL WINAPI InternetSetPerSiteCookieDecisionW( LPCWSTR pchHostName, DWORD dwDecision )
786 {
787     FIXME("(%s, 0x%08x) stub\n", debugstr_w(pchHostName), dwDecision);
788     return FALSE;
789 }
790
791 /***********************************************************************
792  *           IsDomainLegalCookieDomainW (WININET.@)
793  */
794 BOOL WINAPI IsDomainLegalCookieDomainW( LPCWSTR s1, LPCWSTR s2 )
795 {
796     const WCHAR *p;
797
798     FIXME("(%s, %s)\n", debugstr_w(s1), debugstr_w(s2));
799
800     if (!s1 || !s2)
801     {
802         SetLastError(ERROR_INVALID_PARAMETER);
803         return FALSE;
804     }
805     if (s1[0] == '.' || !s1[0] || s2[0] == '.' || !s2[0])
806     {
807         SetLastError(ERROR_INVALID_NAME);
808         return FALSE;
809     }
810     if (!(p = strchrW(s2, '.'))) return FALSE;
811     if (strchrW(p + 1, '.') && !strcmpW(p + 1, s1)) return TRUE;
812     else if (!strcmpW(s1, s2)) return TRUE;
813     return FALSE;
814 }