Commit:    fd8f45452032720d3239af2106434232c95249e2
Author:    Dmitry Stogov <dmi...@zend.com>         Wed, 31 Jul 2013 16:32:26 
+0400
Parents:   0a974f14d13832838dcc7bae88b3271b7d035f46
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=fd8f45452032720d3239af2106434232c95249e2

Log:
Fixed bug #65018 (SoapHeader problems with SoapServer)

Bugs:
https://bugs.php.net/65018

Changed paths:
  M  NEWS
  M  ext/soap/soap.c
  A  ext/soap/tests/bugs/bug65018.phpt

diff --git a/NEWS b/NEWS
index 97c25df..d480e3d 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,9 @@ PHP                                                           
             NEWS
   . Fixed bug #50308 (session id not appended properly for empty anchor tags).
     (Arpad)
 
+- SOAP:
+  . Fixed bug #65018 (SoapHeader problems with SoapServer). (Dmitry)
+
 - SPL:
   . Fixed bug #65328 (Segfault when getting SplStack object Value). (Laruence)
 
diff --git a/ext/soap/soap.c b/ext/soap/soap.c
index e08f8b6..9371df6 100644
--- a/ext/soap/soap.c
+++ b/ext/soap/soap.c
@@ -3658,7 +3658,44 @@ ignore_header:
        return function;
 }
 
-static int serialize_response_call2(xmlNodePtr body, sdlFunctionPtr function, 
char *function_name, char *uri, zval *ret, int version, int main TSRMLS_DC)
+static void set_soap_header_attributes(xmlNodePtr h, HashTable *ht, int 
version)
+{
+       zval **tmp;
+
+       if (zend_hash_find(ht, "mustUnderstand", sizeof("mustUnderstand"), 
(void**)&tmp) == SUCCESS &&
+           Z_TYPE_PP(tmp) == IS_BOOL && Z_LVAL_PP(tmp)) {
+               if (version == SOAP_1_1) {
+                       xmlSetProp(h, 
BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":mustUnderstand"), BAD_CAST("1"));
+               } else {
+                       xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":mustUnderstand"), BAD_CAST("true"));
+               }
+       }
+       if (zend_hash_find(ht, "actor", sizeof("actor"), (void**)&tmp) == 
SUCCESS) {
+               if (Z_TYPE_PP(tmp) == IS_STRING) {
+                       if (version == SOAP_1_1) {
+                               xmlSetProp(h, 
BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":actor"), BAD_CAST(Z_STRVAL_PP(tmp)));
+                       } else {
+                               xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(Z_STRVAL_PP(tmp)));
+                       }
+               } else if (Z_TYPE_PP(tmp) == IS_LONG) {
+                       if (version == SOAP_1_1) {
+                               if (Z_LVAL_PP(tmp) == SOAP_ACTOR_NEXT) {
+                                       xmlSetProp(h, 
BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":actor"), BAD_CAST(SOAP_1_1_ACTOR_NEXT));
+                               }
+                       } else {
+                               if (Z_LVAL_PP(tmp) == SOAP_ACTOR_NEXT) {
+                                       xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_NEXT));
+                               } else if (Z_LVAL_PP(tmp) == SOAP_ACTOR_NONE) {
+                                       xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_NONE));
+                               } else if (Z_LVAL_PP(tmp) == 
SOAP_ACTOR_UNLIMATERECEIVER) {
+                                       xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), 
BAD_CAST(SOAP_1_2_ACTOR_UNLIMATERECEIVER));
+                               }
+                       }
+               }
+       }
+}
+
+static int serialize_response_call2(xmlNodePtr body, sdlFunctionPtr function, 
char *function_name, char *uri, zval *ret, int version, int main, xmlNodePtr 
*node TSRMLS_DC)
 {
        xmlNodePtr method = NULL, param;
        sdlParamPtr parameter = NULL;
@@ -3758,6 +3795,9 @@ static int serialize_response_call2(xmlNodePtr body, 
sdlFunctionPtr function, ch
        if (use == SOAP_ENCODED && version == SOAP_1_2 && method != NULL) {
                xmlSetNsProp(method, body->ns, BAD_CAST("encodingStyle"), 
BAD_CAST(SOAP_1_2_ENC_NAMESPACE));
        }
+       if (node) {
+               *node = method;
+       }
        return use;
 }
 
@@ -3839,7 +3879,7 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr 
function, char *function
                        }
 
                        if (headers->function) {
-                               if (serialize_response_call2(head, 
headers->function, Z_STRVAL(headers->function_name), uri, hdr_ret, version, 0 
TSRMLS_CC) == SOAP_ENCODED) {
+                               if (serialize_response_call2(head, 
headers->function, Z_STRVAL(headers->function_name), uri, hdr_ret, version, 0, 
NULL TSRMLS_CC) == SOAP_ENCODED) {
                                        use = SOAP_ENCODED;
                                }
                        } else {
@@ -4025,15 +4065,15 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr 
function, char *function
                                        zval *hdr_ret = &h->retval;
                                        char *hdr_ns   = h->hdr?h->hdr->ns:NULL;
                                        char *hdr_name = 
Z_STRVAL(h->function_name);
-
+                                       HashTable *ht = NULL;
 
                                        if (Z_TYPE(h->retval) == IS_OBJECT &&
                                            
instanceof_function(Z_OBJCE(h->retval), soap_header_class_entry TSRMLS_CC)) {
-                                               HashTable* ht = 
Z_OBJPROP(h->retval);
                                                zval **tmp;
                                                sdlSoapBindingFunctionHeaderPtr 
*hdr;
                                                smart_str key = {0};
 
+                                               ht = Z_OBJPROP(h->retval);
                                                if (zend_hash_find(ht, 
"namespace", sizeof("namespace"), (void**)&tmp) == SUCCESS &&
                                              Z_TYPE_PP(tmp) == IS_STRING) {
                                                        smart_str_appendl(&key, 
Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
@@ -4064,9 +4104,14 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr 
function, char *function
                                        }
 
                                        if (h->function) {
-                                               if 
(serialize_response_call2(head, h->function, Z_STRVAL(h->function_name), uri, 
hdr_ret, version, 0 TSRMLS_CC) == SOAP_ENCODED) {
+                                               xmlNodePtr xmlHdr = NULL;
+
+                                               if 
(serialize_response_call2(head, h->function, Z_STRVAL(h->function_name), uri, 
hdr_ret, version, 0, &xmlHdr TSRMLS_CC) == SOAP_ENCODED) {
                                                        use = SOAP_ENCODED;
                                                }
+                                               if (ht) {
+                                                       
set_soap_header_attributes(xmlHdr, ht, version);
+                                               }
                                        } else {
                                                xmlNodePtr xmlHdr = 
master_to_xml(hdr_enc, hdr_ret, hdr_use, head TSRMLS_CC);
                                                if (hdr_name) {
@@ -4076,6 +4121,9 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr 
function, char *function
                                                        xmlNsPtr nsptr = 
encode_add_ns(xmlHdr,hdr_ns);
                                                        xmlSetNs(xmlHdr, nsptr);
                                                }
+                                               if (ht) {
+                                                       
set_soap_header_attributes(xmlHdr, ht, version);
+                                               }
                                        }
                                }
                                h = h->next;
@@ -4089,7 +4137,7 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr 
function, char *function
 
                body = xmlNewChild(envelope, ns, BAD_CAST("Body"), NULL);
 
-               if (serialize_response_call2(body, function, function_name, 
uri, ret, version, 1 TSRMLS_CC) == SOAP_ENCODED) {
+               if (serialize_response_call2(body, function, function_name, 
uri, ret, version, 1, NULL TSRMLS_CC) == SOAP_ENCODED) {
                        use = SOAP_ENCODED;
                }
 
@@ -4281,38 +4329,7 @@ static xmlDocPtr serialize_function_call(zval *this_ptr, 
sdlFunctionPtr function
                                }
                                nsptr = encode_add_ns(h, Z_STRVAL_PP(ns));
                                xmlSetNs(h, nsptr);
-
-                               if (zend_hash_find(ht, "mustUnderstand", 
sizeof("mustUnderstand"), (void**)&tmp) == SUCCESS &&
-                                   Z_TYPE_PP(tmp) == IS_BOOL && 
Z_LVAL_PP(tmp)) {
-                                       if (version == SOAP_1_1) {
-                                               xmlSetProp(h, 
BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":mustUnderstand"), BAD_CAST("1"));
-                                       } else {
-                                               xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":mustUnderstand"), BAD_CAST("true"));
-                                       }
-                               }
-                               if (zend_hash_find(ht, "actor", 
sizeof("actor"), (void**)&tmp) == SUCCESS) {
-                                       if (Z_TYPE_PP(tmp) == IS_STRING) {
-                                               if (version == SOAP_1_1) {
-                                                       xmlSetProp(h, 
BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":actor"), BAD_CAST(Z_STRVAL_PP(tmp)));
-                                               } else {
-                                                       xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(Z_STRVAL_PP(tmp)));
-                                               }
-                                       } else if (Z_TYPE_PP(tmp) == IS_LONG) {
-                                               if (version == SOAP_1_1) {
-                                                       if (Z_LVAL_PP(tmp) == 
SOAP_ACTOR_NEXT) {
-                                                               xmlSetProp(h, 
BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":actor"), BAD_CAST(SOAP_1_1_ACTOR_NEXT));
-                                                       }
-                                               } else {
-                                                       if (Z_LVAL_PP(tmp) == 
SOAP_ACTOR_NEXT) {
-                                                               xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_NEXT));
-                                                       } else if 
(Z_LVAL_PP(tmp) == SOAP_ACTOR_NONE) {
-                                                               xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_NONE));
-                                                       } else if 
(Z_LVAL_PP(tmp) == SOAP_ACTOR_UNLIMATERECEIVER) {
-                                                               xmlSetProp(h, 
BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), 
BAD_CAST(SOAP_1_2_ACTOR_UNLIMATERECEIVER));
-                                                       }
-                                               }
-                                       }
-                               }
+                               set_soap_header_attributes(h, ht, version);
                        }
                        zend_hash_move_forward(soap_headers);
                }
diff --git a/ext/soap/tests/bugs/bug65018.phpt 
b/ext/soap/tests/bugs/bug65018.phpt
new file mode 100644
index 0000000..bbb9b5e
--- /dev/null
+++ b/ext/soap/tests/bugs/bug65018.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Bug #65018 (SoapHeader problems with SoapServer)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+       class Tool{
+               public function TOKEN($id){
+                       return new SoapHeader('namespace1', 'TOKEN', $id, true);
+               }
+               public function Method(){}
+       }
+
+       $input = $input =
+               '<?xml version="1.0"?>'.PHP_EOL.
+               '<SOAP-ENV:Envelope 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:ns1="namespace1"'.
+               ' xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";'.
+               ' xmlns:xsd="http://www.w3.org/2001/XMLSchema";>'.
+               '<SOAP-ENV:Header><ns1:TOKEN 
soapenv:mustUnderstand="1">abc</ns1:TOKEN></SOAP-ENV:Header>'.
+               '<SOAP-ENV:Body><ns1:Method 
/></SOAP-ENV:Body></SOAP-ENV:Envelope>';
+
+       $soap = new SoapServer(null, array('uri' => '127.0.0.1'));
+       $soap->setClass('Tool');
+       $soap->handle($input);
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:ns1="namespace1" xmlns:ns2="127.0.0.1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"; 
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";><SOAP-ENV:Header><ns1:TOKEN
 
SOAP-ENV:mustUnderstand="1">abc</ns1:TOKEN></SOAP-ENV:Header><SOAP-ENV:Body><ns2:MethodResponse><return
 xsi:nil="true"/></ns2:MethodResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to