mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-14 11:01:29 +00:00
winhttp: Simplify secure_proxy_connect.
Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
60a8bb68ec
commit
dffb4705c5
|
@ -1337,122 +1337,73 @@ static BOOL do_authorization( request_t *request, DWORD target, DWORD scheme_fla
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static LPWSTR concatenate_string_list( LPCWSTR *list, int len )
|
static WCHAR *build_proxy_connect_string( request_t *request )
|
||||||
{
|
{
|
||||||
LPCWSTR *t;
|
static const WCHAR fmtW[] = {'%','s',':','%','u',0};
|
||||||
LPWSTR str;
|
static const WCHAR connectW[] = {'C','O','N','N','E','C','T', 0};
|
||||||
|
static const WCHAR spaceW[] = {' ',0}, crlfW[] = {'\r','\n',0}, colonW[] = {':',' ',0};
|
||||||
|
static const WCHAR twocrlfW[] = {'\r','\n','\r','\n',0};
|
||||||
|
WCHAR *ret, *host;
|
||||||
|
unsigned int i;
|
||||||
|
int len;
|
||||||
|
|
||||||
for( t = list; *t ; t++ )
|
if (!(host = heap_alloc( (strlenW( request->connect->hostname ) + 7) * sizeof(WCHAR) ))) return NULL;
|
||||||
len += strlenW( *t );
|
len = sprintfW( host, fmtW, request->connect->hostname, request->connect->hostport );
|
||||||
len++;
|
|
||||||
|
|
||||||
str = heap_alloc( len * sizeof(WCHAR) );
|
len += ARRAY_SIZE(connectW);
|
||||||
if (!str) return NULL;
|
len += ARRAY_SIZE(http1_1);
|
||||||
*str = 0;
|
|
||||||
|
|
||||||
for( t = list; *t ; t++ )
|
|
||||||
strcatW( str, *t );
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
static LPWSTR build_header_request_string( request_t *request, LPCWSTR verb,
|
|
||||||
LPCWSTR path, LPCWSTR version )
|
|
||||||
{
|
|
||||||
static const WCHAR crlf[] = {'\r','\n',0};
|
|
||||||
static const WCHAR space[] = { ' ',0 };
|
|
||||||
static const WCHAR colon[] = { ':',' ',0 };
|
|
||||||
static const WCHAR twocrlf[] = {'\r','\n','\r','\n', 0};
|
|
||||||
LPWSTR requestString;
|
|
||||||
DWORD len, n;
|
|
||||||
LPCWSTR *req;
|
|
||||||
UINT i;
|
|
||||||
LPWSTR p;
|
|
||||||
|
|
||||||
/* allocate space for an array of all the string pointers to be added */
|
|
||||||
len = (request->num_headers) * 4 + 10;
|
|
||||||
req = heap_alloc( len * sizeof(LPCWSTR) );
|
|
||||||
if (!req) return NULL;
|
|
||||||
|
|
||||||
/* add the verb, path and HTTP version string */
|
|
||||||
n = 0;
|
|
||||||
req[n++] = verb;
|
|
||||||
req[n++] = space;
|
|
||||||
req[n++] = path;
|
|
||||||
req[n++] = space;
|
|
||||||
req[n++] = version;
|
|
||||||
|
|
||||||
/* Append custom request headers */
|
|
||||||
for (i = 0; i < request->num_headers; i++)
|
for (i = 0; i < request->num_headers; i++)
|
||||||
{
|
{
|
||||||
if (request->headers[i].is_request)
|
if (request->headers[i].is_request)
|
||||||
{
|
len += strlenW( request->headers[i].field ) + strlenW( request->headers[i].value ) + 4; /* '\r\n: ' */
|
||||||
req[n++] = crlf;
|
}
|
||||||
req[n++] = request->headers[i].field;
|
len += 4; /* '\r\n\r\n' */
|
||||||
req[n++] = colon;
|
|
||||||
req[n++] = request->headers[i].value;
|
|
||||||
|
|
||||||
TRACE("Adding custom header %s (%s)\n",
|
if ((ret = heap_alloc( (len + 1) * sizeof(WCHAR) )))
|
||||||
debugstr_w(request->headers[i].field),
|
{
|
||||||
debugstr_w(request->headers[i].value));
|
strcpyW( ret, connectW );
|
||||||
|
strcatW( ret, spaceW );
|
||||||
|
strcatW( ret, host );
|
||||||
|
strcatW( ret, spaceW );
|
||||||
|
strcatW( ret, http1_1 );
|
||||||
|
|
||||||
|
for (i = 0; i < request->num_headers; i++)
|
||||||
|
{
|
||||||
|
if (request->headers[i].is_request)
|
||||||
|
{
|
||||||
|
strcatW( ret, crlfW );
|
||||||
|
strcatW( ret, request->headers[i].field );
|
||||||
|
strcatW( ret, colonW );
|
||||||
|
strcatW( ret, request->headers[i].value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
strcatW( ret, twocrlfW );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( n >= len )
|
heap_free( host );
|
||||||
ERR("oops. buffer overrun\n");
|
return ret;
|
||||||
|
|
||||||
req[n] = NULL;
|
|
||||||
requestString = concatenate_string_list( req, 4 );
|
|
||||||
heap_free( req );
|
|
||||||
if (!requestString) return NULL;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set (header) termination string for request
|
|
||||||
* Make sure there are exactly two new lines at the end of the request
|
|
||||||
*/
|
|
||||||
p = &requestString[strlenW(requestString)-1];
|
|
||||||
while ( (*p == '\n') || (*p == '\r') )
|
|
||||||
p--;
|
|
||||||
strcpyW( p+1, twocrlf );
|
|
||||||
|
|
||||||
return requestString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL read_reply( request_t *request );
|
static BOOL read_reply( request_t *request );
|
||||||
|
|
||||||
static BOOL secure_proxy_connect( request_t *request )
|
static BOOL secure_proxy_connect( request_t *request )
|
||||||
{
|
{
|
||||||
static const WCHAR verbConnect[] = {'C','O','N','N','E','C','T',0};
|
WCHAR *str;
|
||||||
static const WCHAR fmt[] = {'%','s',':','%','u',0};
|
char *strA;
|
||||||
BOOL ret = FALSE;
|
int len, bytes_sent;
|
||||||
LPWSTR path;
|
BOOL ret;
|
||||||
connect_t *connect = request->connect;
|
|
||||||
|
|
||||||
path = heap_alloc( (strlenW( connect->hostname ) + 13) * sizeof(WCHAR) );
|
if (!(str = build_proxy_connect_string( request ))) return FALSE;
|
||||||
if (path)
|
strA = strdupWA( str );
|
||||||
{
|
heap_free( str );
|
||||||
LPWSTR requestString;
|
if (!strA) return FALSE;
|
||||||
|
|
||||||
sprintfW( path, fmt, connect->hostname, connect->hostport );
|
len = strlen( strA );
|
||||||
requestString = build_header_request_string( request, verbConnect,
|
ret = netconn_send( request->netconn, strA, len, &bytes_sent );
|
||||||
path, http1_1 );
|
heap_free( strA );
|
||||||
heap_free( path );
|
if (ret) ret = read_reply( request );
|
||||||
if (requestString)
|
|
||||||
{
|
|
||||||
LPSTR req_ascii = strdupWA( requestString );
|
|
||||||
|
|
||||||
heap_free( requestString );
|
|
||||||
if (req_ascii)
|
|
||||||
{
|
|
||||||
int len = strlen( req_ascii ), bytes_sent;
|
|
||||||
|
|
||||||
ret = netconn_send( request->netconn, req_ascii, len, &bytes_sent );
|
|
||||||
heap_free( req_ascii );
|
|
||||||
if (ret)
|
|
||||||
ret = read_reply( request );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue