cvs: php-src(PHP_5_0) / NEWS /ext/soap php_encoding.c php_sdl.c php_soap.h soap.c /ext/soap/tests server021.phpt /ext/soap/tests/bugs bug28969.phpt
| From: | Dmitry Stogov | Date: | Tue, 10 Aug 2004 16:30:31 +0000 |
| Subject: | cvs: php-src(PHP_5_0) / NEWS /ext/soap php_encoding.c php_sdl.c php_soap.h soap.c /ext/soap/tests server021.phpt /ext/soap/tests/bugs bug28969.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-28261@lists.php.net to get a copy of this message | ||
dmitry Tue Aug 10 12:30:31 2004 EDT
Added files: (Branch: PHP_5_0)
/php-src/ext/soap/tests/bugs bug28969.phpt
Modified files:
/php-src NEWS
/php-src/ext/soap php_encoding.c php_sdl.c php_soap.h soap.c
/php-src/ext/soap/tests server021.phpt
Log:
Fixed bug #28969 (Wrong data encoding of special characters)
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1760.2.29&r2=1.1760.2.30&ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1760.2.29 php-src/NEWS:1.1760.2.30 --- php-src/NEWS:1.1760.2.29 Tue Aug 10 09:47:30 2004 +++ php-src/NEWS Tue Aug 10 12:30:30 2004 @@ -44,6 +44,7 @@ - Fixed bug #29109 (SoapFault exception: [WSDL] Out of memory). (Dmitry) - Fixed bug #29061 (soap extension segfaults). (Dmitry) - Fixed bug #28985 (__getTypes() returning nothing on complex WSDL). (Dmitry) +- Fixed bug #28969 (Wrong data encoding of special characters). (Dmitry) - Fixed bug #28895 (ReflectionClass::isAbstract always returns false). (Marcus) - Fixed bug #28829 (Thread-unsafety in bcmath elementary values). (Sara) - Fixed bug #28464 (catch() does not catch exceptions by interfaces). (Marcus) http://cvs.php.net/diff.php/php-src/ext/soap/php_encoding.c?r1=1.71&r2=1.71.2.1&ty=u Index: php-src/ext/soap/php_encoding.c diff -u php-src/ext/soap/php_encoding.c:1.71 php-src/ext/soap/php_encoding.c:1.71.2.1 --- php-src/ext/soap/php_encoding.c:1.71 Wed May 5 06:31:25 2004 +++ php-src/ext/soap/php_encoding.c Tue Aug 10 12:30:30 2004 @@ -17,7 +17,7 @@ | Dmitry Stogov <dmitry@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: php_encoding.c,v 1.71 2004/05/05 10:31:25 dmitry Exp $ */ +/* $Id: php_encoding.c,v 1.71.2.1 2004/08/10 16:30:30 dmitry Exp $ */ #include <time.h> @@ -31,6 +31,7 @@ static zval *to_zval_string(encodeTypePtr type, xmlNodePtr data); static zval *to_zval_stringr(encodeTypePtr type, xmlNodePtr data); static zval *to_zval_stringc(encodeTypePtr type, xmlNodePtr data); +static zval *to_zval_stringb(encodeTypePtr type, xmlNodePtr data); static zval *to_zval_map(encodeTypePtr type, xmlNodePtr data); static zval *to_zval_null(encodeTypePtr type, xmlNodePtr data); @@ -145,8 +146,8 @@ {{XSD_GMONTH, XSD_GMONTH_STRING, XSD_NAMESPACE, NULL}, to_zval_stringc, to_xml_gmonth}, {{XSD_DURATION, XSD_DURATION_STRING, XSD_NAMESPACE, NULL}, to_zval_stringc, to_xml_duration}, - {{XSD_HEXBINARY, XSD_HEXBINARY_STRING, XSD_NAMESPACE, NULL}, to_zval_stringc, to_xml_stringl}, - {{XSD_BASE64BINARY, XSD_BASE64BINARY_STRING, XSD_NAMESPACE, NULL}, to_zval_stringc, to_xml_stringl}, + {{XSD_HEXBINARY, XSD_HEXBINARY_STRING, XSD_NAMESPACE, NULL}, to_zval_stringb, to_xml_stringl}, + {{XSD_BASE64BINARY, XSD_BASE64BINARY_STRING, XSD_NAMESPACE, NULL}, to_zval_stringb, to_xml_stringl}, {{XSD_LONG, XSD_LONG_STRING, XSD_NAMESPACE, NULL}, to_zval_long, to_xml_long}, {{XSD_INT, XSD_INT_STRING, XSD_NAMESPACE, NULL}, to_zval_long, to_xml_long}, @@ -460,7 +461,23 @@ FIND_XML_NULL(data, ret); if (data && data->children) { if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { - ZVAL_STRING(ret, data->children->content, 1); + TSRMLS_FETCH(); + + if (SOAP_GLOBAL(encoding) != NULL) { + xmlBufferPtr in = xmlBufferCreateStatic(data->children->content, strlen(data->children->content)); + xmlBufferPtr out = xmlBufferCreate(); + int n = xmlCharEncOutFunc(SOAP_GLOBAL(encoding), out, in); + + if (n >= 0) { + ZVAL_STRING(ret, (char*)xmlBufferContent(out), 1); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } + xmlBufferFree(out); + xmlBufferFree(in); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } } else if (data->children->type == XML_CDATA_SECTION_NODE && data->children->next == NULL) { ZVAL_STRING(ret, data->children->content, 1); } else { @@ -479,8 +496,24 @@ FIND_XML_NULL(data, ret); if (data && data->children) { if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + TSRMLS_FETCH(); + whiteSpace_replace(data->children->content); - ZVAL_STRING(ret, data->children->content, 1); + if (SOAP_GLOBAL(encoding) != NULL) { + xmlBufferPtr in = xmlBufferCreateStatic(data->children->content, strlen(data->children->content)); + xmlBufferPtr out = xmlBufferCreate(); + int n = xmlCharEncOutFunc(SOAP_GLOBAL(encoding), out, in); + + if (n >= 0) { + ZVAL_STRING(ret, (char*)xmlBufferContent(out), 1); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } + xmlBufferFree(out); + xmlBufferFree(in); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } } else if (data->children->type == XML_CDATA_SECTION_NODE && data->children->next == NULL) { ZVAL_STRING(ret, data->children->content, 1); } else { @@ -499,6 +532,42 @@ FIND_XML_NULL(data, ret); if (data && data->children) { if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + TSRMLS_FETCH(); + + whiteSpace_collapse(data->children->content); + if (SOAP_GLOBAL(encoding) != NULL) { + xmlBufferPtr in = xmlBufferCreateStatic(data->children->content, strlen(data->children->content)); + xmlBufferPtr out = xmlBufferCreate(); + int n = xmlCharEncOutFunc(SOAP_GLOBAL(encoding), out, in); + + if (n >= 0) { + ZVAL_STRING(ret, (char*)xmlBufferContent(out), 1); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } + xmlBufferFree(out); + xmlBufferFree(in); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } + } else if (data->children->type == XML_CDATA_SECTION_NODE && data->children->next == NULL) { + ZVAL_STRING(ret, data->children->content, 1); + } else { + soap_error0(E_ERROR, "Encoding: Violation of encoding rules"); + } + } else { + ZVAL_EMPTY_STRING(ret); + } + return ret; +} + +static zval *to_zval_stringb(encodeTypePtr type, xmlNodePtr data) +{ + zval *ret; + MAKE_STD_ZVAL(ret); + FIND_XML_NULL(data, ret); + if (data && data->children) { + if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { whiteSpace_collapse(data->children->content); ZVAL_STRING(ret, data->children->content, 1); } else if (data->children->type == XML_CDATA_SECTION_NODE && data->children->next == NULL) { @@ -532,6 +601,24 @@ convert_to_string(&tmp); str = php_escape_html_entities(Z_STRVAL(tmp), Z_STRLEN(tmp), &new_len, 0, 0, NULL TSRMLS_CC); zval_dtor(&tmp); + } + + if (SOAP_GLOBAL(encoding) != NULL) { + xmlBufferPtr in = xmlBufferCreateStatic(str, new_len); + xmlBufferPtr out = xmlBufferCreate(); + int n = xmlCharEncInFunc(SOAP_GLOBAL(encoding), out, in); + + if (n >= 0) { + efree(str); + str = estrdup(xmlBufferContent(out)); + new_len = n; + } else if (!xmlCheckUTF8(str)) { + soap_error1(E_ERROR, "Encoding: string '%s' is not a valid utf-8 string", str); + } + xmlBufferFree(out); + xmlBufferFree(in); + } else if (!xmlCheckUTF8(str)) { + soap_error1(E_ERROR, "Encoding: string '%s' is not a valid utf-8 string", str); } xmlNodeSetContentLen(ret, str, new_len); http://cvs.php.net/diff.php/php-src/ext/soap/php_sdl.c?r1=1.70.2.1&r2=1.70.2.2&ty=u Index: php-src/ext/soap/php_sdl.c diff -u php-src/ext/soap/php_sdl.c:1.70.2.1 php-src/ext/soap/php_sdl.c:1.70.2.2 --- php-src/ext/soap/php_sdl.c:1.70.2.1 Mon Aug 9 01:50:05 2004 +++ php-src/ext/soap/php_sdl.c Tue Aug 10 12:30:30 2004 @@ -17,7 +17,7 @@ | Dmitry Stogov <dmitry@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: php_sdl.c,v 1.70.2.1 2004/08/09 05:50:05 dmitry Exp $ */ +/* $Id: php_sdl.c,v 1.70.2.2 2004/08/10 16:30:30 dmitry Exp $ */ #include "php_soap.h" #include "libxml/uri.h" http://cvs.php.net/diff.php/php-src/ext/soap/php_soap.h?r1=1.33&r2=1.33.2.1&ty=u Index: php-src/ext/soap/php_soap.h diff -u php-src/ext/soap/php_soap.h:1.33 php-src/ext/soap/php_soap.h:1.33.2.1 --- php-src/ext/soap/php_soap.h:1.33 Wed May 5 06:31:26 2004 +++ php-src/ext/soap/php_soap.h Tue Aug 10 12:30:30 2004 @@ -17,7 +17,7 @@ | Dmitry Stogov <dmitry@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: php_soap.h,v 1.33 2004/05/05 10:31:26 dmitry Exp $ */ +/* $Id: php_soap.h,v 1.33.2.1 2004/08/10 16:30:30 dmitry Exp $ */ #ifndef PHP_SOAP_H #define PHP_SOAP_H @@ -115,6 +115,7 @@ int type; char *actor; char *uri; + xmlCharEncodingHandlerPtr encoding; }; #define SOAP_CLASS 1 @@ -158,6 +159,7 @@ zend_bool cache_enabled; char* cache_dir; long cache_ttl; + xmlCharEncodingHandlerPtr encoding; ZEND_END_MODULE_GLOBALS(soap) #ifdef PHP_WIN32 http://cvs.php.net/diff.php/php-src/ext/soap/soap.c?r1=1.110.2.1&r2=1.110.2.2&ty=u Index: php-src/ext/soap/soap.c diff -u php-src/ext/soap/soap.c:1.110.2.1 php-src/ext/soap/soap.c:1.110.2.2 --- php-src/ext/soap/soap.c:1.110.2.1 Mon Aug 9 01:50:05 2004 +++ php-src/ext/soap/soap.c Tue Aug 10 12:30:30 2004 @@ -17,7 +17,7 @@ | Dmitry Stogov <dmitry@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: soap.c,v 1.110.2.1 2004/08/09 05:50:05 dmitry Exp $ */ +/* $Id: soap.c,v 1.110.2.2 2004/08/10 16:30:30 dmitry Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -423,6 +423,7 @@ SOAP_GLOBAL(error_object) = NULL; SOAP_GLOBAL(sdl) = NULL; SOAP_GLOBAL(soap_version) = SOAP_1_1; + SOAP_GLOBAL(encoding) = NULL; return SUCCESS; } @@ -835,6 +836,19 @@ Z_TYPE_PP(tmp) == IS_STRING) { service->actor = estrndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); } + + if (zend_hash_find(ht, "encoding", sizeof("encoding"), (void**)&tmp) == SUCCESS && + Z_TYPE_PP(tmp) == IS_STRING) { + xmlCharEncodingHandlerPtr encoding; + + encoding = xmlFindCharEncodingHandler(Z_STRVAL_PP(tmp)); + if (encoding == NULL) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid arguments. Invalid 'encoding' option - '%s'.", Z_STRVAL_PP(tmp)); + } else { + service->encoding = encoding; + } + } + } else if (wsdl == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid arguments. 'uri' option is required in nonWSDL mode."); } @@ -1233,6 +1247,7 @@ sdlFunctionPtr function; char *arg = NULL; int arg_len; + xmlCharEncodingHandlerPtr old_encoding; SOAP_SERVER_BEGIN_CODE(); @@ -1374,6 +1389,8 @@ old_sdl = SOAP_GLOBAL(sdl); SOAP_GLOBAL(sdl) = service->sdl; + old_encoding = SOAP_GLOBAL(encoding); + SOAP_GLOBAL(encoding) = service->encoding; old_soap_version = SOAP_GLOBAL(soap_version); function = deserialize_function_call(service->sdl, doc_request, service->actor, &function_name, &num_params, ¶ms, &soap_version, &soap_headers TSRMLS_CC); xmlFreeDoc(doc_request); @@ -1636,6 +1653,7 @@ fail: SOAP_GLOBAL(soap_version) = old_soap_version; + SOAP_GLOBAL(encoding) = old_encoding; SOAP_GLOBAL(sdl) = old_sdl; /* Free soap headers */ @@ -1936,6 +1954,18 @@ zend_hash_exists(EG(function_table), "gzencode", sizeof("gzencode"))) { add_property_long(this_ptr, "compression", Z_LVAL_PP(tmp)); } + if (zend_hash_find(ht, "encoding", sizeof("encoding"), (void**)&tmp) == SUCCESS && + Z_TYPE_PP(tmp) == IS_STRING) { + xmlCharEncodingHandlerPtr encoding; + + encoding = xmlFindCharEncodingHandler(Z_STRVAL_PP(tmp)); + if (encoding == NULL) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid 'encoding' option - '%s'.", Z_STRVAL_PP(tmp)); + } else { + xmlCharEncCloseFunc(encoding); + add_property_stringl(this_ptr, "_encoding", Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1); + } + } } else if (wsdl == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "'location' and 'uri' options are requred in nonWSDL mode."); return; @@ -2046,6 +2076,7 @@ int ret = FALSE; int soap_version; zval response; + xmlCharEncodingHandlerPtr old_encoding; SOAP_CLIENT_BEGIN_CODE(); @@ -2070,6 +2101,14 @@ SOAP_GLOBAL(soap_version) = soap_version; old_sdl = SOAP_GLOBAL(sdl); SOAP_GLOBAL(sdl) = sdl; + old_encoding = SOAP_GLOBAL(encoding); + if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_encoding", sizeof("_encoding"), (void **) &tmp) == SUCCESS && + Z_TYPE_PP(tmp) == IS_STRING) { + SOAP_GLOBAL(encoding) = xmlFindCharEncodingHandler(Z_STRVAL_PP(tmp)); + } else { + SOAP_GLOBAL(encoding) = NULL; + } + if (sdl != NULL) { fn = get_function(sdl, function); if (fn != NULL) { @@ -2166,6 +2205,10 @@ zend_throw_exception_object(exception TSRMLS_CC); } #endif + if (SOAP_GLOBAL(encoding) != NULL) { + xmlCharEncCloseFunc(SOAP_GLOBAL(encoding)); + } + SOAP_GLOBAL(encoding) = old_encoding; SOAP_GLOBAL(sdl) = old_sdl; SOAP_CLIENT_END_CODE(); } @@ -3909,6 +3952,9 @@ } if (service->sdl) { delete_sdl(service->sdl); + } + if (service->encoding) { + xmlCharEncCloseFunc(service->encoding); } efree(service); } http://cvs.php.net/diff.php/php-src/ext/soap/tests/server021.phpt?r1=1.1&r2=1.1.2.1&ty=u Index: php-src/ext/soap/tests/server021.phpt diff -u php-src/ext/soap/tests/server021.phpt:1.1 php-src/ext/soap/tests/server021.phpt:1.1.2.1 --- php-src/ext/soap/tests/server021.phpt:1.1 Wed May 5 06:52:33 2004 +++ php-src/ext/soap/tests/server021.phpt Tue Aug 10 12:30:30 2004 @@ -5,7 +5,7 @@ --FILE-- <?php class Foo { - function __call($name) { + function __call($name, $args) { if ($name == "test") { return "Hello World"; } else { http://cvs.php.net/co.php/php-src/ext/soap/tests/bugs/bug28969.phpt?r=1.1&p=1 Index: php-src/ext/soap/tests/bugs/bug28969.phpt +++ php-src/ext/soap/tests/bugs/bug28969.phpt --TEST-- Bug #28969 (Wrong data encoding of special characters) --SKIPIF-- <?php require_once('skipif.inc'); ?> --FILE-- <?php function test() { return "¦è¥"; // return utf8_encode("¦è¥"); } class LocalSoapClient extends SoapClient { function LocalSoapClient($wsdl, $options) { $this->SoapClient($wsdl, $options); $this->server = new SoapServer($wsdl, $options); $this->server->addFunction('test'); } function __doRequest($request, $location, $action, $version) { ob_start(); $this->server->handle($request); $response = ob_get_contents(); ob_end_clean(); return $response; } } $x = new LocalSoapClient(NULL,array('location'=>'test://', 'uri'=>'http://testuri.org', 'encoding'=>'ISO-8859-1')); var_dump($x->test()); echo "ok\n"; ?> --EXPECT-- string(3) "¦è¥" ok
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1760.2.29&r2=1.1760.2.30&ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1760.2.29 php-src/NEWS:1.1760.2.30 --- php-src/NEWS:1.1760.2.29 Tue Aug 10 09:47:30 2004 +++ php-src/NEWS Tue Aug 10 12:30:30 2004 @@ -44,6 +44,7 @@ - Fixed bug #29109 (SoapFault exception: [WSDL] Out of memory). (Dmitry) - Fixed bug #29061 (soap extension segfaults). (Dmitry) - Fixed bug #28985 (__getTypes() returning nothing on complex WSDL). (Dmitry) +- Fixed bug #28969 (Wrong data encoding of special characters). (Dmitry) - Fixed bug #28895 (ReflectionClass::isAbstract always returns false). (Marcus) - Fixed bug #28829 (Thread-unsafety in bcmath elementary values). (Sara) - Fixed bug #28464 (catch() does not catch exceptions by interfaces). (Marcus) http://cvs.php.net/diff.php/php-src/ext/soap/php_encoding.c?r1=1.71&r2=1.71.2.1&ty=u Index: php-src/ext/soap/php_encoding.c diff -u php-src/ext/soap/php_encoding.c:1.71 php-src/ext/soap/php_encoding.c:1.71.2.1 --- php-src/ext/soap/php_encoding.c:1.71 Wed May 5 06:31:25 2004 +++ php-src/ext/soap/php_encoding.c Tue Aug 10 12:30:30 2004 @@ -17,7 +17,7 @@ | Dmitry Stogov <dmitry@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: php_encoding.c,v 1.71 2004/05/05 10:31:25 dmitry Exp $ */ +/* $Id: php_encoding.c,v 1.71.2.1 2004/08/10 16:30:30 dmitry Exp $ */ #include <time.h> @@ -31,6 +31,7 @@ static zval *to_zval_string(encodeTypePtr type, xmlNodePtr data); static zval *to_zval_stringr(encodeTypePtr type, xmlNodePtr data); static zval *to_zval_stringc(encodeTypePtr type, xmlNodePtr data); +static zval *to_zval_stringb(encodeTypePtr type, xmlNodePtr data); static zval *to_zval_map(encodeTypePtr type, xmlNodePtr data); static zval *to_zval_null(encodeTypePtr type, xmlNodePtr data); @@ -145,8 +146,8 @@ {{XSD_GMONTH, XSD_GMONTH_STRING, XSD_NAMESPACE, NULL}, to_zval_stringc, to_xml_gmonth}, {{XSD_DURATION, XSD_DURATION_STRING, XSD_NAMESPACE, NULL}, to_zval_stringc, to_xml_duration}, - {{XSD_HEXBINARY, XSD_HEXBINARY_STRING, XSD_NAMESPACE, NULL}, to_zval_stringc, to_xml_stringl}, - {{XSD_BASE64BINARY, XSD_BASE64BINARY_STRING, XSD_NAMESPACE, NULL}, to_zval_stringc, to_xml_stringl}, + {{XSD_HEXBINARY, XSD_HEXBINARY_STRING, XSD_NAMESPACE, NULL}, to_zval_stringb, to_xml_stringl}, + {{XSD_BASE64BINARY, XSD_BASE64BINARY_STRING, XSD_NAMESPACE, NULL}, to_zval_stringb, to_xml_stringl}, {{XSD_LONG, XSD_LONG_STRING, XSD_NAMESPACE, NULL}, to_zval_long, to_xml_long}, {{XSD_INT, XSD_INT_STRING, XSD_NAMESPACE, NULL}, to_zval_long, to_xml_long}, @@ -460,7 +461,23 @@ FIND_XML_NULL(data, ret); if (data && data->children) { if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { - ZVAL_STRING(ret, data->children->content, 1); + TSRMLS_FETCH(); + + if (SOAP_GLOBAL(encoding) != NULL) { + xmlBufferPtr in = xmlBufferCreateStatic(data->children->content, strlen(data->children->content)); + xmlBufferPtr out = xmlBufferCreate(); + int n = xmlCharEncOutFunc(SOAP_GLOBAL(encoding), out, in); + + if (n >= 0) { + ZVAL_STRING(ret, (char*)xmlBufferContent(out), 1); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } + xmlBufferFree(out); + xmlBufferFree(in); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } } else if (data->children->type == XML_CDATA_SECTION_NODE && data->children->next == NULL) { ZVAL_STRING(ret, data->children->content, 1); } else { @@ -479,8 +496,24 @@ FIND_XML_NULL(data, ret); if (data && data->children) { if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + TSRMLS_FETCH(); + whiteSpace_replace(data->children->content); - ZVAL_STRING(ret, data->children->content, 1); + if (SOAP_GLOBAL(encoding) != NULL) { + xmlBufferPtr in = xmlBufferCreateStatic(data->children->content, strlen(data->children->content)); + xmlBufferPtr out = xmlBufferCreate(); + int n = xmlCharEncOutFunc(SOAP_GLOBAL(encoding), out, in); + + if (n >= 0) { + ZVAL_STRING(ret, (char*)xmlBufferContent(out), 1); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } + xmlBufferFree(out); + xmlBufferFree(in); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } } else if (data->children->type == XML_CDATA_SECTION_NODE && data->children->next == NULL) { ZVAL_STRING(ret, data->children->content, 1); } else { @@ -499,6 +532,42 @@ FIND_XML_NULL(data, ret); if (data && data->children) { if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + TSRMLS_FETCH(); + + whiteSpace_collapse(data->children->content); + if (SOAP_GLOBAL(encoding) != NULL) { + xmlBufferPtr in = xmlBufferCreateStatic(data->children->content, strlen(data->children->content)); + xmlBufferPtr out = xmlBufferCreate(); + int n = xmlCharEncOutFunc(SOAP_GLOBAL(encoding), out, in); + + if (n >= 0) { + ZVAL_STRING(ret, (char*)xmlBufferContent(out), 1); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } + xmlBufferFree(out); + xmlBufferFree(in); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } + } else if (data->children->type == XML_CDATA_SECTION_NODE && data->children->next == NULL) { + ZVAL_STRING(ret, data->children->content, 1); + } else { + soap_error0(E_ERROR, "Encoding: Violation of encoding rules"); + } + } else { + ZVAL_EMPTY_STRING(ret); + } + return ret; +} + +static zval *to_zval_stringb(encodeTypePtr type, xmlNodePtr data) +{ + zval *ret; + MAKE_STD_ZVAL(ret); + FIND_XML_NULL(data, ret); + if (data && data->children) { + if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { whiteSpace_collapse(data->children->content); ZVAL_STRING(ret, data->children->content, 1); } else if (data->children->type == XML_CDATA_SECTION_NODE && data->children->next == NULL) { @@ -532,6 +601,24 @@ convert_to_string(&tmp); str = php_escape_html_entities(Z_STRVAL(tmp), Z_STRLEN(tmp), &new_len, 0, 0, NULL TSRMLS_CC); zval_dtor(&tmp); + } + + if (SOAP_GLOBAL(encoding) != NULL) { + xmlBufferPtr in = xmlBufferCreateStatic(str, new_len); + xmlBufferPtr out = xmlBufferCreate(); + int n = xmlCharEncInFunc(SOAP_GLOBAL(encoding), out, in); + + if (n >= 0) { + efree(str); + str = estrdup(xmlBufferContent(out)); + new_len = n; + } else if (!xmlCheckUTF8(str)) { + soap_error1(E_ERROR, "Encoding: string '%s' is not a valid utf-8 string", str); + } + xmlBufferFree(out); + xmlBufferFree(in); + } else if (!xmlCheckUTF8(str)) { + soap_error1(E_ERROR, "Encoding: string '%s' is not a valid utf-8 string", str); } xmlNodeSetContentLen(ret, str, new_len); http://cvs.php.net/diff.php/php-src/ext/soap/php_sdl.c?r1=1.70.2.1&r2=1.70.2.2&ty=u Index: php-src/ext/soap/php_sdl.c diff -u php-src/ext/soap/php_sdl.c:1.70.2.1 php-src/ext/soap/php_sdl.c:1.70.2.2 --- php-src/ext/soap/php_sdl.c:1.70.2.1 Mon Aug 9 01:50:05 2004 +++ php-src/ext/soap/php_sdl.c Tue Aug 10 12:30:30 2004 @@ -17,7 +17,7 @@ | Dmitry Stogov <dmitry@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: php_sdl.c,v 1.70.2.1 2004/08/09 05:50:05 dmitry Exp $ */ +/* $Id: php_sdl.c,v 1.70.2.2 2004/08/10 16:30:30 dmitry Exp $ */ #include "php_soap.h" #include "libxml/uri.h" http://cvs.php.net/diff.php/php-src/ext/soap/php_soap.h?r1=1.33&r2=1.33.2.1&ty=u Index: php-src/ext/soap/php_soap.h diff -u php-src/ext/soap/php_soap.h:1.33 php-src/ext/soap/php_soap.h:1.33.2.1 --- php-src/ext/soap/php_soap.h:1.33 Wed May 5 06:31:26 2004 +++ php-src/ext/soap/php_soap.h Tue Aug 10 12:30:30 2004 @@ -17,7 +17,7 @@ | Dmitry Stogov <dmitry@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: php_soap.h,v 1.33 2004/05/05 10:31:26 dmitry Exp $ */ +/* $Id: php_soap.h,v 1.33.2.1 2004/08/10 16:30:30 dmitry Exp $ */ #ifndef PHP_SOAP_H #define PHP_SOAP_H @@ -115,6 +115,7 @@ int type; char *actor; char *uri; + xmlCharEncodingHandlerPtr encoding; }; #define SOAP_CLASS 1 @@ -158,6 +159,7 @@ zend_bool cache_enabled; char* cache_dir; long cache_ttl; + xmlCharEncodingHandlerPtr encoding; ZEND_END_MODULE_GLOBALS(soap) #ifdef PHP_WIN32 http://cvs.php.net/diff.php/php-src/ext/soap/soap.c?r1=1.110.2.1&r2=1.110.2.2&ty=u Index: php-src/ext/soap/soap.c diff -u php-src/ext/soap/soap.c:1.110.2.1 php-src/ext/soap/soap.c:1.110.2.2 --- php-src/ext/soap/soap.c:1.110.2.1 Mon Aug 9 01:50:05 2004 +++ php-src/ext/soap/soap.c Tue Aug 10 12:30:30 2004 @@ -17,7 +17,7 @@ | Dmitry Stogov <dmitry@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: soap.c,v 1.110.2.1 2004/08/09 05:50:05 dmitry Exp $ */ +/* $Id: soap.c,v 1.110.2.2 2004/08/10 16:30:30 dmitry Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -423,6 +423,7 @@ SOAP_GLOBAL(error_object) = NULL; SOAP_GLOBAL(sdl) = NULL; SOAP_GLOBAL(soap_version) = SOAP_1_1; + SOAP_GLOBAL(encoding) = NULL; return SUCCESS; } @@ -835,6 +836,19 @@ Z_TYPE_PP(tmp) == IS_STRING) { service->actor = estrndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); } + + if (zend_hash_find(ht, "encoding", sizeof("encoding"), (void**)&tmp) == SUCCESS && + Z_TYPE_PP(tmp) == IS_STRING) { + xmlCharEncodingHandlerPtr encoding; + + encoding = xmlFindCharEncodingHandler(Z_STRVAL_PP(tmp)); + if (encoding == NULL) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid arguments. Invalid 'encoding' option - '%s'.", Z_STRVAL_PP(tmp)); + } else { + service->encoding = encoding; + } + } + } else if (wsdl == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid arguments. 'uri' option is required in nonWSDL mode."); } @@ -1233,6 +1247,7 @@ sdlFunctionPtr function; char *arg = NULL; int arg_len; + xmlCharEncodingHandlerPtr old_encoding; SOAP_SERVER_BEGIN_CODE(); @@ -1374,6 +1389,8 @@ old_sdl = SOAP_GLOBAL(sdl); SOAP_GLOBAL(sdl) = service->sdl; + old_encoding = SOAP_GLOBAL(encoding); + SOAP_GLOBAL(encoding) = service->encoding; old_soap_version = SOAP_GLOBAL(soap_version); function = deserialize_function_call(service->sdl, doc_request, service->actor, &function_name, &num_params, ¶ms, &soap_version, &soap_headers TSRMLS_CC); xmlFreeDoc(doc_request); @@ -1636,6 +1653,7 @@ fail: SOAP_GLOBAL(soap_version) = old_soap_version; + SOAP_GLOBAL(encoding) = old_encoding; SOAP_GLOBAL(sdl) = old_sdl; /* Free soap headers */ @@ -1936,6 +1954,18 @@ zend_hash_exists(EG(function_table), "gzencode", sizeof("gzencode"))) { add_property_long(this_ptr, "compression", Z_LVAL_PP(tmp)); } + if (zend_hash_find(ht, "encoding", sizeof("encoding"), (void**)&tmp) == SUCCESS && + Z_TYPE_PP(tmp) == IS_STRING) { + xmlCharEncodingHandlerPtr encoding; + + encoding = xmlFindCharEncodingHandler(Z_STRVAL_PP(tmp)); + if (encoding == NULL) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid 'encoding' option - '%s'.", Z_STRVAL_PP(tmp)); + } else { + xmlCharEncCloseFunc(encoding); + add_property_stringl(this_ptr, "_encoding", Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1); + } + } } else if (wsdl == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "'location' and 'uri' options are requred in nonWSDL mode."); return; @@ -2046,6 +2076,7 @@ int ret = FALSE; int soap_version; zval response; + xmlCharEncodingHandlerPtr old_encoding; SOAP_CLIENT_BEGIN_CODE(); @@ -2070,6 +2101,14 @@ SOAP_GLOBAL(soap_version) = soap_version; old_sdl = SOAP_GLOBAL(sdl); SOAP_GLOBAL(sdl) = sdl; + old_encoding = SOAP_GLOBAL(encoding); + if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_encoding", sizeof("_encoding"), (void **) &tmp) == SUCCESS && + Z_TYPE_PP(tmp) == IS_STRING) { + SOAP_GLOBAL(encoding) = xmlFindCharEncodingHandler(Z_STRVAL_PP(tmp)); + } else { + SOAP_GLOBAL(encoding) = NULL; + } + if (sdl != NULL) { fn = get_function(sdl, function); if (fn != NULL) { @@ -2166,6 +2205,10 @@ zend_throw_exception_object(exception TSRMLS_CC); } #endif + if (SOAP_GLOBAL(encoding) != NULL) { + xmlCharEncCloseFunc(SOAP_GLOBAL(encoding)); + } + SOAP_GLOBAL(encoding) = old_encoding; SOAP_GLOBAL(sdl) = old_sdl; SOAP_CLIENT_END_CODE(); } @@ -3909,6 +3952,9 @@ } if (service->sdl) { delete_sdl(service->sdl); + } + if (service->encoding) { + xmlCharEncCloseFunc(service->encoding); } efree(service); } http://cvs.php.net/diff.php/php-src/ext/soap/tests/server021.phpt?r1=1.1&r2=1.1.2.1&ty=u Index: php-src/ext/soap/tests/server021.phpt diff -u php-src/ext/soap/tests/server021.phpt:1.1 php-src/ext/soap/tests/server021.phpt:1.1.2.1 --- php-src/ext/soap/tests/server021.phpt:1.1 Wed May 5 06:52:33 2004 +++ php-src/ext/soap/tests/server021.phpt Tue Aug 10 12:30:30 2004 @@ -5,7 +5,7 @@ --FILE-- <?php class Foo { - function __call($name) { + function __call($name, $args) { if ($name == "test") { return "Hello World"; } else { http://cvs.php.net/co.php/php-src/ext/soap/tests/bugs/bug28969.phpt?r=1.1&p=1 Index: php-src/ext/soap/tests/bugs/bug28969.phpt +++ php-src/ext/soap/tests/bugs/bug28969.phpt --TEST-- Bug #28969 (Wrong data encoding of special characters) --SKIPIF-- <?php require_once('skipif.inc'); ?> --FILE-- <?php function test() { return "¦è¥"; // return utf8_encode("¦è¥"); } class LocalSoapClient extends SoapClient { function LocalSoapClient($wsdl, $options) { $this->SoapClient($wsdl, $options); $this->server = new SoapServer($wsdl, $options); $this->server->addFunction('test'); } function __doRequest($request, $location, $action, $version) { ob_start(); $this->server->handle($request); $response = ob_get_contents(); ob_end_clean(); return $response; } } $x = new LocalSoapClient(NULL,array('location'=>'test://', 'uri'=>'http://testuri.org', 'encoding'=>'ISO-8859-1')); var_dump($x->test()); echo "ok\n"; ?> --EXPECT-- string(3) "¦è¥" ok