]> granicus.if.org Git - php/commitdiff
Free XML documents after WSDL parsing (they no longer need).
authorDmitry Stogov <dmitry@php.net>
Fri, 6 Feb 2004 11:56:03 +0000 (11:56 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 6 Feb 2004 11:56:03 +0000 (11:56 +0000)
ext/soap/php_encoding.c
ext/soap/php_encoding.h
ext/soap/php_schema.c
ext/soap/php_schema.h
ext/soap/php_sdl.c
ext/soap/php_sdl.h
ext/soap/php_soap.h
ext/soap/soap.c

index f4341eccb9029a2c450b567b32e1578b1ac6cf8a..3a7f3a243c70a5fba87935a31db2474f0f9b48a9 100644 (file)
@@ -1381,7 +1381,7 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod
 
        if (Z_TYPE_P(data) == IS_ARRAY) {
                sdlAttributePtr *arrayType;
-               xmlAttrPtr *arrayTypeAttr;
+               sdlExtraAttributePtr *ext;
                sdlTypePtr elementType;
 
                i = zend_hash_num_elements(Z_ARRVAL_P(data));
@@ -1391,24 +1391,21 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod
                    zend_hash_find(sdl_type->attributes, SOAP_1_1_ENC_NAMESPACE":arrayType",
                      sizeof(SOAP_1_1_ENC_NAMESPACE":arrayType"),
                      (void **)&arrayType) == SUCCESS &&
-                   zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arrayType", sizeof(WSDL_NAMESPACE":arrayType"), (void **)&arrayTypeAttr) == SUCCESS) {
+                   zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arrayType", sizeof(WSDL_NAMESPACE":arrayType"), (void **)&ext) == SUCCESS) {
 
-                       char *ns = NULL, *value, *end;
-                       xmlNsPtr myNs;
+                       char *value, *end;
                        zval** el;
 
-                       parse_namespace((*arrayTypeAttr)->children->content, &value, &ns);
-                       myNs = xmlSearchNs((*arrayTypeAttr)->doc, (*arrayTypeAttr)->parent, ns);
-
+                       value = estrdup((*ext)->val);
                        end = strrchr(value,'[');
                        if (end) {
                                *end = '\0';
                                end++;
                                dimension = calc_dimension(end);
                        }
-                       if (myNs != NULL) {
-                               enc = get_encoder(SOAP_GLOBAL(sdl), myNs->href, value);
-                               get_type_str(xmlParam, myNs->href, value, &array_type);
+                       if ((*ext)->ns != NULL) {
+                               enc = get_encoder(SOAP_GLOBAL(sdl), (*ext)->ns, value);
+                               get_type_str(xmlParam, (*ext)->ns, value, &array_type);
                        } else {
                                smart_str_appends(&array_type, value);
                        }
@@ -1434,38 +1431,25 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod
                        }
 
                        efree(value);
-                       if (ns) efree(ns);
 
                } else if (sdl_type &&
                           sdl_type->attributes &&
                           zend_hash_find(sdl_type->attributes, SOAP_1_2_ENC_NAMESPACE":itemType",
                             sizeof(SOAP_1_2_ENC_NAMESPACE":itemType"),
                             (void **)&arrayType) == SUCCESS &&
-                          zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":itemType", sizeof(WSDL_NAMESPACE":itemType"), (void **)&arrayTypeAttr) == SUCCESS) {
-                       char *name, *ns;
-                       xmlNsPtr nsptr;
-                       xmlAttrPtr attr;
-
-                       attr = *arrayTypeAttr;
-                       parse_namespace(attr->children->content, &name, &ns);
-                       nsptr = xmlSearchNs(attr->doc, attr->parent, ns);
-
-                       if (nsptr != NULL) {
-                               enc = get_encoder(SOAP_GLOBAL(sdl), nsptr->href, name);
-                               get_type_str(xmlParam, nsptr->href, name, &array_type);
+                          zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":itemType", sizeof(WSDL_NAMESPACE":itemType"), (void **)&ext) == SUCCESS) {
+                       if ((*ext)->ns != NULL) {
+                               enc = get_encoder(SOAP_GLOBAL(sdl), (*ext)->ns, (*ext)->val);
+                               get_type_str(xmlParam, (*ext)->ns, (*ext)->val, &array_type);
                        } else {
-                               smart_str_appends(&array_type, name);
+                               smart_str_appends(&array_type, (*ext)->val);
                        }
-                       efree(name);
-                       if (ns) {efree(ns);}
                        if (zend_hash_find(sdl_type->attributes, SOAP_1_2_ENC_NAMESPACE":arraySize",
                                           sizeof(SOAP_1_2_ENC_NAMESPACE":arraySize"),
                                           (void **)&arrayType) == SUCCESS &&
-                           zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arraySize", sizeof(WSDL_NAMESPACE":arraysize"), (void **)&arrayTypeAttr) == SUCCESS) {
-                               attr = *arrayTypeAttr;
-
-                               dimension = calc_dimension_12(attr->children->content);
-                               dims = get_position_12(dimension, attr->children->content);
+                           zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arraySize", sizeof(WSDL_NAMESPACE":arraysize"), (void **)&ext) == SUCCESS) {
+                               dimension = calc_dimension_12((*ext)->val);
+                               dims = get_position_12(dimension, (*ext)->val);
                                if (dims[0] == 0) {dims[0] = i;}
 
                                smart_str_append_long(&array_size, dims[0]);
@@ -1483,13 +1467,9 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod
                           zend_hash_find(sdl_type->attributes, SOAP_1_2_ENC_NAMESPACE":arraySize",
                             sizeof(SOAP_1_2_ENC_NAMESPACE":arraySize"),
                             (void **)&arrayType) == SUCCESS &&
-                          zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arraySize", sizeof(WSDL_NAMESPACE":arraySize"), (void **)&arrayTypeAttr) == SUCCESS) {
-                       xmlAttrPtr attr;
-
-                       attr = *arrayTypeAttr;
-
-                       dimension = calc_dimension_12(attr->children->content);
-                       dims = get_position_12(dimension, attr->children->content);
+                          zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arraySize", sizeof(WSDL_NAMESPACE":arraySize"), (void **)&ext) == SUCCESS) {
+                       dimension = calc_dimension_12((*ext)->val);
+                       dims = get_position_12(dimension, (*ext)->val);
                        if (dims[0] == 0) {dims[0] = i;}
 
                        smart_str_append_long(&array_size, dims[0]);
@@ -1575,9 +1555,10 @@ static zval *to_zval_array(encodeTypePtr type, xmlNodePtr data)
        int dimension = 1;
        int* dims = NULL;
        int* pos = NULL;
-       xmlAttrPtr attr, *tmp;
+       xmlAttrPtr attr;        
        sdlPtr sdl;
        sdlAttributePtr *arrayType;
+       sdlExtraAttributePtr *ext;
        sdlTypePtr elementType;
 
        TSRMLS_FETCH();
@@ -1641,23 +1622,19 @@ static zval *to_zval_array(encodeTypePtr type, xmlNodePtr data)
                   zend_hash_find(type->sdl_type->attributes, SOAP_1_1_ENC_NAMESPACE":arrayType",
                                  sizeof(SOAP_1_1_ENC_NAMESPACE":arrayType"),
                                  (void **)&arrayType) == SUCCESS &&
-                  zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arrayType", sizeof(WSDL_NAMESPACE":arrayType"), (void **)&tmp) == SUCCESS) {
-               char *type, *end, *ns;
-               xmlNsPtr nsptr;
-
-               attr = *tmp;
-               parse_namespace(attr->children->content, &type, &ns);
-               nsptr = xmlSearchNs(attr->doc, attr->parent, ns);
+                  zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arrayType", sizeof(WSDL_NAMESPACE":arrayType"), (void **)&ext) == SUCCESS) {
+               char *type, *end;
 
+               type = estrdup((*ext)->val);
                end = strrchr(type,'[');
                if (end) {
                        *end = '\0';
                }
-               if (nsptr != NULL) {
-                       enc = get_encoder(SOAP_GLOBAL(sdl), nsptr->href, type);
+               if ((*ext)->ns != NULL) {
+                       enc = get_encoder(SOAP_GLOBAL(sdl), (*ext)->ns, type);
                }
                efree(type);
-               if (ns) {efree(ns);}
+
                dims = emalloc(sizeof(int));
                *dims = 0;
 
@@ -1666,28 +1643,18 @@ static zval *to_zval_array(encodeTypePtr type, xmlNodePtr data)
                   zend_hash_find(type->sdl_type->attributes, SOAP_1_2_ENC_NAMESPACE":itemType",
                                  sizeof(SOAP_1_2_ENC_NAMESPACE":itemType"),
                                  (void **)&arrayType) == SUCCESS &&
-                  zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":itemType", sizeof(WSDL_NAMESPACE":itemType"), (void **)&tmp) == SUCCESS) {
-
-               char *name, *ns;
-               xmlNsPtr nsptr;
-
-               attr = *tmp;
-               parse_namespace(attr->children->content, &name, &ns);
-               nsptr = xmlSearchNs(attr->doc, attr->parent, ns);
+                  zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":itemType", sizeof(WSDL_NAMESPACE":itemType"), (void **)&ext) == SUCCESS) {
 
-               if (nsptr != NULL) {
-                       enc = get_encoder(SOAP_GLOBAL(sdl), nsptr->href, name);
+               if ((*ext)->ns != NULL) {
+                       enc = get_encoder(SOAP_GLOBAL(sdl), (*ext)->ns, (*ext)->val);
                }
-               efree(name);
-               if (ns) {efree(ns);}
 
                if (zend_hash_find(type->sdl_type->attributes, SOAP_1_2_ENC_NAMESPACE":arraySize",
                                   sizeof(SOAP_1_2_ENC_NAMESPACE":arraySize"),
                                   (void **)&arrayType) == SUCCESS &&
-                   zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arraySize", sizeof(WSDL_NAMESPACE":arraysize"), (void **)&tmp) == SUCCESS) {
-                       attr = *tmp;
-                       dimension = calc_dimension_12(attr->children->content);
-                       dims = get_position_12(dimension, attr->children->content);
+                   zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arraySize", sizeof(WSDL_NAMESPACE":arraysize"), (void **)&ext) == SUCCESS) {
+                       dimension = calc_dimension_12((*ext)->val);
+                       dims = get_position_12(dimension, (*ext)->val);
                } else {
                        dims = emalloc(sizeof(int));
                        *dims = 0;
@@ -1697,11 +1664,10 @@ static zval *to_zval_array(encodeTypePtr type, xmlNodePtr data)
                   zend_hash_find(type->sdl_type->attributes, SOAP_1_2_ENC_NAMESPACE":arraySize",
                                  sizeof(SOAP_1_2_ENC_NAMESPACE":arraySize"),
                                  (void **)&arrayType) == SUCCESS &&
-                  zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arraySize", sizeof(WSDL_NAMESPACE":arraysize"), (void **)&tmp) == SUCCESS) {
+                  zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arraySize", sizeof(WSDL_NAMESPACE":arraysize"), (void **)&ext) == SUCCESS) {
 
-               attr = *tmp;
-               dimension = calc_dimension_12(attr->children->content);
-               dims = get_position_12(dimension, attr->children->content);
+               dimension = calc_dimension_12((*ext)->val);
+               dims = get_position_12(dimension, (*ext)->val);
                if (type->sdl_type && type->sdl_type->elements &&
                    zend_hash_num_elements(type->sdl_type->elements) == 1 &&
                    (elementType = *(sdlTypePtr*)type->sdl_type->elements->pListHead->pData) != NULL &&
@@ -2373,7 +2339,7 @@ xmlNsPtr encode_add_ns(xmlNodePtr node, const char* ns)
                char* prefix;
                TSRMLS_FETCH();
 
-               if (zend_hash_find(SOAP_GLOBAL(defEncNs), (char*)ns, strlen(ns) + 1, (void **)&prefix) == SUCCESS) {
+               if (zend_hash_find(&SOAP_GLOBAL(defEncNs), (char*)ns, strlen(ns) + 1, (void **)&prefix) == SUCCESS) {
                        xmlns = xmlNewNs(node->doc->children,ns,prefix);
                } else {
                        smart_str prefix = {0};
index 4673d3ee0ee2dd4b2ffccd70fd8afe25c8fc051e..47069d102031c4e089e6b4ac5b863762c5c88cc2 100644 (file)
@@ -203,9 +203,9 @@ void whiteSpace_collapse(char* str);
 xmlNodePtr sdl_guess_convert_xml(encodeTypePtr enc, zval* data, int style, xmlNodePtr parent);
 zval *sdl_guess_convert_zval(encodeTypePtr enc, xmlNodePtr data);
 
-#define get_conversion(e) get_conversion_ex(SOAP_GLOBAL(defEncIndex), e)
-#define get_conversion_from_type(n, t) get_conversion_from_type_ex(SOAP_GLOBAL(defEnc), n, t)
-#define get_conversion_from_href_type(t) get_conversion_from_href_type_ex(SOAP_GLOBAL(defEnc), t, strlen(t))
+#define get_conversion(e) get_conversion_ex(&SOAP_GLOBAL(defEncIndex), e)
+#define get_conversion_from_type(n, t) get_conversion_from_type_ex(&SOAP_GLOBAL(defEnc), n, t)
+#define get_conversion_from_href_type(t) get_conversion_from_href_type_ex(&SOAP_GLOBAL(defEnc), t, strlen(t))
 
 void encode_reset_ns();
 xmlNsPtr encode_add_ns(xmlNodePtr node, const char* ns);
index 2af3d67303df86cdf02bee55983e2e59bea91cd1..5fe7037249ed8621ca77f9f880ea99a3cf25de83 100644 (file)
@@ -37,17 +37,18 @@ static int schema_choice(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr choiceType, sdlT
 static int schema_group(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr groupType, sdlTypePtr cur_type, sdlContentModelPtr model);
 static int schema_any(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr extType, sdlTypePtr cur_type, sdlContentModelPtr model);
 static int schema_element(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr element, sdlTypePtr cur_type, sdlContentModelPtr model);
-static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdlTypePtr cur_type);
-static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdlTypePtr cur_type);
+static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdlTypePtr cur_type, sdlCtx *ctx);
+static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdlTypePtr cur_type, sdlCtx *ctx);
 
 static int schema_restriction_var_int(xmlNodePtr val, sdlRestrictionIntPtr *valptr);
 
 static int schema_restriction_var_char(xmlNodePtr val, sdlRestrictionCharPtr *valptr);
 
-static void schema_type_fixup(sdlPtr sdl, sdlTypePtr type);
+static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type);
 
 static void delete_model(void *handle);
 static void delete_type(void *data);
+static void delete_extra_attribute(void *attribute);
 static void delete_attribute(void *attribute);
 static void delete_restriction_var_int(void *rvi);
 static void delete_schema_restriction_var_char(void *srvc);
@@ -115,9 +116,9 @@ static encodePtr get_create_encoder(sdlPtr sdl, sdlTypePtr cur_type, const char
        return enc;
 }
 
-static void schema_load_file(sdlPtr sdl, xmlAttrPtr ns, xmlChar *location, xmlAttrPtr tns, int import) {
+static void schema_load_file(sdlCtx *ctx, xmlAttrPtr ns, xmlChar *location, xmlAttrPtr tns, int import) {
        if (location != NULL &&
-           !zend_hash_exists(&sdl->docs, location, strlen(location)+1)) {
+           !zend_hash_exists(&ctx->docs, location, strlen(location)+1)) {
                xmlDocPtr doc;
                xmlNodePtr schema;
                xmlAttrPtr new_tns;
@@ -153,8 +154,8 @@ static void schema_load_file(sdlPtr sdl, xmlAttrPtr ns, xmlChar *location, xmlAt
                                php_error(E_ERROR, "SOAP-ERROR: Parsing Schema: can't include schema from '%s', different 'targetNamespace'",location);
                        }
                }
-               zend_hash_add(&sdl->docs, location, strlen(location)+1, (void**)&doc, sizeof(xmlDocPtr), NULL);
-               load_schema(sdl, schema);
+               zend_hash_add(&ctx->docs, location, strlen(location)+1, (void**)&doc, sizeof(xmlDocPtr), NULL);
+               load_schema(ctx, schema);
        }
 }
 
@@ -178,18 +179,22 @@ static void schema_load_file(sdlPtr sdl, xmlAttrPtr ns, xmlChar *location, xmlAt
   Content: ((include | import | redefine | annotation)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*)
 </schema>
 */
-int load_schema(sdlPtr sdl,xmlNodePtr schema)
+int load_schema(sdlCtx *ctx,xmlNodePtr schema)
 {
        xmlNodePtr trav;
        xmlAttrPtr tns;
 
-       if (!sdl->types) {
-               sdl->types = malloc(sizeof(HashTable));
-               zend_hash_init(sdl->types, 0, NULL, delete_type, 1);
+       if (!ctx->sdl->types) {
+               ctx->sdl->types = malloc(sizeof(HashTable));
+               zend_hash_init(ctx->sdl->types, 0, NULL, delete_type, 1);
        }
-       if (!sdl->elements) {
-               sdl->elements = malloc(sizeof(HashTable));
-               zend_hash_init(sdl->elements, 0, NULL, delete_type, 1);
+       if (!ctx->attributes) {
+               ctx->attributes = emalloc(sizeof(HashTable));
+               zend_hash_init(ctx->attributes, 0, NULL, delete_attribute, 0);
+       }
+       if (!ctx->attributeGroups) {
+               ctx->attributeGroups = emalloc(sizeof(HashTable));
+               zend_hash_init(ctx->attributeGroups, 0, NULL, delete_type, 0);
        }
 
        tns = get_attribute(schema->properties, "targetNamespace");
@@ -212,7 +217,7 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
                        uri = xmlBuildURI(location->children->content, base);
                            xmlFree(base);
                                }
-                               schema_load_file(sdl,NULL,uri,tns,0);
+                               schema_load_file(ctx,NULL,uri,tns,0);
                    xmlFree(uri);
                        }
 
@@ -232,7 +237,7 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
                        uri = xmlBuildURI(location->children->content, base);
                            xmlFree(base);
                                }
-                               schema_load_file(sdl,NULL,uri,tns,0);
+                               schema_load_file(ctx,NULL,uri,tns,0);
                    xmlFree(uri);
                                /* TODO: <redefine> support */
                        }
@@ -257,7 +262,7 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
                            xmlFree(base);
                                }
                        }
-                       schema_load_file(sdl,ns,uri,tns,1);
+                       schema_load_file(ctx,ns,uri,tns,1);
                  if (uri != NULL) {xmlFree(uri);}
                } else if (node_is_equal(trav,"annotation")) {
                        /* TODO: <annotation> support */
@@ -276,17 +281,17 @@ int load_schema(sdlPtr sdl,xmlNodePtr schema)
 
        while (trav != NULL) {
                if (node_is_equal(trav,"simpleType")) {
-                       schema_simpleType(sdl, tns, trav, NULL);
+                       schema_simpleType(ctx->sdl, tns, trav, NULL);
                } else if (node_is_equal(trav,"complexType")) {
-                       schema_complexType(sdl, tns, trav, NULL);
+                       schema_complexType(ctx->sdl, tns, trav, NULL);
                } else if (node_is_equal(trav,"group")) {
-                       schema_group(sdl, tns, trav, NULL, NULL);
+                       schema_group(ctx->sdl, tns, trav, NULL, NULL);
                } else if (node_is_equal(trav,"attributeGroup")) {
-                       schema_attributeGroup(sdl, tns, trav, NULL);
+                       schema_attributeGroup(ctx->sdl, tns, trav, NULL, ctx);
                } else if (node_is_equal(trav,"element")) {
-                       schema_element(sdl, tns, trav, NULL, NULL);
+                       schema_element(ctx->sdl, tns, trav, NULL, NULL);
                } else if (node_is_equal(trav,"attribute")) {
-                       schema_attribute(sdl, tns, trav, NULL);
+                       schema_attribute(ctx->sdl, tns, trav, NULL, ctx);
                } else if (node_is_equal(trav,"notation")) {
                        /* TODO: <notation> support */
                } else if (node_is_equal(trav,"annotation")) {
@@ -703,9 +708,9 @@ static int schema_restriction_simpleContent(sdlPtr sdl, xmlAttrPtr tsn, xmlNodeP
        if (!simpleType) {
                while (trav != NULL) {
                        if (node_is_equal(trav,"attribute")) {
-                               schema_attribute(sdl, tsn, trav, cur_type);
+                               schema_attribute(sdl, tsn, trav, cur_type, NULL);
                        } else if (node_is_equal(trav,"attributeGroup")) {
-                               schema_attributeGroup(sdl, tsn, trav, cur_type);
+                               schema_attributeGroup(sdl, tsn, trav, cur_type, NULL);
                        } else if (node_is_equal(trav,"anyAttribute")) {
                                /* TODO: <anyAttribute> support */
                                trav = trav->next;
@@ -774,9 +779,9 @@ static int schema_restriction_complexContent(sdlPtr sdl, xmlAttrPtr tsn, xmlNode
        }
        while (trav != NULL) {
                if (node_is_equal(trav,"attribute")) {
-                       schema_attribute(sdl, tsn, trav, cur_type);
+                       schema_attribute(sdl, tsn, trav, cur_type, NULL);
                } else if (node_is_equal(trav,"attributeGroup")) {
-                       schema_attributeGroup(sdl, tsn, trav, cur_type);
+                       schema_attributeGroup(sdl, tsn, trav, cur_type, NULL);
                } else if (node_is_equal(trav,"anyAttribute")) {
                        /* TODO: <anyAttribute> support */
                        trav = trav->next;
@@ -884,9 +889,9 @@ static int schema_extension_simpleContent(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr
        }
        while (trav != NULL) {
                if (node_is_equal(trav,"attribute")) {
-                       schema_attribute(sdl, tsn, trav, cur_type);
+                       schema_attribute(sdl, tsn, trav, cur_type, NULL);
                } else if (node_is_equal(trav,"attributeGroup")) {
-                       schema_attributeGroup(sdl, tsn, trav, cur_type);
+                       schema_attributeGroup(sdl, tsn, trav, cur_type, NULL);
                } else if (node_is_equal(trav,"anyAttribute")) {
                        /* TODO: <anyAttribute> support */
                        trav = trav->next;
@@ -954,9 +959,9 @@ static int schema_extension_complexContent(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePt
        }
        while (trav != NULL) {
                if (node_is_equal(trav,"attribute")) {
-                       schema_attribute(sdl, tsn, trav, cur_type);
+                       schema_attribute(sdl, tsn, trav, cur_type, NULL);
                } else if (node_is_equal(trav,"attributeGroup")) {
-                       schema_attributeGroup(sdl, tsn, trav, cur_type);
+                       schema_attributeGroup(sdl, tsn, trav, cur_type, NULL);
                } else if (node_is_equal(trav,"anyAttribute")) {
                        /* TODO: <anyAttribute> support */
                        trav = trav->next;
@@ -1452,9 +1457,9 @@ static int schema_complexType(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr compType, s
                        }
                        while (trav != NULL) {
                                if (node_is_equal(trav,"attribute")) {
-                                       schema_attribute(sdl, tsn, trav, cur_type);
+                                       schema_attribute(sdl, tsn, trav, cur_type, NULL);
                                } else if (node_is_equal(trav,"attributeGroup")) {
-                                       schema_attributeGroup(sdl, tsn, trav, cur_type);
+                                       schema_attributeGroup(sdl, tsn, trav, cur_type, NULL);
                                } else if (node_is_equal(trav,"anyAttribute")) {
                                        /* TODO: <anyAttribute> support */
                                        trav = trav->next;
@@ -1542,6 +1547,10 @@ static int schema_element(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr element, sdlTyp
                newType->nillable = FALSE;
 
                if (cur_type == NULL) {
+                       if (sdl->elements == NULL) {
+                               sdl->elements = malloc(sizeof(HashTable));
+                               zend_hash_init(sdl->elements, 0, NULL, delete_type, 1);
+                       }
                        addHash = sdl->elements;
                        smart_str_appends(&key, newType->namens);
                        smart_str_appendc(&key, ':');
@@ -1701,7 +1710,7 @@ static int schema_element(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr element, sdlTyp
   Content: (annotation?, (simpleType?))
 </attribute>
 */
-static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdlTypePtr cur_type)
+static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdlTypePtr cur_type, sdlCtx *ctx)
 {
        sdlAttributePtr newAttr;
        xmlAttrPtr attr, name, ref = NULL, type = NULL;
@@ -1749,11 +1758,7 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdl
                }
 
                if (cur_type == NULL) {
-                       if (sdl->attributes == NULL) {
-                               sdl->attributes = malloc(sizeof(HashTable));
-                               zend_hash_init(sdl->attributes, 0, NULL, delete_attribute, 1);
-                       }
-                       addHash = sdl->attributes;
+                       addHash = ctx->attributes;
                } else {
                        if (cur_type->attributes == NULL) {
                                cur_type->attributes = malloc(sizeof(HashTable));
@@ -1825,17 +1830,33 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdl
 
                        if (strncmp(nsPtr->href, SCHEMA_NAMESPACE, sizeof(SCHEMA_NAMESPACE))) {
                                smart_str key2 = {0};
+                               sdlExtraAttributePtr ext;
+                               xmlNsPtr nsptr;
+                               char *value, *ns;
+
+                               ext = malloc(sizeof(sdlExtraAttribute));
+                               memset(ext, 0, sizeof(sdlExtraAttribute));
+                               parse_namespace(attr->children->content, &value, &ns);
+                               nsptr = xmlSearchNs(attr->doc, attr->parent, ns);
+                               if (nsptr) {
+                                       ext->ns = strdup(nsptr->href);
+                                       ext->val = strdup(value);
+                               } else {
+                                       ext->val = strdup(attr->children->content);
+                               }
+                               if (ns) {efree(ns);}
+                               efree(value);
 
                                if (!newAttr->extraAttributes) {
                                        newAttr->extraAttributes = malloc(sizeof(HashTable));
-                                       zend_hash_init(newAttr->extraAttributes, 0, NULL, NULL, 1);
+                                       zend_hash_init(newAttr->extraAttributes, 0, NULL, delete_extra_attribute, 1);
                                }
 
                                smart_str_appends(&key2, nsPtr->href);
                                smart_str_appendc(&key2, ':');
                                smart_str_appends(&key2, attr->name);
                                smart_str_0(&key2);
-                               zend_hash_add(newAttr->extraAttributes, key2.c, key2.len + 1, &attr, sizeof(xmlAttrPtr), NULL);
+                               zend_hash_add(newAttr->extraAttributes, key2.c, key2.len + 1, &ext, sizeof(sdlExtraAttributePtr), NULL);
                                smart_str_free(&key2);
                        }
                }
@@ -1871,7 +1892,7 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdl
        return TRUE;
 }
 
-static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrGroup, sdlTypePtr cur_type)
+static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrGroup, sdlTypePtr cur_type, sdlCtx *ctx)
 {
        xmlNodePtr trav;
        xmlAttrPtr name, ref = NULL;
@@ -1887,11 +1908,6 @@ static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrGrou
                        sdlTypePtr newType;
                        smart_str key = {0};
 
-                       if (sdl->attributeGroups == NULL) {
-                               sdl->attributeGroups = malloc(sizeof(HashTable));
-                               zend_hash_init(sdl->attributeGroups, 0, NULL, delete_type, 1);
-                       }
-
                        ns = get_attribute(attrGroup->properties, "targetNamespace");
                        if (ns == NULL) {
                                ns = tsn;
@@ -1906,7 +1922,7 @@ static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrGrou
                        smart_str_appends(&key, newType->name);
                        smart_str_0(&key);
 
-                       if (zend_hash_add(sdl->attributeGroups, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), NULL) != SUCCESS) {
+                       if (zend_hash_add(ctx->attributeGroups, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), NULL) != SUCCESS) {
                                php_error(E_ERROR, "SOAP-ERROR: Parsing Schema: attributeGroup '%s' already defined", key.c);
                        }
                        cur_type = newType;
@@ -1950,12 +1966,12 @@ static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrGrou
                        if (ref != NULL) {
                                php_error(E_ERROR, "SOAP-ERROR: Parsing Schema: attributeGroup has both 'ref' attribute and subattribute");
                        }
-                       schema_attribute(sdl, tsn, trav, cur_type);
+                       schema_attribute(sdl, tsn, trav, cur_type, NULL);
                } else if (node_is_equal(trav,"attributeGroup")) {
                        if (ref != NULL) {
                                php_error(E_ERROR, "SOAP-ERROR: Parsing Schema: attributeGroup has both 'ref' attribute and subattribute");
                        }
-                       schema_attributeGroup(sdl, tsn, trav, cur_type);
+                       schema_attributeGroup(sdl, tsn, trav, cur_type, NULL);
                } else if (node_is_equal(trav,"anyAttribute")) {
                        if (ref != NULL) {
                                php_error(E_ERROR, "SOAP-ERROR: Parsing Schema: attributeGroup has both 'ref' attribute and subattribute");
@@ -1974,14 +1990,30 @@ static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrGrou
        return TRUE;
 }
 
-static void schema_attribute_fixup(sdlPtr sdl, sdlAttributePtr attr)
+static void copy_extra_attribute(void *attribute) 
+{
+       sdlExtraAttributePtr *attr = (sdlExtraAttributePtr*)attribute;
+       sdlExtraAttributePtr new_attr;
+
+       new_attr = malloc(sizeof(sdlExtraAttribute));
+       memcpy(new_attr, *attr, sizeof(sdlExtraAttribute));
+       *attr = new_attr;
+       if (new_attr->ns) {
+               new_attr->ns = strdup(new_attr->ns);
+       }
+       if (new_attr->val) {
+               new_attr->val = strdup(new_attr->val);
+       }
+}
+
+static void schema_attribute_fixup(sdlCtx *ctx, sdlAttributePtr attr)
 {
        sdlAttributePtr *tmp;
 
        if (attr->ref != NULL) {
-               if (sdl->attributes != NULL) {
-                       if (zend_hash_find(sdl->attributes, attr->ref, strlen(attr->ref)+1, (void**)&tmp) == SUCCESS) {
-                               schema_attribute_fixup(sdl, *tmp);
+               if (ctx->attributes != NULL) {
+                       if (zend_hash_find(ctx->attributes, attr->ref, strlen(attr->ref)+1, (void**)&tmp) == SUCCESS) {
+                               schema_attribute_fixup(ctx, *tmp);
                                if ((*tmp)->name != NULL && attr->name == NULL) {
                                        attr->name = strdup((*tmp)->name);
                                }
@@ -2001,9 +2033,8 @@ static void schema_attribute_fixup(sdlPtr sdl, sdlAttributePtr attr)
                                  xmlNodePtr node;
 
                                        attr->extraAttributes = malloc(sizeof(HashTable));
-
-                                       zend_hash_init(attr->extraAttributes, 0, NULL, NULL, 1);
-                                       zend_hash_copy(attr->extraAttributes, (*tmp)->extraAttributes, NULL, &node, sizeof(xmlNodePtr));
+                                       zend_hash_init(attr->extraAttributes, 0, NULL, delete_extra_attribute, 1);
+                                       zend_hash_copy(attr->extraAttributes, (*tmp)->extraAttributes, copy_extra_attribute, &node, sizeof(xmlNodePtr));
                                }
                                attr->encode = (*tmp)->encode;
                        }
@@ -2020,14 +2051,14 @@ static void schema_attribute_fixup(sdlPtr sdl, sdlAttributePtr attr)
        }
 }
 
-static void schema_attributegroup_fixup(sdlPtr sdl, sdlAttributePtr attr, HashTable *ht)
+static void schema_attributegroup_fixup(sdlCtx *ctx, sdlAttributePtr attr, HashTable *ht)
 {
        sdlTypePtr *tmp;
        sdlAttributePtr *tmp_attr;
 
        if (attr->ref != NULL) {
-               if (sdl->attributeGroups != NULL) {
-                       if (zend_hash_find(sdl->attributeGroups, attr->ref, strlen(attr->ref)+1, (void**)&tmp) == SUCCESS) {
+               if (ctx->attributeGroups != NULL) {
+                       if (zend_hash_find(ctx->attributeGroups, attr->ref, strlen(attr->ref)+1, (void**)&tmp) == SUCCESS) {
                                if ((*tmp)->attributes) {
                                        zend_hash_internal_pointer_reset((*tmp)->attributes);
                                        while (zend_hash_get_current_data((*tmp)->attributes,(void**)&tmp_attr) == SUCCESS) {
@@ -2036,7 +2067,7 @@ static void schema_attributegroup_fixup(sdlPtr sdl, sdlAttributePtr attr, HashTa
                                                        uint key_len;
                                                        sdlAttributePtr newAttr;
 
-                                                       schema_attribute_fixup(sdl,*tmp_attr);
+                                                       schema_attribute_fixup(ctx,*tmp_attr);
 
                                                        newAttr = malloc(sizeof(sdlAttribute));
                                                        memcpy(newAttr, *tmp_attr, sizeof(sdlAttribute));
@@ -2046,9 +2077,8 @@ static void schema_attributegroup_fixup(sdlPtr sdl, sdlAttributePtr attr, HashTa
                                                        if (newAttr->extraAttributes) {
                                                          xmlNodePtr node;
                                                                HashTable *ht = malloc(sizeof(HashTable));
-
-                                                               zend_hash_init(ht, 0, NULL, NULL, 1);
-                                                               zend_hash_copy(ht, newAttr->extraAttributes, NULL, &node, sizeof(xmlNodePtr));
+                                                               zend_hash_init(ht, 0, NULL, delete_extra_attribute, 1);
+                                                               zend_hash_copy(ht, newAttr->extraAttributes, copy_extra_attribute, &node, sizeof(xmlNodePtr));
                                                                newAttr->extraAttributes = ht;
                                                        }
 
@@ -2059,7 +2089,7 @@ static void schema_attributegroup_fixup(sdlPtr sdl, sdlAttributePtr attr, HashTa
                                                } else {
                                                        ulong index;
 
-                                                       schema_attributegroup_fixup(sdl,*tmp_attr, ht);
+                                                       schema_attributegroup_fixup(ctx,*tmp_attr, ht);
                                                        zend_hash_get_current_key((*tmp)->attributes, NULL, &index, 0);
                                                        zend_hash_index_del((*tmp)->attributes, index);
                                                }
@@ -2072,14 +2102,14 @@ static void schema_attributegroup_fixup(sdlPtr sdl, sdlAttributePtr attr, HashTa
        }
 }
 
-static void schema_content_model_fixup(sdlPtr sdl, sdlContentModelPtr model)
+static void schema_content_model_fixup(sdlCtx *ctx, sdlContentModelPtr model)
 {
        switch (model->kind) {
                case XSD_CONTENT_GROUP_REF: {
                        sdlTypePtr *tmp;
 
-                       if (sdl->groups && zend_hash_find(sdl->groups, model->u.group_ref, strlen(model->u.group_ref)+1, (void**)&tmp) == SUCCESS) {
-                               schema_type_fixup(sdl,*tmp);
+                       if (ctx->sdl->groups && zend_hash_find(ctx->sdl->groups, model->u.group_ref, strlen(model->u.group_ref)+1, (void**)&tmp) == SUCCESS) {
+                               schema_type_fixup(ctx,*tmp);
                                efree(model->u.group_ref);
                                model->kind = XSD_CONTENT_GROUP;
                                model->u.group = (*tmp)->model;
@@ -2095,7 +2125,7 @@ static void schema_content_model_fixup(sdlPtr sdl, sdlContentModelPtr model)
 
                        zend_hash_internal_pointer_reset(model->u.content);
                        while (zend_hash_get_current_data(model->u.content, (void**)&tmp) == SUCCESS) {
-                               schema_content_model_fixup(sdl, *tmp);
+                               schema_content_model_fixup(ctx, *tmp);
                                zend_hash_move_forward(model->u.content);
                        }
                        break;
@@ -2105,14 +2135,14 @@ static void schema_content_model_fixup(sdlPtr sdl, sdlContentModelPtr model)
        }
 }
 
-static void schema_type_fixup(sdlPtr sdl, sdlTypePtr type)
+static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type)
 {
        sdlTypePtr *tmp;
        sdlAttributePtr *attr;
 
        if (type->ref != NULL) {
-               if (sdl->elements != NULL) {
-                       if (zend_hash_find(sdl->elements, type->ref, strlen(type->ref)+1, (void**)&tmp) == SUCCESS) {
+               if (ctx->sdl->elements != NULL) {
+                       if (zend_hash_find(ctx->sdl->elements, type->ref, strlen(type->ref)+1, (void**)&tmp) == SUCCESS) {
                                type->encode = (*tmp)->encode;
                                /* TODO: nillable */
                        } else {
@@ -2125,23 +2155,23 @@ static void schema_type_fixup(sdlPtr sdl, sdlTypePtr type)
        if (type->elements) {
                zend_hash_internal_pointer_reset(type->elements);
                while (zend_hash_get_current_data(type->elements,(void**)&tmp) == SUCCESS) {
-                       schema_type_fixup(sdl,*tmp);
+                       schema_type_fixup(ctx,*tmp);
                        zend_hash_move_forward(type->elements);
                }
        }
        if (type->model) {
-               schema_content_model_fixup(sdl, type->model);
+               schema_content_model_fixup(ctx, type->model);
        }
        if (type->attributes) {
                zend_hash_internal_pointer_reset(type->attributes);
                while (zend_hash_get_current_data(type->attributes,(void**)&attr) == SUCCESS) {
                        if (zend_hash_get_current_key_type(type->attributes) == HASH_KEY_IS_STRING) {
-                               schema_attribute_fixup(sdl,*attr);
+                               schema_attribute_fixup(ctx,*attr);
                                zend_hash_move_forward(type->attributes);
                        } else {
                                ulong index;
 
-                               schema_attributegroup_fixup(sdl,*attr,type->attributes);
+                               schema_attributegroup_fixup(ctx,*attr,type->attributes);
                                zend_hash_get_current_key(type->attributes, NULL, &index, 0);
                                zend_hash_index_del(type->attributes, index);
                        }
@@ -2149,62 +2179,55 @@ static void schema_type_fixup(sdlPtr sdl, sdlTypePtr type)
        }
 }
 
-int schema_pass2(sdlPtr sdl)
+void schema_pass2(sdlCtx *ctx)
 {
+       sdlPtr sdl = ctx->sdl;
        sdlAttributePtr *attr;
        sdlTypePtr *type;
 
-       if (sdl->attributes) {
-               zend_hash_internal_pointer_reset(sdl->attributes);
-               while (zend_hash_get_current_data(sdl->attributes,(void**)&attr) == SUCCESS) {
-                       schema_attribute_fixup(sdl,*attr);
-                       zend_hash_move_forward(sdl->attributes);
+       if (ctx->attributes) {
+               zend_hash_internal_pointer_reset(ctx->attributes);
+               while (zend_hash_get_current_data(ctx->attributes,(void**)&attr) == SUCCESS) {
+                       schema_attribute_fixup(ctx,*attr);
+                       zend_hash_move_forward(ctx->attributes);
                }
        }
-       if (sdl->attributeGroups) {
-               zend_hash_internal_pointer_reset(sdl->attributeGroups);
-               while (zend_hash_get_current_data(sdl->attributeGroups,(void**)&type) == SUCCESS) {
-                       schema_type_fixup(sdl,*type);
-                       zend_hash_move_forward(sdl->attributeGroups);
+       if (ctx->attributeGroups) {
+               zend_hash_internal_pointer_reset(ctx->attributeGroups);
+               while (zend_hash_get_current_data(ctx->attributeGroups,(void**)&type) == SUCCESS) {
+                       schema_type_fixup(ctx,*type);
+                       zend_hash_move_forward(ctx->attributeGroups);
                }
        }
        if (sdl->elements) {
                zend_hash_internal_pointer_reset(sdl->elements);
                while (zend_hash_get_current_data(sdl->elements,(void**)&type) == SUCCESS) {
-                       schema_type_fixup(sdl,*type);
+                       schema_type_fixup(ctx,*type);
                        zend_hash_move_forward(sdl->elements);
                }
        }
        if (sdl->groups) {
                zend_hash_internal_pointer_reset(sdl->groups);
                while (zend_hash_get_current_data(sdl->groups,(void**)&type) == SUCCESS) {
-                       schema_type_fixup(sdl,*type);
+                       schema_type_fixup(ctx,*type);
                        zend_hash_move_forward(sdl->groups);
                }
        }
        if (sdl->types) {
                zend_hash_internal_pointer_reset(sdl->types);
                while (zend_hash_get_current_data(sdl->types,(void**)&type) == SUCCESS) {
-                       schema_type_fixup(sdl,*type);
+                       schema_type_fixup(ctx,*type);
                        zend_hash_move_forward(sdl->types);
                }
        }
-       return TRUE;
-}
-
-int schema_pass3(sdlPtr sdl)
-{
-       if (sdl->attributes) {
-               zend_hash_destroy(sdl->attributes);
-               free(sdl->attributes);
-               sdl->attributes = NULL;
+       if (ctx->attributes) {
+               zend_hash_destroy(ctx->attributes);
+               efree(ctx->attributes);
        }
-       if (sdl->attributeGroups) {
-               zend_hash_destroy(sdl->attributeGroups);
-               free(sdl->attributeGroups);
-               sdl->attributeGroups = NULL;
+       if (ctx->attributeGroups) {
+               zend_hash_destroy(ctx->attributeGroups);
+               efree(ctx->attributeGroups);
        }
-       return TRUE;
 }
 
 static void delete_model(void *handle)
@@ -2271,6 +2294,19 @@ static void delete_type(void *data)
        free(type);
 }
 
+static void delete_extra_attribute(void *attribute)
+{
+       sdlExtraAttributePtr attr = *((sdlExtraAttributePtr*)attribute);
+
+       if (attr->ns) {
+               free(attr->ns);
+       }
+       if (attr->val) {
+               free(attr->val);
+       }
+       free(attr);
+}
+
 static void delete_attribute(void *attribute)
 {
        sdlAttributePtr attr = *((sdlAttributePtr*)attribute);
@@ -2291,6 +2327,7 @@ static void delete_attribute(void *attribute)
                zend_hash_destroy(attr->extraAttributes);
                free(attr->extraAttributes);
        }
+       free(attr);
 }
 
 static void delete_restriction_var_int(void *rvi)
index 152227c9a10942bcee44f0629c42d1df4cb2e37a..7b121fae09059d30b4a7cfda7e6a06b80960da58 100644 (file)
@@ -22,8 +22,7 @@
 #ifndef PHP_SCHEMA_H
 #define PHP_SCHEMA_H
 
-int load_schema(sdlPtr sdl, xmlNodePtr schema);
-int schema_pass2(sdlPtr sdl);
-int schema_pass3(sdlPtr sdl);
+int load_schema(sdlCtx *ctx, xmlNodePtr schema);
+void schema_pass2(sdlCtx *ctx);
 
 #endif
index 1ceec6539b54dd970ea2c66497ce4b58484ab0c2..3e8607adc3ae787fa83d7371f06256ee0e72a174 100644 (file)
 #include "php_soap.h"
 #include "libxml/uri.h"
 
-typedef struct sdlCtx {
-       sdlPtr root;
-       HashTable messages;
-       HashTable bindings;
-       HashTable portTypes;
-       HashTable services;
-} sdlCtx;
-
 static void delete_binding(void *binding);
 static void delete_function(void *function);
 static void delete_paramater(void *paramater);
@@ -53,7 +45,7 @@ static sdlTypePtr get_element(sdlPtr sdl, xmlNodePtr node, const char *type)
        sdlTypePtr ret = NULL;
        TSRMLS_FETCH();
 
-       if (sdl && sdl->elements) {
+       if (sdl->elements) {
                xmlNsPtr nsptr;
                char *ns, *cptype;
                sdlTypePtr *sdl_type;
@@ -148,12 +140,12 @@ sdlBindingPtr get_binding_from_name(sdlPtr sdl, char *name, char *ns)
 
 static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
 {
-       sdlPtr tmpsdl = ctx->root;
+       sdlPtr tmpsdl = ctx->sdl;
        xmlDocPtr wsdl;
        xmlNodePtr root, definitions, trav;
        xmlAttrPtr targetNamespace;
 
-       if (zend_hash_exists(&tmpsdl->docs, struri, strlen(struri)+1)) {
+       if (zend_hash_exists(&ctx->docs, struri, strlen(struri)+1)) {
          return;
        }
 
@@ -165,7 +157,7 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
                php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Couldn't load from '%s'", struri);
        }
 
-       zend_hash_add(&tmpsdl->docs, struri, strlen(struri)+1, (void**)&wsdl, sizeof(xmlDocPtr), NULL);
+       zend_hash_add(&ctx->docs, struri, strlen(struri)+1, (void**)&wsdl, sizeof(xmlDocPtr), NULL);
 
        root = wsdl->children;
        definitions = get_node(root, "definitions");
@@ -173,7 +165,7 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
                if (include) {
                        xmlNodePtr schema = get_node(root, "schema");
                        if (schema) {
-                               load_schema(tmpsdl, schema);
+                               load_schema(ctx, schema);
                                return;
                        }
                }
@@ -195,7 +187,7 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
                        xmlNodePtr schema;
 
                        FOREACHNODE(trav2, "schema", schema) {
-                               load_schema(tmpsdl, schema);
+                               load_schema(ctx, schema);
                        }
                        ENDFOREACH(trav2);
 
@@ -333,11 +325,11 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap
 
                tmp = get_attribute(part->properties, "type");
                if (tmp != NULL) {
-                       h->encode = get_encoder_from_prefix(ctx->root, part, tmp->children->content);
+                       h->encode = get_encoder_from_prefix(ctx->sdl, part, tmp->children->content);
                } else {
                        tmp = get_attribute(part->properties, "element");
                        if (tmp != NULL) {
-                               h->element = get_element(ctx->root, part, tmp->children->content);
+                               h->element = get_element(ctx->sdl, part, tmp->children->content);
                                if (h->element) {
                                        h->encode = h->element->encode;
                                }
@@ -424,11 +416,11 @@ static HashTable* wsdl_message(sdlCtx *ctx, char* message_name)
 
                type = get_attribute(part->properties, "type");
                if (type != NULL) {
-                       param->encode = get_encoder_from_prefix(ctx->root, part, type->children->content);
+                       param->encode = get_encoder_from_prefix(ctx->sdl, part, type->children->content);
                } else {
                        element = get_attribute(part->properties, "element");
                        if (element != NULL) {
-                               param->element = get_element(ctx->root, part, element->children->content);
+                               param->element = get_element(ctx->sdl, part, element->children->content);
                                if (param->element) {
                                        param->encode = param->element->encode;
                                }
@@ -446,19 +438,20 @@ static sdlPtr load_wsdl(char *struri)
        sdlCtx ctx;
        int i,n;
 
-       ctx.root = malloc(sizeof(sdl));
-       memset(ctx.root, 0, sizeof(sdl));
-       ctx.root->source = strdup(struri);
-       zend_hash_init(&ctx.root->docs, 0, NULL, delete_document, 1);
-       zend_hash_init(&ctx.root->functions, 0, NULL, delete_function, 1);
+       memset(&ctx,0,sizeof(ctx));
+       ctx.sdl = malloc(sizeof(sdl));
+       memset(ctx.sdl, 0, sizeof(sdl));
+       ctx.sdl->source = strdup(struri);
+       zend_hash_init(&ctx.sdl->functions, 0, NULL, delete_function, 1);
 
+       zend_hash_init(&ctx.docs, 0, NULL, delete_document, 0);
        zend_hash_init(&ctx.messages, 0, NULL, NULL, 0);
        zend_hash_init(&ctx.bindings, 0, NULL, NULL, 0);
        zend_hash_init(&ctx.portTypes, 0, NULL, NULL, 0);
        zend_hash_init(&ctx.services,  0, NULL, NULL, 0);
 
        load_wsdl_ex(struri,&ctx, 0);
-       schema_pass2(ctx.root);
+       schema_pass2(&ctx);
 
        n = zend_hash_num_elements(&ctx.services);
        if (n > 0) {
@@ -705,28 +698,28 @@ static sdlPtr load_wsdl(char *struri)
                                                char *tmp = estrdup(function->functionName);
                                                int  len = strlen(tmp);
 
-                                               zend_hash_add(&ctx.root->functions, php_strtolower(tmp, len), len+1, &function, sizeof(sdlFunctionPtr), NULL);
+                                               zend_hash_add(&ctx.sdl->functions, php_strtolower(tmp, len), len+1, &function, sizeof(sdlFunctionPtr), NULL);
                                                efree(tmp);
                                                if (function->requestName != NULL && strcmp(function->requestName,function->functionName) != 0) {
-                                                       if (ctx.root->requests == NULL) {
-                                                               ctx.root->requests = malloc(sizeof(HashTable));
-                                                               zend_hash_init(ctx.root->requests, 0, NULL, NULL, 1);
+                                                       if (ctx.sdl->requests == NULL) {
+                                                               ctx.sdl->requests = malloc(sizeof(HashTable));
+                                                               zend_hash_init(ctx.sdl->requests, 0, NULL, NULL, 1);
                                                        }
                                                        tmp = estrdup(function->requestName);
                                                        len = strlen(tmp);
-                                                       zend_hash_add(ctx.root->requests, php_strtolower(tmp, len), len+1, &function, sizeof(sdlFunctionPtr), NULL);
+                                                       zend_hash_add(ctx.sdl->requests, php_strtolower(tmp, len), len+1, &function, sizeof(sdlFunctionPtr), NULL);
                                                        efree(tmp);
                                                }
                                        }
                                }
                                ENDFOREACH(trav2);
 
-                               if (!ctx.root->bindings) {
-                                       ctx.root->bindings = malloc(sizeof(HashTable));
-                                       zend_hash_init(ctx.root->bindings, 0, NULL, delete_binding, 1);
+                               if (!ctx.sdl->bindings) {
+                                       ctx.sdl->bindings = malloc(sizeof(HashTable));
+                                       zend_hash_init(ctx.sdl->bindings, 0, NULL, delete_binding, 1);
                                }
 
-                               zend_hash_add(ctx.root->bindings, tmpbinding->name, strlen(tmpbinding->name), &tmpbinding, sizeof(sdlBindingPtr), NULL);
+                               zend_hash_add(ctx.sdl->bindings, tmpbinding->name, strlen(tmpbinding->name), &tmpbinding, sizeof(sdlBindingPtr), NULL);
                        }
                        ENDFOREACH(trav);
 
@@ -736,13 +729,13 @@ static sdlPtr load_wsdl(char *struri)
                php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Couldn't bind to service");
        }
 
-       schema_pass3(ctx.root);
        zend_hash_destroy(&ctx.messages);
        zend_hash_destroy(&ctx.bindings);
        zend_hash_destroy(&ctx.portTypes);
        zend_hash_destroy(&ctx.services);
+       zend_hash_destroy(&ctx.docs);
 
-       return ctx.root;
+       return ctx.sdl;
 }
 
 sdlPtr get_sdl(char *uri)
@@ -767,7 +760,6 @@ void delete_sdl(void *handle)
 {
        sdlPtr tmp = *((sdlPtr*)handle);
 
-       zend_hash_destroy(&tmp->docs);
        zend_hash_destroy(&tmp->functions);
        if (tmp->source) {
                free(tmp->source);
@@ -775,6 +767,10 @@ void delete_sdl(void *handle)
        if (tmp->target_ns) {
                free(tmp->target_ns);
        }
+       if (tmp->elements) {
+               zend_hash_destroy(tmp->elements);
+               free(tmp->elements);
+       }
        if (tmp->encoders) {
                zend_hash_destroy(tmp->encoders);
                free(tmp->encoders);
@@ -783,18 +779,6 @@ void delete_sdl(void *handle)
                zend_hash_destroy(tmp->types);
                free(tmp->types);
        }
-       if (tmp->elements) {
-               zend_hash_destroy(tmp->elements);
-               free(tmp->elements);
-       }
-       if (tmp->attributes) {
-               zend_hash_destroy(tmp->attributes);
-               free(tmp->attributes);
-       }
-       if (tmp->attributeGroups) {
-               zend_hash_destroy(tmp->attributeGroups);
-               free(tmp->attributeGroups);
-       }
        if (tmp->groups) {
                zend_hash_destroy(tmp->groups);
                free(tmp->groups);
@@ -827,6 +811,7 @@ static void delete_binding(void *data)
                        free(soapBind->transport);
                }
        }
+       free(binding);
 }
 
 static void delete_sdl_soap_binding_function_body(sdlSoapBindingFunctionBody body)
@@ -874,6 +859,7 @@ static void delete_function(void *data)
                delete_sdl_soap_binding_function_body(soapFunction->output);
                delete_sdl_soap_binding_function_body(soapFunction->falut);
        }
+       free(function);
 }
 
 static void delete_paramater(void *data)
index 221c7e03efcdbf76120bcdc66c04ab5ccd663468..4b53b2b295b511405b76513bab0d7d10cb9adb87 100644 (file)
 #define SOAP_LITERAL 2
 
 struct _sdl {
-       HashTable  docs;             /* pointer to the parsed xml file */
        HashTable  functions;        /* array of sdlFunction */
        HashTable *types;            /* array of sdlTypesPtr */
        HashTable *elements;         /* array of sdlTypesPtr */
        HashTable *encoders;         /* array of encodePtr */
        HashTable *bindings;         /* array of sdlBindings (key'd by name) */
        HashTable *requests;         /* array of sdlFunction (references) */
-       HashTable *attributes;       /* array of sdlAttributePtr */
-       HashTable *attributeGroups;  /* array of sdlTypesPtr */
        HashTable *groups;           /* array of sdlTypesPtr */
        char      *target_ns;
        char      *source;
 };
 
+typedef struct sdlCtx {
+       sdlPtr     sdl;
+
+       HashTable  docs;             /* array of xmlDocPtr */
+
+       HashTable  messages;         /* array of xmlNodePtr */
+       HashTable  bindings;         /* array of xmlNodePtr */
+       HashTable  portTypes;        /* array of xmlNodePtr */
+       HashTable  services;         /* array of xmlNodePtr */
+
+       HashTable *attributes;       /* array of sdlAttributePtr */
+       HashTable *attributeGroups;  /* array of sdlTypesPtr */
+} sdlCtx;
+
 struct _sdlBinding {
        char *name;
        char *location;
@@ -192,6 +203,10 @@ typedef enum _sdlForm {
        XSD_FORM_UNQUALIFIED
 } sdlForm;
 
+typedef struct _sdlExtraAttribute {
+       char *ns;
+       char *val;
+} sdlExtraAttribute, *sdlExtraAttributePtr;
 
 struct _sdlAttribute {
        char      *name;
@@ -200,7 +215,7 @@ struct _sdlAttribute {
        char      *fixed;
        sdlForm    form;
        sdlUse     use;
-       HashTable *extraAttributes;                     /* array of xmlNodePtr */
+       HashTable *extraAttributes;                     /* array of sdlExtraAttribute */
        encodePtr  encode;
 };
 
index a0e48936f9165223375d30308d124c1b1fd88599..3986cc064c725c7dea6223afade5fc478dd64b20 100644 (file)
@@ -139,10 +139,9 @@ struct _soapService {
 #define SOAP_1_2_ACTOR_UNLIMATERECEIVER "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"
 
 ZEND_BEGIN_MODULE_GLOBALS(soap)
-       HashTable *defEncNs;
-       HashTable *defEncPrefix;
-       HashTable *defEnc;
-       HashTable *defEncIndex;
+       HashTable  defEncNs;     /* mapping of default namespaces to prefixes */
+       HashTable  defEnc;
+       HashTable  defEncIndex;
        HashTable *sdls;
        HashTable *overrides;
        int        cur_uniq_ns;
index 55082571b00d200919b516748c5631f83df71b4a..4ee1de533759e416bb2dcf1ccd17108510b1b936 100644 (file)
@@ -285,17 +285,9 @@ static void php_soap_init_globals(zend_soap_globals *soap_globals)
        soap_globals->sdls = malloc(sizeof(HashTable));
        zend_hash_init(soap_globals->sdls, 0, NULL, delete_sdl, 1);
 
-       soap_globals->defEnc = malloc(sizeof(HashTable));
-       zend_hash_init(soap_globals->defEnc, 0, NULL, NULL, 1);
-
-       soap_globals->defEncIndex = malloc(sizeof(HashTable));
-       zend_hash_init(soap_globals->defEncIndex, 0, NULL, NULL, 1);
-
-       soap_globals->defEncNs = malloc(sizeof(HashTable));
-       zend_hash_init(soap_globals->defEncNs, 0, NULL, NULL, 1);
-
-       soap_globals->defEncPrefix = malloc(sizeof(HashTable));
-       zend_hash_init(soap_globals->defEncPrefix, 0, NULL, NULL, 1);
+       zend_hash_init(&soap_globals->defEnc, 0, NULL, NULL, 1);
+       zend_hash_init(&soap_globals->defEncIndex, 0, NULL, NULL, 1);
+       zend_hash_init(&soap_globals->defEncNs, 0, NULL, NULL, 1);
 
        soap_globals->overrides = NULL;
 
@@ -309,29 +301,24 @@ static void php_soap_init_globals(zend_soap_globals *soap_globals)
                                char *ns_type;
                                ns_type = emalloc(strlen(defaultEncoding[i].details.ns) + strlen(defaultEncoding[i].details.type_str) + 2);
                                sprintf(ns_type, "%s:%s", defaultEncoding[i].details.ns, defaultEncoding[i].details.type_str);
-                               zend_hash_add(soap_globals->defEnc, ns_type, strlen(ns_type) + 1, &enc, sizeof(encodePtr), NULL);
+                               zend_hash_add(&soap_globals->defEnc, ns_type, strlen(ns_type) + 1, &enc, sizeof(encodePtr), NULL);
                                efree(ns_type);
                        } else {
-                               zend_hash_add(soap_globals->defEnc, defaultEncoding[i].details.type_str, strlen(defaultEncoding[i].details.type_str) + 1, &enc, sizeof(encodePtr), NULL);
+                               zend_hash_add(&soap_globals->defEnc, defaultEncoding[i].details.type_str, strlen(defaultEncoding[i].details.type_str) + 1, &enc, sizeof(encodePtr), NULL);
                        }
                }
                /* Index everything by number */
-               if (!zend_hash_index_exists(soap_globals->defEncIndex, defaultEncoding[i].details.type)) {
-                       zend_hash_index_update(soap_globals->defEncIndex, defaultEncoding[i].details.type, &enc, sizeof(encodePtr), NULL);
+               if (!zend_hash_index_exists(&soap_globals->defEncIndex, defaultEncoding[i].details.type)) {
+                       zend_hash_index_update(&soap_globals->defEncIndex, defaultEncoding[i].details.type, &enc, sizeof(encodePtr), NULL);
                }
                i++;
        } while (defaultEncoding[i].details.type != END_KNOWN_TYPES);
 
        /* hash by namespace */
-       zend_hash_add(soap_globals->defEncNs, XSD_1999_NAMESPACE, sizeof(XSD_1999_NAMESPACE), XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX), NULL);
-       zend_hash_add(soap_globals->defEncNs, XSD_NAMESPACE, sizeof(XSD_NAMESPACE), XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX), NULL);
-       zend_hash_add(soap_globals->defEncNs, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE), SOAP_1_1_ENC_NS_PREFIX, sizeof(SOAP_1_1_ENC_NS_PREFIX), NULL);
-       zend_hash_add(soap_globals->defEncNs, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE), SOAP_1_2_ENC_NS_PREFIX, sizeof(SOAP_1_2_ENC_NS_PREFIX), NULL);
-
-       /* and by prefix */
-       zend_hash_add(soap_globals->defEncPrefix, XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX), XSD_NAMESPACE, sizeof(XSD_NAMESPACE), NULL);
-       zend_hash_add(soap_globals->defEncPrefix, SOAP_1_1_ENC_NS_PREFIX, sizeof(SOAP_1_1_ENC_NS_PREFIX), SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE), NULL);
-       zend_hash_add(soap_globals->defEncPrefix, SOAP_1_2_ENC_NS_PREFIX, sizeof(SOAP_1_2_ENC_NS_PREFIX), SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE), NULL);
+       zend_hash_add(&soap_globals->defEncNs, XSD_1999_NAMESPACE, sizeof(XSD_1999_NAMESPACE), XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX), NULL);
+       zend_hash_add(&soap_globals->defEncNs, XSD_NAMESPACE, sizeof(XSD_NAMESPACE), XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX), NULL);
+       zend_hash_add(&soap_globals->defEncNs, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE), SOAP_1_1_ENC_NS_PREFIX, sizeof(SOAP_1_1_ENC_NS_PREFIX), NULL);
+       zend_hash_add(&soap_globals->defEncNs, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE), SOAP_1_2_ENC_NS_PREFIX, sizeof(SOAP_1_2_ENC_NS_PREFIX), NULL);
 
        soap_globals->use_soap_error_handler = 0;
        soap_globals->sdl = NULL;
@@ -341,11 +328,11 @@ static void php_soap_init_globals(zend_soap_globals *soap_globals)
 PHP_MSHUTDOWN_FUNCTION(soap)
 {
        zend_error_cb = old_error_handler;
+       zend_hash_destroy(&SOAP_GLOBAL(defEnc));
+       zend_hash_destroy(&SOAP_GLOBAL(defEncIndex));
+       zend_hash_destroy(&SOAP_GLOBAL(defEncNs));
        zend_hash_destroy(SOAP_GLOBAL(sdls));
-       zend_hash_destroy(SOAP_GLOBAL(defEnc));
-       zend_hash_destroy(SOAP_GLOBAL(defEncIndex));
-       zend_hash_destroy(SOAP_GLOBAL(defEncNs));
-       zend_hash_destroy(SOAP_GLOBAL(defEncPrefix));
+       free(SOAP_GLOBAL(sdls));
        return SUCCESS;
 }
 
@@ -618,7 +605,7 @@ PHP_METHOD(soapvar,soapvar)
        if (Z_TYPE_P(type) == IS_NULL) {
                add_property_long(this_ptr, "enc_type", UNKNOWN_TYPE);
        } else {
-               if (zend_hash_index_exists(SOAP_GLOBAL(defEncIndex), Z_LVAL_P(type))) {
+               if (zend_hash_index_exists(&SOAP_GLOBAL(defEncIndex), Z_LVAL_P(type))) {
                        add_property_long(this_ptr, "enc_type", Z_LVAL_P(type));
                } else {
                        php_error(E_ERROR, "Invalid type ID to SoapVar constructor");
@@ -1149,6 +1136,7 @@ PHP_METHOD(soapserver, handle)
                                        SOAP_GLOBAL(soap_version) = SOAP_1_2;
                                }
                        }
+                       xmlFreeDoc(doc_request);
                        php_error(E_ERROR,"DTD are not supported by SOAP");
                }