webservices: Implement WsCreateChannel and WsFreeChannel.
[wine.git] / dlls / webservices / channel.c
blobc8a920dd1d9f1824226f24f0da007864be8b018f
1 /*
2 * Copyright 2016 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "webservices.h"
26 #include "wine/debug.h"
27 #include "wine/list.h"
28 #include "webservices_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(webservices);
32 static const struct
34 ULONG size;
35 BOOL readonly;
37 channel_props[] =
39 { sizeof(ULONG), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE */
40 { sizeof(UINT64), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_STREAMED_MESSAGE_SIZE */
41 { sizeof(ULONG), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_STREAMED_START_SIZE */
42 { sizeof(ULONG), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_STREAMED_FLUSH_SIZE */
43 { sizeof(WS_ENCODING), FALSE }, /* WS_CHANNEL_PROPERTY_ENCODING */
44 { sizeof(WS_ENVELOPE_VERSION), FALSE }, /* WS_CHANNEL_PROPERTY_ENVELOPE_VERSION */
45 { sizeof(WS_ADDRESSING_VERSION), FALSE }, /* WS_CHANNEL_PROPERTY_ADDRESSING_VERSION */
46 { sizeof(ULONG), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_SESSION_DICTIONARY_SIZE */
47 { sizeof(WS_CHANNEL_STATE), TRUE }, /* WS_CHANNEL_PROPERTY_STATE */
50 static struct channel *alloc_channel(void)
52 static const ULONG count = sizeof(channel_props)/sizeof(channel_props[0]);
53 struct channel *ret;
54 ULONG i, size = sizeof(*ret) + count * sizeof(WS_CHANNEL_PROPERTY);
55 char *ptr;
57 for (i = 0; i < count; i++) size += channel_props[i].size;
58 if (!(ret = heap_alloc_zero( size ))) return NULL;
60 ptr = (char *)&ret->prop[count];
61 for (i = 0; i < count; i++)
63 ret->prop[i].value = ptr;
64 ret->prop[i].valueSize = channel_props[i].size;
65 ptr += ret->prop[i].valueSize;
67 ret->prop_count = count;
68 return ret;
71 static HRESULT set_channel_prop( struct channel *channel, WS_CHANNEL_PROPERTY_ID id, const void *value,
72 ULONG size )
74 if (id >= channel->prop_count || size != channel_props[id].size || channel_props[id].readonly)
75 return E_INVALIDARG;
77 memcpy( channel->prop[id].value, value, size );
78 return S_OK;
81 void free_channel( struct channel *channel )
83 heap_free( channel );
86 HRESULT create_channel( WS_CHANNEL_TYPE type, WS_CHANNEL_BINDING binding,
87 const WS_CHANNEL_PROPERTY *properties, ULONG count, struct channel **ret )
89 struct channel *channel;
90 ULONG i, msg_size = 65536;
91 HRESULT hr;
93 if (!(channel = alloc_channel())) return E_OUTOFMEMORY;
95 set_channel_prop( channel, WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE, &msg_size, sizeof(msg_size) );
97 for (i = 0; i < count; i++)
99 hr = set_channel_prop( channel, properties[i].id, properties[i].value, properties[i].valueSize );
100 if (hr != S_OK)
102 free_channel( channel );
103 return hr;
107 channel->type = type;
108 channel->binding = binding;
110 *ret = channel;
111 return S_OK;
114 /**************************************************************************
115 * WsCreateChannel [webservices.@]
117 HRESULT WINAPI WsCreateChannel( WS_CHANNEL_TYPE type, WS_CHANNEL_BINDING binding,
118 const WS_CHANNEL_PROPERTY *properties, ULONG count,
119 const WS_SECURITY_DESCRIPTION *desc, WS_CHANNEL **handle,
120 WS_ERROR *error )
122 struct channel *channel;
123 HRESULT hr;
125 TRACE( "%u %u %p %u %p %p %p\n", type, binding, properties, count, desc, handle, error );
126 if (error) FIXME( "ignoring error parameter\n" );
127 if (desc) FIXME( "ignoring security description\n" );
129 if (!handle) return E_INVALIDARG;
131 if (type != WS_CHANNEL_TYPE_REQUEST)
133 FIXME( "channel type %u not implemented\n", type );
134 return E_NOTIMPL;
136 if (binding != WS_HTTP_CHANNEL_BINDING)
138 FIXME( "channel binding %u not implemented\n", binding );
139 return E_NOTIMPL;
142 if ((hr = create_channel( type, binding, properties, count, &channel )) != S_OK)
143 return hr;
145 *handle = (WS_CHANNEL *)channel;
146 return S_OK;
149 /**************************************************************************
150 * WsFreeChannel [webservices.@]
152 void WINAPI WsFreeChannel( WS_CHANNEL *handle )
154 struct channel *channel = (struct channel *)handle;
156 TRACE( "%p\n", handle );
157 free_channel( channel );