dmitry Thu Apr 21 07:16:50 2005 EDT
Modified files:
/php-src/ext/soap soap.c
Log:
Fixed wrong SoapFault codes. The codes MUST be namespace qualified.
http://cvs.php.net/diff.php/php-src/ext/soap/soap.c?r1=1.143&r2=1.144&ty=u
Index: php-src/ext/soap/soap.c
diff -u php-src/ext/soap/soap.c:1.143 php-src/ext/soap/soap.c:1.144
--- php-src/ext/soap/soap.c:1.143 Wed Apr 20 06:59:01 2005
+++ php-src/ext/soap/soap.c Thu Apr 21 07:16:48 2005
@@ -17,7 +17,7 @@
| Dmitry Stogov <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: soap.c,v 1.143 2005/04/20 10:59:01 dmitry Exp $ */
+/* $Id: soap.c,v 1.144 2005/04/21 11:16:48 dmitry Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -48,7 +48,7 @@
static void type_to_string(sdlTypePtr type, smart_str *buf, int level);
static void clear_soap_fault(zval *obj TSRMLS_DC);
-static void set_soap_fault(zval *obj, char *fault_code, char *fault_string,
char *fault_actor, zval *fault_detail, char *name TSRMLS_DC);
+static void set_soap_fault(zval *obj, char *fault_code_ns, char *fault_code,
char *fault_string, char *fault_actor, zval *fault_detail, char *name
TSRMLS_DC);
static void soap_server_fault(char* code, char* string, char *actor, zval*
details, char *name TSRMLS_DC);
static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault,
soapHeader* hdr TSRMLS_DC);
@@ -719,17 +719,36 @@
SoapFault constructor */
PHP_METHOD(SoapFault, SoapFault)
{
- char *fault_string = NULL, *fault_code = NULL, *fault_actor = NULL,
*name = NULL;
+ char *fault_string = NULL, *fault_code = NULL, *fault_actor = NULL,
*name = NULL, *fault_code_ns = NULL;
int fault_string_len, fault_code_len, fault_actor_len, name_len;
- zval *details = NULL, *headerfault = NULL;
+ zval *code = NULL, *details = NULL, *headerfault = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s!z!s!z",
- &fault_code, &fault_code_len,
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|s!z!s!z",
+ &code,
&fault_string, &fault_string_len,
&fault_actor, &fault_actor_len,
&details, &name, &name_len, &headerfault) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameters");
}
+ if (Z_TYPE_P(code) == IS_NULL) {
+ } else if (Z_TYPE_P(code) == IS_STRING) {
+ fault_code = Z_STRVAL_P(code);
+ } else if (Z_TYPE_P(code) == IS_ARRAY &&
zend_hash_num_elements(Z_ARRVAL_P(code)) == 2) {
+ zval **t_ns, **t_code;
+
+ zend_hash_internal_pointer_reset(Z_ARRVAL_P(code));
+ zend_hash_get_current_data(Z_ARRVAL_P(code), (void**)&t_ns);
+ zend_hash_move_forward(Z_ARRVAL_P(code));
+ zend_hash_get_current_data(Z_ARRVAL_P(code), (void**)&t_code);
+ if (Z_TYPE_PP(t_ns) == IS_STRING && Z_TYPE_PP(t_code) ==
IS_STRING) {
+ fault_code_ns = Z_STRVAL_PP(t_ns);
+ fault_code = Z_STRVAL_PP(t_code);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid
parameters. Invalid fault code.");
+ }
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameters.
Invalid fault code.");
+ }
if (fault_code != NULL && fault_code_len == 0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameters.
Invalid fault code.");
}
@@ -737,7 +756,7 @@
name = NULL;
}
- set_soap_fault(this_ptr, fault_code, fault_string, fault_actor,
details, name TSRMLS_CC);
+ set_soap_fault(this_ptr, fault_code_ns, fault_code, fault_string,
fault_actor, details, name TSRMLS_CC);
if (headerfault != NULL) {
add_property_zval(this_ptr, "headerfault", headerfault);
}
@@ -1810,7 +1829,7 @@
INIT_ZVAL(ret);
- set_soap_fault(&ret, code, string, actor, details, name TSRMLS_CC);
+ set_soap_fault(&ret, NULL, code, string, actor, details, name
TSRMLS_CC);
/* TODO: Which function */
soap_server_fault_ex(NULL, &ret, NULL TSRMLS_CC);
}
@@ -1912,7 +1931,7 @@
php_end_ob_buffer(0, 0 TSRMLS_CC);
INIT_ZVAL(fault_obj);
- set_soap_fault(&fault_obj, code, buffer, NULL, outbuf,
NULL TSRMLS_CC);
+ set_soap_fault(&fault_obj, NULL, code, buffer, NULL,
outbuf, NULL TSRMLS_CC);
fault = 1;
}
@@ -2713,7 +2732,7 @@
{
zval *fault;
ALLOC_INIT_ZVAL(fault);
- set_soap_fault(fault, fault_code, fault_string, fault_actor,
fault_detail, NULL TSRMLS_CC);
+ set_soap_fault(fault, NULL, fault_code, fault_string, fault_actor,
fault_detail, NULL TSRMLS_CC);
#ifdef ZEND_ENGINE_2
fault->refcount--;
#endif
@@ -2721,7 +2740,7 @@
return fault;
}
-static void set_soap_fault(zval *obj, char *fault_code, char *fault_string,
char *fault_actor, zval *fault_detail, char *name TSRMLS_DC)
+static void set_soap_fault(zval *obj, char *fault_code_ns, char *fault_code,
char *fault_string, char *fault_actor, zval *fault_detail, char *name TSRMLS_DC)
{
if (Z_TYPE_P(obj) != IS_OBJECT) {
object_init_ex(obj, soap_fault_class_entry);
@@ -2731,38 +2750,36 @@
}
if (fault_code != NULL) {
int soap_version = SOAP_GLOBAL(soap_version);
- smart_str code = {0};
- if (soap_version == SOAP_1_1) {
- if (strcmp(fault_code,"Client") == 0 ||
- strcmp(fault_code,"Server") == 0 ||
- strcmp(fault_code,"VersionMismatch") == 0 ||
- strcmp(fault_code,"MustUnderstand") == 0) {
- smart_str_appendl(&code,
SOAP_1_1_ENV_NS_PREFIX, sizeof(SOAP_1_1_ENV_NS_PREFIX)-1);
- smart_str_appendc(&code, ':');
- }
- smart_str_appends(&code,fault_code);
- } else if (soap_version == SOAP_1_2) {
- if (strcmp(fault_code,"Client") == 0) {
- smart_str_appendl(&code,
SOAP_1_2_ENV_NS_PREFIX, sizeof(SOAP_1_2_ENV_NS_PREFIX)-1);
- smart_str_appendc(&code, ':');
-
smart_str_appendl(&code,"Sender",sizeof("Sender")-1);
- } else if (strcmp(fault_code,"Server") == 0) {
- smart_str_appendl(&code,
SOAP_1_2_ENV_NS_PREFIX, sizeof(SOAP_1_2_ENV_NS_PREFIX)-1);
- smart_str_appendc(&code, ':');
-
smart_str_appendl(&code,"Receiver",sizeof("Receiver")-1);
- } else if (strcmp(fault_code,"VersionMismatch") == 0 ||
- strcmp(fault_code,"MustUnderstand") == 0 ||
- strcmp(fault_code,"DataEncodingUnknown") ==
0) {
- smart_str_appendl(&code,
SOAP_1_2_ENV_NS_PREFIX, sizeof(SOAP_1_2_ENV_NS_PREFIX)-1);
- smart_str_appendc(&code, ':');
- smart_str_appends(&code,fault_code);
- } else {
- smart_str_appends(&code,fault_code);
+
+ if (fault_code_ns) {
+ add_property_string(obj, "faultcode", fault_code, 1);
+ add_property_string(obj, "faultcodens", fault_code_ns,
1);
+ } else {
+ if (soap_version == SOAP_1_1) {
+ add_property_string(obj, "faultcode",
fault_code, 1);
+ if (strcmp(fault_code,"Client") == 0 ||
+ strcmp(fault_code,"Server") == 0 ||
+ strcmp(fault_code,"VersionMismatch") == 0 ||
+ strcmp(fault_code,"MustUnderstand") == 0) {
+ add_property_string(obj, "faultcodens",
SOAP_1_1_ENV_NAMESPACE, 1);
+ }
+ } else if (soap_version == SOAP_1_2) {
+ if (strcmp(fault_code,"Client") == 0) {
+ add_property_string(obj, "faultcode",
"Sender", 1);
+ add_property_string(obj, "faultcodens",
SOAP_1_2_ENV_NAMESPACE, 1);
+ } else if (strcmp(fault_code,"Server") == 0) {
+ add_property_string(obj, "faultcode",
"Receiver", 1);
+ add_property_string(obj, "faultcodens",
SOAP_1_2_ENV_NAMESPACE, 1);
+ } else if (strcmp(fault_code,"VersionMismatch")
== 0 ||
+ strcmp(fault_code,"MustUnderstand")
== 0 ||
+
strcmp(fault_code,"DataEncodingUnknown") == 0) {
+ add_property_string(obj, "faultcode",
fault_code, 1);
+ add_property_string(obj, "faultcodens",
SOAP_1_2_ENV_NAMESPACE, 1);
+ } else {
+ add_property_string(obj, "faultcode",
fault_code, 1);
+ }
}
}
- smart_str_0(&code);
- add_property_string(obj, "faultcode", code.c, 1);
- smart_str_free(&code);
}
if (fault_actor != NULL) {
add_property_string(obj, "faultactor", fault_actor, 1);
@@ -3280,6 +3297,7 @@
HashTable* prop;
zval **tmp;
sdlFaultPtr fault = NULL;
+ char *fault_ns = NULL;
prop = Z_OBJPROP_P(ret);
@@ -3344,6 +3362,9 @@
body = xmlNewChild(envelope, ns, "Body", NULL);
param = xmlNewChild(body, ns, "Fault", NULL);
+ if (zend_hash_find(prop, "faultcodens", sizeof("faultcodens"),
(void**)&tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_STRING) {
+ fault_ns = Z_STRVAL_PP(tmp);
+ }
use = SOAP_LITERAL;
if (zend_hash_find(prop, "_name", sizeof("_name"),
(void**)&tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_STRING) {
sdlFaultPtr *tmp_fault;
@@ -3355,6 +3376,9 @@
fault->bindingAttributes) {
sdlSoapBindingFunctionFaultPtr fb =
(sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
use = fb->use;
+ if (fault_ns == NULL) {
+ fault_ns = fb->ns;
+ }
}
}
} else if (function && function->faults &&
@@ -3368,6 +3392,23 @@
fault->bindingAttributes) {
sdlSoapBindingFunctionFaultPtr fb =
(sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
use = fb->use;
+ if (fault_ns == NULL) {
+ fault_ns = fb->ns;
+ }
+ }
+ }
+
+ if (fault_ns == NULL &&
+ fault &&
+ fault->details &&
+ zend_hash_num_elements(fault->details) == 1) {
+ sdlParamPtr sparam;
+
+ zend_hash_internal_pointer_reset(fault->details);
+ zend_hash_get_current_data(fault->details,
(void**)&sparam);
+ sparam = *(sdlParamPtr*)sparam;
+ if (sparam->element) {
+ fault_ns = sparam->element->namens;
}
}
@@ -3377,7 +3418,12 @@
xmlNodePtr node = xmlNewNode(NULL, "faultcode");
char *str =
php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0,
NULL TSRMLS_CC);
xmlAddChild(param, node);
- xmlNodeSetContentLen(node, str, new_len);
+ if (fault_ns) {
+ xmlNsPtr nsptr = encode_add_ns(node,
fault_ns);
+ xmlNodeSetContent(node,
xmlBuildQName(str, nsptr->prefix, NULL, 0));
+ } else {
+ xmlNodeSetContentLen(node, str,
new_len);
+ }
efree(str);
}
if (zend_hash_find(prop, "faultstring",
sizeof("faultstring"), (void**)&tmp) == SUCCESS) {
@@ -3403,7 +3449,12 @@
xmlNodePtr node = xmlNewChild(param, ns,
"Code", NULL);
char *str =
php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0,
NULL TSRMLS_CC);
node = xmlNewChild(node, ns, "Value", NULL);
- xmlNodeSetContentLen(node, str, new_len);
+ if (fault_ns) {
+ xmlNsPtr nsptr = encode_add_ns(node,
fault_ns);
+ xmlNodeSetContent(node,
xmlBuildQName(str, nsptr->prefix, NULL, 0));
+ } else {
+ xmlNodeSetContentLen(node, str,
new_len);
+ }
efree(str);
}
if (zend_hash_find(prop, "faultstring",
sizeof("faultstring"), (void**)&tmp) == SUCCESS) {
@@ -3439,7 +3490,7 @@
function->binding->bindingType == BINDING_SOAP &&
function->bindingAttributes) {
sdlSoapBindingFunctionPtr fnb =
(sdlSoapBindingFunctionPtr)function->bindingAttributes;
- if (fnb->style == SOAP_RPC) {
+ if (fnb->style == SOAP_RPC && !sparam->element)
{
if (fault->bindingAttributes) {
sdlSoapBindingFunctionFaultPtr
fb = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
if (fb->ns) {
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php