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