]> granicus.if.org Git - php/commitdiff
Make ext/soap work around libxml2 bug in xmlCheckUTF8 (2.6.7-2.6.13)
authorDmitry Stogov <dmitry@php.net>
Tue, 7 Sep 2004 14:41:29 +0000 (14:41 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 7 Sep 2004 14:41:29 +0000 (14:41 +0000)
ext/soap/php_encoding.c

index 99786128684ab85e885162dfb416f5bd03caf94e..d107d7ff5d3b6a5210bbcf414ef5ab6c27987e20 100644 (file)
@@ -581,6 +581,32 @@ static zval *to_zval_stringb(encodeTypePtr type, xmlNodePtr data)
        return ret;
 }
 
+static int php_soap_xmlCheckUTF8(const unsigned char *s)
+{
+       int i;
+       unsigned char c;
+
+       for (i = 0; (c = s[i++]);) {
+               if ((c & 0x80) == 0) {
+               } else if ((c & 0xe0) == 0xc0) {
+                       if ((s[i++] & 0xc0) != 0x80) {
+                               return 0;
+                       }
+               } else if ((c & 0xf0) == 0xe0) {
+                       if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) {
+                               return 0;
+                       }
+               } else if ((c & 0xf8) == 0xf0) {
+                       if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) {
+                               return 0;
+                       }
+               } else {
+                       return 0;
+               }
+       }
+       return 1;
+}
+
 static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNodePtr parent)
 {
        xmlNodePtr ret;
@@ -612,12 +638,12 @@ static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNo
                        efree(str);
                        str = estrdup(xmlBufferContent(out));
                        new_len = n;
-               } else if (!xmlCheckUTF8(str)) {
+               } else if (!php_soap_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)) {
+       } else if (!php_soap_xmlCheckUTF8(str)) {
                soap_error1(E_ERROR,  "Encoding: string '%s' is not a valid utf-8 string", str);
        }