Commit 9a741bf3 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

wininet: Moved getting cookie from known host to separated function.

parent aca2385d
......@@ -260,114 +260,110 @@ static void COOKIE_deleteDomain(cookie_domain *deadDomain)
HeapFree(GetProcessHeap(), 0, deadDomain);
}
/***********************************************************************
* InternetGetCookieW (WININET.@)
*
* Retrieve cookie from the specified url
*
* It should be noted that on windows the lpszCookieName parameter is "not implemented".
* So it won't be implemented here.
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
LPWSTR lpCookieData, LPDWORD lpdwSize)
static BOOL get_cookie(const WCHAR *host, const WCHAR *path, WCHAR *cookie_data, DWORD *size)
{
BOOL ret;
struct list * cursor;
unsigned int cnt = 0, domain_count = 0, cookie_count = 0;
WCHAR hostName[2048], path[2048];
unsigned cnt = 0, len, domain_count = 0, cookie_count = 0;
cookie_domain *domain;
FILETIME tm;
TRACE("(%s, %s, %p, %p)\n", debugstr_w(lpszUrl),debugstr_w(lpszCookieName),
lpCookieData, lpdwSize);
if (!lpszUrl)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
GetSystemTimeAsFileTime(&tm);
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_ENTRY(domain, &domain_list, cookie_domain, entry) {
struct list *cursor, *cursor2;
GetSystemTimeAsFileTime(&tm);
if(!COOKIE_matchDomain(host, path, domain, TRUE))
continue;
LIST_FOR_EACH(cursor, &domain_list)
{
cookie_domain *cookiesDomain = LIST_ENTRY(cursor, cookie_domain, entry);
if (COOKIE_matchDomain(hostName, path, cookiesDomain, TRUE))
{
struct list * cursor, * cursor2;
domain_count++;
TRACE("found domain %p\n", cookiesDomain);
TRACE("found domain %p\n", domain);
LIST_FOR_EACH_SAFE(cursor, cursor2, &domain->cookie_list) {
cookie *cookie_iter = LIST_ENTRY(cursor, cookie, entry);
LIST_FOR_EACH_SAFE(cursor, cursor2, &cookiesDomain->cookie_list)
{
cookie *thisCookie = LIST_ENTRY(cursor, cookie, entry);
/* check for expiry */
if ((thisCookie->expiry.dwLowDateTime != 0 || thisCookie->expiry.dwHighDateTime != 0) && CompareFileTime(&tm,&thisCookie->expiry) > 0)
if((cookie_iter->expiry.dwLowDateTime != 0 || cookie_iter->expiry.dwHighDateTime != 0)
&& CompareFileTime(&tm, &cookie_iter->expiry) > 0)
{
TRACE("Found expired cookie. deleting\n");
COOKIE_deleteCookie(thisCookie, FALSE);
COOKIE_deleteCookie(cookie_iter, FALSE);
continue;
}
if (lpCookieData == NULL) /* return the size of the buffer required to lpdwSize */
{
unsigned int len;
if (cookie_count) cnt += 2; /* '; ' */
cnt += strlenW(thisCookie->lpCookieName);
if ((len = strlenW(thisCookie->lpCookieData)))
{
if(!cookie_data) { /* return the size of the buffer required to lpdwSize */
if (cookie_count)
cnt += 2; /* '; ' */
cnt += strlenW(cookie_iter->lpCookieName);
if ((len = strlenW(cookie_iter->lpCookieData))) {
cnt += 1; /* = */
cnt += len;
}
}
else
{
}else {
static const WCHAR szsc[] = { ';',' ',0 };
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 (cookie_count) cnt += snprintfW(cookie_data + cnt, *size - cnt, szsc);
cnt += snprintfW(cookie_data + cnt, *size - cnt, szname, cookie_iter->lpCookieName);
if (thisCookie->lpCookieData[0])
cnt += snprintfW(lpCookieData + cnt, *lpdwSize - cnt, szdata, thisCookie->lpCookieData);
if (cookie_iter->lpCookieData[0])
cnt += snprintfW(cookie_data + cnt, *size - cnt, szdata, cookie_iter->lpCookieData);
TRACE("Cookie: %s\n", debugstr_w(lpCookieData));
TRACE("Cookie: %s\n", debugstr_w(cookie_data));
}
cookie_count++;
}
}
}
if (!domain_count)
{
TRACE("no cookies found for %s\n", debugstr_w(hostName));
if (!domain_count) {
TRACE("no cookies found for %s\n", debugstr_w(host));
SetLastError(ERROR_NO_MORE_ITEMS);
return FALSE;
}
if (lpCookieData == NULL)
{
*lpdwSize = (cnt + 1) * sizeof(WCHAR);
TRACE("returning %u\n", *lpdwSize);
if(!cookie_data) {
*size = (cnt + 1) * sizeof(WCHAR);
TRACE("returning %u\n", *size);
return TRUE;
}
*lpdwSize = cnt + 1;
*size = cnt + 1;
TRACE("Returning %u (from %u domains): %s\n", cnt, domain_count, debugstr_w(cookie_data));
return cnt != 0;
}
/***********************************************************************
* InternetGetCookieW (WININET.@)
*
* Retrieve cookie from the specified url
*
* It should be noted that on windows the lpszCookieName parameter is "not implemented".
* So it won't be implemented here.
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
LPWSTR lpCookieData, LPDWORD lpdwSize)
{
WCHAR host[INTERNET_MAX_HOST_NAME_LENGTH], path[INTERNET_MAX_PATH_LENGTH];
BOOL ret;
TRACE("(%s, %s, %p, %p)\n", debugstr_w(lpszUrl),debugstr_w(lpszCookieName), lpCookieData, lpdwSize);
if (!lpszUrl)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
TRACE("Returning %u (from %u domains): %s\n", cnt, domain_count,
debugstr_w(lpCookieData));
host[0] = 0;
ret = COOKIE_crackUrlSimple(lpszUrl, host, sizeof(host)/sizeof(host[0]), path, sizeof(path)/sizeof(path[0]));
if (!ret || !host[0]) return FALSE;
return (cnt ? TRUE : FALSE);
return get_cookie(host, path, lpCookieData, lpdwSize);
}
......
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