]> granicus.if.org Git - php/commitdiff
WSDL parsing speedup. Source cleanup.
authorDmitry Stogov <dmitry@php.net>
Thu, 5 Feb 2004 09:28:09 +0000 (09:28 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 5 Feb 2004 09:28:09 +0000 (09:28 +0000)
ext/soap/php_encoding.c
ext/soap/php_packet_soap.c
ext/soap/php_schema.c
ext/soap/php_sdl.c
ext/soap/php_soap.h
ext/soap/php_xml.c
ext/soap/php_xml.h
ext/soap/soap.c

index a0c9da9e450f187003d6af24a3f5c199d4ccfb15..2978990c027abb335a7cbb6b1b00423ebb8eedf1 100644 (file)
@@ -1731,9 +1731,6 @@ static zval *to_zval_array(encodeTypePtr type, xmlNodePtr data)
                }
                get_position_ex(dimension, tmp, &pos);
        }
-       if (enc == NULL) {
-               enc = get_conversion(UNKNOWN_TYPE);
-       }
 
        array_init(ret);
        trav = data->children;
@@ -1821,7 +1818,6 @@ static xmlNodePtr to_xml_map(encodeTypePtr type, zval *data, int style, xmlNodeP
                        zval **temp_data;
                        char *key_val;
                        int int_val;
-                       encodePtr enc;
 
                        zend_hash_get_current_data(data->value.ht, (void **)&temp_data);
                        if (Z_TYPE_PP(temp_data) != IS_NULL) {
@@ -1847,9 +1843,7 @@ static xmlNodePtr to_xml_map(encodeTypePtr type, zval *data, int style, xmlNodeP
                                        smart_str_free(&tmp);
                                }
 
-
-                               enc = get_conversion((*temp_data)->type);
-                               xparam = master_to_xml(enc, (*temp_data), style, item);
+                               xparam = master_to_xml(get_conversion((*temp_data)->type), (*temp_data), style, item);
 
                                xmlNodeSetName(xparam, "value");
                        }
@@ -1867,7 +1861,6 @@ static zval *to_zval_map(encodeTypePtr type, xmlNodePtr data)
 {
        zval *ret, *key, *value;
        xmlNodePtr trav, item, xmlKey, xmlValue;
-       encodePtr enc;
        TSRMLS_FETCH();
 
        MAKE_STD_ZVAL(ret);
@@ -1877,7 +1870,6 @@ static zval *to_zval_map(encodeTypePtr type, xmlNodePtr data)
                array_init(ret);
                trav = data->children;
 
-               enc = get_conversion(UNKNOWN_TYPE);
                trav = data->children;
                FOREACHNODE(trav, "item", item) {
                        xmlKey = get_node(item->children, "key");
@@ -1890,8 +1882,8 @@ static zval *to_zval_map(encodeTypePtr type, xmlNodePtr data)
                                php_error(E_ERROR, "SOAP-ERROR: Encoding: Can't decode apache map, missing value");
                        }
 
-                       key = master_to_zval(enc, xmlKey);
-                       value = master_to_zval(enc, xmlValue);
+                       key = master_to_zval(NULL, xmlKey);
+                       value = master_to_zval(NULL, xmlValue);
 
                        if (Z_TYPE_P(key) == IS_STRING) {
                                zend_hash_update(Z_ARRVAL_P(ret), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &value, sizeof(zval *), NULL);
@@ -2497,7 +2489,7 @@ static void get_array_type(xmlNodePtr node, zval *array, smart_str *type TSRMLS_
        HashTable *ht = HASH_OF(array);
        int i, count, cur_type, prev_type, different;
        zval **tmp;
-       char *prev_stype, *cur_stype, *prev_ns, *cur_ns;
+       char *prev_stype = NULL, *cur_stype = NULL, *prev_ns = NULL, *cur_ns = NULL;
 
        if (!array || Z_TYPE_P(array) != IS_ARRAY) {
                smart_str_appendl(type, "xsd:anyType", 11);
index 1df72f66ce7bf09057abb0ceb3c265da63c566ae..c3efe0b9d42fa77cf6df9d6a5c2a3bac482d592c 100644 (file)
@@ -29,20 +29,13 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction
        xmlNodePtr trav, env, head, body, resp, cur, fault;
        xmlAttrPtr attr;
        int param_count = 0;
-       int old_error_reporting;
-       int soap_version;
+       int soap_version = SOAP_1_1;
        HashTable *hdrs = NULL;
 
        ZVAL_NULL(return_value);
 
-       old_error_reporting = EG(error_reporting);
-       EG(error_reporting) &= ~(E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE);
-
        /* Parse XML packet */
-       response = xmlParseMemory(buffer, buffer_size);
-       xmlCleanupParser();
-
-       EG(error_reporting) = old_error_reporting;
+       response = soap_xmlParseMemory(buffer, buffer_size);
 
        if (!response) {
                add_soap_fault(this_ptr, "Client", "looks like we got no XML document", NULL, NULL TSRMLS_CC);
index cde1a8ef8653539e5c640947dcd7254455647f19..2af3d67303df86cdf02bee55983e2e59bea91cd1 100644 (file)
@@ -122,12 +122,10 @@ static void schema_load_file(sdlPtr sdl, xmlAttrPtr ns, xmlChar *location, xmlAt
                xmlNodePtr schema;
                xmlAttrPtr new_tns;
 
-               doc = xmlParseFile(location);
-               xmlCleanupParser();
+               doc = soap_xmlParseFile(location);
                if (doc == NULL) {
                        php_error(E_ERROR, "SOAP-ERROR: Parsing Schema: can't import schema from '%s'",location);
                }
-               cleanup_xml(doc);
                schema = get_node(doc->children, "schema");
                if (schema == NULL) {
                        xmlFreeDoc(doc);
@@ -666,29 +664,29 @@ static int schema_restriction_simpleContent(sdlPtr sdl, xmlAttrPtr tsn, xmlNodeP
                trav = trav->next;
        }
        while (trav != NULL) {
-               if (!strcmp(trav->name, "minExclusive")) {
+               if (node_is_equal(trav, "minExclusive")) {
                        schema_restriction_var_int(trav, &cur_type->restrictions->minExclusive);
-               } else if (!strcmp(trav->name, "minInclusive")) {
+               } else if (node_is_equal(trav, "minInclusive")) {
                        schema_restriction_var_int(trav, &cur_type->restrictions->minInclusive);
-               } else if (!strcmp(trav->name, "maxExclusive")) {
+               } else if (node_is_equal(trav, "maxExclusive")) {
                        schema_restriction_var_int(trav, &cur_type->restrictions->maxExclusive);
-               } else if (!strcmp(trav->name, "maxInclusive")) {
+               } else if (node_is_equal(trav, "maxInclusive")) {
                        schema_restriction_var_int(trav, &cur_type->restrictions->maxInclusive);
-               } else if (!strcmp(trav->name, "totalDigits")) {
+               } else if (node_is_equal(trav, "totalDigits")) {
                        schema_restriction_var_int(trav, &cur_type->restrictions->totalDigits);
-               } else if (!strcmp(trav->name, "fractionDigits")) {
+               } else if (node_is_equal(trav, "fractionDigits")) {
                        schema_restriction_var_int(trav, &cur_type->restrictions->fractionDigits);
-               } else if (!strcmp(trav->name, "length")) {
+               } else if (node_is_equal(trav, "length")) {
                        schema_restriction_var_int(trav, &cur_type->restrictions->length);
-               } else if (!strcmp(trav->name, "minLength")) {
+               } else if (node_is_equal(trav, "minLength")) {
                        schema_restriction_var_int(trav, &cur_type->restrictions->minLength);
-               } else if (!strcmp(trav->name, "maxLength")) {
+               } else if (node_is_equal(trav, "maxLength")) {
                        schema_restriction_var_int(trav, &cur_type->restrictions->maxLength);
-               } else if (!strcmp(trav->name, "whiteSpace")) {
+               } else if (node_is_equal(trav, "whiteSpace")) {
                        schema_restriction_var_char(trav, &cur_type->restrictions->whiteSpace);
-               } else if (!strcmp(trav->name, "pattern")) {
+               } else if (node_is_equal(trav, "pattern")) {
                        schema_restriction_var_char(trav, &cur_type->restrictions->pattern);
-               } else if (!strcmp(trav->name, "enumeration")) {
+               } else if (node_is_equal(trav, "enumeration")) {
                        sdlRestrictionCharPtr enumval = NULL;
 
                        schema_restriction_var_char(trav, &enumval);
@@ -807,8 +805,8 @@ static int schema_restriction_var_int(xmlNodePtr val, sdlRestrictionIntPtr *valp
        fixed = get_attribute(val->properties, "fixed");
        (*valptr)->fixed = FALSE;
        if (fixed != NULL) {
-               if (!strcmp(fixed->children->content, "true") ||
-                       !strcmp(fixed->children->content, "1"))
+               if (!strncmp(fixed->children->content, "true", sizeof("true")) ||
+                       !strncmp(fixed->children->content, "1", sizeof("1")))
                        (*valptr)->fixed = TRUE;
        }
 
@@ -834,8 +832,8 @@ static int schema_restriction_var_char(xmlNodePtr val, sdlRestrictionCharPtr *va
        fixed = get_attribute(val->properties, "fixed");
        (*valptr)->fixed = FALSE;
        if (fixed != NULL) {
-               if (!strcmp(fixed->children->content, "true") ||
-                   !strcmp(fixed->children->content, "1")) {
+               if (!strncmp(fixed->children->content, "true", sizeof("true")) ||
+                   !strncmp(fixed->children->content, "1", sizeof("1"))) {
                        (*valptr)->fixed = TRUE;
                }
        }
@@ -1009,7 +1007,7 @@ static int schema_all(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr all, sdlTypePtr cur
 
        attr = get_attribute(all->properties, "maxOccurs");
        if (attr) {
-               if (!strcmp(attr->children->content, "unbounded")) {
+               if (!strncmp(attr->children->content, "unbounded", sizeof("unbounded"))) {
                        newModel->max_occurs = -1;
                } else {
                        newModel->max_occurs = atoi(attr->children->content);
@@ -1131,7 +1129,7 @@ static int schema_group(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr groupType, sdlTyp
 
        attr = get_attribute(groupType->properties, "maxOccurs");
        if (attr) {
-               if (!strcmp(attr->children->content, "unbounded")) {
+               if (!strncmp(attr->children->content, "unbounded", sizeof("unbounded"))) {
                        newModel->max_occurs = -1;
                } else {
                        newModel->max_occurs = atoi(attr->children->content);
@@ -1209,7 +1207,7 @@ static int schema_choice(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr choiceType, sdlT
 
        attr = get_attribute(choiceType->properties, "maxOccurs");
        if (attr) {
-               if (!strcmp(attr->children->content, "unbounded")) {
+               if (!strncmp(attr->children->content, "unbounded", sizeof("unbounded"))) {
                        newModel->max_occurs = -1;
                } else {
                        newModel->max_occurs = atoi(attr->children->content);
@@ -1275,7 +1273,7 @@ static int schema_sequence(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr seqType, sdlTy
 
        attr = get_attribute(seqType->properties, "maxOccurs");
        if (attr) {
-               if (!strcmp(attr->children->content, "unbounded")) {
+               if (!strncmp(attr->children->content, "unbounded", sizeof("unbounded"))) {
                        newModel->max_occurs = -1;
                } else {
                        newModel->max_occurs = atoi(attr->children->content);
@@ -1577,7 +1575,7 @@ static int schema_element(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr element, sdlTyp
 
                        attr = get_attribute(attrs, "maxOccurs");
                        if (attr) {
-                               if (!strcmp(attr->children->content, "unbounded")) {
+                               if (!strncmp(attr->children->content, "unbounded", sizeof("unbounded"))) {
                                        newModel->max_occurs = -1;
                                } else {
                                        newModel->max_occurs = atoi(attr->children->content);
@@ -1797,9 +1795,9 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdl
                } else if (attr_is_equal_ex(attr, "fixed", SCHEMA_NAMESPACE)) {
                        newAttr->fixed = strdup(attr->children->content);
                } else if (attr_is_equal_ex(attr, "form", SCHEMA_NAMESPACE)) {
-                       if (strcmp(attr->children->content,"qualified") == 0) {
+                       if (strncmp(attr->children->content,"qualified",sizeof("qualified")) == 0) {
                          newAttr->form = XSD_FORM_QUALIFIED;
-                       } else if (strcmp(attr->children->content,"unqualified") == 0) {
+                       } else if (strncmp(attr->children->content,"unqualified",sizeof("unqualified")) == 0) {
                          newAttr->form = XSD_FORM_UNQUALIFIED;
                        } else {
                          newAttr->form = XSD_FORM_DEFAULT;
@@ -1813,11 +1811,11 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdl
                } else if (attr_is_equal_ex(attr, "type", SCHEMA_NAMESPACE)) {
                        /* already processed */
                } else if (attr_is_equal_ex(attr, "use", SCHEMA_NAMESPACE)) {
-                       if (strcmp(attr->children->content,"prohibited") == 0) {
+                       if (strncmp(attr->children->content,"prohibited",sizeof("prohibited")) == 0) {
                          newAttr->use = XSD_USE_PROHIBITED;
-                       } else if (strcmp(attr->children->content,"required") == 0) {
+                       } else if (strncmp(attr->children->content,"required",sizeof("required")) == 0) {
                          newAttr->use = XSD_USE_REQUIRED;
-                       } else if (strcmp(attr->children->content,"optional") == 0) {
+                       } else if (strncmp(attr->children->content,"optional",sizeof("optional")) == 0) {
                          newAttr->use = XSD_USE_OPTIONAL;
                        } else {
                          newAttr->use = XSD_USE_DEFAULT;
@@ -1825,7 +1823,7 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sdl
                } else {
                        xmlNsPtr nsPtr = attr_find_ns(attr);
 
-                       if (strcmp(nsPtr->href, SCHEMA_NAMESPACE)) {
+                       if (strncmp(nsPtr->href, SCHEMA_NAMESPACE, sizeof(SCHEMA_NAMESPACE))) {
                                smart_str key2 = {0};
 
                                if (!newAttr->extraAttributes) {
@@ -2009,7 +2007,7 @@ static void schema_attribute_fixup(sdlPtr sdl, sdlAttributePtr attr)
                                }
                                attr->encode = (*tmp)->encode;
                        }
-               } 
+               }
                if (attr->name == NULL && attr->ref != NULL) {
                        char *name, *ns;
                        parse_namespace(attr->ref, &name, &ns);
index 9dd4455823b977afebcdc3d9d2b4d927ea348270..1ceec6539b54dd970ea2c66497ce4b58484ab0c2 100644 (file)
@@ -45,9 +45,6 @@ encodePtr get_encoder_from_prefix(sdlPtr sdl, xmlNodePtr data, const char *type)
        if (enc == NULL && sdl) {
                enc = get_conversion_from_type_ex(sdl->encoders, data, type);
        }
-       if (enc == NULL) {
-               enc = get_conversion(UNKNOWN_TYPE);
-       }
        return enc;
 }
 
@@ -112,9 +109,6 @@ encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat)
        if (enc == NULL && sdl) {
                enc = get_conversion_from_href_type_ex(sdl->encoders, nscat, strlen(nscat));
        }
-       if (enc == NULL) {
-               enc = get_conversion(UNKNOWN_TYPE);
-       }
        return enc;
 }
 
@@ -158,8 +152,6 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
        xmlDocPtr wsdl;
        xmlNodePtr root, definitions, trav;
        xmlAttrPtr targetNamespace;
-       int old_error_reporting;
-       TSRMLS_FETCH();
 
        if (zend_hash_exists(&tmpsdl->docs, struri, strlen(struri)+1)) {
          return;
@@ -167,19 +159,11 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
 
        /* TODO: WSDL Caching */
 
-       old_error_reporting = EG(error_reporting);
-       EG(error_reporting) &= ~(E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE);
-
-       wsdl = xmlParseFile(struri);
-       xmlCleanupParser();
-
-       EG(error_reporting) = old_error_reporting;
-
+       wsdl = soap_xmlParseFile(struri);
 
        if (!wsdl) {
                php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Couldn't load from '%s'", struri);
        }
-       cleanup_xml(wsdl);
 
        zend_hash_add(&tmpsdl->docs, struri, strlen(struri)+1, (void**)&wsdl, sizeof(xmlDocPtr), NULL);
 
@@ -205,75 +189,71 @@ static void load_wsdl_ex(char *struri, sdlCtx *ctx, int include)
 
        trav = definitions->children;
        while (trav != NULL) {
-               if (trav->type == XML_ELEMENT_NODE) {
-                       if (strcmp(trav->name,"types") == 0) {
-                               /* TODO: Only one "types" is allowed */
-                               xmlNodePtr trav2 = trav->children;
-                               xmlNodePtr schema;
-                               FOREACHNODE(trav2, "schema", schema) {
-                                       load_schema(tmpsdl, schema);
-                               }
-                               ENDFOREACH(trav2);
+               if (node_is_equal(trav,"types")) {
+                       /* TODO: Only one "types" is allowed */
+                       xmlNodePtr trav2 = trav->children;
+                       xmlNodePtr schema;
 
-                       } else if (strcmp(trav->name,"import") == 0) {
-                               /* TODO: namespace ??? */
-                               xmlAttrPtr tmp = get_attribute(trav->properties, "location");
-                               if (tmp) {
-                                 xmlChar *uri;
-                                       xmlChar *base = xmlNodeGetBase(trav->doc, trav);
+                       FOREACHNODE(trav2, "schema", schema) {
+                               load_schema(tmpsdl, schema);
+                       }
+                       ENDFOREACH(trav2);
 
-                                       if (base == NULL) {
-                                   uri = xmlBuildURI(tmp->children->content, trav->doc->URL);
-                                       } else {
-                               uri = xmlBuildURI(tmp->children->content, base);
-                                   xmlFree(base);
-                                       }
-                                       load_wsdl_ex(uri, ctx, 1);
-                           xmlFree(uri);
-                               }
+               } else if (node_is_equal(trav,"import")) {
+                       /* TODO: namespace ??? */
+                       xmlAttrPtr tmp = get_attribute(trav->properties, "location");
+                       if (tmp) {
+                         xmlChar *uri;
+                               xmlChar *base = xmlNodeGetBase(trav->doc, trav);
 
-                       } else if (strcmp(trav->name,"message") == 0) {
-                               xmlAttrPtr name = get_attribute(trav->properties, "name");
-                               if (name && name->children && name->children->content) {
-                                       if (zend_hash_add(&ctx->messages, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
-                                               php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <message> '%s' already defined",name->children->content);
-                                       }
+                               if (base == NULL) {
+                           uri = xmlBuildURI(tmp->children->content, trav->doc->URL);
                                } else {
-                                       php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <message> hasn't name attribute");
+                       uri = xmlBuildURI(tmp->children->content, base);
+                           xmlFree(base);
                                }
+                               load_wsdl_ex(uri, ctx, 1);
+                   xmlFree(uri);
+                       }
 
-                       } else if (strcmp(trav->name,"portType") == 0) {
-                               xmlAttrPtr name = get_attribute(trav->properties, "name");
-                               if (name && name->children && name->children->content) {
-                                       if (zend_hash_add(&ctx->portTypes, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
-                                               php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <portType> '%s' already defined",name->children->content);
-                                       }
-                               } else {
-                                       php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <portType> hasn't name attribute");
+               } else if (node_is_equal(trav,"message")) {
+                       xmlAttrPtr name = get_attribute(trav->properties, "name");
+                       if (name && name->children && name->children->content) {
+                               if (zend_hash_add(&ctx->messages, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
+                                       php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <message> '%s' already defined",name->children->content);
                                }
+                       } else {
+                               php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <message> hasn't name attribute");
+                       }
 
-                       } else if (strcmp(trav->name,"binding") == 0) {
-                               xmlAttrPtr name = get_attribute(trav->properties, "name");
-                               if (name && name->children && name->children->content) {
-                                       if (zend_hash_add(&ctx->bindings, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
-                                               php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <binding> '%s' already defined",name->children->content);
-                                       }
-                               } else {
-                                       php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <binding> hasn't name attribute");
+               } else if (node_is_equal(trav,"portType")) {
+                       xmlAttrPtr name = get_attribute(trav->properties, "name");
+                       if (name && name->children && name->children->content) {
+                               if (zend_hash_add(&ctx->portTypes, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
+                                       php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <portType> '%s' already defined",name->children->content);
                                }
+                       } else {
+                               php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <portType> hasn't name attribute");
+                       }
 
-                       } else if (strcmp(trav->name,"service") == 0) {
-                               xmlAttrPtr name = get_attribute(trav->properties, "name");
-                               if (name && name->children && name->children->content) {
-                                       if (zend_hash_add(&ctx->services, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
-                                               php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <service> '%s' already defined",name->children->content);
-                                       }
-                               } else {
-                                       php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <service> hasn't name attribute");
+               } else if (node_is_equal(trav,"binding")) {
+                       xmlAttrPtr name = get_attribute(trav->properties, "name");
+                       if (name && name->children && name->children->content) {
+                               if (zend_hash_add(&ctx->bindings, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
+                                       php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <binding> '%s' already defined",name->children->content);
                                }
+                       } else {
+                               php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <binding> hasn't name attribute");
+                       }
 
+               } else if (node_is_equal(trav,"service")) {
+                       xmlAttrPtr name = get_attribute(trav->properties, "name");
+                       if (name && name->children && name->children->content) {
+                               if (zend_hash_add(&ctx->services, name->children->content, strlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
+                                       php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <service> '%s' already defined",name->children->content);
+                               }
                        } else {
-                         /* TODO: extensibility elements */
+                               php_error(E_ERROR,"SOAP-ERROR: Parsing WSDL: <service> hasn't name attribute");
                        }
                }
                trav = trav->next;
@@ -288,7 +268,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap
        body = get_node_ex(node->children, "body", wsdl_soap_namespace);
        if (body) {
                tmp = get_attribute(body->properties, "use");
-               if (tmp && !strcmp(tmp->children->content, "literal")) {
+               if (tmp && !strncmp(tmp->children->content, "literal", sizeof("literal"))) {
                        binding->use = SOAP_LITERAL;
                } else {
                        binding->use = SOAP_ENCODED;
@@ -307,8 +287,8 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap
                if (binding->use == SOAP_ENCODED) {
                        tmp = get_attribute(body->properties, "encodingStyle");
                        if (tmp &&
-                           strcmp(tmp->children->content,SOAP_1_1_ENC_NAMESPACE) != 0 &&
-                         strcmp(tmp->children->content,SOAP_1_2_ENC_NAMESPACE) != 0) {
+                           strncmp(tmp->children->content,SOAP_1_1_ENC_NAMESPACE,sizeof(SOAP_1_1_ENC_NAMESPACE)) != 0 &&
+                         strncmp(tmp->children->content,SOAP_1_2_ENC_NAMESPACE,sizeof(SOAP_1_2_ENC_NAMESPACE)) != 0) {
                                php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Unknown encodingStyle '%s'",tmp->children->content);
                        } else if (tmp == NULL) {
                                php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Unspecified encodingStyle");
@@ -365,7 +345,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap
                }
 
                tmp = get_attribute(header->properties, "use");
-               if (tmp && !strcmp(tmp->children->content, "encoded")) {
+               if (tmp && !strncmp(tmp->children->content, "encoded", sizeof("encoded"))) {
                        h->use = SOAP_ENCODED;
                } else {
                        h->use = SOAP_LITERAL;
@@ -379,8 +359,8 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap
                if (h->use == SOAP_ENCODED) {
                        tmp = get_attribute(header->properties, "encodingStyle");
                        if (tmp &&
-                           strcmp(tmp->children->content,SOAP_1_1_ENC_NAMESPACE) != 0 &&
-                           strcmp(tmp->children->content,SOAP_1_2_ENC_NAMESPACE) != 0) {
+                           strncmp(tmp->children->content,SOAP_1_1_ENC_NAMESPACE,sizeof(SOAP_1_1_ENC_NAMESPACE)) != 0 &&
+                           strncmp(tmp->children->content,SOAP_1_2_ENC_NAMESPACE,sizeof(SOAP_1_2_ENC_NAMESPACE)) != 0) {
                                php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Unknown encodingStyle '%s'",tmp->children->content);
                        } else if (tmp == NULL) {
                                php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Unspecified encodingStyle");
@@ -411,7 +391,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap
 
 static HashTable* wsdl_message(sdlCtx *ctx, char* message_name)
 {
-       xmlNodePtr trav, part, message, *tmp;
+       xmlNodePtr trav, part, message = NULL, *tmp;
        HashTable* parameters = NULL;
        char *ns, *ctype;
 
@@ -478,7 +458,6 @@ static sdlPtr load_wsdl(char *struri)
        zend_hash_init(&ctx.services,  0, NULL, NULL, 0);
 
        load_wsdl_ex(struri,&ctx, 0);
-
        schema_pass2(ctx.root);
 
        n = zend_hash_num_elements(&ctx.services);
@@ -521,25 +500,25 @@ static sdlPtr load_wsdl(char *struri)
 
                                tmpbinding->location = strdup(location->children->content);
 
-                               if (address->ns && !strcmp(address->ns->href, WSDL_SOAP11_NAMESPACE)) {
-                                       wsdl_soap_namespace = WSDL_SOAP11_NAMESPACE;
-                                       tmpbinding->bindingType = BINDING_SOAP;
-                               } else if (address->ns && !strcmp(address->ns->href, WSDL_SOAP12_NAMESPACE)) {
-                                       wsdl_soap_namespace = WSDL_SOAP12_NAMESPACE;
-                                       tmpbinding->bindingType = BINDING_SOAP;
-                               } else if (address->ns && !strcmp(address->ns->href, RPC_SOAP12_NAMESPACE)) {
-                                       wsdl_soap_namespace = RPC_SOAP12_NAMESPACE;
-                                       tmpbinding->bindingType = BINDING_SOAP;
-                               } else if (address->ns && !strcmp(address->ns->href, WSDL_HTTP11_NAMESPACE)) {
-                                       tmpbinding->bindingType = BINDING_HTTP;
-                               } else if (address->ns && !strcmp(address->ns->href, WSDL_HTTP12_NAMESPACE)) {
-                                       tmpbinding->bindingType = BINDING_HTTP;
-                               } else {
-                                       if (address->ns) {
-                                               php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: PHP-SOAP doesn't support binding '%s'",address->ns->href);
+                               if (address->ns) {
+                                       if (!strncmp(address->ns->href, WSDL_SOAP11_NAMESPACE, sizeof(WSDL_SOAP11_NAMESPACE))) {
+                                               wsdl_soap_namespace = WSDL_SOAP11_NAMESPACE;
+                                               tmpbinding->bindingType = BINDING_SOAP;
+                                       } else if (!strncmp(address->ns->href, WSDL_SOAP12_NAMESPACE, sizeof(WSDL_SOAP12_NAMESPACE))) {
+                                               wsdl_soap_namespace = WSDL_SOAP12_NAMESPACE;
+                                               tmpbinding->bindingType = BINDING_SOAP;
+                                       } else if (!strncmp(address->ns->href, RPC_SOAP12_NAMESPACE, sizeof(RPC_SOAP12_NAMESPACE))) {
+                                               wsdl_soap_namespace = RPC_SOAP12_NAMESPACE;
+                                               tmpbinding->bindingType = BINDING_SOAP;
+                                       } else if (!strncmp(address->ns->href, WSDL_HTTP11_NAMESPACE, sizeof(WSDL_HTTP11_NAMESPACE))) {
+                                               tmpbinding->bindingType = BINDING_HTTP;
+                                       } else if (!strncmp(address->ns->href, WSDL_HTTP12_NAMESPACE, sizeof(WSDL_HTTP12_NAMESPACE))) {
+                                               tmpbinding->bindingType = BINDING_HTTP;
                                        } else {
-                                               php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Unknown binding type");
+                                               php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: PHP-SOAP doesn't support binding '%s'",address->ns->href);
                                        }
+                               } else {
+                                       php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Unknown binding type");
                                }
 
                                parse_namespace(bindingAttr->children->content, &ctype, &ns);
@@ -563,13 +542,13 @@ static sdlPtr load_wsdl(char *struri)
                                        soapBindingNode = get_node_ex(binding->children, "binding", wsdl_soap_namespace);
                                        if (soapBindingNode) {
                                                tmp = get_attribute(soapBindingNode->properties, "style");
-                                               if (tmp && !strcmp(tmp->children->content, "rpc")) {
+                                               if (tmp && !strncmp(tmp->children->content, "rpc", sizeof("rpc"))) {
                                                        soapBinding->style = SOAP_RPC;
                                                }
 
                                                tmp = get_attribute(soapBindingNode->properties, "transport");
                                                if (tmp) {
-                                                       if (strcmp(tmp->children->content, WSDL_HTTP_TRANSPORT)) {
+                                                       if (strncmp(tmp->children->content, WSDL_HTTP_TRANSPORT, sizeof(WSDL_HTTP_TRANSPORT))) {
                                                                php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: PHP-SOAP doesn't support transport '%s'", tmp->children->content);
                                                        }
                                                        soapBinding->transport = strdup(tmp->children->content);
@@ -642,7 +621,7 @@ static sdlPtr load_wsdl(char *struri)
 
                                                        tmp = get_attribute(soapOperation->properties, "style");
                                                        if (tmp) {
-                                                               if (!strcmp(tmp->children->content, "rpc")) {
+                                                               if (!strncmp(tmp->children->content, "rpc", sizeof("rpc"))) {
                                                                        soapFunctionBinding->style = SOAP_RPC;
                                                                } else {
                                                                        soapFunctionBinding->style = SOAP_DOCUMENT;
@@ -697,7 +676,7 @@ static sdlPtr load_wsdl(char *struri)
                                                } else if (input == NULL) {
                                                        function->responseName = strdup(function->functionName);
                                                } else {
-                                                       function->responseName = malloc(strlen(function->functionName) + strlen("Response") + 1);
+                                                       function->responseName = malloc(strlen(function->functionName) + sizeof("Response"));
                                                        sprintf(function->responseName, "%sResponse", function->functionName);
                                                }
 
index 2796d7e6b3881c27d1011e622182ced4931961a0..a0e48936f9165223375d30308d124c1b1fd88599 100644 (file)
@@ -164,7 +164,7 @@ extern zend_module_entry soap_module_entry;
 #define soap_module_ptr &soap_module_entry
 #define phpext_soap_ptr soap_module_ptr
 
-ZEND_EXTERN_MODULE_GLOBALS(soap);
+ZEND_EXTERN_MODULE_GLOBALS(soap)
 
 #ifdef ZTS
 # define SOAP_GLOBAL(v) TSRMG(soap_globals_id, zend_soap_globals *, v)
index 0f03d19fa710c55e01e131a2edd79c1831606e8c..6912be670cb15b51b9490427c9e4274a83c54836 100644 (file)
 /* $Id$ */
 
 #include "php_soap.h"
+#include "libxml/parser.h"
+#include "libxml/parserInternals.h"
 
 /* Channel libxml file io layer through the PHP streams subsystem.
  * This allows use of ftps:// and https:// urls */
 
+static int is_blank(const char* str)
+{
+       while (*str != '\0') {
+               if (*str != ' '  && *str != 0x9 && *str != 0xa && *str != 0xd) {
+                       return 0;
+               }
+               str++;
+       }
+       return 1;
+}
+
+/* removes all empty text, comments and other insignoficant nodes */
+static void cleanup_xml_node(xmlNodePtr node)
+{
+       xmlNodePtr trav;
+       xmlNodePtr del = NULL;
+
+       trav = node->children;
+       while (trav != NULL) {
+               if (del != NULL) {
+fprintf(stderr,"***garbage\n");
+                       xmlUnlinkNode(del);
+                       xmlFreeNode(del);
+                       del = NULL;
+               }
+               if (trav->type == XML_TEXT_NODE) {
+                       if (is_blank(trav->content)) {
+                               del = trav;
+                       }
+               } else if ((trav->type != XML_ELEMENT_NODE) &&
+                          (trav->type != XML_CDATA_SECTION_NODE)) {
+                       del = trav;
+               } else if (trav->children != NULL) {
+                       cleanup_xml_node(trav);
+               }
+               trav = trav->next;
+       }
+       if (del != NULL) {
+               xmlUnlinkNode(del);
+               xmlFreeNode(del);
+       }
+}
+
+static void soap_ignorableWhitespace(void *ctx, const xmlChar *ch, int len)
+{
+}
+
+static void soap_Comment(void *ctx, const xmlChar *value)
+{
+}
+
+xmlDocPtr soap_xmlParseFile(const char *filename)
+{
+  xmlParserCtxtPtr ctxt = NULL;
+       xmlDocPtr ret;
+
+/*
+       xmlInitParser();
+*/
+       ctxt = xmlCreateFileParserCtxt(filename);
+       if (ctxt) {
+               ctxt->keepBlanks = 0;
+               ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace;
+               ctxt->sax->comment = soap_Comment;
+               ctxt->sax->warning = NULL;
+               ctxt->sax->error = NULL;
+               /*ctxt->sax->fatalError = NULL;*/
+               xmlParseDocument(ctxt);
+               if (ctxt->wellFormed) {
+                       ret = ctxt->myDoc;
+                       if (ret->URL == NULL && ctxt->directory != NULL) {
+                               ret->URL = xmlStrdup(ctxt->directory);
+                       }
+               } else {
+                       ret = NULL;
+                       xmlFreeDoc(ctxt->myDoc);
+                       ctxt->myDoc = NULL;
+               }
+               xmlFreeParserCtxt(ctxt);
+       } else {
+         ret = NULL;
+       }
+
+/*
+       xmlCleanupParser();
+*/
+
+       if (ret) {
+               cleanup_xml_node((xmlNodePtr)ret);
+       }
+       return ret;
+}
+
+xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size)
+{
+  xmlParserCtxtPtr ctxt = NULL;
+       xmlDocPtr ret;
+
+/*
+       xmlInitParser();
+*/
+       ctxt = xmlCreateMemoryParserCtxt(buf, buf_size);
+       if (ctxt) {
+               ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace;
+               ctxt->sax->comment = soap_Comment;
+               ctxt->sax->warning = NULL;
+               ctxt->sax->error = NULL;
+               /*ctxt->sax->fatalError = NULL;*/
+               xmlParseDocument(ctxt);
+               if (ctxt->wellFormed) {
+                       ret = ctxt->myDoc;
+                       if (ret->URL == NULL && ctxt->directory != NULL) {
+                               ret->URL = xmlStrdup(ctxt->directory);
+                       }
+               } else {
+                       ret = NULL;
+                       xmlFreeDoc(ctxt->myDoc);
+                       ctxt->myDoc = NULL;
+               }
+               xmlFreeParserCtxt(ctxt);
+       } else {
+         ret = NULL;
+       }
+
+/*
+       xmlCleanupParser();
+*/
+
+/*
+       if (ret) {
+               cleanup_xml_node((xmlNodePtr)ret);
+       }
+*/
+       return ret;
+}
+
 int php_stream_xmlIO_match_wrapper(const char *filename)
 {
        TSRMLS_FETCH();
@@ -194,50 +332,3 @@ int parse_namespace(const char *inval, char **value, char **namespace)
 
        return FALSE;
 }
-
-static int is_blank(const char* str)
-{
-       while (*str != '\0') {
-               if (*str != ' '  && *str != 0x9 && *str != 0xa && *str != 0xd) {
-                       return 0;
-               }
-               str++;
-       }
-       return 1;
-}
-
-/* removes all empty text, comments and other insignoficant nodes */
-static void cleanup_xml_node(xmlNodePtr node)
-{
-       xmlNodePtr trav;
-       xmlNodePtr del = NULL;
-
-       trav = node->children;
-       while (trav != NULL) {
-               if (del != NULL) {
-                       xmlUnlinkNode(del);
-                       xmlFreeNode(del);
-                       del = NULL;
-               }
-               if (trav->type == XML_TEXT_NODE) {
-                       if (is_blank(trav->content)) {
-                               del = trav;
-                       }
-               } else if ((trav->type != XML_ELEMENT_NODE) &&
-                          (trav->type != XML_CDATA_SECTION_NODE)) {
-                       del = trav;
-               } else if (trav->children != NULL) {
-                       cleanup_xml_node(trav);
-               }
-               trav = trav->next;
-       }
-       if (del != NULL) {
-               xmlUnlinkNode(del);
-               xmlFreeNode(del);
-       }
-}
-
-void cleanup_xml(xmlDocPtr doc)
-{
-       cleanup_xml_node((xmlNodePtr)doc);
-}
index 9616e163aef7406111650cd461b3994c15532f62..4ec1600b441d53498521226ee2f9b55e2df02af4 100644 (file)
@@ -30,6 +30,9 @@
 #define node_is_equal(node, name) node_is_equal_ex(node, name, NULL)
 #define attr_is_equal(node, name) attr_is_equal_ex(node, name, NULL)
 
+xmlDocPtr soap_xmlParseFile(const char *filename);
+xmlDocPtr soap_xmlParseMemory(const void *buf, size_t size);
+
 xmlNsPtr attr_find_ns(xmlAttrPtr node);
 xmlNsPtr node_find_ns(xmlNodePtr node);
 int attr_is_equal_ex(xmlAttrPtr node, char *name, char *ns);
@@ -41,8 +44,6 @@ xmlNodePtr get_node_with_attribute_ex(xmlNodePtr node, char *name, char *name_ns
 xmlNodePtr get_node_with_attribute_recursive_ex(xmlNodePtr node, char *name, char *name_ns, char *attribute, char *value, char *attr_ns);
 int parse_namespace(const char *inval,char **value,char **namespace);
 
-void cleanup_xml(xmlDocPtr doc);
-
 int php_stream_xmlIO_match_wrapper(const char *filename);
 void *php_stream_xmlIO_open_wrapper(const char *filename);
 int php_stream_xmlIO_read(void *context, char *buffer, int len);
index d531a28834c81ceb19c54a39e9a517e93f4ef2ca..d9bf00e909d53fad54d4b4c0d19343f917ae5539 100644 (file)
@@ -112,7 +112,7 @@ zend_class_entry* soap_var_class_entry;
 zend_class_entry* soap_param_class_entry;
 zend_class_entry* soap_header_class_entry;
 
-ZEND_DECLARE_MODULE_GLOBALS(soap);
+ZEND_DECLARE_MODULE_GLOBALS(soap)
 
 static void (*old_error_handler)(int, const char *, const uint, const char*, va_list);
 
@@ -232,7 +232,7 @@ ZEND_BEGIN_ARG_INFO(__call_args, 0)
        ZEND_ARG_PASS_INFO(0)
        ZEND_ARG_PASS_INFO(0)
        ZEND_ARG_PASS_INFO(1)
-ZEND_END_ARG_INFO();
+ZEND_END_ARG_INFO()
 #else
 unsigned char __call_args[] = { 6, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE };
 #endif
@@ -1119,15 +1119,9 @@ PHP_METHOD(soapserver, handle)
 
        if (zend_hash_find(&EG(symbol_table), HTTP_RAW_POST_DATA, sizeof(HTTP_RAW_POST_DATA), (void **) &raw_post)!=FAILURE
                && ((*raw_post)->type==IS_STRING)) {
-               int old_error_reporting = EG(error_reporting);
                sdlFunctionPtr function;
 
-               EG(error_reporting) &= ~(E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE);
-
-               doc_request = xmlParseMemory(Z_STRVAL_PP(raw_post),Z_STRLEN_PP(raw_post));
-               xmlCleanupParser();
-
-               EG(error_reporting) = old_error_reporting;
+               doc_request = soap_xmlParseMemory(Z_STRVAL_PP(raw_post),Z_STRLEN_PP(raw_post));
 
                if (doc_request == NULL) {
                        php_error(E_ERROR, "Bad Request");
@@ -1271,7 +1265,7 @@ PHP_METHOD(soapserver, handle)
                        if (function && function->responseName) {
                                response_name = estrdup(function->responseName);
                        } else {
-                               response_name = emalloc(Z_STRLEN(function_name) + strlen("Response") + 1);
+                               response_name = emalloc(Z_STRLEN(function_name) + sizeof("Response"));
                                sprintf(response_name,"%sResponse",Z_STRVAL(function_name));
                        }
                        SOAP_GLOBAL(overrides) = service->mapping;
@@ -2230,7 +2224,7 @@ static sdlFunctionPtr deseralize_function_call(sdlPtr sdl, xmlDocPtr request, ch
                                        }
                                        attr = get_attribute_ex(hdr_func->properties,"actor",envelope_ns);
                                        if (attr != NULL) {
-                                               if (strcmp(attr->children->content,"http://schemas.xmlsoap.org/soap/actor/next") != 0 &&
+                                               if (strcmp(attr->children->content,SOAP_1_1_ACTOR_NEXT) != 0 &&
                                                    (actor == NULL || strcmp(attr->children->content,actor) != 0)) {
                                                  goto ignore_header;
                                                }
@@ -2242,8 +2236,8 @@ static sdlFunctionPtr deseralize_function_call(sdlPtr sdl, xmlDocPtr request, ch
                                        }
                                        attr = get_attribute_ex(hdr_func->properties,"role",envelope_ns);
                                        if (attr != NULL) {
-                                               if (strcmp(attr->children->content,"http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver") != 0 &&
-                                                   strcmp(attr->children->content,"http://www.w3.org/2003/05/soap-envelope/role/next") != 0 &&
+                                               if (strcmp(attr->children->content,SOAP_1_2_ACTOR_UNLIMATERECEIVER) != 0 &&
+                                                   strcmp(attr->children->content,SOAP_1_2_ACTOR_NEXT) != 0 &&
                                                    (actor == NULL || strcmp(attr->children->content,actor) != 0)) {
                                                  goto ignore_header;
                                                }
@@ -2369,10 +2363,10 @@ static int seralize_response_call2(xmlNodePtr body, sdlFunctionPtr function, cha
                        if (main && version == SOAP_1_2) {
                                xmlNs *rpc_ns = xmlNewNs(body, RPC_SOAP12_NAMESPACE, RPC_SOAP12_NS_PREFIX);
                                rpc_result = xmlNewChild(method, rpc_ns, "result", NULL);
-                       }
-                       param = seralize_parameter(parameter, ret, 0, "return", use, method TSRMLS_CC);
-                       if (main && version == SOAP_1_2) {
+                               param = seralize_parameter(parameter, ret, 0, "return", use, method TSRMLS_CC);
                                xmlNodeSetContent(rpc_result,param->name);
+                       } else {
+                               param = seralize_parameter(parameter, ret, 0, "return", use, method TSRMLS_CC);
                        }
                } else {
                        param = seralize_parameter(parameter, ret, 0, "return", use, body TSRMLS_CC);
@@ -2814,6 +2808,7 @@ static xmlNodePtr seralize_parameter(sdlParamPtr param, zval *param_val, int ind
 {
        char *paramName;
        xmlNodePtr xmlParam;
+       char paramNameBuf[10];
 
        if (Z_TYPE_P(param_val) == IS_OBJECT &&
                Z_OBJCE_P(param_val) == soap_param_class_entry) {
@@ -2828,20 +2823,18 @@ static xmlNodePtr seralize_parameter(sdlParamPtr param, zval *param_val, int ind
        }
 
        if (param != NULL && param->paramName != NULL) {
-               paramName = estrdup(param->paramName);
+               paramName = param->paramName;
        } else {
                if (name == NULL) {
-                       paramName = emalloc(10);
+                       paramName = paramNameBuf;
                        sprintf(paramName,"param%d",index);
                } else {
-                       paramName = estrdup(name);
+                       paramName = name;
                }
        }
 
        xmlParam = seralize_zval(param_val, param, paramName, style, parent TSRMLS_CC);
 
-       efree(paramName);
-
        return xmlParam;
 }