dxgi: Return actual swap effect for D3D11 swapchains.
[wine.git] / dlls / webservices / proxy.c
blobda30cb027affe68376cb1ce8a55c0eafe6d9e57e
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[sizeof(proxy_props)/sizeof(proxy_props[0])];
54 #define PROXY_MAGIC (('P' << 24) | ('R' << 16) | ('O' << 8) | 'X')
56 static struct proxy *alloc_proxy(void)
58 static const ULONG count = sizeof(proxy_props)/sizeof(proxy_props[0]);
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 ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": proxy.cs");
68 prop_init( proxy_props, count, ret->prop, &ret[1] );
69 ret->prop_count = count;
70 return ret;
73 static void reset_proxy( struct proxy *proxy )
75 WsResetChannel( proxy->channel, NULL );
76 proxy->state = WS_SERVICE_PROXY_STATE_CREATED;
79 static void free_proxy( struct proxy *proxy )
81 reset_proxy( proxy );
82 WsFreeChannel( proxy->channel );
84 proxy->cs.DebugInfo->Spare[0] = 0;
85 DeleteCriticalSection( &proxy->cs );
86 heap_free( proxy );
89 static HRESULT create_proxy( WS_CHANNEL *channel, const WS_PROXY_PROPERTY *properties, ULONG count,
90 WS_SERVICE_PROXY **handle )
92 struct proxy *proxy;
93 HRESULT hr;
94 ULONG i;
96 if (!(proxy = alloc_proxy())) return E_OUTOFMEMORY;
98 for (i = 0; i < count; i++)
100 hr = prop_set( proxy->prop, proxy->prop_count, properties[i].id, properties[i].value,
101 properties[i].valueSize );
102 if (hr != S_OK)
104 free_proxy( proxy );
105 return hr;
109 proxy->channel = channel;
111 *handle = (WS_SERVICE_PROXY *)proxy;
112 return S_OK;
115 /**************************************************************************
116 * WsCreateServiceProxy [webservices.@]
118 HRESULT WINAPI WsCreateServiceProxy( const WS_CHANNEL_TYPE type, const WS_CHANNEL_BINDING binding,
119 const WS_SECURITY_DESCRIPTION *desc,
120 const WS_PROXY_PROPERTY *proxy_props, ULONG proxy_props_count,
121 const WS_CHANNEL_PROPERTY *channel_props,
122 const ULONG channel_props_count, WS_SERVICE_PROXY **handle,
123 WS_ERROR *error )
125 WS_CHANNEL *channel;
126 HRESULT hr;
128 TRACE( "%u %u %p %p %u %p %u %p %p\n", type, binding, desc, proxy_props, proxy_props_count,
129 channel_props, channel_props_count, handle, error );
130 if (error) FIXME( "ignoring error parameter\n" );
131 if (desc) FIXME( "ignoring security description\n" );
133 if (!handle) return E_INVALIDARG;
135 if ((hr = WsCreateChannel( type, binding, channel_props, channel_props_count, NULL, &channel,
136 NULL )) != S_OK) return hr;
138 if ((hr = create_proxy( channel, proxy_props, proxy_props_count, handle )) != S_OK)
140 WsFreeChannel( channel );
141 return hr;
144 TRACE( "created %p\n", *handle );
145 return S_OK;
148 /**************************************************************************
149 * WsCreateServiceProxyFromTemplate [webservices.@]
151 HRESULT WINAPI WsCreateServiceProxyFromTemplate( WS_CHANNEL_TYPE channel_type,
152 const WS_PROXY_PROPERTY *properties, const ULONG count,
153 WS_BINDING_TEMPLATE_TYPE type, void *value, ULONG size,
154 const void *desc, ULONG desc_size, WS_SERVICE_PROXY **handle,
155 WS_ERROR *error )
157 const WS_CHANNEL_PROPERTY *channel_props = NULL;
158 ULONG channel_props_count = 0;
159 WS_CHANNEL_BINDING binding;
160 WS_CHANNEL *channel;
161 HRESULT hr;
163 TRACE( "%u %p %u %u %p %u %p %u %p %p\n", channel_type, properties, count, type, value, size, desc,
164 desc_size, handle, error );
165 if (error) FIXME( "ignoring error parameter\n" );
167 if (!desc || !handle) return E_INVALIDARG;
168 FIXME( "ignoring description\n" );
170 switch (type)
172 case WS_HTTP_BINDING_TEMPLATE_TYPE:
174 WS_HTTP_BINDING_TEMPLATE *http = value;
175 if (http)
177 channel_props = http->channelProperties.properties;
178 channel_props_count = http->channelProperties.propertyCount;
180 binding = WS_HTTP_CHANNEL_BINDING;
181 break;
183 case WS_HTTP_SSL_BINDING_TEMPLATE_TYPE:
185 WS_HTTP_SSL_BINDING_TEMPLATE *https = value;
186 if (https)
188 channel_props = https->channelProperties.properties;
189 channel_props_count = https->channelProperties.propertyCount;
191 binding = WS_HTTP_CHANNEL_BINDING;
192 break;
194 default:
195 FIXME( "template type %u not implemented\n", type );
196 return E_NOTIMPL;
199 if ((hr = WsCreateChannel( channel_type, binding, channel_props, channel_props_count, NULL,
200 &channel, NULL )) != S_OK) return hr;
202 if ((hr = create_proxy( channel, properties, count, handle )) != S_OK)
204 WsFreeChannel( channel );
205 return hr;
208 TRACE( "created %p\n", *handle );
209 return S_OK;
212 /**************************************************************************
213 * WsResetServiceProxy [webservices.@]
215 HRESULT WINAPI WsResetServiceProxy( WS_SERVICE_PROXY *handle, WS_ERROR *error )
217 struct proxy *proxy = (struct proxy *)handle;
219 TRACE( "%p %p\n", handle, error );
220 if (error) FIXME( "ignoring error parameter\n" );
222 if (!proxy) return E_INVALIDARG;
224 EnterCriticalSection( &proxy->cs );
226 if (proxy->magic != PROXY_MAGIC)
228 LeaveCriticalSection( &proxy->cs );
229 return E_INVALIDARG;
232 if (proxy->state != WS_SERVICE_PROXY_STATE_CREATED && proxy->state != WS_SERVICE_PROXY_STATE_CLOSED)
234 LeaveCriticalSection( &proxy->cs );
235 return WS_E_INVALID_OPERATION;
238 reset_proxy( proxy );
240 LeaveCriticalSection( &proxy->cs );
241 return S_OK;
244 /**************************************************************************
245 * WsFreeServiceProxy [webservices.@]
247 void WINAPI WsFreeServiceProxy( WS_SERVICE_PROXY *handle )
249 struct proxy *proxy = (struct proxy *)handle;
251 TRACE( "%p\n", handle );
253 if (!proxy) return;
255 EnterCriticalSection( &proxy->cs );
257 if (proxy->magic != PROXY_MAGIC)
259 LeaveCriticalSection( &proxy->cs );
260 return;
263 proxy->magic = 0;
265 LeaveCriticalSection( &proxy->cs );
266 free_proxy( proxy );
269 /**************************************************************************
270 * WsGetServiceProxyProperty [webservices.@]
272 HRESULT WINAPI WsGetServiceProxyProperty( WS_SERVICE_PROXY *handle, WS_PROXY_PROPERTY_ID id,
273 void *buf, ULONG size, WS_ERROR *error )
275 struct proxy *proxy = (struct proxy *)handle;
276 HRESULT hr = S_OK;
278 TRACE( "%p %u %p %u %p\n", handle, id, buf, size, error );
279 if (error) FIXME( "ignoring error parameter\n" );
281 if (!proxy) return E_INVALIDARG;
283 EnterCriticalSection( &proxy->cs );
285 if (proxy->magic != PROXY_MAGIC)
287 LeaveCriticalSection( &proxy->cs );
288 return E_INVALIDARG;
291 switch (id)
293 case WS_PROXY_PROPERTY_STATE:
294 if (!buf || size != sizeof(proxy->state)) hr = E_INVALIDARG;
295 else *(WS_SERVICE_PROXY_STATE *)buf = proxy->state;
296 break;
298 default:
299 hr = prop_get( proxy->prop, proxy->prop_count, id, buf, size );
302 LeaveCriticalSection( &proxy->cs );
303 return hr;
306 /**************************************************************************
307 * WsOpenServiceProxy [webservices.@]
309 HRESULT WINAPI WsOpenServiceProxy( WS_SERVICE_PROXY *handle, const WS_ENDPOINT_ADDRESS *endpoint,
310 const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error )
312 struct proxy *proxy = (struct proxy *)handle;
313 HRESULT hr;
315 TRACE( "%p %p %p %p\n", handle, endpoint, ctx, error );
316 if (error) FIXME( "ignoring error parameter\n" );
317 if (ctx) FIXME( "ignoring ctx parameter\n" );
319 if (!proxy || !endpoint) return E_INVALIDARG;
321 EnterCriticalSection( &proxy->cs );
323 if (proxy->magic != PROXY_MAGIC)
325 LeaveCriticalSection( &proxy->cs );
326 return E_INVALIDARG;
329 if ((hr = WsOpenChannel( proxy->channel, endpoint, NULL, NULL )) == S_OK)
330 proxy->state = WS_SERVICE_PROXY_STATE_OPEN;
332 LeaveCriticalSection( &proxy->cs );
333 return hr;
336 /**************************************************************************
337 * WsCloseServiceProxy [webservices.@]
339 HRESULT WINAPI WsCloseServiceProxy( WS_SERVICE_PROXY *handle, const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error )
341 struct proxy *proxy = (struct proxy *)handle;
342 HRESULT hr;
344 TRACE( "%p %p %p\n", handle, ctx, error );
345 if (error) FIXME( "ignoring error parameter\n" );
346 if (ctx) FIXME( "ignoring ctx parameter\n" );
348 if (!proxy) return E_INVALIDARG;
350 EnterCriticalSection( &proxy->cs );
352 if (proxy->magic != PROXY_MAGIC)
354 LeaveCriticalSection( &proxy->cs );
355 return E_INVALIDARG;
358 if ((hr = WsCloseChannel( proxy->channel, NULL, NULL )) == S_OK)
359 proxy->state = WS_SERVICE_PROXY_STATE_CLOSED;
361 LeaveCriticalSection( &proxy->cs );
362 return hr;
365 /**************************************************************************
366 * WsAbortServiceProxy [webservices.@]
368 HRESULT WINAPI WsAbortServiceProxy( WS_SERVICE_PROXY *handle, WS_ERROR *error )
370 FIXME( "%p %p\n", handle, error );
371 return E_NOTIMPL;
374 static HRESULT set_send_context( WS_MESSAGE *msg, const WS_CALL_PROPERTY *props, ULONG count )
376 ULONG i;
377 for (i = 0; i < count; i++)
379 if (props[i].id == WS_CALL_PROPERTY_SEND_MESSAGE_CONTEXT)
381 if (props[i].valueSize != sizeof(WS_PROXY_MESSAGE_CALLBACK_CONTEXT)) return E_INVALIDARG;
382 message_set_send_context( msg, props[i].value );
383 break;
386 return S_OK;
389 static HRESULT set_receive_context( WS_MESSAGE *msg, const WS_CALL_PROPERTY *props, ULONG count )
391 ULONG i;
392 for (i = 0; i < count; i++)
394 if (props[i].id == WS_CALL_PROPERTY_RECEIVE_MESSAGE_CONTEXT)
396 if (props[i].valueSize != sizeof(WS_PROXY_MESSAGE_CALLBACK_CONTEXT)) return E_INVALIDARG;
397 message_set_receive_context( msg, props[i].value );
398 break;
401 return S_OK;
404 static HRESULT write_message( WS_MESSAGE *msg, WS_XML_WRITER *writer, const WS_ELEMENT_DESCRIPTION *desc,
405 const WS_PARAMETER_DESCRIPTION *params, ULONG count, const void **args )
407 HRESULT hr;
408 message_do_send_callback( msg );
409 if ((hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL )) != S_OK) return hr;
410 if ((hr = write_input_params( writer, desc, params, count, args )) != S_OK) return hr;
411 return WsWriteEnvelopeEnd( msg, NULL );
414 static HRESULT set_output( WS_XML_WRITER *writer )
416 WS_XML_WRITER_TEXT_ENCODING text = { {WS_XML_WRITER_ENCODING_TYPE_TEXT}, WS_CHARSET_UTF8 };
417 WS_XML_WRITER_BUFFER_OUTPUT buf = { {WS_XML_WRITER_OUTPUT_TYPE_BUFFER} };
418 return WsSetOutput( writer, &text.encoding, &buf.output, NULL, 0, NULL );
421 static HRESULT send_message( WS_CHANNEL *channel, WS_MESSAGE *msg, WS_MESSAGE_DESCRIPTION *desc,
422 WS_PARAMETER_DESCRIPTION *params, ULONG count, const void **args )
424 WS_XML_WRITER *writer;
425 HRESULT hr;
427 if ((hr = message_set_action( msg, desc->action )) != S_OK) return hr;
428 if ((hr = WsCreateWriter( NULL, 0, &writer, NULL )) != S_OK) return hr;
429 if ((hr = set_output( writer )) != S_OK) goto done;
430 if ((hr = write_message( msg, writer, desc->bodyElementDescription, params, count, args )) != S_OK) goto done;
431 hr = channel_send_message( channel, msg );
433 done:
434 WsFreeWriter( writer );
435 return hr;
438 static HRESULT read_message( WS_MESSAGE *msg, WS_XML_READER *reader, WS_HEAP *heap,
439 const WS_ELEMENT_DESCRIPTION *desc, const WS_PARAMETER_DESCRIPTION *params,
440 ULONG count, const void **args )
442 HRESULT hr;
443 if ((hr = WsReadEnvelopeStart( msg, reader, NULL, NULL, NULL )) != S_OK) return hr;
444 message_do_receive_callback( msg );
445 if ((hr = read_output_params( reader, heap, desc, params, count, args )) != S_OK) return hr;
446 return WsReadEnvelopeEnd( msg, NULL );
449 static HRESULT receive_message( WS_CHANNEL *channel, WS_MESSAGE *msg, WS_MESSAGE_DESCRIPTION *desc,
450 WS_PARAMETER_DESCRIPTION *params, ULONG count, WS_HEAP *heap, const void **args )
452 WS_XML_READER *reader;
453 HRESULT hr;
455 if ((hr = message_set_action( msg, desc->action )) != S_OK) return hr;
456 if ((hr = channel_receive_message( channel )) != S_OK) return hr;
457 if ((hr = channel_get_reader( channel, &reader )) != S_OK) return hr;
458 return read_message( msg, reader, heap, desc->bodyElementDescription, params, count, args );
461 static HRESULT create_input_message( WS_CHANNEL *channel, const WS_CALL_PROPERTY *properties,
462 ULONG count, WS_MESSAGE **ret )
464 WS_MESSAGE *msg;
465 HRESULT hr;
467 if ((hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL )) != S_OK) return hr;
468 if ((hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL )) != S_OK ||
469 (hr = set_send_context( msg, properties, count )) != S_OK)
471 WsFreeMessage( msg );
472 return hr;
474 *ret = msg;
475 return S_OK;
478 static HRESULT create_output_message( WS_CHANNEL *channel, const WS_CALL_PROPERTY *properties,
479 ULONG count, WS_MESSAGE **ret )
481 WS_MESSAGE *msg;
482 HRESULT hr;
484 if ((hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL )) != S_OK) return hr;
485 if ((hr = set_receive_context( msg, properties, count )) != S_OK)
487 WsFreeMessage( msg );
488 return hr;
490 *ret = msg;
491 return S_OK;
494 /**************************************************************************
495 * WsCall [webservices.@]
497 HRESULT WINAPI WsCall( WS_SERVICE_PROXY *handle, const WS_OPERATION_DESCRIPTION *desc, const void **args,
498 WS_HEAP *heap, const WS_CALL_PROPERTY *properties, const ULONG count,
499 const WS_ASYNC_CONTEXT *ctx, WS_ERROR *error )
501 struct proxy *proxy = (struct proxy *)handle;
502 WS_MESSAGE *msg = NULL;
503 HRESULT hr;
504 ULONG i;
506 TRACE( "%p %p %p %p %p %u %p %p\n", handle, desc, args, heap, properties, count, ctx, error );
507 if (error) FIXME( "ignoring error parameter\n" );
508 if (ctx) FIXME( "ignoring ctx parameter\n" );
509 for (i = 0; i < count; i++)
511 if (properties[i].id != WS_CALL_PROPERTY_SEND_MESSAGE_CONTEXT &&
512 properties[i].id != WS_CALL_PROPERTY_RECEIVE_MESSAGE_CONTEXT)
514 FIXME( "unimplemented call property %u\n", properties[i].id );
515 return E_NOTIMPL;
519 if (!proxy || !desc || (desc->parameterCount && !args)) return E_INVALIDARG;
521 EnterCriticalSection( &proxy->cs );
523 if (proxy->magic != PROXY_MAGIC)
525 LeaveCriticalSection( &proxy->cs );
526 return E_INVALIDARG;
529 if ((hr = create_input_message( proxy->channel, properties, count, &msg )) != S_OK) goto done;
530 if ((hr = send_message( proxy->channel, msg, desc->inputMessageDescription, desc->parameterDescription,
531 desc->parameterCount, args )) != S_OK) goto done;
533 WsFreeMessage( msg );
534 msg = NULL;
536 if ((hr = create_output_message( proxy->channel, properties, count, &msg )) != S_OK) goto done;
537 hr = receive_message( proxy->channel, msg, desc->outputMessageDescription, desc->parameterDescription,
538 desc->parameterCount, heap, args );
540 done:
541 WsFreeMessage( msg );
542 LeaveCriticalSection( &proxy->cs );
543 return hr;