wininet: Fix a number of problems with InternetSetCookie.
This commit is contained in:
parent
306129c92e
commit
b6ee3c1d6b
|
@ -174,7 +174,7 @@ static cookie_domain *COOKIE_addDomain(LPCWSTR domain, LPCWSTR path)
|
|||
return newDomain;
|
||||
}
|
||||
|
||||
static void COOKIE_crackUrlSimple(LPCWSTR lpszUrl, LPWSTR hostName, int hostNameLen, LPWSTR path, int pathLen)
|
||||
static BOOL COOKIE_crackUrlSimple(LPCWSTR lpszUrl, LPWSTR hostName, int hostNameLen, LPWSTR path, int pathLen)
|
||||
{
|
||||
URL_COMPONENTSW UrlComponents;
|
||||
|
||||
|
@ -191,7 +191,7 @@ static void COOKIE_crackUrlSimple(LPCWSTR lpszUrl, LPWSTR hostName, int hostName
|
|||
UrlComponents.dwHostNameLength = hostNameLen;
|
||||
UrlComponents.dwUrlPathLength = pathLen;
|
||||
|
||||
InternetCrackUrlW(lpszUrl, 0, 0, &UrlComponents);
|
||||
return InternetCrackUrlW(lpszUrl, 0, 0, &UrlComponents);
|
||||
}
|
||||
|
||||
/* match a domain. domain must match if the domain is not NULL. path must match if the path is not NULL */
|
||||
|
@ -392,6 +392,34 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
|
|||
return r;
|
||||
}
|
||||
|
||||
static BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWSTR cookie_data)
|
||||
{
|
||||
cookie_domain *thisCookieDomain = NULL;
|
||||
cookie *thisCookie;
|
||||
struct list *cursor;
|
||||
|
||||
LIST_FOR_EACH(cursor, &domain_list)
|
||||
{
|
||||
thisCookieDomain = LIST_ENTRY(cursor, cookie_domain, entry);
|
||||
if (COOKIE_matchDomain(domain, NULL /* FIXME: path */, thisCookieDomain, FALSE))
|
||||
break;
|
||||
thisCookieDomain = NULL;
|
||||
}
|
||||
|
||||
if (!thisCookieDomain)
|
||||
thisCookieDomain = COOKIE_addDomain(domain, path);
|
||||
|
||||
if ((thisCookie = COOKIE_findCookie(thisCookieDomain, cookie_name)))
|
||||
COOKIE_deleteCookie(thisCookie, FALSE);
|
||||
|
||||
TRACE("setting cookie %s=%s for domain %s\n", debugstr_w(cookie_name),
|
||||
debugstr_w(cookie_data), debugstr_w(thisCookieDomain->lpCookieDomain));
|
||||
|
||||
if (!COOKIE_addCookie(thisCookieDomain, cookie_name, cookie_data))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* InternetSetCookieW (WININET.@)
|
||||
|
@ -406,64 +434,47 @@ BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
|
|||
BOOL WINAPI InternetSetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
|
||||
LPCWSTR lpCookieData)
|
||||
{
|
||||
cookie_domain *thisCookieDomain = NULL;
|
||||
cookie *thisCookie;
|
||||
BOOL ret;
|
||||
WCHAR hostName[2048], path[2048];
|
||||
struct list * cursor;
|
||||
|
||||
TRACE("(%s,%s,%s)\n", debugstr_w(lpszUrl),
|
||||
debugstr_w(lpszCookieName), debugstr_w(lpCookieData));
|
||||
|
||||
if (!lpCookieData)
|
||||
if (!lpszUrl || !lpCookieData)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
hostName[0] = 0;
|
||||
ret = COOKIE_crackUrlSimple(lpszUrl, hostName, sizeof(hostName)/sizeof(hostName[0]), path, sizeof(path)/sizeof(path[0]));
|
||||
if (!ret || !hostName[0]) return FALSE;
|
||||
|
||||
if (!lpszCookieName)
|
||||
{
|
||||
/* some apps (or is it us??) try to add a cookie with no cookie name, but
|
||||
* the cookie data in the form of name=data. */
|
||||
/* FIXME, probably a bug here, for now I don't care */
|
||||
WCHAR *ourCookieName, *ourCookieData;
|
||||
int ourCookieNameSize;
|
||||
BOOL ret;
|
||||
unsigned int len;
|
||||
WCHAR *cookie, *data;
|
||||
|
||||
if (!(ourCookieData = strchrW(lpCookieData, '=')))
|
||||
{
|
||||
TRACE("something terribly wrong with cookie data %s\n",
|
||||
debugstr_w(ourCookieData));
|
||||
return FALSE;
|
||||
}
|
||||
ourCookieNameSize = ourCookieData - lpCookieData;
|
||||
ourCookieData += 1;
|
||||
ourCookieName = HeapAlloc(GetProcessHeap(), 0,
|
||||
(ourCookieNameSize + 1)*sizeof(WCHAR));
|
||||
memcpy(ourCookieName, lpCookieData, ourCookieNameSize * sizeof(WCHAR));
|
||||
ourCookieName[ourCookieNameSize] = '\0';
|
||||
TRACE("setting (hacked) cookie of %s, %s\n",
|
||||
debugstr_w(ourCookieName), debugstr_w(ourCookieData));
|
||||
ret = InternetSetCookieW(lpszUrl, ourCookieName, ourCookieData);
|
||||
HeapFree(GetProcessHeap(), 0, ourCookieName);
|
||||
len = strlenW(lpCookieData);
|
||||
if (!(cookie = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR))))
|
||||
{
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
return FALSE;
|
||||
}
|
||||
strcpyW(cookie, lpCookieData);
|
||||
|
||||
/* some apps (or is it us??) try to add a cookie with no cookie name, but
|
||||
* the cookie data in the form of name[=data].
|
||||
*/
|
||||
if (!(data = strchrW(cookie, '='))) data = cookie + len;
|
||||
else data++;
|
||||
|
||||
ret = set_cookie(hostName, path, cookie, data);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, cookie);
|
||||
return ret;
|
||||
}
|
||||
|
||||
COOKIE_crackUrlSimple(lpszUrl, hostName, sizeof(hostName)/sizeof(hostName[0]), path, sizeof(path)/sizeof(path[0]));
|
||||
|
||||
LIST_FOR_EACH(cursor, &domain_list)
|
||||
{
|
||||
thisCookieDomain = LIST_ENTRY(cursor, cookie_domain, entry);
|
||||
if (COOKIE_matchDomain(hostName, NULL /* FIXME: path */, thisCookieDomain, FALSE))
|
||||
break;
|
||||
thisCookieDomain = NULL;
|
||||
}
|
||||
if (!thisCookieDomain)
|
||||
thisCookieDomain = COOKIE_addDomain(hostName, path);
|
||||
|
||||
if ((thisCookie = COOKIE_findCookie(thisCookieDomain, lpszCookieName)))
|
||||
COOKIE_deleteCookie(thisCookie, FALSE);
|
||||
|
||||
thisCookie = COOKIE_addCookie(thisCookieDomain, lpszCookieName, lpCookieData);
|
||||
return TRUE;
|
||||
return set_cookie(hostName, path, lpszCookieName, lpCookieData);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -218,6 +218,7 @@ static void test_null(void)
|
|||
static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
|
||||
static const WCHAR szEmpty[] = { 0 };
|
||||
static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
|
||||
static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
|
||||
static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
|
||||
WCHAR buffer[0x20];
|
||||
BOOL r;
|
||||
|
@ -267,14 +268,15 @@ static void test_null(void)
|
|||
r = InternetSetCookieW(szUrl, szServer, szServer);
|
||||
ok(r == TRUE, "return wrong\n");
|
||||
|
||||
todo_wine {
|
||||
r = InternetSetCookieW(szUrl, NULL, szServer);
|
||||
ok(r == TRUE, "return wrong\n");
|
||||
}
|
||||
|
||||
r = InternetSetCookieW(szUrl, szServer, szEmpty);
|
||||
ok(r == TRUE, "return wrong\n");
|
||||
|
||||
r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
|
||||
ok(r == FALSE, "return wrong\n");
|
||||
|
||||
r = InternetSetCookieW(szServer, NULL, szServer);
|
||||
todo_wine {
|
||||
ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
|
||||
|
|
Loading…
Reference in New Issue