winhttp: Make cookie access thread safe.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Jacek Caban 2018-10-05 14:59:10 +02:00 committed by Alexandre Julliard
parent acf936b94a
commit 533083e498
3 changed files with 27 additions and 10 deletions

View File

@ -116,24 +116,28 @@ static BOOL add_cookie( session_t *session, cookie_t *cookie, WCHAR *domain_name
cookie_t *old_cookie; cookie_t *old_cookie;
struct list *item; struct list *item;
if (!(cookie->path = strdupW( path ))) return FALSE;
EnterCriticalSection( &session->cs );
LIST_FOR_EACH( item, &session->cookie_cache ) LIST_FOR_EACH( item, &session->cookie_cache )
{ {
domain = LIST_ENTRY( item, domain_t, entry ); domain = LIST_ENTRY( item, domain_t, entry );
if (domain_match( domain_name, domain, FALSE )) break; if (domain_match( domain_name, domain, FALSE )) break;
domain = NULL; domain = NULL;
} }
if (!domain) if (!domain) domain = add_domain( session, domain_name );
{
if (!(domain = add_domain( session, domain_name ))) return FALSE;
}
else if ((old_cookie = find_cookie( domain, path, cookie->name ))) delete_cookie( old_cookie ); else if ((old_cookie = find_cookie( domain, path, cookie->name ))) delete_cookie( old_cookie );
cookie->path = strdupW( path ); if (domain)
list_add_head( &domain->cookies, &cookie->entry ); {
list_add_head( &domain->cookies, &cookie->entry );
TRACE("domain %s path %s <- %s=%s\n", debugstr_w(domain_name), debugstr_w(cookie->path),
debugstr_w(cookie->name), debugstr_w(cookie->value));
}
TRACE("domain %s path %s <- %s=%s\n", debugstr_w(domain_name), debugstr_w(cookie->path), LeaveCriticalSection( &session->cs );
debugstr_w(cookie->name), debugstr_w(cookie->value)); return domain != NULL;
return TRUE;
} }
static cookie_t *parse_cookie( const WCHAR *string ) static cookie_t *parse_cookie( const WCHAR *string )
@ -303,6 +307,8 @@ BOOL add_cookie_headers( request_t *request )
struct list *domain_cursor; struct list *domain_cursor;
session_t *session = request->connect->session; session_t *session = request->connect->session;
EnterCriticalSection( &session->cs );
LIST_FOR_EACH( domain_cursor, &session->cookie_cache ) LIST_FOR_EACH( domain_cursor, &session->cookie_cache )
{ {
domain_t *domain = LIST_ENTRY( domain_cursor, domain_t, entry ); domain_t *domain = LIST_ENTRY( domain_cursor, domain_t, entry );
@ -325,7 +331,11 @@ BOOL add_cookie_headers( request_t *request )
len = len_cookie + len_name; len = len_cookie + len_name;
if (cookie->value) len += strlenW( cookie->value ) + 1; if (cookie->value) len += strlenW( cookie->value ) + 1;
if (!(header = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return FALSE; if (!(header = heap_alloc( (len + 1) * sizeof(WCHAR) )))
{
LeaveCriticalSection( &session->cs );
return FALSE;
}
memcpy( header, cookieW, len_cookie * sizeof(WCHAR) ); memcpy( header, cookieW, len_cookie * sizeof(WCHAR) );
strcpyW( header + len_cookie, cookie->name ); strcpyW( header + len_cookie, cookie->name );
@ -343,5 +353,7 @@ BOOL add_cookie_headers( request_t *request )
} }
} }
} }
LeaveCriticalSection( &session->cs );
return TRUE; return TRUE;
} }

View File

@ -102,6 +102,8 @@ static void session_destroy( object_header_t *hdr )
domain = LIST_ENTRY( item, domain_t, entry ); domain = LIST_ENTRY( item, domain_t, entry );
delete_domain( domain ); delete_domain( domain );
} }
session->cs.DebugInfo->Spare[0] = 0;
DeleteCriticalSection( &session->cs );
heap_free( session->agent ); heap_free( session->agent );
heap_free( session->proxy_server ); heap_free( session->proxy_server );
heap_free( session->proxy_bypass ); heap_free( session->proxy_bypass );
@ -279,6 +281,8 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWST
session->receive_timeout = DEFAULT_RECEIVE_TIMEOUT; session->receive_timeout = DEFAULT_RECEIVE_TIMEOUT;
session->receive_response_timeout = DEFAULT_RECEIVE_RESPONSE_TIMEOUT; session->receive_response_timeout = DEFAULT_RECEIVE_RESPONSE_TIMEOUT;
list_init( &session->cookie_cache ); list_init( &session->cookie_cache );
InitializeCriticalSection( &session->cs );
session->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": session.cs");
if (agent && !(session->agent = strdupW( agent ))) goto end; if (agent && !(session->agent = strdupW( agent ))) goto end;
if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY) if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)

View File

@ -85,6 +85,7 @@ typedef struct {
typedef struct typedef struct
{ {
object_header_t hdr; object_header_t hdr;
CRITICAL_SECTION cs;
LPWSTR agent; LPWSTR agent;
DWORD access; DWORD access;
int resolve_timeout; int resolve_timeout;