diff options
author | Dmitry Stogov <dmitry@php.net> | 2004-02-05 09:28:09 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2004-02-05 09:28:09 +0000 |
commit | 2c1dcf32a04482613229b5d31b736b789a1dbc9b (patch) | |
tree | 3c6e4a2890e44b514494f79e80f11dc4c00b3fd8 /ext | |
parent | 1c433049ca51f61687ff97d9ddd0ade03d2da5c3 (diff) | |
download | php-git-2c1dcf32a04482613229b5d31b736b789a1dbc9b.tar.gz |
WSDL parsing speedup. Source cleanup.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/soap/php_encoding.c | 16 | ||||
-rw-r--r-- | ext/soap/php_packet_soap.c | 11 | ||||
-rw-r--r-- | ext/soap/php_schema.c | 60 | ||||
-rw-r--r-- | ext/soap/php_sdl.c | 183 | ||||
-rw-r--r-- | ext/soap/php_soap.h | 2 | ||||
-rw-r--r-- | ext/soap/php_xml.c | 185 | ||||
-rw-r--r-- | ext/soap/php_xml.h | 5 | ||||
-rw-r--r-- | ext/soap/soap.c | 35 |
8 files changed, 272 insertions, 225 deletions
diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index a0c9da9e45..2978990c02 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -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); diff --git a/ext/soap/php_packet_soap.c b/ext/soap/php_packet_soap.c index 1df72f66ce..c3efe0b9d4 100644 --- a/ext/soap/php_packet_soap.c +++ b/ext/soap/php_packet_soap.c @@ -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); diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c index cde1a8ef86..2af3d67303 100644 --- a/ext/soap/php_schema.c +++ b/ext/soap/php_schema.c @@ -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); diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 9dd4455823..1ceec6539b 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -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); } diff --git a/ext/soap/php_soap.h b/ext/soap/php_soap.h index 2796d7e6b3..a0e48936f9 100644 --- a/ext/soap/php_soap.h +++ b/ext/soap/php_soap.h @@ -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) diff --git a/ext/soap/php_xml.c b/ext/soap/php_xml.c index 0f03d19fa7..6912be670c 100644 --- a/ext/soap/php_xml.c +++ b/ext/soap/php_xml.c @@ -20,10 +20,148 @@ /* $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); -} diff --git a/ext/soap/php_xml.h b/ext/soap/php_xml.h index 9616e163ae..4ec1600b44 100644 --- a/ext/soap/php_xml.h +++ b/ext/soap/php_xml.h @@ -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); diff --git a/ext/soap/soap.c b/ext/soap/soap.c index d531a28834..d9bf00e909 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -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; } |