ntdll: Allow explicitly specified asm.v2 namespace for "trustInfo".
[wine.git] / dlls / webservices / msg.c
blob19a107629c27618f2ac787ea8b349df031ea2e36
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 "rpc.h"
25 #include "webservices.h"
27 #include "wine/debug.h"
28 #include "wine/heap.h"
29 #include "wine/list.h"
30 #include "wine/unicode.h"
31 #include "webservices_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(webservices);
35 static const struct prop_desc msg_props[] =
37 { sizeof(WS_MESSAGE_STATE), TRUE }, /* WS_MESSAGE_PROPERTY_STATE */
38 { sizeof(WS_HEAP *), TRUE }, /* WS_MESSAGE_PROPERTY_HEAP */
39 { sizeof(WS_ENVELOPE_VERSION), TRUE }, /* WS_MESSAGE_PROPERTY_ENVELOPE_VERSION */
40 { sizeof(WS_ADDRESSING_VERSION), TRUE }, /* WS_MESSAGE_PROPERTY_ADDRESSING_VERSION */
41 { sizeof(WS_XML_BUFFER *), TRUE }, /* WS_MESSAGE_PROPERTY_HEADER_BUFFER */
42 { sizeof(WS_XML_NODE_POSITION *), TRUE }, /* WS_MESSAGE_PROPERTY_HEADER_POSITION */
43 { sizeof(WS_XML_READER *), TRUE }, /* WS_MESSAGE_PROPERTY_BODY_READER */
44 { sizeof(WS_XML_WRITER *), TRUE }, /* WS_MESSAGE_PROPERTY_BODY_WRITER */
45 { sizeof(BOOL), TRUE }, /* WS_MESSAGE_PROPERTY_IS_ADDRESSED */
48 struct header
50 WS_HEADER_TYPE type;
51 BOOL mapped;
52 WS_XML_STRING name;
53 WS_XML_STRING ns;
54 union
56 WS_XML_BUFFER *buf;
57 WS_XML_STRING *text;
58 } u;
61 struct msg
63 ULONG magic;
64 CRITICAL_SECTION cs;
65 WS_MESSAGE_INITIALIZATION init;
66 WS_MESSAGE_STATE state;
67 GUID id;
68 GUID id_req;
69 WS_ENVELOPE_VERSION version_env;
70 WS_ADDRESSING_VERSION version_addr;
71 BOOL is_addressed;
72 WS_STRING addr;
73 WS_XML_STRING *action;
74 WS_HEAP *heap;
75 WS_XML_BUFFER *buf;
76 WS_XML_WRITER *writer;
77 WS_XML_WRITER *writer_body;
78 WS_XML_READER *reader;
79 WS_XML_READER *reader_body;
80 ULONG header_count;
81 ULONG header_size;
82 struct header **header;
83 WS_PROXY_MESSAGE_CALLBACK_CONTEXT ctx_send;
84 WS_PROXY_MESSAGE_CALLBACK_CONTEXT ctx_receive;
85 ULONG prop_count;
86 struct prop prop[sizeof(msg_props)/sizeof(msg_props[0])];
89 #define MSG_MAGIC (('M' << 24) | ('E' << 16) | ('S' << 8) | 'S')
90 #define HEADER_ARRAY_SIZE 2
92 static struct msg *alloc_msg(void)
94 static const ULONG count = sizeof(msg_props)/sizeof(msg_props[0]);
95 struct msg *ret;
96 ULONG size = sizeof(*ret) + prop_size( msg_props, count );
98 if (!(ret = heap_alloc_zero( size ))) return NULL;
99 if (!(ret->header = heap_alloc( HEADER_ARRAY_SIZE * sizeof(struct header *) )))
101 heap_free( ret );
102 return NULL;
104 ret->magic = MSG_MAGIC;
105 ret->state = WS_MESSAGE_STATE_EMPTY;
106 ret->header_size = HEADER_ARRAY_SIZE;
108 InitializeCriticalSection( &ret->cs );
109 ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": msg.cs");
111 prop_init( msg_props, count, ret->prop, &ret[1] );
112 ret->prop_count = count;
113 return ret;
116 static void free_header( struct header *header )
118 heap_free( header->name.bytes );
119 heap_free( header->ns.bytes );
120 if (header->mapped) free_xml_string( header->u.text );
121 heap_free( header );
124 static void reset_msg( struct msg *msg )
126 ULONG i;
128 msg->state = WS_MESSAGE_STATE_EMPTY;
129 msg->init = 0;
130 UuidCreate( &msg->id );
131 memset( &msg->id_req, 0, sizeof(msg->id_req) );
132 msg->is_addressed = FALSE;
133 heap_free( msg->addr.chars );
134 msg->addr.chars = NULL;
135 msg->addr.length = 0;
137 free_xml_string( msg->action );
138 msg->action = NULL;
140 WsResetHeap( msg->heap, NULL );
141 msg->buf = NULL; /* allocated on msg->heap */
142 msg->writer_body = NULL; /* owned by caller */
143 msg->reader_body = NULL; /* owned by caller */
145 for (i = 0; i < msg->header_count; i++)
147 free_header( msg->header[i] );
148 msg->header[i] = NULL;
150 msg->header_count = 0;
152 memset( &msg->ctx_send, 0, sizeof(msg->ctx_send) );
153 memset( &msg->ctx_receive, 0, sizeof(msg->ctx_receive) );
156 static void free_msg( struct msg *msg )
158 reset_msg( msg );
160 WsFreeWriter( msg->writer );
161 WsFreeReader( msg->reader );
162 WsFreeHeap( msg->heap );
163 heap_free( msg->header );
165 msg->cs.DebugInfo->Spare[0] = 0;
166 DeleteCriticalSection( &msg->cs );
167 heap_free( msg );
170 #define HEAP_MAX_SIZE (1 << 16)
171 static HRESULT create_msg( WS_ENVELOPE_VERSION env_version, WS_ADDRESSING_VERSION addr_version,
172 const WS_MESSAGE_PROPERTY *properties, ULONG count, WS_MESSAGE **handle )
174 struct msg *msg;
175 HRESULT hr;
176 ULONG i;
178 if (!(msg = alloc_msg())) return E_OUTOFMEMORY;
180 for (i = 0; i < count; i++)
182 if (properties[i].id == WS_MESSAGE_PROPERTY_ENVELOPE_VERSION ||
183 properties[i].id == WS_MESSAGE_PROPERTY_ADDRESSING_VERSION)
185 free_msg( msg );
186 return E_INVALIDARG;
188 hr = prop_set( msg->prop, msg->prop_count, properties[i].id, properties[i].value,
189 properties[i].valueSize );
190 if (hr != S_OK)
192 free_msg( msg );
193 return hr;
197 if ((hr = WsCreateHeap( HEAP_MAX_SIZE, 0, NULL, 0, &msg->heap, NULL )) != S_OK)
199 free_msg( msg );
200 return hr;
203 UuidCreate( &msg->id );
204 msg->version_env = env_version;
205 msg->version_addr = addr_version;
207 *handle = (WS_MESSAGE *)msg;
208 return S_OK;
211 /**************************************************************************
212 * WsCreateMessage [webservices.@]
214 HRESULT WINAPI WsCreateMessage( WS_ENVELOPE_VERSION env_version, WS_ADDRESSING_VERSION addr_version,
215 const WS_MESSAGE_PROPERTY *properties, ULONG count, WS_MESSAGE **handle,
216 WS_ERROR *error )
218 HRESULT hr;
220 TRACE( "%u %u %p %u %p %p\n", env_version, addr_version, properties, count, handle, error );
221 if (error) FIXME( "ignoring error parameter\n" );
223 if (!handle || !env_version || !addr_version ||
224 (env_version == WS_ENVELOPE_VERSION_NONE && addr_version != WS_ADDRESSING_VERSION_TRANSPORT))
226 return E_INVALIDARG;
229 if ((hr = create_msg( env_version, addr_version, properties, count, handle )) != S_OK) return hr;
230 TRACE( "created %p\n", *handle );
231 return S_OK;
234 /**************************************************************************
235 * WsCreateMessageForChannel [webservices.@]
237 HRESULT WINAPI WsCreateMessageForChannel( WS_CHANNEL *channel_handle, const WS_MESSAGE_PROPERTY *properties,
238 ULONG count, WS_MESSAGE **handle, WS_ERROR *error )
240 WS_ENVELOPE_VERSION version_env;
241 WS_ADDRESSING_VERSION version_addr;
242 HRESULT hr;
244 TRACE( "%p %p %u %p %p\n", channel_handle, properties, count, handle, error );
245 if (error) FIXME( "ignoring error parameter\n" );
247 if (!channel_handle || !handle) return E_INVALIDARG;
249 if ((hr = WsGetChannelProperty( channel_handle, WS_CHANNEL_PROPERTY_ENVELOPE_VERSION, &version_env,
250 sizeof(version_env), NULL )) != S_OK || !version_env)
251 version_env = WS_ENVELOPE_VERSION_SOAP_1_2;
253 if ((hr = WsGetChannelProperty( channel_handle, WS_CHANNEL_PROPERTY_ADDRESSING_VERSION, &version_addr,
254 sizeof(version_addr), NULL )) != S_OK || !version_addr)
255 version_addr = WS_ADDRESSING_VERSION_1_0;
257 if ((hr = create_msg( version_env, version_addr, properties, count, handle )) != S_OK) return hr;
258 TRACE( "created %p\n", *handle );
259 return S_OK;
262 /**************************************************************************
263 * WsFreeMessage [webservices.@]
265 void WINAPI WsFreeMessage( WS_MESSAGE *handle )
267 struct msg *msg = (struct msg *)handle;
269 TRACE( "%p\n", handle );
271 if (!msg) return;
273 EnterCriticalSection( &msg->cs );
275 if (msg->magic != MSG_MAGIC)
277 LeaveCriticalSection( &msg->cs );
278 return;
281 msg->magic = 0;
283 LeaveCriticalSection( &msg->cs );
284 free_msg( msg );
287 /**************************************************************************
288 * WsResetMessage [webservices.@]
290 HRESULT WINAPI WsResetMessage( WS_MESSAGE *handle, WS_ERROR *error )
292 struct msg *msg = (struct msg *)handle;
294 TRACE( "%p %p\n", handle, error );
295 if (error) FIXME( "ignoring error parameter\n" );
297 if (!msg) return E_INVALIDARG;
299 EnterCriticalSection( &msg->cs );
301 if (msg->magic != MSG_MAGIC)
303 LeaveCriticalSection( &msg->cs );
304 return E_INVALIDARG;
307 reset_msg( msg );
309 LeaveCriticalSection( &msg->cs );
310 return S_OK;
313 /**************************************************************************
314 * WsGetMessageProperty [webservices.@]
316 HRESULT WINAPI WsGetMessageProperty( WS_MESSAGE *handle, WS_MESSAGE_PROPERTY_ID id, void *buf,
317 ULONG size, WS_ERROR *error )
319 struct msg *msg = (struct msg *)handle;
320 HRESULT hr = S_OK;
322 TRACE( "%p %u %p %u %p\n", handle, id, buf, size, error );
323 if (error) FIXME( "ignoring error parameter\n" );
325 if (!msg) return E_INVALIDARG;
327 EnterCriticalSection( &msg->cs );
329 if (msg->magic != MSG_MAGIC)
331 LeaveCriticalSection( &msg->cs );
332 return E_INVALIDARG;
335 switch (id)
337 case WS_MESSAGE_PROPERTY_STATE:
338 if (!buf || size != sizeof(msg->state)) hr = E_INVALIDARG;
339 else *(WS_MESSAGE_STATE *)buf = msg->state;
340 break;
342 case WS_MESSAGE_PROPERTY_HEAP:
343 if (!buf || size != sizeof(msg->heap)) hr = E_INVALIDARG;
344 else *(WS_HEAP **)buf = msg->heap;
345 break;
347 case WS_MESSAGE_PROPERTY_ENVELOPE_VERSION:
348 if (!buf || size != sizeof(msg->version_env)) hr = E_INVALIDARG;
349 else *(WS_ENVELOPE_VERSION *)buf = msg->version_env;
350 break;
352 case WS_MESSAGE_PROPERTY_ADDRESSING_VERSION:
353 if (!buf || size != sizeof(msg->version_addr)) hr = E_INVALIDARG;
354 else *(WS_ADDRESSING_VERSION *)buf = msg->version_addr;
355 break;
357 case WS_MESSAGE_PROPERTY_HEADER_BUFFER:
358 if (!buf || size != sizeof(msg->buf)) hr = E_INVALIDARG;
359 else *(WS_XML_BUFFER **)buf = msg->buf;
360 break;
362 case WS_MESSAGE_PROPERTY_BODY_READER:
363 if (!buf || size != sizeof(msg->reader_body)) hr = E_INVALIDARG;
364 else *(WS_XML_READER **)buf = msg->reader_body;
365 break;
367 case WS_MESSAGE_PROPERTY_BODY_WRITER:
368 if (!buf || size != sizeof(msg->writer_body)) hr = E_INVALIDARG;
369 else *(WS_XML_WRITER **)buf = msg->writer_body;
370 break;
372 case WS_MESSAGE_PROPERTY_IS_ADDRESSED:
373 if (msg->state < WS_MESSAGE_STATE_INITIALIZED) hr = WS_E_INVALID_OPERATION;
374 else *(BOOL *)buf = msg->is_addressed;
375 break;
377 default:
378 hr = prop_get( msg->prop, msg->prop_count, id, buf, size );
381 LeaveCriticalSection( &msg->cs );
382 return hr;
385 /**************************************************************************
386 * WsSetMessageProperty [webservices.@]
388 HRESULT WINAPI WsSetMessageProperty( WS_MESSAGE *handle, WS_MESSAGE_PROPERTY_ID id, const void *value,
389 ULONG size, WS_ERROR *error )
391 struct msg *msg = (struct msg *)handle;
392 HRESULT hr;
394 TRACE( "%p %u %p %u\n", handle, id, value, size );
395 if (error) FIXME( "ignoring error parameter\n" );
397 if (!msg) return E_INVALIDARG;
399 EnterCriticalSection( &msg->cs );
401 if (msg->magic != MSG_MAGIC)
403 LeaveCriticalSection( &msg->cs );
404 return E_INVALIDARG;
407 switch (id)
409 case WS_MESSAGE_PROPERTY_STATE:
410 case WS_MESSAGE_PROPERTY_ENVELOPE_VERSION:
411 case WS_MESSAGE_PROPERTY_ADDRESSING_VERSION:
412 case WS_MESSAGE_PROPERTY_IS_ADDRESSED:
413 if (msg->state < WS_MESSAGE_STATE_INITIALIZED) hr = WS_E_INVALID_OPERATION;
414 else hr = E_INVALIDARG;
415 break;
417 default:
418 hr = prop_set( msg->prop, msg->prop_count, id, value, size );
421 LeaveCriticalSection( &msg->cs );
422 return hr;
425 /**************************************************************************
426 * WsAddressMessage [webservices.@]
428 HRESULT WINAPI WsAddressMessage( WS_MESSAGE *handle, const WS_ENDPOINT_ADDRESS *addr, WS_ERROR *error )
430 struct msg *msg = (struct msg *)handle;
431 HRESULT hr = S_OK;
433 TRACE( "%p %p %p\n", handle, addr, error );
434 if (error) FIXME( "ignoring error parameter\n" );
435 if (addr && (addr->headers || addr->extensions || addr->identity))
437 FIXME( "headers, extensions or identity not supported\n" );
438 return E_NOTIMPL;
441 if (!msg) return E_INVALIDARG;
443 EnterCriticalSection( &msg->cs );
445 if (msg->magic != MSG_MAGIC)
447 LeaveCriticalSection( &msg->cs );
448 return E_INVALIDARG;
451 if (msg->state < WS_MESSAGE_STATE_INITIALIZED || msg->is_addressed)
453 LeaveCriticalSection( &msg->cs );
454 return WS_E_INVALID_OPERATION;
457 if (addr && addr->url.length)
459 if (!(msg->addr.chars = heap_alloc( addr->url.length * sizeof(WCHAR) ))) hr = E_OUTOFMEMORY;
460 else
462 memcpy( msg->addr.chars, addr->url.chars, addr->url.length * sizeof(WCHAR) );
463 msg->addr.length = addr->url.length;
467 if (hr == S_OK) msg->is_addressed = TRUE;
469 LeaveCriticalSection( &msg->cs );
470 return hr;
473 static const WS_XML_STRING *get_env_namespace( WS_ENVELOPE_VERSION version )
475 static const WS_XML_STRING namespaces[] =
477 {41, (BYTE *)"http://schemas.xmlsoap.org/soap/envelope/"},
478 {39, (BYTE *)"http://www.w3.org/2003/05/soap-envelope"},
479 {0, NULL},
482 if (version < WS_ENVELOPE_VERSION_SOAP_1_1 || version > WS_ENVELOPE_VERSION_NONE)
484 ERR( "unknown version %u\n", version );
485 return NULL;
488 return &namespaces[version - 1];
491 static const WS_XML_STRING *get_addr_namespace( WS_ADDRESSING_VERSION version )
493 static const WS_XML_STRING namespaces[] =
495 {48, (BYTE *)"http://schemas.xmlsoap.org/ws/2004/08/addressing"},
496 {36, (BYTE *)"http://www.w3.org/2005/08/addressing"},
497 {55, (BYTE *)"http://schemas.microsoft.com/ws/2005/05/addressing/none"},
500 if (version < WS_ADDRESSING_VERSION_0_9 || version > WS_ADDRESSING_VERSION_TRANSPORT)
502 ERR( "unknown version %u\n", version );
503 return NULL;
506 return &namespaces[version - 1];
509 static const WS_XML_STRING *get_header_name( WS_HEADER_TYPE type )
511 static const WS_XML_STRING headers[] =
513 {6, (BYTE *)"Action"},
514 {2, (BYTE *)"To"},
515 {9, (BYTE *)"MessageID"},
516 {9, (BYTE *)"RelatesTo"},
517 {4, (BYTE *)"From"},
518 {7, (BYTE *)"ReplyTo"},
519 {7, (BYTE *)"FaultTo"},
522 if (type < WS_ACTION_HEADER || type > WS_FAULT_TO_HEADER)
524 ERR( "unknown type %u\n", type );
525 return NULL;
528 return &headers[type - 1];
531 static HRESULT write_must_understand( WS_XML_WRITER *writer, const WS_XML_STRING *prefix, const WS_XML_STRING *ns )
533 static const WS_XML_STRING understand = {14, (BYTE *)"mustUnderstand"};
534 WS_XML_INT32_TEXT one = {{WS_XML_TEXT_TYPE_INT32}, 1};
535 HRESULT hr;
537 if ((hr = WsWriteStartAttribute( writer, prefix, &understand, ns, FALSE, NULL )) != S_OK) return hr;
538 if ((hr = WsWriteText( writer, &one.text, NULL )) != S_OK) return hr;
539 return WsWriteEndAttribute( writer, NULL );
542 static HRESULT write_action_header( WS_XML_WRITER *writer, const WS_XML_STRING *prefix_env,
543 const WS_XML_STRING *ns_env, const WS_XML_STRING *prefix_addr,
544 const WS_XML_STRING *ns_addr, const WS_XML_STRING *text )
546 WS_XML_UTF8_TEXT utf8 = {{WS_XML_TEXT_TYPE_UTF8}};
547 const WS_XML_STRING *action = get_header_name( WS_ACTION_HEADER );
548 HRESULT hr;
550 if (!text || !text->length) return S_OK;
551 utf8.value.length = text->length;
552 utf8.value.bytes = text->bytes;
554 if ((hr = WsWriteStartElement( writer, prefix_addr, action, ns_addr, NULL )) != S_OK) return hr;
555 if ((hr = write_must_understand( writer, prefix_env, ns_env )) != S_OK) return hr;
556 if ((hr = WsWriteText( writer, &utf8.text, NULL )) != S_OK) return hr;
557 return WsWriteEndElement( writer, NULL ); /* </a:Action> */
560 static HRESULT write_to_header( WS_XML_WRITER *writer, const WS_XML_STRING *prefix_env,
561 const WS_XML_STRING *ns_env, const WS_XML_STRING *prefix_addr,
562 const WS_XML_STRING *ns_addr, const WS_STRING *addr )
564 WS_XML_UTF16_TEXT utf16 = {{WS_XML_TEXT_TYPE_UTF16}, (BYTE *)addr->chars, addr->length * sizeof(WCHAR)};
565 const WS_XML_STRING *to = get_header_name( WS_TO_HEADER );
566 HRESULT hr;
568 if ((hr = WsWriteStartElement( writer, prefix_addr, to, ns_addr, NULL )) != S_OK) return hr;
569 if ((hr = write_must_understand( writer, prefix_env, ns_env )) != S_OK) return hr;
570 if ((hr = WsWriteText( writer, &utf16.text, NULL )) != S_OK) return hr;
571 return WsWriteEndElement( writer, NULL ); /* </a:To> */
574 static HRESULT write_replyto_header( WS_XML_WRITER *writer, const WS_XML_STRING *prefix_env,
575 const WS_XML_STRING *ns_env, const WS_XML_STRING *prefix_addr,
576 const WS_XML_STRING *ns_addr )
578 static const char anonymous[] = "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous";
579 WS_XML_UTF8_TEXT utf8 = {{WS_XML_TEXT_TYPE_UTF8}, {sizeof(anonymous) - 1, (BYTE *)anonymous}};
580 const WS_XML_STRING address = {7, (BYTE *)"Address"}, *replyto = get_header_name( WS_REPLY_TO_HEADER );
581 HRESULT hr;
583 if ((hr = WsWriteStartElement( writer, prefix_addr, replyto, ns_addr, NULL )) != S_OK) return hr;
584 if ((hr = WsWriteStartElement( writer, prefix_addr, &address, ns_addr, NULL )) != S_OK) return hr;
585 if ((hr = WsWriteText( writer, &utf8.text, NULL )) != S_OK) return hr;
586 if ((hr = WsWriteEndElement( writer, NULL )) != S_OK) return hr; /* </a:Address> */
587 return WsWriteEndElement( writer, NULL ); /* </a:ReplyTo> */
590 static HRESULT write_msgid_header( WS_XML_WRITER *writer, const WS_XML_STRING *prefix_env,
591 const WS_XML_STRING *ns_env, const WS_XML_STRING *prefix_addr,
592 const WS_XML_STRING *ns_addr, const GUID *guid )
594 WS_XML_UNIQUE_ID_TEXT id = {{WS_XML_TEXT_TYPE_UNIQUE_ID}, *guid};
595 const WS_XML_STRING *msgid = get_header_name( WS_MESSAGE_ID_HEADER );
596 HRESULT hr;
598 if ((hr = WsWriteStartElement( writer, prefix_addr, msgid, ns_addr, NULL )) != S_OK) return hr;
599 if ((hr = WsWriteText( writer, &id.text, NULL )) != S_OK) return hr;
600 return WsWriteEndElement( writer, NULL ); /* </a:MessageID> */
603 static HRESULT write_relatesto_header( WS_XML_WRITER *writer, const WS_XML_STRING *prefix_env,
604 const WS_XML_STRING *ns_env, const WS_XML_STRING *prefix_addr,
605 const WS_XML_STRING *ns_addr, const GUID *guid )
607 WS_XML_UNIQUE_ID_TEXT id = {{WS_XML_TEXT_TYPE_UNIQUE_ID}, *guid};
608 const WS_XML_STRING *relatesto = get_header_name( WS_RELATES_TO_HEADER );
609 HRESULT hr;
611 if ((hr = WsWriteStartElement( writer, prefix_addr, relatesto, ns_addr, NULL )) != S_OK) return hr;
612 if ((hr = WsWriteText( writer, &id.text, NULL )) != S_OK) return hr;
613 return WsWriteEndElement( writer, NULL ); /* </a:RelatesTo> */
616 static HRESULT write_headers( struct msg *msg, WS_XML_WRITER *writer, const WS_XML_STRING *prefix_env,
617 const WS_XML_STRING *ns_env, const WS_XML_STRING *prefix_addr,
618 const WS_XML_STRING *ns_addr )
620 static const WS_XML_STRING header = {6, (BYTE *)"Header"};
621 HRESULT hr;
622 ULONG i;
624 if ((hr = WsWriteXmlnsAttribute( writer, prefix_addr, ns_addr, FALSE, NULL )) != S_OK) return hr;
625 if ((hr = WsWriteStartElement( writer, prefix_env, &header, ns_env, NULL )) != S_OK) return hr;
627 if ((hr = write_action_header( writer, prefix_env, ns_env, prefix_addr, ns_addr, msg->action )) != S_OK)
628 return hr;
630 if (msg->init == WS_REPLY_MESSAGE)
632 if ((hr = write_relatesto_header( writer, prefix_env, ns_env, prefix_addr, ns_addr, &msg->id_req )) != S_OK)
633 return hr;
635 else if (msg->addr.length)
637 if ((hr = write_to_header( writer, prefix_env, ns_env, prefix_addr, ns_addr, &msg->addr )) != S_OK)
638 return hr;
640 else
642 if ((hr = write_msgid_header( writer, prefix_env, ns_env, prefix_addr, ns_addr, &msg->id )) != S_OK)
643 return hr;
644 if (msg->version_addr == WS_ADDRESSING_VERSION_0_9 &&
645 (hr = write_replyto_header( writer, prefix_env, ns_env, prefix_addr, ns_addr )) != S_OK) return hr;
648 for (i = 0; i < msg->header_count; i++)
650 if (msg->header[i]->mapped) continue;
651 if ((hr = WsWriteXmlBuffer( writer, msg->header[i]->u.buf, NULL )) != S_OK) return hr;
654 return WsWriteEndElement( writer, NULL ); /* </s:Header> */
657 static HRESULT write_headers_transport( struct msg *msg, WS_XML_WRITER *writer, const WS_XML_STRING *prefix,
658 const WS_XML_STRING *ns )
660 static const WS_XML_STRING header = {6, (BYTE *)"Header"};
661 HRESULT hr = S_OK;
662 ULONG i;
664 if ((msg->header_count || !msg->action) &&
665 (hr = WsWriteStartElement( writer, prefix, &header, ns, NULL )) != S_OK) return hr;
667 for (i = 0; i < msg->header_count; i++)
669 if (msg->header[i]->mapped) continue;
670 if ((hr = WsWriteXmlBuffer( writer, msg->header[i]->u.buf, NULL )) != S_OK) return hr;
673 if (msg->header_count || !msg->action) hr = WsWriteEndElement( writer, NULL ); /* </s:Header> */
674 return hr;
677 static HRESULT write_envelope_start( struct msg *msg, WS_XML_WRITER *writer )
679 static const WS_XML_STRING envelope = {8, (BYTE *)"Envelope"}, body = {4, (BYTE *)"Body"};
680 static const WS_XML_STRING prefix_s = {1, (BYTE *)"s"}, prefix_a = {1, (BYTE *)"a"};
681 const WS_XML_STRING *prefix_env = (msg->version_env == WS_ENVELOPE_VERSION_NONE) ? NULL : &prefix_s;
682 const WS_XML_STRING *prefix_addr = (msg->version_addr == WS_ADDRESSING_VERSION_TRANSPORT) ? NULL : &prefix_a;
683 const WS_XML_STRING *ns_env = get_env_namespace( msg->version_env );
684 const WS_XML_STRING *ns_addr = get_addr_namespace( msg->version_addr );
685 HRESULT hr;
687 if ((hr = WsWriteStartElement( writer, prefix_env, &envelope, ns_env, NULL )) != S_OK) return hr;
689 if (msg->version_addr == WS_ADDRESSING_VERSION_TRANSPORT)
690 hr = write_headers_transport( msg, writer, prefix_env, ns_env );
691 else
692 hr = write_headers( msg, writer, prefix_env, ns_env, prefix_addr, ns_addr );
693 if (hr != S_OK) return hr;
695 return WsWriteStartElement( writer, prefix_env, &body, ns_env, NULL ); /* <s:Body> */
698 static HRESULT write_envelope_end( WS_XML_WRITER *writer )
700 HRESULT hr;
701 if ((hr = WsWriteEndElement( writer, NULL )) != S_OK) return hr; /* </s:Body> */
702 return WsWriteEndElement( writer, NULL ); /* </s:Envelope> */
705 static HRESULT write_envelope( struct msg *msg )
707 HRESULT hr;
708 if (!msg->writer && (hr = WsCreateWriter( NULL, 0, &msg->writer, NULL )) != S_OK) return hr;
709 if (!msg->buf && (hr = WsCreateXmlBuffer( msg->heap, NULL, 0, &msg->buf, NULL )) != S_OK) return hr;
710 if ((hr = WsSetOutputToBuffer( msg->writer, msg->buf, NULL, 0, NULL )) != S_OK) return hr;
711 if ((hr = write_envelope_start( msg, msg->writer )) != S_OK) return hr;
712 return write_envelope_end( msg->writer );
715 /**************************************************************************
716 * WsWriteEnvelopeStart [webservices.@]
718 HRESULT WINAPI WsWriteEnvelopeStart( WS_MESSAGE *handle, WS_XML_WRITER *writer,
719 WS_MESSAGE_DONE_CALLBACK cb, void *state, WS_ERROR *error )
721 struct msg *msg = (struct msg *)handle;
722 HRESULT hr;
724 TRACE( "%p %p %p %p %p\n", handle, writer, cb, state, error );
725 if (error) FIXME( "ignoring error parameter\n" );
726 if (cb)
728 FIXME( "callback not supported\n" );
729 return E_NOTIMPL;
732 if (!msg || !writer) return E_INVALIDARG;
734 EnterCriticalSection( &msg->cs );
736 if (msg->magic != MSG_MAGIC)
738 LeaveCriticalSection( &msg->cs );
739 return E_INVALIDARG;
742 if (msg->state != WS_MESSAGE_STATE_INITIALIZED)
744 LeaveCriticalSection( &msg->cs );
745 return WS_E_INVALID_OPERATION;
748 if ((hr = write_envelope( msg )) != S_OK) goto done;
749 if ((hr = write_envelope_start( msg, writer )) != S_OK) goto done;
751 msg->writer_body = writer;
752 msg->state = WS_MESSAGE_STATE_WRITING;
754 done:
755 LeaveCriticalSection( &msg->cs );
756 return hr;
759 /**************************************************************************
760 * WsWriteEnvelopeEnd [webservices.@]
762 HRESULT WINAPI WsWriteEnvelopeEnd( WS_MESSAGE *handle, WS_ERROR *error )
764 struct msg *msg = (struct msg *)handle;
765 HRESULT hr;
767 TRACE( "%p %p\n", handle, error );
768 if (error) FIXME( "ignoring error parameter\n" );
770 if (!msg) return E_INVALIDARG;
772 EnterCriticalSection( &msg->cs );
774 if (msg->magic != MSG_MAGIC)
776 LeaveCriticalSection( &msg->cs );
777 return E_INVALIDARG;
780 if (msg->state != WS_MESSAGE_STATE_WRITING)
782 LeaveCriticalSection( &msg->cs );
783 return WS_E_INVALID_OPERATION;
786 if ((hr = write_envelope_end( msg->writer_body )) == S_OK) msg->state = WS_MESSAGE_STATE_DONE;
788 LeaveCriticalSection( &msg->cs );
789 return hr;
792 /**************************************************************************
793 * WsWriteBody [webservices.@]
795 HRESULT WINAPI WsWriteBody( WS_MESSAGE *handle, const WS_ELEMENT_DESCRIPTION *desc, WS_WRITE_OPTION option,
796 const void *value, ULONG size, WS_ERROR *error )
798 struct msg *msg = (struct msg *)handle;
799 HRESULT hr;
801 TRACE( "%p %p %08x %p %u %p\n", handle, desc, option, value, size, error );
802 if (error) FIXME( "ignoring error parameter\n" );
804 if (!msg || !desc) return E_INVALIDARG;
806 EnterCriticalSection( &msg->cs );
808 if (msg->magic != MSG_MAGIC)
810 LeaveCriticalSection( &msg->cs );
811 return E_INVALIDARG;
814 if (msg->state != WS_MESSAGE_STATE_WRITING)
816 LeaveCriticalSection( &msg->cs );
817 return WS_E_INVALID_OPERATION;
820 if (desc->elementLocalName &&
821 (hr = WsWriteStartElement( msg->writer_body, NULL, desc->elementLocalName, desc->elementNs,
822 NULL )) != S_OK) goto done;
824 if ((hr = WsWriteType( msg->writer_body, WS_ANY_ELEMENT_TYPE_MAPPING, desc->type, desc->typeDescription,
825 option, value, size, NULL )) != S_OK) goto done;
827 if (desc->elementLocalName) hr = WsWriteEndElement( msg->writer_body, NULL );
829 done:
830 LeaveCriticalSection( &msg->cs );
831 return hr;
834 static BOOL match_current_element( WS_XML_READER *reader, const WS_XML_STRING *localname )
836 const WS_XML_NODE *node;
837 const WS_XML_ELEMENT_NODE *elem;
839 if (WsGetReaderNode( reader, &node, NULL ) != S_OK) return FALSE;
840 if (node->nodeType != WS_XML_NODE_TYPE_ELEMENT) return FALSE;
841 elem = (const WS_XML_ELEMENT_NODE *)node;
842 return WsXmlStringEquals( elem->localName, localname, NULL ) == S_OK;
845 static HRESULT read_message_id( WS_XML_READER *reader, GUID *ret )
847 const WS_XML_NODE *node;
848 const WS_XML_TEXT_NODE *text;
849 const WS_XML_UNIQUE_ID_TEXT *id;
850 HRESULT hr;
852 if ((hr = WsReadNode( reader, NULL )) != S_OK) return hr;
853 if ((hr = WsGetReaderNode( reader, &node, NULL )) != S_OK) return hr;
854 if (node->nodeType != WS_XML_NODE_TYPE_TEXT) return WS_E_INVALID_FORMAT;
855 text = (const WS_XML_TEXT_NODE *)node;
856 if (text->text->textType != WS_XML_TEXT_TYPE_UNIQUE_ID)
858 FIXME( "unhandled text type %u\n", text->text->textType );
859 return E_NOTIMPL;
861 id = (const WS_XML_UNIQUE_ID_TEXT *)text->text;
862 *ret = id->value;
863 return S_OK;
866 static HRESULT read_envelope_start( struct msg *msg, WS_XML_READER *reader )
868 static const WS_XML_STRING envelope = {8, (BYTE *)"Envelope"}, body = {4, (BYTE *)"Body"};
869 static const WS_XML_STRING header = {6, (BYTE *)"Header"}, msgid = {9, (BYTE *)"MessageID"};
870 HRESULT hr;
872 if ((hr = WsReadNode( reader, NULL )) != S_OK) return hr;
873 if (!match_current_element( reader, &envelope )) return WS_E_INVALID_FORMAT;
874 if ((hr = WsReadNode( reader, NULL )) != S_OK) return hr;
875 if (match_current_element( reader, &header ))
877 for (;;)
879 if ((hr = WsReadNode( reader, NULL )) != S_OK) return hr;
880 if (match_current_element( reader, &msgid ) && (hr = read_message_id( reader, &msg->id_req )) != S_OK)
881 return hr;
882 if (match_current_element( reader, &body )) break;
885 if (!match_current_element( reader, &body )) return WS_E_INVALID_FORMAT;
886 return WsReadNode( reader, NULL );
889 /**************************************************************************
890 * WsReadEnvelopeStart [webservices.@]
892 HRESULT WINAPI WsReadEnvelopeStart( WS_MESSAGE *handle, WS_XML_READER *reader, WS_MESSAGE_DONE_CALLBACK cb,
893 void *state, WS_ERROR *error )
895 struct msg *msg = (struct msg *)handle;
896 HRESULT hr;
898 TRACE( "%p %p %p %p %p\n", handle, reader, cb, state, error );
899 if (error) FIXME( "ignoring error parameter\n" );
900 if (cb)
902 FIXME( "callback not supported\n" );
903 return E_NOTIMPL;
906 if (!msg || !reader) return E_INVALIDARG;
908 EnterCriticalSection( &msg->cs );
910 if (msg->magic != MSG_MAGIC)
912 LeaveCriticalSection( &msg->cs );
913 return E_INVALIDARG;
916 if (msg->state != WS_MESSAGE_STATE_EMPTY)
918 LeaveCriticalSection( &msg->cs );
919 return WS_E_INVALID_OPERATION;
922 if ((hr = read_envelope_start( msg, reader )) == S_OK &&
923 (hr = create_header_buffer( reader, msg->heap, &msg->buf )) == S_OK)
925 msg->reader_body = reader;
926 msg->state = WS_MESSAGE_STATE_READING;
929 LeaveCriticalSection( &msg->cs );
930 return hr;
933 static HRESULT read_envelope_end( WS_XML_READER *reader )
935 HRESULT hr;
936 if ((hr = WsReadEndElement( reader, NULL )) != S_OK) return hr; /* </s:Body> */
937 return WsReadEndElement( reader, NULL ); /* </s:Envelope> */
940 /**************************************************************************
941 * WsReadEnvelopeEnd [webservices.@]
943 HRESULT WINAPI WsReadEnvelopeEnd( WS_MESSAGE *handle, WS_ERROR *error )
945 struct msg *msg = (struct msg *)handle;
946 HRESULT hr;
948 TRACE( "%p %p\n", handle, error );
949 if (error) FIXME( "ignoring error parameter\n" );
951 if (!msg) return E_INVALIDARG;
953 EnterCriticalSection( &msg->cs );
955 if (msg->magic != MSG_MAGIC)
957 LeaveCriticalSection( &msg->cs );
958 return E_INVALIDARG;
961 if (msg->state != WS_MESSAGE_STATE_READING)
963 LeaveCriticalSection( &msg->cs );
964 return WS_E_INVALID_OPERATION;
967 if ((hr = read_envelope_end( msg->reader_body )) == S_OK) msg->state = WS_MESSAGE_STATE_DONE;
969 LeaveCriticalSection( &msg->cs );
970 return hr;
973 /**************************************************************************
974 * WsReadBody [webservices.@]
976 HRESULT WINAPI WsReadBody( WS_MESSAGE *handle, const WS_ELEMENT_DESCRIPTION *desc, WS_READ_OPTION option,
977 WS_HEAP *heap, void *value, ULONG size, WS_ERROR *error )
979 struct msg *msg = (struct msg *)handle;
980 HRESULT hr;
982 TRACE( "%p %p %08x %p %p %u %p\n", handle, desc, option, heap, value, size, error );
983 if (error) FIXME( "ignoring error parameter\n" );
985 if (!msg || !desc) return E_INVALIDARG;
987 EnterCriticalSection( &msg->cs );
989 if (msg->magic != MSG_MAGIC)
991 LeaveCriticalSection( &msg->cs );
992 return E_INVALIDARG;
995 if (msg->state != WS_MESSAGE_STATE_READING)
997 LeaveCriticalSection( &msg->cs );
998 return WS_E_INVALID_OPERATION;
1001 hr = WsReadElement( msg->reader_body, desc, option, heap, value, size, NULL );
1003 LeaveCriticalSection( &msg->cs );
1004 return hr;
1007 /**************************************************************************
1008 * WsInitializeMessage [webservices.@]
1010 HRESULT WINAPI WsInitializeMessage( WS_MESSAGE *handle, WS_MESSAGE_INITIALIZATION init,
1011 WS_MESSAGE *src_handle, WS_ERROR *error )
1013 struct msg *msg = (struct msg *)handle;
1014 HRESULT hr;
1016 TRACE( "%p %u %p %p\n", handle, init, src_handle, error );
1017 if (error) FIXME( "ignoring error parameter\n" );
1018 if (src_handle)
1020 FIXME( "src message not supported\n" );
1021 return E_NOTIMPL;
1024 if (!msg || init > WS_FAULT_MESSAGE) return E_INVALIDARG;
1026 EnterCriticalSection( &msg->cs );
1028 if (msg->magic != MSG_MAGIC)
1030 LeaveCriticalSection( &msg->cs );
1031 return E_INVALIDARG;
1034 if (msg->state >= WS_MESSAGE_STATE_INITIALIZED)
1036 LeaveCriticalSection( &msg->cs );
1037 return WS_E_INVALID_OPERATION;
1040 if ((hr = write_envelope( msg )) == S_OK)
1042 msg->init = init;
1043 msg->state = WS_MESSAGE_STATE_INITIALIZED;
1046 LeaveCriticalSection( &msg->cs );
1047 return hr;
1050 static HRESULT grow_header_array( struct msg *msg, ULONG size )
1052 struct header **tmp;
1053 if (size <= msg->header_size) return S_OK;
1054 if (!(tmp = heap_realloc( msg->header, 2 * msg->header_size * sizeof(struct header *) )))
1055 return E_OUTOFMEMORY;
1056 msg->header = tmp;
1057 msg->header_size *= 2;
1058 return S_OK;
1061 static struct header *alloc_header( WS_HEADER_TYPE type, BOOL mapped, const WS_XML_STRING *name,
1062 const WS_XML_STRING *ns )
1064 struct header *ret;
1065 if (!(ret = heap_alloc_zero( sizeof(*ret) ))) return NULL;
1066 if (name && name->length)
1068 if (!(ret->name.bytes = heap_alloc( name->length )))
1070 free_header( ret );
1071 return NULL;
1073 memcpy( ret->name.bytes, name->bytes, name->length );
1074 ret->name.length = name->length;
1076 if (ns && ns->length)
1078 if (!(ret->ns.bytes = heap_alloc( ns->length )))
1080 free_header( ret );
1081 return NULL;
1083 memcpy( ret->ns.bytes, ns->bytes, ns->length );
1084 ret->ns.length = ns->length;
1086 ret->type = type;
1087 ret->mapped = mapped;
1088 return ret;
1091 static HRESULT write_standard_header( struct msg *msg, WS_HEADER_TYPE type, WS_TYPE value_type,
1092 WS_WRITE_OPTION option, const void *value, ULONG size )
1094 static const WS_XML_STRING ns = {0, NULL};
1095 static const WS_XML_STRING prefix_s = {1, (BYTE *)"s"}, prefix_a = {1, (BYTE *)"a"};
1096 const WS_XML_STRING *prefix_env = (msg->version_env == WS_ENVELOPE_VERSION_NONE) ? NULL : &prefix_s;
1097 const WS_XML_STRING *prefix_addr = (msg->version_addr == WS_ADDRESSING_VERSION_TRANSPORT) ? NULL : &prefix_a;
1098 const WS_XML_STRING *localname = get_header_name( type );
1099 HRESULT hr;
1101 if ((hr = WsWriteStartElement( msg->writer, prefix_addr, localname, &ns, NULL )) != S_OK) return hr;
1102 if ((hr = write_must_understand( msg->writer, prefix_env, &ns )) != S_OK) return hr;
1103 if (msg->version_addr == WS_ADDRESSING_VERSION_TRANSPORT)
1105 const WS_XML_STRING *ns_addr = get_addr_namespace( WS_ADDRESSING_VERSION_TRANSPORT );
1106 if ((hr = WsWriteXmlnsAttribute( msg->writer, NULL, ns_addr, FALSE, NULL )) != S_OK) return hr;
1108 if ((hr = WsWriteType( msg->writer, WS_ELEMENT_CONTENT_TYPE_MAPPING, value_type, NULL, option, value, size,
1109 NULL )) != S_OK) return hr;
1110 return WsWriteEndElement( msg->writer, NULL );
1113 static HRESULT build_standard_header( struct msg *msg, WS_HEADER_TYPE type, WS_TYPE value_type,
1114 WS_WRITE_OPTION option, const void *value, ULONG size,
1115 struct header **ret )
1117 struct header *header;
1118 WS_XML_BUFFER *buf;
1119 HRESULT hr;
1121 if (!(header = alloc_header( type, FALSE, get_header_name(type), NULL ))) return E_OUTOFMEMORY;
1123 if (!msg->writer && (hr = WsCreateWriter( NULL, 0, &msg->writer, NULL )) != S_OK) goto done;
1124 if ((hr = WsCreateXmlBuffer( msg->heap, NULL, 0, &buf, NULL )) != S_OK) goto done;
1125 if ((hr = WsSetOutputToBuffer( msg->writer, buf, NULL, 0, NULL )) != S_OK) goto done;
1126 if ((hr = write_standard_header( msg, type, value_type, option, value, size )) != S_OK) goto done;
1128 header->u.buf = buf;
1130 done:
1131 if (hr != S_OK) free_header( header );
1132 else *ret = header;
1133 return hr;
1136 /**************************************************************************
1137 * WsSetHeader [webservices.@]
1139 HRESULT WINAPI WsSetHeader( WS_MESSAGE *handle, WS_HEADER_TYPE type, WS_TYPE value_type,
1140 WS_WRITE_OPTION option, const void *value, ULONG size, WS_ERROR *error )
1142 struct msg *msg = (struct msg *)handle;
1143 struct header *header;
1144 BOOL found = FALSE;
1145 HRESULT hr;
1146 ULONG i;
1148 TRACE( "%p %u %u %08x %p %u %p\n", handle, type, value_type, option, value, size, error );
1149 if (error) FIXME( "ignoring error parameter\n" );
1151 if (!msg || type < WS_ACTION_HEADER || type > WS_FAULT_TO_HEADER) return E_INVALIDARG;
1153 EnterCriticalSection( &msg->cs );
1155 if (msg->magic != MSG_MAGIC)
1157 LeaveCriticalSection( &msg->cs );
1158 return E_INVALIDARG;
1161 if (msg->state < WS_MESSAGE_STATE_INITIALIZED)
1163 LeaveCriticalSection( &msg->cs );
1164 return WS_E_INVALID_OPERATION;
1167 for (i = 0; i < msg->header_count; i++)
1169 if (msg->header[i]->type == type)
1171 found = TRUE;
1172 break;
1176 if (!found)
1178 if ((hr = grow_header_array( msg, msg->header_count + 1 )) != S_OK) goto done;
1179 i = msg->header_count;
1182 if ((hr = build_standard_header( msg, type, value_type, option, value, size, &header )) != S_OK)
1183 goto done;
1185 if (!found) msg->header_count++;
1186 else free_header( msg->header[i] );
1188 msg->header[i] = header;
1189 hr = write_envelope( msg );
1191 done:
1192 LeaveCriticalSection( &msg->cs );
1193 return hr;
1196 static HRESULT find_header( WS_XML_READER *reader, const WS_XML_STRING *localname, const WS_XML_STRING *ns )
1198 const WS_XML_NODE *node;
1199 const WS_XML_ELEMENT_NODE *elem;
1200 HRESULT hr;
1202 for (;;)
1204 if ((hr = WsReadNode( reader, NULL )) != S_OK) return hr;
1205 if ((hr = WsGetReaderNode( reader, &node, NULL )) != S_OK) return hr;
1206 if (node->nodeType == WS_XML_NODE_TYPE_EOF) return WS_E_INVALID_FORMAT;
1207 if (node->nodeType != WS_XML_NODE_TYPE_ELEMENT) continue;
1209 elem = (const WS_XML_ELEMENT_NODE *)node;
1210 if (WsXmlStringEquals( elem->localName, localname, NULL ) == S_OK &&
1211 WsXmlStringEquals( elem->ns, ns, NULL ) == S_OK) break;
1214 return S_OK;
1217 static HRESULT get_standard_header( struct msg *msg, WS_HEADER_TYPE type, WS_TYPE value_type,
1218 WS_READ_OPTION option, WS_HEAP *heap, void *value, ULONG size )
1220 const WS_XML_STRING *localname = get_header_name( type );
1221 const WS_XML_STRING *ns = get_addr_namespace( msg->version_addr );
1222 HRESULT hr;
1224 if (!heap) heap = msg->heap;
1225 if (!msg->reader && (hr = WsCreateReader( NULL, 0, &msg->reader, NULL )) != S_OK) return hr;
1226 if ((hr = WsSetInputToBuffer( msg->reader, msg->buf, NULL, 0, NULL )) != S_OK) return hr;
1228 if ((hr = find_header( msg->reader, localname, ns )) != S_OK) return hr;
1229 return read_header( msg->reader, localname, ns, value_type, NULL, option, heap, value, size );
1232 /**************************************************************************
1233 * WsGetHeader [webservices.@]
1235 HRESULT WINAPI WsGetHeader( WS_MESSAGE *handle, WS_HEADER_TYPE type, WS_TYPE value_type, WS_READ_OPTION option,
1236 WS_HEAP *heap, void *value, ULONG size, WS_ERROR *error )
1238 struct msg *msg = (struct msg *)handle;
1239 HRESULT hr;
1241 TRACE( "%p %u %u %08x %p %p %u %p\n", handle, type, value_type, option, heap, value, size, error );
1242 if (error) FIXME( "ignoring error parameter\n" );
1244 if (!msg || type < WS_ACTION_HEADER || type > WS_FAULT_TO_HEADER || option < WS_READ_REQUIRED_VALUE ||
1245 option > WS_READ_OPTIONAL_POINTER) return E_INVALIDARG;
1247 EnterCriticalSection( &msg->cs );
1249 if (msg->magic != MSG_MAGIC)
1251 LeaveCriticalSection( &msg->cs );
1252 return E_INVALIDARG;
1255 if (msg->state < WS_MESSAGE_STATE_INITIALIZED)
1257 LeaveCriticalSection( &msg->cs );
1258 return WS_E_INVALID_OPERATION;
1261 hr = get_standard_header( msg, type, value_type, option, heap, value, size );
1263 LeaveCriticalSection( &msg->cs );
1264 return hr;
1267 static void remove_header( struct msg *msg, ULONG i )
1269 free_header( msg->header[i] );
1270 memmove( &msg->header[i], &msg->header[i + 1], (msg->header_count - i - 1) * sizeof(struct header *) );
1271 msg->header_count--;
1274 /**************************************************************************
1275 * WsRemoveHeader [webservices.@]
1277 HRESULT WINAPI WsRemoveHeader( WS_MESSAGE *handle, WS_HEADER_TYPE type, WS_ERROR *error )
1279 struct msg *msg = (struct msg *)handle;
1280 BOOL removed = FALSE;
1281 HRESULT hr = S_OK;
1282 ULONG i;
1284 TRACE( "%p %u %p\n", handle, type, error );
1285 if (error) FIXME( "ignoring error parameter\n" );
1287 if (!msg) return E_INVALIDARG;
1289 EnterCriticalSection( &msg->cs );
1291 if (msg->magic != MSG_MAGIC)
1293 LeaveCriticalSection( &msg->cs );
1294 return E_INVALIDARG;
1297 if (msg->state < WS_MESSAGE_STATE_INITIALIZED)
1299 LeaveCriticalSection( &msg->cs );
1300 return WS_E_INVALID_OPERATION;
1303 if (type < WS_ACTION_HEADER || type > WS_FAULT_TO_HEADER)
1305 LeaveCriticalSection( &msg->cs );
1306 return E_INVALIDARG;
1309 for (i = 0; i < msg->header_count; i++)
1311 if (msg->header[i]->type == type)
1313 remove_header( msg, i );
1314 removed = TRUE;
1315 break;
1319 if (removed) hr = write_envelope( msg );
1321 LeaveCriticalSection( &msg->cs );
1322 return hr;
1325 static HRESULT build_mapped_header( const WS_XML_STRING *name, WS_TYPE type, WS_WRITE_OPTION option,
1326 const void *value, ULONG size, struct header **ret )
1328 struct header *header;
1330 if (!(header = alloc_header( 0, TRUE, name, NULL ))) return E_OUTOFMEMORY;
1331 switch (type)
1333 case WS_WSZ_TYPE:
1335 int len;
1336 const WCHAR *src;
1338 if (option != WS_WRITE_REQUIRED_POINTER || size != sizeof(WCHAR *))
1340 free_header( header );
1341 return E_INVALIDARG;
1343 src = *(const WCHAR **)value;
1344 len = WideCharToMultiByte( CP_UTF8, 0, src, -1, NULL, 0, NULL, NULL ) - 1;
1345 if (!(header->u.text = alloc_xml_string( NULL, len )))
1347 free_header( header );
1348 return E_OUTOFMEMORY;
1350 WideCharToMultiByte( CP_UTF8, 0, src, -1, (char *)header->u.text->bytes, len, NULL, NULL );
1351 break;
1353 case WS_XML_STRING_TYPE:
1355 const WS_XML_STRING *str = value;
1357 if (option != WS_WRITE_REQUIRED_VALUE)
1359 FIXME( "unhandled write option %u\n", option );
1360 free_header( header );
1361 return E_NOTIMPL;
1363 if (size != sizeof(*str))
1365 free_header( header );
1366 return E_INVALIDARG;
1368 if (!(header->u.text = alloc_xml_string( NULL, str->length )))
1370 free_header( header );
1371 return E_OUTOFMEMORY;
1373 memcpy( header->u.text->bytes, str->bytes, str->length );
1374 break;
1376 case WS_STRING_TYPE:
1378 int len;
1379 const WS_STRING *str = value;
1381 if (option != WS_WRITE_REQUIRED_VALUE)
1383 FIXME( "unhandled write option %u\n", option );
1384 free_header( header );
1385 return E_NOTIMPL;
1387 if (size != sizeof(*str))
1389 free_header( header );
1390 return E_INVALIDARG;
1392 len = WideCharToMultiByte( CP_UTF8, 0, str->chars, str->length, NULL, 0, NULL, NULL );
1393 if (!(header->u.text = alloc_xml_string( NULL, len )))
1395 free_header( header );
1396 return E_OUTOFMEMORY;
1398 WideCharToMultiByte( CP_UTF8, 0, str->chars, str->length, (char *)header->u.text->bytes,
1399 len, NULL, NULL );
1400 break;
1402 default:
1403 FIXME( "unhandled type %u\n", type );
1404 free_header( header );
1405 return E_NOTIMPL;
1408 *ret = header;
1409 return S_OK;
1412 /**************************************************************************
1413 * WsAddMappedHeader [webservices.@]
1415 HRESULT WINAPI WsAddMappedHeader( WS_MESSAGE *handle, const WS_XML_STRING *name, WS_TYPE type,
1416 WS_WRITE_OPTION option, const void *value, ULONG size, WS_ERROR *error )
1418 struct msg *msg = (struct msg *)handle;
1419 struct header *header;
1420 BOOL found = FALSE;
1421 HRESULT hr;
1422 ULONG i;
1424 TRACE( "%p %s %u %08x %p %u %p\n", handle, debugstr_xmlstr(name), type, option, value, size, error );
1425 if (error) FIXME( "ignoring error parameter\n" );
1427 if (!msg || !name) return E_INVALIDARG;
1429 EnterCriticalSection( &msg->cs );
1431 if (msg->magic != MSG_MAGIC)
1433 LeaveCriticalSection( &msg->cs );
1434 return E_INVALIDARG;
1437 if (msg->state < WS_MESSAGE_STATE_INITIALIZED)
1439 LeaveCriticalSection( &msg->cs );
1440 return WS_E_INVALID_OPERATION;
1443 for (i = 0; i < msg->header_count; i++)
1445 if (msg->header[i]->type || !msg->header[i]->mapped) continue;
1446 if (WsXmlStringEquals( name, &msg->header[i]->name, NULL ) == S_OK)
1448 found = TRUE;
1449 break;
1453 if (!found)
1455 if ((hr = grow_header_array( msg, msg->header_count + 1 )) != S_OK) goto done;
1456 i = msg->header_count;
1459 if ((hr = build_mapped_header( name, type, option, value, size, &header )) != S_OK) goto done;
1461 if (!found) msg->header_count++;
1462 else free_header( msg->header[i] );
1464 msg->header[i] = header;
1466 done:
1467 LeaveCriticalSection( &msg->cs );
1468 return hr;
1471 /**************************************************************************
1472 * WsRemoveMappedHeader [webservices.@]
1474 HRESULT WINAPI WsRemoveMappedHeader( WS_MESSAGE *handle, const WS_XML_STRING *name, WS_ERROR *error )
1476 struct msg *msg = (struct msg *)handle;
1477 ULONG i;
1479 TRACE( "%p %s %p\n", handle, debugstr_xmlstr(name), error );
1480 if (error) FIXME( "ignoring error parameter\n" );
1482 if (!msg || !name) return E_INVALIDARG;
1484 EnterCriticalSection( &msg->cs );
1486 if (msg->magic != MSG_MAGIC)
1488 LeaveCriticalSection( &msg->cs );
1489 return E_INVALIDARG;
1492 if (msg->state < WS_MESSAGE_STATE_INITIALIZED)
1494 LeaveCriticalSection( &msg->cs );
1495 return WS_E_INVALID_OPERATION;
1498 for (i = 0; i < msg->header_count; i++)
1500 if (msg->header[i]->type || !msg->header[i]->mapped) continue;
1501 if (WsXmlStringEquals( name, &msg->header[i]->name, NULL ) == S_OK)
1503 remove_header( msg, i );
1504 break;
1508 LeaveCriticalSection( &msg->cs );
1509 return S_OK;
1512 static HRESULT write_custom_header( WS_XML_WRITER *writer, const WS_XML_STRING *name, const WS_XML_STRING *ns,
1513 WS_TYPE type, const void *desc, WS_WRITE_OPTION option, const void *value,
1514 ULONG size )
1516 HRESULT hr;
1517 if ((hr = WsWriteStartElement( writer, NULL, name, ns, NULL )) != S_OK) return hr;
1518 if ((hr = WsWriteType( writer, WS_ELEMENT_CONTENT_TYPE_MAPPING, type, desc, option, value, size,
1519 NULL )) != S_OK) return hr;
1520 return WsWriteEndElement( writer, NULL );
1523 static HRESULT build_custom_header( struct msg *msg, const WS_XML_STRING *name, const WS_XML_STRING *ns,
1524 WS_TYPE type, const void *desc, WS_WRITE_OPTION option, const void *value,
1525 ULONG size, struct header **ret )
1527 struct header *header;
1528 WS_XML_BUFFER *buf;
1529 HRESULT hr;
1531 if (!(header = alloc_header( 0, FALSE, name, ns ))) return E_OUTOFMEMORY;
1533 if (!msg->writer && (hr = WsCreateWriter( NULL, 0, &msg->writer, NULL )) != S_OK) goto done;
1534 if ((hr = WsCreateXmlBuffer( msg->heap, NULL, 0, &buf, NULL )) != S_OK) goto done;
1535 if ((hr = WsSetOutputToBuffer( msg->writer, buf, NULL, 0, NULL )) != S_OK) goto done;
1536 if ((hr = write_custom_header( msg->writer, name, ns, type, desc, option, value, size )) != S_OK) goto done;
1538 header->u.buf = buf;
1540 done:
1541 if (hr != S_OK) free_header( header );
1542 else *ret = header;
1543 return hr;
1546 /**************************************************************************
1547 * WsAddCustomHeader [webservices.@]
1549 HRESULT WINAPI WsAddCustomHeader( WS_MESSAGE *handle, const WS_ELEMENT_DESCRIPTION *desc, WS_WRITE_OPTION option,
1550 const void *value, ULONG size, ULONG attrs, WS_ERROR *error )
1552 struct msg *msg = (struct msg *)handle;
1553 struct header *header;
1554 HRESULT hr;
1556 TRACE( "%p %p %08x %p %u %08x %p\n", handle, desc, option, value, size, attrs, error );
1557 if (error) FIXME( "ignoring error parameter\n" );
1559 if (!msg || !desc) return E_INVALIDARG;
1561 EnterCriticalSection( &msg->cs );
1563 if (msg->magic != MSG_MAGIC)
1565 LeaveCriticalSection( &msg->cs );
1566 return E_INVALIDARG;
1569 if (msg->state < WS_MESSAGE_STATE_INITIALIZED)
1571 LeaveCriticalSection( &msg->cs );
1572 return WS_E_INVALID_OPERATION;
1575 if ((hr = grow_header_array( msg, msg->header_count + 1 )) != S_OK) goto done;
1576 if ((hr = build_custom_header( msg, desc->elementLocalName, desc->elementNs, desc->type,
1577 desc->typeDescription, option, value, size, &header )) != S_OK) goto done;
1578 msg->header[msg->header_count++] = header;
1579 hr = write_envelope( msg );
1581 done:
1582 LeaveCriticalSection( &msg->cs );
1583 return hr;
1586 static HRESULT get_custom_header( struct msg *msg, const WS_ELEMENT_DESCRIPTION *desc, WS_READ_OPTION option,
1587 WS_HEAP *heap, void *value, ULONG size )
1589 HRESULT hr;
1590 if (!heap) heap = msg->heap;
1591 if (!msg->reader && (hr = WsCreateReader( NULL, 0, &msg->reader, NULL )) != S_OK) return hr;
1592 if ((hr = WsSetInputToBuffer( msg->reader, msg->buf, NULL, 0, NULL )) != S_OK) return hr;
1594 if ((hr = find_header( msg->reader, desc->elementLocalName, desc->elementNs )) != S_OK) return hr;
1595 return read_header( msg->reader, desc->elementLocalName, desc->elementNs, desc->type, desc->typeDescription,
1596 option, heap, value, size );
1599 /**************************************************************************
1600 * WsGetCustomHeader [webservices.@]
1602 HRESULT WINAPI WsGetCustomHeader( WS_MESSAGE *handle, const WS_ELEMENT_DESCRIPTION *desc,
1603 WS_REPEATING_HEADER_OPTION repeat_option, ULONG index, WS_READ_OPTION option,
1604 WS_HEAP *heap, void *value, ULONG size, ULONG *attrs, WS_ERROR *error )
1606 struct msg *msg = (struct msg *)handle;
1607 HRESULT hr;
1609 TRACE( "%p %p %08x %u %08x %p %p %u %p %p\n", handle, desc, repeat_option, index, option, heap, value,
1610 size, attrs, error );
1611 if (error) FIXME( "ignoring error parameter\n" );
1613 if (!msg || !desc || repeat_option < WS_REPEATING_HEADER || repeat_option > WS_SINGLETON_HEADER ||
1614 (repeat_option == WS_SINGLETON_HEADER && index)) return E_INVALIDARG;
1616 if (repeat_option == WS_REPEATING_HEADER)
1618 FIXME( "repeating header not supported\n" );
1619 return E_NOTIMPL;
1621 if (attrs)
1623 FIXME( "attributes not supported\n" );
1624 return E_NOTIMPL;
1627 EnterCriticalSection( &msg->cs );
1629 if (msg->magic != MSG_MAGIC)
1631 LeaveCriticalSection( &msg->cs );
1632 return E_INVALIDARG;
1635 if (msg->state < WS_MESSAGE_STATE_INITIALIZED)
1637 LeaveCriticalSection( &msg->cs );
1638 return WS_E_INVALID_OPERATION;
1641 hr = get_custom_header( msg, desc, option, heap, value, size );
1643 LeaveCriticalSection( &msg->cs );
1644 return hr;
1647 /**************************************************************************
1648 * WsRemoveCustomHeader [webservices.@]
1650 HRESULT WINAPI WsRemoveCustomHeader( WS_MESSAGE *handle, const WS_XML_STRING *name, const WS_XML_STRING *ns,
1651 WS_ERROR *error )
1653 struct msg *msg = (struct msg *)handle;
1654 BOOL removed = FALSE;
1655 HRESULT hr = S_OK;
1656 ULONG i;
1658 TRACE( "%p %s %s %p\n", handle, debugstr_xmlstr(name), debugstr_xmlstr(ns), error );
1659 if (error) FIXME( "ignoring error parameter\n" );
1661 if (!msg || !name || !ns) return E_INVALIDARG;
1663 EnterCriticalSection( &msg->cs );
1665 if (msg->magic != MSG_MAGIC)
1667 LeaveCriticalSection( &msg->cs );
1668 return E_INVALIDARG;
1671 if (msg->state < WS_MESSAGE_STATE_INITIALIZED)
1673 LeaveCriticalSection( &msg->cs );
1674 return WS_E_INVALID_OPERATION;
1677 for (i = 0; i < msg->header_count; i++)
1679 if (msg->header[i]->type || msg->header[i]->mapped) continue;
1680 if (WsXmlStringEquals( name, &msg->header[i]->name, NULL ) == S_OK &&
1681 WsXmlStringEquals( ns, &msg->header[i]->ns, NULL ) == S_OK)
1683 remove_header( msg, i );
1684 removed = TRUE;
1685 i--;
1689 if (removed) hr = write_envelope( msg );
1691 LeaveCriticalSection( &msg->cs );
1692 return hr;
1695 static WCHAR *build_http_header( const WCHAR *name, const WCHAR *value, ULONG *ret_len )
1697 int len_name = strlenW( name ), len_value = strlenW( value );
1698 WCHAR *ret = heap_alloc( (len_name + len_value) * sizeof(WCHAR) );
1700 if (!ret) return NULL;
1701 memcpy( ret, name, len_name * sizeof(WCHAR) );
1702 memcpy( ret + len_name, value, len_value * sizeof(WCHAR) );
1703 *ret_len = len_name + len_value;
1704 return ret;
1707 static inline HRESULT insert_http_header( HINTERNET req, const WCHAR *header, ULONG len, ULONG flags )
1709 if (WinHttpAddRequestHeaders( req, header, len, flags )) return S_OK;
1710 return HRESULT_FROM_WIN32( GetLastError() );
1713 HRESULT message_insert_http_headers( WS_MESSAGE *handle, HINTERNET req )
1715 static const WCHAR contenttypeW[] =
1716 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ',0};
1717 static const WCHAR soapxmlW[] =
1718 {'a','p','p','l','i','c','a','t','i','o','n','/','s','o','a','p','+','x','m','l',0};
1719 static const WCHAR textxmlW[] =
1720 {'t','e','x','t','/','x','m','l',0};
1721 static const WCHAR charsetW[] =
1722 {'c','h','a','r','s','e','t','=','u','t','f','-','8',0};
1723 struct msg *msg = (struct msg *)handle;
1724 HRESULT hr = E_OUTOFMEMORY;
1725 WCHAR *header = NULL, *buf;
1726 ULONG len;
1728 EnterCriticalSection( &msg->cs );
1730 if (msg->magic != MSG_MAGIC)
1732 LeaveCriticalSection( &msg->cs );
1733 return E_INVALIDARG;
1736 switch (msg->version_env)
1738 case WS_ENVELOPE_VERSION_SOAP_1_1:
1739 header = build_http_header( contenttypeW, textxmlW, &len );
1740 break;
1742 case WS_ENVELOPE_VERSION_SOAP_1_2:
1743 header = build_http_header( contenttypeW, soapxmlW, &len );
1744 break;
1746 default:
1747 FIXME( "unhandled envelope version %u\n", msg->version_env );
1748 hr = E_NOTIMPL;
1750 if (!header) goto done;
1752 if ((hr = insert_http_header( req, header, len, WINHTTP_ADDREQ_FLAG_ADD )) != S_OK) goto done;
1753 heap_free( header );
1755 hr = E_OUTOFMEMORY;
1756 if (!(header = build_http_header( contenttypeW, charsetW, &len ))) goto done;
1757 if ((hr = insert_http_header( req, header, len, WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON )) != S_OK)
1758 goto done;
1759 heap_free( header );
1760 header = NULL;
1762 switch (msg->version_env)
1764 case WS_ENVELOPE_VERSION_SOAP_1_1:
1766 static const WCHAR soapactionW[] = {'S','O','A','P','A','c','t','i','o','n',':',' ',0};
1768 if (!(len = MultiByteToWideChar( CP_UTF8, 0, (char *)msg->action->bytes, msg->action->length, NULL, 0 )))
1769 break;
1771 hr = E_OUTOFMEMORY;
1772 if (!(buf = heap_alloc( (len + 3) * sizeof(WCHAR) ))) goto done;
1773 buf[0] = '"';
1774 MultiByteToWideChar( CP_UTF8, 0, (char *)msg->action->bytes, msg->action->length, buf + 1, len );
1775 buf[len + 1] = '"';
1776 buf[len + 2] = 0;
1778 header = build_http_header( soapactionW, buf, &len );
1779 heap_free( buf );
1780 if (!header) goto done;
1782 hr = insert_http_header( req, header, len, WINHTTP_ADDREQ_FLAG_ADD );
1783 break;
1785 case WS_ENVELOPE_VERSION_SOAP_1_2:
1787 static const WCHAR actionW[] = {'a','c','t','i','o','n','=','"'};
1788 ULONG len_action = sizeof(actionW)/sizeof(actionW[0]);
1790 if (!(len = MultiByteToWideChar( CP_UTF8, 0, (char *)msg->action->bytes, msg->action->length, NULL, 0 )))
1791 break;
1793 hr = E_OUTOFMEMORY;
1794 if (!(buf = heap_alloc( (len + len_action + 2) * sizeof(WCHAR) ))) goto done;
1795 memcpy( buf, actionW, len_action * sizeof(WCHAR) );
1796 MultiByteToWideChar( CP_UTF8, 0, (char *)msg->action->bytes, msg->action->length, buf + len_action, len );
1797 len += len_action;
1798 buf[len++] = '"';
1799 buf[len] = 0;
1801 header = build_http_header( contenttypeW, buf, &len );
1802 heap_free( buf );
1803 if (!header) goto done;
1805 hr = insert_http_header( req, header, len, WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON );
1806 break;
1808 default:
1809 FIXME( "unhandled envelope version %u\n", msg->version_env );
1810 hr = E_NOTIMPL;
1813 done:
1814 heap_free( header );
1815 LeaveCriticalSection( &msg->cs );
1816 return hr;
1819 void message_set_send_context( WS_MESSAGE *handle, const WS_PROXY_MESSAGE_CALLBACK_CONTEXT *ctx )
1821 struct msg *msg = (struct msg *)handle;
1823 EnterCriticalSection( &msg->cs );
1825 if (msg->magic != MSG_MAGIC)
1827 LeaveCriticalSection( &msg->cs );
1828 return;
1831 msg->ctx_send.callback = ctx->callback;
1832 msg->ctx_send.state = ctx->state;
1834 LeaveCriticalSection( &msg->cs );
1837 void message_set_receive_context( WS_MESSAGE *handle, const WS_PROXY_MESSAGE_CALLBACK_CONTEXT *ctx )
1839 struct msg *msg = (struct msg *)handle;
1841 EnterCriticalSection( &msg->cs );
1843 if (msg->magic != MSG_MAGIC)
1845 LeaveCriticalSection( &msg->cs );
1846 return;
1849 msg->ctx_receive.callback = ctx->callback;
1850 msg->ctx_receive.state = ctx->state;
1852 LeaveCriticalSection( &msg->cs );
1855 void message_do_send_callback( WS_MESSAGE *handle )
1857 struct msg *msg = (struct msg *)handle;
1859 EnterCriticalSection( &msg->cs );
1861 if (msg->magic != MSG_MAGIC)
1863 LeaveCriticalSection( &msg->cs );
1864 return;
1867 if (msg->ctx_send.callback)
1869 HRESULT hr;
1870 TRACE( "executing callback %p\n", msg->ctx_send.callback );
1871 hr = msg->ctx_send.callback( handle, msg->heap, msg->ctx_send.state, NULL );
1872 TRACE( "callback %p returned %08x\n", msg->ctx_send.callback, hr );
1875 LeaveCriticalSection( &msg->cs );
1878 void message_do_receive_callback( WS_MESSAGE *handle )
1880 struct msg *msg = (struct msg *)handle;
1882 EnterCriticalSection( &msg->cs );
1884 if (msg->magic != MSG_MAGIC)
1886 LeaveCriticalSection( &msg->cs );
1887 return;
1890 if (msg->ctx_receive.callback)
1892 HRESULT hr;
1893 TRACE( "executing callback %p\n", msg->ctx_receive.callback );
1894 hr = msg->ctx_receive.callback( handle, msg->heap, msg->ctx_receive.state, NULL );
1895 TRACE( "callback %p returned %08x\n", msg->ctx_receive.callback, hr );
1898 LeaveCriticalSection( &msg->cs );
1901 HRESULT message_set_action( WS_MESSAGE *handle, const WS_XML_STRING *action )
1903 struct msg *msg = (struct msg *)handle;
1904 HRESULT hr = S_OK;
1906 EnterCriticalSection( &msg->cs );
1908 if (msg->magic != MSG_MAGIC)
1910 LeaveCriticalSection( &msg->cs );
1911 return E_INVALIDARG;
1914 if (!action || !action->length)
1916 free_xml_string( msg->action );
1917 msg->action = NULL;
1919 else
1921 WS_XML_STRING *str;
1922 if (!(str = dup_xml_string( action, FALSE ))) hr = E_OUTOFMEMORY;
1923 else
1925 free_xml_string( msg->action );
1926 msg->action = str;
1930 LeaveCriticalSection( &msg->cs );
1931 return hr;
1934 HRESULT message_get_id( WS_MESSAGE *handle, GUID *id )
1936 struct msg *msg = (struct msg *)handle;
1937 HRESULT hr = S_OK;
1939 EnterCriticalSection( &msg->cs );
1941 if (msg->magic != MSG_MAGIC)
1943 LeaveCriticalSection( &msg->cs );
1944 return E_INVALIDARG;
1947 *id = msg->id_req;
1949 LeaveCriticalSection( &msg->cs );
1950 return hr;
1953 HRESULT message_set_request_id( WS_MESSAGE *handle, const GUID *id )
1955 struct msg *msg = (struct msg *)handle;
1956 HRESULT hr = S_OK;
1958 EnterCriticalSection( &msg->cs );
1960 if (msg->magic != MSG_MAGIC)
1962 LeaveCriticalSection( &msg->cs );
1963 return E_INVALIDARG;
1966 msg->id_req = *id;
1968 LeaveCriticalSection( &msg->cs );
1969 return hr;