dmitry          Tue Mar 21 12:05:10 2006 UTC

  Modified files:              
    /php-src/ext/soap   php_soap.h soap.c 
    /php-src/ext/soap/tests     server023.phpt server024.phpt 
                                server025.phpt server025.wsdl 
  Log:
  Fixed bug #36721 (The SoapServer is not able to send a header that it didn't 
receive)
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/soap/php_soap.h?r1=1.41&r2=1.42&diff_format=u
Index: php-src/ext/soap/php_soap.h
diff -u php-src/ext/soap/php_soap.h:1.41 php-src/ext/soap/php_soap.h:1.42
--- php-src/ext/soap/php_soap.h:1.41    Tue Feb  7 12:49:30 2006
+++ php-src/ext/soap/php_soap.h Tue Mar 21 12:05:09 2006
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: php_soap.h,v 1.41 2006/02/07 12:49:30 dmitry Exp $ */
+/* $Id: php_soap.h,v 1.42 2006/03/21 12:05:09 dmitry Exp $ */
 
 #ifndef PHP_SOAP_H
 #define PHP_SOAP_H
@@ -97,6 +97,8 @@
        } map_class;
 };
 
+struct _soapHeader;
+
 struct _soapService {
        sdlPtr sdl;
 
@@ -120,6 +122,7 @@
        xmlCharEncodingHandlerPtr encoding;
        HashTable *class_map;
        int        features;
+       struct _soapHeader **soap_headers_ptr;
 };
 
 #define SOAP_CLASS 1
http://cvs.php.net/viewcvs.cgi/php-src/ext/soap/soap.c?r1=1.179&r2=1.180&diff_format=u
Index: php-src/ext/soap/soap.c
diff -u php-src/ext/soap/soap.c:1.179 php-src/ext/soap/soap.c:1.180
--- php-src/ext/soap/soap.c:1.179       Fri Mar 10 11:47:05 2006
+++ php-src/ext/soap/soap.c     Tue Mar 21 12:05:09 2006
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: soap.c,v 1.179 2006/03/10 11:47:05 dmitry Exp $ */
+/* $Id: soap.c,v 1.180 2006/03/21 12:05:09 dmitry Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -244,6 +244,7 @@
 PHP_METHOD(SoapServer, handle);
 PHP_METHOD(SoapServer, setPersistence);
 PHP_METHOD(SoapServer, fault);
+PHP_METHOD(SoapServer, addSoapHeader);
 #ifdef HAVE_PHP_DOMXML
 PHP_METHOD(PHP_SOAP_SERVER_CLASS, map);
 #endif
@@ -309,6 +310,7 @@
        PHP_ME(SoapServer, getFunctions, NULL, 0)
        PHP_ME(SoapServer, handle, NULL, 0)
        PHP_ME(SoapServer, fault, NULL, 0)
+       PHP_ME(SoapServer, addSoapHeader, NULL, 0)
 #ifdef HAVE_PHP_DOMXML
        PHP_ME(SoapServer, map, NULL, 0)
 #endif
@@ -1520,6 +1522,8 @@
        function = deserialize_function_call(service->sdl, doc_request, 
service->actor, &function_name, &num_params, &params, &soap_version, 
&soap_headers TSRMLS_CC);
        xmlFreeDoc(doc_request);
 
+       service->soap_headers_ptr = &soap_headers;
+
        soap_obj = NULL;
        if (service->type == SOAP_CLASS) {
 #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
@@ -1804,15 +1808,18 @@
                int i;
 
                soap_headers = soap_headers->next;
-               i = h->num_params;
-               while (i > 0) {
-                       zval_ptr_dtor(&h->parameters[--i]);
+               if (h->parameters) {
+                       i = h->num_params;
+                       while (i > 0) {
+                               zval_ptr_dtor(&h->parameters[--i]);
+                       }
+                       efree(h->parameters);
                }
-               efree(h->parameters);
                zval_dtor(&h->function_name);
                zval_dtor(&h->retval);
                efree(h);
        }
+       service->soap_headers_ptr = NULL;
 
        /* Free Memory */
        if (num_params > 0) {
@@ -1849,6 +1856,37 @@
 }
 /* }}} */
 
+PHP_METHOD(SoapServer, addSoapHeader)
+{
+       soapServicePtr service;
+       zval *fault;
+       soapHeader **p;
+
+       SOAP_SERVER_BEGIN_CODE();
+
+       FETCH_THIS_SERVICE(service);
+
+       if (!service || !service->soap_headers_ptr) {
+               php_error_docref(NULL TSRMLS_CC, E_ERROR, "The 
SoapServer::addSoapHeader function may be called only during SOAP request 
processing");
+       }
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &fault, 
soap_header_class_entry) == FAILURE) {
+               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameters");
+       }
+
+       p = service->soap_headers_ptr;
+       while (*p != NULL) {
+               p = &(*p)->next;
+       }
+       *p = emalloc(sizeof(soapHeader));
+       memset(*p, 0, sizeof(soapHeader));
+       ZVAL_NULL(&(*p)->function_name);
+       (*p)->retval = *fault;
+       zval_copy_ctor(&(*p)->retval);
+
+       SOAP_SERVER_END_CODE();
+}
+
 static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, 
soapHeader *hdr TSRMLS_DC)
 {
        int soap_version;
@@ -2519,7 +2557,7 @@
        zend_hash_internal_pointer_reset(ht);
        while (zend_hash_get_current_data(ht, (void**)&tmp) == SUCCESS) {
                if (Z_TYPE_PP(tmp) != IS_OBJECT ||
-                   Z_OBJCE_PP(tmp) != soap_header_class_entry) {
+                   !instanceof_function(Z_OBJCE_PP(tmp), 
soap_header_class_entry TSRMLS_CC)) {
                        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid SOAP 
header");
                }
                zend_hash_move_forward(ht);
@@ -2579,7 +2617,7 @@
                verify_soap_headers_array(soap_headers TSRMLS_CC);
                free_soap_headers = 0;
        } else if (Z_TYPE_P(headers) == IS_OBJECT &&
-                  Z_OBJCE_P(headers) == soap_header_class_entry) {
+                  instanceof_function(Z_OBJCE_P(headers), 
soap_header_class_entry TSRMLS_CC)) {
            soap_headers = emalloc(sizeof(HashTable));
                zend_hash_init(soap_headers, 0, NULL, ZVAL_PTR_DTOR, 0);
                zend_hash_next_index_insert(soap_headers, &headers, 
sizeof(zval*), NULL);
@@ -2842,7 +2880,7 @@
                        add_property_zval(this_ptr, "__default_headers", 
headers);
                }
        } else if (Z_TYPE_P(headers) == IS_OBJECT &&
-                  Z_OBJCE_P(headers) == soap_header_class_entry) {
+                  instanceof_function(Z_OBJCE_P(headers), 
soap_header_class_entry TSRMLS_CC)) {
                zval *default_headers;
                ALLOC_INIT_ZVAL(default_headers);
                array_init(default_headers);
@@ -3514,7 +3552,7 @@
 
                        head = xmlNewChild(envelope, ns, "Header", NULL);
                        if (Z_TYPE_P(hdr_ret) == IS_OBJECT &&
-                           Z_OBJCE_P(hdr_ret) == soap_header_class_entry) {
+                           instanceof_function(Z_OBJCE_P(hdr_ret), 
soap_header_class_entry TSRMLS_CC)) {
                                HashTable* ht = Z_OBJPROP_P(hdr_ret);
                                zval **tmp;
                                sdlSoapBindingFunctionHeaderPtr *hdr;
@@ -3741,7 +3779,7 @@
 
 
                                        if (Z_TYPE(h->retval) == IS_OBJECT &&
-                                           Z_OBJCE(h->retval) == 
soap_header_class_entry) {
+                                           
instanceof_function(Z_OBJCE(h->retval), soap_header_class_entry TSRMLS_CC)) {
                                                HashTable* ht = 
Z_OBJPROP(h->retval);
                                                zval **tmp;
                                                sdlSoapBindingFunctionHeaderPtr 
*hdr;
http://cvs.php.net/viewcvs.cgi/php-src/ext/soap/tests/server023.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/soap/tests/server023.phpt
diff -u /dev/null php-src/ext/soap/tests/server023.phpt:1.2
--- /dev/null   Tue Mar 21 12:05:10 2006
+++ php-src/ext/soap/tests/server023.phpt       Tue Mar 21 12:05:10 2006
@@ -0,0 +1,37 @@
+--TEST--
+SOAP Server 23: Send SOAP headers those were not received
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function test() {
+       global $server;
+       $server->addSoapHeader(new SoapHeader("http://testuri.org";, "Test1", 
"Hello Header!"));
+       $server->addSoapHeader(new SoapHeader("http://testuri.org";, "Test2", 
"Hello Header!"));
+       return "Hello Body!";
+}
+
+$server = new soapserver(null,array('uri'=>"http://testuri.org";));
+$server->addfunction("test");
+
+$HTTP_RAW_POST_DATA = <<<EOF
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<SOAP-ENV:Envelope
+  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
+  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
+  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xmlns:si="http://soapinterop.org/xsd";>
+  <SOAP-ENV:Body>
+    <ns1:test xmlns:ns1="http://testuri.org"/>
+  </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
+EOF;
+
+$server->handle();
+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://testuri.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:Header><ns1:Test1>Hello
 Header!</ns1:Test1><ns1:Test2>Hello 
Header!</ns1:Test2></SOAP-ENV:Header><SOAP-ENV:Body><ns1:testResponse><return 
xsi:type="xsd:string">Hello 
Body!</return></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
+ok
http://cvs.php.net/viewcvs.cgi/php-src/ext/soap/tests/server024.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/soap/tests/server024.phpt
diff -u /dev/null php-src/ext/soap/tests/server024.phpt:1.2
--- /dev/null   Tue Mar 21 12:05:10 2006
+++ php-src/ext/soap/tests/server024.phpt       Tue Mar 21 12:05:10 2006
@@ -0,0 +1,49 @@
+--TEST--
+SOAP Server 24: Send SOAP headers those were not received
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+class TestHeader1 extends SoapHeader {
+       function __construct($data) {
+               parent::__construct("http://testuri.org";, "Test1", $data);
+       }
+}
+
+class TestHeader2 extends SoapHeader {
+       function __construct($data) {
+               parent::__construct("http://testuri.org";, "Test2", $data);
+       }
+}
+
+function test() {
+       global $server;
+       $server->addSoapHeader(new TestHeader1("Hello Header!"));
+       $server->addSoapHeader(new TestHeader2("Hello Header!"));
+       return "Hello Body!";
+}
+
+$server = new soapserver(null,array('uri'=>"http://testuri.org";));
+$server->addfunction("test");
+
+$HTTP_RAW_POST_DATA = <<<EOF
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<SOAP-ENV:Envelope
+  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
+  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
+  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xmlns:si="http://soapinterop.org/xsd";>
+  <SOAP-ENV:Body>
+    <ns1:test xmlns:ns1="http://testuri.org"/>
+  </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
+EOF;
+
+$server->handle();
+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://testuri.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:Header><ns1:Test1>Hello
 Header!</ns1:Test1><ns1:Test2>Hello 
Header!</ns1:Test2></SOAP-ENV:Header><SOAP-ENV:Body><ns1:testResponse><return 
xsi:type="xsd:string">Hello 
Body!</return></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
+ok
http://cvs.php.net/viewcvs.cgi/php-src/ext/soap/tests/server025.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/soap/tests/server025.phpt
diff -u /dev/null php-src/ext/soap/tests/server025.phpt:1.2
--- /dev/null   Tue Mar 21 12:05:10 2006
+++ php-src/ext/soap/tests/server025.phpt       Tue Mar 21 12:05:10 2006
@@ -0,0 +1,46 @@
+--TEST--
+SOAP Server 25: One-way SOAP headers encoding using WSDL
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+class TestHeader1 extends SoapHeader {
+       function __construct($data) {
+               parent::__construct("http://testuri.org";, "Test1", $data);
+       }
+}
+
+class TestHeader2 extends SoapHeader {
+       function __construct($data) {
+               parent::__construct("http://testuri.org";, "Test2", $data);
+       }
+}
+
+function test() {
+       global $server;
+       $server->addSoapHeader(new TestHeader1("Hello Header!"));
+       $server->addSoapHeader(new TestHeader2("Hello Header!"));
+       return "Hello Body!";
+}
+
+$server = new soapserver(dirname(__FILE__)."/server025.wsdl");
+$server->addfunction("test");
+
+$HTTP_RAW_POST_DATA = <<<EOF
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<SOAP-ENV:Envelope
+  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
+  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";>
+  <SOAP-ENV:Body>
+    <ns1:test xmlns:ns1="http://testuri.org"/>
+  </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
+EOF;
+
+$server->handle();
+echo "ok\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:ns1="http://testuri.org";><SOAP-ENV:Header><ns1:Test1 
xsi:type="xsd:string">Hello Header!</ns1:Test1><ns1:Test2 
xsi:type="xsd:string">Hello 
Header!</ns1:Test2></SOAP-ENV:Header><SOAP-ENV:Body><ns1:testResponse><result>Hello
 Body!</result></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
+ok
http://cvs.php.net/viewcvs.cgi/php-src/ext/soap/tests/server025.wsdl?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/soap/tests/server025.wsdl
diff -u /dev/null php-src/ext/soap/tests/server025.wsdl:1.2
--- /dev/null   Tue Mar 21 12:05:10 2006
+++ php-src/ext/soap/tests/server025.wsdl       Tue Mar 21 12:05:10 2006
@@ -0,0 +1,55 @@
+<?xml version="1.0" ?>
+<definitions
+    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
+    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/";
+    xmlns:si="http://soapinterop.org/xsd";
+    xmlns:tns="http://linuxsrv.home/~dmitry/soap/test.wsdl";
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
+    xmlns="http://schemas.xmlsoap.org/wsdl/";
+    targetNamespace="http://testuri.org";>
+
+  <message name="TestHeader1">
+    <part name="Test1" type="xsd:string" />
+  </message>
+  <message name="TestHeader2">
+    <part name="Test2" type="xsd:string" />
+  </message>
+
+  <message name="TestRequest">
+  </message>
+  <message name="TestResponse">
+    <part name="result" type="xsd:string" />
+  </message>
+
+  <portType name="TestServicePortType">
+    <operation name="test">
+      <input message="tns:TestRequest" />
+      <output message="tns:TestResponse" />
+    </operation>
+  </portType>
+
+  <binding name="TestServiceBinding" type="tns:TestServicePortType">
+    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"; 
/>
+    <operation name="test">
+      <soap:operation soapAction="Test" style="rpc" />
+      <input>
+        <soap:body namespace="http://testuri.org"; use="encoded" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"; />
+      </input>
+      <output>
+        <soap:body namespace="http://testuri.org"; use="literal" />
+        <soap:header namespace="http://testuri.org"; message="tns:TestHeader1" 
part="Test1" use="encoded" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"; />
+        <soap:header namespace="http://testuri.org"; message="tns:TestHeader2" 
part="Test2" use="encoded" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"; />
+      </output>
+    </operation>
+  </binding>
+
+  <service name="TestService">
+    <port name="TestServicePort" binding="tns:TestServiceBinding">
+      <soap:address 
location="http://linuxsrv.home/~dmitry/soap/soap_server.php"; />
+    </port>
+  </service>
+
+</definitions>

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

Reply via email to