From 207248483e29991215407fe2d2dd5ef1fd7e6fa7 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 20 Apr 2005 10:58:38 +0000 Subject: [PATCH] Fixed bug #32776 (SOAP doesn't support one-way operations) --- NEWS | 1 + ext/soap/php_packet_soap.c | 5 ++++ ext/soap/soap.c | 44 ++++++++++++++++++----------- ext/soap/tests/bugs/bug32776.phpt | 47 +++++++++++++++++++++++++++++++ ext/soap/tests/bugs/bug32776.wsdl | 47 +++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 17 deletions(-) create mode 100644 ext/soap/tests/bugs/bug32776.phpt create mode 100644 ext/soap/tests/bugs/bug32776.wsdl diff --git a/NEWS b/NEWS index 27e769cff7..e6375d2e3f 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ PHP NEWS - Changed sha1_file() and md5_file() functions to use streams instead of low level IO. (Uwe) - Fixed memory corruption in ImageTTFText() with 64bit systems. (Andrey) +- Fixed bug #32776 (SOAP doesn't support one-way operations). (Dmitry) - Fixed bug #32759 (incorrect determination of default value (COM)). (Wez) - Fixed bug #32758 (Cannot access safearray properties in VB6 objects). (Wez) - Fixed bug #32755 (Segfault in replaceChild() when DocumentFragment has diff --git a/ext/soap/php_packet_soap.c b/ext/soap/php_packet_soap.c index 81805b4b42..fbf476611b 100644 --- a/ext/soap/php_packet_soap.c +++ b/ext/soap/php_packet_soap.c @@ -34,6 +34,11 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction ZVAL_NULL(return_value); + /* Response for one-way opearation */ + if (buffer_size == 0) { + return TRUE; + } + /* Parse XML packet */ response = soap_xmlParseMemory(buffer, buffer_size); diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 42fd649716..41c7d30060 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1689,25 +1689,30 @@ PHP_METHOD(SoapServer, handle) /* Flush buffer */ php_end_ob_buffer(0, 0 TSRMLS_CC); - /* xmlDocDumpMemoryEnc(doc_return, &buf, &size, XML_CHAR_ENCODING_UTF8); */ - xmlDocDumpMemory(doc_return, &buf, &size); - - if (size == 0) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Dump memory failed"); - } + if (doc_return) { + /* xmlDocDumpMemoryEnc(doc_return, &buf, &size, XML_CHAR_ENCODING_UTF8); */ + xmlDocDumpMemory(doc_return, &buf, &size); + + if (size == 0) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Dump memory failed"); + } + + sprintf(cont_len, "Content-Length: %d", size); + sapi_add_header(cont_len, strlen(cont_len), 1); + if (soap_version == SOAP_1_2) { + sapi_add_header("Content-Type: application/soap+xml; charset=utf-8", sizeof("Content-Type: application/soap+xml; charset=utf-8")-1, 1); + } else { + sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1); + } - sprintf(cont_len, "Content-Length: %d", size); - sapi_add_header(cont_len, strlen(cont_len), 1); - if (soap_version == SOAP_1_2) { - sapi_add_header("Content-Type: application/soap+xml; charset=utf-8", sizeof("Content-Type: application/soap+xml; charset=utf-8")-1, 1); + xmlFreeDoc(doc_return); + php_write(buf, size TSRMLS_CC); + xmlFree(buf); } else { - sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1); + sapi_add_header("HTTP/1.1 202 Accepted", sizeof("HTTP/1.1 202 Accepted")-1, 1); + sapi_add_header("Content-Length: 0", sizeof("Content-Length: 0")-1, 1); } - xmlFreeDoc(doc_return); - php_write(buf, size TSRMLS_CC); - xmlFree(buf); - fail: SOAP_GLOBAL(soap_version) = old_soap_version; SOAP_GLOBAL(encoding) = old_encoding; @@ -3156,7 +3161,7 @@ static int serialize_response_call2(xmlNodePtr body, sdlFunctionPtr function, ch ns = encode_add_ns(body, fnb->output.ns); if (function->responseName) { method = xmlNewChild(body, ns, function->responseName, NULL); - } else { + } else if (function->responseParameters) { method = xmlNewChild(body, ns, function->functionName, NULL); } } @@ -3248,6 +3253,7 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function xmlNodePtr envelope = NULL, body, param; xmlNsPtr ns = NULL; int use = SOAP_LITERAL; + xmlNodePtr head = NULL; encode_reset_ns(); @@ -3459,7 +3465,6 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function } else { if (headers) { - xmlNodePtr head; soapHeader *h; head = xmlNewChild(envelope, ns, "Header", NULL); @@ -3552,6 +3557,11 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function } } + if (function && function->responseName == NULL && + body->children == NULL && head == NULL) { + xmlFreeDoc(doc); + return NULL; + } return doc; } diff --git a/ext/soap/tests/bugs/bug32776.phpt b/ext/soap/tests/bugs/bug32776.phpt new file mode 100644 index 0000000000..b3c4ff0170 --- /dev/null +++ b/ext/soap/tests/bugs/bug32776.phpt @@ -0,0 +1,47 @@ +--TEST-- +Bug #32776 SOAP doesn't support one-way operations +--SKIPIF-- + +--FILE-- +server = new SoapServer($wsdl, $options); + $this->server->addFunction('test'); + } + + function __doRequest($request, $location, $action, $version) { + ob_start(); + $this->server->handle($request); + $response = ob_get_contents(); + ob_end_clean(); + return $response; + } + +} + +$x = new LocalSoapClient(dirname(__FILE__)."/bug32776.wsdl",array("trace"=>true,"exceptions"=>false)); +var_dump($x->test("Hello")); +var_dump($d); +var_dump($x->__getLastRequest()); +var_dump($x->__getLastResponse()); +echo "ok\n"; +?> +--EXPECT-- +NULL +string(5) "Hello" +string(459) " +Hello +" +string(0) "" +ok diff --git a/ext/soap/tests/bugs/bug32776.wsdl b/ext/soap/tests/bugs/bug32776.wsdl new file mode 100644 index 0000000000..733901849e --- /dev/null +++ b/ext/soap/tests/bugs/bug32776.wsdl @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.40.0