Browse Source

Fixed bug #65018 (SoapHeader problems with SoapServer)

pull/400/head
Dmitry Stogov 13 years ago
parent
commit
fd8f454520
  1. 3
      NEWS
  2. 93
      ext/soap/soap.c
  3. 28
      ext/soap/tests/bugs/bug65018.phpt

3
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)

93
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);
}

28
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>
Loading…
Cancel
Save