Commit c94ccee1 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

webservices: Create a new HTTP request for each message.

parent 43deec95
...@@ -113,6 +113,8 @@ struct channel ...@@ -113,6 +113,8 @@ struct channel
HINTERNET session; HINTERNET session;
HINTERNET connect; HINTERNET connect;
HINTERNET request; HINTERNET request;
WCHAR *path;
DWORD flags;
} http; } http;
struct struct
{ {
...@@ -169,6 +171,9 @@ static void reset_channel( struct channel *channel ) ...@@ -169,6 +171,9 @@ static void reset_channel( struct channel *channel )
channel->u.http.connect = NULL; channel->u.http.connect = NULL;
WinHttpCloseHandle( channel->u.http.session ); WinHttpCloseHandle( channel->u.http.session );
channel->u.http.session = NULL; channel->u.http.session = NULL;
heap_free( channel->u.http.path );
channel->u.http.path = NULL;
channel->u.http.flags = 0;
break; break;
case WS_TCP_CHANNEL_BINDING: case WS_TCP_CHANNEL_BINDING:
...@@ -587,34 +592,29 @@ static HRESULT connect_channel_http( struct channel *channel ) ...@@ -587,34 +592,29 @@ static HRESULT connect_channel_http( struct channel *channel )
{ {
static const WCHAR agentW[] = static const WCHAR agentW[] =
{'M','S','-','W','e','b','S','e','r','v','i','c','e','s','/','1','.','0',0}; {'M','S','-','W','e','b','S','e','r','v','i','c','e','s','/','1','.','0',0};
static const WCHAR postW[] = HINTERNET ses = NULL, con = NULL;
{'P','O','S','T',0};
HINTERNET ses = NULL, con = NULL, req = NULL;
WCHAR *path;
URL_COMPONENTS uc; URL_COMPONENTS uc;
DWORD flags = 0;
HRESULT hr; HRESULT hr;
if (channel->u.http.request) return S_OK; if (channel->u.http.connect) return S_OK;
if ((hr = parse_http_url( channel->addr.url.chars, channel->addr.url.length, &uc )) != S_OK) return hr; if ((hr = parse_http_url( channel->addr.url.chars, channel->addr.url.length, &uc )) != S_OK) return hr;
if (!uc.dwExtraInfoLength) path = uc.lpszUrlPath; if (!(channel->u.http.path = heap_alloc( (uc.dwUrlPathLength + uc.dwExtraInfoLength + 1) * sizeof(WCHAR) )))
else if (!(path = heap_alloc( (uc.dwUrlPathLength + uc.dwExtraInfoLength + 1) * sizeof(WCHAR) )))
{ {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
goto done; goto done;
} }
else else
{ {
strcpyW( path, uc.lpszUrlPath ); strcpyW( channel->u.http.path, uc.lpszUrlPath );
strcatW( path, uc.lpszExtraInfo ); if (uc.dwExtraInfoLength) strcatW( channel->u.http.path, uc.lpszExtraInfo );
} }
switch (uc.nScheme) switch (uc.nScheme)
{ {
case INTERNET_SCHEME_HTTP: break; case INTERNET_SCHEME_HTTP: break;
case INTERNET_SCHEME_HTTPS: case INTERNET_SCHEME_HTTPS:
flags |= WINHTTP_FLAG_SECURE; channel->u.http.flags |= WINHTTP_FLAG_SECURE;
break; break;
default: default:
...@@ -632,29 +632,19 @@ static HRESULT connect_channel_http( struct channel *channel ) ...@@ -632,29 +632,19 @@ static HRESULT connect_channel_http( struct channel *channel )
hr = HRESULT_FROM_WIN32( GetLastError() ); hr = HRESULT_FROM_WIN32( GetLastError() );
goto done; goto done;
} }
if (!(req = WinHttpOpenRequest( con, postW, path, NULL, NULL, NULL, flags )))
{
hr = HRESULT_FROM_WIN32( GetLastError() );
goto done;
}
if ((hr = message_insert_http_headers( channel->msg, req )) != S_OK) goto done;
channel->u.http.session = ses; channel->u.http.session = ses;
channel->u.http.connect = con; channel->u.http.connect = con;
channel->u.http.request = req;
done: done:
if (hr != S_OK) if (hr != S_OK)
{ {
WinHttpCloseHandle( req );
WinHttpCloseHandle( con ); WinHttpCloseHandle( con );
WinHttpCloseHandle( ses ); WinHttpCloseHandle( ses );
} }
heap_free( uc.lpszHostName ); heap_free( uc.lpszHostName );
heap_free( uc.lpszUrlPath ); heap_free( uc.lpszUrlPath );
heap_free( uc.lpszExtraInfo ); heap_free( uc.lpszExtraInfo );
if (path != uc.lpszUrlPath) heap_free( path );
return hr; return hr;
} }
...@@ -762,7 +752,7 @@ static HRESULT write_message( WS_MESSAGE *handle, WS_XML_WRITER *writer, const W ...@@ -762,7 +752,7 @@ static HRESULT write_message( WS_MESSAGE *handle, WS_XML_WRITER *writer, const W
return WsWriteEnvelopeEnd( handle, NULL ); return WsWriteEnvelopeEnd( handle, NULL );
} }
static HRESULT send_message_http( HANDLE request, BYTE *data, ULONG len ) static HRESULT send_message_http( HINTERNET request, BYTE *data, ULONG len )
{ {
if (!WinHttpSendRequest( request, NULL, 0, data, len, len, 0 )) if (!WinHttpSendRequest( request, NULL, 0, data, len, len, 0 ))
return HRESULT_FROM_WIN32( GetLastError() ); return HRESULT_FROM_WIN32( GetLastError() );
...@@ -984,6 +974,14 @@ static HRESULT send_sized_envelope( struct channel *channel, BYTE *data, ULONG l ...@@ -984,6 +974,14 @@ static HRESULT send_sized_envelope( struct channel *channel, BYTE *data, ULONG l
return send_bytes( channel->u.tcp.socket, data, len ); return send_bytes( channel->u.tcp.socket, data, len );
} }
static HRESULT open_http_request( struct channel *channel, HINTERNET *req )
{
static const WCHAR postW[] = {'P','O','S','T',0};
if ((*req = WinHttpOpenRequest( channel->u.http.connect, postW, channel->u.http.path,
NULL, NULL, NULL, channel->u.http.flags ))) return S_OK;
return HRESULT_FROM_WIN32( GetLastError() );
}
static HRESULT send_message( struct channel *channel, WS_MESSAGE *msg ) static HRESULT send_message( struct channel *channel, WS_MESSAGE *msg )
{ {
WS_XML_WRITER *writer; WS_XML_WRITER *writer;
...@@ -999,6 +997,13 @@ static HRESULT send_message( struct channel *channel, WS_MESSAGE *msg ) ...@@ -999,6 +997,13 @@ static HRESULT send_message( struct channel *channel, WS_MESSAGE *msg )
switch (channel->binding) switch (channel->binding)
{ {
case WS_HTTP_CHANNEL_BINDING: case WS_HTTP_CHANNEL_BINDING:
if (channel->u.http.request)
{
WinHttpCloseHandle( channel->u.http.request );
channel->u.http.request = NULL;
}
if ((hr = open_http_request( channel, &channel->u.http.request )) != S_OK) return hr;
if ((hr = message_insert_http_headers( msg, channel->u.http.request )) != S_OK) return hr;
return send_message_http( channel->u.http.request, buf.bytes, buf.length ); return send_message_http( channel->u.http.request, buf.bytes, buf.length );
case WS_TCP_CHANNEL_BINDING: case WS_TCP_CHANNEL_BINDING:
......
...@@ -1610,9 +1610,13 @@ HRESULT WINAPI WsRemoveCustomHeader( WS_MESSAGE *handle, const WS_XML_STRING *na ...@@ -1610,9 +1610,13 @@ HRESULT WINAPI WsRemoveCustomHeader( WS_MESSAGE *handle, const WS_XML_STRING *na
static WCHAR *build_http_header( const WCHAR *name, const WCHAR *value, ULONG *ret_len ) static WCHAR *build_http_header( const WCHAR *name, const WCHAR *value, ULONG *ret_len )
{ {
static const WCHAR fmtW[] = {'%','s',':',' ','%','s',0}; int len_name = strlenW( name ), len_value = strlenW( value );
WCHAR *ret = heap_alloc( (strlenW(name) + strlenW(value) + 3) * sizeof(WCHAR) ); WCHAR *ret = heap_alloc( (len_name + len_value) * sizeof(WCHAR) );
if (ret) *ret_len = sprintfW( ret, fmtW, name, value );
if (!ret) return NULL;
memcpy( ret, name, len_name * sizeof(WCHAR) );
memcpy( ret + len_name, value, len_value * sizeof(WCHAR) );
*ret_len = len_name + len_value;
return ret; return ret;
} }
...@@ -1625,7 +1629,7 @@ static inline HRESULT insert_http_header( HINTERNET req, const WCHAR *header, UL ...@@ -1625,7 +1629,7 @@ static inline HRESULT insert_http_header( HINTERNET req, const WCHAR *header, UL
HRESULT message_insert_http_headers( WS_MESSAGE *handle, HINTERNET req ) HRESULT message_insert_http_headers( WS_MESSAGE *handle, HINTERNET req )
{ {
static const WCHAR contenttypeW[] = static const WCHAR contenttypeW[] =
{'C','o','n','t','e','n','t','-','T','y','p','e',0}; {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ',0};
static const WCHAR soapxmlW[] = static const WCHAR soapxmlW[] =
{'a','p','p','l','i','c','a','t','i','o','n','/','s','o','a','p','+','x','m','l',0}; {'a','p','p','l','i','c','a','t','i','o','n','/','s','o','a','p','+','x','m','l',0};
static const WCHAR textxmlW[] = static const WCHAR textxmlW[] =
...@@ -1675,7 +1679,7 @@ HRESULT message_insert_http_headers( WS_MESSAGE *handle, HINTERNET req ) ...@@ -1675,7 +1679,7 @@ HRESULT message_insert_http_headers( WS_MESSAGE *handle, HINTERNET req )
{ {
case WS_ENVELOPE_VERSION_SOAP_1_1: case WS_ENVELOPE_VERSION_SOAP_1_1:
{ {
static const WCHAR soapactionW[] = {'S','O','A','P','A','c','t','i','o','n',0}; static const WCHAR soapactionW[] = {'S','O','A','P','A','c','t','i','o','n',':',' ',0};
if (!(len = msg->action.length)) break; if (!(len = msg->action.length)) break;
......
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