[5/7] webservices: Add support for setting the channel encoding.

Hans Leidekker hans at codeweavers.com
Mon Jul 10 04:02:32 CDT 2017


Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
 dlls/webservices/channel.c       | 49 ++++++++++++++++++++++++++++++----------
 dlls/webservices/tests/channel.c | 45 ++++++++++++++++++++++++++++--------
 2 files changed, 73 insertions(+), 21 deletions(-)

diff --git a/dlls/webservices/channel.c b/dlls/webservices/channel.c
index 1fa96a9..6326d60 100644
--- a/dlls/webservices/channel.c
+++ b/dlls/webservices/channel.c
@@ -37,7 +37,7 @@ static const struct prop_desc channel_props[] =
     { sizeof(UINT64), FALSE },                              /* WS_CHANNEL_PROPERTY_MAX_STREAMED_MESSAGE_SIZE */
     { sizeof(ULONG), FALSE },                               /* WS_CHANNEL_PROPERTY_MAX_STREAMED_START_SIZE */
     { sizeof(ULONG), FALSE },                               /* WS_CHANNEL_PROPERTY_MAX_STREAMED_FLUSH_SIZE */
-    { sizeof(WS_ENCODING), FALSE },                         /* WS_CHANNEL_PROPERTY_ENCODING */
+    { sizeof(WS_ENCODING), TRUE },                          /* WS_CHANNEL_PROPERTY_ENCODING */
     { sizeof(WS_ENVELOPE_VERSION), FALSE },                 /* WS_CHANNEL_PROPERTY_ENVELOPE_VERSION */
     { sizeof(WS_ADDRESSING_VERSION), FALSE },               /* WS_CHANNEL_PROPERTY_ADDRESSING_VERSION */
     { sizeof(ULONG), FALSE },                               /* WS_CHANNEL_PROPERTY_MAX_SESSION_DICTIONARY_SIZE */
@@ -96,6 +96,7 @@ struct channel
     WS_XML_WRITER          *writer;
     WS_XML_READER          *reader;
     WS_MESSAGE             *msg;
+    WS_ENCODING             encoding;
     union
     {
         struct
@@ -199,33 +200,52 @@ static HRESULT create_channel( WS_CHANNEL_TYPE type, WS_CHANNEL_BINDING binding,
     prop_set( channel->prop, channel->prop_count, WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE,
               &msg_size, sizeof(msg_size) );
 
-    for (i = 0; i < count; i++)
-    {
-        hr = prop_set( channel->prop, channel->prop_count, properties[i].id, properties[i].value,
-                       properties[i].valueSize );
-        if (hr != S_OK)
-        {
-            free_channel( channel );
-            return hr;
-        }
-    }
-
     channel->type    = type;
     channel->binding = binding;
 
     switch (channel->binding)
     {
+    case WS_HTTP_CHANNEL_BINDING:
+        channel->encoding = WS_ENCODING_XML_UTF8;
+        break;
+
     case WS_TCP_CHANNEL_BINDING:
         channel->u.tcp.socket = -1;
+        channel->encoding     = WS_ENCODING_XML_BINARY_SESSION_1;
         break;
 
     case WS_UDP_CHANNEL_BINDING:
         channel->u.udp.socket = -1;
+        channel->encoding     = WS_ENCODING_XML_UTF8;
         break;
 
     default: break;
     }
 
+    for (i = 0; i < count; i++)
+    {
+        switch (properties[i].id)
+        {
+        case WS_CHANNEL_PROPERTY_ENCODING:
+            if (!properties[i].value || properties[i].valueSize != sizeof(channel->encoding))
+            {
+                free_channel( channel );
+                return E_INVALIDARG;
+            }
+            channel->encoding = *(WS_ENCODING *)properties[i].value;
+            break;
+
+        default:
+            if ((hr = prop_set( channel->prop, channel->prop_count, properties[i].id, properties[i].value,
+                                properties[i].valueSize )) != S_OK)
+            {
+                free_channel( channel );
+                return hr;
+            }
+            break;
+        }
+    }
+
     *ret = channel;
     return S_OK;
 }
@@ -380,6 +400,11 @@ HRESULT WINAPI WsGetChannelProperty( WS_CHANNEL *handle, WS_CHANNEL_PROPERTY_ID
         else *(WS_CHANNEL_TYPE *)buf = channel->type;
         break;
 
+    case WS_CHANNEL_PROPERTY_ENCODING:
+        if (!buf || size != sizeof(channel->encoding)) hr = E_INVALIDARG;
+        else *(WS_ENCODING *)buf = channel->encoding;
+        break;
+
     default:
         hr = prop_get( channel->prop, channel->prop_count, id, buf, size );
     }
diff --git a/dlls/webservices/tests/channel.c b/dlls/webservices/tests/channel.c
index 16f3ccf..ceefad9 100644
--- a/dlls/webservices/tests/channel.c
+++ b/dlls/webservices/tests/channel.c
@@ -26,7 +26,9 @@ static void test_WsCreateChannel(void)
     HRESULT hr;
     WS_CHANNEL *channel;
     WS_CHANNEL_STATE state;
-    ULONG size, value;
+    WS_CHANNEL_PROPERTY prop;
+    WS_ENCODING encoding;
+    ULONG size;
 
     hr = WsCreateChannel( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, NULL, 0, NULL, NULL, NULL );
     ok( hr == E_INVALIDARG, "got %08x\n", hr );
@@ -36,24 +38,49 @@ static void test_WsCreateChannel(void)
     ok( hr == S_OK, "got %08x\n", hr );
     ok( channel != NULL, "channel not set\n" );
 
-    value = 0xdeadbeef;
-    size = sizeof(value);
-    hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE, &value, size, NULL );
+    size = 0xdeadbeef;
+    hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE, &size, sizeof(size), NULL );
     ok( hr == S_OK, "got %08x\n", hr );
-    ok( value == 65536, "got %u\n", value );
+    ok( size == 65536, "got %u\n", size );
+
+    encoding = 0xdeadbeef;
+    hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_ENCODING, &encoding, sizeof(encoding), NULL );
+    ok( hr == S_OK, "got %08x\n", hr );
+    ok( encoding == WS_ENCODING_XML_UTF8, "got %u\n", encoding );
 
     /* read-only property */
     state = 0xdeadbeef;
-    size = sizeof(state);
-    hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_STATE, &state, size, NULL );
+    hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_STATE, &state, sizeof(state), NULL );
     ok( hr == S_OK, "got %08x\n", hr );
     ok( state == WS_CHANNEL_STATE_CREATED, "got %u\n", state );
 
     state = WS_CHANNEL_STATE_CREATED;
-    size = sizeof(state);
-    hr = WsSetChannelProperty( channel, WS_CHANNEL_PROPERTY_STATE, &state, size, NULL );
+    hr = WsSetChannelProperty( channel, WS_CHANNEL_PROPERTY_STATE, &state, sizeof(state), NULL );
+    ok( hr == E_INVALIDARG, "got %08x\n", hr );
+
+    encoding = WS_ENCODING_XML_UTF8;
+    hr = WsSetChannelProperty( channel, WS_CHANNEL_PROPERTY_ENCODING, &encoding, sizeof(encoding), NULL );
     ok( hr == E_INVALIDARG, "got %08x\n", hr );
+    WsFreeChannel( channel );
 
+    encoding = WS_ENCODING_XML_UTF16LE;
+    prop.id        = WS_CHANNEL_PROPERTY_ENCODING;
+    prop.value     = &encoding;
+    prop.valueSize = sizeof(encoding);
+    hr = WsCreateChannel( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, &prop, 1, NULL, &channel, NULL );
+    ok( hr == S_OK, "got %08x\n", hr );
+    encoding = 0xdeadbeef;
+    hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_ENCODING, &encoding, sizeof(encoding), NULL );
+    ok( hr == S_OK, "got %08x\n", hr );
+    ok( encoding == WS_ENCODING_XML_UTF16LE, "got %u\n", encoding );
+    WsFreeChannel( channel );
+
+    hr = WsCreateChannel( WS_CHANNEL_TYPE_DUPLEX_SESSION, WS_TCP_CHANNEL_BINDING, NULL, 0, NULL, &channel, NULL );
+    ok( hr == S_OK, "got %08x\n", hr );
+    encoding = 0xdeadbeef;
+    hr = WsGetChannelProperty( channel, WS_CHANNEL_PROPERTY_ENCODING, &encoding, sizeof(encoding), NULL );
+    ok( hr == S_OK, "got %08x\n", hr );
+    ok( encoding == WS_ENCODING_XML_BINARY_SESSION_1, "got %u\n", encoding );
     WsFreeChannel( channel );
 }
 
-- 
2.1.4




More information about the wine-patches mailing list