You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1526 lines
58 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. wsaapi.c
  3. WS-Addressing plugin.
  4. gSOAP XML Web services tools
  5. Copyright (C) 2000-2008, Robert van Engelen, Genivia Inc., All Rights Reserved.
  6. This part of the software is released under one of the following licenses:
  7. GPL, the gSOAP public license, or Genivia's license for commercial use.
  8. --------------------------------------------------------------------------------
  9. gSOAP public license.
  10. The contents of this file are subject to the gSOAP Public License Version 1.3
  11. (the "License"); you may not use this file except in compliance with the
  12. License. You may obtain a copy of the License at
  13. http://www.cs.fsu.edu/~engelen/soaplicense.html
  14. Software distributed under the License is distributed on an "AS IS" basis,
  15. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. for the specific language governing rights and limitations under the License.
  17. The Initial Developer of the Original Code is Robert A. van Engelen.
  18. Copyright (C) 2000-2008, Robert van Engelen, Genivia Inc., All Rights Reserved.
  19. --------------------------------------------------------------------------------
  20. GPL license.
  21. This program is free software; you can redistribute it and/or modify it under
  22. the terms of the GNU General Public License as published by the Free Software
  23. Foundation; either version 2 of the License, or (at your option) any later
  24. version.
  25. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  26. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  27. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  28. You should have received a copy of the GNU General Public License along with
  29. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  30. Place, Suite 330, Boston, MA 02111-1307 USA
  31. Author contact information:
  32. engelen@genivia.com / engelen@acm.org
  33. This program is released under the GPL with the additional exemption that
  34. compiling, linking, and/or using OpenSSL is allowed.
  35. --------------------------------------------------------------------------------
  36. A commercial use license is available from Genivia, Inc., contact@genivia.com
  37. --------------------------------------------------------------------------------
  38. */
  39. /**
  40. @mainpage
  41. - @ref wsa_0 documents the wsa plugin for WS-Addressing (2003/2004/2005
  42. standards) support.
  43. */
  44. /**
  45. @page wsa_0 The wsa plugin for client applications and stand-alone services
  46. @section wsa_1 WS-Addressing Setup
  47. The material in this section relates to the WS-Addressing specification.
  48. To use the wsa plugin:
  49. -# Run wsdl2h -t typemap.dat on a WSDL of a service that requires WS-Addressing
  50. headers. The typemap.dat file included in the gSOAP package is used to
  51. recognize and translate Addressing header blocks.
  52. -# Run soapcpp2 -a on the header file produced by wsdl2h. To enable
  53. addressing-based service operation selection, you MUST use soapcpp2 option
  54. -a. This allows the service to dispatch methods based on the WS-Addressing
  55. action information header value (when the wsa plugin is registered).
  56. -# (Re-)compile and link stdsoap2.c/pp or libgsoap, (dom.c/pp when needed),
  57. wsaapi.c and the soapcpp2-generated source files.
  58. -# Use the wsa plugin API functions described below.
  59. An example wsa client/server application can be found in samples/wsa.
  60. A gSOAP service definitions header file with a "wsa import" to support
  61. WS-Addressing is automatically generated by wsdl2h for a set of WSDLs that use
  62. WS-Addressing. The wsdl2h-generated header file should be further processed by
  63. soapcpp2 to generate the binding code. The wsaapi.h and wsaapi.c implement the
  64. WS-Addressing API described in this document.
  65. A wsdl2h-generated service definitions header file might include the following
  66. imports:
  67. @code
  68. #import "soap12.h"
  69. #import "wsa.h" // or wsa3.h (2003/03), wsa4.h (2004/03), wsa5.h (2005/03)
  70. @endcode
  71. The wsa.h header file is imported from import/wsa.h when soapcpp2 is run on
  72. this file. The wsa.h import can be manually added to enable WS-Addressing when
  73. needed. The gSOAP service definitions header file is processed with soapcpp2 to
  74. generate the client-side and/or server-side binding code.
  75. Note that the wsa.h, wsa3.h, wsa4.h, and wsa5.h header files are located in the
  76. import directory of the gSOAP package. These files define the WS-Addressing
  77. information header elements and types. The soap12.h header file enables SOAP
  78. 1.2 messaging.
  79. For developers: the WS-Addressing header blocks in wsa.h (and others) were
  80. generated from the WS-Addressing schema with the wsdl2h tool and
  81. WS/WS-typemap.dat as follows:
  82. @code
  83. > wsdl2h -cegy -o wsa.h -t WS/WS-typemap.dat WS/WS-Addressing.xsd
  84. @endcode
  85. Refer to wsa.h for more details.
  86. @section wsa_2 Client-side Usage
  87. @subsection wsa_2_1 Constructing WS-Addressing Information Headers
  88. To associate WS-Addressing information headers with service operations, the
  89. SOAP Header struct SOAP_ENV__Header must have been defined and for each service
  90. operation that uses WS-Addressing method-header-part directives should be used
  91. in the gSOAP service definitions header file as follows:
  92. @code
  93. #import "wsa.h"
  94. //gsoap ns service method-header-part: example wsa__MessageID
  95. //gsoap ns service method-header-part: example wsa__RelatesTo
  96. //gsoap ns service method-header-part: example wsa__From
  97. //gsoap ns service method-header-part: example wsa__ReplyTo
  98. //gsoap ns service method-header-part: example wsa__FaultTo
  99. //gsoap ns service method-header-part: example wsa__To
  100. //gsoap ns service method-header-part: example wsa__Action
  101. //gsoap ns service method-action: example urn:example/examplePort/example
  102. int ns__example(char *in, struct ns__exampleResponse *out);
  103. @endcode
  104. Note that the use of wsa versions determines the wsa prefix, e.g. use wsa5 for
  105. the latest WS-Addressing as in wsa5__MessageID.
  106. In the client-side code, the WS-Addressing information headers are set with
  107. soap_wsa_request() by passing an optional message UUID string, a mandatory
  108. destination address URI string, and a mandatory request action URI string. The
  109. wsa plugin should be registered with the current soap struct context. An
  110. optional source address information header can be added with
  111. soap_wsa_add_From() (must be invoked after the soap_wsa_request call).
  112. For example:
  113. @code
  114. #include "wsaapi.h"
  115. soap_register_plugin(soap, soap_wsa);
  116. if (soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction))
  117. || soap_wsa_add_From(soap, FromAddress)) // optional: add a 'From' address
  118. ... // error: out of memory
  119. if (soap_call_ns__example(soap, ToAddress, NULL, ...))
  120. soap_print_fault(soap, stderr); // an error occurred
  121. else
  122. // process the response
  123. @endcode
  124. To generate a UUID for the RequestMessageID, use:
  125. @code
  126. const char *RequestMessageID = soap_wsa_rand_uuid(soap);
  127. @endcode
  128. @subsection wsa_2_2 Information Headers for Relaying Server Responses
  129. To relay the response to another destination, the WS-Addressing ReplyTo
  130. information header is added with soap_wsa_add_ReplyTo() by passing a reply
  131. address URI string. The service returns HTTP 202 ACCEPTED to the client when
  132. the response message relay was successful.
  133. For example:
  134. @code
  135. #include "wsaapi.h"
  136. soap_register_plugin(soap, soap_wsa);
  137. if (soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction)
  138. || soap_wsa_add_From(soap, FromAddress) // optional: add a 'From' address
  139. || soap_wsa_add_ReplyTo(soap, ReplyToAddress))
  140. ... // error: out of memory
  141. if (soap_call_ns__example(soap, ToAddress, NULL, ...))
  142. {
  143. if (soap->error == 202) // HTTP ACCEPTED
  144. printf("Request was accepted and results were forwarded\n");
  145. else
  146. soap_print_fault(soap, stderr); // an error occurred
  147. }
  148. else
  149. // unexpected OK: for some reason the response was not relayed
  150. @endcode
  151. Note: the response message will be relayed when the From address is absent or
  152. different than the ReplyTo address
  153. @subsection wsa_2_3 Information Headers for Relaying Server Faults
  154. To relay a server fault message to another destination, the WS-Addressing
  155. FaultTo information header is added with soap_wsa_add_FaultTo() by passing a
  156. relay address URI string. The service returns HTTP 202 ACCEPTED to the client
  157. when the fault was relayed.
  158. For example:
  159. @code
  160. #include "wsaapi.h"
  161. soap_register_plugin(soap, soap_wsa);
  162. if (soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction)
  163. || soap_wsa_add_From(soap, FromAddress) // optional: add a 'From' address
  164. || soap_wsa_add_FaultTo(soap, FaultToAddress))
  165. ... // error: out of memory
  166. if (soap_call_ns__example(soap, ToAddress, NULL, ...))
  167. {
  168. if (soap->error == 202) // HTTP ACCEPTED
  169. printf("A fault occurred and the fault details were forwarded\n");
  170. else
  171. soap_print_fault(soap, stderr); // a connection error occurred
  172. }
  173. else
  174. // process response
  175. @endcode
  176. Note that the call can still return a fault, such as a connection error when
  177. the service is not responding. In addition to the fault relay, the responses
  178. can be relayed with soap_wsa_add_ReplyTo().
  179. @subsection wsa_2_4 Error Handling
  180. SOAP and HTTP errors set the soap->error attribute, as shown in this example:
  181. @code
  182. if (soap_call_ns__example(soap, ToAddress, NULL, ...))
  183. {
  184. if (soap->error == 202) // HTTP ACCEPTED
  185. printf("A fault occurred and the fault details were forwarded\n");
  186. else
  187. soap_print_fault(soap, stderr); // a connection error occurred
  188. }
  189. else
  190. // process response
  191. @endcode
  192. When a WS-Addressing error occurred, the wsa error code is stored in the SOAP
  193. Fault Subcode field. This information can be retrieved with:
  194. @code
  195. wsa__FaultSubcodeValues fault;
  196. if (soap_wsa_check_fault(soap, &fault))
  197. {
  198. switch (fault)
  199. {
  200. case wsa__InvalidMessageInformationHeader: ...
  201. case wsa__MessageInformationHeaderRequired: ...
  202. case wsa__DestinationUreachable: ...
  203. case wsa__ActionNotSupported: ...
  204. case wsa__EndpointUnavailable: ...
  205. }
  206. }
  207. @endcode
  208. When using wsa5.h, please refer to the standards and fault codes for this
  209. implementation. For the wsa5.h 2005/03 standard, several faults have an
  210. additional parameter (SOAP Fault detail):
  211. @code
  212. wsa5__FaultCodesType fault;
  213. char *info;
  214. if (soap_wsa_check_fault(soap, &fault, &info))
  215. {
  216. switch (fault)
  217. {
  218. case wsa5__InvalidAddressingHeader:
  219. if (info)
  220. printf("The invalid addressing header element is %s\n", info);
  221. ...
  222. }
  223. }
  224. @endcode
  225. @subsection wsa_2_5 Combining WS-Addressing with WS-Security
  226. WS-Security can be combined with WS-Addressing. To sign WS-Addressing header
  227. blocks, use the soap_wsse_set_wsu_id() WSSE-plugin call to set the wsu:Id
  228. attribute and signing of these attributed elements. For example, suppose we use
  229. WS-Addressing 2005:
  230. @code
  231. #include "wsaapi.h"
  232. #include "wsseapi.h"
  233. soap_register_plugin(soap, soap_wsa);
  234. soap_register_plugin(soap, soap_wsse);
  235. soap_wsse_set_wsu_id(soap, "wsa5:From wsa5:To wsa5:ReplyTo wsa5:FaultTo wsa5:Action");
  236. if (soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction)
  237. || soap_wsa_add_From(soap, FromAddress) // optional: add a 'From' address
  238. || soap_wsa_add_FaultTo(soap, FaultToAddress))
  239. ... // error: out of memory
  240. if (soap_call_ns__example(soap, ToAddress, NULL, ...))
  241. ... // error
  242. @endcode
  243. Note: soap_wsse_set_wsu_id() should only be set once. Each new call overrides
  244. the previous.
  245. For more details on WS-Security, please see the
  246. <a href="../../wsse/html/index.html">WSSE plugin documentation</a>.
  247. @section wsa_3 Server-side Usage
  248. The wsa plugin should be registered with:
  249. @code
  250. soap_register_plugin(soap, soap_wsa);
  251. @endcode
  252. Once the plugin is registered, the soap_bind(), soap_accept(), and soap_serve()
  253. functions can be called to process requests and semi-automatically handle the
  254. WS-Addressing header blocks.
  255. Important: to dispatch service operations based on the WS-Addressing wsa:Action
  256. information header, you must use soapcpp2 option -a. The generates a new
  257. dispatcher (in soapServer.c) based on the action value.
  258. A service operation implementation should use soap_wsa_check() at the start of
  259. its execution to verify the validity of the WS-Addressing information headers
  260. in the SOAP request message. To allow response message to be automatically
  261. relayed based on the ReplyTo information header, the service operation should
  262. return soap_wsa_reply() with an optional message UUID string and a mandatory
  263. response action string. The response action string is documented in the
  264. wsdl2h-generated .h file for this service operation.
  265. For example:
  266. @code
  267. int ns__example(struct soap *soap, char *in, struct ns__exampleResponse *out)
  268. { if (soap_wsa_check(soap))
  269. return soap->error;
  270. // ... service logic
  271. return soap_wsa_reply(soap, ResponseMessageID, ResponseAction);
  272. }
  273. @endcode
  274. To return a SOAP fault that is automatically relayed to a fault service based
  275. on the FaultTo information header, the soap_wsa_sender_fault(),
  276. soap_wsa_receiver_fault(), soap_wsa_sender_fault_subcode(), and
  277. soap_wsa_receiver_fault_subcode() functions should be used instead of the
  278. usual soap_sender_fault(), soap_receiver_fault(), soap_sender_fault_subcode(),
  279. and soap_receiver_fault_subcode(), respectively. In case a Action must be
  280. associated with a SOAP Fault, use the soap_wsa_sender_fault_subcode_action()
  281. and soap_wsa_receiver_fault_subcode_action() functions to set the WS-Addressing
  282. Action (and HTTP SOAP Action header as well).
  283. For example, the following service operation illustrates the use of
  284. soap_wsa_check() to verify and process WS-Addressing header blocks and
  285. soap_wsA_reply() to enable responses to be relayed as per ReplyTo address in
  286. the WS-Addressing header:
  287. @code
  288. int ns__example(struct soap *soap, char *in, struct ns__exampleResponse *out)
  289. { if (soap_wsa_check(soap))
  290. return soap->error;
  291. // ... service logic
  292. // ... an error occurred, need to return fault possibly to fault service:
  293. return soap_wsa_sender_fault(soap, "Exception in service operation", NULL);
  294. // ... normal execution continues
  295. return soap_wsa_reply(soap, ResponseMessageID, ResponseAction);
  296. }
  297. @endcode
  298. @section wsa_4 HTTPS Server-side Usage
  299. To enable HTTPS (SSL/TSL) servers, compile the sources with -DWITH_OPENSSL (and
  300. link with libgsoapssl, libssl, and libcrypto). Because WS-Addressing may relay
  301. messages over HTTPS as a sender (client), you must initialize the SSL context
  302. for server and client uses. Therefore, the context must have access to all the
  303. certificates need to verify the authenticity of the ReplyTo and FaultTo HTTPS
  304. servers. To do so, use the following SSL initialization before soap_bind():
  305. @code
  306. struct soap *soap = soap_new();
  307. if (soap_ssl_server_context(soap,
  308. SOAP_SSL_DEFAULT,
  309. "server.pem", // the keyfile (server should authenticate)
  310. "password", // password to read the key file
  311. "cacert.pem", // cacert file to store trusted certificates (role as client)
  312. NULL, // optional capath
  313. NULL, // DH file name or DH param key len bits, when NULL use RSA
  314. NULL, // file with random data to seed randomness
  315. "myserver" // unique server identification for SSL session cache
  316. ))
  317. { soap_print_fault(soap, stderr);
  318. ...
  319. }
  320. soap->bind_flags = SO_REUSEADDR;
  321. if (!soap_valid_socket(soap_bind(soap, NULL, port, 100)))
  322. { soap_print_fault(soap, stderr);
  323. ...
  324. }
  325. @endcode
  326. @section wsa_5 Implementing a Server for Handling ReplyTo Response Messages
  327. To implement a separate server for handling relayed SOAP response messages
  328. based on the ReplyTo information header in the request message, the gSOAP
  329. header file should include a one-way service operation for the response
  330. message. These one-way response service operations are automatically generated
  331. with wsdl2h option -b.
  332. For example, suppose a service operation returns an exampleResponse message. We
  333. declare the one-way exampleResponse operation as follows:
  334. @code
  335. #import "wsa.h"
  336. //gsoap ns service method-header-part: exampleResult wsa__MessageID
  337. //gsoap ns service method-header-part: exampleResult wsa__RelatesTo
  338. //gsoap ns service method-header-part: exampleResult wsa__From
  339. //gsoap ns service method-header-part: exampleResult wsa__ReplyTo
  340. //gsoap ns service method-header-part: exampleResult wsa__FaultTo
  341. //gsoap ns service method-header-part: exampleResult wsa__To
  342. //gsoap ns service method-header-part: exampleResult wsa__Action
  343. //gsoap ns service method-action: exampleResult urn:example/examplePort/exampleResponse
  344. int ns__exampleResponse(char *out, void);
  345. @endcode
  346. Note that the action information is important, because it is used by the
  347. service dispatcher (assuming soapcpp2 option -a is used).
  348. The implementation in the server code uses soap_wsa_check() to check the
  349. presense and validity of the WS-Addressing information header in the message.
  350. The soap_send_empty_response() function should be used to return an
  351. acknowledgment HTTP header with HTTP 202 ACCEPTED to the sender:
  352. @code
  353. int ns__exampleResponse(struct soap *soap, char *out)
  354. { if (soap_wsa_check(soap))
  355. return soap_send_empty_response(soap, 500); // HTTP 500 Internal Server Error
  356. // ... service logic
  357. return soap_send_empty_response(soap, SOAP_OK); // HTTP 202 ACCEPTED
  358. }
  359. @endcode
  360. @section wsa_6 Implementing a Server for Handling FaultTo Fault Messages
  361. To implement a separate server for handling relayed SOAP fault messages based
  362. on the FaultTo information header in the request message, the gSOAP header file
  363. for soapcpp2 should include a SOAP fault service operation. This operation
  364. accepts fault messages that are relayed by other services.
  365. Basically, we use a trick to generate the SOAP-ENV:Fault struct via a one-way
  366. service operation. This allows us both to implement a one-way service operation
  367. that accepts faults and to automatically generate the fault struct for fault
  368. data storage and manipulation.
  369. The fault operation in the WS-Addressing files (wsa5.h etc.) is declared as
  370. follows (here shown for the 2004/08 standard):
  371. @code
  372. //gsoap SOAP_ENV service method-action: Fault http://schemas.xmlsoap.org/ws/2004/08/addressing/fault
  373. int SOAP_ENV__Fault
  374. ( _QName faultcode, // SOAP 1.1
  375. char *faultstring, // SOAP 1.1
  376. char *faultactor, // SOAP 1.1
  377. struct SOAP_ENV__Detail *detail, // SOAP 1.1
  378. struct SOAP_ENV__Code *SOAP_ENV__Code, // SOAP 1.2
  379. struct SOAP_ENV__Reason *SOAP_ENV__Reason, // SOAP 1.2
  380. char *SOAP_ENV__Node, // SOAP 1.2
  381. char *SOAP_ENV__Role, // SOAP 1.2
  382. struct SOAP_ENV__Detail *SOAP_ENV__Detail, // SOAP 1.2
  383. void
  384. );
  385. @endcode
  386. Because each service operation has a struct to hold its input parameters, we
  387. automatically generate the (original) SOAP_ENV__Fault struct on the fly!
  388. It is important to associate the wsa fault action with this operation as shown
  389. above.
  390. The implementation of the Fault service operation in your server code should be
  391. something like:
  392. @code
  393. int SOAP_ENV__Fault(struct soap *soap, char *faultcode, char *faultstring, char *faultactor, struct SOAP_ENV__Detail *detail, struct SOAP_ENV__Code *SOAP_ENV__Code, struct SOAP_ENV__Reason *SOAP_ENV__Reason, char *SOAP_ENV__Node, char *SOAP_ENV__Role, struct SOAP_ENV__Detail *SOAP_ENV__Detail)
  394. {
  395. ... = faultcode; // SOAP 1.1 fault code string (QName)
  396. ... = faultstring; // SOAP 1.1 fault string
  397. ... = faultactor; // SOAP 1.1 fault actor string
  398. ... = detail; // SOAP 1.1 fault detail struct
  399. ... = SOAP_ENV__Code; // SOAP 1.2 fault code struct
  400. ... = SOAP_ENV__Reason; // SOAP 1.2 reason struct
  401. ... = SOAP_ENV__Node; // SOAP 1.2 node string
  402. ... = SOAP_ENV__Role; // SOAP 1.2 role string
  403. ... = SOAP_ENV__Detail; // SOAP 1.2 detail struct
  404. return SOAP_OK;
  405. }
  406. @endcode
  407. Note that SOAP 1.1 or SOAP 1.2 parameters are set based on the 1.1/1.2
  408. messaging requirements.
  409. */
  410. #include "wsaapi.h"
  411. #ifdef __cplusplus
  412. extern "C" {
  413. #endif
  414. /** Plugin identification for plugin registry */
  415. const char soap_wsa_id[] = SOAP_WSA_ID;
  416. #if defined(SOAP_WSA_2003)
  417. /** Anonymous Reply/To endpoint address */
  418. const char *soap_wsa_anonymousURI = "http://schemas.xmlsoap.org/ws/2003/03/addressing/role/anonymous";
  419. /** Specifies no Reply endpoint address (no reply) */
  420. const char *soap_wsa_noneURI = "addressing/none not supported";
  421. const char *soap_wsa_faultAction = "http://schemas.xmlsoap.org/ws/2003/03/addressing/fault";
  422. #elif defined(SOAP_WSA_2004)
  423. /** Anonymous Reply/To endpoint address */
  424. const char *soap_wsa_anonymousURI = "http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous";
  425. /** Specifies no Reply endpoint address (no reply) */
  426. const char *soap_wsa_noneURI = "addressing/none not supported";
  427. const char *soap_wsa_faultAction = "http://schemas.xmlsoap.org/ws/2004/03/addressing/fault";
  428. #elif defined(SOAP_WSA_2005)
  429. /** Anonymous Reply/To endpoint address */
  430. const char *soap_wsa_anonymousURI = "http://www.w3.org/2005/08/addressing/anonymous";
  431. /** Specifies no Reply endpoint address (no reply) */
  432. const char *soap_wsa_noneURI = "http://www.w3.org/2005/08/addressing/none";
  433. const char *soap_wsa_faultAction = "http://www.w3.org/2005/08/addressing/soap/fault";
  434. #else
  435. /** Anonymous Reply/To endpoint address */
  436. const char *soap_wsa_anonymousURI = "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous";
  437. /** Specifies no Reply endpoint address (no reply) */
  438. const char *soap_wsa_noneURI = "addressing/none not supported";
  439. const char *soap_wsa_faultAction = "http://schemas.xmlsoap.org/ws/2004/08/addressing/fault";
  440. #endif
  441. /** anonymous URI of 2004 and 2005 schemas */
  442. const char *soap_wsa_allAnonymousURI = "http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous http://www.w3.org/2005/08/addressing/anonymous";
  443. /******************************************************************************\
  444. *
  445. * Static protos
  446. *
  447. \******************************************************************************/
  448. static int soap_wsa_init(struct soap *soap, struct soap_wsa_data *data);
  449. static void soap_wsa_delete(struct soap *soap, struct soap_plugin *p);
  450. static int soap_wsa_header(struct soap *soap);
  451. static void soap_wsa_set_error(struct soap *soap, const char **c, const char **s);
  452. static int soap_wsa_response(struct soap *soap, int status, size_t count);
  453. static int soap_wsa_disconnect(struct soap *soap);
  454. static int soap_wsa_alloc_header(struct soap *soap);
  455. /******************************************************************************\
  456. *
  457. * UUID
  458. *
  459. \******************************************************************************/
  460. /**
  461. @fn const char *soap_wsa_rand_uuid(struct soap *soap)
  462. @brief Generates a random UUID (UUID algorithm version 4). Compile all source
  463. codes with -DWITH_OPENSSL for better randomness results.
  464. @param soap context
  465. @return UUID "urn:uuid:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
  466. */
  467. const char*
  468. soap_wsa_rand_uuid(struct soap *soap)
  469. { const int uuidlen = 48;
  470. char *uuid = (char*)soap_malloc(soap, uuidlen);
  471. int r1, r2, r3, r4;
  472. #ifdef WITH_OPENSSL
  473. r1 = soap_random;
  474. r2 = soap_random;
  475. #else
  476. static int k = 0xFACEB00B;
  477. int lo = k % 127773;
  478. int hi = k / 127773;
  479. # ifdef HAVE_GETTIMEOFDAY
  480. struct timeval tv;
  481. gettimeofday(&tv, NULL);
  482. r1 = 10000000 * tv.tv_sec + tv.tv_usec;
  483. #else
  484. r1 = (int)time(NULL);
  485. # endif
  486. k = 16807 * lo - 2836 * hi;
  487. if (k <= 0)
  488. k += 0x7FFFFFFF;
  489. r2 = k;
  490. k &= 0x8FFFFFFF;
  491. r2 += *(int*)soap->buf;
  492. #endif
  493. r3 = soap_random;
  494. r4 = soap_random;
  495. #ifdef HAVE_SNPRINTF
  496. soap_snprintf(uuid, uuidlen, "urn:uuid:%8.8x-%4.4hx-4%3.3hx-%4.4hx-%4.4hx%8.8x", r1, (short)(r2 >> 16), ((short)r2 >> 4) & 0x0FFF, ((short)(r3 >> 16) & 0x3FFF) | 0x8000, (short)r3, r4);
  497. #else
  498. sprintf(uuid, "urn:uuid:%8.8x-%4.4hx-4%3.3hx-%4.4hx-%4.4hx%8.8x", r1, (short)(r2 >> 16), ((short)r2 >> 4) & 0x0FFF, ((short)(r3 >> 16) & 0x3FFF) | 0x8000, (short)r3, r4);
  499. #endif
  500. DBGFUN1("soap_wsa_rand_uuid", "%s", uuid);
  501. return uuid;
  502. }
  503. /******************************************************************************\
  504. *
  505. * Client-side Request
  506. *
  507. \******************************************************************************/
  508. /**
  509. @fn int soap_wsa_request(struct soap *soap, const char *id, const char *to, const char *action)
  510. @brief Sets the WS-Addressing information header for the next request message
  511. with MessageID (optional), To (optional), and Action (required).
  512. @param soap context
  513. @param[in] id is the message ID (optional)
  514. @param[in] to is the target endpoint (optional, set to anonymous when NULL)
  515. @param[in] action is the target action (required)
  516. @return SOAP_OK or error
  517. Note: use soap_wsa_add_From, soap_wsa_add_ReplyTo, soap_wsa_add_FaultTo to add
  518. other addressing fields following this function call.
  519. */
  520. int
  521. soap_wsa_request(struct soap *soap, const char *id, const char *to, const char *action)
  522. { DBGFUN3("soap_wsa_request", "id=%s", id?id:"(null)", "to=%s", to?to:"(null)", "action=%s", action?action:"(null)");
  523. if (soap_wsa_alloc_header(soap))
  524. return soap->error;
  525. soap->header->SOAP_WSA(MessageID) = soap_strdup(soap, id);
  526. if (to)
  527. soap->header->SOAP_WSA(To) = soap_strdup(soap, to);
  528. else /* this is optional */
  529. soap->header->SOAP_WSA(To) = (char*)soap_wsa_anonymousURI;
  530. soap->header->SOAP_WSA(Action) = soap_strdup(soap, action);
  531. soap->header->SOAP_WSA(RelatesTo) = NULL;
  532. soap->header->SOAP_WSA(From) = NULL;
  533. soap->header->SOAP_WSA(FaultTo) = NULL;
  534. soap_wsa_add_ReplyTo(soap, NULL);
  535. return soap_wsa_check(soap);
  536. }
  537. /**
  538. @fn int soap_wsa_add_From(struct soap *soap, const char *from)
  539. @brief Sets WS-Addressing From header for request message.
  540. @param soap context
  541. @param[in] from endpoint URI
  542. @return SOAP_OK or SOAP_ERR
  543. Use soap_wsa_request to populate the WS-Addressing header first.
  544. */
  545. int
  546. soap_wsa_add_From(struct soap *soap, const char *from)
  547. { if (!soap->header)
  548. return SOAP_ERR;
  549. soap->header->SOAP_WSA(From) = (SOAP_WSA_(,From)*)soap_malloc(soap, sizeof(SOAP_WSA_(,From)));
  550. SOAP_WSA_(soap_default,EndpointReferenceType)(soap, soap->header->SOAP_WSA(From));
  551. soap->header->SOAP_WSA(From)->Address = soap_strdup(soap, from);
  552. return SOAP_OK;
  553. }
  554. /**
  555. @fn int soap_wsa_add_NoReply(struct soap *soap)
  556. @brief Sets WS-Addressing ReplyTo header to 'none' (no reply)
  557. @param soap context
  558. @return SOAP_OK or SOAP_ERR
  559. Note: WS-Addressing 2005/08 standard.
  560. Use soap_wsa_request to populate the WS-Addressing header.
  561. */
  562. int
  563. soap_wsa_add_NoReply(struct soap *soap)
  564. { return soap_wsa_add_ReplyTo(soap, soap_wsa_noneURI);
  565. }
  566. /**
  567. @fn int soap_wsa_add_ReplyTo(struct soap *soap, const char *replyTo)
  568. @brief Sets WS-Addressing ReplyTo header for request message.
  569. @param soap context
  570. @param[in] replyTo endpoint URI or NULL for anonymous
  571. @return SOAP_OK or SOAP_ERR
  572. Use soap_wsa_request to populate the WS-Addressing header.
  573. */
  574. int
  575. soap_wsa_add_ReplyTo(struct soap *soap, const char *replyTo)
  576. { if (!soap->header)
  577. return SOAP_ERR;
  578. #ifndef SOAP_WSA_2005
  579. if (!replyTo)
  580. replyTo = soap_wsa_anonymousURI;
  581. #endif
  582. if (replyTo)
  583. { soap->header->SOAP_WSA(ReplyTo) = (SOAP_WSA_(,ReplyTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,ReplyTo)));
  584. SOAP_WSA_(soap_default,EndpointReferenceType)(soap, soap->header->SOAP_WSA(ReplyTo));
  585. soap->header->SOAP_WSA(ReplyTo)->Address = soap_strdup(soap, replyTo);
  586. }
  587. else
  588. soap->header->SOAP_WSA(ReplyTo) = NULL;
  589. return SOAP_OK;
  590. }
  591. /**
  592. @fn int soap_wsa_add_FaultTo(struct soap *soap, const char *faultTo)
  593. @brief Sets WS-Addressing FaultTo header for request message.
  594. @param soap context
  595. @param[in] faultTo endpoint URI or NULL for remove faultTo
  596. @return SOAP_OK or SOAP_ERR
  597. Use soap_wsa_request to populate the WS-Addressing header first.
  598. */
  599. int
  600. soap_wsa_add_FaultTo(struct soap *soap, const char *faultTo)
  601. { if (!soap->header)
  602. return SOAP_ERR;
  603. if (faultTo)
  604. { soap->header->SOAP_WSA(FaultTo) = (SOAP_WSA_(,FaultTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,FaultTo)));
  605. SOAP_WSA_(soap_default,EndpointReferenceType)(soap, soap->header->SOAP_WSA(FaultTo));
  606. soap->header->SOAP_WSA(FaultTo)->Address = soap_strdup(soap, faultTo);
  607. }
  608. else
  609. soap->header->SOAP_WSA(FaultTo) = NULL;
  610. return SOAP_OK;
  611. }
  612. /**
  613. @fn int soap_wsa_add_RelatesTo(struct soap *soap, const char *relatesTo)
  614. @brief Sets WS-Addressing RelatesTo header.
  615. @param soap context
  616. @param[in] relatesTo endpoint URI
  617. @return SOAP_OK or SOAP_ERR
  618. Use soap_wsa_request to populate the WS-Addressing header.
  619. */
  620. int
  621. soap_wsa_add_RelatesTo(struct soap *soap, const char *relatesTo)
  622. { if (!soap->header)
  623. return SOAP_ERR;
  624. if (relatesTo)
  625. { soap->header->SOAP_WSA(RelatesTo) = (SOAP_WSA_(,RelatesTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,RelatesTo)));
  626. SOAP_WSA_(soap_default_,RelatesTo)(soap, soap->header->SOAP_WSA(RelatesTo));
  627. soap->header->SOAP_WSA(RelatesTo)->__item = soap_strdup(soap, relatesTo);
  628. }
  629. return SOAP_OK;
  630. }
  631. /**
  632. @fn const char *soap_wsa_From(struct soap *soap)
  633. @brief Returns WS-Addressing From header.
  634. @param soap context
  635. @return From string or NULL
  636. */
  637. const char*
  638. soap_wsa_From(struct soap *soap)
  639. { if (!soap->header || !soap->header->SOAP_WSA(From))
  640. return NULL;
  641. return soap->header->SOAP_WSA(From)->Address;
  642. }
  643. /**
  644. @fn const char *soap_wsa_ReplyTo(struct soap *soap)
  645. @brief Returns WS-Addressing ReplyTo header.
  646. @param soap context
  647. @return From string or NULL
  648. */
  649. const char*
  650. soap_wsa_ReplyTo(struct soap *soap)
  651. { if (!soap->header || !soap->header->SOAP_WSA(ReplyTo))
  652. return NULL;
  653. return soap->header->SOAP_WSA(ReplyTo)->Address;
  654. }
  655. /**
  656. @fn const char *soap_wsa_FaultTo(struct soap *soap)
  657. @brief Returns WS-Addressing FaultTo header.
  658. @param soap context
  659. @return From string or NULL
  660. */
  661. const char*
  662. soap_wsa_FaultTo(struct soap *soap)
  663. { if (!soap->header || !soap->header->SOAP_WSA(FaultTo))
  664. return NULL;
  665. return soap->header->SOAP_WSA(FaultTo)->Address;
  666. }
  667. /**
  668. @fn const char *soap_wsa_RelatesTo(struct soap *soap)
  669. @brief Returns WS-Addressing RelatesTo header.
  670. @param soap context
  671. @return From string or NULL
  672. */
  673. const char*
  674. soap_wsa_RelatesTo(struct soap *soap)
  675. { if (!soap->header || !soap->header->SOAP_WSA(RelatesTo))
  676. return NULL;
  677. return soap->header->SOAP_WSA(RelatesTo)->__item;
  678. }
  679. /******************************************************************************\
  680. *
  681. * Server-side Check and Reply
  682. *
  683. \******************************************************************************/
  684. /**
  685. @fn int soap_wsa_check(struct soap *soap)
  686. @brief Checks the presence and validity of WS-Addressing information headers.
  687. @param soap context
  688. @return SOAP_OK or fault
  689. */
  690. int
  691. soap_wsa_check(struct soap *soap)
  692. { DBGFUN("soap_wsa_check");
  693. if (!soap->header || !soap->header->SOAP_WSA(Action))
  694. #if defined(SOAP_WSA_2005)
  695. return soap_wsa_error(soap, wsa5__MessageAddressingHeaderRequired, NULL);
  696. #elif defined(SOAP_WSA_2003)
  697. return soap_wsa_error(soap, "WS-Addressing header missing");
  698. #else
  699. return soap_wsa_error(soap, SOAP_WSA(MessageInformationHeaderRequired));
  700. #endif
  701. return SOAP_OK;
  702. }
  703. /**
  704. @fn int soap_wsa_reply(struct soap *soap, const char *id, const char *action)
  705. @brief Sets WS-Addressing header fields for server response. Automatically
  706. relays the response to the ReplyTo address (when ReplyTo != to From and ReplyTo
  707. != 'none') and returns HTTP 202 Accept to sender when relay was successful.
  708. @param soap context
  709. @param[in] id is the messageID (optional)
  710. @param[in] action is the target action (required)
  711. @return SOAP_OK or fault
  712. */
  713. int
  714. soap_wsa_reply(struct soap *soap, const char *id, const char *action)
  715. { struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  716. struct SOAP_ENV__Header *oldheader, *newheader;
  717. DBGFUN1("soap_wsa_reply", "action=%s", action?action:"(null)");
  718. if (!data)
  719. return soap->error = SOAP_PLUGIN_ERROR;
  720. oldheader = soap->header;
  721. soap->header = NULL;
  722. /* if endpoint address for reply is 'none' return immediately and STOP engine */
  723. if (oldheader && oldheader->SOAP_WSA(ReplyTo) && oldheader->SOAP_WSA(ReplyTo)->Address && !strcmp(oldheader->SOAP_WSA(ReplyTo)->Address, soap_wsa_noneURI))
  724. return soap_send_empty_response(soap, SOAP_OK);
  725. /* allocate a new header */
  726. if (soap_wsa_alloc_header(soap))
  727. return soap->error;
  728. newheader = soap->header;
  729. /* copy members to new header, except WSA data */
  730. if (oldheader)
  731. *newheader = *oldheader;
  732. newheader->SOAP_WSA(MessageID) = soap_strdup(soap, id);
  733. newheader->SOAP_WSA(Action) = soap_strdup(soap, action);
  734. newheader->SOAP_WSA(RelatesTo) = NULL;
  735. newheader->SOAP_WSA(From) = NULL;
  736. newheader->SOAP_WSA(To) = NULL;
  737. newheader->SOAP_WSA(ReplyTo) = NULL;
  738. newheader->SOAP_WSA(FaultTo) = NULL;
  739. /* check current header content */
  740. if (oldheader && oldheader->SOAP_WSA(MessageID))
  741. { newheader->SOAP_WSA(RelatesTo) = (SOAP_WSA_(,RelatesTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,RelatesTo)));
  742. SOAP_WSA_(soap_default_,RelatesTo)(soap, newheader->SOAP_WSA(RelatesTo));
  743. newheader->SOAP_WSA(RelatesTo)->__item = oldheader->SOAP_WSA(MessageID);
  744. }
  745. #ifdef SOAP_WSA_2005
  746. /* WCF Interoperability:
  747. ChannelInstance is required when the WCF Application hosts multiple
  748. Callback Channels within the same application. The
  749. ReferenceParameters->ChannelInstance element serves as a hint to the WCF
  750. Client dispatcher, as to which WCF callback instance a received SOAP
  751. Envelope belongs to ChannelInstance is declared as a pointer, so it is
  752. essentially an optional element. Tests with Applications not requiring
  753. ChannelInstance have also been done for the following fix.
  754. */
  755. if (oldheader && oldheader->SOAP_WSA(ReplyTo) && oldheader->SOAP_WSA(ReplyTo)->ReferenceParameters && oldheader->SOAP_WSA(ReplyTo)->ReferenceParameters->chan__ChannelInstance)
  756. { if (newheader)
  757. { if (!newheader->chan__ChannelInstance)
  758. { newheader->chan__ChannelInstance = (struct chan__ChannelInstanceType*)soap_malloc(soap, sizeof(struct chan__ChannelInstanceType));
  759. if (newheader->chan__ChannelInstance)
  760. { soap_default_chan__ChannelInstanceType(soap, newheader->chan__ChannelInstance);
  761. newheader->chan__ChannelInstance->__item = *(oldheader->SOAP_WSA(ReplyTo)->ReferenceParameters->chan__ChannelInstance);
  762. newheader->chan__ChannelInstance->wsa5__IsReferenceParameter = _wsa5__IsReferenceParameter__true;
  763. }
  764. }
  765. else
  766. { newheader->chan__ChannelInstance->__item = *(oldheader->SOAP_WSA(ReplyTo)->ReferenceParameters->chan__ChannelInstance);
  767. newheader->chan__ChannelInstance->wsa5__IsReferenceParameter = _wsa5__IsReferenceParameter__true;
  768. }
  769. }
  770. }
  771. #endif
  772. if (oldheader && oldheader->SOAP_WSA(ReplyTo) && oldheader->SOAP_WSA(ReplyTo)->Address && !soap_tagsearch(soap_wsa_allAnonymousURI, oldheader->SOAP_WSA(ReplyTo)->Address))
  773. { newheader->SOAP_WSA(To) = oldheader->SOAP_WSA(ReplyTo)->Address;
  774. /* (re)connect to ReplyTo endpoint if From != ReplyTo */
  775. if (!oldheader->SOAP_WSA(From) || !oldheader->SOAP_WSA(From)->Address || strcmp(oldheader->SOAP_WSA(From)->Address, oldheader->SOAP_WSA(ReplyTo)->Address))
  776. { struct soap *reply_soap = soap_copy(soap);
  777. if (reply_soap)
  778. { soap_copy_stream(reply_soap, soap);
  779. soap_free_stream(soap); /* prevents close in soap_connect() below */
  780. soap->omode |= SOAP_ENC_XML; /* omit HTTP header ("encode XML body only") */
  781. if (soap_connect(soap, newheader->SOAP_WSA(To), newheader->SOAP_WSA(Action)))
  782. { int err;
  783. soap_copy_stream(soap, reply_soap);
  784. soap_free_stream(reply_soap);
  785. soap_end(reply_soap);
  786. soap_free(reply_soap);
  787. soap->header = oldheader;
  788. #if defined(SOAP_WSA_2005)
  789. err = soap_wsa_error(soap, SOAP_WSA(DestinationUnreachable), newheader->SOAP_WSA(To));
  790. #elif defined(SOAP_WSA_2003)
  791. err = soap_wsa_error(soap, "WS-Addessing destination unreachable");
  792. #else
  793. err = soap_wsa_error(soap, SOAP_WSA(DestinationUnreachable));
  794. #endif
  795. soap->header = NULL;
  796. return err;
  797. }
  798. if (soap_valid_socket(reply_soap->socket))
  799. soap_send_empty_response(reply_soap, SOAP_OK); /* HTTP ACCEPTED */
  800. soap->header = newheader;
  801. soap->omode &= ~SOAP_ENC_XML; /* HTTP header required */
  802. soap_end(reply_soap);
  803. soap_free(reply_soap);
  804. data->fresponse = soap->fresponse;
  805. soap->fresponse = soap_wsa_response; /* response will be a POST */
  806. }
  807. }
  808. }
  809. else if (oldheader && oldheader->SOAP_WSA(From))
  810. newheader->SOAP_WSA(To) = oldheader->SOAP_WSA(From)->Address;
  811. else
  812. newheader->SOAP_WSA(To) = (char*)soap_wsa_anonymousURI;
  813. soap->header = newheader;
  814. soap->action = newheader->SOAP_WSA(Action);
  815. return SOAP_OK;
  816. }
  817. /******************************************************************************\
  818. *
  819. * Server-side SOAP Fault
  820. *
  821. \******************************************************************************/
  822. /**
  823. @fn int soap_wsa_fault_subcode(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail)
  824. @brief Sets sender/receiver SOAP Fault (sub)code for server fault response.
  825. @param soap context
  826. @param[in] flag 0=receiver, 1=sender
  827. @param[in] faultsubcode sub code string
  828. @param[in] faultstring fault string
  829. @param[in] faultdetail detail string
  830. @return SOAP_FAULT
  831. */
  832. int
  833. soap_wsa_fault_subcode(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail)
  834. { return soap_wsa_fault_subcode_action(soap, flag, faultsubcode, faultstring, faultdetail, NULL);
  835. }
  836. /**
  837. @fn int soap_wsa_fault_subcode_action(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
  838. @brief Sets sender/receiver SOAP Fault (sub)code and action for server fault response.
  839. @param soap context
  840. @param[in] flag 0=receiver, 1=sender
  841. @param[in] faultsubcode sub code string
  842. @param[in] faultstring fault string
  843. @param[in] faultdetail detail string
  844. @param[in] action WS-Addressing action string
  845. @return SOAP_FAULT
  846. */
  847. int
  848. soap_wsa_fault_subcode_action(struct soap *soap, int flag, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
  849. { struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  850. struct SOAP_ENV__Header *oldheader, *newheader;
  851. DBGFUN2("soap_wsa_fault_subcode", "faultsubcode=%s", faultsubcode?faultsubcode:"(null)", "faultstring=%s", faultstring?faultstring:"(null)");
  852. if (!data)
  853. return soap->error = SOAP_PLUGIN_ERROR;
  854. oldheader = soap->header;
  855. /* no FaultTo: use ReplyTo */
  856. if (oldheader && oldheader->SOAP_WSA(ReplyTo) && (!oldheader->SOAP_WSA(FaultTo) || soap_tagsearch(soap_wsa_allAnonymousURI, oldheader->SOAP_WSA(FaultTo)->Address)))
  857. { if (!oldheader->SOAP_WSA(FaultTo))
  858. { oldheader->SOAP_WSA(FaultTo) = (SOAP_WSA_(,FaultTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,FaultTo)));
  859. SOAP_WSA_(soap_default,EndpointReferenceType)(soap, soap->header->SOAP_WSA(FaultTo));
  860. }
  861. oldheader->SOAP_WSA(FaultTo)->Address = oldheader->SOAP_WSA(ReplyTo)->Address;
  862. }
  863. if (oldheader && oldheader->SOAP_WSA(FaultTo))
  864. { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "WSA FaultTo='%s'\n", oldheader->SOAP_WSA(FaultTo)->Address));
  865. }
  866. if (oldheader && oldheader->SOAP_WSA(FaultTo) && !strcmp(oldheader->SOAP_WSA(FaultTo)->Address, soap_wsa_noneURI))
  867. return soap_send_empty_response(soap, SOAP_OK); /* HTTP ACCEPTED */
  868. soap->header = NULL;
  869. /* allocate a new header */
  870. if (soap_wsa_alloc_header(soap))
  871. return soap->error;
  872. newheader = soap->header;
  873. soap_default_SOAP_ENV__Header(soap, newheader); /* remove/clear SOAP Header */
  874. /* check header */
  875. if (oldheader && oldheader->SOAP_WSA(MessageID))
  876. { newheader->SOAP_WSA(RelatesTo) = (SOAP_WSA_(,RelatesTo)*)soap_malloc(soap, sizeof(SOAP_WSA_(,RelatesTo)));
  877. SOAP_WSA_(soap_default_,RelatesTo)(soap, newheader->SOAP_WSA(RelatesTo));
  878. newheader->SOAP_WSA(RelatesTo)->__item = oldheader->SOAP_WSA(MessageID);
  879. }
  880. /* header->wsa__MessageID = "..."; */
  881. newheader->SOAP_WSA(Action) = (char*)soap_wsa_faultAction;
  882. if (oldheader && oldheader->SOAP_WSA(FaultTo) && oldheader->SOAP_WSA(FaultTo)->Address && !soap_tagsearch(soap_wsa_allAnonymousURI, oldheader->SOAP_WSA(FaultTo)->Address))
  883. { newheader->SOAP_WSA(To) = oldheader->SOAP_WSA(FaultTo)->Address;
  884. /* (re)connect to FaultTo endpoint if From != FaultTo */
  885. if (!oldheader->SOAP_WSA(From) || !oldheader->SOAP_WSA(From)->Address || strcmp(oldheader->SOAP_WSA(From)->Address, oldheader->SOAP_WSA(FaultTo)->Address))
  886. { soap->keep_alive = 0;
  887. soap_send_empty_response(soap, SOAP_OK); /* HTTP ACCEPTED */
  888. if (soap_connect(soap, newheader->SOAP_WSA(To), newheader->SOAP_WSA(Action)))
  889. return soap->error = SOAP_STOP; /* nowhere to go */
  890. soap_set_endpoint(soap, newheader->SOAP_WSA(To));
  891. if (action)
  892. soap->action = (char*)action;
  893. else
  894. soap->action = newheader->SOAP_WSA(Action);
  895. data->fresponse = soap->fresponse;
  896. soap->fresponse = soap_wsa_response; /* response will be a POST */
  897. }
  898. }
  899. else if (oldheader && oldheader->SOAP_WSA(From))
  900. newheader->SOAP_WSA(To) = oldheader->SOAP_WSA(From)->Address;
  901. else
  902. newheader->SOAP_WSA(To) = (char*)soap_wsa_anonymousURI;
  903. soap->header = newheader;
  904. if (flag)
  905. return soap_sender_fault_subcode(soap, faultsubcode, faultstring, faultdetail);
  906. return soap_receiver_fault_subcode(soap, faultsubcode, faultstring, faultdetail);
  907. }
  908. /**
  909. @fn int soap_wsa_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)
  910. @brief Sets sender SOAP Fault (sub)code for server fault response.
  911. @param soap context
  912. @param[in] faultsubcode sub code string
  913. @param[in] faultstring fault string
  914. @param[in] faultdetail detail string
  915. @return SOAP_FAULT
  916. */
  917. int
  918. soap_wsa_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)
  919. { return soap_wsa_fault_subcode(soap, 1, faultsubcode, faultstring, faultdetail);
  920. }
  921. /**
  922. @fn int soap_wsa_sender_fault_subcode_action(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
  923. @brief Sets sender SOAP Fault (sub)code for server fault response.
  924. @param soap context
  925. @param[in] faultsubcode sub code string
  926. @param[in] faultstring fault string
  927. @param[in] faultdetail detail string
  928. @param[in] action WS-Addressing action string
  929. @return SOAP_FAULT
  930. */
  931. int
  932. soap_wsa_sender_fault_subcode_action(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
  933. { return soap_wsa_fault_subcode_action(soap, 1, faultsubcode, faultstring, faultdetail, action);
  934. }
  935. /**
  936. @fn int soap_wsa_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)
  937. @brief Sets receiver SOAP Fault (sub)code for server fault response.
  938. @param soap context
  939. @param[in] faultsubcode sub code string
  940. @param[in] faultstring fault string
  941. @param[in] faultdetail detail string
  942. @return SOAP_FAULT
  943. */
  944. int
  945. soap_wsa_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail)
  946. { return soap_wsa_fault_subcode(soap, 0, faultsubcode, faultstring, faultdetail);
  947. }
  948. /**
  949. @fn int soap_wsa_receiver_fault_subcode_action(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
  950. @brief Sets receiver SOAP Fault (sub)code for server fault response.
  951. @param soap context
  952. @param[in] faultsubcode sub code string
  953. @param[in] faultstring fault string
  954. @param[in] faultdetail detail string
  955. @param[in] action WS-Addressing action string
  956. @return SOAP_FAULT
  957. */
  958. int
  959. soap_wsa_receiver_fault_subcode_action(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail, const char *action)
  960. { return soap_wsa_fault_subcode_action(soap, 0, faultsubcode, faultstring, faultdetail, action);
  961. }
  962. /**
  963. @fn int soap_wsa_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
  964. @brief Sets sender SOAP Fault for server fault response.
  965. @param soap context
  966. @param[in] faultstring fault string
  967. @param[in] faultdetail detail string
  968. @return SOAP_FAULT
  969. */
  970. int
  971. soap_wsa_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
  972. { return soap_wsa_fault_subcode(soap, 1, NULL, faultstring, faultdetail);
  973. }
  974. /**
  975. @fn int soap_wsa_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
  976. @brief Sets receiver SOAP Fault for server fault response.
  977. @param soap context
  978. @param[in] faultstring fault string
  979. @param[in] faultdetail detail string
  980. @return SOAP_FAULT
  981. */
  982. int
  983. soap_wsa_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
  984. { return soap_wsa_fault_subcode(soap, 0, NULL, faultstring, faultdetail);
  985. }
  986. /******************************************************************************\
  987. *
  988. * WS-Addressing Faults
  989. *
  990. \******************************************************************************/
  991. #if defined(SOAP_WSA_2005)
  992. /**
  993. @fn int soap_wsa_check_fault(struct soap *soap, SOAP_WSA(FaultCodesType) *fault, const char **info)
  994. @brief Checks the presence of a WS-Addressing fault
  995. @param soap context
  996. @param[out] fault code
  997. @param[out] info string pointer related to the wsa fault (or set to NULL)
  998. @return SOAP_OK (no fault) or fault code
  999. */
  1000. int
  1001. soap_wsa_check_fault(struct soap *soap, SOAP_WSA(FaultCodesType) *fault, const char **info)
  1002. { if (soap->error && soap->fault && soap->fault->SOAP_ENV__Code)
  1003. { const char *code = soap_check_faultsubcode(soap);
  1004. if (code)
  1005. { SOAP_WSA__(soap_s2,FaultCodesType)(soap, code, fault);
  1006. if (info)
  1007. { struct SOAP_ENV__Detail *detail;
  1008. *info = NULL;
  1009. if (soap->fault->detail)
  1010. detail = soap->fault->detail;
  1011. else
  1012. detail = soap->fault->SOAP_ENV__Detail;
  1013. if (detail)
  1014. { switch (detail->__type)
  1015. { case SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName):
  1016. case SOAP_WSA_(SOAP_TYPE_,ProblemIRI):
  1017. *info = (char*)detail->fault;
  1018. break;
  1019. case SOAP_WSA_(SOAP_TYPE_,ProblemAction):
  1020. *info = ((SOAP_WSA_(,ProblemAction)*)detail->fault)->Action;
  1021. break;
  1022. default:
  1023. break;
  1024. }
  1025. }
  1026. }
  1027. return soap->error;
  1028. }
  1029. }
  1030. return SOAP_OK;
  1031. }
  1032. #elif defined(SOAP_WSA_2003)
  1033. int
  1034. soap_wsa_check_fault(struct soap *soap, char **fault)
  1035. { struct SOAP_ENV__Detail detail;
  1036. *fault = NULL;
  1037. if (soap->error && soap->fault)
  1038. { if (soap->fault->detail)
  1039. detail = soap->fault->detail;
  1040. else
  1041. detail = soap->fault->SOAP_ENV__Detail;
  1042. }
  1043. if (detail)
  1044. { *fault = detail->__any;
  1045. if (*fault)
  1046. return soap->error;
  1047. }
  1048. return SOAP_OK;
  1049. }
  1050. #else
  1051. /**
  1052. @fn int soap_wsa_check_fault(struct soap *soap, SOAP_WSA(FaultSubcodeValues) *fault)
  1053. @brief Checks the presence of a WS-Addressing fault
  1054. @param soap context
  1055. @param[out] fault code
  1056. @return SOAP_OK (no fault) or fault code
  1057. */
  1058. int
  1059. soap_wsa_check_fault(struct soap *soap, SOAP_WSA(FaultSubcodeValues) *fault)
  1060. { if (soap->error && soap->fault && soap->fault->SOAP_ENV__Code)
  1061. { const char *code = soap_check_faultsubcode(soap);
  1062. if (code)
  1063. { SOAP_WSA__(soap_s2,FaultSubcodeValues)(soap, code, fault);
  1064. return soap->error;
  1065. }
  1066. }
  1067. return SOAP_OK;
  1068. }
  1069. #endif
  1070. #if defined(SOAP_WSA_2005)
  1071. /**
  1072. @fn int soap_wsa_error(struct soap *soap, SOAP_WSA(FaultCodesType) fault, const char *info)
  1073. @brief Sets SOAP Fault (sub)code for server WS-Addressing fault response.
  1074. @param soap context
  1075. @param[in] fault is one of wsa:FaultCodesType enumeration values
  1076. @param[in] info is the value of the element in the Fault detail field
  1077. @return SOAP_FAULT
  1078. */
  1079. int
  1080. soap_wsa_error(struct soap *soap, SOAP_WSA(FaultCodesType) fault, const char *info)
  1081. { const char *code = SOAP_WSA_(soap,FaultCodesType2s)(soap, fault);
  1082. /* populate the SOAP Fault as per WS-Addressing spec */
  1083. switch (fault)
  1084. { case SOAP_WSA(InvalidAddressingHeader):
  1085. soap_faultdetail(soap);
  1086. if (soap->version == 1)
  1087. { soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName);
  1088. soap->fault->detail->fault = (void*)info;
  1089. }
  1090. else
  1091. { soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName);
  1092. soap->fault->SOAP_ENV__Detail->fault = (void*)info;
  1093. }
  1094. soap_wsa_sender_fault_subcode(soap, code, "A header representing a Message Addressing Property is not valid and the message cannot be processed.", NULL);
  1095. break;
  1096. case SOAP_WSA(InvalidAddress):
  1097. soap_wsa_sender_fault_subcode(soap, code, "Invalid address.", NULL);
  1098. break;
  1099. case SOAP_WSA(InvalidEPR):
  1100. soap_wsa_sender_fault_subcode(soap, code, "Invalid EPR.", NULL);
  1101. break;
  1102. case SOAP_WSA(InvalidCardinality):
  1103. soap_wsa_sender_fault_subcode(soap, code, "Invalid cardinality of headers.", NULL);
  1104. break;
  1105. case SOAP_WSA(MissingAddressInEPR):
  1106. soap_wsa_sender_fault_subcode(soap, code, "Missing EPR address.", NULL);
  1107. break;
  1108. case SOAP_WSA(DuplicateMessageID):
  1109. soap_wsa_sender_fault_subcode(soap, code, "Message contains the message ID of a message already received.", NULL);
  1110. break;
  1111. case SOAP_WSA(ActionMismatch):
  1112. soap_wsa_sender_fault_subcode(soap, code, "Action and SOAP action of the message do not match.", NULL);
  1113. break;
  1114. case SOAP_WSA(MessageAddressingHeaderRequired):
  1115. soap_faultdetail(soap);
  1116. if (soap->version == 1)
  1117. { soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName);
  1118. soap->fault->detail->fault = (void*)info;
  1119. }
  1120. else
  1121. { soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemHeaderQName);
  1122. soap->fault->SOAP_ENV__Detail->fault = (void*)info;
  1123. }
  1124. soap_wsa_sender_fault_subcode(soap, code, "A required header representing a Message Addressing Property is not present.", NULL);
  1125. break;
  1126. case SOAP_WSA(DestinationUnreachable):
  1127. soap_faultdetail(soap);
  1128. if (soap->version == 1)
  1129. { soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemIRI);
  1130. soap->fault->detail->fault = (void*)info;
  1131. }
  1132. else
  1133. { soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemIRI);
  1134. soap->fault->SOAP_ENV__Detail->fault = (void*)info;
  1135. }
  1136. soap_wsa_sender_fault_subcode(soap, code, "No route can be determined to reach [destination]", NULL);
  1137. break;
  1138. case SOAP_WSA(ActionNotSupported):
  1139. soap_faultdetail(soap);
  1140. if (soap->version == 1)
  1141. { soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemAction);
  1142. soap->fault->detail->fault = (void*)soap_malloc(soap, sizeof(SOAP_WSA_(,ProblemAction)));
  1143. SOAP_WSA_(soap_default_,ProblemAction)(soap, (SOAP_WSA_(,ProblemAction)*)soap->fault->detail->fault);
  1144. ((SOAP_WSA_(,ProblemAction)*)soap->fault->detail->fault)->Action = (char*)info;
  1145. }
  1146. else
  1147. { soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemAction);
  1148. soap->fault->SOAP_ENV__Detail->fault = (void*)soap_malloc(soap, sizeof(SOAP_WSA_(,ProblemAction)));
  1149. SOAP_WSA_(soap_default_,ProblemAction)(soap, (SOAP_WSA_(,ProblemAction)*)soap->fault->SOAP_ENV__Detail->fault);
  1150. ((SOAP_WSA_(,ProblemAction)*)soap->fault->SOAP_ENV__Detail->fault)->Action = (char*)info;
  1151. }
  1152. soap_wsa_sender_fault_subcode(soap, code, "The [action] cannot be processed at the receiver.", NULL);
  1153. break;
  1154. case SOAP_WSA(EndpointUnavailable):
  1155. soap_faultdetail(soap);
  1156. if (soap->version == 1)
  1157. { soap->fault->detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemIRI);
  1158. soap->fault->detail->fault = (void*)info;
  1159. }
  1160. else
  1161. { soap->fault->SOAP_ENV__Detail->__type = SOAP_WSA_(SOAP_TYPE_,ProblemIRI);
  1162. soap->fault->SOAP_ENV__Detail->fault = (void*)info;
  1163. }
  1164. soap_wsa_receiver_fault_subcode(soap, code, "The endpoint is unable to process the message at this time.", NULL);
  1165. break;
  1166. default:
  1167. break;
  1168. }
  1169. return SOAP_FAULT;
  1170. }
  1171. #elif defined(SOAP_WSA_2003)
  1172. int
  1173. soap_wsa_error(struct soap *soap, const char *fault)
  1174. { return soap_wsa_sender_fault_subcode(soap, NULL, fault, NULL);
  1175. }
  1176. #else
  1177. /**
  1178. @fn int soap_wsa_error(struct soap *soap, SOAP_WSA(FaultSubcodeValues) fault)
  1179. @brief Sets SOAP Fault (sub)code for server WS-Addressing fault response.
  1180. @param soap context
  1181. @param[in] fault is one of wsa:FaultSubcodeValues
  1182. @return SOAP_FAULT
  1183. */
  1184. int
  1185. soap_wsa_error(struct soap *soap, SOAP_WSA(FaultSubcodeValues) fault)
  1186. { const char *code = SOAP_WSA_(soap,FaultSubcodeValues2s)(soap, fault);
  1187. /* populate the SOAP Fault as per WS-Addressing spec */
  1188. switch (fault)
  1189. { case SOAP_WSA(InvalidMessageInformationHeader):
  1190. return soap_wsa_sender_fault_subcode(soap, code, "A message information header is not valid and the message cannot be processed. The validity failure can be either structural or semantic, e.g. a [destination] that is not a URI or a [relationship] to a [message id] that was never issued.", "Invalid header");
  1191. case SOAP_WSA(MessageInformationHeaderRequired):
  1192. return soap_wsa_sender_fault_subcode(soap, code, "A required message information header, To, MessageID, or Action, is not present.", "Missing Header QName");
  1193. case SOAP_WSA(DestinationUnreachable):
  1194. return soap_wsa_sender_fault_subcode(soap, code, "No route can be determined to reach the destination role defined by the WS-Addressing To.", NULL);
  1195. case SOAP_WSA(ActionNotSupported):
  1196. return soap_wsa_sender_fault_subcode(soap, code, "The [action] cannot be processed at the receiver.", soap->action);
  1197. case SOAP_WSA(EndpointUnavailable):
  1198. return soap_wsa_receiver_fault_subcode(soap, code, "The endpoint is unable to process the message at this time.", NULL);
  1199. default:
  1200. break;
  1201. }
  1202. return SOAP_FAULT;
  1203. }
  1204. #endif
  1205. /******************************************************************************\
  1206. *
  1207. * Plugin registry functions
  1208. *
  1209. \******************************************************************************/
  1210. /**
  1211. @fn int soap_wsa(struct soap *soap, struct soap_plugin *p, void *arg)
  1212. @brief Plugin registry function, used with soap_register_plugin.
  1213. @param soap context
  1214. @param[in,out] p plugin created in registry
  1215. @param[in] arg passed from soap_register_plugin_arg
  1216. @return SOAP_OK
  1217. */
  1218. int
  1219. soap_wsa(struct soap *soap, struct soap_plugin *p, void *arg)
  1220. { DBGFUN("soap_wsa");
  1221. p->id = soap_wsa_id;
  1222. p->data = (void*)SOAP_MALLOC(soap, sizeof(struct soap_wsa_data));
  1223. p->fcopy = NULL;
  1224. p->fdelete = soap_wsa_delete;
  1225. if (p->data)
  1226. { if (soap_wsa_init(soap, (struct soap_wsa_data*)p->data))
  1227. { SOAP_FREE(soap, p->data);
  1228. return SOAP_EOM;
  1229. }
  1230. }
  1231. return SOAP_OK;
  1232. }
  1233. /**
  1234. @fn int soap_wsa_init(struct soap *soap, struct soap_wsa_data *data)
  1235. @brief Initializes plugin data.
  1236. @param soap context
  1237. @param[in,out] data plugin data
  1238. @return SOAP_OK
  1239. */
  1240. static int
  1241. soap_wsa_init(struct soap *soap, struct soap_wsa_data *data)
  1242. { DBGFUN("soap_wsa_init");
  1243. data->fheader = soap->fheader;
  1244. data->fseterror = soap->fseterror;
  1245. soap->fheader = soap_wsa_header;
  1246. soap->fseterror = soap_wsa_set_error;
  1247. data->fresponse = NULL;
  1248. data->fdisconnect = NULL;
  1249. return SOAP_OK;
  1250. }
  1251. /**
  1252. @fn void soap_wsa_delete(struct soap *soap, struct soap_plugin *p)
  1253. @brief Deletes plugin data.
  1254. @param soap context
  1255. @param[in,out] p plugin
  1256. @return SOAP_OK
  1257. */
  1258. static void
  1259. soap_wsa_delete(struct soap *soap, struct soap_plugin *p)
  1260. { DBGFUN("soap_wsa_delete");
  1261. SOAP_FREE(soap, p->data);
  1262. }
  1263. /******************************************************************************\
  1264. *
  1265. * Callbacks registered by plugin
  1266. *
  1267. \******************************************************************************/
  1268. /**
  1269. @fn int soap_wsa_header(struct soap *soap)
  1270. @brief Copies WS-Addressing action to SOAP action
  1271. @param soap context
  1272. @return SOAP_OK or fault
  1273. This callback is invoked to copy the WS-Addressing action to the SOAP action
  1274. before invoking the service operation.
  1275. */
  1276. static int
  1277. soap_wsa_header(struct soap *soap)
  1278. { struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  1279. DBGFUN("soap_wsa_header");
  1280. if (!data)
  1281. return soap->error = SOAP_PLUGIN_ERROR;
  1282. if (data->fheader && data->fheader(soap))
  1283. return soap->error;
  1284. if (soap->header && soap->header->SOAP_WSA(Action))
  1285. { soap->action = soap->header->SOAP_WSA(Action);
  1286. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "WSA action='%s'\n", soap->action));
  1287. }
  1288. return SOAP_OK;
  1289. }
  1290. /**
  1291. @fn void soap_wsa_set_error(struct soap *soap, const char **c, const char **s)
  1292. @brief Copies WS-Addressing action to SOAP action
  1293. @param soap context
  1294. @param c fault code
  1295. @param s fault string
  1296. */
  1297. static void
  1298. soap_wsa_set_error(struct soap *soap, const char **c, const char **s)
  1299. { struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  1300. DBGFUN("soap_wsa_set_error");
  1301. if (!data)
  1302. return;
  1303. if (data->fseterror)
  1304. data->fseterror(soap, c, s);
  1305. if (soap->error == SOAP_NO_METHOD || (soap->error == SOAP_TAG_MISMATCH && soap->level == 2))
  1306. {
  1307. #if defined(SOAP_WSA_2005)
  1308. soap->error = soap_wsa_error(soap, SOAP_WSA(ActionNotSupported), soap->action);
  1309. #elif defined(SOAP_WSA_2003)
  1310. soap->error = soap_wsa_error(soap, "Action not supported");
  1311. #else
  1312. soap->error = soap_wsa_error(soap, SOAP_WSA(ActionNotSupported));
  1313. #endif
  1314. }
  1315. }
  1316. /**
  1317. @fn int soap_wsa_response(struct soap *soap, int status, size_t count)
  1318. @brief Overrides the HTTP response operations to send an HTTP POST
  1319. @param soap context
  1320. @param status code
  1321. @param count message length (if non-chunked)
  1322. */
  1323. static int
  1324. soap_wsa_response(struct soap *soap, int status, size_t count)
  1325. { struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  1326. DBGFUN2("soap_wsa_response", "status=%d", status, "count=%lu", (unsigned long)count);
  1327. if (!data)
  1328. return SOAP_PLUGIN_ERROR;
  1329. soap->fresponse = data->fresponse; /* reset (HTTP response) */
  1330. data->fdisconnect = soap->fdisconnect;
  1331. soap->fdisconnect = soap_wsa_disconnect; /* to accept HTTP 202 */
  1332. return soap->fpost(soap, soap_strdup(soap, soap->endpoint), soap->host, soap->port, soap->path, soap->action, count);
  1333. }
  1334. /**
  1335. @fn int soap_wsa_disconnect(struct soap *soap)
  1336. @brief Accepts HTTP 202 response upon HTTP POST response relay
  1337. @param soap context
  1338. */
  1339. static int
  1340. soap_wsa_disconnect(struct soap *soap)
  1341. { struct soap_wsa_data *data = (struct soap_wsa_data*)soap_lookup_plugin(soap, soap_wsa_id);
  1342. DBGFUN("soap_wsa_disconnect");
  1343. if (!data)
  1344. return SOAP_PLUGIN_ERROR;
  1345. soap->fdisconnect = data->fdisconnect; /* reset */
  1346. return soap_recv_empty_response(soap);
  1347. }
  1348. /******************************************************************************\
  1349. *
  1350. * Misc.
  1351. *
  1352. \******************************************************************************/
  1353. /**
  1354. @fn int soap_wsa_alloc_header(struct soap *soap)
  1355. @brief Adds SOAP Header if not present.
  1356. @param soap context
  1357. @return SOAP_OK
  1358. */
  1359. static int
  1360. soap_wsa_alloc_header(struct soap *soap)
  1361. { soap_header(soap);
  1362. if (soap->header)
  1363. return SOAP_OK;
  1364. return soap->error = SOAP_EOM;
  1365. }
  1366. #ifdef __cplusplus
  1367. }
  1368. #endif