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.

337 lines
8.6 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: soap-env.h,v 1.14 2006/03/06 13:37:38 m0gg Exp $
  3. *
  4. * CSOAP Project: A SOAP client/server library in C
  5. * Copyright (C) 2003 Ferhat Ayaz
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. *
  22. * Email: ayaz@jprogrammer.net
  23. ******************************************************************/
  24. #ifndef cSOAP_ENV_H
  25. #define cSOAP_ENV_H
  26. #include <nanohttp/nanohttp-stream.h>
  27. #include <libcsoap/soap-xml.h>
  28. #include <libcsoap/soap-fault.h>
  29. /**
  30. The SOAP envelope object.
  31. */
  32. typedef struct _SoapEnv
  33. {
  34. xmlNodePtr root; /** Pointer to the firts xml element (envelope) */
  35. xmlNodePtr header;
  36. xmlNodePtr body;
  37. xmlNodePtr cur; /** Pointer to the current xml element. (stack) */
  38. } SoapEnv;
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /* -------------------------------------------------------------- */
  43. /* Envelope creation methods */
  44. /* -------------------------------------------------------------- */
  45. /**
  46. Creates an envelope with a fault object.
  47. @param faultcode The fault code @see fault_code_t
  48. @param faultstring A fault message
  49. @param faultactor The fault actor (This can be NULL)
  50. @param detail The detail of the error (This can be NULL)
  51. @param out the result envelope out parameter like follows
  52. @returns H_OK if success
  53. <pre>
  54. <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
  55. xmlns:xsi="..."
  56. xmlns:xsd="...">
  57. <SOAP-ENV:Body>
  58. <Fault>
  59. <faultcode>...</faultcode>
  60. <faultstring>...</faultstring>
  61. <faultactor>...</faultactor>
  62. <faultdetail>..</faultdetail>
  63. </Fault>
  64. </SOAP-ENV:Body>
  65. </SOAP-ENV:Envelope>
  66. </pre>
  67. */
  68. herror_t
  69. soap_env_new_with_fault(fault_code_t faultcode,
  70. const char *faultstring,
  71. const char *faultactor,
  72. const char *detail, SoapEnv ** out);
  73. /**
  74. Creates an envelope with a method to invoke a soap service.
  75. Use this function to create a client call.
  76. @param urn The urn of the soap service to invoke
  77. @param method The method name of the soap service
  78. @param out the result envelope out parameter like follows
  79. @returns H_OK if success
  80. <pre>
  81. <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
  82. xmlns:xsi="..."
  83. xmlns:xsd="...">
  84. <SOAP-ENV:Body>
  85. <m:[method] xmlns:m="[urn]">
  86. </m:[method]>
  87. </SOAP-ENV:Body>
  88. </SOAP-ENV:Envelope>
  89. </pre>
  90. */
  91. herror_t
  92. soap_env_new_with_method(const char *urn, const char *method, SoapEnv ** out);
  93. /**
  94. Creates a soap envelope with a response.
  95. Use this function to create a response envelope object
  96. for a request. This function is only relevant for soap
  97. service implementors.
  98. @see example csoap/simpleserver.c
  99. @param req The request object. A response object will be created
  100. to this request.
  101. @param out the result envelope out paramter like follows
  102. @returns H_OK if success
  103. <pre>
  104. <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
  105. xmlns:xsi="..."
  106. xmlns:xsd="...">
  107. <SOAP-ENV:Body>
  108. <m:[req-method]Response xmlns:m="[req-urn]">
  109. </m:[req-method]>
  110. </SOAP-ENV:Body>
  111. </SOAP-ENV:Envelope>
  112. </pre>
  113. */
  114. herror_t soap_env_new_with_response(SoapEnv * req, SoapEnv ** out);
  115. /**
  116. Creates an envelope from a given libxml2 xmlDoc
  117. pointer.
  118. @param doc the xml document pointer
  119. @param out the output envelope object
  120. @returns H_OK if success
  121. */
  122. herror_t soap_env_new_from_doc(xmlDocPtr doc, SoapEnv ** out);
  123. /**
  124. Create an envelop object from a string.
  125. The string must be in xml format.
  126. @param buffer The string to parse into a envelope.
  127. @param out the output envelope object
  128. @returns H_OK if success
  129. */
  130. herror_t soap_env_new_from_buffer(const char *buffer, SoapEnv ** out);
  131. /**
  132. Create an envelope from input stream
  133. @param in the input stream object to read from
  134. @param out the output envelope object
  135. @returns H_OK if success
  136. */
  137. herror_t soap_env_new_from_stream(http_input_stream_t * in, SoapEnv ** out);
  138. /* --------------------------------------------------- */
  139. /* XML Serializer functions and typedefs */
  140. /* --------------------------------------------------- */
  141. typedef void (*XmlSerializerCallback) (void * obj, const xmlChar *root_element_name, void (*OnStartElement) (const xmlChar * element_name, int attr_count, xmlChar ** keys, xmlChar ** values, void *userData), void (*OnCharacters) (const xmlChar * element_name, const xmlChar * chars, void *userData), void (*OnEndElement) (const xmlChar * element_name, void *userData), void *userdata);
  142. /* ------------------------------------------------------ */
  143. /* XML build and stack function */
  144. /* ------------------------------------------------------ */
  145. /**
  146. Adds a new xml node under the current parent.
  147. <pre>
  148. <m:[name] type=[type]>[value]</m:[name]>
  149. </pre>
  150. @param env The envelope object
  151. @param type Type of the parameter. Something like "xsd:string" or
  152. "xsd:int" or custom types.
  153. @param name Name of the xml node
  154. @param value Text value of the xml node
  155. @returns The added xmlNode pointer.
  156. @see tutorial
  157. */
  158. xmlNodePtr
  159. soap_env_add_item(SoapEnv * env, const char *type,
  160. const char *name, const char *value);
  161. /**
  162. Adds attachment href node to the envelope current parent.
  163. <pre>
  164. <m:[name] href=[href]/>
  165. </pre>
  166. @param env The envelope object
  167. @param name Name of the xml node
  168. @param href href. A CID string filled by
  169. soap_ctx_add_attachment()
  170. @returns The added xmlNode pointer.
  171. @see soap_ctx_add_file tutorial
  172. */
  173. xmlNodePtr
  174. soap_env_add_attachment(SoapEnv * env, const char *name, const char *href);
  175. /**
  176. Serialize and adds obj to the envelope.
  177. TODO: Document this function !
  178. <br>
  179. <b>Important: </b>
  180. */
  181. void
  182. soap_env_add_custom(SoapEnv * env, void *obj, XmlSerializerCallback cb,
  183. const char *type, const char *name);
  184. /**
  185. Same as soap_env_add_item() with c style arguments
  186. like in printf(). "value" is the format string.
  187. <br>
  188. <b>Important: </b> The totally length of value (incl. args)
  189. must be lower the 1054.
  190. @see soap_env_add_item
  191. */
  192. xmlNodePtr
  193. soap_env_add_itemf(SoapEnv * env, const char *type,
  194. const char *name, const char *value, ...);
  195. /**
  196. Push the current xml node in the soap envelope one level
  197. deeper. Here an example:
  198. <pre>
  199. soap_env_push_item(env, "my:custom", "Person");
  200. soap_env_add_item(env, "xsd:string", "name", "Mickey");
  201. soap_env_add_item(env, "xsd:string", "lastname", "Mouse");
  202. soap_env_pop_item(env);
  203. </pre>
  204. This will create the xml like follows.
  205. <pre>
  206. <Person type="my:custom">
  207. <name>Mickey</name>
  208. <lastname>Mouse</lastname>
  209. </Person>
  210. </pre>
  211. @returns The added xmlNode pointer.
  212. @see tutorial
  213. */
  214. xmlNodePtr soap_env_push_item(SoapEnv * env, const char *type, const char *name);
  215. /**
  216. Sets the xml pointer 1 level higher.
  217. @param env The envelope object
  218. @see soap_env_push_item
  219. */
  220. void soap_env_pop_item(SoapEnv * env);
  221. /**
  222. Free the envelope.
  223. @param env The envelope object
  224. */
  225. void soap_env_free(SoapEnv * env);
  226. /* --------------------------------------------------- */
  227. /* XML node finder functions */
  228. /* --------------------------------------------------- */
  229. /**
  230. Gets the xml node pointing to SOAP Body.
  231. */
  232. xmlNodePtr soap_env_get_body(SoapEnv * env);
  233. /**
  234. Get the xml node pointing to SOAP method (call)
  235. */
  236. xmlNodePtr soap_env_get_method(SoapEnv * env);
  237. /**
  238. Get the xml node pointing to SOAP Fault
  239. */
  240. xmlNodePtr soap_env_get_fault(SoapEnv * env);
  241. /**
  242. Get the xml node pointing to SOAP Header
  243. */
  244. xmlNodePtr soap_env_get_header(SoapEnv * env);
  245. char * soap_env_find_urn(SoapEnv * env);
  246. char * soap_env_find_methodname(SoapEnv * env);
  247. #ifdef __cplusplus
  248. }
  249. #endif
  250. #endif