Commit 5ccfec64 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wininet: Fix a number of problems with InternetGetCookie.

This version incorporates Lei Zhang's changes to the test, with his consent.
parent b6ee3c1d
......@@ -258,21 +258,23 @@ static void COOKIE_deleteDomain(cookie_domain *deadDomain)
BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
LPWSTR lpCookieData, LPDWORD lpdwSize)
{
BOOL ret;
struct list * cursor;
int cnt = 0, domain_count = 0;
int cookie_count = 0;
unsigned int cnt = 0, domain_count = 0, cookie_count = 0;
WCHAR hostName[2048], path[2048];
TRACE("(%s, %s, %p, %p)\n", debugstr_w(lpszUrl),debugstr_w(lpszCookieName),
lpCookieData, lpdwSize);
lpCookieData, lpdwSize);
if (!lpszUrl)
{
SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
COOKIE_crackUrlSimple(lpszUrl, hostName, sizeof(hostName)/sizeof(hostName[0]), path, sizeof(path)/sizeof(path[0]));
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;
LIST_FOR_EACH(cursor, &domain_list)
{
......@@ -288,22 +290,29 @@ BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
cookie *thisCookie = LIST_ENTRY(cursor, cookie, entry);
if (lpCookieData == NULL) /* return the size of the buffer required to lpdwSize */
{
if (cookie_count != 0)
cnt += 2; /* '; ' */
unsigned int len;
if (cookie_count) cnt += 2; /* '; ' */
cnt += strlenW(thisCookie->lpCookieName);
cnt += 1; /* = */
cnt += strlenW(thisCookie->lpCookieData);
if ((len = strlenW(thisCookie->lpCookieData)))
{
cnt += 1; /* = */
cnt += len;
}
}
else
{
static const WCHAR szsc[] = { ';',' ',0 };
static const WCHAR szpseq[] = { '%','s','=','%','s',0 };
if (cookie_count != 0)
cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szsc);
cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szpseq,
thisCookie->lpCookieName,
thisCookie->lpCookieData);
TRACE("Cookie: %s=%s\n", debugstr_w(thisCookie->lpCookieName), debugstr_w(thisCookie->lpCookieData));
static const WCHAR szname[] = { '%','s',0 };
static const WCHAR szdata[] = { '=','%','s',0 };
if (cookie_count) cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szsc);
cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szname, thisCookie->lpCookieName);
if (thisCookie->lpCookieData[0])
cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szdata, thisCookie->lpCookieData);
TRACE("Cookie: %s\n", debugstr_w(lpCookieData));
}
cookie_count++;
}
......@@ -319,15 +328,14 @@ BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
if (lpCookieData == NULL)
{
cnt += 1; /* NULL */
*lpdwSize = cnt*sizeof(WCHAR);
TRACE("returning\n");
return TRUE;
*lpdwSize = (cnt + 1) * sizeof(WCHAR);
TRACE("returning %u\n", *lpdwSize);
return TRUE;
}
*lpdwSize = (cnt + 1)*sizeof(WCHAR);
*lpdwSize = cnt + 1;
TRACE("Returning %i (from %i domains): %s\n", cnt, domain_count,
TRACE("Returning %u (from %u domains): %s\n", cnt, domain_count,
debugstr_w(lpCookieData));
return (cnt ? TRUE : FALSE);
......
......@@ -285,7 +285,7 @@ static void test_null(void)
sz = 0;
r = InternetGetCookieW(NULL, NULL, NULL, &sz);
ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
ok( r == FALSE, "return wrong\n");
r = InternetGetCookieW(szServer, NULL, NULL, &sz);
......@@ -295,25 +295,30 @@ static void test_null(void)
ok( r == FALSE, "return wrong\n");
sz = 0;
r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
ok( r == FALSE, "return wrong\n");
sz = 0;
r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
ok( r == TRUE, "return wrong\n");
todo_wine {
ok( sz == 30, "sz wrong\n");
}
/* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
sz = 0x20;
memset(buffer, 0, sizeof buffer);
r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
ok( r == TRUE, "return wrong\n");
todo_wine {
ok( sz == lstrlenW(buffer), "sz wrong\n");
ok( !lstrcmpW(szExpect, buffer), "cookie data wrong\n");
}
/* sz == lstrlenW(buffer) only in XP SP1 */
ok( sz == 1 + lstrlenW(buffer), "sz wrong\n");
/* before XP SP2, buffer is "server; server" */
ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
sz = sizeof(buffer);
r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
ok(r == TRUE, "ret %d\n", r);
}
/* ############################### */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment