Module: wine Branch: master Commit: 9a741bf3d72498bce5726856ff3f8d5ac9d95420 URL: http://source.winehq.org/git/wine.git/?a=commit;h=9a741bf3d72498bce5726856ff...
Author: Jacek Caban jacek@codeweavers.com Date: Thu May 19 16:11:10 2011 +0200
wininet: Moved getting cookie from known host to separated function.
---
dlls/wininet/cookie.c | 160 ++++++++++++++++++++++++------------------------- 1 files changed, 78 insertions(+), 82 deletions(-)
diff --git a/dlls/wininet/cookie.c b/dlls/wininet/cookie.c index 8a50ef7..683776b 100644 --- a/dlls/wininet/cookie.c +++ b/dlls/wininet/cookie.c @@ -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); + GetSystemTimeAsFileTime(&tm);
- if (!lpszUrl) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } + LIST_FOR_EACH_ENTRY(domain, &domain_list, cookie_domain, entry) { + struct list *cursor, *cursor2;
- 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; - - 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); + domain_count++; + TRACE("found domain %p\n", domain);
- LIST_FOR_EACH_SAFE(cursor, cursor2, &cookiesDomain->cookie_list) + LIST_FOR_EACH_SAFE(cursor, cursor2, &domain->cookie_list) { + cookie *cookie_iter = LIST_ENTRY(cursor, cookie, entry); + + /* check for expiry */ + if((cookie_iter->expiry.dwLowDateTime != 0 || cookie_iter->expiry.dwHighDateTime != 0) + && CompareFileTime(&tm, &cookie_iter->expiry) > 0) { - cookie *thisCookie = LIST_ENTRY(cursor, cookie, entry); - /* check for expiry */ - if ((thisCookie->expiry.dwLowDateTime != 0 || thisCookie->expiry.dwHighDateTime != 0) && CompareFileTime(&tm,&thisCookie->expiry) > 0) - { - TRACE("Found expired cookie. deleting\n"); - COOKIE_deleteCookie(thisCookie, FALSE); - continue; - } + TRACE("Found expired cookie. deleting\n"); + 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))) - { - cnt += 1; /* = */ - cnt += len; - } + 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 - { - static const WCHAR szsc[] = { ';',' ',0 }; - static const WCHAR szname[] = { '%','s',0 }; - static const WCHAR szdata[] = { '=','%','s',0 }; + }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)); - } - cookie_count++; + 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); }