Commit b9c2a195 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

wininet: Make cookies functions thread-safe.

parent fc219b0a
......@@ -49,7 +49,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
/* FIXME
* Cookies are NOT THREAD SAFE
* Cookies could use A LOT OF MEMORY. We need some kind of memory management here!
*/
......@@ -78,6 +77,14 @@ struct _cookie_domain
struct list cookie_list;
};
static CRITICAL_SECTION cookie_cs;
static CRITICAL_SECTION_DEBUG cookie_cs_debug =
{
0, 0, &cookie_cs,
{ &cookie_cs_debug.ProcessLocksList, &cookie_cs_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": cookie_cs") }
};
static CRITICAL_SECTION cookie_cs = { &cookie_cs_debug, -1, 0, 0, 0, 0 };
static struct list domain_list = LIST_INIT(domain_list);
static cookie *COOKIE_addCookie(cookie_domain *domain, LPCWSTR name, LPCWSTR data,
......@@ -529,6 +536,8 @@ BOOL get_cookie(const WCHAR *host, const WCHAR *path, WCHAR *cookie_data, DWORD
GetSystemTimeAsFileTime(&tm);
EnterCriticalSection(&cookie_cs);
load_persistent_cookie(host, path);
LIST_FOR_EACH_ENTRY(domain, &domain_list, cookie_domain, entry) {
......@@ -577,6 +586,8 @@ BOOL get_cookie(const WCHAR *host, const WCHAR *path, WCHAR *cookie_data, DWORD
}
}
LeaveCriticalSection(&cookie_cs);
if (!domain_count) {
TRACE("no cookies found for %s\n", debugstr_w(host));
SetLastError(ERROR_NO_MORE_ITEMS);
......@@ -825,6 +836,8 @@ BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWSTR cooki
}
}
EnterCriticalSection(&cookie_cs);
load_persistent_cookie(domain, path);
LIST_FOR_EACH(cursor, &domain_list)
......@@ -843,6 +856,7 @@ BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWSTR cooki
{
heap_free(data);
if (value != data) heap_free(value);
LeaveCriticalSection(&cookie_cs);
return TRUE;
}
}
......@@ -866,11 +880,19 @@ BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWSTR cooki
{
heap_free(data);
if (value != data) heap_free(value);
LeaveCriticalSection(&cookie_cs);
return FALSE;
}
heap_free(data);
if (value != data) heap_free(value);
return !update_persistent || save_persistent_cookie(thisCookieDomain);
if (!update_persistent || save_persistent_cookie(thisCookieDomain))
{
LeaveCriticalSection(&cookie_cs);
return TRUE;
}
LeaveCriticalSection(&cookie_cs);
return FALSE;
}
/***********************************************************************
......@@ -1115,3 +1137,8 @@ BOOL WINAPI InternetSetPerSiteCookieDecisionW( LPCWSTR pchHostName, DWORD dwDeci
FIXME("(%s, 0x%08x) stub\n", debugstr_w(pchHostName), dwDecision);
return FALSE;
}
void free_cookie(void)
{
DeleteCriticalSection(&cookie_cs);
}
......@@ -315,6 +315,7 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
collect_connections(COLLECT_CLEANUP);
NETCON_unload();
free_urlcache();
free_cookie();
if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
{
......
......@@ -553,6 +553,7 @@ server_t *get_server(const WCHAR*,INTERNET_PORT,BOOL);
BOOL init_urlcache(void) DECLSPEC_HIDDEN;
void free_urlcache(void) DECLSPEC_HIDDEN;
void free_cookie(void) DECLSPEC_HIDDEN;
#define MAX_REPLY_LEN 0x5B4
......
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