Commit ebe6e747 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

winhttp: Use the wcsdup function instead of reimplementing it.

parent 7f5a7189
...@@ -54,7 +54,7 @@ static struct domain *add_domain( struct session *session, WCHAR *name ) ...@@ -54,7 +54,7 @@ static struct domain *add_domain( struct session *session, WCHAR *name )
list_init( &domain->entry ); list_init( &domain->entry );
list_init( &domain->cookies ); list_init( &domain->cookies );
domain->name = strdupW( name ); domain->name = wcsdup( name );
list_add_tail( &session->cookie_cache, &domain->entry ); list_add_tail( &session->cookie_cache, &domain->entry );
TRACE("%s\n", debugstr_w(domain->name)); TRACE("%s\n", debugstr_w(domain->name));
...@@ -135,7 +135,7 @@ static BOOL add_cookie( struct session *session, struct cookie *cookie, WCHAR *d ...@@ -135,7 +135,7 @@ static BOOL add_cookie( struct session *session, struct cookie *cookie, WCHAR *d
struct cookie *old_cookie; struct cookie *old_cookie;
struct list *item; struct list *item;
if (!(cookie->path = strdupW( path ))) return FALSE; if (!(cookie->path = wcsdup( path ))) return FALSE;
EnterCriticalSection( &session->cs ); EnterCriticalSection( &session->cs );
...@@ -303,8 +303,8 @@ BOOL set_cookies( struct request *request, const WCHAR *cookies ) ...@@ -303,8 +303,8 @@ BOOL set_cookies( struct request *request, const WCHAR *cookies )
len -= used; len -= used;
p += used; p += used;
} }
if (!cookie_domain && !(cookie_domain = strdupW( request->connect->servername ))) goto end; if (!cookie_domain && !(cookie_domain = wcsdup( request->connect->servername ))) goto end;
if (!cookie_path && !(cookie_path = strdupW( request->path ))) goto end; if (!cookie_path && !(cookie_path = wcsdup( request->path ))) goto end;
if ((p = wcsrchr( cookie_path, '/' )) && p != cookie_path) *p = 0; if ((p = wcsrchr( cookie_path, '/' )) && p != cookie_path) *p = 0;
ret = add_cookie( session, cookie, cookie_domain, cookie_path ); ret = add_cookie( session, cookie, cookie_domain, cookie_path );
......
...@@ -770,7 +770,7 @@ static struct async_resolve *create_async_resolve( const WCHAR *hostname, INTERN ...@@ -770,7 +770,7 @@ static struct async_resolve *create_async_resolve( const WCHAR *hostname, INTERN
return NULL; return NULL;
} }
ret->ref = 1; ret->ref = 1;
ret->hostname = strdupW( hostname ); ret->hostname = wcsdup( hostname );
ret->port = port; ret->port = port;
if (!(ret->done = CreateEventW( NULL, FALSE, FALSE, NULL ))) if (!(ret->done = CreateEventW( NULL, FALSE, FALSE, NULL )))
{ {
......
...@@ -371,8 +371,8 @@ static DWORD insert_header( struct request *request, struct header *header ) ...@@ -371,8 +371,8 @@ static DWORD insert_header( struct request *request, struct header *header )
if (!hdrs) return ERROR_OUTOFMEMORY; if (!hdrs) return ERROR_OUTOFMEMORY;
request->headers = hdrs; request->headers = hdrs;
request->headers[count - 1].field = strdupW( header->field ); request->headers[count - 1].field = wcsdup( header->field );
request->headers[count - 1].value = strdupW( header->value ); request->headers[count - 1].value = wcsdup( header->value );
request->headers[count - 1].is_request = header->is_request; request->headers[count - 1].is_request = header->is_request;
request->num_headers = count; request->num_headers = count;
return ERROR_SUCCESS; return ERROR_SUCCESS;
...@@ -1562,7 +1562,7 @@ static DWORD open_connection( struct request *request ) ...@@ -1562,7 +1562,7 @@ static DWORD open_connection( struct request *request )
host->secure = is_secure; host->secure = is_secure;
host->port = port; host->port = port;
list_init( &host->connections ); list_init( &host->connections );
if ((host->hostname = strdupW( connect->servername ))) if ((host->hostname = wcsdup( connect->servername )))
{ {
list_add_head( &connection_pool, &host->entry ); list_add_head( &connection_pool, &host->entry );
} }
...@@ -2309,7 +2309,7 @@ BOOL WINAPI WinHttpSendRequest( HINTERNET hrequest, const WCHAR *headers, DWORD ...@@ -2309,7 +2309,7 @@ BOOL WINAPI WinHttpSendRequest( HINTERNET hrequest, const WCHAR *headers, DWORD
SetLastError( ERROR_OUTOFMEMORY ); SetLastError( ERROR_OUTOFMEMORY );
return FALSE; return FALSE;
} }
s->headers = strdupW( headers ); s->headers = wcsdup( headers );
s->headers_len = headers_len; s->headers_len = headers_len;
s->optional = optional; s->optional = optional;
s->optional_len = optional_len; s->optional_len = optional_len;
...@@ -2344,22 +2344,22 @@ static DWORD set_credentials( struct request *request, DWORD target, DWORD schem ...@@ -2344,22 +2344,22 @@ static DWORD set_credentials( struct request *request, DWORD target, DWORD schem
{ {
free( request->creds[TARGET_SERVER][scheme].username ); free( request->creds[TARGET_SERVER][scheme].username );
if (!username) request->creds[TARGET_SERVER][scheme].username = NULL; if (!username) request->creds[TARGET_SERVER][scheme].username = NULL;
else if (!(request->creds[TARGET_SERVER][scheme].username = strdupW( username ))) return ERROR_OUTOFMEMORY; else if (!(request->creds[TARGET_SERVER][scheme].username = wcsdup( username ))) return ERROR_OUTOFMEMORY;
free( request->creds[TARGET_SERVER][scheme].password ); free( request->creds[TARGET_SERVER][scheme].password );
if (!password) request->creds[TARGET_SERVER][scheme].password = NULL; if (!password) request->creds[TARGET_SERVER][scheme].password = NULL;
else if (!(request->creds[TARGET_SERVER][scheme].password = strdupW( password ))) return ERROR_OUTOFMEMORY; else if (!(request->creds[TARGET_SERVER][scheme].password = wcsdup( password ))) return ERROR_OUTOFMEMORY;
break; break;
} }
case WINHTTP_AUTH_TARGET_PROXY: case WINHTTP_AUTH_TARGET_PROXY:
{ {
free( request->creds[TARGET_PROXY][scheme].username ); free( request->creds[TARGET_PROXY][scheme].username );
if (!username) request->creds[TARGET_PROXY][scheme].username = NULL; if (!username) request->creds[TARGET_PROXY][scheme].username = NULL;
else if (!(request->creds[TARGET_PROXY][scheme].username = strdupW( username ))) return ERROR_OUTOFMEMORY; else if (!(request->creds[TARGET_PROXY][scheme].username = wcsdup( username ))) return ERROR_OUTOFMEMORY;
free( request->creds[TARGET_PROXY][scheme].password ); free( request->creds[TARGET_PROXY][scheme].password );
if (!password) request->creds[TARGET_PROXY][scheme].password = NULL; if (!password) request->creds[TARGET_PROXY][scheme].password = NULL;
else if (!(request->creds[TARGET_PROXY][scheme].password = strdupW( password ))) return ERROR_OUTOFMEMORY; else if (!(request->creds[TARGET_PROXY][scheme].password = wcsdup( password ))) return ERROR_OUTOFMEMORY;
break; break;
} }
default: default:
...@@ -2735,13 +2735,13 @@ static DWORD handle_redirect( struct request *request, DWORD status ) ...@@ -2735,13 +2735,13 @@ static DWORD handle_redirect( struct request *request, DWORD status )
memcpy( request->path, uc.lpszUrlPath, (len + 1) * sizeof(WCHAR) ); memcpy( request->path, uc.lpszUrlPath, (len + 1) * sizeof(WCHAR) );
request->path[len] = 0; request->path[len] = 0;
} }
else request->path = strdupW( L"/" ); else request->path = wcsdup( L"/" );
} }
if (status != HTTP_STATUS_REDIRECT_KEEP_VERB && !wcscmp( request->verb, L"POST" )) if (status != HTTP_STATUS_REDIRECT_KEEP_VERB && !wcscmp( request->verb, L"POST" ))
{ {
free( request->verb ); free( request->verb );
request->verb = strdupW( L"GET" ); request->verb = wcsdup( L"GET" );
request->optional = NULL; request->optional = NULL;
request->optional_len = 0; request->optional_len = 0;
} }
...@@ -4659,12 +4659,12 @@ static HRESULT WINAPI winhttp_request_SetProxy( ...@@ -4659,12 +4659,12 @@ static HRESULT WINAPI winhttp_request_SetProxy(
if (V_VT( &proxy_server ) == VT_BSTR) if (V_VT( &proxy_server ) == VT_BSTR)
{ {
free( request->proxy.lpszProxy ); free( request->proxy.lpszProxy );
request->proxy.lpszProxy = strdupW( V_BSTR( &proxy_server ) ); request->proxy.lpszProxy = wcsdup( V_BSTR( &proxy_server ) );
} }
if (V_VT( &bypass_list ) == VT_BSTR) if (V_VT( &bypass_list ) == VT_BSTR)
{ {
free( request->proxy.lpszProxyBypass ); free( request->proxy.lpszProxyBypass );
request->proxy.lpszProxyBypass = strdupW( V_BSTR( &bypass_list ) ); request->proxy.lpszProxyBypass = wcsdup( V_BSTR( &bypass_list ) );
} }
break; break;
...@@ -4796,7 +4796,7 @@ static HRESULT WINAPI winhttp_request_Open( ...@@ -4796,7 +4796,7 @@ static HRESULT WINAPI winhttp_request_Open(
memcpy( path, uc.lpszUrlPath, (uc.dwUrlPathLength + uc.dwExtraInfoLength) * sizeof(WCHAR) ); memcpy( path, uc.lpszUrlPath, (uc.dwUrlPathLength + uc.dwExtraInfoLength) * sizeof(WCHAR) );
path[uc.dwUrlPathLength + uc.dwExtraInfoLength] = 0; path[uc.dwUrlPathLength + uc.dwExtraInfoLength] = 0;
if (!(verb = strdupW( method ))) goto error; if (!(verb = wcsdup( method ))) goto error;
if (SUCCEEDED( VariantChangeType( &async, &async, 0, VT_BOOL )) && V_BOOL( &async )) request->async = TRUE; if (SUCCEEDED( VariantChangeType( &async, &async, 0, VT_BOOL )) && V_BOOL( &async )) request->async = TRUE;
else request->async = FALSE; else request->async = FALSE;
......
...@@ -322,20 +322,20 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWST ...@@ -322,20 +322,20 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWST
InitializeCriticalSection( &session->cs ); InitializeCriticalSection( &session->cs );
session->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": session.cs"); session->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": session.cs");
if (agent && !(session->agent = strdupW( agent ))) goto end; if (agent && !(session->agent = wcsdup( agent ))) goto end;
if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY) if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)
{ {
WINHTTP_PROXY_INFO info; WINHTTP_PROXY_INFO info;
WinHttpGetDefaultProxyConfiguration( &info ); WinHttpGetDefaultProxyConfiguration( &info );
session->access = info.dwAccessType; session->access = info.dwAccessType;
if (info.lpszProxy && !(session->proxy_server = strdupW( info.lpszProxy ))) if (info.lpszProxy && !(session->proxy_server = wcsdup( info.lpszProxy )))
{ {
GlobalFree( info.lpszProxy ); GlobalFree( info.lpszProxy );
GlobalFree( info.lpszProxyBypass ); GlobalFree( info.lpszProxyBypass );
goto end; goto end;
} }
if (info.lpszProxyBypass && !(session->proxy_bypass = strdupW( info.lpszProxyBypass ))) if (info.lpszProxyBypass && !(session->proxy_bypass = wcsdup( info.lpszProxyBypass )))
{ {
GlobalFree( info.lpszProxy ); GlobalFree( info.lpszProxy );
GlobalFree( info.lpszProxyBypass ); GlobalFree( info.lpszProxyBypass );
...@@ -345,8 +345,8 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWST ...@@ -345,8 +345,8 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWST
else if (access == WINHTTP_ACCESS_TYPE_NAMED_PROXY) else if (access == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
{ {
session->access = access; session->access = access;
if (proxy && !(session->proxy_server = strdupW( proxy ))) goto end; if (proxy && !(session->proxy_server = wcsdup( proxy ))) goto end;
if (bypass && !(session->proxy_bypass = strdupW( bypass ))) goto end; if (bypass && !(session->proxy_bypass = wcsdup( bypass ))) goto end;
} }
handle = alloc_handle( &session->hdr ); handle = alloc_handle( &session->hdr );
...@@ -556,7 +556,7 @@ BOOL set_server_for_hostname( struct connect *connect, const WCHAR *server, INTE ...@@ -556,7 +556,7 @@ BOOL set_server_for_hostname( struct connect *connect, const WCHAR *server, INTE
{ {
free( connect->servername ); free( connect->servername );
connect->resolved = FALSE; connect->resolved = FALSE;
if (!(connect->servername = strdupW( session->proxy_server ))) if (!(connect->servername = wcsdup( session->proxy_server )))
{ {
ret = FALSE; ret = FALSE;
goto end; goto end;
...@@ -569,7 +569,7 @@ BOOL set_server_for_hostname( struct connect *connect, const WCHAR *server, INTE ...@@ -569,7 +569,7 @@ BOOL set_server_for_hostname( struct connect *connect, const WCHAR *server, INTE
{ {
free( connect->servername ); free( connect->servername );
connect->resolved = FALSE; connect->resolved = FALSE;
if (!(connect->servername = strdupW( server ))) if (!(connect->servername = wcsdup( server )))
{ {
ret = FALSE; ret = FALSE;
goto end; goto end;
...@@ -624,7 +624,7 @@ HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, const WCHAR *server, INTERN ...@@ -624,7 +624,7 @@ HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, const WCHAR *server, INTERN
addref_object( &session->hdr ); addref_object( &session->hdr );
connect->session = session; connect->session = session;
if (!(connect->hostname = strdupW( server ))) goto end; if (!(connect->hostname = wcsdup( server ))) goto end;
connect->hostport = port; connect->hostport = port;
if (!set_server_for_hostname( connect, server, port )) goto end; if (!set_server_for_hostname( connect, server, port )) goto end;
...@@ -1273,11 +1273,11 @@ HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, const WCHAR *verb, cons ...@@ -1273,11 +1273,11 @@ HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, const WCHAR *verb, cons
request->websocket_set_send_buffer_size = request->websocket_send_buffer_size; request->websocket_set_send_buffer_size = request->websocket_send_buffer_size;
if (!verb || !verb[0]) verb = L"GET"; if (!verb || !verb[0]) verb = L"GET";
if (!(request->verb = strdupW( verb ))) goto end; if (!(request->verb = wcsdup( verb ))) goto end;
if (!(request->path = get_request_path( object ))) goto end; if (!(request->path = get_request_path( object ))) goto end;
if (!version || !version[0]) version = L"HTTP/1.1"; if (!version || !version[0]) version = L"HTTP/1.1";
if (!(request->version = strdupW( version ))) goto end; if (!(request->version = wcsdup( version ))) goto end;
if (!(add_accept_types_header( request, types ))) goto end; if (!(add_accept_types_header( request, types ))) goto end;
if ((hrequest = alloc_handle( &request->hdr ))) if ((hrequest = alloc_handle( &request->hdr )))
......
...@@ -398,16 +398,6 @@ DWORD process_header( struct request *, const WCHAR *, const WCHAR *, DWORD, BOO ...@@ -398,16 +398,6 @@ DWORD process_header( struct request *, const WCHAR *, const WCHAR *, DWORD, BOO
extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN; extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN;
void release_typelib( void ) DECLSPEC_HIDDEN; void release_typelib( void ) DECLSPEC_HIDDEN;
static inline WCHAR *strdupW( const WCHAR *src )
{
WCHAR *dst;
if (!src) return NULL;
dst = malloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) );
if (dst) lstrcpyW( dst, src );
return dst;
}
static inline WCHAR *strdupAW( const char *src ) static inline WCHAR *strdupAW( const char *src )
{ {
WCHAR *dst = NULL; WCHAR *dst = NULL;
......
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