dmitry          Tue Aug 10 12:11:41 2004 EDT

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/soap   php_encoding.c php_soap.h soap.c 
  Log:
  Fixed bug #28969 (Wrong data encoding of special characters).
  
  
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1787&r2=1.1788&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1787 php-src/NEWS:1.1788
--- php-src/NEWS:1.1787 Tue Aug 10 10:57:47 2004
+++ php-src/NEWS        Tue Aug 10 12:11:40 2004
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2004, PHP 5.1.0
+- Fixed bug #28969 (Wrong data encoding of special characters). (Dmitry)
 - Fixed bug #29256 (SOAP HTTP Error when envelop size is more than 24345 bytes)
   (Dmitry, Wez)
 - Fixed bug #29522 (accessing properties without connection) (Georg)
http://cvs.php.net/diff.php/php-src/ext/soap/php_encoding.c?r1=1.71&r2=1.72&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.72
--- 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:11:41 2004
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: php_encoding.c,v 1.71 2004/05/05 10:31:25 dmitry Exp $ */
+/* $Id: php_encoding.c,v 1.72 2004/08/10 16:11:41 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_soap.h?r1=1.33&r2=1.34&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.34
--- 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:11:41 2004
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: php_soap.h,v 1.33 2004/05/05 10:31:26 dmitry Exp $ */
+/* $Id: php_soap.h,v 1.34 2004/08/10 16:11:41 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.114&r2=1.115&ty=u
Index: php-src/ext/soap/soap.c
diff -u php-src/ext/soap/soap.c:1.114 php-src/ext/soap/soap.c:1.115
--- php-src/ext/soap/soap.c:1.114       Tue Jul 20 03:39:32 2004
+++ php-src/ext/soap/soap.c     Tue Aug 10 12:11:41 2004
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: soap.c,v 1.114 2004/07/20 07:39:32 dmitry Exp $ */
+/* $Id: soap.c,v 1.115 2004/08/10 16:11:41 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, &params, &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);
 }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to