From 9f8d30f2153db31f63ea22a541999af8a77948e0 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 9 Jan 2004 16:36:13 +0000 Subject: [PATCH] BUGFIX: WSDL support (complexType/complexContent/restiction/atttibute) --- ext/soap/php_schema.c | 19 +++++++++++++++---- ext/soap/php_sdl.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c index 5fa5a5ee917..e0921e3d038 100644 --- a/ext/soap/php_schema.c +++ b/ext/soap/php_schema.c @@ -121,6 +121,7 @@ static int schema_simpleType(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr simpleType, } ht = cur_type->elements; smart_str_appends(&key, cur_type->name); + smart_str_0(&key); } zend_hash_add(ht, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), (void **)&ptr); @@ -316,22 +317,30 @@ static int schema_restriction_complexContent(sdlPtr *sdl, xmlAttrPtr tsn, xmlNod if(trav->type == XML_ELEMENT_NODE) { if(!strcmp(trav->name, "group")) { schema_group(sdl, tsn, trav, cur_type); - return TRUE; + break; } else if(!strcmp(trav->name, "all")) { schema_all(sdl, tsn, trav, cur_type); - return TRUE; + break; } else if(!strcmp(trav->name, "choice")) { schema_choice(sdl, tsn, trav, cur_type); - return TRUE; + break; } else if(!strcmp(trav->name, "sequence")) { schema_sequence(sdl, tsn, trav, cur_type); - return TRUE; + break; } else if(!strcmp(trav->name, "attribute")) { schema_attribute(sdl, tsn, trav, cur_type); } } trav = trav->next; } + while (trav != NULL) { + if(trav->type == XML_ELEMENT_NODE) { + if(!strcmp(trav->name, "attribute")) { + schema_attribute(sdl, tsn, trav, cur_type); + } + } + trav = trav->next; + } return TRUE; } @@ -773,6 +782,7 @@ static int schema_complexType(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr compType, } ht = cur_type->elements; smart_str_appends(&key, newType->name); + smart_str_0(&key); } zend_hash_add(ht, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), (void **)&ptr); @@ -1055,6 +1065,7 @@ static int schema_attribute(sdlPtr *sdl, xmlAttrPtr tsn, xmlNodePtr attrType, sd smart_str_free(&key); return TRUE; } + smart_str_free(&key); } zend_hash_next_index_insert(cur_type->attributes, &newAttr, sizeof(sdlAttributePtr), NULL); diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 01c8272c7f7..fca6581685e 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -280,6 +280,7 @@ xmlNodePtr sdl_to_xml_array(sdlTypePtr type, zval *data, int style) int dimension = 1; int* dims; xmlNodePtr xmlParam; + sdlTypePtr elementType; encodePtr enc = NULL; TSRMLS_FETCH(); @@ -368,8 +369,47 @@ xmlNodePtr sdl_to_xml_array(sdlTypePtr type, zval *data, int style) efree(value); if (ns) efree(ns); + } else if (type->elements && + zend_hash_num_elements(type->elements) == 1 && + (elementType = *(sdlTypePtr*)type->elements->pListHead->pData) != NULL && + elementType->encode && elementType->encode->details.type_str) { + char* ns = elementType->encode->details.ns; + if (ns) { + if (strcmp(ns,XSD_NAMESPACE) == 0) { + smart_str_appendl(&array_type_and_size, XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX) - 1); + smart_str_appendc(&array_type_and_size, ':'); + } else { + smart_str *prefix = encode_new_ns(); + smart_str smart_ns = {0}; + + smart_str_appendl(&smart_ns, "xmlns:", sizeof("xmlns:") - 1); + smart_str_appendl(&smart_ns, prefix->c, prefix->len); + smart_str_0(&smart_ns); + xmlSetProp(xmlParam, smart_ns.c, ns); + smart_str_free(&smart_ns); + + smart_str_appends(&array_type_and_size, prefix->c); + smart_str_appendc(&array_type_and_size, ':'); + smart_str_free(prefix); + efree(prefix); + } + } + enc = elementType->encode; + smart_str_appends(&array_type_and_size, elementType->encode->details.type_str); + smart_str_free(&array_type); + smart_str_appendc(&array_type_and_size, '['); + smart_str_append_long(&array_type_and_size, i); + smart_str_appendc(&array_type_and_size, ']'); + smart_str_0(&array_type_and_size); + + dims = emalloc(sizeof(int)*dimension); + dims[0] = i; } else { - smart_str_appends(&array_type_and_size, type->name); + smart_str array_type = {0}; + get_array_type(data, &array_type TSRMLS_CC); + enc = get_encoder_ex(SOAP_GLOBAL(sdl), array_type.c); + smart_str_append(&array_type_and_size, &array_type); + smart_str_free(&array_type); smart_str_appendc(&array_type_and_size, '['); smart_str_append_long(&array_type_and_size, i); smart_str_appendc(&array_type_and_size, ']'); @@ -439,6 +479,7 @@ sdlBindingPtr get_binding_from_name(sdlPtr sdl, char *name, char *ns) smart_str_appends(&key, ns); smart_str_appendc(&key, ':'); smart_str_appends(&key, name); + smart_str_0(&key); zend_hash_find(sdl->bindings, key.c, key.len, (void **)&binding);