PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/soap - php_sdl.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 1525 2090 73.0 %
Date: 2016-08-24 Functions: 61 73 83.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2016 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$ */
      21             : 
      22             : #include "php_soap.h"
      23             : #include "ext/libxml/php_libxml.h"
      24             : #include "libxml/uri.h"
      25             : 
      26             : #include "ext/standard/md5.h"
      27             : #include "zend_virtual_cwd.h"
      28             : 
      29             : #include <sys/types.h>
      30             : #include <sys/stat.h>
      31             : #include <fcntl.h>
      32             : 
      33             : #ifndef O_BINARY
      34             : # define O_BINARY 0
      35             : #endif
      36             : 
      37             : static void delete_fault(zval *zv);
      38             : static void delete_fault_persistent(zval *zv);
      39             : static void delete_binding(zval *zv);
      40             : static void delete_binding_persistent(zval *zv);
      41             : static void delete_function(zval *zv);
      42             : static void delete_function_persistent(zval *zv);
      43             : static void delete_parameter(zval *zv);
      44             : static void delete_parameter_persistent(zval *zv);
      45             : static void delete_header(zval *header);
      46             : static void delete_header_int(sdlSoapBindingFunctionHeaderPtr hdr);
      47             : static void delete_header_persistent(zval *zv);
      48             : static void delete_document(zval *zv);
      49             : 
      50       10688 : encodePtr get_encoder_from_prefix(sdlPtr sdl, xmlNodePtr node, const xmlChar *type)
      51             : {
      52       10688 :         encodePtr enc = NULL;
      53             :         xmlNsPtr nsptr;
      54             :         char *ns, *cptype;
      55             : 
      56       10688 :         parse_namespace(type, &cptype, &ns);
      57       10688 :         nsptr = xmlSearchNs(node->doc, node, BAD_CAST(ns));
      58       10688 :         if (nsptr != NULL) {
      59       10665 :                 enc = get_encoder(sdl, (char*)nsptr->href, cptype);
      60       10665 :                 if (enc == NULL) {
      61           9 :                         enc = get_encoder_ex(sdl, cptype, strlen(cptype));
      62             :                 }
      63             :         } else {
      64          23 :                 enc = get_encoder_ex(sdl, (char*)type, xmlStrlen(type));
      65             :         }
      66       10688 :         efree(cptype);
      67       10688 :         if (ns) {efree(ns);}
      68       10688 :         return enc;
      69             : }
      70             : 
      71       10182 : static sdlTypePtr get_element(sdlPtr sdl, xmlNodePtr node, const xmlChar *type)
      72             : {
      73       10182 :         sdlTypePtr ret = NULL;
      74             : 
      75       10182 :         if (sdl->elements) {
      76             :                 xmlNsPtr nsptr;
      77             :                 char *ns, *cptype;
      78             :                 sdlTypePtr sdl_type;
      79             : 
      80       10177 :                 parse_namespace(type, &cptype, &ns);
      81       10177 :                 nsptr = xmlSearchNs(node->doc, node, BAD_CAST(ns));
      82       10177 :                 if (nsptr != NULL) {
      83       10175 :                         int ns_len = xmlStrlen(nsptr->href);
      84       10175 :                         int type_len = strlen(cptype);
      85       10175 :                         int len = ns_len + type_len + 1;
      86       10175 :                         char *nscat = emalloc(len + 1);
      87             : 
      88       10175 :                         memcpy(nscat, nsptr->href, ns_len);
      89       10175 :                         nscat[ns_len] = ':';
      90       10175 :                         memcpy(nscat+ns_len+1, cptype, type_len);
      91       10175 :                         nscat[len] = '\0';
      92             : 
      93       20350 :                         if ((sdl_type = zend_hash_str_find_ptr(sdl->elements, nscat, len)) != NULL) {
      94       10175 :                                 ret = sdl_type;
      95           0 :                         } else if ((sdl_type = zend_hash_str_find_ptr(sdl->elements, (char*)type, type_len)) != NULL) {
      96           0 :                                 ret = sdl_type;
      97             :                         }
      98       10175 :                         efree(nscat);
      99             :                 } else {
     100           4 :                         if ((sdl_type = zend_hash_str_find_ptr(sdl->elements, (char*)type, xmlStrlen(type))) != NULL) {
     101           0 :                                 ret = sdl_type;
     102             :                         }
     103             :                 }
     104             : 
     105       10177 :                 efree(cptype);
     106       10177 :                 if (ns) {efree(ns);}
     107             :         }
     108       10182 :         return ret;
     109             : }
     110             : 
     111       24285 : encodePtr get_encoder(sdlPtr sdl, const char *ns, const char *type)
     112             : {
     113       24285 :         encodePtr enc = NULL;
     114             :         char *nscat;
     115       24285 :         int ns_len = ns ? strlen(ns) : 0;
     116       24285 :         int type_len = strlen(type);
     117       24285 :         int len = ns_len + type_len + 1;
     118             : 
     119       24285 :         nscat = emalloc(len + 1);
     120       24285 :         memcpy(nscat, ns, ns_len);
     121       24285 :         nscat[ns_len] = ':';
     122       24285 :         memcpy(nscat+ns_len+1, type, type_len);
     123       24285 :         nscat[len] = '\0';
     124             : 
     125       24285 :         enc = get_encoder_ex(sdl, nscat, len);
     126             : 
     127       24289 :         if (enc == NULL &&
     128             :             ((ns_len == sizeof(SOAP_1_1_ENC_NAMESPACE)-1 &&
     129           4 :               memcmp(ns, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1) == 0) ||
     130             :              (ns_len == sizeof(SOAP_1_2_ENC_NAMESPACE)-1 &&
     131           0 :               memcmp(ns, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1) == 0))) {
     132             :                 char *enc_nscat;
     133             :                 int enc_ns_len;
     134             :                 int enc_len;
     135             : 
     136           4 :                 enc_ns_len = sizeof(XSD_NAMESPACE)-1;
     137           4 :                 enc_len = enc_ns_len + type_len + 1;
     138           4 :                 enc_nscat = emalloc(enc_len + 1);
     139           4 :                 memcpy(enc_nscat, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1);
     140           4 :                 enc_nscat[enc_ns_len] = ':';
     141           4 :                 memcpy(enc_nscat+enc_ns_len+1, type, type_len);
     142           4 :                 enc_nscat[enc_len] = '\0';
     143             : 
     144           4 :                 enc = get_encoder_ex(NULL, enc_nscat, enc_len);
     145           4 :                 efree(enc_nscat);
     146           4 :                 if (enc && sdl) {
     147           4 :                         encodePtr new_enc       = pemalloc(sizeof(encode), sdl->is_persistent);
     148           4 :                         memcpy(new_enc, enc, sizeof(encode));
     149           4 :                         if (sdl->is_persistent) {
     150           2 :                                 new_enc->details.ns = zend_strndup(ns, ns_len);
     151           2 :                                 new_enc->details.type_str = strdup(new_enc->details.type_str);
     152             :                         } else {
     153           2 :                                 new_enc->details.ns = estrndup(ns, ns_len);
     154           2 :                                 new_enc->details.type_str = estrdup(new_enc->details.type_str);
     155             :                         }
     156           4 :                         if (sdl->encoders == NULL) {
     157           0 :                                 sdl->encoders = pemalloc(sizeof(HashTable), sdl->is_persistent);
     158           0 :                                 zend_hash_init(sdl->encoders, 0, NULL, delete_encoder, sdl->is_persistent);
     159             :                         }
     160           4 :                         zend_hash_str_update_ptr(sdl->encoders, nscat, len, new_enc);
     161           4 :                         enc = new_enc;
     162             :                 }
     163             :         }
     164       24285 :         efree(nscat);
     165       24285 :         return enc;
     166             : }
     167             : 
     168       24323 : encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat, int len)
     169             : {
     170             :         encodePtr enc;
     171             : 
     172       48646 :         if ((enc = zend_hash_str_find_ptr(&SOAP_GLOBAL(defEnc), (char*)nscat, len)) != NULL) {
     173       15754 :                 return enc;
     174       17095 :         } else if (sdl && sdl->encoders && (enc = zend_hash_str_find_ptr(sdl->encoders, (char*)nscat, len)) != NULL) {
     175        6828 :                 return enc;
     176             :         }
     177        1741 :         return NULL;
     178             : }
     179             : 
     180           0 : sdlBindingPtr get_binding_from_type(sdlPtr sdl, sdlBindingType type)
     181             : {
     182             :         sdlBindingPtr binding;
     183             : 
     184           0 :         if (sdl == NULL) {
     185           0 :                 return NULL;
     186             :         }
     187             : 
     188           0 :         ZEND_HASH_FOREACH_PTR(sdl->bindings, binding) {
     189           0 :                 if (binding->bindingType == type) {
     190           0 :                         return binding;
     191             :                 }
     192             :         } ZEND_HASH_FOREACH_END();
     193           0 :         return NULL;
     194             : }
     195             : 
     196           0 : sdlBindingPtr get_binding_from_name(sdlPtr sdl, char *name, char *ns)
     197             : {
     198             :         sdlBindingPtr binding;
     199           0 :         smart_str key = {0};
     200             : 
     201           0 :         smart_str_appends(&key, ns);
     202             :         smart_str_appendc(&key, ':');
     203           0 :         smart_str_appends(&key, name);
     204             :         smart_str_0(&key);
     205             : 
     206           0 :         binding = zend_hash_find_ptr(sdl->bindings, key.s);
     207             : 
     208             :         smart_str_free(&key);
     209           0 :         return binding;
     210             : }
     211             : 
     212       40907 : static int is_wsdl_element(xmlNodePtr node)
     213             : {
     214       40907 :         if (node->ns && strcmp((char*)node->ns->href, WSDL_NAMESPACE) != 0) {
     215             :                 xmlAttrPtr attr;
     216         169 :                 if ((attr = get_attribute_ex(node->properties, "required", WSDL_NAMESPACE)) != NULL &&
     217           2 :                      attr->children && attr->children->content &&
     218           1 :                      (strcmp((char*)attr->children->content, "1") == 0 ||
     219           1 :                       strcmp((char*)attr->children->content, "true") == 0)) {
     220           1 :                         soap_error1(E_ERROR, "Parsing WSDL: Unknown required WSDL extension '%s'", node->ns->href);
     221             :                 }
     222         164 :                 return 0;
     223             :         }
     224       40742 :         return 1;
     225             : }
     226             : 
     227         733 : void sdl_set_uri_credentials(sdlCtx *ctx, char *uri)
     228             : {
     229             :         char *s;
     230             :         size_t l1, l2;
     231             :         zval context;
     232         733 :         zval *header = NULL;
     233             : 
     234             :         /* check if we load xsd from the same server */
     235         733 :         s = strstr(ctx->sdl->source, "://");
     236         733 :         if (!s) return;
     237           2 :         s = strchr(s+3, '/');
     238           2 :         l1 = s ? (size_t)(s - ctx->sdl->source) : strlen(ctx->sdl->source);
     239           2 :         s = strstr((char*)uri, "://");
     240           2 :         if (!s) return;
     241           2 :         s = strchr(s+3, '/');
     242           2 :         l2 = s ? (size_t)(s - (char*)uri) : strlen((char*)uri);
     243           2 :         if (l1 != l2) {
     244             :                 /* check for http://...:80/ */
     245           0 :                 if (l1 > 11 &&
     246           0 :                     ctx->sdl->source[4] == ':' &&
     247           0 :                     ctx->sdl->source[l1-3] == ':' &&
     248           0 :                     ctx->sdl->source[l1-2] == '8' &&
     249           0 :                     ctx->sdl->source[l1-1] == '0') {
     250           0 :                         l1 -= 3;
     251             :                 }
     252           0 :                 if (l2 > 11 &&
     253           0 :                     uri[4] == ':' &&
     254           0 :                     uri[l2-3] == ':' &&
     255           0 :                     uri[l2-2] == '8' &&
     256           0 :                     uri[l2-1] == '0') {
     257           0 :                         l2 -= 3;
     258             :                 }
     259             :                 /* check for https://...:443/ */
     260           0 :                 if (l1 > 13 &&
     261           0 :                     ctx->sdl->source[4] == 's' &&
     262           0 :                     ctx->sdl->source[l1-4] == ':' &&
     263           0 :                     ctx->sdl->source[l1-3] == '4' &&
     264           0 :                     ctx->sdl->source[l1-2] == '4' &&
     265           0 :                     ctx->sdl->source[l1-1] == '3') {
     266           0 :                         l1 -= 4;
     267             :                 }
     268           0 :                 if (l2 > 13 &&
     269           0 :                     uri[4] == 's' &&
     270           0 :                     uri[l2-4] == ':' &&
     271           0 :                     uri[l2-3] == '4' &&
     272           0 :                     uri[l2-2] == '4' &&
     273           0 :                     uri[l2-1] == '3') {
     274           0 :                         l2 -= 4;
     275             :                 }
     276             :         }
     277           2 :         if (l1 != l2 || memcmp(ctx->sdl->source, uri, l1) != 0) {
     278             :                 /* another server. clear authentication credentals */
     279           0 :                 php_libxml_switch_context(NULL, &context);
     280           0 :                 php_libxml_switch_context(&context, NULL);
     281           0 :                 if (Z_TYPE(context) != IS_UNDEF) {
     282           0 :                         zval *context_ptr = &context;
     283           0 :                         ctx->context = php_stream_context_from_zval(context_ptr, 1);
     284             : 
     285           0 :                         if (ctx->context &&
     286           0 :                             (header = php_stream_context_get_option(ctx->context, "http", "header")) != NULL) {
     287           0 :                                 s = strstr(Z_STRVAL_P(header), "Authorization: Basic");
     288           0 :                                 if (s && (s == Z_STRVAL_P(header) || *(s-1) == '\n' || *(s-1) == '\r')) {
     289           0 :                                         char *rest = strstr(s, "\r\n");
     290           0 :                                         if (rest) {
     291             :                                                 zval new_header;
     292             : 
     293           0 :                                                 rest += 2;
     294           0 :                                                 ZVAL_NEW_STR(&new_header, zend_string_alloc(Z_STRLEN_P(header) - (rest - s), 0));
     295           0 :                                                 memcpy(Z_STRVAL(new_header), Z_STRVAL_P(header), s - Z_STRVAL_P(header));
     296           0 :                                                 memcpy(Z_STRVAL(new_header) + (s - Z_STRVAL_P(header)), rest, Z_STRLEN_P(header) - (rest - Z_STRVAL_P(header)) + 1);
     297           0 :                                                 ZVAL_COPY(&ctx->old_header, header);
     298           0 :                                                 php_stream_context_set_option(ctx->context, "http", "header", &new_header);
     299           0 :                                                 zval_ptr_dtor(&new_header);
     300             :                                         }
     301             :                                 }
     302             :                         }
     303             :                 }
     304             :         }
     305             : }
     306             : 
     307         733 : void sdl_restore_uri_credentials(sdlCtx *ctx)
     308             : {
     309        1466 :         if (Z_TYPE(ctx->old_header) != IS_UNDEF) {
     310           0 :             php_stream_context_set_option(ctx->context, "http", "header", &ctx->old_header);
     311           0 :             zval_ptr_dtor(&ctx->old_header);
     312           0 :                 ZVAL_UNDEF(&ctx->old_header);
     313             :         }
     314         733 :         ctx->context = NULL;
     315         733 : }
     316             : 
     317         733 : static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include)
     318             : {
     319         733 :         sdlPtr tmpsdl = ctx->sdl;
     320             :         xmlDocPtr wsdl;
     321             :         xmlNodePtr root, definitions, trav;
     322             :         xmlAttrPtr targetNamespace;
     323             : 
     324         733 :         if (zend_hash_str_exists(&ctx->docs, struri, strlen(struri))) {
     325           4 :                 return;
     326             :         }
     327             : 
     328         729 :         sdl_set_uri_credentials(ctx, struri);
     329         729 :         wsdl = soap_xmlParseFile(struri);
     330         729 :         sdl_restore_uri_credentials(ctx);
     331             : 
     332         729 :         if (!wsdl) {
     333           2 :                 xmlErrorPtr xmlErrorPtr = xmlGetLastError();
     334             : 
     335           2 :                 if (xmlErrorPtr) {
     336           2 :                         soap_error2(E_ERROR, "Parsing WSDL: Couldn't load from '%s' : %s", struri, xmlErrorPtr->message);
     337             :                 } else {
     338           0 :                         soap_error1(E_ERROR, "Parsing WSDL: Couldn't load from '%s'", struri);
     339             :                 }
     340             :         }
     341             : 
     342         727 :         zend_hash_str_add_ptr(&ctx->docs, struri, strlen(struri), wsdl);
     343             : 
     344         727 :         root = wsdl->children;
     345         727 :         definitions = get_node_ex(root, "definitions", WSDL_NAMESPACE);
     346         727 :         if (!definitions) {
     347           6 :                 if (include) {
     348           6 :                         xmlNodePtr schema = get_node_ex(root, "schema", XSD_NAMESPACE);
     349           6 :                         if (schema) {
     350           6 :                                 load_schema(ctx, schema);
     351           6 :                                 return;
     352             :                         }
     353             :                 }
     354           0 :                 soap_error1(E_ERROR, "Parsing WSDL: Couldn't find <definitions> in '%s'", struri);
     355             :         }
     356             : 
     357         721 :         if (!include) {
     358         708 :                 targetNamespace = get_attribute(definitions->properties, "targetNamespace");
     359         708 :                 if (targetNamespace) {
     360         707 :                         tmpsdl->target_ns = estrdup((char*)targetNamespace->children->content);
     361             :                 }
     362             :         }
     363             : 
     364         721 :         trav = definitions->children;
     365       17523 :         while (trav != NULL) {
     366       16081 :                 if (!is_wsdl_element(trav)) {
     367          51 :                         trav = trav->next;
     368          51 :                         continue;
     369             :                 }
     370       16030 :                 if (node_is_equal(trav,"types")) {
     371             :                         /* TODO: Only one "types" is allowed */
     372         686 :                         xmlNodePtr trav2 = trav->children;
     373             : 
     374        2484 :                         while (trav2 != NULL) {
     375        1112 :                                 if (node_is_equal_ex(trav2, "schema", XSD_NAMESPACE)) {
     376        1105 :                                         load_schema(ctx, trav2);
     377           7 :                                 } else if (is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) {
     378           0 :                                         soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name);
     379             :                                 }
     380        1112 :                                 trav2 = trav2->next;
     381             :                         }
     382       15344 :                 } else if (node_is_equal(trav,"import")) {
     383             :                         /* TODO: namespace ??? */
     384          23 :                         xmlAttrPtr tmp = get_attribute(trav->properties, "location");
     385          23 :                         if (tmp) {
     386             :                                 xmlChar *uri;
     387          23 :                                 xmlChar *base = xmlNodeGetBase(trav->doc, trav);
     388             : 
     389          23 :                                 if (base == NULL) {
     390           0 :                                         uri = xmlBuildURI(tmp->children->content, trav->doc->URL);
     391             :                                 } else {
     392          23 :                                         uri = xmlBuildURI(tmp->children->content, base);
     393          23 :                                         xmlFree(base);
     394             :                                 }
     395          23 :                                 load_wsdl_ex(this_ptr, (char*)uri, ctx, 1);
     396          23 :                                 xmlFree(uri);
     397             :                         }
     398             : 
     399       15321 :                 } else if (node_is_equal(trav,"message")) {
     400       12915 :                         xmlAttrPtr name = get_attribute(trav->properties, "name");
     401       25830 :                         if (name && name->children && name->children->content) {
     402       25830 :                                 if (zend_hash_str_add_ptr(&ctx->messages, (char*)name->children->content, xmlStrlen(name->children->content), trav) == NULL) {
     403           0 :                                         soap_error1(E_ERROR, "Parsing WSDL: <message> '%s' already defined", name->children->content);
     404             :                                 }
     405             :                         } else {
     406           0 :                                 soap_error0(E_ERROR, "Parsing WSDL: <message> has no name attribute");
     407             :                         }
     408             : 
     409        2406 :                 } else if (node_is_equal(trav,"portType")) {
     410         790 :                         xmlAttrPtr name = get_attribute(trav->properties, "name");
     411        1580 :                         if (name && name->children && name->children->content) {
     412        1580 :                                 if (zend_hash_str_add_ptr(&ctx->portTypes, (char*)name->children->content, xmlStrlen(name->children->content), trav) == NULL) {
     413           0 :                                         soap_error1(E_ERROR, "Parsing WSDL: <portType> '%s' already defined", name->children->content);
     414             :                                 }
     415             :                         } else {
     416           0 :                                 soap_error0(E_ERROR, "Parsing WSDL: <portType> has no name attribute");
     417             :                         }
     418             : 
     419        1616 :                 } else if (node_is_equal(trav,"binding")) {
     420         874 :                         xmlAttrPtr name = get_attribute(trav->properties, "name");
     421        1748 :                         if (name && name->children && name->children->content) {
     422        1748 :                                 if (zend_hash_str_add_ptr(&ctx->bindings, (char*)name->children->content, xmlStrlen(name->children->content), trav) == NULL) {
     423           0 :                                         soap_error1(E_ERROR, "Parsing WSDL: <binding> '%s' already defined", name->children->content);
     424             :                                 }
     425             :                         } else {
     426           0 :                                 soap_error0(E_ERROR, "Parsing WSDL: <binding> has no name attribute");
     427             :                         }
     428             : 
     429         742 :                 } else if (node_is_equal(trav,"service")) {
     430         741 :                         xmlAttrPtr name = get_attribute(trav->properties, "name");
     431        1482 :                         if (name && name->children && name->children->content) {
     432        1482 :                                 if (zend_hash_str_add_ptr(&ctx->services, (char*)name->children->content, xmlStrlen(name->children->content), trav) == NULL) {
     433           0 :                                         soap_error1(E_ERROR, "Parsing WSDL: <service> '%s' already defined", name->children->content);
     434             :                                 }
     435             :                         } else {
     436           0 :                                 soap_error0(E_ERROR, "Parsing WSDL: <service> has no name attribute");
     437             :                         }
     438           1 :                 } else if (!node_is_equal(trav,"documentation")) {
     439           0 :                         soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
     440             :                 }
     441       16030 :                 trav = trav->next;
     442             :         }
     443             : }
     444             : 
     445        1621 : static sdlSoapBindingFunctionHeaderPtr wsdl_soap_binding_header(sdlCtx* ctx, xmlNodePtr header, char* wsdl_soap_namespace, int fault)
     446             : {
     447             :         xmlAttrPtr tmp;
     448             :         xmlNodePtr message, part;
     449             :         char *ctype;
     450             :         sdlSoapBindingFunctionHeaderPtr h;
     451             : 
     452        1621 :         tmp = get_attribute(header->properties, "message");
     453        1621 :         if (!tmp) {
     454           0 :                 soap_error0(E_ERROR, "Parsing WSDL: Missing message attribute for <header>");
     455             :         }
     456             : 
     457        1621 :         ctype = strrchr((char*)tmp->children->content,':');
     458        1621 :         if (ctype == NULL) {
     459           0 :                 ctype = (char*)tmp->children->content;
     460             :         } else {
     461        1621 :                 ++ctype;
     462             :         }
     463        3242 :         if ((message = zend_hash_str_find_ptr(&ctx->messages, ctype, strlen(ctype))) == NULL) {
     464           0 :                 soap_error1(E_ERROR, "Parsing WSDL: Missing <message> with name '%s'", tmp->children->content);
     465             :         }
     466             : 
     467        1621 :         tmp = get_attribute(header->properties, "part");
     468        1621 :         if (!tmp) {
     469           0 :                 soap_error0(E_ERROR, "Parsing WSDL: Missing part attribute for <header>");
     470             :         }
     471        1621 :         part = get_node_with_attribute_ex(message->children, "part", WSDL_NAMESPACE, "name", (char*)tmp->children->content, NULL);
     472        1621 :         if (!part) {
     473           0 :                 soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in <message>", tmp->children->content);
     474             :         }
     475             : 
     476        1621 :         h = emalloc(sizeof(sdlSoapBindingFunctionHeader));
     477        1621 :         memset(h, 0, sizeof(sdlSoapBindingFunctionHeader));
     478        1621 :         h->name = estrdup((char*)tmp->children->content);
     479             : 
     480        1621 :         tmp = get_attribute(header->properties, "use");
     481        1776 :         if (tmp && !strncmp((char*)tmp->children->content, "encoded", sizeof("encoded"))) {
     482         155 :                 h->use = SOAP_ENCODED;
     483             :         } else {
     484        1466 :                 h->use = SOAP_LITERAL;
     485             :         }
     486             : 
     487        1621 :         tmp = get_attribute(header->properties, "namespace");
     488        1621 :         if (tmp) {
     489         148 :                 h->ns = estrdup((char*)tmp->children->content);
     490             :         }
     491             : 
     492        1621 :         if (h->use == SOAP_ENCODED) {
     493         155 :                 tmp = get_attribute(header->properties, "encodingStyle");
     494         155 :                 if (tmp) {
     495         155 :                         if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) {
     496           9 :                                 h->encodingStyle = SOAP_ENCODING_1_1;
     497         146 :                         } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) {
     498         146 :                                 h->encodingStyle = SOAP_ENCODING_1_2;
     499             :                         } else {
     500           0 :                                 soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content);
     501             :                         }
     502             :                 } else {
     503           0 :                         soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle");
     504             :                 }
     505             :         }
     506             : 
     507        1621 :         tmp = get_attribute(part->properties, "type");
     508        1621 :         if (tmp != NULL) {
     509         157 :                 h->encode = get_encoder_from_prefix(ctx->sdl, part, tmp->children->content);
     510             :         } else {
     511        1464 :                 tmp = get_attribute(part->properties, "element");
     512        1464 :                 if (tmp != NULL) {
     513        1464 :                         h->element = get_element(ctx->sdl, part, tmp->children->content);
     514        1464 :                         if (h->element) {
     515        1464 :                                 h->encode = h->element->encode;
     516        1464 :                                 if (!h->ns && h->element->namens) {
     517        1464 :                                         h->ns = estrdup(h->element->namens);
     518             :                                 }
     519        1464 :                                 if (h->element->name) {
     520        1464 :                                         efree(h->name);
     521        1464 :                                         h->name = estrdup(h->element->name);
     522             :                                 }
     523             :                         }
     524             :                 }
     525             :         }
     526        1621 :         if (!fault) {
     527        1548 :                 xmlNodePtr trav = header->children;
     528        3169 :                 while (trav != NULL) {
     529          73 :                         if (node_is_equal_ex(trav, "headerfault", wsdl_soap_namespace)) {
     530          73 :                                 sdlSoapBindingFunctionHeaderPtr hf = wsdl_soap_binding_header(ctx, trav, wsdl_soap_namespace, 1);
     531          73 :                                 smart_str key = {0};
     532             : 
     533          73 :                                 if (h->headerfaults == NULL) {
     534          73 :                                         h->headerfaults = emalloc(sizeof(HashTable));
     535          73 :                                         zend_hash_init(h->headerfaults, 0, NULL, delete_header, 0);
     536             :                                 }
     537             : 
     538          73 :                                 if (hf->ns) {
     539          73 :                                         smart_str_appends(&key,hf->ns);
     540             :                                         smart_str_appendc(&key,':');
     541             :                                 }
     542          73 :                                 smart_str_appends(&key,hf->name);
     543             :                                 smart_str_0(&key);
     544         146 :                                 if (zend_hash_add_ptr(h->headerfaults, key.s, hf) == NULL) {
     545           0 :                                         delete_header_int(hf);
     546             :                                 }
     547             :                                 smart_str_free(&key);
     548           0 :                         } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) {
     549           0 :                                 soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
     550             :                         }
     551          73 :                         trav = trav->next;
     552             :                 }
     553             :         }
     554        1621 :         return h;
     555             : }
     556             : 
     557       14956 : static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap_namespace, sdlSoapBindingFunctionBody *binding, HashTable* params)
     558             : {
     559             :         xmlNodePtr body, trav;
     560             :         xmlAttrPtr tmp;
     561             : 
     562       14956 :         trav = node->children;
     563       46426 :         while (trav != NULL) {
     564       16514 :                 if (node_is_equal_ex(trav, "body", wsdl_soap_namespace)) {
     565       14954 :                         body = trav;
     566             : 
     567       14954 :                         tmp = get_attribute(body->properties, "use");
     568       23274 :                         if (tmp && !strncmp((char*)tmp->children->content, "literal", sizeof("literal"))) {
     569        8320 :                                 binding->use = SOAP_LITERAL;
     570             :                         } else {
     571        6634 :                                 binding->use = SOAP_ENCODED;
     572             :                         }
     573             : 
     574       14954 :                         tmp = get_attribute(body->properties, "namespace");
     575       14954 :                         if (tmp) {
     576        6785 :                                 binding->ns = estrdup((char*)tmp->children->content);
     577             :                         }
     578             : 
     579       14954 :                         tmp = get_attribute(body->properties, "parts");
     580       14954 :                         if (tmp) {
     581             :                                 HashTable    ht;
     582           0 :                                 char *parts = (char*)tmp->children->content;
     583             : 
     584             :                                 /* Delete all parts those are not in the "parts" attribute */
     585           0 :                                 zend_hash_init(&ht, 0, NULL, delete_parameter, 0);
     586           0 :                                 while (*parts) {
     587             :                                         sdlParamPtr param;
     588           0 :                                         int found = 0;
     589             :                                         char *end;
     590             : 
     591           0 :                                         while (*parts == ' ') ++parts;
     592           0 :                                         if (*parts == '\0') break;
     593           0 :                                         end = strchr(parts, ' ');
     594           0 :                                         if (end) *end = '\0';
     595           0 :                                         ZEND_HASH_FOREACH_PTR(params, param) {
     596           0 :                                                 if (param->paramName &&
     597           0 :                                                     strcmp(parts, param->paramName) == 0) {
     598             :                                                 sdlParamPtr x_param;
     599           0 :                                                 x_param = emalloc(sizeof(sdlParam));
     600           0 :                                                 *x_param = *param;
     601           0 :                                                 param->paramName = NULL;
     602             :                                                 zend_hash_next_index_insert_ptr(&ht, x_param);
     603           0 :                                                 found = 1;
     604           0 :                                                 break;
     605             :                                                 }
     606             :                                         } ZEND_HASH_FOREACH_END();
     607           0 :                                         if (!found) {
     608           0 :                                                 soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in <message>", parts);
     609             :                                         }
     610           0 :                                         parts += strlen(parts);
     611           0 :                                         if (end) *end = ' ';
     612             :                                 }
     613           0 :                                 zend_hash_destroy(params);
     614           0 :                                 *params = ht;
     615             :                         }
     616             : 
     617       14954 :                         if (binding->use == SOAP_ENCODED) {
     618        6634 :                                 tmp = get_attribute(body->properties, "encodingStyle");
     619        6634 :                                 if (tmp) {
     620        6634 :                                         if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) {
     621        4006 :                                                 binding->encodingStyle = SOAP_ENCODING_1_1;
     622        2628 :                                         } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) {
     623        2628 :                                                 binding->encodingStyle = SOAP_ENCODING_1_2;
     624             :                                         } else {
     625           0 :                                                 soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content);
     626             :                                         }
     627             :                                 } else {
     628           0 :                                         soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle");
     629             :                                 }
     630             :                         }
     631        1560 :                 } else if (node_is_equal_ex(trav, "header", wsdl_soap_namespace)) {
     632        1548 :                         sdlSoapBindingFunctionHeaderPtr h = wsdl_soap_binding_header(ctx, trav, wsdl_soap_namespace, 0);
     633        1548 :                         smart_str key = {0};
     634             : 
     635        1548 :                         if (binding->headers == NULL) {
     636         890 :                                 binding->headers = emalloc(sizeof(HashTable));
     637         890 :                                 zend_hash_init(binding->headers, 0, NULL, delete_header, 0);
     638             :                         }
     639             : 
     640        1548 :                         if (h->ns) {
     641        1539 :                                 smart_str_appends(&key,h->ns);
     642             :                                 smart_str_appendc(&key,':');
     643             :                         }
     644        1548 :                         smart_str_appends(&key,h->name);
     645             :                         smart_str_0(&key);
     646        3096 :                         if (zend_hash_add_ptr(binding->headers, key.s, h) == NULL) {
     647           0 :                                 delete_header_int(h);
     648             :                         }
     649             :                         smart_str_free(&key);
     650          12 :                 } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) {
     651           0 :                         soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
     652             :                 }
     653       16514 :                 trav = trav->next;
     654             :         }
     655       14956 : }
     656             : 
     657       16168 : static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name)
     658             : {
     659       16168 :         xmlNodePtr trav, part, message = NULL, tmp;
     660       16168 :         HashTable* parameters = NULL;
     661             :         char *ctype;
     662             : 
     663       16168 :         ctype = strrchr((char*)message_name,':');
     664       16168 :         if (ctype == NULL) {
     665         181 :                 ctype = (char*)message_name;
     666             :         } else {
     667       15987 :                 ++ctype;
     668             :         }
     669       32336 :         if ((tmp = zend_hash_str_find_ptr(&ctx->messages, ctype, strlen(ctype))) == NULL) {
     670           0 :                 soap_error1(E_ERROR, "Parsing WSDL: Missing <message> with name '%s'", message_name);
     671             :         }
     672       16168 :         message = tmp;
     673             : 
     674       16168 :         parameters = emalloc(sizeof(HashTable));
     675       16168 :         zend_hash_init(parameters, 0, NULL, delete_parameter, 0);
     676             : 
     677       16168 :         trav = message->children;
     678       48383 :         while (trav != NULL) {
     679             :                 xmlAttrPtr element, type, name;
     680             :                 sdlParamPtr param;
     681             : 
     682       16047 :                 if (trav->ns != NULL && strcmp((char*)trav->ns->href, WSDL_NAMESPACE) != 0) {
     683           0 :                         soap_error1(E_ERROR, "Parsing WSDL: Unexpected extensibility element <%s>", trav->name);
     684             :                 }
     685       16047 :                 if (node_is_equal(trav,"documentation")) {
     686           8 :                         trav = trav->next;
     687           8 :                         continue;
     688             :                 }
     689       16039 :                 if (!node_is_equal(trav,"part")) {
     690           0 :                         soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
     691             :                 }
     692       16039 :                 part = trav;
     693       16039 :                 param = emalloc(sizeof(sdlParam));
     694       16039 :                 memset(param,0,sizeof(sdlParam));
     695       16039 :                 param->order = 0;
     696             : 
     697       16039 :                 name = get_attribute(part->properties, "name");
     698       16039 :                 if (name == NULL) {
     699           0 :                         soap_error1(E_ERROR, "Parsing WSDL: No name associated with <part> '%s'", message->name);
     700             :                 }
     701             : 
     702       16039 :                 param->paramName = estrdup((char*)name->children->content);
     703             : 
     704       16039 :                 type = get_attribute(part->properties, "type");
     705       16039 :                 if (type != NULL) {
     706        7321 :                         param->encode = get_encoder_from_prefix(ctx->sdl, part, type->children->content);
     707             :                 } else {
     708        8718 :                         element = get_attribute(part->properties, "element");
     709        8718 :                         if (element != NULL) {
     710        8718 :                                 param->element = get_element(ctx->sdl, part, element->children->content);
     711        8718 :                                 if (param->element) {
     712        8711 :                                         param->encode = param->element->encode;
     713             :                                 }
     714             :                         }
     715             :                 }
     716             : 
     717             :                 zend_hash_next_index_insert_ptr(parameters, param);
     718             : 
     719       16039 :                 trav = trav->next;
     720             :         }
     721       16168 :         return parameters;
     722             : }
     723             : 
     724         710 : static sdlPtr load_wsdl(zval *this_ptr, char *struri)
     725             : {
     726             :         sdlCtx ctx;
     727             :         int i,n;
     728             : 
     729         710 :         memset(&ctx,0,sizeof(ctx));
     730         710 :         ctx.sdl = emalloc(sizeof(sdl));
     731         710 :         memset(ctx.sdl, 0, sizeof(sdl));
     732         710 :         ctx.sdl->source = estrdup(struri);
     733         710 :         zend_hash_init(&ctx.sdl->functions, 0, NULL, delete_function, 0);
     734             : 
     735         710 :         zend_hash_init(&ctx.docs, 0, NULL, delete_document, 0);
     736         710 :         zend_hash_init(&ctx.messages, 0, NULL, NULL, 0);
     737         710 :         zend_hash_init(&ctx.bindings, 0, NULL, NULL, 0);
     738         710 :         zend_hash_init(&ctx.portTypes, 0, NULL, NULL, 0);
     739         710 :         zend_hash_init(&ctx.services,  0, NULL, NULL, 0);
     740             : 
     741         710 :         load_wsdl_ex(this_ptr, struri,&ctx, 0);
     742         708 :         schema_pass2(&ctx);
     743             : 
     744         708 :         n = zend_hash_num_elements(&ctx.services);
     745         708 :         if (n > 0) {
     746         708 :                 zend_hash_internal_pointer_reset(&ctx.services);
     747        1448 :                 for (i = 0; i < n; i++) {
     748             :                         xmlNodePtr service, tmp;
     749             :                         xmlNodePtr trav, port;
     750         741 :                         int has_soap_port = 0;
     751             : 
     752         741 :                         service = tmp = zend_hash_get_current_data_ptr(&ctx.services);
     753             : 
     754         741 :                         trav = service->children;
     755        2463 :                         while (trav != NULL) {
     756             :                                 xmlAttrPtr type, name, bindingAttr, location;
     757             :                                 xmlNodePtr portType, operation;
     758             :                                 xmlNodePtr address, binding, trav2;
     759             :                                 char *ctype;
     760             :                                 sdlBindingPtr tmpbinding;
     761         982 :                                 char *wsdl_soap_namespace = NULL;
     762             : 
     763         982 :                                 if (!is_wsdl_element(trav) || node_is_equal(trav,"documentation")) {
     764          80 :                                         trav = trav->next;
     765          80 :                                         continue;
     766             :                                 }
     767         902 :                                 if (!node_is_equal(trav,"port")) {
     768           0 :                                         soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
     769             :                                 }
     770             : 
     771         902 :                                 port = trav;
     772             : 
     773         902 :                                 tmpbinding = emalloc(sizeof(sdlBinding));
     774         902 :                                 memset(tmpbinding, 0, sizeof(sdlBinding));
     775             : 
     776         902 :                                 bindingAttr = get_attribute(port->properties, "binding");
     777         902 :                                 if (bindingAttr == NULL) {
     778           0 :                                         soap_error0(E_ERROR, "Parsing WSDL: No binding associated with <port>");
     779             :                                 }
     780             : 
     781             :                                 /* find address and figure out binding type */
     782         902 :                                 address = NULL;
     783         902 :                                 trav2 = port->children;
     784        2743 :                                 while (trav2 != NULL) {
     785         939 :                                         if (node_is_equal(trav2,"address") && trav2->ns) {
     786         907 :                                                 if (!strncmp((char*)trav2->ns->href, WSDL_SOAP11_NAMESPACE, sizeof(WSDL_SOAP11_NAMESPACE))) {
     787         636 :                                                         address = trav2;
     788         636 :                                                         wsdl_soap_namespace = WSDL_SOAP11_NAMESPACE;
     789         636 :                                                         tmpbinding->bindingType = BINDING_SOAP;
     790         271 :                                                 } else if (!strncmp((char*)trav2->ns->href, WSDL_SOAP12_NAMESPACE, sizeof(WSDL_SOAP12_NAMESPACE))) {
     791         257 :                                                         address = trav2;
     792         257 :                                                         wsdl_soap_namespace = WSDL_SOAP12_NAMESPACE;
     793         257 :                                                         tmpbinding->bindingType = BINDING_SOAP;
     794          14 :                                                 } else if (!strncmp((char*)trav2->ns->href, RPC_SOAP12_NAMESPACE, sizeof(RPC_SOAP12_NAMESPACE))) {
     795           0 :                                                         address = trav2;
     796           0 :                                                         wsdl_soap_namespace = RPC_SOAP12_NAMESPACE;
     797           0 :                                                         tmpbinding->bindingType = BINDING_SOAP;
     798          14 :                                                 } else if (!strncmp((char*)trav2->ns->href, WSDL_HTTP11_NAMESPACE, sizeof(WSDL_HTTP11_NAMESPACE))) {
     799           7 :                                                         address = trav2;
     800           7 :                                                         tmpbinding->bindingType = BINDING_HTTP;
     801           7 :                                                 } else if (!strncmp((char*)trav2->ns->href, WSDL_HTTP12_NAMESPACE, sizeof(WSDL_HTTP12_NAMESPACE))) {
     802           0 :                                                         address = trav2;
     803           0 :                                                         tmpbinding->bindingType = BINDING_HTTP;
     804             :                                                 }
     805             :                                         }
     806         939 :                                         if (trav2 != address && is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) {
     807           0 :                                                 soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name);
     808             :                                         }
     809         939 :                                   trav2 = trav2->next;
     810             :                                 }
     811         902 :                                 if (!address || tmpbinding->bindingType == BINDING_HTTP) {
     812           9 :                                         if (has_soap_port || trav->next || i < n-1) {
     813           8 :                                                 efree(tmpbinding);
     814           8 :                                                 trav = trav->next;
     815           8 :                                                 continue;
     816           1 :                                         } else if (!address) {
     817           0 :                                                 soap_error0(E_ERROR, "Parsing WSDL: No address associated with <port>");
     818             :                                         }
     819             :                                 }
     820         894 :                                 has_soap_port = 1;
     821             : 
     822         894 :                                 location = get_attribute(address->properties, "location");
     823         894 :                                 if (!location) {
     824           0 :                                         soap_error0(E_ERROR, "Parsing WSDL: No location associated with <port>");
     825             :                                 }
     826             : 
     827         894 :                                 tmpbinding->location = estrdup((char*)location->children->content);
     828             : 
     829         894 :                                 ctype = strrchr((char*)bindingAttr->children->content,':');
     830         894 :                                 if (ctype == NULL) {
     831           1 :                                         ctype = (char*)bindingAttr->children->content;
     832             :                                 } else {
     833         893 :                                         ++ctype;
     834             :                                 }
     835        1788 :                                 if ((tmp = zend_hash_str_find_ptr(&ctx.bindings, ctype, strlen(ctype))) == NULL) {
     836           0 :                                         soap_error1(E_ERROR, "Parsing WSDL: No <binding> element with name '%s'", ctype);
     837             :                                 }
     838         894 :                                 binding = tmp;
     839             : 
     840         894 :                                 if (tmpbinding->bindingType == BINDING_SOAP) {
     841             :                                         sdlSoapBindingPtr soapBinding;
     842             :                                         xmlNodePtr soapBindingNode;
     843             :                                         xmlAttrPtr tmp;
     844             : 
     845         893 :                                         soapBinding = emalloc(sizeof(sdlSoapBinding));
     846         893 :                                         memset(soapBinding, 0, sizeof(sdlSoapBinding));
     847         893 :                                         soapBinding->style = SOAP_DOCUMENT;
     848             : 
     849         893 :                                         soapBindingNode = get_node_ex(binding->children, "binding", wsdl_soap_namespace);
     850         893 :                                         if (soapBindingNode) {
     851         892 :                                                 tmp = get_attribute(soapBindingNode->properties, "style");
     852         892 :                                                 if (tmp && !strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) {
     853         508 :                                                         soapBinding->style = SOAP_RPC;
     854             :                                                 }
     855             : 
     856         892 :                                                 tmp = get_attribute(soapBindingNode->properties, "transport");
     857         892 :                                                 if (tmp) {
     858         892 :                                                         if (strncmp((char*)tmp->children->content, WSDL_HTTP_TRANSPORT, sizeof(WSDL_HTTP_TRANSPORT)) == 0) {
     859         860 :                                                                 soapBinding->transport = SOAP_TRANSPORT_HTTP;
     860             :                                                         } else {
     861             :                                                                 /* try the next binding */
     862          32 :                                                                 efree(soapBinding);
     863          32 :                                                                 efree(tmpbinding->location);
     864          32 :                                                                 efree(tmpbinding);
     865          32 :                                                                 trav = trav->next;
     866          32 :                                                                 continue;
     867             :                                                         }
     868             :                                                 }
     869             :                                         }
     870         861 :                                         tmpbinding->bindingAttributes = (void *)soapBinding;
     871             :                                 }
     872             : 
     873         862 :                                 name = get_attribute(binding->properties, "name");
     874         862 :                                 if (name == NULL) {
     875           0 :                                         soap_error0(E_ERROR, "Parsing WSDL: Missing 'name' attribute for <binding>");
     876             :                                 }
     877         862 :                                 tmpbinding->name = estrdup((char*)name->children->content);
     878             : 
     879         862 :                                 type = get_attribute(binding->properties, "type");
     880         862 :                                 if (type == NULL) {
     881           0 :                                         soap_error0(E_ERROR, "Parsing WSDL: Missing 'type' attribute for <binding>");
     882             :                                 }
     883             : 
     884         862 :                                 ctype = strrchr((char*)type->children->content,':');
     885         862 :                                 if (ctype == NULL) {
     886         176 :                                         ctype = (char*)type->children->content;
     887             :                                 } else {
     888         686 :                                         ++ctype;
     889             :                                 }
     890        1724 :                                 if ((tmp = zend_hash_str_find_ptr(&ctx.portTypes, ctype, strlen(ctype))) == NULL) {
     891           0 :                                         soap_error1(E_ERROR, "Parsing WSDL: Missing <portType> with name '%s'", name->children->content);
     892             :                                 }
     893         862 :                                 portType = tmp;
     894             : 
     895         862 :                                 trav2 = binding->children;
     896       10195 :                                 while (trav2 != NULL) {
     897             :                                         sdlFunctionPtr function;
     898             :                                         xmlNodePtr input, output, fault, portTypeOperation, trav3;
     899             :                                         xmlAttrPtr op_name, paramOrder;
     900             : 
     901       32155 :                                         if ((tmpbinding->bindingType == BINDING_SOAP &&
     902        8470 :                                             node_is_equal_ex(trav2, "binding", wsdl_soap_namespace)) ||
     903        7611 :                                             !is_wsdl_element(trav2) ||
     904        7603 :                                             node_is_equal(trav2,"documentation")) {
     905         868 :                                                 trav2 = trav2->next;
     906         868 :                                                 continue;
     907             :                                         }
     908        7603 :                                         if (!node_is_equal(trav2,"operation")) {
     909           0 :                                                 soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name);
     910             :                                         }
     911             : 
     912        7603 :                                         operation = trav2;
     913             : 
     914        7603 :                                         op_name = get_attribute(operation->properties, "name");
     915        7603 :                                         if (op_name == NULL) {
     916           0 :                                                 soap_error0(E_ERROR, "Parsing WSDL: Missing 'name' attribute for <operation>");
     917             :                                         }
     918             : 
     919        7603 :                                         trav3 = operation->children;
     920       38982 :                                         while  (trav3 != NULL) {
     921       47549 :                                                 if (tmpbinding->bindingType == BINDING_SOAP &&
     922       23773 :                                                     node_is_equal_ex(trav3, "operation", wsdl_soap_namespace)) {
     923       42016 :                                                 } else if (is_wsdl_element(trav3) &&
     924       16134 :                                                            !node_is_equal(trav3,"input") &&
     925        8531 :                                                            !node_is_equal(trav3,"output") &&
     926        1176 :                                                            !node_is_equal(trav3,"fault") &&
     927           0 :                                                            !node_is_equal(trav3,"documentation")) {
     928           0 :                                                         soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav3->name);
     929             :                                                 }
     930       23776 :                                                 trav3 = trav3->next;
     931             :                                         }
     932             : 
     933        7603 :                                         portTypeOperation = get_node_with_attribute_ex(portType->children, "operation", WSDL_NAMESPACE, "name", (char*)op_name->children->content, NULL);
     934        7603 :                                         if (portTypeOperation == NULL) {
     935           0 :                                                 soap_error1(E_ERROR, "Parsing WSDL: Missing <portType>/<operation> with name '%s'", op_name->children->content);
     936             :                                         }
     937             : 
     938        7603 :                                         function = emalloc(sizeof(sdlFunction));
     939        7603 :                                         memset(function, 0, sizeof(sdlFunction));
     940        7603 :                                         function->functionName = estrdup((char*)op_name->children->content);
     941             : 
     942        7603 :                                         if (tmpbinding->bindingType == BINDING_SOAP) {
     943             :                                                 sdlSoapBindingFunctionPtr soapFunctionBinding;
     944             :                                                 sdlSoapBindingPtr soapBinding;
     945             :                                                 xmlNodePtr soapOperation;
     946             :                                                 xmlAttrPtr tmp;
     947             : 
     948        7602 :                                                 soapFunctionBinding = emalloc(sizeof(sdlSoapBindingFunction));
     949        7602 :                                                 memset(soapFunctionBinding, 0, sizeof(sdlSoapBindingFunction));
     950        7602 :                                                 soapBinding = (sdlSoapBindingPtr)tmpbinding->bindingAttributes;
     951        7602 :                                                 soapFunctionBinding->style = soapBinding->style;
     952             : 
     953        7602 :                                                 soapOperation = get_node_ex(operation->children, "operation", wsdl_soap_namespace);
     954        7602 :                                                 if (soapOperation) {
     955        7601 :                                                         tmp = get_attribute(soapOperation->properties, "soapAction");
     956        7601 :                                                         if (tmp) {
     957        5919 :                                                                 soapFunctionBinding->soapAction = estrdup((char*)tmp->children->content);
     958             :                                                         }
     959             : 
     960        7601 :                                                         tmp = get_attribute(soapOperation->properties, "style");
     961        7601 :                                                         if (tmp) {
     962        5049 :                                                                 if (!strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) {
     963        1596 :                                                                         soapFunctionBinding->style = SOAP_RPC;
     964             :                                                                 } else {
     965        3453 :                                                                         soapFunctionBinding->style = SOAP_DOCUMENT;
     966             :                                                                 }
     967             :                                                         } else {
     968        2552 :                                                                 soapFunctionBinding->style = soapBinding->style;
     969             :                                                         }
     970             :                                                 }
     971             : 
     972        7602 :                                                 function->bindingAttributes = (void *)soapFunctionBinding;
     973             :                                         }
     974             : 
     975        7603 :                                         input = get_node_ex(portTypeOperation->children, "input", WSDL_NAMESPACE);
     976        7603 :                                         if (input != NULL) {
     977             :                                                 xmlAttrPtr message;
     978             : 
     979        7603 :                                                 message = get_attribute(input->properties, "message");
     980        7603 :                                                 if (message == NULL) {
     981           0 :                                                         soap_error1(E_ERROR, "Parsing WSDL: Missing name for <input> of '%s'", op_name->children->content);
     982             :                                                 }
     983        7603 :                                                 function->requestParameters = wsdl_message(&ctx, message->children->content);
     984             : 
     985             : /* FIXME
     986             :                                                 xmlAttrPtr name = get_attribute(input->properties, "name");
     987             :                                                 if (name != NULL) {
     988             :                                                         function->requestName = estrdup(name->children->content);
     989             :                                                 } else {
     990             : */
     991             :                                                 {
     992        7603 :                                                         function->requestName = estrdup(function->functionName);
     993             :                                                 }
     994             : 
     995        7603 :                                                 if (tmpbinding->bindingType == BINDING_SOAP) {
     996        7602 :                                                         input = get_node_ex(operation->children, "input", WSDL_NAMESPACE);
     997        7602 :                                                         if (input != NULL) {
     998        7602 :                                                                 sdlSoapBindingFunctionPtr soapFunctionBinding = function->bindingAttributes;
     999        7602 :                                                                 wsdl_soap_binding_body(&ctx, input, wsdl_soap_namespace, &soapFunctionBinding->input, function->requestParameters);
    1000             :                                                         }
    1001             :                                                 }
    1002             :                                         }
    1003             : 
    1004        7603 :                                         output = get_node_ex(portTypeOperation->children, "output", WSDL_NAMESPACE);
    1005        7603 :                                         if (output != NULL) {
    1006             :                                                 xmlAttrPtr message;
    1007             : 
    1008        7355 :                                                 message = get_attribute(output->properties, "message");
    1009        7355 :                                                 if (message == NULL) {
    1010           0 :                                                         soap_error1(E_ERROR, "Parsing WSDL: Missing name for <output> of '%s'", op_name->children->content);
    1011             :                                                 }
    1012        7355 :                                                 function->responseParameters = wsdl_message(&ctx, message->children->content);
    1013             : 
    1014             : /* FIXME
    1015             :                                                 xmlAttrPtr name = get_attribute(output->properties, "name");
    1016             :                                                 if (name != NULL) {
    1017             :                                                         function->responseName = estrdup(name->children->content);
    1018             :                                                 } else if (input == NULL) {
    1019             :                                                         function->responseName = estrdup(function->functionName);
    1020             :                                                 } else {
    1021             : */
    1022             :                                                 {
    1023        7355 :                                                         int len = strlen(function->functionName);
    1024        7355 :                                                         function->responseName = emalloc(len + sizeof("Response"));
    1025        7355 :                                                         memcpy(function->responseName, function->functionName, len);
    1026        7355 :                                                         memcpy(function->responseName+len, "Response", sizeof("Response"));
    1027             :                                                 }
    1028             : 
    1029        7355 :                                                 if (tmpbinding->bindingType == BINDING_SOAP) {
    1030        7354 :                                                         output = get_node_ex(operation->children, "output", WSDL_NAMESPACE);
    1031        7354 :                                                         if (output != NULL) {
    1032        7354 :                                                                 sdlSoapBindingFunctionPtr soapFunctionBinding = function->bindingAttributes;
    1033        7354 :                                                                 wsdl_soap_binding_body(&ctx, output, wsdl_soap_namespace, &soapFunctionBinding->output, function->responseParameters);
    1034             :                                                         }
    1035             :                                                 }
    1036             :                                         }
    1037             : 
    1038        7603 :                                         paramOrder = get_attribute(portTypeOperation->properties, "parameterOrder");
    1039             :                                         if (paramOrder) {
    1040             :                                                 /* FIXME: */
    1041             :                                         }
    1042             : 
    1043        7603 :                                         fault = portTypeOperation->children;
    1044       31386 :                                         while (fault != NULL) {
    1045       16180 :                                                 if (node_is_equal_ex(fault, "fault", WSDL_NAMESPACE)) {
    1046             :                                                         xmlAttrPtr message, name;
    1047             :                                                         sdlFaultPtr f;
    1048             : 
    1049        1210 :                                                         name = get_attribute(fault->properties, "name");
    1050        1210 :                                                         if (name == NULL) {
    1051           0 :                                                                 soap_error1(E_ERROR, "Parsing WSDL: Missing name for <fault> of '%s'", op_name->children->content);
    1052             :                                                         }
    1053        1210 :                                                         message = get_attribute(fault->properties, "message");
    1054        1210 :                                                         if (message == NULL) {
    1055           0 :                                                                 soap_error1(E_ERROR, "Parsing WSDL: Missing name for <output> of '%s'", op_name->children->content);
    1056             :                                                         }
    1057             : 
    1058        1210 :                                                         f = emalloc(sizeof(sdlFault));
    1059        1210 :                                                         memset(f, 0, sizeof(sdlFault));
    1060             : 
    1061        1210 :                                                         f->name = estrdup((char*)name->children->content);
    1062        1210 :                                                         f->details = wsdl_message(&ctx, message->children->content);
    1063        1210 :                                                         if (f->details == NULL || zend_hash_num_elements(f->details) > 1) {
    1064           0 :                                                                 soap_error1(E_ERROR, "Parsing WSDL: The fault message '%s' must have a single part", message->children->content);
    1065             :                                                         }
    1066             : 
    1067        1210 :                                                         if (tmpbinding->bindingType == BINDING_SOAP) {
    1068        1210 :                                                                 xmlNodePtr soap_fault = get_node_with_attribute_ex(operation->children, "fault", WSDL_NAMESPACE, "name", f->name, NULL);
    1069        1210 :                                                                 if (soap_fault != NULL) {
    1070        1176 :                                                                         xmlNodePtr trav = soap_fault->children;
    1071        3528 :                                                                         while (trav != NULL) {
    1072        1176 :                                                                                 if (node_is_equal_ex(trav, "fault", wsdl_soap_namespace)) {
    1073             :                                                                                         xmlAttrPtr tmp;
    1074             :                                                                                   sdlSoapBindingFunctionFaultPtr binding;
    1075             : 
    1076        1176 :                                                                                         binding = f->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunctionFault));
    1077        1176 :                                                                                         memset(f->bindingAttributes, 0, sizeof(sdlSoapBindingFunctionFault));
    1078             : 
    1079        1176 :                                                                                         tmp = get_attribute(trav->properties, "use");
    1080        1784 :                                                                                         if (tmp && !strncmp((char*)tmp->children->content, "encoded", sizeof("encoded"))) {
    1081         608 :                                                                                                 binding->use = SOAP_ENCODED;
    1082             :                                                                                         } else {
    1083         568 :                                                                                                 binding->use = SOAP_LITERAL;
    1084             :                                                                                         }
    1085             : 
    1086        1176 :                                                                                         tmp = get_attribute(trav->properties, "namespace");
    1087        1176 :                                                                                         if (tmp) {
    1088         608 :                                                                                                 binding->ns = estrdup((char*)tmp->children->content);
    1089             :                                                                                         }
    1090             : 
    1091        1176 :                                                                                         if (binding->use == SOAP_ENCODED) {
    1092         608 :                                                                                                 tmp = get_attribute(trav->properties, "encodingStyle");
    1093         608 :                                                                                                 if (tmp) {
    1094         608 :                                                                                                         if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) {
    1095         608 :                                                                                                                 binding->encodingStyle = SOAP_ENCODING_1_1;
    1096           0 :                                                                                                         } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) {
    1097           0 :                                                                                                                 binding->encodingStyle = SOAP_ENCODING_1_2;
    1098             :                                                                                                         } else {
    1099           0 :                                                                                                                 soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content);
    1100             :                                                                                                         }
    1101             :                                                                                                 } else {
    1102           0 :                                                                                                         soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle");
    1103             :                                                                                                 }
    1104             :                                                                                         }
    1105           0 :                                                                                 } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) {
    1106           0 :                                                                                         soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
    1107             :                                                                                 }
    1108        1176 :                                                                                 trav = trav->next;
    1109             :                                                                         }
    1110             :                                                                 }
    1111             :                                                         }
    1112        1210 :                                                         if (function->faults == NULL) {
    1113         682 :                                                                 function->faults = emalloc(sizeof(HashTable));
    1114         682 :                                                                 zend_hash_init(function->faults, 0, NULL, delete_fault, 0);
    1115             :                                                         }
    1116        2420 :                                                         if (zend_hash_str_add_ptr(function->faults, f->name, strlen(f->name), f) == NULL) {
    1117           0 :                                                                 soap_error2(E_ERROR, "Parsing WSDL: <fault> with name '%s' already defined in '%s'", f->name, op_name->children->content);
    1118             :                                                         }
    1119             :                                                 }
    1120       16180 :                                                 fault = fault->next;
    1121             :                                         }
    1122             : 
    1123        7603 :                                         function->binding = tmpbinding;
    1124             : 
    1125             :                                         {
    1126        7603 :                                                 char *tmp = estrdup(function->functionName);
    1127        7603 :                                                 int  len = strlen(tmp);
    1128             : 
    1129       15206 :                                                 if (zend_hash_str_add_ptr(&ctx.sdl->functions, php_strtolower(tmp, len), len, function) == NULL) {
    1130        1674 :                                                         zend_hash_next_index_insert_ptr(&ctx.sdl->functions, function);
    1131             :                                                 }
    1132        7603 :                                                 efree(tmp);
    1133        7603 :                                                 if (function->requestName != NULL && strcmp(function->requestName,function->functionName) != 0) {
    1134           0 :                                                         if (ctx.sdl->requests == NULL) {
    1135           0 :                                                                 ctx.sdl->requests = emalloc(sizeof(HashTable));
    1136           0 :                                                                 zend_hash_init(ctx.sdl->requests, 0, NULL, NULL, 0);
    1137             :                                                         }
    1138           0 :                                                         tmp = estrdup(function->requestName);
    1139           0 :                                                         len = strlen(tmp);
    1140           0 :                                                         zend_hash_str_add_ptr(ctx.sdl->requests, php_strtolower(tmp, len), len, function);
    1141           0 :                                                         efree(tmp);
    1142             :                                                 }
    1143             :                                         }
    1144        7603 :                                         trav2 = trav2->next;
    1145             :                                 }
    1146             : 
    1147         861 :                                 if (!ctx.sdl->bindings) {
    1148         705 :                                         ctx.sdl->bindings = emalloc(sizeof(HashTable));
    1149         705 :                                         zend_hash_init(ctx.sdl->bindings, 0, NULL, delete_binding, 0);
    1150             :                                 }
    1151             : 
    1152        1722 :                                 if (!zend_hash_str_add_ptr(ctx.sdl->bindings, tmpbinding->name, strlen(tmpbinding->name), tmpbinding)) {
    1153           0 :                                         zend_hash_next_index_insert_ptr(ctx.sdl->bindings, tmpbinding);
    1154             :                                 }
    1155         861 :                                 trav= trav->next;
    1156             :                         }
    1157             : 
    1158         740 :                         zend_hash_move_forward(&ctx.services);
    1159             :                 }
    1160             :         } else {
    1161           0 :                 soap_error0(E_ERROR, "Parsing WSDL: Couldn't bind to service");
    1162             :         }
    1163             : 
    1164         707 :         if (ctx.sdl->bindings == NULL || ctx.sdl->bindings->nNumOfElements == 0) {
    1165           2 :                 soap_error0(E_ERROR, "Parsing WSDL: Could not find any usable binding services in WSDL.");
    1166             :         }
    1167             : 
    1168         705 :         zend_hash_destroy(&ctx.messages);
    1169         705 :         zend_hash_destroy(&ctx.bindings);
    1170         705 :         zend_hash_destroy(&ctx.portTypes);
    1171         705 :         zend_hash_destroy(&ctx.services);
    1172         705 :         zend_hash_destroy(&ctx.docs);
    1173             : 
    1174         705 :         return ctx.sdl;
    1175             : }
    1176             : 
    1177             : #define WSDL_CACHE_VERSION 0x0e
    1178             : 
    1179             : #define WSDL_CACHE_GET(ret,type,buf)   memcpy(&ret,*buf,sizeof(type)); *buf += sizeof(type);
    1180             : #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;
    1181             : #define WSDL_CACHE_GET_1(ret,type,buf) ret = (type)(**buf); (*buf)++;
    1182             : #define WSDL_CACHE_GET_N(ret,n,buf)    memcpy(ret,*buf,n); *buf += n;
    1183             : #define WSDL_CACHE_SKIP(n,buf)         *buf += n;
    1184             : 
    1185             : #define WSDL_CACHE_PUT_INT(val,buf)    smart_str_appendc(buf,val & 0xff); \
    1186             :                                        smart_str_appendc(buf,(val >> 8) & 0xff); \
    1187             :                                        smart_str_appendc(buf,(val >> 16) & 0xff); \
    1188             :                                        smart_str_appendc(buf,(val >> 24) & 0xff);
    1189             : #define WSDL_CACHE_PUT_1(val,buf)      smart_str_appendc(buf,val);
    1190             : #define WSDL_CACHE_PUT_N(val,n,buf)    smart_str_appendl(buf,(char*)val,n);
    1191             : 
    1192          90 : static char* sdl_deserialize_string(char **in)
    1193             : {
    1194             :         char *s;
    1195             :         int len;
    1196             : 
    1197          90 :         WSDL_CACHE_GET_INT(len, in);
    1198          90 :         if (len == 0x7fffffff) {
    1199          29 :                 return NULL;
    1200             :         } else {
    1201          61 :                 s = emalloc(len+1);
    1202          61 :                 WSDL_CACHE_GET_N(s, len, in);
    1203          61 :                 s[len] = '\0';
    1204          61 :                 return s;
    1205             :         }
    1206             : }
    1207             : 
    1208          27 : static void sdl_deserialize_key(HashTable* ht, void* data, char **in)
    1209             : {
    1210             :         int len;
    1211             : 
    1212          27 :         WSDL_CACHE_GET_INT(len, in);
    1213          27 :         if (len == 0) {
    1214             :                 zend_hash_next_index_insert_ptr(ht, data);
    1215             :         } else {
    1216          17 :                 zend_hash_str_add_ptr(ht, *in, len, data);
    1217          17 :                 WSDL_CACHE_SKIP(len, in);
    1218             :         }
    1219          27 : }
    1220             : 
    1221           0 : static void sdl_deserialize_attribute(sdlAttributePtr attr, encodePtr *encoders, char **in)
    1222             : {
    1223             :         int i;
    1224             : 
    1225           0 :         attr->name = sdl_deserialize_string(in);
    1226           0 :         attr->namens = sdl_deserialize_string(in);
    1227           0 :         attr->ref = sdl_deserialize_string(in);
    1228           0 :         attr->def = sdl_deserialize_string(in);
    1229           0 :         attr->fixed = sdl_deserialize_string(in);
    1230           0 :         WSDL_CACHE_GET_1(attr->form, sdlForm, in);
    1231           0 :         WSDL_CACHE_GET_1(attr->use, sdlUse, in);
    1232           0 :         WSDL_CACHE_GET_INT(i, in);
    1233           0 :         attr->encode = encoders[i];
    1234           0 :         WSDL_CACHE_GET_INT(i, in);
    1235           0 :         if (i > 0) {
    1236           0 :                 attr->extraAttributes = emalloc(sizeof(HashTable));
    1237           0 :                 zend_hash_init(attr->extraAttributes, i, NULL, delete_extra_attribute, 0);
    1238           0 :                 while (i > 0) {
    1239           0 :                         sdlExtraAttributePtr x = emalloc(sizeof(sdlExtraAttribute));
    1240           0 :                         sdl_deserialize_key(attr->extraAttributes, x, in);
    1241           0 :                         x->ns = sdl_deserialize_string(in);
    1242           0 :                         x->val = sdl_deserialize_string(in);
    1243           0 :                         --i;
    1244             :                 }
    1245             :         }
    1246           0 : }
    1247             : 
    1248           0 : static sdlRestrictionIntPtr sdl_deserialize_resriction_int(char **in)
    1249             : {
    1250           0 :         if (**in == 1) {
    1251           0 :                 sdlRestrictionIntPtr x = emalloc(sizeof(sdlRestrictionInt));
    1252           0 :                 WSDL_CACHE_SKIP(1, in);
    1253           0 :                 WSDL_CACHE_GET_INT(x->value, in);
    1254           0 :                 WSDL_CACHE_GET_1(x->fixed, char, in);
    1255           0 :                 return x;
    1256             :         } else {
    1257           0 :                 WSDL_CACHE_SKIP(1, in);
    1258           0 :                 return NULL;
    1259             :         }
    1260             : }
    1261             : 
    1262           0 : static sdlRestrictionCharPtr sdl_deserialize_resriction_char(char **in)
    1263             : {
    1264           0 :         if (**in == 1) {
    1265           0 :                 sdlRestrictionCharPtr x = emalloc(sizeof(sdlRestrictionChar));
    1266           0 :                 WSDL_CACHE_SKIP(1, in);
    1267           0 :                 x->value = sdl_deserialize_string(in);
    1268           0 :                 WSDL_CACHE_GET_1(x->fixed, char, in);
    1269           0 :                 return x;
    1270             :         } else {
    1271           0 :                 WSDL_CACHE_SKIP(1, in);
    1272           0 :                 return NULL;
    1273             :         }
    1274             : }
    1275             : 
    1276           9 : static sdlContentModelPtr sdl_deserialize_model(sdlTypePtr *types, sdlTypePtr *elements, char **in)
    1277             : {
    1278             :         int i;
    1279           9 :         sdlContentModelPtr model = emalloc(sizeof(sdlContentModel));
    1280             : 
    1281           9 :         WSDL_CACHE_GET_1(model->kind, sdlContentKind, in);
    1282           9 :         WSDL_CACHE_GET_INT(model->min_occurs, in);
    1283           9 :         WSDL_CACHE_GET_INT(model->max_occurs, in);
    1284           9 :         switch (model->kind) {
    1285             :                 case XSD_CONTENT_ELEMENT:
    1286           6 :                         WSDL_CACHE_GET_INT(i, in);
    1287           6 :                         model->u.element = elements[i];
    1288           6 :                         break;
    1289             :                 case XSD_CONTENT_SEQUENCE:
    1290             :                 case XSD_CONTENT_ALL:
    1291             :                 case XSD_CONTENT_CHOICE:
    1292           3 :                         WSDL_CACHE_GET_INT(i, in);
    1293           3 :                         model->u.content = emalloc(sizeof(HashTable));
    1294           3 :                         zend_hash_init(model->u.content, i, NULL, delete_model, 0);
    1295          12 :                         while (i > 0) {
    1296           6 :                                 sdlContentModelPtr x = sdl_deserialize_model(types, elements, in);
    1297           6 :                                 zend_hash_next_index_insert_ptr(model->u.content, x);
    1298           6 :                                 i--;
    1299             :                         }
    1300           3 :                         break;
    1301             :                 case XSD_CONTENT_GROUP_REF:
    1302           0 :                         model->u.group_ref = sdl_deserialize_string(in);
    1303           0 :                         break;
    1304             :                 case XSD_CONTENT_GROUP:
    1305           0 :                         WSDL_CACHE_GET_INT(i, in);
    1306           0 :                         model->u.group = types[i];
    1307             :                         break;
    1308             :                 default:
    1309             :                         break;
    1310             :         }
    1311           9 :         return model;
    1312             : }
    1313             : 
    1314           9 : static void sdl_deserialize_type(sdlTypePtr type, sdlTypePtr *types, encodePtr *encoders, char **in)
    1315             : {
    1316             :         int i;
    1317           9 :         sdlTypePtr *elements = NULL;
    1318             : 
    1319           9 :         WSDL_CACHE_GET_1(type->kind, sdlTypeKind, in);
    1320           9 :         type->name = sdl_deserialize_string(in);
    1321           9 :         type->namens = sdl_deserialize_string(in);
    1322           9 :         type->def = sdl_deserialize_string(in);
    1323           9 :         type->fixed = sdl_deserialize_string(in);
    1324           9 :         type->ref = sdl_deserialize_string(in);
    1325           9 :         WSDL_CACHE_GET_1(type->nillable, char, in);
    1326           9 :         WSDL_CACHE_GET_1(type->form, sdlForm, in);
    1327             : 
    1328           9 :         WSDL_CACHE_GET_INT(i, in);
    1329           9 :         type->encode = encoders[i];
    1330             : 
    1331           9 :         if (**in == 1) {
    1332           0 :                 WSDL_CACHE_SKIP(1, in);
    1333           0 :                 type->restrictions = emalloc(sizeof(sdlRestrictions));
    1334             :                 /*memset(type->restrictions, 0, sizeof(sdlRestrictions));*/
    1335           0 :                 type->restrictions->minExclusive = sdl_deserialize_resriction_int(in);
    1336           0 :                 type->restrictions->minInclusive = sdl_deserialize_resriction_int(in);
    1337           0 :                 type->restrictions->maxExclusive = sdl_deserialize_resriction_int(in);
    1338           0 :                 type->restrictions->maxInclusive = sdl_deserialize_resriction_int(in);
    1339           0 :                 type->restrictions->totalDigits = sdl_deserialize_resriction_int(in);
    1340           0 :                 type->restrictions->fractionDigits = sdl_deserialize_resriction_int(in);
    1341           0 :                 type->restrictions->length = sdl_deserialize_resriction_int(in);
    1342           0 :                 type->restrictions->minLength = sdl_deserialize_resriction_int(in);
    1343           0 :                 type->restrictions->maxLength = sdl_deserialize_resriction_int(in);
    1344           0 :                 type->restrictions->whiteSpace = sdl_deserialize_resriction_char(in);
    1345           0 :                 type->restrictions->pattern = sdl_deserialize_resriction_char(in);
    1346           0 :                 WSDL_CACHE_GET_INT(i, in);
    1347           0 :                 if (i > 0) {
    1348           0 :                         type->restrictions->enumeration = emalloc(sizeof(HashTable));
    1349           0 :                         zend_hash_init(type->restrictions->enumeration, i, NULL, delete_restriction_var_char, 0);
    1350           0 :                         while (i > 0) {
    1351           0 :                                 sdlRestrictionCharPtr x = sdl_deserialize_resriction_char(in);
    1352           0 :                                 sdl_deserialize_key(type->restrictions->enumeration, x, in);
    1353           0 :                                 --i;
    1354             :                         }
    1355             :                 } else {
    1356           0 :                         type->restrictions->enumeration = NULL;
    1357             :                 }
    1358             :         } else {
    1359           9 :                 WSDL_CACHE_SKIP(1, in);
    1360             :         }
    1361             : 
    1362           9 :         WSDL_CACHE_GET_INT(i, in);
    1363           9 :         if (i > 0) {
    1364           3 :                 elements = safe_emalloc((i+1), sizeof(sdlTypePtr), 0);
    1365           3 :                 elements[0] = NULL;
    1366           3 :                 type->elements = emalloc(sizeof(HashTable));
    1367           3 :                 zend_hash_init(type->elements, i, NULL, delete_type, 0);
    1368          12 :                 while (i > 0) {
    1369           6 :                         sdlTypePtr t = emalloc(sizeof(sdlType));
    1370           6 :                         memset(t, 0, sizeof(sdlType));
    1371           6 :                         sdl_deserialize_key(type->elements, t, in);
    1372           6 :                         sdl_deserialize_type(t, types, encoders, in);
    1373           6 :                         elements[i] = t;
    1374           6 :                         --i;
    1375             :                 }
    1376             :         }
    1377             : 
    1378           9 :         WSDL_CACHE_GET_INT(i, in);
    1379           9 :         if (i > 0) {
    1380           0 :                 type->attributes = emalloc(sizeof(HashTable));
    1381           0 :                 zend_hash_init(type->attributes, i, NULL, delete_attribute, 0);
    1382           0 :                 while (i > 0) {
    1383           0 :                         sdlAttributePtr attr = emalloc(sizeof(sdlAttribute));
    1384           0 :                         memset(attr, 0, sizeof(sdlAttribute));
    1385           0 :                         sdl_deserialize_key(type->attributes, attr, in);
    1386           0 :                         sdl_deserialize_attribute(attr, encoders, in);
    1387           0 :                         --i;
    1388             :                 }
    1389             :         }
    1390             : 
    1391           9 :         if (**in != 0) {
    1392           3 :                 WSDL_CACHE_SKIP(1, in);
    1393           3 :                 type->model = sdl_deserialize_model(types, elements, in);
    1394             :         } else {
    1395           6 :                 WSDL_CACHE_SKIP(1, in);
    1396             :         }
    1397           9 :         if (elements != NULL) {
    1398           3 :                 efree(elements);
    1399             :         }
    1400           9 : }
    1401             : 
    1402           4 : static void sdl_deserialize_encoder(encodePtr enc, sdlTypePtr *types, char **in)
    1403             : {
    1404             :         int i;
    1405             : 
    1406           4 :         WSDL_CACHE_GET_INT(enc->details.type, in);
    1407           4 :         enc->details.type_str = sdl_deserialize_string(in);
    1408           4 :         enc->details.ns = sdl_deserialize_string(in);
    1409           4 :         WSDL_CACHE_GET_INT(i, in);
    1410           4 :         enc->details.sdl_type = types[i];
    1411           4 :         enc->to_xml = sdl_guess_convert_xml;
    1412           4 :         enc->to_zval = sdl_guess_convert_zval;
    1413             : 
    1414           4 :         if (enc->details.sdl_type == NULL) {
    1415           1 :                 int ns_len = strlen(enc->details.ns);
    1416           1 :                 int type_len = strlen(enc->details.type_str);
    1417             : 
    1418           2 :                 if (((ns_len == sizeof(SOAP_1_1_ENC_NAMESPACE)-1 &&
    1419           1 :                       memcmp(enc->details.ns, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1) == 0) ||
    1420             :                      (ns_len == sizeof(SOAP_1_2_ENC_NAMESPACE)-1 &&
    1421           0 :                       memcmp(enc->details.ns, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1) == 0))) {
    1422             :                         char *enc_nscat;
    1423             :                         int enc_ns_len;
    1424             :                         int enc_len;
    1425             :                         encodePtr real_enc;
    1426             : 
    1427           1 :                         enc_ns_len = sizeof(XSD_NAMESPACE)-1;
    1428           1 :                         enc_len = enc_ns_len + type_len + 1;
    1429           1 :                         enc_nscat = emalloc(enc_len + 1);
    1430           1 :                         memcpy(enc_nscat, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1);
    1431           1 :                         enc_nscat[enc_ns_len] = ':';
    1432           1 :                         memcpy(enc_nscat+enc_ns_len+1, enc->details.type_str, type_len);
    1433           1 :                         enc_nscat[enc_len] = '\0';
    1434             : 
    1435           1 :                         real_enc = get_encoder_ex(NULL, enc_nscat, enc_len);
    1436           1 :                         efree(enc_nscat);
    1437           1 :                         if (real_enc) {
    1438           1 :                                 enc->to_zval = real_enc->to_zval;
    1439           1 :                                 enc->to_xml = real_enc->to_xml;
    1440             :                         }
    1441             :                 }
    1442             :         }
    1443           4 : }
    1444             : 
    1445           6 : static void sdl_deserialize_soap_body(sdlSoapBindingFunctionBodyPtr body, encodePtr *encoders, sdlTypePtr *types, char **in)
    1446             : {
    1447             :         int i, j, n;
    1448             : 
    1449           6 :         WSDL_CACHE_GET_1(body->use, sdlEncodingUse, in);
    1450           6 :         if (body->use == SOAP_ENCODED) {
    1451           4 :                 WSDL_CACHE_GET_1(body->encodingStyle, sdlRpcEncodingStyle, in);
    1452             :         } else {
    1453           2 :                 body->encodingStyle = SOAP_ENCODING_DEFAULT;
    1454             :         }
    1455           6 :         body->ns = sdl_deserialize_string(in);
    1456           6 :         WSDL_CACHE_GET_INT(i, in);
    1457           6 :         if (i > 0) {
    1458           0 :                 body->headers = emalloc(sizeof(HashTable));
    1459           0 :                 zend_hash_init(body->headers, i, NULL, delete_header, 0);
    1460           0 :                 while (i > 0) {
    1461           0 :                         sdlSoapBindingFunctionHeaderPtr tmp = emalloc(sizeof(sdlSoapBindingFunctionHeader));
    1462           0 :                         memset(tmp, 0, sizeof(sdlSoapBindingFunctionHeader));
    1463           0 :                         sdl_deserialize_key(body->headers, tmp, in);
    1464           0 :                         WSDL_CACHE_GET_1(tmp->use, sdlEncodingUse, in);
    1465           0 :                         if (tmp->use == SOAP_ENCODED) {
    1466           0 :                                 WSDL_CACHE_GET_1(tmp->encodingStyle, sdlRpcEncodingStyle, in);
    1467             :                         } else {
    1468           0 :                                 tmp->encodingStyle = SOAP_ENCODING_DEFAULT;
    1469             :                         }
    1470           0 :                         tmp->name = sdl_deserialize_string(in);
    1471           0 :                         tmp->ns = sdl_deserialize_string(in);
    1472           0 :                         WSDL_CACHE_GET_INT(n, in);
    1473           0 :                         tmp->encode = encoders[n];
    1474           0 :                         WSDL_CACHE_GET_INT(n, in);
    1475           0 :                         tmp->element = types[n];
    1476           0 :                         --i;
    1477           0 :                         WSDL_CACHE_GET_INT(j, in);
    1478           0 :                         if (j > 0) {
    1479           0 :                                 tmp->headerfaults = emalloc(sizeof(HashTable));
    1480           0 :                                 zend_hash_init(tmp->headerfaults, i, NULL, delete_header, 0);
    1481           0 :                                 while (j > 0) {
    1482           0 :                                         sdlSoapBindingFunctionHeaderPtr tmp2 = emalloc(sizeof(sdlSoapBindingFunctionHeader));
    1483           0 :                                         memset(tmp2, 0, sizeof(sdlSoapBindingFunctionHeader));
    1484           0 :                                         sdl_deserialize_key(tmp->headerfaults, tmp2, in);
    1485           0 :                                         WSDL_CACHE_GET_1(tmp2->use, sdlEncodingUse, in);
    1486           0 :                                         if (tmp2->use == SOAP_ENCODED) {
    1487           0 :                                                 WSDL_CACHE_GET_1(tmp2->encodingStyle, sdlRpcEncodingStyle, in);
    1488             :                                         } else {
    1489           0 :                                                 tmp2->encodingStyle = SOAP_ENCODING_DEFAULT;
    1490             :                                         }
    1491           0 :                                         tmp2->name = sdl_deserialize_string(in);
    1492           0 :                                         tmp2->ns = sdl_deserialize_string(in);
    1493           0 :                                         WSDL_CACHE_GET_INT(n, in);
    1494           0 :                                         tmp2->encode = encoders[n];
    1495           0 :                                         WSDL_CACHE_GET_INT(n, in);
    1496           0 :                                         tmp2->element = types[n];
    1497           0 :                                         --j;
    1498             :                                 }
    1499             :                         }
    1500             :                 }
    1501             :         }
    1502           6 : }
    1503             : 
    1504           8 : static HashTable* sdl_deserialize_parameters(encodePtr *encoders, sdlTypePtr *types, char **in)
    1505             : {
    1506             :         int i, n;
    1507             :         HashTable *ht;
    1508             : 
    1509           8 :         WSDL_CACHE_GET_INT(i, in);
    1510           8 :         if (i == 0) {return NULL;}
    1511           7 :         ht = emalloc(sizeof(HashTable));
    1512           7 :         zend_hash_init(ht, i, NULL, delete_parameter, 0);
    1513          21 :         while (i > 0) {
    1514           7 :                 sdlParamPtr param = emalloc(sizeof(sdlParam));
    1515           7 :                 sdl_deserialize_key(ht, param, in);
    1516           7 :                 param->paramName = sdl_deserialize_string(in);
    1517           7 :                 WSDL_CACHE_GET_INT(param->order, in);
    1518           7 :                 WSDL_CACHE_GET_INT(n, in);
    1519           7 :                 param->encode = encoders[n];
    1520           7 :                 WSDL_CACHE_GET_INT(n, in);
    1521           7 :                 param->element = types[n];
    1522           7 :                 --i;
    1523             :         }
    1524           7 :         return ht;
    1525             : }
    1526             : 
    1527           8 : static sdlPtr get_sdl_from_cache(const char *fn, const char *uri, time_t t, time_t *cached)
    1528             : {
    1529             :         sdlPtr sdl;
    1530             :         time_t old_t;
    1531             :         int  i, num_groups, num_types, num_elements, num_encoders, num_bindings, num_func;
    1532           8 :         sdlFunctionPtr *functions = NULL;
    1533             :         sdlBindingPtr *bindings;
    1534             :         sdlTypePtr *types;
    1535             :         encodePtr *encoders;
    1536             :         encodePtr enc;
    1537             : 
    1538             :         int f;
    1539             :         struct stat st;
    1540             :         char *in, *buf;
    1541             : 
    1542           8 :         f = open(fn, O_RDONLY|O_BINARY);
    1543           8 :         if (f < 0) {
    1544           1 :                 return NULL;
    1545             :         }
    1546           7 :         if (fstat(f, &st) != 0) {
    1547           0 :                 close(f);
    1548           0 :                 return NULL;
    1549             :         }
    1550           7 :         buf = in = emalloc(st.st_size);
    1551           7 :         if (read(f, in, st.st_size) != st.st_size) {
    1552           0 :                 close(f);
    1553           0 :                 efree(in);
    1554           0 :                 return NULL;
    1555             :         }
    1556           7 :         close(f);
    1557             : 
    1558           7 :         if (strncmp(in,"wsdl",4) != 0 || in[4] != WSDL_CACHE_VERSION || in[5] != '\0') {
    1559           0 :                 unlink(fn);
    1560           0 :                 efree(buf);
    1561           0 :                 return NULL;
    1562             :         }
    1563           7 :         in += 6;
    1564             : 
    1565           7 :         WSDL_CACHE_GET(old_t, time_t, &in);
    1566           7 :         if (old_t < t) {
    1567           5 :                 unlink(fn);
    1568           5 :                 efree(buf);
    1569           5 :                 return NULL;
    1570             :         }
    1571           2 :         *cached = old_t;
    1572             : 
    1573           2 :         WSDL_CACHE_GET_INT(i, &in);
    1574           2 :         if (i == 0 && strncmp(in, uri, i) != 0) {
    1575           0 :                 unlink(fn);
    1576           0 :                 efree(buf);
    1577           0 :                 return NULL;
    1578             :         }
    1579           2 :         WSDL_CACHE_SKIP(i, &in);
    1580             : 
    1581           2 :         sdl = emalloc(sizeof(*sdl));
    1582           2 :         memset(sdl, 0, sizeof(*sdl));
    1583             : 
    1584           2 :         sdl->source = sdl_deserialize_string(&in);
    1585           2 :         sdl->target_ns = sdl_deserialize_string(&in);
    1586             : 
    1587           2 :         WSDL_CACHE_GET_INT(num_groups, &in);
    1588           2 :         WSDL_CACHE_GET_INT(num_types, &in);
    1589           2 :         WSDL_CACHE_GET_INT(num_elements, &in);
    1590           2 :         WSDL_CACHE_GET_INT(num_encoders, &in);
    1591             : 
    1592           2 :         i = num_groups+num_types+num_elements;
    1593           2 :         types = safe_emalloc((i+1), sizeof(sdlTypePtr), 0);
    1594           2 :         types[0] = NULL;
    1595           7 :         while (i > 0) {
    1596           3 :                 types[i] = emalloc(sizeof(sdlType));
    1597           3 :                 memset(types[i], 0, sizeof(sdlType));
    1598           3 :                 i--;
    1599             :         }
    1600             : 
    1601           2 :         i = num_encoders;
    1602           2 :         enc = defaultEncoding;
    1603         152 :         while (enc->details.type != END_KNOWN_TYPES) {
    1604         148 :                 i++; enc++;
    1605             :         }
    1606           2 :         encoders = safe_emalloc((i+1), sizeof(encodePtr), 0);
    1607           2 :         i = num_encoders;
    1608           2 :         encoders[0] = NULL;
    1609           8 :         while (i > 0) {
    1610           4 :                 encoders[i] = emalloc(sizeof(encode));
    1611           4 :                 memset(encoders[i], 0, sizeof(encode));
    1612           4 :                 i--;
    1613             :         }
    1614           2 :         i = num_encoders;
    1615           2 :         enc = defaultEncoding;
    1616         152 :         while (enc->details.type != END_KNOWN_TYPES) {
    1617         148 :                 encoders[++i] = enc++;
    1618             :         }
    1619             : 
    1620           2 :         i = 1;
    1621           2 :         if (num_groups > 0) {
    1622           0 :                 sdl->groups = emalloc(sizeof(HashTable));
    1623           0 :                 zend_hash_init(sdl->groups, num_groups, NULL, delete_type, 0);
    1624           0 :                 while (i < num_groups+1) {
    1625           0 :                         sdl_deserialize_key(sdl->groups, types[i], &in);
    1626           0 :                         sdl_deserialize_type(types[i], types, encoders, &in);
    1627           0 :                         i++;
    1628             :                 }
    1629             :         }
    1630             : 
    1631           2 :         if (num_types > 0) {
    1632           2 :                 sdl->types = emalloc(sizeof(HashTable));
    1633           2 :                 zend_hash_init(sdl->types, num_types, NULL, delete_type, 0);
    1634           7 :                 while (i < num_groups+num_types+1) {
    1635           3 :                         sdl_deserialize_key(sdl->types, types[i], &in);
    1636           3 :                         sdl_deserialize_type(types[i], types, encoders, &in);
    1637           3 :                         i++;
    1638             :                 }
    1639             :         }
    1640             : 
    1641           2 :         if (num_elements > 0) {
    1642           0 :                 sdl->elements = emalloc(sizeof(HashTable));
    1643           0 :                 zend_hash_init(sdl->elements, num_elements, NULL, delete_type, 0);
    1644           0 :                 while (i < num_groups+num_types+num_elements+1) {
    1645           0 :                         sdl_deserialize_key(sdl->elements, types[i], &in);
    1646           0 :                         sdl_deserialize_type(types[i], types, encoders, &in);
    1647           0 :                         i++;
    1648             :                 }
    1649             :         }
    1650             : 
    1651           2 :         i = 1;
    1652           2 :         if (num_encoders > 0) {
    1653           2 :                 sdl->encoders = emalloc(sizeof(HashTable));
    1654           2 :                 zend_hash_init(sdl->encoders, num_encoders, NULL, delete_encoder, 0);
    1655           8 :                 while (i < num_encoders+1) {
    1656           4 :                         sdl_deserialize_key(sdl->encoders, encoders[i], &in);
    1657           4 :                         sdl_deserialize_encoder(encoders[i], types, &in);
    1658           4 :                         i++;
    1659             :                 }
    1660             :         }
    1661             : 
    1662             :         /* deserialize bindings */
    1663           2 :         WSDL_CACHE_GET_INT(num_bindings, &in);
    1664           2 :         bindings = safe_emalloc(num_bindings, sizeof(sdlBindingPtr), 0);
    1665           2 :         if (num_bindings > 0) {
    1666           2 :                 sdl->bindings = emalloc(sizeof(HashTable));
    1667           2 :                 zend_hash_init(sdl->bindings, num_bindings, NULL, delete_binding, 0);
    1668           4 :                 for (i = 0; i < num_bindings; i++) {
    1669           2 :                         sdlBindingPtr binding = emalloc(sizeof(sdlBinding));
    1670           2 :                         memset(binding, 0, sizeof(sdlBinding));
    1671           2 :                         sdl_deserialize_key(sdl->bindings, binding, &in);
    1672           2 :                         binding->name = sdl_deserialize_string(&in);
    1673           2 :                         binding->location = sdl_deserialize_string(&in);
    1674           2 :                         WSDL_CACHE_GET_1(binding->bindingType,sdlBindingType,&in);
    1675           4 :                         if (binding->bindingType == BINDING_SOAP && *in != 0) {
    1676           2 :                           sdlSoapBindingPtr soap_binding = binding->bindingAttributes = emalloc(sizeof(sdlSoapBinding));
    1677           2 :                                 WSDL_CACHE_GET_1(soap_binding->style,sdlEncodingStyle,&in);
    1678           2 :                                 WSDL_CACHE_GET_1(soap_binding->transport,sdlTransport,&in);
    1679             :                         } else {
    1680           0 :                                 WSDL_CACHE_SKIP(1,&in);
    1681             :                         }
    1682           2 :                         bindings[i] = binding;
    1683             :                 }
    1684             :         }
    1685             : 
    1686             :         /* deserialize functions */
    1687           2 :         WSDL_CACHE_GET_INT(num_func, &in);
    1688           2 :         zend_hash_init(&sdl->functions, num_func, NULL, delete_function, 0);
    1689           2 :         if (num_func > 0) {
    1690           2 :                 functions = safe_emalloc(num_func, sizeof(sdlFunctionPtr), 0);
    1691           5 :                 for (i = 0; i < num_func; i++) {
    1692             :                         int binding_num, num_faults;
    1693           3 :                         sdlFunctionPtr func = emalloc(sizeof(sdlFunction));
    1694           3 :                         sdl_deserialize_key(&sdl->functions, func, &in);
    1695           3 :                         func->functionName = sdl_deserialize_string(&in);
    1696           3 :                         func->requestName = sdl_deserialize_string(&in);
    1697           3 :                         func->responseName = sdl_deserialize_string(&in);
    1698             : 
    1699           3 :                         WSDL_CACHE_GET_INT(binding_num, &in);
    1700           3 :                         if (binding_num == 0) {
    1701           0 :                                 func->binding = NULL;
    1702             :                         } else {
    1703           3 :                                 func->binding = bindings[binding_num-1];
    1704             :                         }
    1705           6 :                         if (func->binding && func->binding->bindingType == BINDING_SOAP && *in != 0) {
    1706           3 :                                 sdlSoapBindingFunctionPtr binding = func->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunction));
    1707           3 :                                 memset(binding, 0, sizeof(sdlSoapBindingFunction));
    1708           3 :                                 WSDL_CACHE_GET_1(binding->style,sdlEncodingStyle,&in);
    1709           3 :                                 binding->soapAction = sdl_deserialize_string(&in);
    1710           3 :                                 sdl_deserialize_soap_body(&binding->input, encoders, types, &in);
    1711           3 :                                 sdl_deserialize_soap_body(&binding->output, encoders, types, &in);
    1712             :                         } else {
    1713           0 :                                 WSDL_CACHE_SKIP(1, &in);
    1714           0 :                                 func->bindingAttributes = NULL;
    1715             :                         }
    1716             : 
    1717           3 :                         func->requestParameters = sdl_deserialize_parameters(encoders, types, &in);
    1718           3 :                         func->responseParameters = sdl_deserialize_parameters(encoders, types, &in);
    1719             : 
    1720           3 :                         WSDL_CACHE_GET_INT(num_faults, &in);
    1721           3 :                         if (num_faults > 0) {
    1722             :                           int j;
    1723             : 
    1724           2 :                                 func->faults = emalloc(sizeof(HashTable));
    1725           2 :                                 zend_hash_init(func->faults, num_faults, NULL, delete_fault, 0);
    1726             : 
    1727           4 :                                 for (j = 0; j < num_faults; j++) {
    1728           2 :                                         sdlFaultPtr fault = emalloc(sizeof(sdlFault));
    1729             : 
    1730           2 :                                         sdl_deserialize_key(func->faults, fault, &in);
    1731           2 :                                         fault->name =sdl_deserialize_string(&in);
    1732           2 :                                         fault->details =sdl_deserialize_parameters(encoders, types, &in);
    1733           2 :                                         if (*in != 0) {
    1734           2 :                                                 sdlSoapBindingFunctionFaultPtr binding = fault->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunctionFault));
    1735           2 :                                                 memset(binding, 0, sizeof(sdlSoapBindingFunctionFault));
    1736           2 :                                                 WSDL_CACHE_GET_1(binding->use,sdlEncodingUse,&in);
    1737           2 :                                                 if (binding->use == SOAP_ENCODED) {
    1738           2 :                                                         WSDL_CACHE_GET_1(binding->encodingStyle, sdlRpcEncodingStyle, &in);
    1739             :                                                 } else {
    1740           0 :                                                         binding->encodingStyle = SOAP_ENCODING_DEFAULT;
    1741             :                                                 }
    1742           2 :                                                 binding->ns = sdl_deserialize_string(&in);
    1743             :                                         } else {
    1744           0 :                                                 WSDL_CACHE_SKIP(1, &in);
    1745           0 :                                                 fault->bindingAttributes = NULL;
    1746             :                                         }
    1747             :                                 }
    1748             :                         } else {
    1749           1 :                                 func->faults = NULL;
    1750             :                         }
    1751           3 :                         functions[i] = func;
    1752             :                 }
    1753             :         }
    1754             : 
    1755             :         /* deserialize requests */
    1756           2 :         WSDL_CACHE_GET_INT(i, &in);
    1757           2 :         if (i > 0) {
    1758           0 :                 sdl->requests = emalloc(sizeof(HashTable));
    1759           0 :                 zend_hash_init(sdl->requests, i, NULL, NULL, 0);
    1760           0 :                 while (i > 0) {
    1761             :                         int function_num;
    1762             : 
    1763           0 :                         WSDL_CACHE_GET_INT(function_num, &in);
    1764           0 :                         sdl_deserialize_key(sdl->requests, functions[function_num-1], &in);
    1765           0 :                         i--;
    1766             :                 }
    1767             :         }
    1768             : 
    1769           2 :         if (functions) {
    1770           2 :                 efree(functions);
    1771             :         }
    1772           2 :         efree(bindings);
    1773           2 :         efree(encoders);
    1774           2 :         efree(types);
    1775           2 :         efree(buf);
    1776           2 :         return sdl;
    1777             : }
    1778             : 
    1779         821 : static void sdl_serialize_string(const char *str, smart_str *out)
    1780             : {
    1781             :         int i;
    1782             : 
    1783         821 :         if (str) {
    1784         454 :                 i = strlen(str);
    1785        1816 :                 WSDL_CACHE_PUT_INT(i, out);
    1786         454 :                 if (i > 0) {
    1787         451 :                         WSDL_CACHE_PUT_N(str, i, out);
    1788             :                 }
    1789             :         } else {
    1790             :                 WSDL_CACHE_PUT_INT(0x7fffffff, out);
    1791             :         }
    1792         821 : }
    1793             : 
    1794             : // TODO: refactor it
    1795         228 : static void sdl_serialize_key(zend_string *key, smart_str *out)
    1796             : {
    1797         228 :         if (key) {
    1798         636 :                 WSDL_CACHE_PUT_INT(ZSTR_LEN(key), out);
    1799         159 :                 WSDL_CACHE_PUT_N(ZSTR_VAL(key), ZSTR_LEN(key), out);
    1800             :         } else {
    1801             :                 WSDL_CACHE_PUT_INT(0, out);
    1802             :         }
    1803         228 : }
    1804             : 
    1805         146 : static void sdl_serialize_encoder_ref(encodePtr enc, HashTable *tmp_encoders, smart_str *out) {
    1806         146 :         if (enc) {
    1807             :                 zval *encoder_num;
    1808         110 :                 if ((encoder_num = zend_hash_str_find(tmp_encoders, (char*)&enc, sizeof(enc))) != 0) {
    1809         440 :                         WSDL_CACHE_PUT_INT(Z_LVAL_P(encoder_num), out);
    1810             :                 } else {
    1811             :                         WSDL_CACHE_PUT_INT(0, out);
    1812             :                 }
    1813             :         } else {
    1814             :                 WSDL_CACHE_PUT_INT(0, out);
    1815             :         }
    1816         146 : }
    1817             : 
    1818         119 : static void sdl_serialize_type_ref(sdlTypePtr type, HashTable *tmp_types, smart_str *out) {
    1819         119 :         if (type) {
    1820             :                 zval *type_num;
    1821         104 :                 if ((type_num = zend_hash_str_find(tmp_types, (char*)&type, sizeof(type))) != NULL) {
    1822         416 :                         WSDL_CACHE_PUT_INT(Z_LVAL_P(type_num), out);
    1823             :                 } else {
    1824             :                         WSDL_CACHE_PUT_INT(0, out);
    1825             :                 }
    1826             :         } else {
    1827             :                 WSDL_CACHE_PUT_INT(0,out);
    1828             :         }
    1829         119 : }
    1830             : 
    1831          17 : static void sdl_serialize_attribute(sdlAttributePtr attr, HashTable *tmp_encoders, smart_str *out)
    1832             : {
    1833             :         int i;
    1834             : 
    1835          17 :         sdl_serialize_string(attr->name, out);
    1836          17 :         sdl_serialize_string(attr->namens, out);
    1837          17 :         sdl_serialize_string(attr->ref, out);
    1838          17 :         sdl_serialize_string(attr->def, out);
    1839          17 :         sdl_serialize_string(attr->fixed, out);
    1840          17 :         WSDL_CACHE_PUT_1(attr->form, out);
    1841          17 :         WSDL_CACHE_PUT_1(attr->use, out);
    1842          17 :         sdl_serialize_encoder_ref(attr->encode, tmp_encoders, out);
    1843          17 :         if (attr->extraAttributes) {
    1844           2 :                 i = zend_hash_num_elements(attr->extraAttributes);
    1845             :         } else {
    1846          15 :                 i = 0;
    1847             :         }
    1848          68 :         WSDL_CACHE_PUT_INT(i, out);
    1849          17 :         if (i > 0) {
    1850             :                 sdlExtraAttributePtr tmp;
    1851             :                 zend_string *key;
    1852             : 
    1853           6 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(attr->extraAttributes, key, tmp) {
    1854           2 :                         sdl_serialize_key(key, out);
    1855           2 :                         sdl_serialize_string(tmp->ns, out);
    1856           2 :                         sdl_serialize_string(tmp->val, out);
    1857             :                 } ZEND_HASH_FOREACH_END();
    1858             :         }
    1859          17 : }
    1860             : 
    1861          79 : static void sdl_serialize_model(sdlContentModelPtr model, HashTable *tmp_types, HashTable *tmp_elements, smart_str *out)
    1862             : {
    1863          79 :         WSDL_CACHE_PUT_1(model->kind, out);
    1864         316 :         WSDL_CACHE_PUT_INT(model->min_occurs, out);
    1865         316 :         WSDL_CACHE_PUT_INT(model->max_occurs, out);
    1866          79 :         switch (model->kind) {
    1867             :                 case XSD_CONTENT_ELEMENT:
    1868          53 :                         sdl_serialize_type_ref(model->u.element, tmp_elements, out);
    1869          53 :                         break;
    1870             :                 case XSD_CONTENT_SEQUENCE:
    1871             :                 case XSD_CONTENT_ALL:
    1872             :                 case XSD_CONTENT_CHOICE: {
    1873             :                                 sdlContentModelPtr tmp;
    1874          26 :                                 int i = zend_hash_num_elements(model->u.content);
    1875             : 
    1876         104 :                                 WSDL_CACHE_PUT_INT(i, out);
    1877         132 :                                 ZEND_HASH_FOREACH_PTR(model->u.content, tmp) {
    1878          53 :                                         sdl_serialize_model(tmp, tmp_types, tmp_elements, out);
    1879             :                                 } ZEND_HASH_FOREACH_END();
    1880             :                         }
    1881          26 :                         break;
    1882             :                 case XSD_CONTENT_GROUP_REF:
    1883           0 :                         sdl_serialize_string(model->u.group_ref,out);
    1884           0 :                         break;
    1885             :                 case XSD_CONTENT_GROUP:
    1886           0 :                         sdl_serialize_type_ref(model->u.group, tmp_types, out);
    1887             :                         break;
    1888             :                 default:
    1889             :                         break;
    1890             :         }
    1891          79 : }
    1892             : 
    1893          36 : static void sdl_serialize_resriction_int(sdlRestrictionIntPtr x, smart_str *out)
    1894             : {
    1895          36 :         if (x) {
    1896             :                 WSDL_CACHE_PUT_1(1, out);
    1897           0 :                 WSDL_CACHE_PUT_INT(x->value, out);
    1898           0 :                 WSDL_CACHE_PUT_1(x->fixed, out);
    1899             :         } else {
    1900             :                 WSDL_CACHE_PUT_1(0, out);
    1901             :         }
    1902          36 : }
    1903             : 
    1904          32 : static void sdl_serialize_resriction_char(sdlRestrictionCharPtr x, smart_str *out)
    1905             : {
    1906          32 :         if (x) {
    1907             :                 WSDL_CACHE_PUT_1(1, out);
    1908          24 :                 sdl_serialize_string(x->value, out);
    1909          24 :                 WSDL_CACHE_PUT_1(x->fixed, out);
    1910             :         } else {
    1911             :                 WSDL_CACHE_PUT_1(0, out);
    1912             :         }
    1913          32 : }
    1914             : 
    1915         102 : static void sdl_serialize_type(sdlTypePtr type, HashTable *tmp_encoders, HashTable *tmp_types, smart_str *out)
    1916             : {
    1917             :         int i;
    1918         102 :         HashTable *tmp_elements = NULL;
    1919             : 
    1920         102 :         WSDL_CACHE_PUT_1(type->kind, out);
    1921         102 :         sdl_serialize_string(type->name, out);
    1922         102 :         sdl_serialize_string(type->namens, out);
    1923         102 :         sdl_serialize_string(type->def, out);
    1924         102 :         sdl_serialize_string(type->fixed, out);
    1925         102 :         sdl_serialize_string(type->ref, out);
    1926         102 :         WSDL_CACHE_PUT_1(type->nillable, out);
    1927         102 :         WSDL_CACHE_PUT_1(type->form, out);
    1928         102 :         sdl_serialize_encoder_ref(type->encode, tmp_encoders, out);
    1929             : 
    1930         102 :         if (type->restrictions) {
    1931             :                 WSDL_CACHE_PUT_1(1, out);
    1932           4 :                 sdl_serialize_resriction_int(type->restrictions->minExclusive,out);
    1933           4 :                 sdl_serialize_resriction_int(type->restrictions->minInclusive,out);
    1934           4 :                 sdl_serialize_resriction_int(type->restrictions->maxExclusive,out);
    1935           4 :                 sdl_serialize_resriction_int(type->restrictions->maxInclusive,out);
    1936           4 :                 sdl_serialize_resriction_int(type->restrictions->totalDigits,out);
    1937           4 :                 sdl_serialize_resriction_int(type->restrictions->fractionDigits,out);
    1938           4 :                 sdl_serialize_resriction_int(type->restrictions->length,out);
    1939           4 :                 sdl_serialize_resriction_int(type->restrictions->minLength,out);
    1940           4 :                 sdl_serialize_resriction_int(type->restrictions->maxLength,out);
    1941           4 :                 sdl_serialize_resriction_char(type->restrictions->whiteSpace,out);
    1942           4 :                 sdl_serialize_resriction_char(type->restrictions->pattern,out);
    1943           4 :                 if (type->restrictions->enumeration) {
    1944           4 :                         i = zend_hash_num_elements(type->restrictions->enumeration);
    1945             :                 } else {
    1946           0 :                         i = 0;
    1947             :                 }
    1948          16 :                 WSDL_CACHE_PUT_INT(i, out);
    1949           4 :                 if (i > 0) {
    1950             :                         sdlRestrictionCharPtr tmp;
    1951             :                         zend_string *key;
    1952             : 
    1953          52 :                         ZEND_HASH_FOREACH_STR_KEY_PTR(type->restrictions->enumeration, key, tmp) {
    1954          24 :                                 sdl_serialize_resriction_char(tmp, out);
    1955          24 :                                 sdl_serialize_key(key, out);
    1956             :                         } ZEND_HASH_FOREACH_END();
    1957             :                 }
    1958             :         } else {
    1959             :                 WSDL_CACHE_PUT_1(0, out);
    1960             :         }
    1961         102 :         if (type->elements) {
    1962          26 :                 i = zend_hash_num_elements(type->elements);
    1963             :         } else {
    1964          76 :                 i = 0;
    1965             :         }
    1966         408 :         WSDL_CACHE_PUT_INT(i, out);
    1967         102 :         if (i > 0) {
    1968             :                 sdlTypePtr tmp;
    1969             :                 zend_string *key;
    1970             :                 zval zv;
    1971             : 
    1972          26 :                 tmp_elements = emalloc(sizeof(HashTable));
    1973          26 :                 zend_hash_init(tmp_elements, i, NULL, NULL, 0);
    1974             : 
    1975         132 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(type->elements, key, tmp) {
    1976          53 :                         sdl_serialize_key(key, out);
    1977          53 :                         sdl_serialize_type(tmp, tmp_encoders, tmp_types, out);
    1978          53 :                         ZVAL_LONG(&zv, i);
    1979          53 :                         zend_hash_str_add(tmp_elements, (char*)&tmp, sizeof(tmp), &zv);
    1980          53 :                         i--;
    1981             :                 } ZEND_HASH_FOREACH_END();
    1982             :         }
    1983             : 
    1984         102 :         if (type->attributes) {
    1985          10 :                 i = zend_hash_num_elements(type->attributes);
    1986             :         } else {
    1987          92 :                 i = 0;
    1988             :         }
    1989         408 :         WSDL_CACHE_PUT_INT(i, out);
    1990         102 :         if (i > 0) {
    1991             :                 sdlAttributePtr tmp;
    1992             :                 zend_string *key;
    1993             : 
    1994          44 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) {
    1995          17 :                         sdl_serialize_key(key, out);
    1996          17 :                         sdl_serialize_attribute(tmp, tmp_encoders, out);
    1997             :                 } ZEND_HASH_FOREACH_END();
    1998             :         }
    1999         102 :         if (type->model) {
    2000             :                 WSDL_CACHE_PUT_1(1, out);
    2001          26 :                 sdl_serialize_model(type->model, tmp_types, tmp_elements, out);
    2002             :         } else {
    2003             :                 WSDL_CACHE_PUT_1(0, out);
    2004             :         }
    2005         102 :         if (tmp_elements != NULL) {
    2006          26 :                 zend_hash_destroy(tmp_elements);
    2007          26 :                 efree(tmp_elements);
    2008             :         }
    2009         102 : }
    2010             : 
    2011          39 : static void sdl_serialize_encoder(encodePtr enc, HashTable *tmp_types, smart_str *out)
    2012             : {
    2013         156 :         WSDL_CACHE_PUT_INT(enc->details.type, out);
    2014          39 :         sdl_serialize_string(enc->details.type_str, out);
    2015          39 :         sdl_serialize_string(enc->details.ns, out);
    2016          39 :         sdl_serialize_type_ref(enc->details.sdl_type, tmp_types, out);
    2017          39 : }
    2018             : 
    2019          22 : static void sdl_serialize_parameters(HashTable *ht, HashTable *tmp_encoders, HashTable *tmp_types, smart_str *out)
    2020             : {
    2021             :         int i;
    2022             : 
    2023          22 :         if (ht) {
    2024          22 :                 i = zend_hash_num_elements(ht);
    2025             :         } else {
    2026           0 :                 i = 0;
    2027             :         }
    2028          88 :         WSDL_CACHE_PUT_INT(i, out);
    2029          22 :         if (i > 0) {
    2030             :                 sdlParamPtr tmp;
    2031             :                 zend_string *key;
    2032             : 
    2033          67 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(ht, key, tmp) {
    2034          23 :                         sdl_serialize_key(key, out);
    2035          23 :                         sdl_serialize_string(tmp->paramName, out);
    2036          92 :                         WSDL_CACHE_PUT_INT(tmp->order, out);
    2037          23 :                         sdl_serialize_encoder_ref(tmp->encode, tmp_encoders, out);
    2038          23 :                         sdl_serialize_type_ref(tmp->element, tmp_types, out);
    2039             :                 } ZEND_HASH_FOREACH_END();
    2040             :         }
    2041          22 : }
    2042             : 
    2043          20 : static void sdl_serialize_soap_body(sdlSoapBindingFunctionBodyPtr body, HashTable *tmp_encoders, HashTable *tmp_types, smart_str *out)
    2044             : {
    2045             :         int i, j;
    2046             : 
    2047          20 :         WSDL_CACHE_PUT_1(body->use, out);
    2048          20 :         if (body->use == SOAP_ENCODED) {
    2049           6 :                 WSDL_CACHE_PUT_1(body->encodingStyle, out);
    2050             :         }
    2051          20 :         sdl_serialize_string(body->ns, out);
    2052          20 :         if (body->headers) {
    2053           4 :                 i = zend_hash_num_elements(body->headers);
    2054             :         } else {
    2055          16 :                 i = 0;
    2056             :         }
    2057          80 :         WSDL_CACHE_PUT_INT(i, out);
    2058          20 :         if (i > 0) {
    2059             :                 sdlSoapBindingFunctionHeaderPtr tmp;
    2060             :                 zend_string *key;
    2061             : 
    2062          12 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(body->headers, key, tmp) {
    2063           4 :                         sdl_serialize_key(key, out);
    2064           4 :                         WSDL_CACHE_PUT_1(tmp->use, out);
    2065           4 :                         if (tmp->use == SOAP_ENCODED) {
    2066           0 :                                 WSDL_CACHE_PUT_1(tmp->encodingStyle, out);
    2067             :                         }
    2068           4 :                         sdl_serialize_string(tmp->name, out);
    2069           4 :                         sdl_serialize_string(tmp->ns, out);
    2070           4 :                         sdl_serialize_encoder_ref(tmp->encode, tmp_encoders, out);
    2071           4 :                         sdl_serialize_type_ref(tmp->element, tmp_types, out);
    2072           4 :                         if (tmp->headerfaults) {
    2073           0 :                                 j = zend_hash_num_elements(tmp->headerfaults);
    2074             :                         } else {
    2075           4 :                                 j = 0;
    2076             :                         }
    2077          16 :                         WSDL_CACHE_PUT_INT(j, out);
    2078           4 :                         if (j > 0) {
    2079             :                                 sdlSoapBindingFunctionHeaderPtr tmp2;
    2080             :                                 zend_string *key;
    2081             : 
    2082           0 :                                 ZEND_HASH_FOREACH_STR_KEY_PTR(body->headers, key, tmp2) {
    2083           0 :                                         sdl_serialize_key(key, out);
    2084           0 :                                         WSDL_CACHE_PUT_1(tmp2->use, out);
    2085           0 :                                         if (tmp2->use == SOAP_ENCODED) {
    2086           0 :                                                 WSDL_CACHE_PUT_1(tmp2->encodingStyle, out);
    2087             :                                         }
    2088           0 :                                         sdl_serialize_string(tmp2->name, out);
    2089           0 :                                         sdl_serialize_string(tmp2->ns, out);
    2090           0 :                                         sdl_serialize_encoder_ref(tmp2->encode, tmp_encoders, out);
    2091           0 :                                         sdl_serialize_type_ref(tmp2->element, tmp_types, out);
    2092             :                                 } ZEND_HASH_FOREACH_END();
    2093             :                         }
    2094             :                 } ZEND_HASH_FOREACH_END();
    2095             :         }
    2096          20 : }
    2097             : 
    2098           5 : static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr sdl)
    2099             : {
    2100           5 :         smart_str buf = {0};
    2101           5 :         smart_str *out = &buf;
    2102             :         int i;
    2103           5 :         int type_num = 1;
    2104           5 :         int encoder_num = 1;
    2105             :         int f;
    2106             :         encodePtr enc;
    2107             :         HashTable tmp_types;
    2108             :         HashTable tmp_encoders;
    2109             :         HashTable tmp_bindings;
    2110             :         HashTable tmp_functions;
    2111             : 
    2112             : #ifdef ZEND_WIN32
    2113             :         f = open(fn,O_CREAT|O_WRONLY|O_EXCL|O_BINARY,S_IREAD|S_IWRITE);
    2114             : #else
    2115           5 :         f = open(fn,O_CREAT|O_WRONLY|O_EXCL|O_BINARY,S_IREAD|S_IWRITE);
    2116             : #endif
    2117           5 :         if (f < 0) {return;}
    2118             : 
    2119           5 :         zend_hash_init(&tmp_types, 0, NULL, NULL, 0);
    2120           5 :         zend_hash_init(&tmp_encoders, 0, NULL, NULL, 0);
    2121           5 :         zend_hash_init(&tmp_bindings, 0, NULL, NULL, 0);
    2122           5 :         zend_hash_init(&tmp_functions, 0, NULL, NULL, 0);
    2123             : 
    2124             :         WSDL_CACHE_PUT_N("wsdl", 4, out);
    2125             :         WSDL_CACHE_PUT_1(WSDL_CACHE_VERSION,out);
    2126             :         WSDL_CACHE_PUT_1(0,out);
    2127           5 :         WSDL_CACHE_PUT_N(&t, sizeof(t), out);
    2128             : 
    2129           5 :         sdl_serialize_string(uri, out);
    2130           5 :         sdl_serialize_string(sdl->source, out);
    2131           5 :         sdl_serialize_string(sdl->target_ns, out);
    2132             : 
    2133           5 :         if (sdl->groups) {
    2134           0 :                 i = zend_hash_num_elements(sdl->groups);
    2135             :         } else {
    2136           5 :                 i = 0;
    2137             :         }
    2138          20 :         WSDL_CACHE_PUT_INT(i, out);
    2139           5 :         if (i > 0) {
    2140             :                 sdlTypePtr tmp;
    2141             :                 zval zv;
    2142             : 
    2143           0 :                 ZEND_HASH_FOREACH_PTR(sdl->groups, tmp) {
    2144           0 :                         ZVAL_LONG(&zv, type_num);
    2145           0 :                         zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv);
    2146           0 :                         ++type_num;
    2147             :                 } ZEND_HASH_FOREACH_END();
    2148             :         }
    2149             : 
    2150           5 :         if (sdl->types) {
    2151           5 :                 i = zend_hash_num_elements(sdl->types);
    2152             :         } else {
    2153           0 :                 i = 0;
    2154             :         }
    2155          20 :         WSDL_CACHE_PUT_INT(i, out);
    2156           5 :         if (i > 0) {
    2157             :                 sdlTypePtr tmp;
    2158             :                 zval zv;
    2159             : 
    2160          81 :                 ZEND_HASH_FOREACH_PTR(sdl->types, tmp) {
    2161          38 :                         ZVAL_LONG(&zv,  type_num);
    2162          38 :                         zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv);
    2163          38 :                         ++type_num;
    2164             :                 } ZEND_HASH_FOREACH_END();
    2165             :         }
    2166             : 
    2167           5 :         if (sdl->elements) {
    2168           2 :                 i = zend_hash_num_elements(sdl->elements);
    2169             :         } else {
    2170           3 :                 i = 0;
    2171             :         }
    2172          20 :         WSDL_CACHE_PUT_INT(i, out);
    2173           5 :         if (i > 0) {
    2174             :                 sdlTypePtr tmp;
    2175             :                 zval zv;
    2176             : 
    2177          24 :                 ZEND_HASH_FOREACH_PTR(sdl->elements, tmp) {
    2178          11 :                         ZVAL_LONG(&zv, type_num);
    2179          11 :                         zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv);
    2180          11 :                         ++type_num;
    2181             :                 } ZEND_HASH_FOREACH_END();
    2182             :         }
    2183             : 
    2184           5 :         if (sdl->encoders) {
    2185           5 :                 i = zend_hash_num_elements(sdl->encoders);
    2186             :         } else {
    2187           0 :                 i = 0;
    2188             :         }
    2189          20 :         WSDL_CACHE_PUT_INT(i, out);
    2190           5 :         if (i > 0) {
    2191             :                 encodePtr tmp;
    2192             :                 zval zv;
    2193             : 
    2194          83 :                 ZEND_HASH_FOREACH_PTR(sdl->encoders, tmp) {
    2195          39 :                         ZVAL_LONG(&zv, encoder_num);
    2196          39 :                         zend_hash_str_add(&tmp_encoders, (char*)&tmp, sizeof(tmp), &zv);
    2197          39 :                         ++encoder_num;
    2198             :                 } ZEND_HASH_FOREACH_END();
    2199             :         }
    2200           5 :         enc = defaultEncoding;
    2201         380 :         while (enc->details.type != END_KNOWN_TYPES) {
    2202             :                 zval zv;
    2203             : 
    2204         370 :                 ZVAL_LONG(&zv, encoder_num);
    2205         370 :                 zend_hash_str_add(&tmp_encoders, (char*)&enc, sizeof(encodePtr), &zv);
    2206         370 :                 enc++;
    2207         370 :                 ++encoder_num;
    2208             :         }
    2209             : 
    2210           5 :         if (sdl->groups) {
    2211             :                 sdlTypePtr tmp;
    2212             :                 zend_string *key;
    2213             : 
    2214           0 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->groups, key, tmp) {
    2215           0 :                         sdl_serialize_key(key, out);
    2216           0 :                         sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out);
    2217             :                 } ZEND_HASH_FOREACH_END();
    2218             :         }
    2219             : 
    2220           5 :         if (sdl->types) {
    2221             :                 sdlTypePtr tmp;
    2222             :                 zend_string *key;
    2223             : 
    2224          81 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) {
    2225          38 :                         sdl_serialize_key(key, out);
    2226          38 :                         sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out);
    2227             :                 } ZEND_HASH_FOREACH_END();
    2228             :         }
    2229             : 
    2230           5 :         if (sdl->elements) {
    2231             :                 sdlTypePtr tmp;
    2232             :                 zend_string *key;
    2233             : 
    2234          24 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->elements, key, tmp) {
    2235          11 :                         sdl_serialize_key(key, out);
    2236          11 :                         sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out);
    2237             :                 } ZEND_HASH_FOREACH_END();
    2238             :         }
    2239             : 
    2240           5 :         if (sdl->encoders) {
    2241             :                 encodePtr tmp;
    2242             :                 zend_string *key;
    2243             : 
    2244          83 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) {
    2245          39 :                         sdl_serialize_key(key, out);
    2246          39 :                         sdl_serialize_encoder(tmp, &tmp_types, out);
    2247             :                 } ZEND_HASH_FOREACH_END();
    2248             :         }
    2249             : 
    2250             :         /* serialize bindings */
    2251           5 :         if (sdl->bindings) {
    2252           5 :                 i = zend_hash_num_elements(sdl->bindings);
    2253             :         } else {
    2254           0 :                 i = 0;
    2255             :         }
    2256          20 :         WSDL_CACHE_PUT_INT(i, out);
    2257           5 :         if (i > 0) {
    2258             :                 sdlBindingPtr tmp;
    2259           5 :                 int binding_num = 1;
    2260             :                 zval zv;
    2261             :                 zend_string *key;
    2262             : 
    2263          15 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->bindings, key, tmp) {
    2264           5 :                         sdl_serialize_key(key, out);
    2265           5 :                         sdl_serialize_string(tmp->name, out);
    2266           5 :                         sdl_serialize_string(tmp->location, out);
    2267           5 :                         WSDL_CACHE_PUT_1(tmp->bindingType,out);
    2268          10 :                         if (tmp->bindingType == BINDING_SOAP && tmp->bindingAttributes != NULL) {
    2269           5 :                                 sdlSoapBindingPtr binding = (sdlSoapBindingPtr)tmp->bindingAttributes;
    2270           5 :                                 WSDL_CACHE_PUT_1(binding->style, out);
    2271           5 :                                 WSDL_CACHE_PUT_1(binding->transport, out);
    2272             :                         } else {
    2273             :                                 WSDL_CACHE_PUT_1(0,out);
    2274             :                         }
    2275             : 
    2276           5 :                         ZVAL_LONG(&zv, binding_num);
    2277           5 :                         zend_hash_str_add(&tmp_bindings, (char*)&tmp, sizeof(tmp), &zv);
    2278           5 :                         binding_num++;
    2279             :                 } ZEND_HASH_FOREACH_END();
    2280             :         }
    2281             : 
    2282             :         /* serialize functions */
    2283           5 :         i = zend_hash_num_elements(&sdl->functions);
    2284          20 :         WSDL_CACHE_PUT_INT(i, out);
    2285           5 :         if (i > 0) {
    2286             :                 sdlFunctionPtr tmp;
    2287             :                 zval *binding_num, zv;
    2288           5 :                 int function_num = 1;
    2289             :                 zend_string *key;
    2290             : 
    2291          25 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(&sdl->functions, key, tmp) {
    2292          10 :                         sdl_serialize_key(key, out);
    2293          10 :                         sdl_serialize_string(tmp->functionName, out);
    2294          10 :                         sdl_serialize_string(tmp->requestName, out);
    2295          10 :                         sdl_serialize_string(tmp->responseName, out);
    2296             : 
    2297          10 :                         if (tmp->binding) {
    2298          10 :                                 binding_num = zend_hash_str_find(&tmp_bindings,(char*)&tmp->binding, sizeof(tmp->binding));
    2299          10 :                                 if (binding_num) {
    2300          40 :                                         WSDL_CACHE_PUT_INT(Z_LVAL_P(binding_num), out);
    2301          10 :                                         if (Z_LVAL_P(binding_num) >= 0) {
    2302          20 :                                                 if (tmp->binding->bindingType == BINDING_SOAP && tmp->bindingAttributes != NULL) {
    2303          10 :                                                         sdlSoapBindingFunctionPtr binding = (sdlSoapBindingFunctionPtr)tmp->bindingAttributes;
    2304          10 :                                                         WSDL_CACHE_PUT_1(binding->style, out);
    2305          10 :                                                         sdl_serialize_string(binding->soapAction, out);
    2306          10 :                                                         sdl_serialize_soap_body(&binding->input, &tmp_encoders, &tmp_types, out);
    2307          10 :                                                         sdl_serialize_soap_body(&binding->output, &tmp_encoders, &tmp_types, out);
    2308             :                                                 } else {
    2309             :                                                         WSDL_CACHE_PUT_1(0,out);
    2310             :                                                 }
    2311             :                                         }
    2312             :                                 }
    2313             :                         }
    2314          10 :                         sdl_serialize_parameters(tmp->requestParameters, &tmp_encoders, &tmp_types, out);
    2315          10 :                         sdl_serialize_parameters(tmp->responseParameters, &tmp_encoders, &tmp_types, out);
    2316             : 
    2317          10 :                         if (tmp->faults) {
    2318             :                                 sdlFaultPtr fault;
    2319             :                                 zend_string *key;
    2320             : 
    2321           8 :                                 WSDL_CACHE_PUT_INT(zend_hash_num_elements(tmp->faults), out);
    2322             : 
    2323           6 :                                 ZEND_HASH_FOREACH_STR_KEY_PTR(tmp->faults, key, fault) {
    2324           2 :                                         sdl_serialize_key(key, out);
    2325           2 :                                         sdl_serialize_string(fault->name, out);
    2326           2 :                                         sdl_serialize_parameters(fault->details, &tmp_encoders, &tmp_types, out);
    2327           4 :                                         if (tmp->binding->bindingType == BINDING_SOAP && fault->bindingAttributes != NULL) {
    2328           2 :                                                 sdlSoapBindingFunctionFaultPtr binding = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
    2329           2 :                                                 WSDL_CACHE_PUT_1(binding->use, out);
    2330           2 :                                                 if (binding->use == SOAP_ENCODED) {
    2331           2 :                                                         WSDL_CACHE_PUT_1(binding->encodingStyle, out);
    2332             :                                                 }
    2333           2 :                                                 sdl_serialize_string(binding->ns, out);
    2334             :                                         } else {
    2335             :                                                 WSDL_CACHE_PUT_1(0, out);
    2336             :                                         }
    2337             :                                 } ZEND_HASH_FOREACH_END();
    2338             :                         } else {
    2339             :                                 WSDL_CACHE_PUT_INT(0, out);
    2340             :                         }
    2341             : 
    2342          10 :                         ZVAL_LONG(&zv, function_num);
    2343          10 :                         zend_hash_str_add(&tmp_functions, (char*)&tmp, sizeof(tmp), &zv);
    2344          10 :                         function_num++;
    2345             :                 } ZEND_HASH_FOREACH_END();
    2346             :         }
    2347             : 
    2348             :         /* serialize requests */
    2349           5 :         if (sdl->requests) {
    2350           0 :                 i = zend_hash_num_elements(sdl->requests);
    2351             :         } else {
    2352           5 :                 i = 0;
    2353             :         }
    2354          20 :         WSDL_CACHE_PUT_INT(i, out);
    2355           5 :         if (i > 0) {
    2356             :                 sdlFunctionPtr tmp;
    2357             :                 zval *function_num;
    2358             :                 zend_string *key;
    2359             : 
    2360           0 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->requests, key, tmp) {
    2361           0 :                         function_num = zend_hash_str_find(&tmp_functions, (char*)&tmp, sizeof(tmp));
    2362           0 :                         WSDL_CACHE_PUT_INT(Z_LVAL_P(function_num), out);
    2363           0 :                         sdl_serialize_key(key, out);
    2364             :                 } ZEND_HASH_FOREACH_END();
    2365             :         }
    2366             : 
    2367           5 :         php_ignore_value(write(f, ZSTR_VAL(buf.s), ZSTR_LEN(buf.s)));
    2368           5 :         close(f);
    2369             :         smart_str_free(&buf);
    2370           5 :         zend_hash_destroy(&tmp_functions);
    2371           5 :         zend_hash_destroy(&tmp_bindings);
    2372           5 :         zend_hash_destroy(&tmp_encoders);
    2373           5 :         zend_hash_destroy(&tmp_types);
    2374             : }
    2375             : 
    2376             : 
    2377           0 : static void make_persistent_restriction_int(void *data)
    2378             : {
    2379           0 :         sdlRestrictionIntPtr *rest = (sdlRestrictionIntPtr *)data;
    2380           0 :         sdlRestrictionIntPtr prest = NULL;
    2381             : 
    2382           0 :         prest = malloc(sizeof(sdlRestrictionInt));
    2383           0 :         *prest = **rest;
    2384           0 :         *rest = prest;
    2385           0 : }
    2386             : 
    2387             : 
    2388           0 : static void make_persistent_restriction_char_int(sdlRestrictionCharPtr *rest)
    2389             : {
    2390           0 :         sdlRestrictionCharPtr prest = NULL;
    2391             : 
    2392           0 :         prest = malloc(sizeof(sdlRestrictionChar));
    2393           0 :         memset(prest, 0, sizeof(sdlRestrictionChar));
    2394           0 :         prest->value = strdup((*rest)->value);
    2395           0 :         prest->fixed = (*rest)->fixed;
    2396           0 :         *rest = prest;
    2397           0 : }
    2398             : 
    2399             : 
    2400           0 : static void make_persistent_restriction_char(zval *zv)
    2401             : {
    2402           0 :         make_persistent_restriction_char_int((sdlRestrictionCharPtr*)&Z_PTR_P(zv));
    2403           0 : }
    2404             : 
    2405             : 
    2406          25 : static void make_persistent_sdl_type_ref(sdlTypePtr *type, HashTable *ptr_map, HashTable *bp_types)
    2407             : {
    2408             :         sdlTypePtr tmp;
    2409             : 
    2410          50 :         if ((tmp = zend_hash_str_find_ptr(ptr_map, (char *)type, sizeof(sdlTypePtr))) != NULL) {
    2411          25 :                 *type = tmp;
    2412             :         } else {
    2413           0 :                 zend_hash_next_index_insert_ptr(bp_types, *type);
    2414             :         }
    2415          25 : }
    2416             : 
    2417             : 
    2418          19 : static void make_persistent_sdl_encoder_ref(encodePtr *enc, HashTable *ptr_map, HashTable *bp_encoders)
    2419             : {
    2420             :         encodePtr tmp;
    2421             : 
    2422             :         /* do not process defaultEncoding's here */
    2423          19 :         if ((*enc) >= defaultEncoding && (*enc) < defaultEncoding + numDefaultEncodings) {
    2424          16 :                 return;
    2425             :         }
    2426             : 
    2427           6 :         if ((tmp = zend_hash_str_find_ptr(ptr_map, (char *)enc, sizeof(encodePtr))) != NULL) {
    2428           0 :                 *enc = tmp;
    2429             :         } else {
    2430             :                 zend_hash_next_index_insert_ptr(bp_encoders, enc);
    2431             :         }
    2432             : }
    2433             : 
    2434             : 
    2435           0 : static HashTable* make_persistent_sdl_function_headers(HashTable *headers, HashTable *ptr_map)
    2436             : {
    2437             :         HashTable *pheaders;
    2438             :         sdlSoapBindingFunctionHeaderPtr tmp, pheader;
    2439             :         encodePtr penc;
    2440             :         sdlTypePtr ptype;
    2441             :         zend_string *key;
    2442             : 
    2443           0 :         pheaders = malloc(sizeof(HashTable));
    2444           0 :         zend_hash_init(pheaders, zend_hash_num_elements(headers), NULL, delete_header_persistent, 1);
    2445             : 
    2446           0 :         ZEND_HASH_FOREACH_STR_KEY_PTR(headers, key, tmp) {
    2447           0 :                 pheader = malloc(sizeof(sdlSoapBindingFunctionHeader));
    2448           0 :                 memset(pheader, 0, sizeof(sdlSoapBindingFunctionHeader));
    2449           0 :                 *pheader = *tmp;
    2450             : 
    2451           0 :                 if (pheader->name) {
    2452           0 :                         pheader->name = strdup(pheader->name);
    2453             :                 }
    2454           0 :                 if (pheader->ns) {
    2455           0 :                         pheader->ns = strdup(pheader->ns);
    2456             :                 }
    2457             : 
    2458           0 :                 if (pheader->encode->details.sdl_type) {
    2459           0 :                         if ((penc = zend_hash_str_find_ptr(ptr_map, (char*)&pheader->encode, sizeof(encodePtr))) == NULL) {
    2460             :                                 assert(0);
    2461             :                         }
    2462           0 :                         pheader->encode = penc;
    2463             :                 }
    2464           0 :                 if (pheader->element) {
    2465           0 :                         if ((ptype = zend_hash_str_find_ptr(ptr_map, (char*)&pheader->element, sizeof(sdlTypePtr))) == NULL) {
    2466             :                                 assert(0);
    2467             :                         }
    2468           0 :                         pheader->element = ptype;
    2469             :                 }
    2470             : 
    2471           0 :                 if (pheader->headerfaults) {
    2472           0 :                         pheader->headerfaults = make_persistent_sdl_function_headers(pheader->headerfaults, ptr_map);
    2473             :                 }
    2474             : 
    2475           0 :                 if (key) {
    2476             :                         /* We have to duplicate key emalloc->malloc */
    2477           0 :                         zend_hash_str_add_ptr(pheaders, ZSTR_VAL(key), ZSTR_LEN(key), pheader);
    2478             :                 } else {
    2479             :                         zend_hash_next_index_insert_ptr(pheaders, pheader);
    2480             :                 }
    2481             :         } ZEND_HASH_FOREACH_END();
    2482             : 
    2483           0 :         return pheaders;
    2484             : }
    2485             : 
    2486             : 
    2487           2 : static void make_persistent_sdl_soap_body(sdlSoapBindingFunctionBodyPtr body, HashTable *ptr_map)
    2488             : {
    2489           2 :         if (body->ns) {
    2490           2 :                 body->ns = strdup(body->ns);
    2491             :         }
    2492             : 
    2493           2 :         if (body->headers) {
    2494           0 :                 body->headers = make_persistent_sdl_function_headers(body->headers, ptr_map);
    2495             :         }
    2496           2 : }
    2497             : 
    2498             : 
    2499           2 : static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *ptr_map)
    2500             : {
    2501             :         HashTable *pparams;
    2502             :         sdlParamPtr tmp, pparam;
    2503             :         sdlTypePtr ptype;
    2504             :         encodePtr penc;
    2505             :         zend_string *key;
    2506             : 
    2507           2 :         pparams = malloc(sizeof(HashTable));
    2508           2 :         zend_hash_init(pparams, zend_hash_num_elements(params), NULL, delete_parameter_persistent, 1);
    2509             : 
    2510          10 :         ZEND_HASH_FOREACH_STR_KEY_PTR(params, key, tmp) {
    2511           4 :                 pparam = malloc(sizeof(sdlParam));
    2512           4 :                 memset(pparam, 0, sizeof(sdlParam));
    2513           4 :                 *pparam = *tmp;
    2514             : 
    2515           4 :                 if (pparam->paramName) {
    2516           4 :                         pparam->paramName = strdup(pparam->paramName);
    2517             :                 }
    2518             : 
    2519           4 :                 if (pparam->encode && pparam->encode->details.sdl_type) {
    2520           4 :                         if ((penc = zend_hash_str_find_ptr(ptr_map, (char*)&pparam->encode, sizeof(encodePtr))) == NULL) {
    2521             :                                 assert(0);
    2522             :                         }
    2523           2 :                         pparam->encode = penc;
    2524             :                 }
    2525           4 :                 if (pparam->element) {
    2526           0 :                         if ((ptype = zend_hash_str_find_ptr(ptr_map, (char*)&pparam->element, sizeof(sdlTypePtr))) == NULL) {
    2527             :                                 assert(0);
    2528             :                         }
    2529           0 :                         pparam->element = ptype;
    2530             :                 }
    2531             : 
    2532           4 :                 if (key) {
    2533             :                         /* We have to duplicate key emalloc->malloc */
    2534           0 :                         zend_hash_str_add_ptr(pparams, ZSTR_VAL(key), ZSTR_LEN(key), pparam);
    2535             :                 } else {
    2536             :                         zend_hash_next_index_insert_ptr(pparams, pparam);
    2537             :                 }
    2538             :         } ZEND_HASH_FOREACH_END();
    2539             : 
    2540           2 :         return pparams;
    2541             : }
    2542             : 
    2543           0 : static HashTable* make_persistent_sdl_function_faults(sdlFunctionPtr func, HashTable *faults, HashTable *ptr_map)
    2544             : {
    2545             :         HashTable *pfaults;
    2546             :         sdlFaultPtr tmp, pfault;
    2547             :         zend_string *key;
    2548             : 
    2549           0 :         pfaults = malloc(sizeof(HashTable));
    2550           0 :         zend_hash_init(pfaults, zend_hash_num_elements(faults), NULL, delete_fault_persistent, 1);
    2551             : 
    2552           0 :         ZEND_HASH_FOREACH_STR_KEY_PTR(faults, key, tmp) {
    2553           0 :                 pfault = malloc(sizeof(sdlFault));
    2554           0 :                 memset(pfault, 0, sizeof(sdlFault));
    2555           0 :                 *pfault = *tmp;
    2556             : 
    2557           0 :                 if (pfault->name) {
    2558           0 :                         pfault->name = strdup(pfault->name);
    2559             :                 }
    2560           0 :                 if (pfault->details) {
    2561           0 :                         pfault->details = make_persistent_sdl_parameters(pfault->details, ptr_map);
    2562             :                 }
    2563             : 
    2564           0 :                 if (func->binding->bindingType == BINDING_SOAP && pfault->bindingAttributes) {
    2565             :                         sdlSoapBindingFunctionFaultPtr soap_binding;
    2566             : 
    2567           0 :                         soap_binding = malloc(sizeof(sdlSoapBindingFunctionFault));
    2568           0 :                         memset(soap_binding, 0, sizeof(sdlSoapBindingFunctionFault));
    2569           0 :                         *soap_binding = *(sdlSoapBindingFunctionFaultPtr)pfault->bindingAttributes;
    2570           0 :                         if (soap_binding->ns) {
    2571           0 :                                 soap_binding->ns = strdup(soap_binding->ns);
    2572             :                         }
    2573           0 :                         pfault->bindingAttributes = soap_binding;
    2574             :                 }
    2575             : 
    2576           0 :                 if (key) {
    2577             :                         /* We have to duplicate key emalloc->malloc */
    2578           0 :                         zend_hash_str_add_ptr(pfaults, ZSTR_VAL(key), ZSTR_LEN(key), pfault);
    2579             :                 } else {
    2580             :                         zend_hash_next_index_insert_ptr(pfaults, pfault);
    2581             :                 }
    2582             : 
    2583             :         } ZEND_HASH_FOREACH_END();
    2584             : 
    2585           0 :         return pfaults;
    2586             : }
    2587             : 
    2588             : 
    2589           2 : static sdlAttributePtr make_persistent_sdl_attribute(sdlAttributePtr attr, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders)
    2590             : {
    2591             :         sdlAttributePtr pattr;
    2592             :         zend_string *key;
    2593             : 
    2594           2 :         pattr = malloc(sizeof(sdlAttribute));
    2595           2 :         memset(pattr, 0, sizeof(sdlAttribute));
    2596             : 
    2597           2 :         *pattr = *attr;
    2598             : 
    2599           2 :         if (pattr->name) {
    2600           2 :                 pattr->name = strdup(pattr->name);
    2601             :         }
    2602           2 :         if (pattr->namens) {
    2603           2 :                 pattr->namens = strdup(pattr->namens);
    2604             :         }
    2605           2 :         if (pattr->ref) {
    2606           0 :                 pattr->ref = strdup(pattr->ref);
    2607             :         }
    2608           2 :         if (pattr->def) {
    2609           0 :                 pattr->def = strdup(pattr->def);
    2610             :         }
    2611           2 :         if (pattr->fixed) {
    2612           0 :                 pattr->fixed = strdup(pattr->fixed);
    2613             :         }
    2614             : 
    2615             :         /* we do not want to process defaultEncoding's here */
    2616           2 :         if (pattr->encode) {
    2617           0 :                 make_persistent_sdl_encoder_ref(&pattr->encode, ptr_map, bp_encoders);
    2618             :         }
    2619             : 
    2620           2 :         if (pattr->extraAttributes) {
    2621             :                 sdlExtraAttributePtr tmp, pextra;
    2622             : 
    2623           2 :                 pattr->extraAttributes = malloc(sizeof(HashTable));
    2624           2 :                 zend_hash_init(pattr->extraAttributes, zend_hash_num_elements(attr->extraAttributes), NULL, delete_extra_attribute_persistent, 1);
    2625             : 
    2626           2 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(pattr->extraAttributes, key, tmp) {
    2627           0 :                         if (key) {
    2628           0 :                                 pextra = malloc(sizeof(sdlExtraAttribute));
    2629           0 :                                 memset(pextra, 0, sizeof(sdlExtraAttribute));
    2630             : 
    2631           0 :                                 if (tmp->ns) {
    2632           0 :                                         pextra->ns = strdup(tmp->ns);
    2633             :                                 }
    2634           0 :                                 if (tmp->val) {
    2635           0 :                                         pextra->val = strdup(tmp->val);
    2636             :                                 }
    2637             : 
    2638             :                                 /* We have to duplicate key emalloc->malloc */
    2639           0 :                                 zend_hash_str_add_ptr(pattr->extraAttributes, ZSTR_VAL(key), ZSTR_LEN(key), pextra);
    2640             :                         }
    2641             :                 } ZEND_HASH_FOREACH_END();
    2642             :         }
    2643             : 
    2644           2 :         return pattr;
    2645             : }
    2646             : 
    2647             : 
    2648          23 : static sdlContentModelPtr make_persistent_sdl_model(sdlContentModelPtr model, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders)
    2649             : {
    2650             :         sdlContentModelPtr pmodel;
    2651             :         sdlContentModelPtr tmp, pcontent;
    2652             : 
    2653          23 :         pmodel = malloc(sizeof(sdlContentModel));
    2654          23 :         memset(pmodel, 0, sizeof(sdlContentModel));
    2655          23 :         *pmodel = *model;
    2656             : 
    2657          23 :         switch (pmodel->kind) {
    2658             :                 case XSD_CONTENT_ELEMENT:
    2659          17 :                         if (pmodel->u.element) {
    2660          17 :                                 make_persistent_sdl_type_ref(&pmodel->u.element, ptr_map, bp_types);
    2661             :                         }
    2662          17 :                         break;
    2663             : 
    2664             :                 case XSD_CONTENT_SEQUENCE:
    2665             :                 case XSD_CONTENT_ALL:
    2666             :                 case XSD_CONTENT_CHOICE:
    2667           6 :                         pmodel->u.content = malloc(sizeof(HashTable));
    2668           6 :                         zend_hash_init(pmodel->u.content, zend_hash_num_elements(model->u.content), NULL, delete_model_persistent, 1);
    2669             : 
    2670          40 :                         ZEND_HASH_FOREACH_PTR(model->u.content, tmp) {
    2671          17 :                                 pcontent = make_persistent_sdl_model(tmp, ptr_map, bp_types, bp_encoders);
    2672          17 :                                 zend_hash_next_index_insert_ptr(pmodel->u.content, pcontent);
    2673             :                         } ZEND_HASH_FOREACH_END();
    2674           6 :                         break;
    2675             : 
    2676             :                 case XSD_CONTENT_GROUP_REF:
    2677           0 :                         if (pmodel->u.group_ref) {
    2678           0 :                                 pmodel->u.group_ref = strdup(pmodel->u.group_ref);
    2679             :                         }
    2680           0 :                         break;
    2681             : 
    2682             :                 case XSD_CONTENT_GROUP:
    2683           0 :                         if (pmodel->u.group) {
    2684           0 :                                 make_persistent_sdl_type_ref(&pmodel->u.group, ptr_map, bp_types);
    2685             :                         }
    2686             :                         break;
    2687             : 
    2688             :                 default:
    2689             :                         break;
    2690             :         }
    2691             : 
    2692          23 :         return pmodel;
    2693             : }
    2694             : 
    2695             : 
    2696          25 : static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders)
    2697             : {
    2698             :         zend_string *key;
    2699          25 :         sdlTypePtr ptype = NULL;
    2700             : 
    2701          25 :         ptype = malloc(sizeof(sdlType));
    2702          25 :         memset(ptype, 0, sizeof(sdlType));
    2703             : 
    2704          25 :         *ptype = *type;
    2705             : 
    2706          25 :         if (ptype->name) {
    2707          25 :                 ptype->name = strdup(ptype->name);
    2708             :         }
    2709          25 :         if (ptype->namens) {
    2710          25 :                 ptype->namens = strdup(ptype->namens);
    2711             :         }
    2712          25 :         if (ptype->def) {
    2713           0 :                 ptype->def = strdup(ptype->def);
    2714             :         }
    2715          25 :         if (ptype->fixed) {
    2716           0 :                 ptype->fixed = strdup(ptype->fixed);
    2717             :         }
    2718          25 :         if (ptype->ref) {
    2719           0 :                 ptype->ref = strdup(ptype->ref);
    2720             :         }
    2721             : 
    2722             :         /* we do not want to process defaultEncoding's here */
    2723          25 :         if (ptype->encode) {
    2724          19 :                 make_persistent_sdl_encoder_ref(&ptype->encode, ptr_map, bp_encoders);
    2725             :         }
    2726             : 
    2727          25 :         if (ptype->restrictions) {
    2728           0 :                 ptype->restrictions = malloc(sizeof(sdlRestrictions));
    2729           0 :                 memset(ptype->restrictions, 0, sizeof(sdlRestrictions));
    2730           0 :                 *ptype->restrictions = *type->restrictions;
    2731             : 
    2732           0 :                 if (ptype->restrictions->minExclusive) {
    2733           0 :                         make_persistent_restriction_int(&ptype->restrictions->minExclusive);
    2734             :                 }
    2735           0 :                 if (ptype->restrictions->maxExclusive) {
    2736           0 :                         make_persistent_restriction_int(&ptype->restrictions->maxExclusive);
    2737             :                 }
    2738           0 :                 if (ptype->restrictions->minInclusive) {
    2739           0 :                         make_persistent_restriction_int(&ptype->restrictions->minInclusive);
    2740             :                 }
    2741           0 :                 if (ptype->restrictions->maxInclusive) {
    2742           0 :                         make_persistent_restriction_int(&ptype->restrictions->maxInclusive);
    2743             :                 }
    2744           0 :                 if (ptype->restrictions->totalDigits) {
    2745           0 :                         make_persistent_restriction_int(&ptype->restrictions->totalDigits);
    2746             :                 }
    2747           0 :                 if (ptype->restrictions->fractionDigits) {
    2748           0 :                         make_persistent_restriction_int(&ptype->restrictions->fractionDigits);
    2749             :                 }
    2750           0 :                 if (ptype->restrictions->length) {
    2751           0 :                         make_persistent_restriction_int(&ptype->restrictions->length);
    2752             :                 }
    2753           0 :                 if (ptype->restrictions->minLength) {
    2754           0 :                         make_persistent_restriction_int(&ptype->restrictions->minLength);
    2755             :                 }
    2756           0 :                 if (ptype->restrictions->maxLength) {
    2757           0 :                         make_persistent_restriction_int(&ptype->restrictions->maxLength);
    2758             :                 }
    2759           0 :                 if (ptype->restrictions->whiteSpace) {
    2760           0 :                         make_persistent_restriction_char_int(&ptype->restrictions->whiteSpace);
    2761             :                 }
    2762           0 :                 if (ptype->restrictions->pattern) {
    2763           0 :                         make_persistent_restriction_char_int(&ptype->restrictions->pattern);
    2764             :                 }
    2765             : 
    2766           0 :                 if (type->restrictions->enumeration) {
    2767           0 :                         ptype->restrictions->enumeration = malloc(sizeof(HashTable));
    2768           0 :                         zend_hash_init(ptype->restrictions->enumeration, zend_hash_num_elements(type->restrictions->enumeration), NULL, delete_restriction_var_char_persistent, 1);
    2769           0 :                         zend_hash_copy(ptype->restrictions->enumeration, type->restrictions->enumeration, make_persistent_restriction_char);
    2770             :                 }
    2771             :         }
    2772             : 
    2773          25 :         if (ptype->elements) {
    2774             :                 sdlTypePtr tmp, pelem;
    2775             : 
    2776           6 :                 ptype->elements = malloc(sizeof(HashTable));
    2777           6 :                 zend_hash_init(ptype->elements, zend_hash_num_elements(type->elements), NULL, delete_type_persistent, 1);
    2778             : 
    2779          40 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(type->elements, key, tmp) {
    2780          17 :                         pelem = make_persistent_sdl_type(tmp, ptr_map, bp_types, bp_encoders);
    2781          17 :                         if (key) {
    2782             :                                 /* We have to duplicate key emalloc->malloc */
    2783          17 :                                 zend_hash_str_add_ptr(ptype->elements, ZSTR_VAL(key), ZSTR_LEN(key), pelem);
    2784             :                         } else {
    2785           0 :                                 zend_hash_next_index_insert_ptr(ptype->elements, pelem);
    2786             :                         }
    2787          17 :                         zend_hash_str_add_ptr(ptr_map, (char*)&tmp, sizeof(tmp), pelem);
    2788             :                 } ZEND_HASH_FOREACH_END();
    2789             :         }
    2790             : 
    2791          25 :         if (ptype->attributes) {
    2792             :                 sdlAttributePtr tmp, pattr;
    2793             : 
    2794           2 :                 ptype->attributes = malloc(sizeof(HashTable));
    2795           2 :                 zend_hash_init(ptype->attributes, zend_hash_num_elements(type->attributes), NULL, delete_attribute_persistent, 1);
    2796             : 
    2797           6 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) {
    2798           2 :                         pattr = make_persistent_sdl_attribute(tmp, ptr_map, bp_types, bp_encoders);
    2799           2 :                         if (key) {
    2800             :                                 /* We have to duplicate key emalloc->malloc */
    2801           2 :                                 zend_hash_str_add_ptr(ptype->attributes, ZSTR_VAL(key), ZSTR_LEN(key), pattr);
    2802             :                         } else {
    2803           0 :                                 zend_hash_next_index_insert_ptr(ptype->attributes, pattr);
    2804             :                         }
    2805             :                 } ZEND_HASH_FOREACH_END();
    2806             :         }
    2807             : 
    2808          25 :         if (type->model) {
    2809           6 :                 ptype->model = make_persistent_sdl_model(ptype->model, ptr_map, bp_types, bp_encoders);
    2810             :         }
    2811             : 
    2812          25 :         return ptype;
    2813             : }
    2814             : 
    2815           8 : static encodePtr make_persistent_sdl_encoder(encodePtr enc, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders)
    2816             : {
    2817           8 :         encodePtr penc = NULL;
    2818             : 
    2819           8 :         penc = malloc(sizeof(encode));
    2820           8 :         memset(penc, 0, sizeof(encode));
    2821             : 
    2822           8 :         *penc = *enc;
    2823             : 
    2824           8 :         if (penc->details.type_str) {
    2825           8 :                 penc->details.type_str = strdup(penc->details.type_str);
    2826             :         }
    2827           8 :         if (penc->details.ns) {
    2828           8 :                 penc->details.ns = strdup(penc->details.ns);
    2829             :         }
    2830             : 
    2831           8 :         if (penc->details.sdl_type) {
    2832           8 :                 make_persistent_sdl_type_ref(&penc->details.sdl_type, ptr_map, bp_types);
    2833             :         }
    2834             : 
    2835           8 :         return penc;
    2836             : }
    2837             : 
    2838           1 : static sdlBindingPtr make_persistent_sdl_binding(sdlBindingPtr bind, HashTable *ptr_map)
    2839             : {
    2840           1 :         sdlBindingPtr pbind = NULL;
    2841             : 
    2842           1 :         pbind = malloc(sizeof(sdlBinding));
    2843           1 :         memset(pbind, 0, sizeof(sdlBinding));
    2844             : 
    2845           1 :         *pbind = *bind;
    2846             : 
    2847           1 :         if (pbind->name) {
    2848           1 :                 pbind->name = strdup(pbind->name);
    2849             :         }
    2850           1 :         if (pbind->location) {
    2851           1 :                 pbind->location = strdup(pbind->location);
    2852             :         }
    2853             : 
    2854           1 :         if (pbind->bindingType == BINDING_SOAP && pbind->bindingAttributes) {
    2855             :                 sdlSoapBindingPtr soap_binding;
    2856             : 
    2857           1 :                 soap_binding = malloc(sizeof(sdlSoapBinding));
    2858           1 :                 memset(soap_binding, 0, sizeof(sdlSoapBinding));
    2859           1 :                 *soap_binding = *(sdlSoapBindingPtr)pbind->bindingAttributes;
    2860           1 :                 pbind->bindingAttributes = soap_binding;
    2861             :         }
    2862             : 
    2863           1 :         return pbind;
    2864             : }
    2865             : 
    2866           1 : static sdlFunctionPtr make_persistent_sdl_function(sdlFunctionPtr func, HashTable *ptr_map)
    2867             : {
    2868           1 :         sdlFunctionPtr pfunc = NULL;
    2869             : 
    2870           1 :         pfunc = malloc(sizeof(sdlFunction));
    2871           1 :         memset(pfunc, 0, sizeof(sdlFunction));
    2872             : 
    2873           1 :         *pfunc = *func;
    2874             : 
    2875           1 :         if (pfunc->functionName) {
    2876           1 :                 pfunc->functionName = strdup(pfunc->functionName);
    2877             :         }
    2878           1 :         if (pfunc->requestName) {
    2879           1 :                 pfunc->requestName = strdup(pfunc->requestName);
    2880             :         }
    2881           1 :         if (pfunc->responseName) {
    2882           1 :                 pfunc->responseName = strdup(pfunc->responseName);
    2883             :         }
    2884             : 
    2885           1 :         if (pfunc->binding) {
    2886             :                 sdlBindingPtr tmp;
    2887             : 
    2888           2 :                 if ((tmp = zend_hash_str_find_ptr(ptr_map, (char*)&pfunc->binding, sizeof(pfunc->binding))) == NULL) {
    2889             :                         assert(0);
    2890             :                 }
    2891           1 :                 pfunc->binding = tmp;
    2892             : 
    2893           1 :                 if (pfunc->binding->bindingType == BINDING_SOAP && pfunc->bindingAttributes) {
    2894             :                         sdlSoapBindingFunctionPtr soap_binding;
    2895             : 
    2896           1 :                         soap_binding = malloc(sizeof(sdlSoapBindingFunction));
    2897           1 :                         memset(soap_binding, 0, sizeof(sdlSoapBindingFunction));
    2898           1 :                         *soap_binding = *(sdlSoapBindingFunctionPtr)pfunc->bindingAttributes;
    2899           1 :                         if (soap_binding->soapAction) {
    2900           1 :                                 soap_binding->soapAction = strdup(soap_binding->soapAction);
    2901             :                         }
    2902           1 :                         make_persistent_sdl_soap_body(&soap_binding->input, ptr_map);
    2903           1 :                         make_persistent_sdl_soap_body(&soap_binding->output, ptr_map);
    2904           1 :                         pfunc->bindingAttributes = soap_binding;
    2905             :                 }
    2906             : 
    2907           1 :                 if (pfunc->requestParameters) {
    2908           1 :                         pfunc->requestParameters = make_persistent_sdl_parameters(pfunc->requestParameters, ptr_map);
    2909             :                 }
    2910           1 :                 if (pfunc->responseParameters) {
    2911           1 :                         pfunc->responseParameters = make_persistent_sdl_parameters(pfunc->responseParameters, ptr_map);
    2912             :                 }
    2913           1 :                 if (pfunc->faults) {
    2914           0 :                         pfunc->faults = make_persistent_sdl_function_faults(pfunc, pfunc->faults, ptr_map);
    2915             :                 }
    2916             :         }
    2917             : 
    2918           1 :         return pfunc;
    2919             : }
    2920             : 
    2921           1 : static sdlPtr make_persistent_sdl(sdlPtr sdl)
    2922             : {
    2923           1 :         sdlPtr psdl = NULL;
    2924             :         HashTable ptr_map;
    2925             :         HashTable bp_types, bp_encoders;
    2926             :         zend_string *key;
    2927             : 
    2928           1 :         zend_hash_init(&bp_types, 0, NULL, NULL, 0);
    2929           1 :         zend_hash_init(&bp_encoders, 0, NULL, NULL, 0);
    2930           1 :         zend_hash_init(&ptr_map, 0, NULL, NULL, 0);
    2931             : 
    2932           1 :         psdl = malloc(sizeof(*sdl));
    2933           1 :         memset(psdl, 0, sizeof(*sdl));
    2934             : 
    2935           1 :         if (sdl->source) {
    2936           1 :                 psdl->source = strdup(sdl->source);
    2937             :         }
    2938           1 :         if (sdl->target_ns) {
    2939           1 :                 psdl->target_ns = strdup(sdl->target_ns);
    2940             :         }
    2941             : 
    2942           1 :         if (sdl->groups) {
    2943             :                 sdlTypePtr tmp;
    2944             :                 sdlTypePtr ptype;
    2945             : 
    2946           0 :                 psdl->groups = malloc(sizeof(HashTable));
    2947           0 :                 zend_hash_init(psdl->groups, zend_hash_num_elements(sdl->groups), NULL, delete_type_persistent, 1);
    2948             : 
    2949           0 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->groups, key, tmp) {
    2950           0 :                         ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders);
    2951           0 :                         if (key) {
    2952             :                                 /* We have to duplicate key emalloc->malloc */
    2953           0 :                                 zend_hash_str_add_ptr(psdl->groups, ZSTR_VAL(key), ZSTR_LEN(key), ptype);
    2954             :                         } else {
    2955           0 :                                 zend_hash_next_index_insert_ptr(psdl->groups, ptype);
    2956             :                         }
    2957           0 :                         zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), ptype);
    2958             :                 } ZEND_HASH_FOREACH_END();
    2959             :         }
    2960             : 
    2961           1 :         if (sdl->types) {
    2962             :                 sdlTypePtr tmp;
    2963             :                 sdlTypePtr ptype;
    2964             : 
    2965           1 :                 psdl->types = malloc(sizeof(HashTable));
    2966           1 :                 zend_hash_init(psdl->types, zend_hash_num_elements(sdl->types), NULL, delete_type_persistent, 1);
    2967             : 
    2968          17 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) {
    2969           8 :                         ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders);
    2970           8 :                         if (key) {
    2971             :                                 /* We have to duplicate key emalloc->malloc */
    2972           0 :                                 zend_hash_str_add_ptr(psdl->types, ZSTR_VAL(key), ZSTR_LEN(key), ptype);
    2973             :                         } else {
    2974           8 :                                 zend_hash_next_index_insert_ptr(psdl->types, ptype);
    2975             :                         }
    2976           8 :                         zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), ptype);
    2977             :                 } ZEND_HASH_FOREACH_END();
    2978             :         }
    2979             : 
    2980           1 :         if (sdl->elements) {
    2981             :                 sdlTypePtr tmp;
    2982             :                 sdlTypePtr ptype;
    2983             : 
    2984           0 :                 psdl->elements = malloc(sizeof(HashTable));
    2985           0 :                 zend_hash_init(psdl->elements, zend_hash_num_elements(sdl->elements), NULL, delete_type_persistent, 1);
    2986             : 
    2987           0 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->elements, key, tmp) {
    2988           0 :                         ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders);
    2989           0 :                         if (key) {
    2990             :                                 /* We have to duplicate key emalloc->malloc */
    2991           0 :                                 zend_hash_str_add_ptr(psdl->elements, ZSTR_VAL(key), ZSTR_LEN(key), ptype);
    2992             :                         } else {
    2993           0 :                                 zend_hash_next_index_insert_ptr(psdl->elements, ptype);
    2994             :                         }
    2995           0 :                         zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), ptype);
    2996             :                 } ZEND_HASH_FOREACH_END();
    2997             :         }
    2998             : 
    2999           1 :         if (sdl->encoders) {
    3000             :                 encodePtr tmp;
    3001             :                 encodePtr penc;
    3002             : 
    3003           1 :                 psdl->encoders = malloc(sizeof(HashTable));
    3004           1 :                 zend_hash_init(psdl->encoders, zend_hash_num_elements(sdl->encoders), NULL, delete_encoder_persistent, 1);
    3005             : 
    3006          17 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) {
    3007           8 :                         penc = make_persistent_sdl_encoder(tmp, &ptr_map, &bp_types, &bp_encoders);
    3008           8 :                         if (key) {
    3009             :                                 /* We have to duplicate key emalloc->malloc */
    3010           8 :                                 zend_hash_str_add_ptr(psdl->encoders, ZSTR_VAL(key), ZSTR_LEN(key), penc);
    3011             :                         } else {
    3012           0 :                                 zend_hash_next_index_insert_ptr(psdl->encoders, penc);
    3013             :                         }
    3014           8 :                         zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), penc);
    3015             :                 } ZEND_HASH_FOREACH_END();
    3016             :         }
    3017             : 
    3018             :         /* do backpatching here */
    3019           1 :         if (zend_hash_num_elements(&bp_types)) {
    3020           0 :                 sdlTypePtr *tmp, ptype = NULL;
    3021             : 
    3022           0 :                 ZEND_HASH_FOREACH_PTR(&bp_types, tmp) {
    3023           0 :                         if ((ptype = zend_hash_str_find_ptr(&ptr_map, (char*)tmp, sizeof(*tmp))) == NULL) {
    3024             :                                 assert(0);
    3025             :                         }
    3026           0 :                         *tmp = ptype;
    3027             :                 } ZEND_HASH_FOREACH_END();
    3028             :         }
    3029           1 :         if (zend_hash_num_elements(&bp_encoders)) {
    3030           1 :                 encodePtr *tmp, penc = NULL;
    3031             : 
    3032           7 :                 ZEND_HASH_FOREACH_PTR(&bp_encoders, tmp) {
    3033           6 :                         if ((penc = zend_hash_str_find_ptr(&ptr_map, (char*)tmp, sizeof(*tmp))) == NULL) {
    3034             :                                 assert(0);
    3035             :                         }
    3036           3 :                         *tmp = penc;
    3037             :                 } ZEND_HASH_FOREACH_END();
    3038             :         }
    3039             : 
    3040             : 
    3041           1 :         if (sdl->bindings) {
    3042             :                 sdlBindingPtr tmp;
    3043             :                 sdlBindingPtr pbind;
    3044             : 
    3045           1 :                 psdl->bindings = malloc(sizeof(HashTable));
    3046           1 :                 zend_hash_init(psdl->bindings, zend_hash_num_elements(sdl->bindings), NULL, delete_binding_persistent, 1);
    3047             : 
    3048           3 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->bindings, key, tmp) {
    3049           1 :                         pbind = make_persistent_sdl_binding(tmp, &ptr_map);
    3050           1 :                         if (key) {
    3051             :                                 /* We have to duplicate key emalloc->malloc */
    3052           1 :                                 zend_hash_str_add_ptr(psdl->bindings, ZSTR_VAL(key), ZSTR_LEN(key), pbind);
    3053             :                         } else {
    3054           0 :                                 zend_hash_next_index_insert_ptr(psdl->bindings, pbind);
    3055             :                         }
    3056           1 :                         zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), pbind);
    3057             :                 } ZEND_HASH_FOREACH_END();
    3058             :         }
    3059             : 
    3060           1 :         zend_hash_init(&psdl->functions, zend_hash_num_elements(&sdl->functions), NULL, delete_function_persistent, 1);
    3061           1 :         if (zend_hash_num_elements(&sdl->functions)) {
    3062             :                 sdlFunctionPtr tmp;
    3063             :                 sdlFunctionPtr pfunc;
    3064             : 
    3065           3 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(&sdl->functions, key, tmp) {
    3066           1 :                         pfunc = make_persistent_sdl_function(tmp, &ptr_map);
    3067           1 :                         if (key) {
    3068             :                                 /* We have to duplicate key emalloc->malloc */
    3069           1 :                                 zend_hash_str_add_ptr(&psdl->functions, ZSTR_VAL(key), ZSTR_LEN(key), pfunc);
    3070             :                         } else {
    3071           0 :                                 zend_hash_next_index_insert_ptr(&psdl->functions, pfunc);
    3072             :                         }
    3073           1 :                         zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), pfunc);
    3074             :                 } ZEND_HASH_FOREACH_END();
    3075             :         }
    3076             : 
    3077           1 :         if (sdl->requests) {
    3078             :                 zval *zv;
    3079             :                 sdlFunctionPtr tmp;
    3080             :                 sdlFunctionPtr preq;
    3081             : 
    3082           0 :                 psdl->requests = malloc(sizeof(HashTable));
    3083           0 :                 zend_hash_init(psdl->requests, zend_hash_num_elements(sdl->requests), NULL, NULL, 1);
    3084             : 
    3085           0 :                 ZEND_HASH_FOREACH_STR_KEY_VAL(sdl->requests, key, zv) {
    3086           0 :                         tmp = Z_PTR_P(zv);
    3087           0 :                         if ((preq = zend_hash_str_find_ptr(&ptr_map, (char*)&tmp, sizeof(tmp))) == NULL) {
    3088             :                                 assert(0);
    3089             :                         }
    3090           0 :                         Z_PTR_P(zv) = preq;
    3091           0 :                         if (key) {
    3092             :                                 /* We have to duplicate key emalloc->malloc */
    3093           0 :                                 zend_hash_str_add_ptr(psdl->requests, ZSTR_VAL(key), ZSTR_LEN(key), preq);
    3094             :                         }
    3095             :                 } ZEND_HASH_FOREACH_END();
    3096             :         }
    3097             : 
    3098           1 :         zend_hash_destroy(&ptr_map);
    3099           1 :         zend_hash_destroy(&bp_encoders);
    3100           1 :         zend_hash_destroy(&bp_types);
    3101             : 
    3102           1 :         return psdl;
    3103             : }
    3104             : 
    3105             : typedef struct _sdl_cache_bucket {
    3106             :         sdlPtr sdl;
    3107             :         time_t time;
    3108             : } sdl_cache_bucket;
    3109             : 
    3110           1 : static void delete_psdl_int(sdl_cache_bucket *p)
    3111             : {
    3112           1 :         sdlPtr tmp = p->sdl;
    3113             : 
    3114           1 :         zend_hash_destroy(&tmp->functions);
    3115           1 :         if (tmp->source) {
    3116           1 :                 free(tmp->source);
    3117             :         }
    3118           1 :         if (tmp->target_ns) {
    3119           1 :                 free(tmp->target_ns);
    3120             :         }
    3121           1 :         if (tmp->elements) {
    3122           0 :                 zend_hash_destroy(tmp->elements);
    3123           0 :                 free(tmp->elements);
    3124             :         }
    3125           1 :         if (tmp->encoders) {
    3126           1 :                 zend_hash_destroy(tmp->encoders);
    3127           1 :                 free(tmp->encoders);
    3128             :         }
    3129           1 :         if (tmp->types) {
    3130           1 :                 zend_hash_destroy(tmp->types);
    3131           1 :                 free(tmp->types);
    3132             :         }
    3133           1 :         if (tmp->groups) {
    3134           0 :                 zend_hash_destroy(tmp->groups);
    3135           0 :                 free(tmp->groups);
    3136             :         }
    3137           1 :         if (tmp->bindings) {
    3138           1 :                 zend_hash_destroy(tmp->bindings);
    3139           1 :                 free(tmp->bindings);
    3140             :         }
    3141           1 :         if (tmp->requests) {
    3142           0 :                 zend_hash_destroy(tmp->requests);
    3143           0 :                 free(tmp->requests);
    3144             :         }
    3145           1 :         free(tmp);
    3146           1 : }
    3147             : 
    3148           1 : static void delete_psdl(zval *zv)
    3149             : {
    3150           1 :         delete_psdl_int(Z_PTR_P(zv));
    3151           1 :         free(Z_PTR_P(zv));
    3152           1 : }
    3153             : 
    3154         721 : sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl)
    3155             : {
    3156             :         char  fn[MAXPATHLEN];
    3157         721 :         sdlPtr sdl = NULL;
    3158         721 :         char* old_error_code = SOAP_GLOBAL(error_code);
    3159         721 :         size_t uri_len = 0;
    3160         721 :         php_stream_context *context=NULL;
    3161             :         zval *tmp, *proxy_host, *proxy_port, orig_context, new_context;
    3162         721 :         smart_str headers = {0};
    3163         721 :         char* key = NULL;
    3164         721 :         time_t t = time(0);
    3165         721 :         zend_bool has_proxy_authorization = 0;
    3166         721 :         zend_bool has_authorization = 0;
    3167             : 
    3168         721 :         ZVAL_UNDEF(&orig_context);
    3169         721 :         ZVAL_UNDEF(&new_context);
    3170        1442 :         if (strchr(uri,':') != NULL || IS_ABSOLUTE_PATH(uri, uri_len)) {
    3171         721 :                 uri_len = strlen(uri);
    3172           0 :         } else if (VCWD_REALPATH(uri, fn) == NULL) {
    3173           0 :                 cache_wsdl = WSDL_CACHE_NONE;
    3174             :         } else {
    3175           0 :                 uri = fn;
    3176           0 :                 uri_len = strlen(uri);
    3177             :         }
    3178             : 
    3179         721 :         if ((cache_wsdl & WSDL_CACHE_MEMORY) && SOAP_GLOBAL(mem_cache)) {
    3180             :                 sdl_cache_bucket *p;
    3181             : 
    3182          18 :                 if (NULL != (p = zend_hash_str_find_ptr(SOAP_GLOBAL(mem_cache), uri, uri_len))) {
    3183           9 :                         if (p->time < t - SOAP_GLOBAL(cache_ttl)) {
    3184             :                                 /* in-memory cache entry is expired */
    3185           0 :                                 zend_hash_str_del(&EG(persistent_list), uri, uri_len);
    3186             :                         } else {
    3187           9 :                                 return p->sdl;
    3188             :                         }
    3189             :                 }
    3190             :         }
    3191             : 
    3192         712 :         if ((cache_wsdl & WSDL_CACHE_DISK) && (uri_len < MAXPATHLEN)) {
    3193           8 :                 time_t t = time(0);
    3194             :                 char md5str[33];
    3195             :                 PHP_MD5_CTX context;
    3196             :                 unsigned char digest[16];
    3197           8 :                 int len = strlen(SOAP_GLOBAL(cache_dir));
    3198             :                 time_t cached;
    3199           8 :                 char *user = php_get_current_user();
    3200           8 :                 int user_len = user ? strlen(user) + 1 : 0;
    3201             : 
    3202           8 :                 md5str[0] = '\0';
    3203           8 :                 PHP_MD5Init(&context);
    3204           8 :                 PHP_MD5Update(&context, (unsigned char*)uri, uri_len);
    3205           8 :                 PHP_MD5Final(digest, &context);
    3206           8 :                 make_digest(md5str, digest);
    3207           8 :                 key = emalloc(len+sizeof("/wsdl-")-1+user_len+sizeof(md5str));
    3208           8 :                 memcpy(key,SOAP_GLOBAL(cache_dir),len);
    3209           8 :                 memcpy(key+len,"/wsdl-",sizeof("/wsdl-")-1);
    3210           8 :                 len += sizeof("/wsdl-")-1;
    3211           8 :                 if (user_len) {
    3212           8 :                         memcpy(key+len, user, user_len-1);
    3213           8 :                         len += user_len-1;
    3214           8 :                         key[len++] = '-';
    3215             :                 }
    3216           8 :                 memcpy(key+len,md5str,sizeof(md5str));
    3217             : 
    3218           8 :                 if ((sdl = get_sdl_from_cache(key, uri, t-SOAP_GLOBAL(cache_ttl), &cached)) != NULL) {
    3219           2 :                         t = cached;
    3220           2 :                         efree(key);
    3221           2 :                         goto cache_in_memory;
    3222             :                 }
    3223             :         }
    3224             : 
    3225         710 :         if (NULL != (tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr),
    3226             :                         "_stream_context", sizeof("_stream_context")-1))) {
    3227           0 :                 context = php_stream_context_from_zval(tmp, 0);
    3228             :         } else {
    3229         710 :                 context = php_stream_context_alloc();
    3230             :         }
    3231             : 
    3232         710 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_user_agent", sizeof("_user_agent")-1)) != NULL &&
    3233           0 :             Z_TYPE_P(tmp) == IS_STRING && Z_STRLEN_P(tmp) > 0) {
    3234             :                 smart_str_appends(&headers, "User-Agent: ");
    3235           0 :                 smart_str_appends(&headers, Z_STRVAL_P(tmp));
    3236             :                 smart_str_appends(&headers, "\r\n");
    3237             :         }
    3238             : 
    3239         710 :         if ((proxy_host = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_proxy_host", sizeof("_proxy_host")-1)) != NULL &&
    3240             :             Z_TYPE_P(proxy_host) == IS_STRING &&
    3241           0 :             (proxy_port = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_proxy_port", sizeof("_proxy_port")-1)) != NULL &&
    3242             :             Z_TYPE_P(proxy_port) == IS_LONG) {
    3243             :                 zval str_port, str_proxy;
    3244           0 :                 smart_str proxy = {0};
    3245           0 :                 ZVAL_DUP(&str_port, proxy_port);
    3246           0 :                 convert_to_string(&str_port);
    3247             :                 smart_str_appends(&proxy,"tcp://");
    3248           0 :                 smart_str_appends(&proxy,Z_STRVAL_P(proxy_host));
    3249             :                 smart_str_appends(&proxy,":");
    3250           0 :                 smart_str_appends(&proxy,Z_STRVAL(str_port));
    3251             :                 smart_str_0(&proxy);
    3252             :                 zval_dtor(&str_port);
    3253           0 :                 ZVAL_NEW_STR(&str_proxy, proxy.s);
    3254             : 
    3255           0 :                 if (!context) {
    3256           0 :                         context = php_stream_context_alloc();
    3257             :                 }
    3258           0 :                 php_stream_context_set_option(context, "http", "proxy", &str_proxy);
    3259           0 :                 zval_ptr_dtor(&str_proxy);
    3260             : 
    3261           0 :                 if (uri_len < sizeof("https://")-1 ||
    3262           0 :                     strncasecmp(uri, "https://", sizeof("https://")-1) != 0) {
    3263           0 :                         ZVAL_TRUE(&str_proxy);
    3264           0 :                         php_stream_context_set_option(context, "http", "request_fulluri", &str_proxy);
    3265             :                 }
    3266             : 
    3267           0 :                 has_proxy_authorization = proxy_authentication(this_ptr, &headers);
    3268             :         }
    3269             : 
    3270         710 :         has_authorization = basic_authentication(this_ptr, &headers);
    3271             : 
    3272             :         /* Use HTTP/1.1 with "Connection: close" by default */
    3273         710 :         if ((tmp = php_stream_context_get_option(context, "http", "protocol_version")) == NULL) {
    3274             :         zval http_version;
    3275             : 
    3276         710 :                 ZVAL_DOUBLE(&http_version, 1.1);
    3277         710 :                 php_stream_context_set_option(context, "http", "protocol_version", &http_version);
    3278             :                 smart_str_appendl(&headers, "Connection: close\r\n", sizeof("Connection: close\r\n")-1);
    3279             :         }
    3280             : 
    3281         710 :         if (headers.s && ZSTR_LEN(headers.s) > 0) {
    3282             :                 zval str_headers;
    3283             : 
    3284         710 :                 if (!context) {
    3285           0 :                         context = php_stream_context_alloc();
    3286             :                 } else {
    3287         710 :                         http_context_headers(context, has_authorization, has_proxy_authorization, 0, &headers);
    3288             :                 }
    3289             : 
    3290             :                 smart_str_0(&headers);
    3291         710 :                 ZVAL_NEW_STR(&str_headers, headers.s);
    3292         710 :                 php_stream_context_set_option(context, "http", "header", &str_headers);
    3293         710 :                 zval_ptr_dtor(&str_headers);
    3294             :         }
    3295             : 
    3296         710 :         if (context) {
    3297         710 :                 php_stream_context_to_zval(context, &new_context);
    3298         710 :                 php_libxml_switch_context(&new_context, &orig_context);
    3299             :         }
    3300             : 
    3301         710 :         SOAP_GLOBAL(error_code) = "WSDL";
    3302             : 
    3303         710 :         sdl = load_wsdl(this_ptr, uri);
    3304         705 :         if (sdl) {
    3305         705 :                 sdl->is_persistent = 0;
    3306             :         }
    3307             : 
    3308         705 :         SOAP_GLOBAL(error_code) = old_error_code;
    3309             : 
    3310         705 :         if (context) {
    3311         705 :                 php_libxml_switch_context(&orig_context, NULL);
    3312         705 :                 zval_ptr_dtor(&new_context);
    3313             :         }
    3314             : 
    3315         705 :         if ((cache_wsdl & WSDL_CACHE_DISK) && key) {
    3316           5 :                 if (sdl) {
    3317           5 :                         add_sdl_to_cache(key, uri, t, sdl);
    3318             :                 }
    3319           5 :                 efree(key);
    3320             :         }
    3321             : 
    3322             : cache_in_memory:
    3323         707 :         if (cache_wsdl & WSDL_CACHE_MEMORY) {
    3324           1 :                 if (sdl) {
    3325             :                         sdlPtr psdl;
    3326             :                         sdl_cache_bucket p;
    3327             : 
    3328           1 :                         if (SOAP_GLOBAL(mem_cache) == NULL) {
    3329           1 :                                 SOAP_GLOBAL(mem_cache) = malloc(sizeof(HashTable));
    3330           1 :                                 zend_hash_init(SOAP_GLOBAL(mem_cache), 0, NULL, delete_psdl, 1);
    3331           0 :                         } else if (SOAP_GLOBAL(cache_limit) > 0 &&
    3332           0 :                                    SOAP_GLOBAL(cache_limit) <= (zend_long)zend_hash_num_elements(SOAP_GLOBAL(mem_cache))) {
    3333             :                                 /* in-memory cache overflow */
    3334             :                                 sdl_cache_bucket *q;
    3335           0 :                                 time_t latest = t;
    3336           0 :                                 zend_string *latest_key = NULL, *key;
    3337             : 
    3338           0 :                                 ZEND_HASH_FOREACH_STR_KEY_PTR(SOAP_GLOBAL(mem_cache), key, q) {
    3339           0 :                                         if (q->time < latest) {
    3340           0 :                                                 latest = q->time;
    3341           0 :                                                 latest_key = key;
    3342             :                                         }
    3343             :                                 } ZEND_HASH_FOREACH_END();
    3344           0 :                                 if (latest_key) {
    3345           0 :                                         zend_hash_del(SOAP_GLOBAL(mem_cache), latest_key);
    3346             :                                 } else {
    3347           0 :                                         return sdl;
    3348             :                                 }
    3349             :                         }
    3350             : 
    3351           1 :                         psdl = make_persistent_sdl(sdl);
    3352           1 :                         psdl->is_persistent = 1;
    3353           1 :                         p.time = t;
    3354           1 :                         p.sdl = psdl;
    3355             : 
    3356           2 :                         if (NULL != zend_hash_str_update_mem(SOAP_GLOBAL(mem_cache), uri,
    3357             :                                                                                         uri_len, &p, sizeof(sdl_cache_bucket))) {
    3358             :                                 /* remove non-persitent sdl structure */
    3359           1 :                                 delete_sdl_impl(sdl);
    3360             :                                 /* and replace it with persistent one */
    3361           1 :                                 sdl = psdl;
    3362             :                         } else {
    3363           0 :                                 php_error_docref(NULL, E_WARNING, "Failed to register persistent entry");
    3364             :                                 /* clean up persistent sdl */
    3365           0 :                                 delete_psdl_int(&p);
    3366             :                                 /* keep non-persistent sdl and return it */
    3367             :                         }
    3368             :                 }
    3369             :         }
    3370             : 
    3371         707 :         return sdl;
    3372             : }
    3373             : 
    3374             : /* Deletes */
    3375         707 : void delete_sdl_impl(void *handle)
    3376             : {
    3377         707 :         sdlPtr tmp = (sdlPtr)handle;
    3378             : 
    3379         707 :         zend_hash_destroy(&tmp->functions);
    3380         707 :         if (tmp->source) {
    3381         707 :                 efree(tmp->source);
    3382             :         }
    3383         707 :         if (tmp->target_ns) {
    3384         706 :                 efree(tmp->target_ns);
    3385             :         }
    3386         707 :         if (tmp->elements) {
    3387         279 :                 zend_hash_destroy(tmp->elements);
    3388         279 :                 efree(tmp->elements);
    3389             :         }
    3390         707 :         if (tmp->encoders) {
    3391         662 :                 zend_hash_destroy(tmp->encoders);
    3392         662 :                 efree(tmp->encoders);
    3393             :         }
    3394         707 :         if (tmp->types) {
    3395         681 :                 zend_hash_destroy(tmp->types);
    3396         681 :                 efree(tmp->types);
    3397             :         }
    3398         707 :         if (tmp->groups) {
    3399           2 :                 zend_hash_destroy(tmp->groups);
    3400           2 :                 efree(tmp->groups);
    3401             :         }
    3402         707 :         if (tmp->bindings) {
    3403         707 :                 zend_hash_destroy(tmp->bindings);
    3404         707 :                 efree(tmp->bindings);
    3405             :         }
    3406         707 :         if (tmp->requests) {
    3407           0 :                 zend_hash_destroy(tmp->requests);
    3408           0 :                 efree(tmp->requests);
    3409             :         }
    3410         707 :         efree(tmp);
    3411         707 : }
    3412             : 
    3413         716 : void delete_sdl(void *handle)
    3414             : {
    3415         716 :         sdlPtr tmp = (sdlPtr)handle;
    3416             : 
    3417         716 :         if (!tmp->is_persistent) {
    3418         706 :                 delete_sdl_impl(tmp);
    3419             :         }
    3420         716 : }
    3421             : 
    3422         863 : static void delete_binding(zval *zv)
    3423             : {
    3424         863 :         sdlBindingPtr binding = Z_PTR_P(zv);
    3425             : 
    3426         863 :         if (binding->location) {
    3427         863 :                 efree(binding->location);
    3428             :         }
    3429         863 :         if (binding->name) {
    3430         863 :                 efree(binding->name);
    3431             :         }
    3432             : 
    3433         863 :         if (binding->bindingType == BINDING_SOAP) {
    3434         862 :                 sdlSoapBindingPtr soapBind = binding->bindingAttributes;
    3435         862 :                 if (soapBind) {
    3436         862 :                         efree(soapBind);
    3437             :                 }
    3438             :         }
    3439         863 :         efree(binding);
    3440         863 : }
    3441             : 
    3442           1 : static void delete_binding_persistent(zval *zv)
    3443             : {
    3444           1 :         sdlBindingPtr binding = Z_PTR_P(zv);
    3445             : 
    3446           1 :         if (binding->location) {
    3447           1 :                 free(binding->location);
    3448             :         }
    3449           1 :         if (binding->name) {
    3450           1 :                 free(binding->name);
    3451             :         }
    3452             : 
    3453           1 :         if (binding->bindingType == BINDING_SOAP) {
    3454           1 :                 sdlSoapBindingPtr soapBind = binding->bindingAttributes;
    3455           1 :                 if (soapBind) {
    3456           1 :                         free(soapBind);
    3457             :                 }
    3458             :         }
    3459           1 :         free(binding);
    3460           1 : }
    3461             : 
    3462       15210 : static void delete_sdl_soap_binding_function_body(sdlSoapBindingFunctionBody body)
    3463             : {
    3464       15210 :         if (body.ns) {
    3465        6789 :                 efree(body.ns);
    3466             :         }
    3467       15210 :         if (body.headers) {
    3468         890 :                 zend_hash_destroy(body.headers);
    3469         890 :                 efree(body.headers);
    3470             :         }
    3471       15210 : }
    3472             : 
    3473           2 : static void delete_sdl_soap_binding_function_body_persistent(sdlSoapBindingFunctionBody body)
    3474             : {
    3475           2 :         if (body.ns) {
    3476           2 :                 free(body.ns);
    3477             :         }
    3478           2 :         if (body.headers) {
    3479           0 :                 zend_hash_destroy(body.headers);
    3480           0 :                 free(body.headers);
    3481             :         }
    3482           2 : }
    3483             : 
    3484        7606 : static void delete_function(zval *zv)
    3485             : {
    3486        7606 :         sdlFunctionPtr function = Z_PTR_P(zv);
    3487             : 
    3488        7606 :         if (function->functionName) {
    3489        7606 :                 efree(function->functionName);
    3490             :         }
    3491        7606 :         if (function->requestName) {
    3492        7606 :                 efree(function->requestName);
    3493             :         }
    3494        7606 :         if (function->responseName) {
    3495        7358 :                 efree(function->responseName);
    3496             :         }
    3497        7606 :         if (function->requestParameters) {
    3498        7605 :                 zend_hash_destroy(function->requestParameters);
    3499        7605 :                 efree(function->requestParameters);
    3500             :         }
    3501        7606 :         if (function->responseParameters) {
    3502        7358 :                 zend_hash_destroy(function->responseParameters);
    3503        7358 :                 efree(function->responseParameters);
    3504             :         }
    3505        7606 :         if (function->faults) {
    3506         684 :                 zend_hash_destroy(function->faults);
    3507         684 :                 efree(function->faults);
    3508             :         }
    3509             : 
    3510       22816 :         if (function->bindingAttributes &&
    3511       15210 :             function->binding && function->binding->bindingType == BINDING_SOAP) {
    3512        7605 :                 sdlSoapBindingFunctionPtr soapFunction = function->bindingAttributes;
    3513        7605 :                 if (soapFunction->soapAction) {
    3514        5922 :                         efree(soapFunction->soapAction);
    3515             :                 }
    3516        7605 :                 delete_sdl_soap_binding_function_body(soapFunction->input);
    3517        7605 :                 delete_sdl_soap_binding_function_body(soapFunction->output);
    3518        7605 :                 efree(soapFunction);
    3519             :         }
    3520        7606 :         efree(function);
    3521        7606 : }
    3522             : 
    3523           1 : static void delete_function_persistent(zval *zv)
    3524             : {
    3525           1 :         sdlFunctionPtr function = Z_PTR_P(zv);
    3526             : 
    3527           1 :         if (function->functionName) {
    3528           1 :                 free(function->functionName);
    3529             :         }
    3530           1 :         if (function->requestName) {
    3531           1 :                 free(function->requestName);
    3532             :         }
    3533           1 :         if (function->responseName) {
    3534           1 :                 free(function->responseName);
    3535             :         }
    3536           1 :         if (function->requestParameters) {
    3537           1 :                 zend_hash_destroy(function->requestParameters);
    3538           1 :                 free(function->requestParameters);
    3539             :         }
    3540           1 :         if (function->responseParameters) {
    3541           1 :                 zend_hash_destroy(function->responseParameters);
    3542           1 :                 free(function->responseParameters);
    3543             :         }
    3544           1 :         if (function->faults) {
    3545           0 :                 zend_hash_destroy(function->faults);
    3546           0 :                 free(function->faults);
    3547             :         }
    3548             : 
    3549           3 :         if (function->bindingAttributes &&
    3550           2 :             function->binding && function->binding->bindingType == BINDING_SOAP) {
    3551           1 :                 sdlSoapBindingFunctionPtr soapFunction = function->bindingAttributes;
    3552           1 :                 if (soapFunction->soapAction) {
    3553           1 :                         free(soapFunction->soapAction);
    3554             :                 }
    3555           1 :                 delete_sdl_soap_binding_function_body_persistent(soapFunction->input);
    3556           1 :                 delete_sdl_soap_binding_function_body_persistent(soapFunction->output);
    3557           1 :                 free(soapFunction);
    3558             :         }
    3559           1 :         free(function);
    3560           1 : }
    3561             : 
    3562       16046 : static void delete_parameter(zval *zv)
    3563             : {
    3564       16046 :         sdlParamPtr param = Z_PTR_P(zv);
    3565       16046 :         if (param->paramName) {
    3566       16046 :                 efree(param->paramName);
    3567             :         }
    3568       16046 :         efree(param);
    3569       16046 : }
    3570             : 
    3571           4 : static void delete_parameter_persistent(zval *zv)
    3572             : {
    3573           4 :         sdlParamPtr param = Z_PTR_P(zv);
    3574           4 :         if (param->paramName) {
    3575           4 :                 free(param->paramName);
    3576             :         }
    3577           4 :         free(param);
    3578           4 : }
    3579             : 
    3580        1621 : static void delete_header_int(sdlSoapBindingFunctionHeaderPtr hdr)
    3581             : {
    3582        1621 :         if (hdr->name) {
    3583        1621 :                 efree(hdr->name);
    3584             :         }
    3585        1621 :         if (hdr->ns) {
    3586        1612 :                 efree(hdr->ns);
    3587             :         }
    3588        1621 :         if (hdr->headerfaults) {
    3589          73 :                 zend_hash_destroy(hdr->headerfaults);
    3590          73 :                 efree(hdr->headerfaults);
    3591             :         }
    3592        1621 :         efree(hdr);
    3593        1621 : }
    3594             : 
    3595        1621 : static void delete_header(zval *zv)
    3596             : {
    3597        1621 :         delete_header_int(Z_PTR_P(zv));
    3598        1621 : }
    3599             : 
    3600           0 : static void delete_header_persistent(zval *zv)
    3601             : {
    3602           0 :         sdlSoapBindingFunctionHeaderPtr hdr = Z_PTR_P(zv);
    3603           0 :         if (hdr->name) {
    3604           0 :                 free(hdr->name);
    3605             :         }
    3606           0 :         if (hdr->ns) {
    3607           0 :                 free(hdr->ns);
    3608             :         }
    3609           0 :         if (hdr->headerfaults) {
    3610           0 :                 zend_hash_destroy(hdr->headerfaults);
    3611           0 :                 free(hdr->headerfaults);
    3612             :         }
    3613           0 :         free(hdr);
    3614           0 : }
    3615             : 
    3616        1212 : static void delete_fault(zval *zv)
    3617             : {
    3618        1212 :         sdlFaultPtr fault = Z_PTR_P(zv);
    3619        1212 :         if (fault->name) {
    3620        1212 :                 efree(fault->name);
    3621             :         }
    3622        1212 :         if (fault->details) {
    3623        1212 :                 zend_hash_destroy(fault->details);
    3624        1212 :                 efree(fault->details);
    3625             :         }
    3626        1212 :         if (fault->bindingAttributes) {
    3627        1178 :                 sdlSoapBindingFunctionFaultPtr binding = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
    3628             : 
    3629        1178 :                 if (binding->ns) {
    3630         610 :                         efree(binding->ns);
    3631             :                 }
    3632        1178 :                 efree(fault->bindingAttributes);
    3633             :         }
    3634        1212 :         efree(fault);
    3635        1212 : }
    3636             : 
    3637           0 : static void delete_fault_persistent(zval *zv)
    3638             : {
    3639           0 :         sdlFaultPtr fault = Z_PTR_P(zv);
    3640           0 :         if (fault->name) {
    3641           0 :                 free(fault->name);
    3642             :         }
    3643           0 :         if (fault->details) {
    3644           0 :                 zend_hash_destroy(fault->details);
    3645           0 :                 free(fault->details);
    3646             :         }
    3647           0 :         if (fault->bindingAttributes) {
    3648           0 :                 sdlSoapBindingFunctionFaultPtr binding = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
    3649             : 
    3650           0 :                 if (binding->ns) {
    3651           0 :                         free(binding->ns);
    3652             :                 }
    3653           0 :                 free(fault->bindingAttributes);
    3654             :         }
    3655           0 :         free(fault);
    3656           0 : }
    3657             : 
    3658         728 : static void delete_document(zval *zv)
    3659             : {
    3660         728 :         xmlDocPtr doc = Z_PTR_P(zv);
    3661         728 :         xmlFreeDoc(doc);
    3662         728 : }
    3663             : 

Generated by: LCOV version 1.10

Generated at Wed, 24 Aug 2016 12:20:29 +0000 (5 hours ago)

Copyright © 2005-2016 The PHP Group
All rights reserved.