wininet: Rerite COOKIE_crackUrlSimple to use substrings.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2016-05-16 22:45:57 +02:00 committed by Alexandre Julliard
parent 18a31e49bc
commit 8264e2de94
1 changed files with 21 additions and 45 deletions

View File

@ -509,44 +509,23 @@ static BOOL save_persistent_cookie(cookie_container_t *container)
return CommitUrlCacheEntryW(cookie_url, cookie_file, time, time, 0, NULL, 0, txtW, 0); return CommitUrlCacheEntryW(cookie_url, cookie_file, time, time, 0, NULL, 0, txtW, 0);
} }
static BOOL COOKIE_crackUrlSimple(LPCWSTR lpszUrl, LPWSTR hostName, int hostNameLen, LPWSTR path, int pathLen) static BOOL cookie_parse_url(const WCHAR *url, substr_t *host, substr_t *path)
{ {
URL_COMPONENTSW UrlComponents; URL_COMPONENTSW comp = { sizeof(comp) };
static const WCHAR rootW[] = {'/',0};
UrlComponents.lpszExtraInfo = NULL; comp.dwHostNameLength = 1;
UrlComponents.lpszPassword = NULL; comp.dwUrlPathLength = 1;
UrlComponents.lpszScheme = NULL;
UrlComponents.lpszUrlPath = path;
UrlComponents.lpszUserName = NULL;
UrlComponents.lpszHostName = hostName;
UrlComponents.dwExtraInfoLength = 0;
UrlComponents.dwPasswordLength = 0;
UrlComponents.dwSchemeLength = 0;
UrlComponents.dwUserNameLength = 0;
UrlComponents.dwHostNameLength = hostNameLen;
UrlComponents.dwUrlPathLength = pathLen;
if (!InternetCrackUrlW(lpszUrl, 0, 0, &UrlComponents)) return FALSE; if(!InternetCrackUrlW(url, 0, 0, &comp) || !comp.dwHostNameLength)
return FALSE;
/* discard the webpage off the end of the path */ /* discard the webpage off the end of the path */
if (UrlComponents.dwUrlPathLength) while(comp.dwUrlPathLength && comp.lpszUrlPath[comp.dwUrlPathLength-1] != '/')
{ comp.dwUrlPathLength--;
if (path[UrlComponents.dwUrlPathLength - 1] != '/')
{ *host = substr(comp.lpszHostName, comp.dwHostNameLength);
WCHAR *ptr; *path = comp.dwUrlPathLength ? substr(comp.lpszUrlPath, comp.dwUrlPathLength) : substr(rootW, 1);
if ((ptr = strrchrW(path, '/'))) *(++ptr) = 0;
else
{
path[0] = '/';
path[1] = 0;
}
}
}
else if (pathLen >= 2)
{
path[0] = '/';
path[1] = 0;
}
return TRUE; return TRUE;
} }
@ -734,8 +713,8 @@ DWORD get_cookie_header(const WCHAR *host, const WCHAR *path, WCHAR **ret)
BOOL WINAPI InternetGetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName, BOOL WINAPI InternetGetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
LPWSTR lpCookieData, LPDWORD lpdwSize, DWORD flags, void *reserved) LPWSTR lpCookieData, LPDWORD lpdwSize, DWORD flags, void *reserved)
{ {
WCHAR host[INTERNET_MAX_HOST_NAME_LENGTH], path[INTERNET_MAX_PATH_LENGTH];
cookie_set_t cookie_set = {0}; cookie_set_t cookie_set = {0};
substr_t host, path;
DWORD res; DWORD res;
BOOL ret; BOOL ret;
@ -750,16 +729,15 @@ BOOL WINAPI InternetGetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
return FALSE; return FALSE;
} }
host[0] = 0; ret = cookie_parse_url(lpszUrl, &host, &path);
ret = COOKIE_crackUrlSimple(lpszUrl, host, sizeof(host)/sizeof(host[0]), path, sizeof(path)/sizeof(path[0])); if (!ret) {
if (!ret || !host[0]) {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
} }
EnterCriticalSection(&cookie_cs); EnterCriticalSection(&cookie_cs);
res = get_cookie(substrz(host), substrz(path), flags, &cookie_set); res = get_cookie(host, path, flags, &cookie_set);
if(res != ERROR_SUCCESS) { if(res != ERROR_SUCCESS) {
LeaveCriticalSection(&cookie_cs); LeaveCriticalSection(&cookie_cs);
SetLastError(res); SetLastError(res);
@ -780,7 +758,7 @@ BOOL WINAPI InternetGetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
lpCookieData[cookie_set.string_len] = 0; lpCookieData[cookie_set.string_len] = 0;
} }
}else { }else {
TRACE("no cookies found for %s\n", debugstr_w(host)); TRACE("no cookies found for %s\n", debugstr_wn(host.str, host.len));
SetLastError(ERROR_NO_MORE_ITEMS); SetLastError(ERROR_NO_MORE_ITEMS);
ret = FALSE; ret = FALSE;
} }
@ -1078,9 +1056,8 @@ DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, D
DWORD WINAPI InternetSetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName, DWORD WINAPI InternetSetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
LPCWSTR lpCookieData, DWORD flags, DWORD_PTR reserved) LPCWSTR lpCookieData, DWORD flags, DWORD_PTR reserved)
{ {
substr_t name, data; substr_t host, path, name, data;
BOOL ret; BOOL ret;
WCHAR hostName[INTERNET_MAX_HOST_NAME_LENGTH], path[INTERNET_MAX_PATH_LENGTH];
TRACE("(%s, %s, %s, %x, %lx)\n", debugstr_w(lpszUrl), debugstr_w(lpszCookieName), TRACE("(%s, %s, %s, %x, %lx)\n", debugstr_w(lpszUrl), debugstr_w(lpszCookieName),
debugstr_w(lpCookieData), flags, reserved); debugstr_w(lpCookieData), flags, reserved);
@ -1094,9 +1071,8 @@ DWORD WINAPI InternetSetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
return COOKIE_STATE_UNKNOWN; return COOKIE_STATE_UNKNOWN;
} }
hostName[0] = 0; ret = cookie_parse_url(lpszUrl, &host, &path);
ret = COOKIE_crackUrlSimple(lpszUrl, hostName, sizeof(hostName)/sizeof(hostName[0]), path, sizeof(path)/sizeof(path[0])); if (!ret || !host.len) return COOKIE_STATE_UNKNOWN;
if (!ret || !hostName[0]) return COOKIE_STATE_UNKNOWN;
if (!lpszCookieName) { if (!lpszCookieName) {
const WCHAR *ptr; const WCHAR *ptr;
@ -1114,7 +1090,7 @@ DWORD WINAPI InternetSetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
data = substrz(lpCookieData); data = substrz(lpCookieData);
} }
return set_cookie(substrz(hostName), substrz(path), name, data, flags); return set_cookie(host, path, name, data, flags);
} }
/*********************************************************************** /***********************************************************************