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.

1142 lines
35 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. dom.c[pp]
  3. gSOAP DOM implementation v3
  4. gSOAP XML Web services tools
  5. Copyright (C) 2000-2012, Robert van Engelen, Genivia, Inc. All Rights Reserved.
  6. This part of the software is released under ONE of the following licenses:
  7. GPL, or 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-2012 Robert A. 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. #include "stdsoap2.h"
  40. SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_xsd__anyType(struct soap*, struct soap_dom_element const*);
  41. SOAP_FMAC3 void SOAP_FMAC4 soap_traverse_xsd__anyType(struct soap*, struct soap_dom_element*, const char*, soap_walker, soap_walker);
  42. SOAP_FMAC1 void SOAP_FMAC2 soap_default_xsd__anyType(struct soap*, struct soap_dom_element *);
  43. SOAP_FMAC3 int SOAP_FMAC4 soap_put_xsd__anyType(struct soap*, const struct soap_dom_element *, const char*, const char*);
  44. SOAP_FMAC1 int SOAP_FMAC2 soap_out_xsd__anyType(struct soap*, const char*, int, const struct soap_dom_element *, const char*);
  45. SOAP_FMAC3 struct soap_dom_element * SOAP_FMAC4 soap_get_xsd__anyType(struct soap*, struct soap_dom_element *, const char*, const char*);
  46. SOAP_FMAC1 struct soap_dom_element * SOAP_FMAC2 soap_in_xsd__anyType(struct soap*, const char*, struct soap_dom_element *, const char*);
  47. SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_xsd__anyAttribute(struct soap*, struct soap_dom_attribute const*);
  48. SOAP_FMAC3 void SOAP_FMAC4 soap_traverse_xsd__anyAttribute(struct soap*, struct soap_dom_attribute*, const char*, soap_walker, soap_walker);
  49. SOAP_FMAC1 void SOAP_FMAC2 soap_default_xsd__anyAttribute(struct soap*, struct soap_dom_attribute *);
  50. SOAP_FMAC3 int SOAP_FMAC4 soap_put_xsd__anyAttribute(struct soap*, const struct soap_dom_attribute *, const char*, const char*);
  51. SOAP_FMAC1 int SOAP_FMAC2 soap_out_xsd__anyAttribute(struct soap*, const char*, int, const struct soap_dom_attribute *, const char*);
  52. SOAP_FMAC3 struct soap_dom_attribute * SOAP_FMAC4 soap_get_xsd__anyAttribute(struct soap*, struct soap_dom_attribute *, const char*, const char*);
  53. SOAP_FMAC1 struct soap_dom_attribute * SOAP_FMAC2 soap_in_xsd__anyAttribute(struct soap*, const char*, struct soap_dom_attribute *, const char*);
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. #ifndef WITH_NOIDREF
  58. SOAP_FMAC1 void SOAP_FMAC2 soap_markelement(struct soap*, const void*, int);
  59. #endif
  60. SOAP_FMAC1 int SOAP_FMAC2 soap_putelement(struct soap*, const void*, const char*, int, int);
  61. SOAP_FMAC1 void *SOAP_FMAC2 soap_getelement(struct soap*, int*);
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. /* format string for generating DOM namespace prefixes (<= 16 chars total) */
  66. #define SOAP_DOMID_FORMAT "dom%d"
  67. /* namespace name (URI) lookup and store routines */
  68. static const char *soap_lookup_ns_prefix(struct soap*, const char*);
  69. static const char *soap_push_ns_prefix(struct soap*, const char*, const char*, int);
  70. static int out_element(struct soap *soap, const struct soap_dom_element *node, const char *prefix, const char *name);
  71. static int out_attribute(struct soap *soap, const char *prefix, const char *name, const char *data, const wchar_t *wide, int flag);
  72. /******************************************************************************\
  73. *
  74. * DOM custom (de)serializers
  75. *
  76. \******************************************************************************/
  77. SOAP_FMAC1
  78. void
  79. SOAP_FMAC2
  80. soap_serialize_xsd__anyType(struct soap *soap, const struct soap_dom_element *node)
  81. { if (node)
  82. { if (node->type && node->node)
  83. soap_markelement(soap, node->node, node->type);
  84. else
  85. { const struct soap_dom_element *elt;
  86. for (elt = node->elts; elt; elt = elt->next)
  87. soap_serialize_xsd__anyType(soap, elt);
  88. }
  89. }
  90. }
  91. SOAP_FMAC3
  92. void
  93. SOAP_FMAC4
  94. soap_traverse_xsd__anyType(struct soap *soap, struct soap_dom_element *node, const char *s, soap_walker p, soap_walker q)
  95. {
  96. }
  97. /******************************************************************************/
  98. SOAP_FMAC1
  99. void
  100. SOAP_FMAC2
  101. soap_serialize_xsd__anyAttribute(struct soap *soap, const struct soap_dom_attribute *node)
  102. {
  103. }
  104. SOAP_FMAC1
  105. void
  106. SOAP_FMAC2
  107. soap_traverse_xsd__anyAttribute(struct soap *soap, struct soap_dom_attribute *node, const char *s, soap_walker p, soap_walker q)
  108. {
  109. }
  110. /******************************************************************************/
  111. SOAP_FMAC1
  112. void
  113. SOAP_FMAC2
  114. soap_default_xsd__anyType(struct soap *soap, struct soap_dom_element *node)
  115. { node->next = NULL;
  116. node->prnt = NULL;
  117. node->elts = NULL;
  118. node->atts = NULL;
  119. node->nstr = NULL;
  120. node->name = NULL;
  121. node->data = NULL;
  122. node->wide = NULL;
  123. node->node = NULL;
  124. node->type = 0;
  125. node->head = NULL;
  126. node->tail = NULL;
  127. node->soap = soap;
  128. }
  129. /******************************************************************************/
  130. SOAP_FMAC1
  131. void
  132. SOAP_FMAC2
  133. soap_default_xsd__anyAttribute(struct soap *soap, struct soap_dom_attribute *node)
  134. { node->next = NULL;
  135. node->nstr = NULL;
  136. node->name = NULL;
  137. node->data = NULL;
  138. node->wide = NULL;
  139. node->soap = soap;
  140. }
  141. /******************************************************************************/
  142. static int
  143. out_element(struct soap *soap, const struct soap_dom_element *node, const char *prefix, const char *name)
  144. { if (node->head && soap_send(soap, node->head))
  145. return soap->error;
  146. if (node->type && node->node)
  147. { if (prefix && *prefix)
  148. { char *s = (char*)SOAP_MALLOC(soap, strlen(prefix) + strlen(name) + 2);
  149. if (!s)
  150. return soap->error = SOAP_EOM;
  151. sprintf(s, "%s:%s", prefix, name);
  152. soap_putelement(soap, node->node, s, 0, node->type);
  153. SOAP_FREE(soap, s);
  154. }
  155. else
  156. return soap_putelement(soap, node->node, name, 0, node->type);
  157. }
  158. else if (prefix && *prefix)
  159. { char *s;
  160. if (strlen(prefix) + strlen(name) < sizeof(soap->msgbuf))
  161. s = soap->msgbuf;
  162. else
  163. { s = (char*)SOAP_MALLOC(soap, strlen(prefix) + strlen(name) + 2);
  164. if (!s)
  165. return soap->error = SOAP_EOM;
  166. }
  167. sprintf(s, "%s:%s", prefix, name);
  168. soap_element(soap, s, 0, NULL); /* element() */
  169. if (s != soap->msgbuf)
  170. SOAP_FREE(soap, s);
  171. }
  172. else if (*name != '-')
  173. { soap_mode m = soap->mode;
  174. if ((soap->mode & SOAP_DOM_ASIS))
  175. soap->mode &= ~SOAP_XML_INDENT;
  176. soap_element(soap, name, 0, NULL); /* element() */
  177. soap->mode = m;
  178. }
  179. return soap->error;
  180. }
  181. /******************************************************************************/
  182. static int
  183. out_attribute(struct soap *soap, const char *prefix, const char *name, const char *data, const wchar_t *wide, int flag)
  184. { char *s;
  185. const char *t;
  186. int err;
  187. if (wide)
  188. data = soap_wchar2s(soap, wide);
  189. if (!prefix || !*prefix)
  190. { if (wide)
  191. return soap_set_attr(soap, name, data, 2);
  192. if (flag)
  193. return soap_set_attr(soap, name, data, 1);
  194. return soap_attribute(soap, name, data);
  195. }
  196. t = strchr(name, ':');
  197. if (t)
  198. t++;
  199. else
  200. t = name;
  201. if (strlen(prefix) + strlen(t) < sizeof(soap->msgbuf))
  202. s = soap->msgbuf;
  203. else
  204. { s = (char*)SOAP_MALLOC(soap, strlen(prefix) + strlen(t) + 2);
  205. if (!s)
  206. return soap->error = SOAP_EOM;
  207. }
  208. sprintf(s, "%s:%s", prefix, t);
  209. if (wide)
  210. err = soap_set_attr(soap, s, data, 2);
  211. else if (flag)
  212. err = soap_set_attr(soap, s, data, 1);
  213. else
  214. err = soap_attribute(soap, s, data);
  215. if (s != soap->msgbuf)
  216. SOAP_FREE(soap, s);
  217. return err;
  218. }
  219. /******************************************************************************/
  220. SOAP_FMAC1
  221. int
  222. SOAP_FMAC2
  223. soap_out_xsd__anyType(struct soap *soap, const char *tag, int id, const struct soap_dom_element *node, const char *type)
  224. { if (node)
  225. { const char *prefix; /* namespace prefix, if namespace is present */
  226. size_t colon;
  227. if (!(soap->mode & SOAP_DOM_ASIS))
  228. { const struct soap_dom_attribute *att;
  229. for (att = node->atts; att; att = att->next)
  230. { if (att->name && att->data && !strncmp(att->name, "xmlns:", 6))
  231. { if (soap_push_namespace(soap, att->name + 6, att->data) == NULL)
  232. return soap->error;
  233. }
  234. else if (att->name && att->data && !strcmp(att->name, "xmlns"))
  235. { if (soap_push_namespace(soap, "", att->data) == NULL)
  236. return soap->error;
  237. }
  238. }
  239. }
  240. if (node->name)
  241. tag = node->name;
  242. else if (!tag)
  243. tag = "-";
  244. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' output at level %u\n", tag, soap->level));
  245. if ((prefix = strchr(tag, ':')))
  246. { colon = prefix - tag + 1;
  247. if (colon > sizeof(soap->tag))
  248. colon = sizeof(soap->tag);
  249. }
  250. else
  251. colon = 0;
  252. prefix = NULL;
  253. if (node->nstr && *node->nstr && !(soap->mode & SOAP_DOM_ASIS))
  254. { if (colon)
  255. { strncpy(soap->tag, tag, colon - 1);
  256. soap->tag[colon - 1] = '\0';
  257. if ((prefix = soap_push_ns_prefix(soap, soap->tag, node->nstr, 1)) == NULL
  258. || out_element(soap, node, prefix, tag + colon))
  259. return soap->error;
  260. }
  261. else
  262. { if ((prefix = soap_lookup_ns_prefix(soap, node->nstr)))
  263. { if (out_element(soap, node, prefix, tag + colon))
  264. return soap->error;
  265. }
  266. else
  267. { if ((prefix = soap_push_ns_prefix(soap, NULL, node->nstr, 1)) == NULL
  268. || out_element(soap, node, prefix, tag + colon))
  269. return soap->error;
  270. }
  271. }
  272. }
  273. else
  274. { colon = 0;
  275. if (out_element(soap, node, NULL, tag))
  276. return soap->error;
  277. }
  278. if (!node->type || !node->node)
  279. { struct soap_dom_attribute *att;
  280. struct soap_dom_element *elt;
  281. for (att = node->atts; att; att = att->next)
  282. { if (att->name)
  283. { if (att->nstr && !(soap->mode & SOAP_DOM_ASIS))
  284. { const char *p;
  285. if ((att->nstr == node->nstr || (node->nstr && !strcmp(att->nstr, node->nstr))) && prefix)
  286. { if (out_attribute(soap, prefix, att->name, att->data, att->wide, 0))
  287. return soap->error;
  288. }
  289. else if ((p = soap_lookup_ns_prefix(soap, att->nstr)))
  290. { if (out_attribute(soap, p, att->name, att->data, att->wide, 0))
  291. return soap->error;
  292. }
  293. else if (!strncmp(att->name, "xml", 3))
  294. { if (out_attribute(soap, NULL, att->name, att->data, att->wide, 0))
  295. return soap->error;
  296. }
  297. else if ((p = soap_push_ns_prefix(soap, NULL, att->nstr, 0)) == NULL
  298. || out_attribute(soap, p, att->name, att->data, att->wide, 0))
  299. return soap->error;
  300. }
  301. else if (soap_attribute(soap, att->name, att->wide ? soap_wchar2s(soap, att->wide) : att->data))
  302. return soap->error;
  303. }
  304. }
  305. if ((soap->mode & SOAP_DOM_ASIS) && !node->data && !node->wide && !node->elts && !node->tail)
  306. { soap_mode m = soap->mode;
  307. soap->mode &= ~SOAP_XML_INDENT;
  308. if (*tag != '-' && soap_element_start_end_out(soap, tag))
  309. return soap->error;
  310. soap->mode = m;
  311. }
  312. else
  313. { if (*tag != '-' && soap_element_start_end_out(soap, NULL))
  314. return soap->error;
  315. if (*tag != '-' && node->data)
  316. { if (soap_string_out(soap, node->data, 0))
  317. return soap->error;
  318. }
  319. else if (node->data)
  320. { if (soap_send(soap, node->data))
  321. return soap->error;
  322. }
  323. else if (node->wide)
  324. { if (soap_wstring_out(soap, node->wide, 0))
  325. return soap->error;
  326. }
  327. for (elt = node->elts; elt; elt = elt->next)
  328. { if (soap_out_xsd__anyType(soap, NULL, 0, elt, NULL))
  329. return soap->error;
  330. }
  331. if (node->tail && soap_send(soap, node->tail))
  332. return soap->error;
  333. if (!prefix || !*prefix)
  334. { soap_mode m = soap->mode;
  335. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of DOM node '%s'\n", tag + colon));
  336. if ((soap->mode & SOAP_DOM_ASIS))
  337. soap->mode &= ~SOAP_XML_INDENT;
  338. if (soap_element_end_out(soap, tag + colon))
  339. return soap->error;
  340. soap->mode = m;
  341. }
  342. else
  343. { char *s;
  344. if (strlen(prefix) + strlen(tag + colon) < sizeof(soap->msgbuf))
  345. s = soap->msgbuf;
  346. else
  347. { s = (char*)SOAP_MALLOC(soap, strlen(prefix) + strlen(tag + colon) + 2);
  348. if (!s)
  349. return soap->error = SOAP_EOM;
  350. }
  351. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of DOM node '%s'\n", tag));
  352. sprintf(s, "%s:%s", prefix, tag + colon);
  353. soap_pop_namespace(soap);
  354. if (soap_element_end_out(soap, s))
  355. return soap->error;
  356. if (s != soap->msgbuf)
  357. SOAP_FREE(soap, s);
  358. }
  359. }
  360. }
  361. }
  362. return SOAP_OK;
  363. }
  364. /******************************************************************************/
  365. SOAP_FMAC1
  366. int
  367. SOAP_FMAC2
  368. soap_out_xsd__anyAttribute(struct soap *soap, const char *tag, int id, const struct soap_dom_attribute *node, const char *type)
  369. { if (!(soap->mode & SOAP_DOM_ASIS))
  370. { const struct soap_dom_attribute *att;
  371. for (att = node; att; att = att->next)
  372. { if (att->name && att->data && !strncmp(att->name, "xmlns:", 6))
  373. { if (soap_push_namespace(soap, att->name + 6, att->data) == NULL)
  374. return soap->error;
  375. }
  376. else if (att->name && att->data && !strcmp(att->name, "xmlns"))
  377. { if (soap_push_namespace(soap, "", att->data) == NULL)
  378. return soap->error;
  379. }
  380. }
  381. }
  382. while (node)
  383. { if (node->name)
  384. { if (node->nstr && !(soap->mode & SOAP_DOM_ASIS) && strncmp(node->name, "xml", 3) && !strchr(node->name, ':'))
  385. { const char *p;
  386. p = soap_lookup_ns_prefix(soap, node->nstr);
  387. if (!p && !(p = soap_push_ns_prefix(soap, NULL, node->nstr, 1)))
  388. return soap->error;
  389. if (out_attribute(soap, p, node->name, node->data, node->wide, 1))
  390. return soap->error;
  391. }
  392. else
  393. out_attribute(soap, NULL, node->name, node->data, node->wide, 1);
  394. }
  395. node = node->next;
  396. }
  397. return SOAP_OK;
  398. }
  399. /******************************************************************************/
  400. SOAP_FMAC1
  401. struct soap_dom_element *
  402. SOAP_FMAC2
  403. soap_in_xsd__anyType(struct soap *soap, const char *tag, struct soap_dom_element *node, const char *type)
  404. { register struct soap_attribute *tp;
  405. register struct soap_dom_attribute **att;
  406. if (soap_peek_element(soap))
  407. { if (soap->error != SOAP_NO_TAG)
  408. return NULL;
  409. if (!node)
  410. { if (!(node = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element))))
  411. { soap->error = SOAP_EOM;
  412. return NULL;
  413. }
  414. }
  415. soap_default_xsd__anyType(soap, node);
  416. if (!(node->data = soap_string_in(soap, 1, -1, -1)) || !*node->data)
  417. return NULL;
  418. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node with cdata\n"));
  419. soap->error = SOAP_OK;
  420. return node;
  421. }
  422. if (!node)
  423. { if (!(node = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element))))
  424. { soap->error = SOAP_EOM;
  425. return NULL;
  426. }
  427. }
  428. soap_default_xsd__anyType(soap, node);
  429. node->nstr = soap_current_namespace(soap, soap->tag);
  430. if ((soap->mode & SOAP_DOM_ASIS))
  431. node->name = soap_strdup(soap, soap->tag);
  432. else
  433. { char *s = strchr(soap->tag, ':');
  434. if (s)
  435. node->name = soap_strdup(soap, s+1);
  436. else
  437. node->name = soap_strdup(soap, soap->tag);
  438. }
  439. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' start xmlns='%s'\n", node->name, node->nstr?node->nstr:""));
  440. if ((soap->mode & SOAP_DOM_NODE) || (!(soap->mode & SOAP_DOM_TREE) && *soap->id))
  441. { if ((node->node = soap_getelement(soap, &node->type)) && node->type)
  442. { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node contains type %d from xsi:type\n", node->type));
  443. return node;
  444. }
  445. if (soap->error == SOAP_TAG_MISMATCH)
  446. soap->error = SOAP_OK;
  447. else
  448. return NULL;
  449. }
  450. att = &node->atts;
  451. for (tp = soap->attributes; tp; tp = tp->next)
  452. { if (tp->visible)
  453. { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node attribute='%s'\n", tp->name));
  454. *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
  455. if (!*att)
  456. { soap->error = SOAP_EOM;
  457. return NULL;
  458. }
  459. (*att)->next = NULL;
  460. (*att)->nstr = soap_current_namespace(soap, tp->name);
  461. if ((soap->mode & SOAP_DOM_ASIS) || !strncmp(tp->name, "xml", 3))
  462. (*att)->name = soap_strdup(soap, tp->name);
  463. else
  464. { char *s = strchr(tp->name, ':');
  465. if (s)
  466. (*att)->name = soap_strdup(soap, s+1);
  467. else
  468. (*att)->name = soap_strdup(soap, tp->name);
  469. }
  470. if (tp->visible == 2)
  471. (*att)->data = soap_strdup(soap, tp->value);
  472. else
  473. (*att)->data = NULL;
  474. (*att)->wide = NULL;
  475. (*att)->soap = soap;
  476. att = &(*att)->next;
  477. tp->visible = 0;
  478. }
  479. }
  480. soap_element_begin_in(soap, NULL, 1, NULL);
  481. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' pulled\n", node->name));
  482. if (soap->body)
  483. { if (!soap_peek_element(soap))
  484. { struct soap_dom_element **elt;
  485. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' has subelements\n", node->name));
  486. elt = &node->elts;
  487. for (;;)
  488. { if (!(*elt = soap_in_xsd__anyType(soap, NULL, NULL, NULL)))
  489. { if (soap->error != SOAP_NO_TAG)
  490. return NULL;
  491. soap->error = SOAP_OK;
  492. break;
  493. }
  494. (*elt)->prnt = node;
  495. elt = &(*elt)->next;
  496. }
  497. }
  498. else if (soap->error == SOAP_NO_TAG)
  499. { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' has cdata\n", node->name));
  500. if ((soap->mode & SOAP_C_UTFSTRING) || (soap->mode & SOAP_C_MBSTRING))
  501. { if (!(node->data = soap_string_in(soap, 1, -1, -1)))
  502. return NULL;
  503. }
  504. else if (!(node->wide = soap_wstring_in(soap, 1, -1, -1)))
  505. return NULL;
  506. }
  507. else
  508. return NULL;
  509. if (soap_element_end_in(soap, node->name))
  510. return NULL;
  511. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node end '%s'\n", node->name));
  512. }
  513. return node;
  514. }
  515. /******************************************************************************/
  516. SOAP_FMAC1
  517. struct soap_dom_attribute *
  518. SOAP_FMAC2
  519. soap_in_xsd__anyAttribute(struct soap *soap, const char *tag, struct soap_dom_attribute *node, const char *type)
  520. { register struct soap_attribute *tp;
  521. struct soap_dom_attribute *tmp = node;
  522. struct soap_dom_attribute *att = node;
  523. for (tp = soap->attributes; tp; tp = tp->next)
  524. { if (tp->visible)
  525. { if (!att)
  526. { att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
  527. if (tmp)
  528. tmp->next = att;
  529. else
  530. node = att;
  531. tmp = att;
  532. }
  533. DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node attribute='%s'\n", tp->name));
  534. if (!att)
  535. { soap->error = SOAP_EOM;
  536. return NULL;
  537. }
  538. att->next = NULL;
  539. att->nstr = soap_current_namespace(soap, tp->name);
  540. if ((soap->mode & SOAP_DOM_ASIS) || !strncmp(tp->name, "xml", 3))
  541. att->name = soap_strdup(soap, tp->name);
  542. else
  543. { char *s = strchr(tp->name, ':');
  544. if (s)
  545. att->name = soap_strdup(soap, s+1);
  546. else
  547. att->name = soap_strdup(soap, tp->name);
  548. }
  549. if (tp->visible == 2)
  550. att->data = soap_strdup(soap, tp->value);
  551. else
  552. att->data = NULL;
  553. att->wide = NULL;
  554. att->soap = soap;
  555. att = NULL;
  556. }
  557. }
  558. return node;
  559. }
  560. /******************************************************************************\
  561. *
  562. * DOM traversing
  563. *
  564. \******************************************************************************/
  565. SOAP_FMAC1
  566. struct soap_dom_element *
  567. SOAP_FMAC2
  568. soap_dom_next_element(struct soap_dom_element *elt)
  569. { if (elt->elts)
  570. return elt->elts;
  571. if (elt->next)
  572. return elt->next;
  573. do elt = elt->prnt;
  574. while (elt && !elt->next);
  575. if (elt)
  576. elt = elt->next;
  577. return elt;
  578. }
  579. /******************************************************************************/
  580. struct soap_dom_attribute *
  581. soap_dom_next_attribute(struct soap_dom_attribute *att)
  582. { return att->next;
  583. }
  584. /******************************************************************************\
  585. *
  586. * Namespace prefix lookup/store
  587. *
  588. \******************************************************************************/
  589. static const char *
  590. soap_lookup_ns_prefix(struct soap *soap, const char *ns)
  591. { register struct soap_nlist *np;
  592. for (np = soap->nlist; np; np = np->next)
  593. { if (np->ns && !strcmp(np->ns, ns))
  594. return np->id;
  595. }
  596. return NULL;
  597. }
  598. /******************************************************************************/
  599. static const char *
  600. soap_push_ns_prefix(struct soap *soap, const char *id, const char *ns, int flag)
  601. { register struct soap_nlist *np;
  602. if (!id)
  603. { struct Namespace *n;
  604. for (n = soap->local_namespaces; n && n->id; n++)
  605. { if (n->ns && !strcmp(n->ns, ns))
  606. { id = n->id;
  607. break;
  608. }
  609. }
  610. if (!id)
  611. { sprintf(soap->tag, SOAP_DOMID_FORMAT, soap->idnum++);
  612. id = soap->tag;
  613. }
  614. }
  615. /* fix advance generation of xmlns, when element (level) is not output yet */
  616. if (flag)
  617. soap->level++;
  618. np = soap_push_namespace(soap, id, ns);
  619. if (flag)
  620. soap->level--;
  621. if (!np)
  622. return NULL;
  623. if (!np->ns)
  624. { np->ns = soap->local_namespaces[np->index].out;
  625. if (!np->ns)
  626. np->ns = soap->local_namespaces[np->index].ns;
  627. }
  628. np->index = 0; /* for C14N utilized mark */
  629. if (*np->id)
  630. { sprintf(soap->msgbuf, "xmlns:%s", np->id);
  631. out_attribute(soap, NULL, soap->msgbuf, ns, NULL, flag);
  632. }
  633. else
  634. out_attribute(soap, NULL, "xmlns", ns, NULL, flag);
  635. return np->id;
  636. }
  637. #ifdef __cplusplus
  638. /******************************************************************************\
  639. *
  640. * soap_dom_element class
  641. *
  642. \******************************************************************************/
  643. soap_dom_element::soap_dom_element()
  644. { soap_default_xsd__anyType(NULL, this);
  645. }
  646. /******************************************************************************/
  647. soap_dom_element::soap_dom_element(struct soap *soap)
  648. { soap_default_xsd__anyType(soap, this);
  649. }
  650. /******************************************************************************/
  651. soap_dom_element::soap_dom_element(struct soap *soap, const char *nstr, const char *name)
  652. { soap_default_xsd__anyType(soap, this);
  653. this->nstr = soap_strdup(soap, nstr);
  654. this->name = soap_strdup(soap, name);
  655. }
  656. /******************************************************************************/
  657. soap_dom_element::soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data)
  658. { soap_default_xsd__anyType(soap, this);
  659. this->nstr = soap_strdup(soap, nstr);
  660. this->name = soap_strdup(soap, name);
  661. this->data = soap_strdup(soap, data);
  662. }
  663. /******************************************************************************/
  664. soap_dom_element::soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type)
  665. { soap_default_xsd__anyType(soap, this);
  666. this->nstr = soap_strdup(soap, nstr);
  667. this->name = soap_strdup(soap, name);
  668. this->node = node;
  669. this->type = type;
  670. }
  671. /******************************************************************************/
  672. soap_dom_element::~soap_dom_element()
  673. { }
  674. /******************************************************************************/
  675. soap_dom_element &soap_dom_element::set(const char *nstr, const char *name)
  676. { this->nstr = soap_strdup(soap, nstr);
  677. this->name = soap_strdup(soap, name);
  678. return *this;
  679. }
  680. /******************************************************************************/
  681. soap_dom_element &soap_dom_element::set(const char *data)
  682. { this->data = soap_strdup(soap, data);
  683. return *this;
  684. }
  685. /******************************************************************************/
  686. soap_dom_element &soap_dom_element::set(void *node, int type)
  687. { this->node = node;
  688. this->type = type;
  689. return *this;
  690. }
  691. /******************************************************************************/
  692. soap_dom_element &soap_dom_element::add(struct soap_dom_element *elt)
  693. { elt->prnt = this;
  694. for (struct soap_dom_element *e = elts; e; e = e->next)
  695. { if (!e->next)
  696. { e->next = elt;
  697. return *this;
  698. }
  699. }
  700. elts = elt;
  701. return *this;
  702. }
  703. /******************************************************************************/
  704. soap_dom_element &soap_dom_element::add(struct soap_dom_element &elt)
  705. { return add(&elt);
  706. }
  707. /******************************************************************************/
  708. soap_dom_element &soap_dom_element::add(struct soap_dom_attribute *att)
  709. { for (struct soap_dom_attribute *a = atts; a; a = a->next)
  710. { if (!a->next)
  711. { a->next = att;
  712. return *this;
  713. }
  714. }
  715. atts = att;
  716. return *this;
  717. }
  718. /******************************************************************************/
  719. soap_dom_element &soap_dom_element::add(struct soap_dom_attribute &att)
  720. { return add(&att);
  721. }
  722. /******************************************************************************/
  723. soap_dom_element_iterator soap_dom_element::begin()
  724. { soap_dom_element_iterator iter(this);
  725. return iter;
  726. }
  727. /******************************************************************************/
  728. soap_dom_element_iterator soap_dom_element::end()
  729. { soap_dom_element_iterator iter(NULL);
  730. return iter;
  731. }
  732. /******************************************************************************/
  733. soap_dom_element_iterator soap_dom_element::find(const char *nstr, const char *name)
  734. { soap_dom_element_iterator iter(this);
  735. iter.nstr = nstr;
  736. iter.name = name;
  737. if (name && soap_tag_cmp(this->name, name))
  738. return ++iter;
  739. if (nstr && this->nstr && soap_tag_cmp(this->nstr, nstr))
  740. return ++iter;
  741. return iter;
  742. }
  743. /******************************************************************************/
  744. soap_dom_element_iterator soap_dom_element::find(int type)
  745. { soap_dom_element_iterator iter(this);
  746. iter.type = type;
  747. if (this->type != type)
  748. return ++iter;
  749. return iter;
  750. }
  751. /******************************************************************************/
  752. void soap_dom_element::unlink()
  753. { soap_unlink(soap, this);
  754. soap_unlink(soap, nstr);
  755. soap_unlink(soap, name);
  756. soap_unlink(soap, data);
  757. soap_unlink(soap, wide);
  758. if (elts)
  759. elts->unlink();
  760. if (atts)
  761. atts->unlink();
  762. if (next)
  763. next->unlink();
  764. node = NULL;
  765. type = 0;
  766. }
  767. /******************************************************************************\
  768. *
  769. * soap_dom_attribute class
  770. *
  771. \******************************************************************************/
  772. soap_dom_attribute::soap_dom_attribute()
  773. { this->soap = NULL;
  774. this->next = NULL;
  775. this->nstr = NULL;
  776. this->name = NULL;
  777. this->data = NULL;
  778. this->wide = NULL;
  779. }
  780. /******************************************************************************/
  781. soap_dom_attribute::soap_dom_attribute(struct soap *soap)
  782. { this->soap = soap;
  783. this->next = NULL;
  784. this->nstr = NULL;
  785. this->name = NULL;
  786. this->data = NULL;
  787. this->wide = NULL;
  788. }
  789. /******************************************************************************/
  790. soap_dom_attribute::soap_dom_attribute(struct soap *soap, const char *nstr, const char *name, const char *data)
  791. { this->soap = soap;
  792. this->next = NULL;
  793. this->nstr = soap_strdup(soap, nstr);
  794. this->name = soap_strdup(soap, name);
  795. this->data = soap_strdup(soap, data);
  796. this->wide = NULL;
  797. }
  798. /******************************************************************************/
  799. soap_dom_attribute::~soap_dom_attribute()
  800. { }
  801. /******************************************************************************/
  802. soap_dom_attribute &soap_dom_attribute::set(const char *nstr, const char *name)
  803. { this->nstr = soap_strdup(soap, nstr);
  804. this->name = soap_strdup(soap, name);
  805. return *this;
  806. }
  807. /******************************************************************************/
  808. soap_dom_attribute &soap_dom_attribute::set(const char *data)
  809. { this->data = soap_strdup(soap, data);
  810. return *this;
  811. }
  812. /******************************************************************************/
  813. soap_dom_attribute_iterator soap_dom_attribute::begin()
  814. { soap_dom_attribute_iterator iter(this);
  815. return iter;
  816. }
  817. /******************************************************************************/
  818. soap_dom_attribute_iterator soap_dom_attribute::end()
  819. { soap_dom_attribute_iterator iter(NULL);
  820. return iter;
  821. }
  822. /******************************************************************************/
  823. soap_dom_attribute_iterator soap_dom_attribute::find(const char *nstr, const char *name)
  824. { soap_dom_attribute_iterator iter(this);
  825. iter.nstr = nstr;
  826. iter.name = name;
  827. if (name && soap_tag_cmp(this->name, name))
  828. return ++iter;
  829. if (nstr && this->nstr && soap_tag_cmp(this->nstr, nstr))
  830. return ++iter;
  831. return iter;
  832. }
  833. /******************************************************************************/
  834. void soap_dom_attribute::unlink()
  835. { soap_unlink(soap, this);
  836. soap_unlink(soap, nstr);
  837. soap_unlink(soap, name);
  838. soap_unlink(soap, data);
  839. soap_unlink(soap, wide);
  840. if (next)
  841. next->unlink();
  842. }
  843. /******************************************************************************\
  844. *
  845. * soap_dom_element_iterator class
  846. *
  847. \******************************************************************************/
  848. soap_dom_element_iterator::soap_dom_element_iterator()
  849. { elt = NULL;
  850. nstr = NULL;
  851. name = NULL;
  852. type = 0;
  853. }
  854. /******************************************************************************/
  855. soap_dom_element_iterator::soap_dom_element_iterator(struct soap_dom_element *elt)
  856. { this->elt = elt;
  857. nstr = NULL;
  858. name = NULL;
  859. type = 0;
  860. }
  861. /******************************************************************************/
  862. soap_dom_element_iterator::~soap_dom_element_iterator()
  863. { }
  864. /******************************************************************************/
  865. bool soap_dom_element_iterator::operator==(const soap_dom_element_iterator &iter) const
  866. { return this->elt == iter.elt;
  867. }
  868. /******************************************************************************/
  869. bool soap_dom_element_iterator::operator!=(const soap_dom_element_iterator &iter) const
  870. { return this->elt != iter.elt;
  871. }
  872. /******************************************************************************/
  873. struct soap_dom_element &soap_dom_element_iterator::operator*() const
  874. { return *this->elt;
  875. }
  876. /******************************************************************************/
  877. soap_dom_element_iterator &soap_dom_element_iterator::operator++()
  878. { while (elt)
  879. { elt = soap_dom_next_element(elt);
  880. if (!elt)
  881. break;
  882. if (name && elt->name)
  883. { if (!soap_tag_cmp(elt->name, name))
  884. { if (nstr && elt->nstr)
  885. { if (!soap_tag_cmp(elt->nstr, nstr))
  886. break;
  887. }
  888. else
  889. break;
  890. }
  891. }
  892. else if (type)
  893. { if (elt->type == type)
  894. break;
  895. }
  896. else
  897. break;
  898. }
  899. return *this;
  900. }
  901. /******************************************************************************\
  902. *
  903. * soap_dom_attribute_iterator class
  904. *
  905. \******************************************************************************/
  906. soap_dom_attribute_iterator::soap_dom_attribute_iterator()
  907. { att = NULL;
  908. nstr = NULL;
  909. name = NULL;
  910. }
  911. /******************************************************************************/
  912. soap_dom_attribute_iterator::soap_dom_attribute_iterator(struct soap_dom_attribute *att)
  913. { this->att = att;
  914. nstr = NULL;
  915. name = NULL;
  916. }
  917. /******************************************************************************/
  918. soap_dom_attribute_iterator::~soap_dom_attribute_iterator()
  919. { }
  920. /******************************************************************************/
  921. bool soap_dom_attribute_iterator::operator==(const soap_dom_attribute_iterator &iter) const
  922. { return this->att == iter.att;
  923. }
  924. /******************************************************************************/
  925. bool soap_dom_attribute_iterator::operator!=(const soap_dom_attribute_iterator &iter) const
  926. { return this->att != iter.att;
  927. }
  928. /******************************************************************************/
  929. struct soap_dom_attribute &soap_dom_attribute_iterator::operator*() const
  930. { return *this->att;
  931. }
  932. /******************************************************************************/
  933. soap_dom_attribute_iterator &soap_dom_attribute_iterator::operator++()
  934. { while (att)
  935. { att = soap_dom_next_attribute(att);
  936. if (!att)
  937. break;
  938. if (name && att->name)
  939. { if (!soap_tag_cmp(att->name, name))
  940. { if (nstr && att->nstr)
  941. { if (!soap_tag_cmp(att->nstr, nstr))
  942. break;
  943. }
  944. else
  945. break;
  946. }
  947. }
  948. else
  949. break;
  950. }
  951. return *this;
  952. }
  953. /******************************************************************************\
  954. *
  955. * I/O
  956. *
  957. \******************************************************************************/
  958. #ifndef UNDER_CE
  959. std::ostream &operator<<(std::ostream &o, const struct soap_dom_element &e)
  960. { if (!e.soap)
  961. { struct soap soap;
  962. soap_init2(&soap, SOAP_IO_DEFAULT, SOAP_XML_GRAPH);
  963. soap_serialize_xsd__anyType(&soap, &e);
  964. soap_begin_send(&soap);
  965. soap.ns = 2; /* do not dump namespace table */
  966. soap_out_xsd__anyType(&soap, NULL, 0, &e, NULL);
  967. soap_end_send(&soap);
  968. soap_end(&soap);
  969. soap_done(&soap);
  970. }
  971. else
  972. { std::ostream *os = e.soap->os;
  973. e.soap->os = &o;
  974. soap_mode omode = e.soap->omode;
  975. soap_set_omode(e.soap, SOAP_XML_GRAPH);
  976. soap_serialize_xsd__anyType(e.soap, &e);
  977. soap_begin_send(e.soap);
  978. e.soap->ns = 2; /* do not dump namespace table */
  979. soap_out_xsd__anyType(e.soap, NULL, 0, &e, NULL);
  980. soap_end_send(e.soap);
  981. e.soap->os = os;
  982. e.soap->omode = omode;
  983. }
  984. return o;
  985. }
  986. /******************************************************************************/
  987. std::istream &operator>>(std::istream &i, struct soap_dom_element &e)
  988. { if (!e.soap)
  989. e.soap = soap_new();
  990. std::istream *is = e.soap->is;
  991. e.soap->is = &i;
  992. if (soap_begin_recv(e.soap)
  993. || !soap_in_xsd__anyType(e.soap, NULL, &e, NULL)
  994. || soap_end_recv(e.soap))
  995. { /* handle error? Note: e.soap->error is set and app should check */
  996. }
  997. e.soap->is = is;
  998. return i;
  999. }
  1000. #endif
  1001. #endif