PageRenderTime 61ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/ext/soap/php_sdl.c

http://github.com/infusion/PHP
C | 3660 lines | 3150 code | 451 blank | 59 comment | 937 complexity | 20c169c3e9195f7297b0b7594439edd9 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2011 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Brad Lafountain <rodif_bl@yahoo.com> |
  16. | Shane Caraveo <shane@caraveo.com> |
  17. | Dmitry Stogov <dmitry@zend.com> |
  18. +----------------------------------------------------------------------+
  19. */
  20. /* $Id: php_sdl.c 306939 2011-01-01 02:19:59Z felipe $ */
  21. #include "php_soap.h"
  22. #include "ext/libxml/php_libxml.h"
  23. #include "libxml/uri.h"
  24. #include "ext/standard/md5.h"
  25. #include "tsrm_virtual_cwd.h"
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include <fcntl.h>
  29. #ifndef O_BINARY
  30. # define O_BINARY 0
  31. #endif
  32. static void delete_fault(void *fault);
  33. static void delete_fault_persistent(void *fault);
  34. static void delete_binding(void *binding);
  35. static void delete_binding_persistent(void *binding);
  36. static void delete_function(void *function);
  37. static void delete_function_persistent(void *function);
  38. static void delete_parameter(void *paramater);
  39. static void delete_parameter_persistent(void *paramater);
  40. static void delete_header(void *header);
  41. static void delete_header_persistent(void *header);
  42. static void delete_document(void *doc_ptr);
  43. encodePtr get_encoder_from_prefix(sdlPtr sdl, xmlNodePtr node, const xmlChar *type)
  44. {
  45. encodePtr enc = NULL;
  46. xmlNsPtr nsptr;
  47. char *ns, *cptype;
  48. parse_namespace(type, &cptype, &ns);
  49. nsptr = xmlSearchNs(node->doc, node, BAD_CAST(ns));
  50. if (nsptr != NULL) {
  51. enc = get_encoder(sdl, (char*)nsptr->href, cptype);
  52. if (enc == NULL) {
  53. enc = get_encoder_ex(sdl, cptype, strlen(cptype));
  54. }
  55. } else {
  56. enc = get_encoder_ex(sdl, (char*)type, xmlStrlen(type));
  57. }
  58. efree(cptype);
  59. if (ns) {efree(ns);}
  60. return enc;
  61. }
  62. static sdlTypePtr get_element(sdlPtr sdl, xmlNodePtr node, const xmlChar *type)
  63. {
  64. sdlTypePtr ret = NULL;
  65. if (sdl->elements) {
  66. xmlNsPtr nsptr;
  67. char *ns, *cptype;
  68. sdlTypePtr *sdl_type;
  69. parse_namespace(type, &cptype, &ns);
  70. nsptr = xmlSearchNs(node->doc, node, BAD_CAST(ns));
  71. if (nsptr != NULL) {
  72. int ns_len = xmlStrlen(nsptr->href);
  73. int type_len = strlen(cptype);
  74. int len = ns_len + type_len + 1;
  75. char *nscat = emalloc(len + 1);
  76. memcpy(nscat, nsptr->href, ns_len);
  77. nscat[ns_len] = ':';
  78. memcpy(nscat+ns_len+1, cptype, type_len);
  79. nscat[len] = '\0';
  80. if (zend_hash_find(sdl->elements, nscat, len + 1, (void **)&sdl_type) == SUCCESS) {
  81. ret = *sdl_type;
  82. } else if (zend_hash_find(sdl->elements, (char*)type, type_len + 1, (void **)&sdl_type) == SUCCESS) {
  83. ret = *sdl_type;
  84. }
  85. efree(nscat);
  86. } else {
  87. if (zend_hash_find(sdl->elements, (char*)type, xmlStrlen(type) + 1, (void **)&sdl_type) == SUCCESS) {
  88. ret = *sdl_type;
  89. }
  90. }
  91. efree(cptype);
  92. if (ns) {efree(ns);}
  93. }
  94. return ret;
  95. }
  96. encodePtr get_encoder(sdlPtr sdl, const char *ns, const char *type)
  97. {
  98. encodePtr enc = NULL;
  99. char *nscat;
  100. int ns_len = strlen(ns);
  101. int type_len = strlen(type);
  102. int len = ns_len + type_len + 1;
  103. nscat = emalloc(len + 1);
  104. memcpy(nscat, ns, ns_len);
  105. nscat[ns_len] = ':';
  106. memcpy(nscat+ns_len+1, type, type_len);
  107. nscat[len] = '\0';
  108. enc = get_encoder_ex(sdl, nscat, len);
  109. if (enc == NULL &&
  110. ((ns_len == sizeof(SOAP_1_1_ENC_NAMESPACE)-1 &&
  111. memcmp(ns, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1) == 0) ||
  112. (ns_len == sizeof(SOAP_1_2_ENC_NAMESPACE)-1 &&
  113. memcmp(ns, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1) == 0))) {
  114. char *enc_nscat;
  115. int enc_ns_len;
  116. int enc_len;
  117. enc_ns_len = sizeof(XSD_NAMESPACE)-1;
  118. enc_len = enc_ns_len + type_len + 1;
  119. enc_nscat = emalloc(enc_len + 1);
  120. memcpy(enc_nscat, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1);
  121. enc_nscat[enc_ns_len] = ':';
  122. memcpy(enc_nscat+enc_ns_len+1, type, type_len);
  123. enc_nscat[enc_len] = '\0';
  124. enc = get_encoder_ex(NULL, enc_nscat, enc_len);
  125. efree(enc_nscat);
  126. if (enc && sdl) {
  127. encodePtr new_enc = pemalloc(sizeof(encode), sdl->is_persistent);
  128. memcpy(new_enc, enc, sizeof(encode));
  129. if (sdl->is_persistent) {
  130. new_enc->details.ns = zend_strndup(ns, ns_len);
  131. new_enc->details.type_str = strdup(new_enc->details.type_str);
  132. } else {
  133. new_enc->details.ns = estrndup(ns, ns_len);
  134. new_enc->details.type_str = estrdup(new_enc->details.type_str);
  135. }
  136. if (sdl->encoders == NULL) {
  137. sdl->encoders = pemalloc(sizeof(HashTable), sdl->is_persistent);
  138. zend_hash_init(sdl->encoders, 0, NULL, delete_encoder, sdl->is_persistent);
  139. }
  140. zend_hash_update(sdl->encoders, nscat, len + 1, &new_enc, sizeof(encodePtr), NULL);
  141. enc = new_enc;
  142. }
  143. }
  144. efree(nscat);
  145. return enc;
  146. }
  147. encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat, int len)
  148. {
  149. encodePtr *enc;
  150. TSRMLS_FETCH();
  151. if (zend_hash_find(&SOAP_GLOBAL(defEnc), (char*)nscat, len + 1, (void **)&enc) == SUCCESS) {
  152. return (*enc);
  153. } else if (sdl && sdl->encoders && zend_hash_find(sdl->encoders, (char*)nscat, len + 1, (void **)&enc) == SUCCESS) {
  154. return (*enc);
  155. }
  156. return NULL;
  157. }
  158. sdlBindingPtr get_binding_from_type(sdlPtr sdl, int type)
  159. {
  160. sdlBindingPtr *binding;
  161. if (sdl == NULL) {
  162. return NULL;
  163. }
  164. for (zend_hash_internal_pointer_reset(sdl->bindings);
  165. zend_hash_get_current_data(sdl->bindings, (void **) &binding) == SUCCESS;
  166. zend_hash_move_forward(sdl->bindings)) {
  167. if ((*binding)->bindingType == type) {
  168. return *binding;
  169. }
  170. }
  171. return NULL;
  172. }
  173. sdlBindingPtr get_binding_from_name(sdlPtr sdl, char *name, char *ns)
  174. {
  175. sdlBindingPtr binding = NULL;
  176. smart_str key = {0};
  177. smart_str_appends(&key, ns);
  178. smart_str_appendc(&key, ':');
  179. smart_str_appends(&key, name);
  180. smart_str_0(&key);
  181. zend_hash_find(sdl->bindings, key.c, key.len, (void **)&binding);
  182. smart_str_free(&key);
  183. return binding;
  184. }
  185. static int is_wsdl_element(xmlNodePtr node)
  186. {
  187. if (node->ns && strcmp((char*)node->ns->href, WSDL_NAMESPACE) != 0) {
  188. xmlAttrPtr attr;
  189. if ((attr = get_attribute_ex(node->properties, "required", WSDL_NAMESPACE)) != NULL &&
  190. attr->children && attr->children->content &&
  191. (strcmp((char*)attr->children->content, "1") == 0 ||
  192. strcmp((char*)attr->children->content, "true") == 0)) {
  193. soap_error1(E_ERROR, "Parsing WSDL: Unknown required WSDL extension '%s'", node->ns->href);
  194. }
  195. return 0;
  196. }
  197. return 1;
  198. }
  199. void sdl_set_uri_credentials(sdlCtx *ctx, char *uri TSRMLS_DC)
  200. {
  201. char *s;
  202. int l1, l2;
  203. zval *context = NULL;
  204. zval **header = NULL;
  205. /* check if we load xsd from the same server */
  206. s = strstr(ctx->sdl->source, "://");
  207. if (!s) return;
  208. s = strchr(s+3, '/');
  209. l1 = s - ctx->sdl->source;
  210. s = strstr((char*)uri, "://");
  211. if (!s) return;
  212. s = strchr(s+3, '/');
  213. l2 = s - (char*)uri;
  214. if (l1 != l2 || memcmp(ctx->sdl->source, uri, l1) != 0) {
  215. /* another server. clear authentication credentals */
  216. context = php_libxml_switch_context(NULL TSRMLS_CC);
  217. php_libxml_switch_context(context TSRMLS_CC);
  218. if (context) {
  219. ctx->context = php_stream_context_from_zval(context, 1);
  220. if (ctx->context &&
  221. php_stream_context_get_option(ctx->context, "http", "header", &header) == SUCCESS) {
  222. s = strstr(Z_STRVAL_PP(header), "Authorization: Basic");
  223. if (s && (s == Z_STRVAL_PP(header) || *(s-1) == '\n' || *(s-1) == '\r')) {
  224. char *rest = strstr(s, "\r\n");
  225. if (rest) {
  226. zval new_header;
  227. rest += 2;
  228. Z_TYPE(new_header) = IS_STRING;
  229. Z_STRLEN(new_header) = Z_STRLEN_PP(header) - (rest - s);
  230. Z_STRVAL(new_header) = emalloc(Z_STRLEN_PP(header) + 1);
  231. memcpy(Z_STRVAL(new_header), Z_STRVAL_PP(header), s - Z_STRVAL_PP(header));
  232. memcpy(Z_STRVAL(new_header) + (s - Z_STRVAL_PP(header)), rest, Z_STRLEN_PP(header) - (rest - Z_STRVAL_PP(header)) + 1);
  233. ctx->old_header = *header;
  234. Z_ADDREF_P(ctx->old_header);
  235. php_stream_context_set_option(ctx->context, "http", "header", &new_header);
  236. zval_dtor(&new_header);
  237. }
  238. }
  239. }
  240. }
  241. }
  242. }
  243. void sdl_restore_uri_credentials(sdlCtx *ctx TSRMLS_DC)
  244. {
  245. if (ctx->old_header) {
  246. php_stream_context_set_option(ctx->context, "http", "header", ctx->old_header);
  247. zval_ptr_dtor(&ctx->old_header);
  248. ctx->old_header = NULL;
  249. }
  250. ctx->context = NULL;
  251. }
  252. static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include TSRMLS_DC)
  253. {
  254. sdlPtr tmpsdl = ctx->sdl;
  255. xmlDocPtr wsdl;
  256. xmlNodePtr root, definitions, trav;
  257. xmlAttrPtr targetNamespace;
  258. if (zend_hash_exists(&ctx->docs, struri, strlen(struri)+1)) {
  259. return;
  260. }
  261. sdl_set_uri_credentials(ctx, struri TSRMLS_CC);
  262. wsdl = soap_xmlParseFile(struri TSRMLS_CC);
  263. sdl_restore_uri_credentials(ctx TSRMLS_CC);
  264. if (!wsdl) {
  265. xmlErrorPtr xmlErrorPtr = xmlGetLastError();
  266. if (xmlErrorPtr) {
  267. soap_error2(E_ERROR, "Parsing WSDL: Couldn't load from '%s' : %s", struri, xmlErrorPtr->message);
  268. } else {
  269. soap_error1(E_ERROR, "Parsing WSDL: Couldn't load from '%s'", struri);
  270. }
  271. }
  272. zend_hash_add(&ctx->docs, struri, strlen(struri)+1, (void**)&wsdl, sizeof(xmlDocPtr), NULL);
  273. root = wsdl->children;
  274. definitions = get_node_ex(root, "definitions", WSDL_NAMESPACE);
  275. if (!definitions) {
  276. if (include) {
  277. xmlNodePtr schema = get_node_ex(root, "schema", XSD_NAMESPACE);
  278. if (schema) {
  279. load_schema(ctx, schema TSRMLS_CC);
  280. return;
  281. }
  282. }
  283. soap_error1(E_ERROR, "Parsing WSDL: Couldn't find <definitions> in '%s'", struri);
  284. }
  285. if (!include) {
  286. targetNamespace = get_attribute(definitions->properties, "targetNamespace");
  287. if (targetNamespace) {
  288. tmpsdl->target_ns = estrdup((char*)targetNamespace->children->content);
  289. }
  290. }
  291. trav = definitions->children;
  292. while (trav != NULL) {
  293. if (!is_wsdl_element(trav)) {
  294. trav = trav->next;
  295. continue;
  296. }
  297. if (node_is_equal(trav,"types")) {
  298. /* TODO: Only one "types" is allowed */
  299. xmlNodePtr trav2 = trav->children;
  300. while (trav2 != NULL) {
  301. if (node_is_equal_ex(trav2, "schema", XSD_NAMESPACE)) {
  302. load_schema(ctx, trav2 TSRMLS_CC);
  303. } else if (is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) {
  304. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name);
  305. }
  306. trav2 = trav2->next;
  307. }
  308. } else if (node_is_equal(trav,"import")) {
  309. /* TODO: namespace ??? */
  310. xmlAttrPtr tmp = get_attribute(trav->properties, "location");
  311. if (tmp) {
  312. xmlChar *uri;
  313. xmlChar *base = xmlNodeGetBase(trav->doc, trav);
  314. if (base == NULL) {
  315. uri = xmlBuildURI(tmp->children->content, trav->doc->URL);
  316. } else {
  317. uri = xmlBuildURI(tmp->children->content, base);
  318. xmlFree(base);
  319. }
  320. load_wsdl_ex(this_ptr, (char*)uri, ctx, 1 TSRMLS_CC);
  321. xmlFree(uri);
  322. }
  323. } else if (node_is_equal(trav,"message")) {
  324. xmlAttrPtr name = get_attribute(trav->properties, "name");
  325. if (name && name->children && name->children->content) {
  326. if (zend_hash_add(&ctx->messages, (char*)name->children->content, xmlStrlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
  327. soap_error1(E_ERROR, "Parsing WSDL: <message> '%s' already defined", name->children->content);
  328. }
  329. } else {
  330. soap_error0(E_ERROR, "Parsing WSDL: <message> has no name attribute");
  331. }
  332. } else if (node_is_equal(trav,"portType")) {
  333. xmlAttrPtr name = get_attribute(trav->properties, "name");
  334. if (name && name->children && name->children->content) {
  335. if (zend_hash_add(&ctx->portTypes, (char*)name->children->content, xmlStrlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
  336. soap_error1(E_ERROR, "Parsing WSDL: <portType> '%s' already defined", name->children->content);
  337. }
  338. } else {
  339. soap_error0(E_ERROR, "Parsing WSDL: <portType> has no name attribute");
  340. }
  341. } else if (node_is_equal(trav,"binding")) {
  342. xmlAttrPtr name = get_attribute(trav->properties, "name");
  343. if (name && name->children && name->children->content) {
  344. if (zend_hash_add(&ctx->bindings, (char*)name->children->content, xmlStrlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
  345. soap_error1(E_ERROR, "Parsing WSDL: <binding> '%s' already defined", name->children->content);
  346. }
  347. } else {
  348. soap_error0(E_ERROR, "Parsing WSDL: <binding> has no name attribute");
  349. }
  350. } else if (node_is_equal(trav,"service")) {
  351. xmlAttrPtr name = get_attribute(trav->properties, "name");
  352. if (name && name->children && name->children->content) {
  353. if (zend_hash_add(&ctx->services, (char*)name->children->content, xmlStrlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
  354. soap_error1(E_ERROR, "Parsing WSDL: <service> '%s' already defined", name->children->content);
  355. }
  356. } else {
  357. soap_error0(E_ERROR, "Parsing WSDL: <service> has no name attribute");
  358. }
  359. } else if (!node_is_equal(trav,"documentation")) {
  360. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  361. }
  362. trav = trav->next;
  363. }
  364. }
  365. static sdlSoapBindingFunctionHeaderPtr wsdl_soap_binding_header(sdlCtx* ctx, xmlNodePtr header, char* wsdl_soap_namespace, int fault)
  366. {
  367. xmlAttrPtr tmp;
  368. xmlNodePtr *message, part;
  369. char *ctype;
  370. sdlSoapBindingFunctionHeaderPtr h;
  371. tmp = get_attribute(header->properties, "message");
  372. if (!tmp) {
  373. soap_error0(E_ERROR, "Parsing WSDL: Missing message attribute for <header>");
  374. }
  375. ctype = strrchr((char*)tmp->children->content,':');
  376. if (ctype == NULL) {
  377. ctype = (char*)tmp->children->content;
  378. } else {
  379. ++ctype;
  380. }
  381. if (zend_hash_find(&ctx->messages, ctype, strlen(ctype)+1, (void**)&message) != SUCCESS) {
  382. soap_error1(E_ERROR, "Parsing WSDL: Missing <message> with name '%s'", tmp->children->content);
  383. }
  384. tmp = get_attribute(header->properties, "part");
  385. if (!tmp) {
  386. soap_error0(E_ERROR, "Parsing WSDL: Missing part attribute for <header>");
  387. }
  388. part = get_node_with_attribute_ex((*message)->children, "part", WSDL_NAMESPACE, "name", (char*)tmp->children->content, NULL);
  389. if (!part) {
  390. soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in <message>", tmp->children->content);
  391. }
  392. h = emalloc(sizeof(sdlSoapBindingFunctionHeader));
  393. memset(h, 0, sizeof(sdlSoapBindingFunctionHeader));
  394. h->name = estrdup((char*)tmp->children->content);
  395. tmp = get_attribute(header->properties, "use");
  396. if (tmp && !strncmp((char*)tmp->children->content, "encoded", sizeof("encoded"))) {
  397. h->use = SOAP_ENCODED;
  398. } else {
  399. h->use = SOAP_LITERAL;
  400. }
  401. tmp = get_attribute(header->properties, "namespace");
  402. if (tmp) {
  403. h->ns = estrdup((char*)tmp->children->content);
  404. }
  405. if (h->use == SOAP_ENCODED) {
  406. tmp = get_attribute(header->properties, "encodingStyle");
  407. if (tmp) {
  408. if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) {
  409. h->encodingStyle = SOAP_ENCODING_1_1;
  410. } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) {
  411. h->encodingStyle = SOAP_ENCODING_1_2;
  412. } else {
  413. soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content);
  414. }
  415. } else {
  416. soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle");
  417. }
  418. }
  419. tmp = get_attribute(part->properties, "type");
  420. if (tmp != NULL) {
  421. h->encode = get_encoder_from_prefix(ctx->sdl, part, tmp->children->content);
  422. } else {
  423. tmp = get_attribute(part->properties, "element");
  424. if (tmp != NULL) {
  425. h->element = get_element(ctx->sdl, part, tmp->children->content);
  426. if (h->element) {
  427. h->encode = h->element->encode;
  428. if (!h->ns && h->element->namens) {
  429. h->ns = estrdup(h->element->namens);
  430. }
  431. if (h->element->name) {
  432. efree(h->name);
  433. h->name = estrdup(h->element->name);
  434. }
  435. }
  436. }
  437. }
  438. if (!fault) {
  439. xmlNodePtr trav = header->children;
  440. while (trav != NULL) {
  441. if (node_is_equal_ex(trav, "headerfault", wsdl_soap_namespace)) {
  442. sdlSoapBindingFunctionHeaderPtr hf = wsdl_soap_binding_header(ctx, trav, wsdl_soap_namespace, 1);
  443. smart_str key = {0};
  444. if (h->headerfaults == NULL) {
  445. h->headerfaults = emalloc(sizeof(HashTable));
  446. zend_hash_init(h->headerfaults, 0, NULL, delete_header, 0);
  447. }
  448. if (hf->ns) {
  449. smart_str_appends(&key,hf->ns);
  450. smart_str_appendc(&key,':');
  451. }
  452. smart_str_appends(&key,hf->name);
  453. smart_str_0(&key);
  454. if (zend_hash_add(h->headerfaults, key.c, key.len+1, (void**)&hf, sizeof(sdlSoapBindingFunctionHeaderPtr), NULL) != SUCCESS) {
  455. delete_header((void**)&hf);
  456. }
  457. smart_str_free(&key);
  458. } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) {
  459. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  460. }
  461. trav = trav->next;
  462. }
  463. }
  464. return h;
  465. }
  466. static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap_namespace, sdlSoapBindingFunctionBody *binding, HashTable* params)
  467. {
  468. xmlNodePtr body, trav;
  469. xmlAttrPtr tmp;
  470. trav = node->children;
  471. while (trav != NULL) {
  472. if (node_is_equal_ex(trav, "body", wsdl_soap_namespace)) {
  473. body = trav;
  474. tmp = get_attribute(body->properties, "use");
  475. if (tmp && !strncmp((char*)tmp->children->content, "literal", sizeof("literal"))) {
  476. binding->use = SOAP_LITERAL;
  477. } else {
  478. binding->use = SOAP_ENCODED;
  479. }
  480. tmp = get_attribute(body->properties, "namespace");
  481. if (tmp) {
  482. binding->ns = estrdup((char*)tmp->children->content);
  483. }
  484. tmp = get_attribute(body->properties, "parts");
  485. if (tmp) {
  486. HashTable ht;
  487. char *parts = (char*)tmp->children->content;
  488. /* Delete all parts those are not in the "parts" attribute */
  489. zend_hash_init(&ht, 0, NULL, delete_parameter, 0);
  490. while (*parts) {
  491. HashPosition pos;
  492. sdlParamPtr *param;
  493. int found = 0;
  494. char *end;
  495. while (*parts == ' ') ++parts;
  496. if (*parts == '\0') break;
  497. end = strchr(parts, ' ');
  498. if (end) *end = '\0';
  499. zend_hash_internal_pointer_reset_ex(params, &pos);
  500. while (zend_hash_get_current_data_ex(params, (void **)&param, &pos) != FAILURE) {
  501. if ((*param)->paramName &&
  502. strcmp(parts, (*param)->paramName) == 0) {
  503. sdlParamPtr x_param;
  504. x_param = emalloc(sizeof(sdlParam));
  505. *x_param = **param;
  506. (*param)->paramName = NULL;
  507. zend_hash_next_index_insert(&ht, &x_param, sizeof(sdlParamPtr), NULL);
  508. found = 1;
  509. break;
  510. }
  511. zend_hash_move_forward_ex(params, &pos);
  512. }
  513. if (!found) {
  514. soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in <message>", parts);
  515. }
  516. parts += strlen(parts);
  517. if (end) *end = ' ';
  518. }
  519. zend_hash_destroy(params);
  520. *params = ht;
  521. }
  522. if (binding->use == SOAP_ENCODED) {
  523. tmp = get_attribute(body->properties, "encodingStyle");
  524. if (tmp) {
  525. if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) {
  526. binding->encodingStyle = SOAP_ENCODING_1_1;
  527. } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) {
  528. binding->encodingStyle = SOAP_ENCODING_1_2;
  529. } else {
  530. soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content);
  531. }
  532. } else {
  533. soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle");
  534. }
  535. }
  536. } else if (node_is_equal_ex(trav, "header", wsdl_soap_namespace)) {
  537. sdlSoapBindingFunctionHeaderPtr h = wsdl_soap_binding_header(ctx, trav, wsdl_soap_namespace, 0);
  538. smart_str key = {0};
  539. if (binding->headers == NULL) {
  540. binding->headers = emalloc(sizeof(HashTable));
  541. zend_hash_init(binding->headers, 0, NULL, delete_header, 0);
  542. }
  543. if (h->ns) {
  544. smart_str_appends(&key,h->ns);
  545. smart_str_appendc(&key,':');
  546. }
  547. smart_str_appends(&key,h->name);
  548. smart_str_0(&key);
  549. if (zend_hash_add(binding->headers, key.c, key.len+1, (void**)&h, sizeof(sdlSoapBindingFunctionHeaderPtr), NULL) != SUCCESS) {
  550. delete_header((void**)&h);
  551. }
  552. smart_str_free(&key);
  553. } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) {
  554. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  555. }
  556. trav = trav->next;
  557. }
  558. }
  559. static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name)
  560. {
  561. xmlNodePtr trav, part, message = NULL, *tmp;
  562. HashTable* parameters = NULL;
  563. char *ctype;
  564. ctype = strrchr((char*)message_name,':');
  565. if (ctype == NULL) {
  566. ctype = (char*)message_name;
  567. } else {
  568. ++ctype;
  569. }
  570. if (zend_hash_find(&ctx->messages, ctype, strlen(ctype)+1, (void**)&tmp) != SUCCESS) {
  571. soap_error1(E_ERROR, "Parsing WSDL: Missing <message> with name '%s'", message_name);
  572. }
  573. message = *tmp;
  574. parameters = emalloc(sizeof(HashTable));
  575. zend_hash_init(parameters, 0, NULL, delete_parameter, 0);
  576. trav = message->children;
  577. while (trav != NULL) {
  578. xmlAttrPtr element, type, name;
  579. sdlParamPtr param;
  580. if (trav->ns != NULL && strcmp((char*)trav->ns->href, WSDL_NAMESPACE) != 0) {
  581. soap_error1(E_ERROR, "Parsing WSDL: Unexpected extensibility element <%s>", trav->name);
  582. }
  583. if (node_is_equal(trav,"documentation")) {
  584. trav = trav->next;
  585. continue;
  586. }
  587. if (!node_is_equal(trav,"part")) {
  588. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  589. }
  590. part = trav;
  591. param = emalloc(sizeof(sdlParam));
  592. memset(param,0,sizeof(sdlParam));
  593. param->order = 0;
  594. name = get_attribute(part->properties, "name");
  595. if (name == NULL) {
  596. soap_error1(E_ERROR, "Parsing WSDL: No name associated with <part> '%s'", message->name);
  597. }
  598. param->paramName = estrdup((char*)name->children->content);
  599. type = get_attribute(part->properties, "type");
  600. if (type != NULL) {
  601. param->encode = get_encoder_from_prefix(ctx->sdl, part, type->children->content);
  602. } else {
  603. element = get_attribute(part->properties, "element");
  604. if (element != NULL) {
  605. param->element = get_element(ctx->sdl, part, element->children->content);
  606. if (param->element) {
  607. param->encode = param->element->encode;
  608. }
  609. }
  610. }
  611. zend_hash_next_index_insert(parameters, &param, sizeof(sdlParamPtr), NULL);
  612. trav = trav->next;
  613. }
  614. return parameters;
  615. }
  616. static sdlPtr load_wsdl(zval *this_ptr, char *struri TSRMLS_DC)
  617. {
  618. sdlCtx ctx;
  619. int i,n;
  620. memset(&ctx,0,sizeof(ctx));
  621. ctx.sdl = emalloc(sizeof(sdl));
  622. memset(ctx.sdl, 0, sizeof(sdl));
  623. ctx.sdl->source = estrdup(struri);
  624. zend_hash_init(&ctx.sdl->functions, 0, NULL, delete_function, 0);
  625. zend_hash_init(&ctx.docs, 0, NULL, delete_document, 0);
  626. zend_hash_init(&ctx.messages, 0, NULL, NULL, 0);
  627. zend_hash_init(&ctx.bindings, 0, NULL, NULL, 0);
  628. zend_hash_init(&ctx.portTypes, 0, NULL, NULL, 0);
  629. zend_hash_init(&ctx.services, 0, NULL, NULL, 0);
  630. load_wsdl_ex(this_ptr, struri,&ctx, 0 TSRMLS_CC);
  631. schema_pass2(&ctx);
  632. n = zend_hash_num_elements(&ctx.services);
  633. if (n > 0) {
  634. zend_hash_internal_pointer_reset(&ctx.services);
  635. for (i = 0; i < n; i++) {
  636. xmlNodePtr *tmp, service;
  637. xmlNodePtr trav, port;
  638. int has_soap_port = 0;
  639. zend_hash_get_current_data(&ctx.services, (void **)&tmp);
  640. service = *tmp;
  641. trav = service->children;
  642. while (trav != NULL) {
  643. xmlAttrPtr type, name, bindingAttr, location;
  644. xmlNodePtr portType, operation;
  645. xmlNodePtr address, binding, trav2;
  646. char *ctype;
  647. sdlBindingPtr tmpbinding;
  648. char *wsdl_soap_namespace = NULL;
  649. if (!is_wsdl_element(trav) || node_is_equal(trav,"documentation")) {
  650. trav = trav->next;
  651. continue;
  652. }
  653. if (!node_is_equal(trav,"port")) {
  654. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  655. }
  656. port = trav;
  657. tmpbinding = emalloc(sizeof(sdlBinding));
  658. memset(tmpbinding, 0, sizeof(sdlBinding));
  659. bindingAttr = get_attribute(port->properties, "binding");
  660. if (bindingAttr == NULL) {
  661. soap_error0(E_ERROR, "Parsing WSDL: No binding associated with <port>");
  662. }
  663. /* find address and figure out binding type */
  664. address = NULL;
  665. trav2 = port->children;
  666. while (trav2 != NULL) {
  667. if (node_is_equal(trav2,"address") && trav2->ns) {
  668. if (!strncmp((char*)trav2->ns->href, WSDL_SOAP11_NAMESPACE, sizeof(WSDL_SOAP11_NAMESPACE))) {
  669. address = trav2;
  670. wsdl_soap_namespace = WSDL_SOAP11_NAMESPACE;
  671. tmpbinding->bindingType = BINDING_SOAP;
  672. } else if (!strncmp((char*)trav2->ns->href, WSDL_SOAP12_NAMESPACE, sizeof(WSDL_SOAP12_NAMESPACE))) {
  673. address = trav2;
  674. wsdl_soap_namespace = WSDL_SOAP12_NAMESPACE;
  675. tmpbinding->bindingType = BINDING_SOAP;
  676. } else if (!strncmp((char*)trav2->ns->href, RPC_SOAP12_NAMESPACE, sizeof(RPC_SOAP12_NAMESPACE))) {
  677. address = trav2;
  678. wsdl_soap_namespace = RPC_SOAP12_NAMESPACE;
  679. tmpbinding->bindingType = BINDING_SOAP;
  680. } else if (!strncmp((char*)trav2->ns->href, WSDL_HTTP11_NAMESPACE, sizeof(WSDL_HTTP11_NAMESPACE))) {
  681. address = trav2;
  682. tmpbinding->bindingType = BINDING_HTTP;
  683. } else if (!strncmp((char*)trav2->ns->href, WSDL_HTTP12_NAMESPACE, sizeof(WSDL_HTTP12_NAMESPACE))) {
  684. address = trav2;
  685. tmpbinding->bindingType = BINDING_HTTP;
  686. }
  687. }
  688. if (trav2 != address && is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) {
  689. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name);
  690. }
  691. trav2 = trav2->next;
  692. }
  693. if (!address || tmpbinding->bindingType == BINDING_HTTP) {
  694. if (has_soap_port || trav->next || i < n-1) {
  695. efree(tmpbinding);
  696. trav = trav->next;
  697. continue;
  698. } else if (!address) {
  699. soap_error0(E_ERROR, "Parsing WSDL: No address associated with <port>");
  700. }
  701. }
  702. has_soap_port = 1;
  703. location = get_attribute(address->properties, "location");
  704. if (!location) {
  705. soap_error0(E_ERROR, "Parsing WSDL: No location associated with <port>");
  706. }
  707. tmpbinding->location = estrdup((char*)location->children->content);
  708. ctype = strrchr((char*)bindingAttr->children->content,':');
  709. if (ctype == NULL) {
  710. ctype = (char*)bindingAttr->children->content;
  711. } else {
  712. ++ctype;
  713. }
  714. if (zend_hash_find(&ctx.bindings, ctype, strlen(ctype)+1, (void*)&tmp) != SUCCESS) {
  715. soap_error1(E_ERROR, "Parsing WSDL: No <binding> element with name '%s'", ctype);
  716. }
  717. binding = *tmp;
  718. if (tmpbinding->bindingType == BINDING_SOAP) {
  719. sdlSoapBindingPtr soapBinding;
  720. xmlNodePtr soapBindingNode;
  721. xmlAttrPtr tmp;
  722. soapBinding = emalloc(sizeof(sdlSoapBinding));
  723. memset(soapBinding, 0, sizeof(sdlSoapBinding));
  724. soapBinding->style = SOAP_DOCUMENT;
  725. soapBindingNode = get_node_ex(binding->children, "binding", wsdl_soap_namespace);
  726. if (soapBindingNode) {
  727. tmp = get_attribute(soapBindingNode->properties, "style");
  728. if (tmp && !strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) {
  729. soapBinding->style = SOAP_RPC;
  730. }
  731. tmp = get_attribute(soapBindingNode->properties, "transport");
  732. if (tmp) {
  733. if (strncmp((char*)tmp->children->content, WSDL_HTTP_TRANSPORT, sizeof(WSDL_HTTP_TRANSPORT)) == 0) {
  734. soapBinding->transport = SOAP_TRANSPORT_HTTP;
  735. } else {
  736. /* try the next binding */
  737. efree(soapBinding);
  738. efree(tmpbinding->location);
  739. efree(tmpbinding);
  740. trav = trav->next;
  741. continue;
  742. }
  743. }
  744. }
  745. tmpbinding->bindingAttributes = (void *)soapBinding;
  746. }
  747. name = get_attribute(binding->properties, "name");
  748. if (name == NULL) {
  749. soap_error0(E_ERROR, "Parsing WSDL: Missing 'name' attribute for <binding>");
  750. }
  751. tmpbinding->name = estrdup((char*)name->children->content);
  752. type = get_attribute(binding->properties, "type");
  753. if (type == NULL) {
  754. soap_error0(E_ERROR, "Parsing WSDL: Missing 'type' attribute for <binding>");
  755. }
  756. ctype = strrchr((char*)type->children->content,':');
  757. if (ctype == NULL) {
  758. ctype = (char*)type->children->content;
  759. } else {
  760. ++ctype;
  761. }
  762. if (zend_hash_find(&ctx.portTypes, ctype, strlen(ctype)+1, (void**)&tmp) != SUCCESS) {
  763. soap_error1(E_ERROR, "Parsing WSDL: Missing <portType> with name '%s'", name->children->content);
  764. }
  765. portType = *tmp;
  766. trav2 = binding->children;
  767. while (trav2 != NULL) {
  768. sdlFunctionPtr function;
  769. xmlNodePtr input, output, fault, portTypeOperation, trav3;
  770. xmlAttrPtr op_name, paramOrder;
  771. if ((tmpbinding->bindingType == BINDING_SOAP &&
  772. node_is_equal_ex(trav2, "binding", wsdl_soap_namespace)) ||
  773. !is_wsdl_element(trav2) ||
  774. node_is_equal(trav2,"documentation")) {
  775. trav2 = trav2->next;
  776. continue;
  777. }
  778. if (!node_is_equal(trav2,"operation")) {
  779. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name);
  780. }
  781. operation = trav2;
  782. op_name = get_attribute(operation->properties, "name");
  783. if (op_name == NULL) {
  784. soap_error0(E_ERROR, "Parsing WSDL: Missing 'name' attribute for <operation>");
  785. }
  786. trav3 = operation->children;
  787. while (trav3 != NULL) {
  788. if (tmpbinding->bindingType == BINDING_SOAP &&
  789. node_is_equal_ex(trav3, "operation", wsdl_soap_namespace)) {
  790. } else if (is_wsdl_element(trav3) &&
  791. !node_is_equal(trav3,"input") &&
  792. !node_is_equal(trav3,"output") &&
  793. !node_is_equal(trav3,"fault") &&
  794. !node_is_equal(trav3,"documentation")) {
  795. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav3->name);
  796. }
  797. trav3 = trav3->next;
  798. }
  799. portTypeOperation = get_node_with_attribute_ex(portType->children, "operation", WSDL_NAMESPACE, "name", (char*)op_name->children->content, NULL);
  800. if (portTypeOperation == NULL) {
  801. soap_error1(E_ERROR, "Parsing WSDL: Missing <portType>/<operation> with name '%s'", op_name->children->content);
  802. }
  803. function = emalloc(sizeof(sdlFunction));
  804. memset(function, 0, sizeof(sdlFunction));
  805. function->functionName = estrdup((char*)op_name->children->content);
  806. if (tmpbinding->bindingType == BINDING_SOAP) {
  807. sdlSoapBindingFunctionPtr soapFunctionBinding;
  808. sdlSoapBindingPtr soapBinding;
  809. xmlNodePtr soapOperation;
  810. xmlAttrPtr tmp;
  811. soapFunctionBinding = emalloc(sizeof(sdlSoapBindingFunction));
  812. memset(soapFunctionBinding, 0, sizeof(sdlSoapBindingFunction));
  813. soapBinding = (sdlSoapBindingPtr)tmpbinding->bindingAttributes;
  814. soapFunctionBinding->style = soapBinding->style;
  815. soapOperation = get_node_ex(operation->children, "operation", wsdl_soap_namespace);
  816. if (soapOperation) {
  817. tmp = get_attribute(soapOperation->properties, "soapAction");
  818. if (tmp) {
  819. soapFunctionBinding->soapAction = estrdup((char*)tmp->children->content);
  820. }
  821. tmp = get_attribute(soapOperation->properties, "style");
  822. if (tmp) {
  823. if (!strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) {
  824. soapFunctionBinding->style = SOAP_RPC;
  825. } else {
  826. soapFunctionBinding->style = SOAP_DOCUMENT;
  827. }
  828. } else {
  829. soapFunctionBinding->style = soapBinding->style;
  830. }
  831. }
  832. function->bindingAttributes = (void *)soapFunctionBinding;
  833. }
  834. input = get_node_ex(portTypeOperation->children, "input", WSDL_NAMESPACE);
  835. if (input != NULL) {
  836. xmlAttrPtr message, name;
  837. message = get_attribute(input->properties, "message");
  838. if (message == NULL) {
  839. soap_error1(E_ERROR, "Parsing WSDL: Missing name for <input> of '%s'", op_name->children->content);
  840. }
  841. function->requestParameters = wsdl_message(&ctx, message->children->content);
  842. name = get_attribute(input->properties, "name");
  843. /* FIXME
  844. if (name != NULL) {
  845. function->requestName = estrdup(name->children->content);
  846. } else {
  847. */
  848. {
  849. function->requestName = estrdup(function->functionName);
  850. }
  851. if (tmpbinding->bindingType == BINDING_SOAP) {
  852. input = get_node_ex(operation->children, "input", WSDL_NAMESPACE);
  853. if (input != NULL) {
  854. sdlSoapBindingFunctionPtr soapFunctionBinding = function->bindingAttributes;
  855. wsdl_soap_binding_body(&ctx, input, wsdl_soap_namespace, &soapFunctionBinding->input, function->requestParameters);
  856. }
  857. }
  858. }
  859. output = get_node_ex(portTypeOperation->children, "output", WSDL_NAMESPACE);
  860. if (output != NULL) {
  861. xmlAttrPtr message, name;
  862. message = get_attribute(output->properties, "message");
  863. if (message == NULL) {
  864. soap_error1(E_ERROR, "Parsing WSDL: Missing name for <output> of '%s'", op_name->children->content);
  865. }
  866. function->responseParameters = wsdl_message(&ctx, message->children->content);
  867. name = get_attribute(output->properties, "name");
  868. /* FIXME
  869. if (name != NULL) {
  870. function->responseName = estrdup(name->children->content);
  871. } else if (input == NULL) {
  872. function->responseName = estrdup(function->functionName);
  873. } else {
  874. */
  875. {
  876. int len = strlen(function->functionName);
  877. function->responseName = emalloc(len + sizeof("Response"));
  878. memcpy(function->responseName, function->functionName, len);
  879. memcpy(function->responseName+len, "Response", sizeof("Response"));
  880. }
  881. if (tmpbinding->bindingType == BINDING_SOAP) {
  882. output = get_node_ex(operation->children, "output", WSDL_NAMESPACE);
  883. if (output != NULL) {
  884. sdlSoapBindingFunctionPtr soapFunctionBinding = function->bindingAttributes;
  885. wsdl_soap_binding_body(&ctx, output, wsdl_soap_namespace, &soapFunctionBinding->output, function->responseParameters);
  886. }
  887. }
  888. }
  889. paramOrder = get_attribute(portTypeOperation->properties, "parameterOrder");
  890. if (paramOrder) {
  891. /* FIXME: */
  892. }
  893. fault = portTypeOperation->children;
  894. while (fault != NULL) {
  895. if (node_is_equal_ex(fault, "fault", WSDL_NAMESPACE)) {
  896. xmlAttrPtr message, name;
  897. sdlFaultPtr f;
  898. name = get_attribute(fault->properties, "name");
  899. if (name == NULL) {
  900. soap_error1(E_ERROR, "Parsing WSDL: Missing name for <fault> of '%s'", op_name->children->content);
  901. }
  902. message = get_attribute(fault->properties, "message");
  903. if (message == NULL) {
  904. soap_error1(E_ERROR, "Parsing WSDL: Missing name for <output> of '%s'", op_name->children->content);
  905. }
  906. f = emalloc(sizeof(sdlFault));
  907. memset(f, 0, sizeof(sdlFault));
  908. f->name = estrdup((char*)name->children->content);
  909. f->details = wsdl_message(&ctx, message->children->content);
  910. if (f->details == NULL || zend_hash_num_elements(f->details) > 1) {
  911. soap_error1(E_ERROR, "Parsing WSDL: The fault message '%s' must have a single part", message->children->content);
  912. }
  913. if (tmpbinding->bindingType == BINDING_SOAP) {
  914. xmlNodePtr soap_fault = get_node_with_attribute_ex(operation->children, "fault", WSDL_NAMESPACE, "name", f->name, NULL);
  915. if (soap_fault != NULL) {
  916. xmlNodePtr trav = soap_fault->children;
  917. while (trav != NULL) {
  918. if (node_is_equal_ex(trav, "fault", wsdl_soap_namespace)) {
  919. xmlAttrPtr tmp;
  920. sdlSoapBindingFunctionFaultPtr binding;
  921. binding = f->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunctionFault));
  922. memset(f->bindingAttributes, 0, sizeof(sdlSoapBindingFunctionFault));
  923. tmp = get_attribute(trav->properties, "use");
  924. if (tmp && !strncmp((char*)tmp->children->content, "encoded", sizeof("encoded"))) {
  925. binding->use = SOAP_ENCODED;
  926. } else {
  927. binding->use = SOAP_LITERAL;
  928. }
  929. tmp = get_attribute(trav->properties, "namespace");
  930. if (tmp) {
  931. binding->ns = estrdup((char*)tmp->children->content);
  932. }
  933. if (binding->use == SOAP_ENCODED) {
  934. tmp = get_attribute(trav->properties, "encodingStyle");
  935. if (tmp) {
  936. if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) {
  937. binding->encodingStyle = SOAP_ENCODING_1_1;
  938. } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) {
  939. binding->encodingStyle = SOAP_ENCODING_1_2;
  940. } else {
  941. soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content);
  942. }
  943. } else {
  944. soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle");
  945. }
  946. }
  947. } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) {
  948. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  949. }
  950. trav = trav->next;
  951. }
  952. }
  953. }
  954. if (function->faults == NULL) {
  955. function->faults = emalloc(sizeof(HashTable));
  956. zend_hash_init(function->faults, 0, NULL, delete_fault, 0);
  957. }
  958. if (zend_hash_add(function->faults, f->name, strlen(f->name)+1, (void**)&f, sizeof(sdlFaultPtr), NULL) != SUCCESS) {
  959. soap_error2(E_ERROR, "Parsing WSDL: <fault> with name '%s' already defined in '%s'", f->name, op_name->children->content);
  960. }
  961. }
  962. fault = fault->next;
  963. }
  964. function->binding = tmpbinding;
  965. {
  966. char *tmp = estrdup(function->functionName);
  967. int len = strlen(tmp);
  968. if (zend_hash_add(&ctx.sdl->functions, php_strtolower(tmp, len), len+1, &function, sizeof(sdlFunctionPtr), NULL) != SUCCESS) {
  969. zend_hash_next_index_insert(&ctx.sdl->functions, &function, sizeof(sdlFunctionPtr), NULL);
  970. }
  971. efree(tmp);
  972. if (function->requestName != NULL && strcmp(function->requestName,function->functionName) != 0) {
  973. if (ctx.sdl->requests == NULL) {
  974. ctx.sdl->requests = emalloc(sizeof(HashTable));
  975. zend_hash_init(ctx.sdl->requests, 0, NULL, NULL, 0);
  976. }
  977. tmp = estrdup(function->requestName);
  978. len = strlen(tmp);
  979. zend_hash_add(ctx.sdl->requests, php_strtolower(tmp, len), len+1, &function, sizeof(sdlFunctionPtr), NULL);
  980. efree(tmp);
  981. }
  982. }
  983. trav2 = trav2->next;
  984. }
  985. if (!ctx.sdl->bindings) {
  986. ctx.sdl->bindings = emalloc(sizeof(HashTable));
  987. zend_hash_init(ctx.sdl->bindings, 0, NULL, delete_binding, 0);
  988. }
  989. zend_hash_add(ctx.sdl->bindings, tmpbinding->name, strlen(tmpbinding->name), &tmpbinding, sizeof(sdlBindingPtr), NULL);
  990. trav= trav->next;
  991. }
  992. zend_hash_move_forward(&ctx.services);
  993. }
  994. } else {
  995. soap_error0(E_ERROR, "Parsing WSDL: Couldn't bind to service");
  996. }
  997. if (ctx.sdl->bindings == NULL || ctx.sdl->bindings->nNumOfElements == 0) {
  998. soap_error0(E_ERROR, "Parsing WSDL: Could not find any usable binding services in WSDL.");
  999. }
  1000. zend_hash_destroy(&ctx.messages);
  1001. zend_hash_destroy(&ctx.bindings);
  1002. zend_hash_destroy(&ctx.portTypes);
  1003. zend_hash_destroy(&ctx.services);
  1004. zend_hash_destroy(&ctx.docs);
  1005. return ctx.sdl;
  1006. }
  1007. #define WSDL_CACHE_VERSION 0x0e
  1008. #define WSDL_CACHE_GET(ret,type,buf) memcpy(&ret,*buf,sizeof(type)); *buf += sizeof(type);
  1009. #define WSDL_CACHE_GET_INT(ret,buf) ret = ((unsigned char)(*buf)[0])|((unsigned char)(*buf)[1]<<8)|((unsigned char)(*buf)[2]<<16)|((int)(*buf)[3]<<24); *buf += 4;
  1010. #define WSDL_CACHE_GET_1(ret,type,buf) ret = (type)(**buf); (*buf)++;
  1011. #define WSDL_CACHE_GET_N(ret,n,buf) memcpy(ret,*buf,n); *buf += n;
  1012. #define WSDL_CACHE_SKIP(n,buf) *buf += n;
  1013. #define WSDL_CACHE_PUT_INT(val,buf) smart_str_appendc(buf,val & 0xff); \
  1014. smart_str_appendc(buf,(val >> 8) & 0xff); \
  1015. smart_str_appendc(buf,(val >> 16) & 0xff); \
  1016. smart_str_appendc(buf,(val >> 24) & 0xff);
  1017. #define WSDL_CACHE_PUT_1(val,buf) smart_str_appendc(buf,val);
  1018. #define WSDL_CACHE_PUT_N(val,n,buf) smart_str_appendl(buf,(char*)val,n);
  1019. static char* sdl_deserialize_string(char **in)
  1020. {
  1021. char *s;
  1022. int len;
  1023. WSDL_CACHE_GET_INT(len, in);
  1024. if (len == 0x7fffffff) {
  1025. return NULL;
  1026. } else {
  1027. s = emalloc(len+1);
  1028. WSDL_CACHE_GET_N(s, len, in);
  1029. s[len] = '\0';
  1030. return s;
  1031. }
  1032. }
  1033. static void sdl_deserialize_key(HashTable* ht, void* data, char **in)
  1034. {
  1035. int len;
  1036. WSDL_CACHE_GET_INT(len, in);
  1037. if (len == 0) {
  1038. zend_hash_next_index_insert(ht, &data, sizeof(void*), NULL);
  1039. } else {
  1040. zend_hash_add(ht, *in, len, &data, sizeof(void*), NULL);
  1041. WSDL_CACHE_SKIP(len, in);
  1042. }
  1043. }
  1044. static void sdl_deserialize_attribute(sdlAttributePtr attr, encodePtr *encoders, char **in)
  1045. {
  1046. int i;
  1047. attr->name = sdl_deserialize_string(in);
  1048. attr->namens = sdl_deserialize_string(in);
  1049. attr->ref = sdl_deserialize_string(in);
  1050. attr->def = sdl_deserialize_string(in);
  1051. attr->fixed = sdl_deserialize_string(in);
  1052. WSDL_CACHE_GET_1(attr->form, sdlForm, in);
  1053. WSDL_CACHE_GET_1(attr->use, sdlUse, in);
  1054. WSDL_CACHE_GET_INT(i, in);
  1055. attr->encode = encoders[i];
  1056. WSDL_CACHE_GET_INT(i, in);
  1057. if (i > 0) {
  1058. attr->extraAttributes = emalloc(sizeof(HashTable));
  1059. zend_hash_init(attr->extraAttributes, i, NULL, delete_extra_attribute, 0);
  1060. while (i > 0) {
  1061. sdlExtraAttributePtr x = emalloc(sizeof(sdlExtraAttribute));
  1062. sdl_deserialize_key(attr->extraAttributes, x, in);
  1063. x->ns = sdl_deserialize_string(in);
  1064. x->val = sdl_deserialize_string(in);
  1065. --i;
  1066. }
  1067. }
  1068. }
  1069. static sdlRestrictionIntPtr sdl_deserialize_resriction_int(char **in)
  1070. {
  1071. if (**in == 1) {
  1072. sdlRestrictionIntPtr x = emalloc(sizeof(sdlRestrictionInt));
  1073. WSDL_CACHE_SKIP(1, in);
  1074. WSDL_CACHE_GET_INT(x->value, in);
  1075. WSDL_CACHE_GET_1(x->fixed, char, in);
  1076. return x;
  1077. } else {
  1078. WSDL_CACHE_SKIP(1, in);
  1079. return NULL;
  1080. }
  1081. }
  1082. static sdlRestrictionCharPtr sdl_deserialize_resriction_char(char **in)
  1083. {
  1084. if (**in == 1) {
  1085. sdlRestrictionCharPtr x = emalloc(sizeof(sdlRestrictionChar));
  1086. WSDL_CACHE_SKIP(1, in);
  1087. x->value = sdl_deserialize_string(in);
  1088. WSDL_CACHE_GET_1(x->fixed, char, in);
  1089. return x;
  1090. } else {
  1091. WSDL_CACHE_SKIP(1, in);
  1092. return NULL;
  1093. }
  1094. }
  1095. static sdlContentModelPtr sdl_deserialize_model(sdlTypePtr *types, sdlTypePtr *elements, char **in)
  1096. {
  1097. int i;
  1098. sdlContentModelPtr model = emalloc(sizeof(sdlContentModel));
  1099. WSDL_CACHE_GET_1(model->kind, sdlContentKind, in);
  1100. WSDL_CACHE_GET_INT(model->min_occurs, in);
  1101. WSDL_CACHE_GET_INT(model->max_occurs, in);
  1102. switch (model->kind) {
  1103. case XSD_CONTENT_ELEMENT:
  1104. WSDL_CACHE_GET_INT(i, in);
  1105. model->u.element = elements[i];
  1106. break;
  1107. case XSD_CONTENT_SEQUENCE:
  1108. case XSD_CONTENT_ALL:
  1109. case XSD_CONTENT_CHOICE:
  1110. WSDL_CACHE_GET_INT(i, in);
  1111. model->u.content = emalloc(sizeof(HashTable));
  1112. zend_hash_init(model->u.content, i, NULL, delete_model, 0);
  1113. while (i > 0) {
  1114. sdlContentModelPtr x = sdl_deserialize_model(types, elements, in);
  1115. zend_hash_next_index_insert(model->u.content,&x,sizeof(sdlContentModelPtr),NULL);
  1116. i--;
  1117. }
  1118. break;
  1119. case XSD_CONTENT_GROUP_REF:
  1120. model->u.group_ref = sdl_deserialize_string(in);
  1121. break;
  1122. case XSD_CONTENT_GROUP:
  1123. WSDL_CACHE_GET_INT(i, in);
  1124. model->u.group = types[i];
  1125. break;
  1126. default:
  1127. break;
  1128. }
  1129. return model;
  1130. }
  1131. static void sdl_deserialize_type(sdlTypePtr type, sdlTypePtr *types, encodePtr *encoders, char **in)
  1132. {
  1133. int i;
  1134. sdlTypePtr *elements = NULL;
  1135. WSDL_CACHE_GET_1(type->kind, sdlTypeKind, in);
  1136. type->name = sdl_deserialize_string(in);
  1137. type->namens = sdl_deserialize_string(in);
  1138. type->def = sdl_deserialize_string(in);
  1139. type->fixed = sdl_deserialize_string(in);
  1140. type->ref = sdl_deserialize_string(in);
  1141. WSDL_CACHE_GET_1(type->nillable, char, in);
  1142. WSDL_CACHE_GET_1(type->form, sdlForm, in);
  1143. WSDL_CACHE_GET_INT(i, in);
  1144. type->encode = encoders[i];
  1145. if (**in == 1) {
  1146. WSDL_CACHE_SKIP(1, in);
  1147. type->restrictions = emalloc(sizeof(sdlRestrictions));
  1148. /*memset(type->restrictions, 0, sizeof(sdlRestrictions));*/
  1149. type->restrictions->minExclusive = sdl_deserialize_resriction_int(in);
  1150. type->restrictions->minInclusive = sdl_deserialize_resriction_int(in);
  1151. type->restrictions->maxExclusive = sdl_deserialize_resriction_int(in);
  1152. type->restrictions->maxInclusive = sdl_deserialize_resriction_int(in);
  1153. type->restrictions->totalDigits = sdl_deserialize_resriction_int(in);
  1154. type->restrictions->fractionDigits = sdl_deserialize_resriction_int(in);
  1155. type->restrictions->length = sdl_deserialize_resriction_int(in);
  1156. type->restrictions->minLength = sdl_deserialize_resriction_int(in);
  1157. type->restrictions->maxLength = sdl_deserialize_resriction_int(in);
  1158. type->restrictions->whiteSpace = sdl_deserialize_resriction_char(in);
  1159. type->restrictions->pattern = sdl_deserialize_resriction_char(in);
  1160. WSDL_CACHE_GET_INT(i, in);
  1161. if (i > 0) {
  1162. type->restrictions->enumeration = emalloc(sizeof(HashTable));
  1163. zend_hash_init(type->restrictions->enumeration, i, NULL, delete_restriction_var_char, 0);
  1164. while (i > 0) {
  1165. sdlRestrictionCharPtr x = sdl_deserialize_resriction_char(in);
  1166. sdl_deserialize_key(type->restrictions->enumeration, x, in);
  1167. --i;
  1168. }
  1169. } else {
  1170. type->restrictions->enumeration = NULL;
  1171. }
  1172. } else {
  1173. WSDL_CACHE_SKIP(1, in);
  1174. }
  1175. WSDL_CACHE_GET_INT(i, in);
  1176. if (i > 0) {
  1177. elements = safe_emalloc((i+1), sizeof(sdlTypePtr), 0);
  1178. elements[0] = NULL;
  1179. type->elements = emalloc(sizeof(HashTable));
  1180. zend_hash_init(type->elements, i, NULL, delete_type, 0);
  1181. while (i > 0) {
  1182. sdlTypePtr t = emalloc(sizeof(sdlType));
  1183. memset(t, 0, sizeof(sdlType));
  1184. sdl_deserialize_key(type->elements, t, in);
  1185. sdl_deserialize_type(t, types, encoders, in);
  1186. elements[i] = t;
  1187. --i;
  1188. }
  1189. }
  1190. WSDL_CACHE_GET_INT(i, in);
  1191. if (i > 0) {
  1192. type->attributes = emalloc(sizeof(HashTable));
  1193. zend_hash_init(type->attributes, i, NULL, delete_attribute, 0);
  1194. while (i > 0) {
  1195. sdlAttributePtr attr = emalloc(sizeof(sdlAttribute));
  1196. memset(attr, 0, sizeof(sdlAttribute));
  1197. sdl_deserialize_key(type->attributes, attr, in);
  1198. sdl_deserialize_attribute(attr, encoders, in);
  1199. --i;
  1200. }
  1201. }
  1202. if (**in != 0) {
  1203. WSDL_CACHE_SKIP(1, in);
  1204. type->model = sdl_deserialize_model(types, elements, in);
  1205. } else {
  1206. WSDL_CACHE_SKIP(1, in);
  1207. }
  1208. if (elements != NULL) {
  1209. efree(elements);
  1210. }
  1211. }
  1212. static void sdl_deserialize_encoder(encodePtr enc, sdlTypePtr *types, char **in)
  1213. {
  1214. int i;
  1215. WSDL_CACHE_GET_INT(enc->details.type, in);
  1216. enc->details.type_str = sdl_deserialize_string(in);
  1217. enc->details.ns = sdl_deserialize_string(in);
  1218. WSDL_CACHE_GET_INT(i, in);
  1219. enc->details.sdl_type = types[i];
  1220. enc->to_xml = sdl_guess_convert_xml;
  1221. enc->to_zval = sdl_guess_convert_zval;
  1222. if (enc->details.sdl_type == NULL) {
  1223. int ns_len = strlen(enc->details.ns);
  1224. int type_len = strlen(enc->details.type_str);
  1225. if (((ns_len == sizeof(SOAP_1_1_ENC_NAMESPACE)-1 &&
  1226. memcmp(enc->details.ns, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1) == 0) ||
  1227. (ns_len == sizeof(SOAP_1_2_ENC_NAMESPACE)-1 &&
  1228. memcmp(enc->details.ns, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1) == 0))) {
  1229. char *enc_nscat;
  1230. int enc_ns_len;
  1231. int enc_len;
  1232. encodePtr real_enc;
  1233. enc_ns_len = sizeof(XSD_NAMESPACE)-1;
  1234. enc_len = enc_ns_len + type_len + 1;
  1235. enc_nscat = emalloc(enc_len + 1);
  1236. memcpy(enc_nscat, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1);
  1237. enc_nscat[enc_ns_len] = ':';
  1238. memcpy(enc_nscat+enc_ns_len+1, enc->details.type_str, type_len);
  1239. enc_nscat[enc_len] = '\0';
  1240. real_enc = get_encoder_ex(NULL, enc_nscat, enc_len);
  1241. efree(enc_nscat);
  1242. if (real_enc) {
  1243. enc->to_zval = real_enc->to_zval;
  1244. enc->to_xml = real_enc->to_xml;
  1245. }
  1246. }
  1247. }
  1248. }
  1249. static void sdl_deserialize_soap_body(sdlSoapBindingFunctionBodyPtr body, encodePtr *encoders, sdlTypePtr *types, char **in)
  1250. {
  1251. int i, j, n;
  1252. WSDL_CACHE_GET_1(body->use, sdlEncodingUse, in);
  1253. if (body->use == SOAP_ENCODED) {
  1254. WSDL_CACHE_GET_1(body->encodingStyle, sdlRpcEncodingStyle, in);
  1255. } else {
  1256. body->encodingStyle = SOAP_ENCODING_DEFAULT;
  1257. }
  1258. body->ns = sdl_deserialize_string(in);
  1259. WSDL_CACHE_GET_INT(i, in);
  1260. if (i > 0) {
  1261. body->headers = emalloc(sizeof(HashTable));
  1262. zend_hash_init(body->headers, i, NULL, delete_header, 0);
  1263. while (i > 0) {
  1264. sdlSoapBindingFunctionHeaderPtr tmp = emalloc(sizeof(sdlSoapBindingFunctionHeader));
  1265. memset(tmp, 0, sizeof(sdlSoapBindingFunctionHeader));
  1266. sdl_deserialize_key(body->headers, tmp, in);
  1267. WSDL_CACHE_GET_1(tmp->use, sdlEncodingUse, in);
  1268. if (tmp->use == SOAP_ENCODED) {
  1269. WSDL_CACHE_GET_1(tmp->encodingStyle, sdlRpcEncodingStyle, in);
  1270. } else {
  1271. tmp->encodingStyle = SOAP_ENCODING_DEFAULT;
  1272. }
  1273. tmp->name = sdl_deserialize_string(in);
  1274. tmp->ns = sdl_deserialize_string(in);
  1275. WSDL_CACHE_GET_INT(n, in);
  1276. tmp->encode = encoders[n];
  1277. WSDL_CACHE_GET_INT(n, in);
  1278. tmp->element = types[n];
  1279. --i;
  1280. WSDL_CACHE_GET_INT(j, in);
  1281. if (j > 0) {
  1282. tmp->headerfaults = emalloc(sizeof(HashTable));
  1283. zend_hash_init(tmp->headerfaults, i, NULL, delete_header, 0);
  1284. while (j > 0) {
  1285. sdlSoapBindingFunctionHeaderPtr tmp2 = emalloc(sizeof(sdlSoapBindingFunctionHeader));
  1286. memset(tmp2, 0, sizeof(sdlSoapBindingFunctionHeader));
  1287. sdl_deserialize_key(tmp->headerfaults, tmp2, in);
  1288. WSDL_CACHE_GET_1(tmp2->use, sdlEncodingUse, in);
  1289. if (tmp2->use == SOAP_ENCODED) {
  1290. WSDL_CACHE_GET_1(tmp2->encodin

Large files files are truncated, but you can click here to view the full file