]> granicus.if.org Git - php/commitdiff
Fixed bug #32139 (SOAP client does not auto-handle base64 encoding).
authorIlia Alshanetsky <iliaa@php.net>
Wed, 27 Jul 2005 14:52:52 +0000 (14:52 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 27 Jul 2005 14:52:52 +0000 (14:52 +0000)
NEWS
ext/soap/php_encoding.c
ext/soap/tests/interop/Round2/Base/r2_base_017p.phpt
ext/soap/tests/interop/Round2/Base/r2_base_017s.phpt
ext/soap/tests/interop/Round2/Base/r2_base_017w.phpt
ext/soap/tests/interop/Round4/GroupI/r4_groupI_xsd_006w.phpt

diff --git a/NEWS b/NEWS
index 5b419f046f74b300131e4b022c75d3e2bc66fc73..ddeef9599718b558fa72f3818f4555fab3d56e65 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ PHP                                                                        NEWS
 - Fixed bug #33578 (strtotime() problem with "Oct17" format). (Derick)
 - Fixed bug #33558 (warning with nested calls to functions returning by
   reference). (Dmitry)
+- Fixed bug #32139 (SOAP client does not auto-handle base64 encoding). (Ilia)
 
 14 Jul 2005, PHP 5.1 Beta 3
 - Upgraded bundled SQLite library for PDO:SQLite to 3.2.2 (Ilia)
index 68709dc34390222d73eab1d925ac1dea5bfd5622..9d3d10c22061c4a9773bd3ea641fdfc054acb47f 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "php_soap.h"
 #include "ext/libxml/php_libxml.h"
+#include "ext/standard/base64.h"
 #include <libxml/parserInternals.h>
 #include "zend_strtod.h"
 
@@ -607,9 +608,26 @@ static zval *to_zval_stringb(encodeTypePtr type, xmlNodePtr data)
        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);
+
+                       if (type->type_str && !strcmp(type->type_str, "base64Binary")) {
+                               unsigned char *str;
+                               int str_len;
+                       
+                               str = php_base64_decode(data->children->content, strlen(data->children->content), &str_len);
+                               ZVAL_STRINGL(ret, str, str_len, 0);
+                       } 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);
+                       if (type->type_str && !strcmp(type->type_str, "base64Binary")) {
+                               unsigned char *str;
+                               int str_len;
+                       
+                               str = php_base64_decode(data->children->content, strlen(data->children->content), &str_len);
+                               ZVAL_STRINGL(ret, str, str_len, 0);
+                       } else {
+                               ZVAL_STRING(ret, data->children->content, 1);
+                       }
                } else {
                        soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
                }
@@ -637,7 +655,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);
        }
 
@@ -671,19 +689,38 @@ static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNo
 static xmlNodePtr to_xml_stringl(encodeTypePtr type, zval *data, int style, xmlNodePtr parent)
 {
        xmlNodePtr ret;
+       zend_bool benc = type->type_str && !strcmp(type->type_str, "base64Binary");
 
        ret = xmlNewNode(NULL,"BOGUS");
        xmlAddChild(parent, ret);
        FIND_ZVAL_NULL(data, ret, style);
 
        if (Z_TYPE_P(data) == IS_STRING) {
-               xmlNodeSetContentLen(ret, Z_STRVAL_P(data), Z_STRLEN_P(data));
+               if (!benc) {
+                       xmlNodeSetContentLen(ret, Z_STRVAL_P(data), Z_STRLEN_P(data));
+               } else {
+                       char *str;
+                       int str_len;
+                       
+                       str = php_base64_encode(Z_STRVAL_P(data), Z_STRLEN_P(data), &str_len);
+                       xmlNodeSetContentLen(ret, str, str_len);
+                       efree(str);
+               }
        } else {
                zval tmp = *data;
 
                zval_copy_ctor(&tmp);
                convert_to_string(&tmp);
-               xmlNodeSetContentLen(ret, Z_STRVAL(tmp), Z_STRLEN(tmp));
+               if (!benc) {
+                       xmlNodeSetContentLen(ret, Z_STRVAL(tmp), Z_STRLEN(tmp));
+               } else {
+                       char *str;
+                       int str_len;
+
+                       str = php_base64_encode(Z_STRVAL(tmp), Z_STRLEN(tmp), &str_len);
+                       xmlNodeSetContentLen(ret, str, str_len);
+                       efree(str);
+               }
                zval_dtor(&tmp);
        }
 
index 92261b626669544fbb236961e1f42209133f6539..5f6b3c314304d05f978a66c673c241999be09262 100644 (file)
@@ -5,7 +5,7 @@ SOAP Interop Round2 base 017 (php/direct): echoBase64
 --FILE--
 <?php
 $client = new SoapClient(NULL,array("location"=>"test://","uri"=>"http://soapinterop.org/","trace"=>1,"exceptions"=>0));
-$client->__soapCall("echoBase64", array('TmVicmFza2E='), array("soapaction"=>"http://soapinterop.org/","uri"=>"http://soapinterop.org/"));
+$client->__soapCall("echoBase64", array('Nebraska'), array("soapaction"=>"http://soapinterop.org/","uri"=>"http://soapinterop.org/"));
 echo $client->__getlastrequest();
 $HTTP_RAW_POST_DATA = $client->__getlastrequest();
 include("round2_base.inc");
@@ -13,7 +13,7 @@ echo "ok\n";
 ?>
 --EXPECT--
 <?xml version="1.0" encoding="UTF-8"?>
-<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soapinterop.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:echoBase64><param0 xsi:type="xsd:string">TmVicmFza2E=</param0></ns1:echoBase64></SOAP-ENV:Body></SOAP-ENV:Envelope>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soapinterop.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:echoBase64><param0 xsi:type="xsd:string">Nebraska</param0></ns1:echoBase64></SOAP-ENV:Body></SOAP-ENV:Envelope>
 <?xml version="1.0" encoding="UTF-8"?>
 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soapinterop.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:echoBase64Response><outputBase64 xsi:type="xsd:base64Binary">TmVicmFza2E=</outputBase64></ns1:echoBase64Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
 ok
index 21b5f61a7a18dcf6ba2d90cdbad0f2a0f47fee1e..3e3c6e12720d94f276b32f7411c3a3a6cd6799ef 100644 (file)
@@ -5,7 +5,7 @@ SOAP Interop Round2 base 017 (soap/direct): echoBase64
 --FILE--
 <?php
 $client = new SoapClient(NULL,array("location"=>"test://","uri"=>"http://soapinterop.org/","trace"=>1,"exceptions"=>0));
-$client->__soapCall("echoBase64", array(new SoapParam(new SoapVar('TmVicmFza2E=',XSD_BASE64BINARY),"inputBase64")), array("soapaction"=>"http://soapinterop.org/","uri"=>"http://soapinterop.org/"));
+$client->__soapCall("echoBase64", array(new SoapParam(new SoapVar('Nebraska',XSD_BASE64BINARY),"inputBase64")), array("soapaction"=>"http://soapinterop.org/","uri"=>"http://soapinterop.org/"));
 echo $client->__getlastrequest();
 $HTTP_RAW_POST_DATA = $client->__getlastrequest();
 include("round2_base.inc");
index af351b59e84f2d24e572b3f4a11938ff74eb0c43..7471c371d9001f4bb6362777e49b7a1ce565c8f5 100644 (file)
@@ -5,7 +5,7 @@ SOAP Interop Round2 base 017 (php/wsdl): echoBase64
 --FILE--
 <?php
 $client = new SoapClient(dirname(__FILE__)."/round2_base.wsdl",array("trace"=>1,"exceptions"=>0));
-$client->echoBase64('TmVicmFza2E=');
+$client->echoBase64('Nebraska');
 echo $client->__getlastrequest();
 $HTTP_RAW_POST_DATA = $client->__getlastrequest();
 include("round2_base.inc");
index 58e6b46b0ff449df8a7aee376af7d48351e11395..c9d953407030ea4e2548bd124be5c6f064ce29bd 100644 (file)
Binary files a/ext/soap/tests/interop/Round4/GroupI/r4_groupI_xsd_006w.phpt and b/ext/soap/tests/interop/Round4/GroupI/r4_groupI_xsd_006w.phpt differ