wined3d: Drop support for WINED3DFMT_D32_UNORM.
[wine.git] / dlls / webservices / proxy.c
blob811aa8d9ae63de71e09f235c84dabaeb1472aba6
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/heap.h"
28 #include "wine/list.h"
29 #include "webservices_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(webservices);
33 static const struct prop_desc proxy_props[] =
35 { sizeof(ULONG), FALSE, TRUE }, /* WS_PROXY_PROPERTY_CALL_TIMEOUT */
36 { sizeof(WS_MESSAGE_PROPERTIES), FALSE }, /* WS_PROXY_PROPERTY_MESSAGE_PROPERTIES */
37 { sizeof(USHORT), FALSE, TRUE }, /* WS_PROXY_PROPERTY_MAX_CALL_POOL_SIZE */
38 { sizeof(WS_SERVICE_PROXY_STATE), TRUE }, /* WS_PROXY_PROPERTY_STATE */
39 { sizeof(ULONG), FALSE, TRUE }, /* WS_PROXY_PROPERTY_MAX_PENDING_CALLS */
40 { sizeof(ULONG), FALSE, TRUE }, /* WS_PROXY_PROPERTY_MAX_CLOSE_TIMEOUT */
41 { sizeof(LANGID), FALSE, TRUE }, /* WS_PROXY_FAULT_LANG_ID */
44 struct proxy
46 ULONG magic;
47 CRITICAL_SECTION cs;
48 WS_SERVICE_PROXY_STATE state;
49 WS_CHANNEL *channel;
50 ULONG prop_count;
51 struct prop prop[ARRAY_SIZE( proxy_props )];
54 #define PROXY_MAGIC (('P' << 24) | ('R' << 16) | ('O' << 8) | 'X')
56 static struct proxy *alloc_proxy(void)
58 static const ULONG count = ARRAY_SIZE( proxy_props );
59 struct proxy *ret;
60 ULONG size = sizeof(*ret) + prop_size( proxy_props, count );
62 if (!(ret = heap_alloc_zero( size ))) return NULL;
64 ret->magic = PROXY_MAGIC;
65 InitializeCriticalSection( &ret->cs );
66 #ifndef __MINGW32__
67 ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": proxy.cs");
68 #endif
70 prop_init( proxy_props, count, ret->prop, &ret[1] );
71 ret->prop_count = count;
72 return ret;
75 static void reset_proxy( struct proxy *proxy )
77 WsResetChannel( proxy->channel, NULL );
78 proxy->state = WS_SERVICE_PROXY_STATE_CREATED;
81 static void free_proxy( struct proxy *proxy )
83 reset_proxy( proxy );
84 WsFreeChannel( proxy->channel );
86 #ifndef __MINGW32__
87 proxy->cs.DebugInfo->Spare[0] = 0;
88 #endif
89 DeleteCriticalSection( &proxy->cs );
90 heap_free( proxy );
93 static HRESULT create_proxy( WS_CHANNEL *channel, const WS_PROXY_PROPERTY *properties, ULONG count,
94 WS_SERVICE_PROXY **handle )
96 struct proxy *proxy;
97 HRESULT hr;
98 ULONG i;
100 if (!(proxy = alloc_proxy())) return E_OUTOFMEMORY;
102 for (i = 0; i < count; i++)
104 hr = prop_set( proxy->prop, proxy->prop_count, properties[i].id, properties[i].value,
105 properties[i].valueSize );
106 if (hr != S_OK)
108 free_proxy( proxy );
109 return hr;
113 proxy->channel = channel;
115 *handle = (WS_SERVICE_PROXY *)proxy;
116 return S_OK;
119 /**************************************************************************
120 * WsCreateServiceProxy [webservices.@]
122 HRESULT WINAPI WsCreateServiceProxy( const WS_CHANNEL_TYPE type, const WS_CHANNEL_BINDING binding,
123 const WS_SECURITY_DESCRIPTION *desc,
124 const WS_PROXY_PROPERTY *proxy_props, ULONG proxy_props_count,
125 const WS_CHANNEL_PROPERTY *channel_props,
126 const ULONG channel_props_count, WS_SERVICE_PROXY **handle,
127 WS_ERROR *error )
129 WS_CHANNEL *channel;
130 HRESULT hr;
132 TRACE( "%u %u %p %p %u %p %u %p %p\n", type, binding, desc, proxy_props, proxy_props_count,
133 channel_props, channel_props_count, handle, error );
134 if (error) FIXME( "ignoring error parameter\n" );
135 if (desc) FIXME( "ignoring security description\n" );
137 if (!handle) return E_INVALIDARG;
139 if ((hr = WsCreateChannel( type, binding, channel_props, channel_props_count, NULL, &channel,
140 NULL )) != S_OK) return hr;
142 if ((hr = create_proxy( channel, proxy_props, proxy_props_count, handle )) != S_OK)
144 WsFreeChannel( channel );
145 return hr;
148 TRACE( "created %p\n", *handle );
149 return S_OK;
152 /**************************************************************************
153 * WsCreateServiceProxyFromTemplate [webservices.@]
155 HRESULT WINAPI WsCreateServiceProxyFromTemplate( WS_CHANNEL_TYPE channel_type,
156 const WS_PROXY_PROPERTY *properties, const ULONG count,
157 WS_BINDING_TEMPLATE_TYPE type, void *value, ULONG size,
158 const void *desc, ULONG desc_size, WS_SERVICE_PROXY **handle,
159 WS_ERROR *error )
161 const WS_CHANNEL_PROPERTY *channel_props = NULL;
162 ULONG channel_props_count = 0;
163 WS_CHANNEL_BINDING binding;
164 WS_CHANNEL *channel;
165 HRESULT hr;
167 TRACE( "%u %p %u %u %p %u %p %u %p %p\n", channel_type, properties, count, type, value, size, desc,
168 desc_size, handle, error );
169 if (error) FIXME( "ignoring error parameter\n" );
171 if (!desc || !handle) return E_INVALIDARG;
172 FIXME( "ignoring description\n" );
174 switch (type)
176 case WS_HTTP_BINDING_TEMPLATE_TYPE:
178 WS_HTTP_BINDING_TEMPLATE *http = value;
179 if (http)
181 channel_props = http->channelProperties.properties;
182 channel_props_count = http->channelProperties.propertyCount;
184 binding = WS_HTTP_CHANNEL_BINDING;
185 break;
187 case WS_HTTP_SSL_BINDING_TEMPLATE_TYPE:
189 WS_HTTP_SSL_BINDING_TEMPLATE *https = value;
190 if (https)
192 channel_props = https->channelProperties.properties;
193 channel_props_count = https->channelProperties.propertyCount;
195 binding = WS_HTTP_CHANNEL_BINDING;
196 break;
198 default:
199 FIXME( "template type %u not implemented\n", type );
200 return E_NOTIMPL;
203 if ((hr = WsCreateChannel( channel_type, binding, channel_props, channel_props_count, NULL,
204 &channel, NULL )) != S_OK) return hr;
206 if ((hr = create_proxy( channel, properties, count, handle )) != S_OK)
208 WsFreeChannel( channel );
209 return hr;
212 TRACE( "created %p\n", *handle );
213 return S_OK;
216 /**************************************************************************
217 * WsResetServiceProxy [webservices.@]
219 HRESULT WINAPI WsResetServiceProxy( WS_SERVICE_PROXY *handle, WS_ERROR *error )
221 struct proxy *proxy = (struct proxy *)handle;
222 HRESULT hr = S_OK;
224 TRACE( "%p %p\n", handle, error );
225 if (error) FIXME( "ignoring error parameter\n" );
227 if (!proxy) return E_INVALIDARG;
229 EnterCriticalSection( &proxy->cs );
231 if (proxy->magic != PROXY_MAGIC)
233 LeaveCriticalSection( &proxy->cs );
234 return E_INVALIDARG;
237 if (proxy->state != WS_SERVICE_PROXY_STATE_CREATED && proxy->state != WS_SERVICE_PROXY_STATE_CLOSED)
238 hr = WS_E_INVALID_OPERATION;
239 else
240 reset_proxy( proxy );
242 LeaveCriticalSection( &proxy->cs );
243 TRACE( "returning %08x\n", hr );
244 return hr;
247 /**************************************************************************
248 * WsFreeServiceProxy [webservices.@]
250 void WINAPI WsFreeServiceProxy( WS_SERVICE_PROXY *handle )
252 struct proxy *proxy = (struct proxy *)handle;
254 TRACE( "%p\n", handle );
256 if (!proxy) return;
258 EnterCriticalSection( &proxy->cs );
260 if (proxy->magic != PROXY_MAGIC)
262 LeaveCriticalSection( &proxy->cs );
263 return;
266 proxy->magic = 0;
268 LeaveCriticalSection( &proxy->cs );
269 free_proxy( proxy );
272 /**************************************************************************
273 * WsGetServiceProxyProperty [webservices.@]
275 HRESULT WINAPI WsGetServiceProxyProperty( WS_SERVICE_PROXY *handle, WS_PROXY_PROPERTY_ID id,
276 void *buf, ULONG size, WS_ERROR *error )
278 struct proxy *proxy = (struct proxy *)handle;
279 HRESULT hr = S_OK;
281 TRACE( "%p %u %p %u %p\n", handle, id, buf, size, error );
282 if (error) FIXME( "ignoring error parameter\n" );
284 if (!proxy) return E_INVALIDARG;
286 EnterCriticalSection( &proxy->cs );
288 if (proxy->magic != PROXY_MAGIC)
290 LeaveCriticalSection( &proxy->cs );
291 return E_INVALIDARG;
294 switch (id)
296 case WS_PROXY_PROPERTY_STATE:
297 if (!buf || size != sizeof(proxy->state)) hr = E_INVALIDARG;
298 else *(WS_SERVICE_PROXY_STATE *)buf = proxy->state;
299 break;
301 default:
302 hr = prop_get( proxy->prop, proxy->prop_count, id, buf, size );
305 LeaveCriticalSection( &proxy->cs );
306 TRACE( "returning %08x\n", hr );
307 return hr;
310 /**************************************************************************
311 * WsOpenServiceProxy [webservices.@]
313 HRESULT WINAPI WsOpenServiceProxy( WS_SERVICE_PROXY *handle, const WS_ENDPOINT_ADDRESS *endpoint,
314 const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error )
316 struct proxy *proxy = (struct proxy *)handle;
317 HRESULT hr;
319 TRACE( "%p %p %p %p\n", handle, endpoint, ctx, error );
320 if (error) FIXME( "ignoring error parameter\n" );
321 if (ctx) FIXME( "ignoring ctx parameter\n" );
323 if (!proxy || !endpoint) return E_INVALIDARG;
325 EnterCriticalSection( &proxy->cs );
327 if (proxy->magic != PROXY_MAGIC)
329 LeaveCriticalSection( &proxy->cs );
330 return E_INVALIDARG;
333 if ((hr = WsOpenChannel( proxy->channel, endpoint, NULL, NULL )) == S_OK)
334 proxy->state = WS_SERVICE_PROXY_STATE_OPEN;
336 LeaveCriticalSection( &proxy->cs );
337 TRACE( "returning %08x\n", hr );
338 return hr;
341 /**************************************************************************
342 * WsCloseServiceProxy [webservices.@]
344 HRESULT WINAPI WsCloseServiceProxy( WS_SERVICE_PROXY *handle, const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error )
346 struct proxy *proxy = (struct proxy *)handle;
347 HRESULT hr;
349 TRACE( "%p %p %p\n", handle, ctx, error );
350 if (error) FIXME( "ignoring error parameter\n" );
351 if (ctx) FIXME( "ignoring ctx parameter\n" );
353 if (!proxy) return E_INVALIDARG;
355 EnterCriticalSection( &proxy->cs );
357 if (proxy->magic != PROXY_MAGIC)
359 LeaveCriticalSection( &proxy->cs );
360 return E_INVALIDARG;
363 if ((hr = WsCloseChannel( proxy->channel, NULL, NULL )) == S_OK)
364 proxy->state = WS_SERVICE_PROXY_STATE_CLOSED;
366 LeaveCriticalSection( &proxy->cs );
367 TRACE( "returning %08x\n", hr );
368 return hr;
371 /**************************************************************************
372 * WsAbortServiceProxy [webservices.@]
374 HRESULT WINAPI WsAbortServiceProxy( WS_SERVICE_PROXY *handle, WS_ERROR *error )
376 FIXME( "%p %p\n", handle, error );
377 return E_NOTIMPL;
380 static HRESULT set_send_context( WS_MESSAGE *msg, const WS_CALL_PROPERTY *props, ULONG count )
382 ULONG i;
383 for (i = 0; i < count; i++)
385 if (props[i].id == WS_CALL_PROPERTY_SEND_MESSAGE_CONTEXT)
387 if (props[i].valueSize != sizeof(WS_PROXY_MESSAGE_CALLBACK_CONTEXT)) return E_INVALIDARG;
388 message_set_send_context( msg, props[i].value );
389 break;
392 return S_OK;
395 static HRESULT set_receive_context( WS_MESSAGE *msg, const WS_CALL_PROPERTY *props, ULONG count )
397 ULONG i;
398 for (i = 0; i < count; i++)
400 if (props[i].id == WS_CALL_PROPERTY_RECEIVE_MESSAGE_CONTEXT)
402 if (props[i].valueSize != sizeof(WS_PROXY_MESSAGE_CALLBACK_CONTEXT)) return E_INVALIDARG;
403 message_set_receive_context( msg, props[i].value );
404 break;
407 return S_OK;
410 static HRESULT write_message( WS_MESSAGE *msg, WS_XML_WRITER *writer, const WS_ELEMENT_DESCRIPTION *desc,
411 const WS_PARAMETER_DESCRIPTION *params, ULONG count, const void **args )
413 HRESULT hr;
414 message_do_send_callback( msg );
415 if ((hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL )) != S_OK) return hr;
416 if ((hr = write_input_params( writer, desc, params, count, args )) != S_OK) return hr;
417 return WsWriteEnvelopeEnd( msg, NULL );
420 static HRESULT set_output( WS_XML_WRITER *writer )
422 WS_XML_WRITER_TEXT_ENCODING text = { {WS_XML_WRITER_ENCODING_TYPE_TEXT}, WS_CHARSET_UTF8 };
423 WS_XML_WRITER_BUFFER_OUTPUT buf = { {WS_XML_WRITER_OUTPUT_TYPE_BUFFER} };
424 return WsSetOutput( writer, &text.encoding, &buf.output, NULL, 0, NULL );
427 static HRESULT send_message( WS_CHANNEL *channel, WS_MESSAGE *msg, WS_MESSAGE_DESCRIPTION *desc,
428 WS_PARAMETER_DESCRIPTION *params, ULONG count, const void **args )
430 WS_XML_WRITER *writer;
431 HRESULT hr;
433 if ((hr = message_set_action( msg, desc->action )) != S_OK) return hr;
434 if ((hr = WsCreateWriter( NULL, 0, &writer, NULL )) != S_OK) return hr;
435 if ((hr = set_output( writer )) != S_OK) goto done;
436 if ((hr = write_message( msg, writer, desc->bodyElementDescription, params, count, args )) != S_OK) goto done;
437 hr = channel_send_message( channel, msg );
439 done:
440 WsFreeWriter( writer );
441 return hr;
444 static HRESULT read_message( WS_MESSAGE *msg, WS_XML_READER *reader, WS_HEAP *heap,
445 const WS_ELEMENT_DESCRIPTION *desc, const WS_PARAMETER_DESCRIPTION *params,
446 ULONG count, const void **args )
448 HRESULT hr;
449 if ((hr = WsReadEnvelopeStart( msg, reader, NULL, NULL, NULL )) != S_OK) return hr;
450 message_do_receive_callback( msg );
451 if ((hr = read_output_params( reader, heap, desc, params, count, args )) != S_OK) return hr;
452 return WsReadEnvelopeEnd( msg, NULL );
455 static HRESULT receive_message( WS_CHANNEL *channel, WS_MESSAGE *msg, WS_MESSAGE_DESCRIPTION *desc,
456 WS_PARAMETER_DESCRIPTION *params, ULONG count, WS_HEAP *heap, const void **args )
458 WS_XML_READER *reader;
459 HRESULT hr;
461 if ((hr = message_set_action( msg, desc->action )) != S_OK) return hr;
462 if ((hr = channel_receive_message( channel )) != S_OK) return hr;
463 if ((hr = channel_get_reader( channel, &reader )) != S_OK) return hr;
464 return read_message( msg, reader, heap, desc->bodyElementDescription, params, count, args );
467 static HRESULT create_input_message( WS_CHANNEL *channel, const WS_CALL_PROPERTY *properties,
468 ULONG count, WS_MESSAGE **ret )
470 WS_MESSAGE *msg;
471 HRESULT hr;
473 if ((hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL )) != S_OK) return hr;
474 if ((hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL )) != S_OK ||
475 (hr = set_send_context( msg, properties, count )) != S_OK)
477 WsFreeMessage( msg );
478 return hr;
480 *ret = msg;
481 return S_OK;
484 static HRESULT create_output_message( WS_CHANNEL *channel, const WS_CALL_PROPERTY *properties,
485 ULONG count, WS_MESSAGE **ret )
487 WS_MESSAGE *msg;
488 HRESULT hr;
490 if ((hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL )) != S_OK) return hr;
491 if ((hr = set_receive_context( msg, properties, count )) != S_OK)
493 WsFreeMessage( msg );
494 return hr;
496 *ret = msg;
497 return S_OK;
500 /**************************************************************************
501 * WsCall [webservices.@]
503 HRESULT WINAPI WsCall( WS_SERVICE_PROXY *handle, const WS_OPERATION_DESCRIPTION *desc, const void **args,
504 WS_HEAP *heap, const WS_CALL_PROPERTY *properties, const ULONG count,
505 const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error )
507 struct proxy *proxy = (struct proxy *)handle;
508 WS_MESSAGE *msg = NULL;
509 HRESULT hr;
510 ULONG i;
512 TRACE( "%p %p %p %p %p %u %p %p\n", handle, desc, args, heap, properties, count, ctx, error );
513 if (error) FIXME( "ignoring error parameter\n" );
514 if (ctx) FIXME( "ignoring ctx parameter\n" );
515 for (i = 0; i < count; i++)
517 if (properties[i].id != WS_CALL_PROPERTY_SEND_MESSAGE_CONTEXT &&
518 properties[i].id != WS_CALL_PROPERTY_RECEIVE_MESSAGE_CONTEXT)
520 FIXME( "unimplemented call property %u\n", properties[i].id );
521 return E_NOTIMPL;
525 if (!proxy || !desc || (desc->parameterCount && !args)) return E_INVALIDARG;
527 EnterCriticalSection( &proxy->cs );
529 if (proxy->magic != PROXY_MAGIC)
531 LeaveCriticalSection( &proxy->cs );
532 return E_INVALIDARG;
535 if ((hr = create_input_message( proxy->channel, properties, count, &msg )) != S_OK) goto done;
536 if ((hr = send_message( proxy->channel, msg, desc->inputMessageDescription, desc->parameterDescription,
537 desc->parameterCount, args )) != S_OK) goto done;
539 WsFreeMessage( msg );
540 msg = NULL;
542 if ((hr = create_output_message( proxy->channel, properties, count, &msg )) != S_OK) goto done;
543 hr = receive_message( proxy->channel, msg, desc->outputMessageDescription, desc->parameterDescription,
544 desc->parameterCount, heap, args );
546 done:
547 WsFreeMessage( msg );
548 LeaveCriticalSection( &proxy->cs );
549 TRACE( "returning %08x\n", hr );
550 return hr;