From: Dmitry Stogov Date: Fri, 3 Mar 2006 09:20:33 +0000 (+0000) Subject: Fixed bug #36575 (SOAP: Incorrect complex type instantiation with hierarchies) X-Git-Tag: php-5.1.3RC1~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=622347bd8cfd3e1831ed18c9f30a2c57abf5271b;p=php Fixed bug #36575 (SOAP: Incorrect complex type instantiation with hierarchies) --- diff --git a/NEWS b/NEWS index 0acb4b88cf..50b8662c8d 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,8 @@ PHP NEWS (Mike) - Fixed crash with DOMImplementation::createDocumentType("name:"). (Mike) - Fixed bug #36599 (DATE_W3C format constant incorrect). (Derick) +- Fixed bug #36575 (SOAP: Incorrect complex type instantiation with + hierarchies). (Dmitry) - Fixed bug #36510 (strtotime() fails to parse date strings with tabs). (Ilia, Derick) - Fixed bug #36459 (Incorrect adding PHPSESSID to links, which contains \r\n). diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 629f491e5b..f675fd949d 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -246,6 +246,23 @@ void whiteSpace_collapse(char* str) *pos = '\0'; } +static encodePtr find_encoder_by_type_name(sdlPtr sdl, const char *type) +{ + if (sdl && sdl->encoders) { + HashPosition pos; + encodePtr *enc; + + for (zend_hash_internal_pointer_reset_ex(sdl->encoders, &pos); + zend_hash_get_current_data_ex(sdl->encoders, (void **) &enc, &pos) == SUCCESS; + zend_hash_move_forward_ex(sdl->encoders, &pos)) { + if (strcmp((*enc)->details.type_str, type) == 0) { + return *enc; + } + } + } + return NULL; +} + xmlNodePtr master_to_xml(encodePtr encode, zval *data, int style, xmlNodePtr parent) { xmlNodePtr node = NULL; @@ -328,7 +345,12 @@ xmlNodePtr master_to_xml(encodePtr encode, zval *data, int style, xmlNodePtr par encodePtr enc = get_encoder(SOAP_GLOBAL(sdl), SOAP_GLOBAL(sdl)->target_ns, type_name); if (enc) { encode = enc; - } + } else if (SOAP_GLOBAL(sdl)) { + enc = find_encoder_by_type_name(SOAP_GLOBAL(sdl), type_name); + if (enc) { + encode = enc; + } + } break; } } @@ -717,7 +739,7 @@ static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNo zval_copy_ctor(&tmp); convert_to_string(&tmp); - str = php_escape_html_entities(Z_STRVAL(tmp), Z_STRLEN(tmp), &new_len, 0, 0, NULL TSRMLS_CC); + str = php_escape_html_entities(Z_STRVAL(tmp), Z_STRLEN(tmp), &new_len, 0, 0, NULL TSRMLS_CC); zval_dtor(&tmp); } @@ -758,7 +780,7 @@ static xmlNodePtr to_xml_base64(encodeTypePtr type, zval *data, int style, xmlNo xmlAddChild(parent, ret); FIND_ZVAL_NULL(data, ret, style); - if (Z_TYPE_P(data) == IS_STRING) { + if (Z_TYPE_P(data) == IS_STRING) { str = php_base64_encode((unsigned char*)Z_STRVAL_P(data), Z_STRLEN_P(data), &str_len); xmlNodeSetContentLen(ret, str, str_len); efree(str); @@ -791,14 +813,14 @@ static xmlNodePtr to_xml_hexbin(encodeTypePtr type, zval *data, int style, xmlNo xmlAddChild(parent, ret); FIND_ZVAL_NULL(data, ret, style); - if (Z_TYPE_P(data) != IS_STRING) { + if (Z_TYPE_P(data) != IS_STRING) { tmp = *data; zval_copy_ctor(&tmp); convert_to_string(&tmp); data = &tmp; } str = (unsigned char *) safe_emalloc(Z_STRLEN_P(data) * 2, sizeof(char), 1); - + for (i = j = 0; i < Z_STRLEN_P(data); i++) { str[j++] = hexconvtab[((unsigned char)Z_STRVAL_P(data)[i]) >> 4]; str[j++] = hexconvtab[((unsigned char)Z_STRVAL_P(data)[i]) & 15]; @@ -1157,7 +1179,7 @@ static void model_to_zval_object(zval *ret, sdlContentModelPtr model, xmlNodePtr add_next_index_zval(array, val); } while ((node = get_node(node->next, model->u.element->name)) != NULL); val = array; - } else if ((SOAP_GLOBAL(features) & SOAP_SINGLE_ELEMENT_ARRAYS) && + } else if ((SOAP_GLOBAL(features) & SOAP_SINGLE_ELEMENT_ARRAYS) && (model->max_occurs == -1 || model->max_occurs > 1)) { zval *array; @@ -1200,7 +1222,7 @@ static void model_to_zval_object(zval *ret, sdlContentModelPtr model, xmlNodePtr } /* Struct encode/decode */ -static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data) +static zval *to_zval_object_ex(encodeTypePtr type, xmlNodePtr data, zend_class_entry *pce) { zval *ret; xmlNodePtr trav; @@ -1210,7 +1232,9 @@ static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data) zend_bool redo_any = 0; TSRMLS_FETCH(); - if (SOAP_GLOBAL(class_map) && type->type_str) { + if (pce) { + ce = pce; + } else if (SOAP_GLOBAL(class_map) && type->type_str) { zval **classname; zend_class_entry *tmp; @@ -1253,7 +1277,20 @@ static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data) sdlType->encode->details.sdl_type->kind != XSD_TYPEKIND_SIMPLE && sdlType->encode->details.sdl_type->kind != XSD_TYPEKIND_LIST && sdlType->encode->details.sdl_type->kind != XSD_TYPEKIND_UNION) { - ret = master_to_zval_int(sdlType->encode, data); + + if (ce != ZEND_STANDARD_CLASS_DEF_PTR && + sdlType->encode->to_zval == sdl_guess_convert_zval && + sdlType->encode->details.sdl_type != NULL && + (sdlType->encode->details.sdl_type->kind == XSD_TYPEKIND_COMPLEX || + sdlType->encode->details.sdl_type->kind == XSD_TYPEKIND_RESTRICTION || + sdlType->encode->details.sdl_type->kind == XSD_TYPEKIND_EXTENSION) && + (sdlType->encode->details.sdl_type->encode == NULL || + (sdlType->encode->details.sdl_type->encode->details.type != IS_ARRAY && + sdlType->encode->details.sdl_type->encode->details.type != SOAP_ENC_ARRAY))) { + ret = to_zval_object_ex(&sdlType->encode->details, data, ce); + } else { + ret = master_to_zval_int(sdlType->encode, data); + } FIND_XML_NULL(data, ret); if (get_zval_property(ret, "any" TSRMLS_CC) != NULL) { unset_zval_property(ret, "any" TSRMLS_CC); @@ -1280,7 +1317,7 @@ static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data) if (sdlType->model) { model_to_zval_object(ret, sdlType->model, data, sdl TSRMLS_CC); if (redo_any && get_zval_property(ret, "any" TSRMLS_CC) == NULL) { - model_to_zval_any(ret, data->children TSRMLS_CC); + model_to_zval_any(ret, data->children TSRMLS_CC); } } if (sdlType->attributes) { @@ -1358,6 +1395,12 @@ static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data) return ret; } +static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data) +{ + return to_zval_object_ex(type, data, NULL); +} + + static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval *object, int style, int strict TSRMLS_DC) { switch (model->kind) { @@ -1598,7 +1641,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo zval *tmp = get_zval_property(data, "_" TSRMLS_CC); if (tmp) { xmlParam = master_to_xml(enc, tmp, style, parent); - } else if (prop == NULL) { + } else if (prop == NULL) { xmlParam = master_to_xml(enc, data, style, parent); } else { xmlParam = xmlNewNode(NULL,"BOGUS"); @@ -1693,7 +1736,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo an implicit schema. Otherwise, use form. */ if ((*attr)->namens && - (!strncmp((*attr)->namens, XML_NAMESPACE, sizeof(XML_NAMESPACE)) || + (!strncmp((*attr)->namens, XML_NAMESPACE, sizeof(XML_NAMESPACE)) || (*attr)->form == XSD_FORM_QUALIFIED)) { xmlNsPtr nsp = encode_add_ns(xmlParam, (*attr)->namens); @@ -2790,7 +2833,7 @@ static zval *to_zval_any(encodeTypePtr type, xmlNodePtr data) } static xmlNodePtr to_xml_any(encodeTypePtr type, zval *data, int style, xmlNodePtr parent) -{ +{ xmlNodePtr ret; if (Z_TYPE_P(data) == IS_STRING) { @@ -3157,7 +3200,7 @@ static encodePtr get_array_type(xmlNodePtr node, zval *array, smart_str *type TS if (different || count == 0) { smart_str_appendl(type, "xsd:anyType", 11); - return get_conversion(XSD_ANYTYPE); + return get_conversion(XSD_ANYTYPE); } else { encodePtr enc; diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 1447b435f7..8da6ad4afb 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -2201,6 +2201,7 @@ PHP_METHOD(SoapClient, SoapClient) MAKE_STD_ZVAL(class_map); *class_map = **tmp; + INIT_PZVAL(class_map); zval_copy_ctor(class_map); #ifdef ZEND_ENGINE_2 class_map->refcount--; diff --git a/ext/soap/tests/bugs/bug35142.phpt b/ext/soap/tests/bugs/bug35142.phpt index b27d9bc6d9..e12b5ad98a 100755 --- a/ext/soap/tests/bugs/bug35142.phpt +++ b/ext/soap/tests/bugs/bug35142.phpt @@ -49,7 +49,7 @@ class LogOffEvent { public $audienceMemberId; public $timestamp; public $smokeStatus; - public $callInititator; + public $callInitiator; function __construct($audienceMemberId, $timestamp, $smokeStatus) { $this->audienceMemberId = $audienceMemberId; @@ -98,6 +98,15 @@ object(IVREvents)#%d (6) { int(101) ["messageId"]=> int(12345) + ["source"]=> + string(3) "IVR" + ["logOnEvent"]=> + object(LogOnEvent)#%d (2) { + ["audienceMemberId"]=> + int(34567) + ["timestamp"]=> + string(25) "2005-11-08T11:22:07+03:00" + } ["logOffEvent"]=> array(2) { [0]=> @@ -123,13 +132,4 @@ object(IVREvents)#%d (6) { string(3) "IVR" } } - ["logOnEvent"]=> - object(LogOnEvent)#%d (2) { - ["audienceMemberId"]=> - int(34567) - ["timestamp"]=> - string(25) "2005-11-08T11:22:07+03:00" - } - ["source"]=> - string(3) "IVR" } diff --git a/ext/soap/tests/bugs/bug36226.phpt b/ext/soap/tests/bugs/bug36226.phpt index 572a380b02..c88d969f29 100755 --- a/ext/soap/tests/bugs/bug36226.phpt +++ b/ext/soap/tests/bugs/bug36226.phpt @@ -50,7 +50,7 @@ class LogOffEvent { public $audienceMemberId; public $timestamp; public $smokeStatus; - public $callInititator; + public $callInitiator; function __construct($audienceMemberId, $timestamp, $smokeStatus) { $this->audienceMemberId = $audienceMemberId; @@ -99,6 +99,18 @@ object(IVREvents)#%d (6) { int(101) ["messageId"]=> int(12345) + ["source"]=> + string(3) "IVR" + ["logOnEvent"]=> + array(1) { + [0]=> + object(LogOnEvent)#10 (2) { + ["audienceMemberId"]=> + int(34567) + ["timestamp"]=> + string(25) "2005-11-08T11:22:07+03:00" + } + } ["logOffEvent"]=> array(2) { [0]=> @@ -124,16 +136,4 @@ object(IVREvents)#%d (6) { string(3) "IVR" } } - ["logOnEvent"]=> - array(1) { - [0]=> - object(LogOnEvent)#10 (2) { - ["audienceMemberId"]=> - int(34567) - ["timestamp"]=> - string(25) "2005-11-08T11:22:07+03:00" - } - } - ["source"]=> - string(3) "IVR" } diff --git a/ext/soap/tests/bugs/bug36575.phpt b/ext/soap/tests/bugs/bug36575.phpt new file mode 100755 index 0000000000..aad8fcad6a --- /dev/null +++ b/ext/soap/tests/bugs/bug36575.phpt @@ -0,0 +1,52 @@ +--TEST-- +Bug #36575 (Incorrect complex type instantiation with hierarchies) +--SKIPIF-- + +--INI-- +soap.wsdl_cache_enabled=0 +--FILE-- +var1 = $a1->var1; + $a3->var2 = "var two"; + $a3->var3 = "var three"; + return $a3; +} + +$classMap = array("A1" => "CT_A1", "A2" => "CT_A2", "A3" => "CT_A3"); + +$client = new SoapClient(dirname(__FILE__)."/bug36575.wsdl", array("trace" => 1, "exceptions" => 0, "classmap" => $classMap)); +$a2 = new CT_A2(); +$a2->var1 = "one"; +$a2->var2 = "two"; +$client->test($a2); + +$soapRequest = $client->__getLastRequest(); + +echo $soapRequest; + +$server = new SoapServer(dirname(__FILE__)."/bug36575.wsdl", array("classmap" => $classMap)); +$server->addFunction("test"); +$server->handle($soapRequest); +echo "ok\n"; +?> +--EXPECT-- + +onetwo + +onevar twovar three +ok diff --git a/ext/soap/tests/bugs/bug36575.wsdl b/ext/soap/tests/bugs/bug36575.wsdl new file mode 100755 index 0000000000..0f1899bcd5 --- /dev/null +++ b/ext/soap/tests/bugs/bug36575.wsdl @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ext/soap/tests/classmap003.phpt b/ext/soap/tests/classmap003.phpt index c126709054..ac87a1682e 100755 --- a/ext/soap/tests/classmap003.phpt +++ b/ext/soap/tests/classmap003.phpt @@ -49,6 +49,6 @@ print_r($client->f()); --EXPECT-- B Object ( - [x] => 5 [y] => 6 + [x] => 5 )