wininet: Set last error for invalid URL argument.
[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 = heap_alloc(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     heap_free(deadCookie->lpCookieName);
136     heap_free(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     heap_free(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 = heap_alloc(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
167     UrlComponents.lpszExtraInfo = NULL;
168     UrlComponents.lpszPassword = NULL;
169     UrlComponents.lpszScheme = NULL;
170     UrlComponents.lpszUrlPath = path;
171     UrlComponents.lpszUserName = NULL;
172     UrlComponents.lpszHostName = hostName;
173     UrlComponents.dwExtraInfoLength = 0;
174     UrlComponents.dwPasswordLength = 0;
175     UrlComponents.dwSchemeLength = 0;
176     UrlComponents.dwUserNameLength = 0;
177     UrlComponents.dwHostNameLength = hostNameLen;
178     UrlComponents.dwUrlPathLength = pathLen;
179
180     if (!InternetCrackUrlW(lpszUrl, 0, 0, &UrlComponents)) return FALSE;
181
182     /* discard the webpage off the end of the path */
183     if (UrlComponents.dwUrlPathLength)
184     {
185         if (path[UrlComponents.dwUrlPathLength - 1] != '/')
186         {
187             WCHAR *ptr;
188             if ((ptr = strrchrW(path, '/'))) *(++ptr) = 0;
189             else
190             {
191                 path[0] = '/';
192                 path[1] = 0;
193             }
194         }
195     }
196     else if (pathLen >= 2)
197     {
198         path[0] = '/';
199         path[1] = 0;
200     }
201     return TRUE;
202 }
203
204 /* match a domain. domain must match if the domain is not NULL. path must match if the path is not NULL */
205 static BOOL COOKIE_matchDomain(LPCWSTR lpszCookieDomain, LPCWSTR lpszCookiePath,
206                                cookie_domain *searchDomain, BOOL allow_partial)
207 {
208     TRACE("searching on domain %p\n", searchDomain);
209         if (lpszCookieDomain)
210         {
211             if (!searchDomain->lpCookieDomain)
212             return FALSE;
213
214             TRACE("comparing domain %s with %s\n", 
215             debugstr_w(lpszCookieDomain), 
216             debugstr_w(searchDomain->lpCookieDomain));
217
218         if (allow_partial && !strstrW(lpszCookieDomain, searchDomain->lpCookieDomain))
219             return FALSE;
220         else if (!allow_partial && lstrcmpW(lpszCookieDomain, searchDomain->lpCookieDomain) != 0)
221             return FALSE;
222         }
223     if (lpszCookiePath)
224     {
225         INT len;
226         TRACE("comparing paths: %s with %s\n", debugstr_w(lpszCookiePath), debugstr_w(searchDomain->lpCookiePath));
227         /* paths match at the beginning.  so a path of  /foo would match
228          * /foobar and /foo/bar
229          */
230         if (!searchDomain->lpCookiePath)
231             return FALSE;
232         if (allow_partial)
233         {
234             len = lstrlenW(searchDomain->lpCookiePath);
235             if (strncmpiW(searchDomain->lpCookiePath, lpszCookiePath, len)!=0)
236                 return FALSE;
237         }
238         else if (strcmpW(lpszCookiePath, searchDomain->lpCookiePath))
239             return FALSE;
240
241         }
242         return TRUE;
243 }
244
245 /* remove a domain from the list and delete it */
246 static void COOKIE_deleteDomain(cookie_domain *deadDomain)
247 {
248     struct list * cursor;
249     while ((cursor = list_tail(&deadDomain->cookie_list)))
250     {
251         COOKIE_deleteCookie(LIST_ENTRY(cursor, cookie, entry), FALSE);
252         list_remove(cursor);
253     }
254     heap_free(deadDomain->lpCookieDomain);
255     heap_free(deadDomain->lpCookiePath);
256
257     list_remove(&deadDomain->entry);
258
259     heap_free(deadDomain);
260 }
261
262 BOOL get_cookie(const WCHAR *host, const WCHAR *path, WCHAR *cookie_data, DWORD *size)
263 {
264     unsigned cnt = 0, len, domain_count = 0, cookie_count = 0;
265     cookie_domain *domain;
266     FILETIME tm;
267
268     GetSystemTimeAsFileTime(&tm);
269
270     LIST_FOR_EACH_ENTRY(domain, &domain_list, cookie_domain, entry) {
271         struct list *cursor, *cursor2;
272
273         if(!COOKIE_matchDomain(host, path, domain, TRUE))
274             continue;
275
276         domain_count++;
277         TRACE("found domain %p\n", domain);
278     
279         LIST_FOR_EACH_SAFE(cursor, cursor2, &domain->cookie_list) {
280             cookie *cookie_iter = LIST_ENTRY(cursor, cookie, entry);
281
282             /* check for expiry */
283             if((cookie_iter->expiry.dwLowDateTime != 0 || cookie_iter->expiry.dwHighDateTime != 0)
284                 && CompareFileTime(&tm, &cookie_iter->expiry)  > 0)
285             {
286                 TRACE("Found expired cookie. deleting\n");
287                 COOKIE_deleteCookie(cookie_iter, FALSE);
288                 continue;
289             }
290
291             if(!cookie_data) { /* return the size of the buffer required to lpdwSize */
292                 if (cookie_count)
293                     cnt += 2; /* '; ' */
294                 cnt += strlenW(cookie_iter->lpCookieName);
295                 if ((len = strlenW(cookie_iter->lpCookieData))) {
296                     cnt += 1; /* = */
297                     cnt += len;
298                 }
299             }else {
300                 static const WCHAR szsc[] = { ';',' ',0 };
301                 static const WCHAR szname[] = { '%','s',0 };
302                 static const WCHAR szdata[] = { '=','%','s',0 };
303
304                 if (cookie_count) cnt += snprintfW(cookie_data + cnt, *size - cnt, szsc);
305                 cnt += snprintfW(cookie_data + cnt, *size - cnt, szname, cookie_iter->lpCookieName);
306
307                 if (cookie_iter->lpCookieData[0])
308                     cnt += snprintfW(cookie_data + cnt, *size - cnt, szdata, cookie_iter->lpCookieData);
309
310                 TRACE("Cookie: %s\n", debugstr_w(cookie_data));
311             }
312             cookie_count++;
313         }
314     }
315
316     if (!domain_count) {
317         TRACE("no cookies found for %s\n", debugstr_w(host));
318         SetLastError(ERROR_NO_MORE_ITEMS);
319         return FALSE;
320     }
321
322     if(!cookie_data) {
323         *size = (cnt + 1) * sizeof(WCHAR);
324         TRACE("returning %u\n", *size);
325         return TRUE;
326     }
327
328     *size = cnt + 1;
329
330     TRACE("Returning %u (from %u domains): %s\n", cnt, domain_count, debugstr_w(cookie_data));
331     return cnt != 0;
332 }
333
334 /***********************************************************************
335  *           InternetGetCookieW (WININET.@)
336  *
337  * Retrieve cookie from the specified url
338  *
339  *  It should be noted that on windows the lpszCookieName parameter is "not implemented".
340  *    So it won't be implemented here.
341  *
342  * RETURNS
343  *    TRUE  on success
344  *    FALSE on failure
345  *
346  */
347 BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
348     LPWSTR lpCookieData, LPDWORD lpdwSize)
349 {
350     WCHAR host[INTERNET_MAX_HOST_NAME_LENGTH], path[INTERNET_MAX_PATH_LENGTH];
351     BOOL ret;
352
353     TRACE("(%s, %s, %p, %p)\n", debugstr_w(lpszUrl),debugstr_w(lpszCookieName), lpCookieData, lpdwSize);
354
355     if (!lpszUrl)
356     {
357         SetLastError(ERROR_INVALID_PARAMETER);
358         return FALSE;
359     }
360
361     host[0] = 0;
362     ret = COOKIE_crackUrlSimple(lpszUrl, host, sizeof(host)/sizeof(host[0]), path, sizeof(path)/sizeof(path[0]));
363     if (!ret || !host[0]) {
364         SetLastError(ERROR_INVALID_PARAMETER);
365         return FALSE;
366     }
367
368     return get_cookie(host, path, lpCookieData, lpdwSize);
369 }
370
371
372 /***********************************************************************
373  *           InternetGetCookieA (WININET.@)
374  *
375  * Retrieve cookie from the specified url
376  *
377  * RETURNS
378  *    TRUE  on success
379  *    FALSE on failure
380  *
381  */
382 BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
383     LPSTR lpCookieData, LPDWORD lpdwSize)
384 {
385     DWORD len;
386     LPWSTR szCookieData = NULL, url, name;
387     BOOL r;
388
389     TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl), debugstr_a(lpszCookieName),
390         lpCookieData);
391
392     url = heap_strdupAtoW(lpszUrl);
393     name = heap_strdupAtoW(lpszCookieName);
394
395     r = InternetGetCookieW( url, name, NULL, &len );
396     if( r )
397     {
398         szCookieData = heap_alloc(len * sizeof(WCHAR));
399         if( !szCookieData )
400         {
401             r = FALSE;
402         }
403         else
404         {
405             r = InternetGetCookieW( url, name, szCookieData, &len );
406
407             *lpdwSize = WideCharToMultiByte( CP_ACP, 0, szCookieData, len,
408                                     lpCookieData, *lpdwSize, NULL, NULL );
409         }
410     }
411     heap_free( szCookieData );
412     heap_free( name );
413     heap_free( url );
414     return r;
415 }
416
417 BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWSTR cookie_data)
418 {
419     cookie_domain *thisCookieDomain = NULL;
420     cookie *thisCookie;
421     struct list *cursor;
422     LPWSTR data, value;
423     WCHAR *ptr;
424     FILETIME expiry;
425     BOOL expired = FALSE;
426
427     value = data = heap_strdupW(cookie_data);
428     if (!data)
429     {
430         ERR("could not allocate the cookie data buffer\n");
431         return FALSE;
432     }
433
434     memset(&expiry,0,sizeof(expiry));
435
436     /* lots of information can be parsed out of the cookie value */
437
438     ptr = data;
439     for (;;)
440     {
441         static const WCHAR szDomain[] = {'d','o','m','a','i','n','=',0};
442         static const WCHAR szPath[] = {'p','a','t','h','=',0};
443         static const WCHAR szExpires[] = {'e','x','p','i','r','e','s','=',0};
444         static const WCHAR szSecure[] = {'s','e','c','u','r','e',0};
445         static const WCHAR szHttpOnly[] = {'h','t','t','p','o','n','l','y',0};
446
447         if (!(ptr = strchrW(ptr,';'))) break;
448         *ptr++ = 0;
449
450         if (value != data) heap_free(value);
451         value = heap_alloc((ptr - data) * sizeof(WCHAR));
452         if (value == NULL)
453         {
454             heap_free(data);
455             ERR("could not allocate the cookie value buffer\n");
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             heap_free(data);
524             if (value != data) heap_free(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         heap_free(data);
538         if (value != data) heap_free(value);
539         return FALSE;
540     }
541     heap_free(data);
542     if (value != data) heap_free(value);
543     return TRUE;
544 }
545
546 /***********************************************************************
547  *           InternetSetCookieW (WININET.@)
548  *
549  * Sets cookie for the specified url
550  *
551  * RETURNS
552  *    TRUE  on success
553  *    FALSE on failure
554  *
555  */
556 BOOL WINAPI InternetSetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
557     LPCWSTR lpCookieData)
558 {
559     BOOL ret;
560     WCHAR hostName[INTERNET_MAX_HOST_NAME_LENGTH], path[INTERNET_MAX_PATH_LENGTH];
561
562     TRACE("(%s,%s,%s)\n", debugstr_w(lpszUrl),
563         debugstr_w(lpszCookieName), debugstr_w(lpCookieData));
564
565     if (!lpszUrl || !lpCookieData)
566     {
567         SetLastError(ERROR_INVALID_PARAMETER);
568         return FALSE;
569     }
570
571     hostName[0] = 0;
572     ret = COOKIE_crackUrlSimple(lpszUrl, hostName, sizeof(hostName)/sizeof(hostName[0]), path, sizeof(path)/sizeof(path[0]));
573     if (!ret || !hostName[0]) return FALSE;
574
575     if (!lpszCookieName)
576     {
577         WCHAR *cookie, *data;
578
579         cookie = heap_strdupW(lpCookieData);
580         if (!cookie)
581         {
582             SetLastError(ERROR_OUTOFMEMORY);
583             return FALSE;
584         }
585
586         /* some apps (or is it us??) try to add a cookie with no cookie name, but
587          * the cookie data in the form of name[=data].
588          */
589         if (!(data = strchrW(cookie, '='))) data = cookie + strlenW(cookie);
590         else *data++ = 0;
591
592         ret = set_cookie(hostName, path, cookie, data);
593
594         heap_free(cookie);
595         return ret;
596     }
597     return set_cookie(hostName, path, lpszCookieName, lpCookieData);
598 }
599
600
601 /***********************************************************************
602  *           InternetSetCookieA (WININET.@)
603  *
604  * Sets cookie for the specified url
605  *
606  * RETURNS
607  *    TRUE  on success
608  *    FALSE on failure
609  *
610  */
611 BOOL WINAPI InternetSetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
612     LPCSTR lpCookieData)
613 {
614     LPWSTR data, url, name;
615     BOOL r;
616
617     TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
618         debugstr_a(lpszCookieName), debugstr_a(lpCookieData));
619
620     url = heap_strdupAtoW(lpszUrl);
621     name = heap_strdupAtoW(lpszCookieName);
622     data = heap_strdupAtoW(lpCookieData);
623
624     r = InternetSetCookieW( url, name, data );
625
626     heap_free( data );
627     heap_free( name );
628     heap_free( url );
629     return r;
630 }
631
632 /***********************************************************************
633  *           InternetSetCookieExA (WININET.@)
634  *
635  * See InternetSetCookieExW.
636  */
637 DWORD WINAPI InternetSetCookieExA( LPCSTR lpszURL, LPCSTR lpszCookieName, LPCSTR lpszCookieData,
638                                    DWORD dwFlags, DWORD_PTR dwReserved)
639 {
640     TRACE("(%s, %s, %s, 0x%08x, 0x%08lx)\n",
641           debugstr_a(lpszURL), debugstr_a(lpszCookieName), debugstr_a(lpszCookieData),
642           dwFlags, dwReserved);
643
644     if (dwFlags) FIXME("flags 0x%08x not supported\n", dwFlags);
645     return InternetSetCookieA(lpszURL, lpszCookieName, lpszCookieData);
646 }
647
648 /***********************************************************************
649  *           InternetSetCookieExW (WININET.@)
650  *
651  * Sets a cookie for the specified URL.
652  *
653  * RETURNS
654  *    TRUE  on success
655  *    FALSE on failure
656  *
657  */
658 DWORD WINAPI InternetSetCookieExW( LPCWSTR lpszURL, LPCWSTR lpszCookieName, LPCWSTR lpszCookieData,
659                                    DWORD dwFlags, DWORD_PTR dwReserved)
660 {
661     TRACE("(%s, %s, %s, 0x%08x, 0x%08lx)\n",
662           debugstr_w(lpszURL), debugstr_w(lpszCookieName), debugstr_w(lpszCookieData),
663           dwFlags, dwReserved);
664
665     if (dwFlags) FIXME("flags 0x%08x not supported\n", dwFlags);
666     return InternetSetCookieW(lpszURL, lpszCookieName, lpszCookieData);
667 }
668
669 /***********************************************************************
670  *           InternetGetCookieExA (WININET.@)
671  *
672  * See InternetGetCookieExW.
673  */
674 BOOL WINAPI InternetGetCookieExA( LPCSTR pchURL, LPCSTR pchCookieName, LPSTR pchCookieData,
675                                   LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
676 {
677     TRACE("(%s, %s, %s, %p, 0x%08x, %p)\n",
678           debugstr_a(pchURL), debugstr_a(pchCookieName), debugstr_a(pchCookieData),
679           pcchCookieData, dwFlags, lpReserved);
680
681     if (dwFlags) FIXME("flags 0x%08x not supported\n", dwFlags);
682     return InternetGetCookieA(pchURL, pchCookieName, pchCookieData, pcchCookieData);
683 }
684
685 /***********************************************************************
686  *           InternetGetCookieExW (WININET.@)
687  *
688  * Retrieve cookie for the specified URL.
689  *
690  * RETURNS
691  *    TRUE  on success
692  *    FALSE on failure
693  *
694  */
695 BOOL WINAPI InternetGetCookieExW( LPCWSTR pchURL, LPCWSTR pchCookieName, LPWSTR pchCookieData,
696                                   LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
697 {
698     TRACE("(%s, %s, %s, %p, 0x%08x, %p)\n",
699           debugstr_w(pchURL), debugstr_w(pchCookieName), debugstr_w(pchCookieData),
700           pcchCookieData, dwFlags, lpReserved);
701
702     if (dwFlags) FIXME("flags 0x%08x not supported\n", dwFlags);
703     return InternetGetCookieW(pchURL, pchCookieName, pchCookieData, pcchCookieData);
704 }
705
706 /***********************************************************************
707  *           InternetClearAllPerSiteCookieDecisions (WININET.@)
708  *
709  * Clears all per-site decisions about cookies.
710  *
711  * RETURNS
712  *    TRUE  on success
713  *    FALSE on failure
714  *
715  */
716 BOOL WINAPI InternetClearAllPerSiteCookieDecisions( VOID )
717 {
718     FIXME("stub\n");
719     return TRUE;
720 }
721
722 /***********************************************************************
723  *           InternetEnumPerSiteCookieDecisionA (WININET.@)
724  *
725  * See InternetEnumPerSiteCookieDecisionW.
726  */
727 BOOL WINAPI InternetEnumPerSiteCookieDecisionA( LPSTR pszSiteName, ULONG *pcSiteNameSize,
728                                                 ULONG *pdwDecision, ULONG dwIndex )
729 {
730     FIXME("(%s, %p, %p, 0x%08x) stub\n",
731           debugstr_a(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
732     return FALSE;
733 }
734
735 /***********************************************************************
736  *           InternetEnumPerSiteCookieDecisionW (WININET.@)
737  *
738  * Enumerates all per-site decisions about cookies.
739  *
740  * RETURNS
741  *    TRUE  on success
742  *    FALSE on failure
743  *
744  */
745 BOOL WINAPI InternetEnumPerSiteCookieDecisionW( LPWSTR pszSiteName, ULONG *pcSiteNameSize,
746                                                 ULONG *pdwDecision, ULONG dwIndex )
747 {
748     FIXME("(%s, %p, %p, 0x%08x) stub\n",
749           debugstr_w(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
750     return FALSE;
751 }
752
753 /***********************************************************************
754  *           InternetGetPerSiteCookieDecisionA (WININET.@)
755  */
756 BOOL WINAPI InternetGetPerSiteCookieDecisionA( LPCSTR pwchHostName, ULONG *pResult )
757 {
758     FIXME("(%s, %p) stub\n", debugstr_a(pwchHostName), pResult);
759     return FALSE;
760 }
761
762 /***********************************************************************
763  *           InternetGetPerSiteCookieDecisionW (WININET.@)
764  */
765 BOOL WINAPI InternetGetPerSiteCookieDecisionW( LPCWSTR pwchHostName, ULONG *pResult )
766 {
767     FIXME("(%s, %p) stub\n", debugstr_w(pwchHostName), pResult);
768     return FALSE;
769 }
770
771 /***********************************************************************
772  *           InternetSetPerSiteCookieDecisionA (WININET.@)
773  */
774 BOOL WINAPI InternetSetPerSiteCookieDecisionA( LPCSTR pchHostName, DWORD dwDecision )
775 {
776     FIXME("(%s, 0x%08x) stub\n", debugstr_a(pchHostName), dwDecision);
777     return FALSE;
778 }
779
780 /***********************************************************************
781  *           InternetSetPerSiteCookieDecisionW (WININET.@)
782  */
783 BOOL WINAPI InternetSetPerSiteCookieDecisionW( LPCWSTR pchHostName, DWORD dwDecision )
784 {
785     FIXME("(%s, 0x%08x) stub\n", debugstr_w(pchHostName), dwDecision);
786     return FALSE;
787 }
788
789 /***********************************************************************
790  *           IsDomainLegalCookieDomainW (WININET.@)
791  */
792 BOOL WINAPI IsDomainLegalCookieDomainW( LPCWSTR s1, LPCWSTR s2 )
793 {
794     const WCHAR *p;
795
796     FIXME("(%s, %s)\n", debugstr_w(s1), debugstr_w(s2));
797
798     if (!s1 || !s2)
799     {
800         SetLastError(ERROR_INVALID_PARAMETER);
801         return FALSE;
802     }
803     if (s1[0] == '.' || !s1[0] || s2[0] == '.' || !s2[0])
804     {
805         SetLastError(ERROR_INVALID_NAME);
806         return FALSE;
807     }
808     if (!(p = strchrW(s2, '.'))) return FALSE;
809     if (strchrW(p + 1, '.') && !strcmpW(p + 1, s1)) return TRUE;
810     else if (!strcmpW(s1, s2)) return TRUE;
811     return FALSE;
812 }