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
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 msg_props
[] =
34 { sizeof(WS_MESSAGE_STATE
), TRUE
}, /* WS_MESSAGE_PROPERTY_STATE */
35 { sizeof(WS_HEAP
*), TRUE
}, /* WS_MESSAGE_PROPERTY_HEAP */
36 { sizeof(WS_ENVELOPE_VERSION
), TRUE
}, /* WS_MESSAGE_PROPERTY_ENVELOPE_VERSION */
37 { sizeof(WS_ADDRESSING_VERSION
), TRUE
}, /* WS_MESSAGE_PROPERTY_ADDRESSING_VERSION */
38 { sizeof(WS_XML_BUFFER
*), TRUE
}, /* WS_MESSAGE_PROPERTY_HEADER_BUFFER */
39 { sizeof(WS_XML_NODE_POSITION
*), TRUE
}, /* WS_MESSAGE_PROPERTY_HEADER_POSITION */
40 { sizeof(WS_XML_READER
*), TRUE
}, /* WS_MESSAGE_PROPERTY_BODY_READER */
41 { sizeof(WS_XML_WRITER
*), TRUE
}, /* WS_MESSAGE_PROPERTY_BODY_WRITER */
42 { sizeof(BOOL
), TRUE
}, /* WS_MESSAGE_PROPERTY_IS_ADDRESSED */
47 WS_MESSAGE_STATE state
;
48 WS_ENVELOPE_VERSION version_env
;
49 WS_ADDRESSING_VERSION version_addr
;
52 struct prop prop
[sizeof(msg_props
)/sizeof(msg_props
[0])];
55 static struct msg
*alloc_msg(void)
57 static const ULONG count
= sizeof(msg_props
)/sizeof(msg_props
[0]);
59 ULONG size
= sizeof(*ret
) + prop_size( msg_props
, count
);
61 if (!(ret
= heap_alloc_zero( size
))) return NULL
;
62 ret
->state
= WS_MESSAGE_STATE_EMPTY
;
63 prop_init( msg_props
, count
, ret
->prop
, &ret
[1] );
64 ret
->prop_count
= count
;
68 static void free_msg( struct msg
*msg
)
73 static HRESULT
create_msg( WS_ENVELOPE_VERSION env_version
, WS_ADDRESSING_VERSION addr_version
,
74 const WS_MESSAGE_PROPERTY
*properties
, ULONG count
, WS_MESSAGE
**handle
)
80 if (!(msg
= alloc_msg())) return E_OUTOFMEMORY
;
82 for (i
= 0; i
< count
; i
++)
84 if (properties
[i
].id
== WS_MESSAGE_PROPERTY_ENVELOPE_VERSION
||
85 properties
[i
].id
== WS_MESSAGE_PROPERTY_ADDRESSING_VERSION
)
90 hr
= prop_set( msg
->prop
, msg
->prop_count
, properties
[i
].id
, properties
[i
].value
,
91 properties
[i
].valueSize
);
99 msg
->version_env
= env_version
;
100 msg
->version_addr
= addr_version
;
102 *handle
= (WS_MESSAGE
*)msg
;
106 /**************************************************************************
107 * WsCreateMessage [webservices.@]
109 HRESULT WINAPI
WsCreateMessage( WS_ENVELOPE_VERSION env_version
, WS_ADDRESSING_VERSION addr_version
,
110 const WS_MESSAGE_PROPERTY
*properties
, ULONG count
, WS_MESSAGE
**handle
,
113 TRACE( "%u %u %p %u %p %p\n", env_version
, addr_version
, properties
, count
, handle
, error
);
114 if (error
) FIXME( "ignoring error parameter\n" );
116 if (!handle
|| !env_version
|| !addr_version
) return E_INVALIDARG
;
117 return create_msg( env_version
, addr_version
, properties
, count
, handle
);
120 /**************************************************************************
121 * WsCreateMessageForChannel [webservices.@]
123 HRESULT WINAPI
WsCreateMessageForChannel( WS_CHANNEL
*channel_handle
, const WS_MESSAGE_PROPERTY
*properties
,
124 ULONG count
, WS_MESSAGE
**handle
, WS_ERROR
*error
)
126 WS_ENVELOPE_VERSION version_env
;
127 WS_ADDRESSING_VERSION version_addr
;
130 TRACE( "%p %p %u %p %p\n", channel_handle
, properties
, count
, handle
, error
);
131 if (error
) FIXME( "ignoring error parameter\n" );
133 if (!channel_handle
|| !handle
) return E_INVALIDARG
;
135 if ((hr
= WsGetChannelProperty( channel_handle
, WS_CHANNEL_PROPERTY_ENVELOPE_VERSION
, &version_env
,
136 sizeof(version_env
), NULL
)) != S_OK
|| !version_env
)
137 version_env
= WS_ENVELOPE_VERSION_SOAP_1_2
;
139 if ((hr
= WsGetChannelProperty( channel_handle
, WS_CHANNEL_PROPERTY_ADDRESSING_VERSION
, &version_addr
,
140 sizeof(version_addr
), NULL
)) != S_OK
|| !version_addr
)
141 version_addr
= WS_ADDRESSING_VERSION_1_0
;
143 return create_msg( version_env
, version_addr
, properties
, count
, handle
);
146 /**************************************************************************
147 * WsFreeMessage [webservices.@]
149 void WINAPI
WsFreeMessage( WS_MESSAGE
*handle
)
151 struct msg
*msg
= (struct msg
*)handle
;
153 TRACE( "%p\n", handle
);
157 /**************************************************************************
158 * WsGetMessageProperty [webservices.@]
160 HRESULT WINAPI
WsGetMessageProperty( WS_MESSAGE
*handle
, WS_MESSAGE_PROPERTY_ID id
, void *buf
,
161 ULONG size
, WS_ERROR
*error
)
163 struct msg
*msg
= (struct msg
*)handle
;
165 TRACE( "%p %u %p %u %p\n", handle
, id
, buf
, size
, error
);
166 if (error
) FIXME( "ignoring error parameter\n" );
168 if (!handle
) return E_INVALIDARG
;
172 case WS_MESSAGE_PROPERTY_STATE
:
173 if (!buf
|| size
!= sizeof(msg
->state
)) return E_INVALIDARG
;
174 *(WS_MESSAGE_STATE
*)buf
= msg
->state
;
177 case WS_MESSAGE_PROPERTY_ENVELOPE_VERSION
:
178 if (!buf
|| size
!= sizeof(msg
->version_env
)) return E_INVALIDARG
;
179 *(WS_ENVELOPE_VERSION
*)buf
= msg
->version_env
;
182 case WS_MESSAGE_PROPERTY_ADDRESSING_VERSION
:
183 if (!buf
|| size
!= sizeof(msg
->version_addr
)) return E_INVALIDARG
;
184 *(WS_ADDRESSING_VERSION
*)buf
= msg
->version_addr
;
187 case WS_MESSAGE_PROPERTY_IS_ADDRESSED
:
188 if (msg
->state
< WS_MESSAGE_STATE_INITIALIZED
) return WS_E_INVALID_OPERATION
;
189 *(BOOL
*)buf
= msg
->is_addressed
;
193 return prop_get( msg
->prop
, msg
->prop_count
, id
, buf
, size
);
197 /**************************************************************************
198 * WsSetMessageProperty [webservices.@]
200 HRESULT WINAPI
WsSetMessageProperty( WS_MESSAGE
*handle
, WS_MESSAGE_PROPERTY_ID id
, const void *value
,
201 ULONG size
, WS_ERROR
*error
)
203 struct msg
*msg
= (struct msg
*)handle
;
205 TRACE( "%p %u %p %u\n", handle
, id
, value
, size
);
206 if (error
) FIXME( "ignoring error parameter\n" );
208 if (!handle
) return E_INVALIDARG
;
212 case WS_MESSAGE_PROPERTY_STATE
:
213 case WS_MESSAGE_PROPERTY_ENVELOPE_VERSION
:
214 case WS_MESSAGE_PROPERTY_ADDRESSING_VERSION
:
215 case WS_MESSAGE_PROPERTY_IS_ADDRESSED
:
216 if (msg
->state
< WS_MESSAGE_STATE_INITIALIZED
) return WS_E_INVALID_OPERATION
;
222 return prop_set( msg
->prop
, msg
->prop_count
, id
, value
, size
);