strmbase: Avoid a COM object to interface cast.
[wine.git] / dlls / webservices / channel.c
blob9081d955e84dd3b926576722b1c18e54ced5767d
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 prop_desc channel_props[] =
34 { sizeof(ULONG), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE */
35 { sizeof(UINT64), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_STREAMED_MESSAGE_SIZE */
36 { sizeof(ULONG), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_STREAMED_START_SIZE */
37 { sizeof(ULONG), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_STREAMED_FLUSH_SIZE */
38 { sizeof(WS_ENCODING), FALSE }, /* WS_CHANNEL_PROPERTY_ENCODING */
39 { sizeof(WS_ENVELOPE_VERSION), FALSE }, /* WS_CHANNEL_PROPERTY_ENVELOPE_VERSION */
40 { sizeof(WS_ADDRESSING_VERSION), FALSE }, /* WS_CHANNEL_PROPERTY_ADDRESSING_VERSION */
41 { sizeof(ULONG), FALSE }, /* WS_CHANNEL_PROPERTY_MAX_SESSION_DICTIONARY_SIZE */
42 { sizeof(WS_CHANNEL_STATE), TRUE }, /* WS_CHANNEL_PROPERTY_STATE */
45 static struct channel *alloc_channel(void)
47 static const ULONG count = sizeof(channel_props)/sizeof(channel_props[0]);
48 struct channel *ret;
49 ULONG size = sizeof(*ret) + prop_size( channel_props, count );
51 if (!(ret = heap_alloc_zero( size ))) return NULL;
52 prop_init( channel_props, count, ret->prop, &ret[1] );
53 ret->prop_count = count;
54 return ret;
57 void free_channel( struct channel *channel )
59 heap_free( channel );
62 HRESULT create_channel( WS_CHANNEL_TYPE type, WS_CHANNEL_BINDING binding,
63 const WS_CHANNEL_PROPERTY *properties, ULONG count, struct channel **ret )
65 struct channel *channel;
66 ULONG i, msg_size = 65536;
67 HRESULT hr;
69 if (!(channel = alloc_channel())) return E_OUTOFMEMORY;
71 prop_set( channel->prop, channel->prop_count, WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE,
72 &msg_size, sizeof(msg_size) );
74 for (i = 0; i < count; i++)
76 hr = prop_set( channel->prop, channel->prop_count, properties[i].id, properties[i].value,
77 properties[i].valueSize );
78 if (hr != S_OK)
80 free_channel( channel );
81 return hr;
85 channel->type = type;
86 channel->binding = binding;
88 *ret = channel;
89 return S_OK;
92 /**************************************************************************
93 * WsCreateChannel [webservices.@]
95 HRESULT WINAPI WsCreateChannel( WS_CHANNEL_TYPE type, WS_CHANNEL_BINDING binding,
96 const WS_CHANNEL_PROPERTY *properties, ULONG count,
97 const WS_SECURITY_DESCRIPTION *desc, WS_CHANNEL **handle,
98 WS_ERROR *error )
100 struct channel *channel;
101 HRESULT hr;
103 TRACE( "%u %u %p %u %p %p %p\n", type, binding, properties, count, desc, handle, error );
104 if (error) FIXME( "ignoring error parameter\n" );
105 if (desc) FIXME( "ignoring security description\n" );
107 if (!handle) return E_INVALIDARG;
109 if (type != WS_CHANNEL_TYPE_REQUEST)
111 FIXME( "channel type %u not implemented\n", type );
112 return E_NOTIMPL;
114 if (binding != WS_HTTP_CHANNEL_BINDING)
116 FIXME( "channel binding %u not implemented\n", binding );
117 return E_NOTIMPL;
120 if ((hr = create_channel( type, binding, properties, count, &channel )) != S_OK)
121 return hr;
123 *handle = (WS_CHANNEL *)channel;
124 return S_OK;
127 /**************************************************************************
128 * WsFreeChannel [webservices.@]
130 void WINAPI WsFreeChannel( WS_CHANNEL *handle )
132 struct channel *channel = (struct channel *)handle;
134 TRACE( "%p\n", handle );
135 free_channel( channel );
138 /**************************************************************************
139 * WsGetChannelProperty [webservices.@]
141 HRESULT WINAPI WsGetChannelProperty( WS_CHANNEL *handle, WS_CHANNEL_PROPERTY_ID id, void *buf,
142 ULONG size, WS_ERROR *error )
144 struct channel *channel = (struct channel *)handle;
146 TRACE( "%p %u %p %u %p\n", handle, id, buf, size, error );
147 if (error) FIXME( "ignoring error parameter\n" );
149 return prop_get( channel->prop, channel->prop_count, id, buf, size );
152 /**************************************************************************
153 * WsSetChannelProperty [webservices.@]
155 HRESULT WINAPI WsSetChannelProperty( WS_CHANNEL *handle, WS_CHANNEL_PROPERTY_ID id, const void *value,
156 ULONG size, WS_ERROR *error )
158 struct channel *channel = (struct channel *)handle;
160 TRACE( "%p %u %p %u\n", handle, id, value, size );
161 if (error) FIXME( "ignoring error parameter\n" );
163 return prop_set( channel->prop, channel->prop_count, id, value, size );
166 HRESULT open_channel( struct channel *channel, const WS_ENDPOINT_ADDRESS *endpoint )
168 channel->state = WS_CHANNEL_STATE_OPEN;
169 return S_OK;
172 /**************************************************************************
173 * WsOpenChannel [webservices.@]
175 HRESULT WINAPI WsOpenChannel( WS_CHANNEL *handle, const WS_ENDPOINT_ADDRESS *endpoint,
176 const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error )
178 struct channel *channel = (struct channel *)handle;
180 TRACE( "%p %p %p %p\n", handle, endpoint, ctx, error );
181 if (error) FIXME( "ignoring error parameter\n" );
182 if (ctx) FIXME( "ignoring ctx parameter\n" );
184 if (!endpoint) return E_INVALIDARG;
185 if (channel->state != WS_CHANNEL_STATE_CREATED) return WS_E_INVALID_OPERATION;
187 return open_channel( channel, endpoint );
190 HRESULT close_channel( struct channel *channel )
192 channel->state = WS_CHANNEL_STATE_CLOSED;
193 return S_OK;
196 /**************************************************************************
197 * WsCloseChannel [webservices.@]
199 HRESULT WINAPI WsCloseChannel( WS_CHANNEL *handle, const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error )
201 struct channel *channel = (struct channel *)handle;
203 TRACE( "%p %p %p\n", handle, ctx, error );
204 if (error) FIXME( "ignoring error parameter\n" );
205 if (ctx) FIXME( "ignoring ctx parameter\n" );
207 return close_channel( channel );