From 29d4c50391cdd5a129d84cc41838bd8714128aab Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 5 Apr 2017 11:40:22 +0200 Subject: [PATCH] webservices: Implement WsResetChannel. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/webservices/channel.c | 65 ++++++++++++++++++++++++------- dlls/webservices/tests/channel.c | 60 ++++++++++++++++++++++++++++ dlls/webservices/webservices.spec | 2 +- 3 files changed, 111 insertions(+), 16 deletions(-) diff --git a/dlls/webservices/channel.c b/dlls/webservices/channel.c index d44fcc0eb29..d82aa67a0e0 100644 --- a/dlls/webservices/channel.c +++ b/dlls/webservices/channel.c @@ -121,14 +121,27 @@ static struct channel *alloc_channel(void) return ret; } +static void reset_channel( struct channel *channel ) +{ + channel->state = WS_CHANNEL_STATE_CREATED; + heap_free( channel->addr.url.chars ); + channel->addr.url.chars = NULL; + channel->addr.url.length = 0; + + WinHttpCloseHandle( channel->http_request ); + channel->http_request = NULL; + WinHttpCloseHandle( channel->http_connect ); + channel->http_connect = NULL; + WinHttpCloseHandle( channel->http_session ); + channel->http_session = NULL; +} + static void free_channel( struct channel *channel ) { + reset_channel( channel ); + WsFreeWriter( channel->writer ); WsFreeReader( channel->reader ); - WinHttpCloseHandle( channel->http_request ); - WinHttpCloseHandle( channel->http_connect ); - WinHttpCloseHandle( channel->http_session ); - heap_free( channel->addr.url.chars ); channel->cs.DebugInfo->Spare[0] = 0; DeleteCriticalSection( &channel->cs ); @@ -225,6 +238,38 @@ void WINAPI WsFreeChannel( WS_CHANNEL *handle ) free_channel( channel ); } +/************************************************************************** + * WsResetChannel [webservices.@] + */ +HRESULT WINAPI WsResetChannel( WS_CHANNEL *handle, WS_ERROR *error ) +{ + struct channel *channel = (struct channel *)handle; + + TRACE( "%p %p\n", handle, error ); + if (error) FIXME( "ignoring error parameter\n" ); + + if (!channel) return E_INVALIDARG; + + EnterCriticalSection( &channel->cs ); + + if (channel->magic != CHANNEL_MAGIC) + { + LeaveCriticalSection( &channel->cs ); + return E_INVALIDARG; + } + + if (channel->state != WS_CHANNEL_STATE_CREATED && channel->state != WS_CHANNEL_STATE_CLOSED) + { + LeaveCriticalSection( &channel->cs ); + return WS_E_INVALID_OPERATION; + } + + reset_channel( channel ); + + LeaveCriticalSection( &channel->cs ); + return S_OK; +} + /************************************************************************** * WsGetChannelProperty [webservices.@] */ @@ -343,17 +388,7 @@ HRESULT WINAPI WsOpenChannel( WS_CHANNEL *handle, const WS_ENDPOINT_ADDRESS *end static HRESULT close_channel( struct channel *channel ) { - WinHttpCloseHandle( channel->http_request ); - channel->http_request = NULL; - WinHttpCloseHandle( channel->http_connect ); - channel->http_connect = NULL; - WinHttpCloseHandle( channel->http_session ); - channel->http_session = NULL; - - heap_free( channel->addr.url.chars ); - channel->addr.url.chars = NULL; - channel->addr.url.length = 0; - + reset_channel( channel ); channel->state = WS_CHANNEL_STATE_CLOSED; return S_OK; } diff --git a/dlls/webservices/tests/channel.c b/dlls/webservices/tests/channel.c index f053c15dee2..74cef3b36a0 100644 --- a/dlls/webservices/tests/channel.c +++ b/dlls/webservices/tests/channel.c @@ -103,8 +103,68 @@ static void test_WsOpenChannel(void) WsFreeChannel( channel ); } +static void test_WsResetChannel(void) +{ + WCHAR url[] = {'h','t','t','p',':','/','/','l','o','c','a','l','h','o','s','t'}; + HRESULT hr; + WS_CHANNEL *channel; + WS_CHANNEL_STATE state; + WS_CHANNEL_TYPE type; + WS_ENDPOINT_ADDRESS addr; + ULONG size, timeout; + + hr = WsCreateChannel( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, NULL, 0, NULL, &channel, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsResetChannel( channel, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + timeout = 5000; + size = sizeof(timeout); + hr = WsSetChannelProperty( channel, WS_CHANNEL_PROPERTY_RESOLVE_TIMEOUT, &timeout, size, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + addr.url.length = sizeof(url)/sizeof(url[0]); + addr.url.chars = url; + addr.headers = NULL; + addr.extensions = NULL; + addr.identity = NULL; + hr = WsOpenChannel( channel, &addr, NULL, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsResetChannel( channel, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = WsCloseChannel( channel, NULL, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsResetChannel( channel, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + state = 0xdeadbeef; + size = sizeof(state); + hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_STATE, &state, size, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( state == WS_CHANNEL_STATE_CREATED, "got %u\n", state ); + + type = 0xdeadbeef; + size = sizeof(type); + hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_CHANNEL_TYPE, &type, size, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( type == WS_CHANNEL_TYPE_REQUEST, "got %u\n", type ); + + timeout = 0xdeadbeef; + size = sizeof(timeout); + hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_RESOLVE_TIMEOUT, &timeout, size, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( timeout == 5000, "got %u\n", timeout ); + + WsFreeChannel( channel ); +} + START_TEST(channel) { test_WsCreateChannel(); test_WsOpenChannel(); + test_WsResetChannel(); } diff --git a/dlls/webservices/webservices.spec b/dlls/webservices/webservices.spec index fd4a831c944..0a3057d2bb5 100644 --- a/dlls/webservices/webservices.spec +++ b/dlls/webservices/webservices.spec @@ -133,7 +133,7 @@ @ stub WsRemoveNode @ stub WsRequestReply @ stub WsRequestSecurityToken -@ stub WsResetChannel +@ stdcall WsResetChannel(ptr ptr) @ stdcall WsResetError(ptr) @ stdcall WsResetHeap(ptr ptr) @ stub WsResetListener