]> granicus.if.org Git - php/commitdiff
SOAP 1.2 Fault support (Code,Reason,Datail instead of faultcode,faultstring,...)
authorDmitry Stogov <dmitry@php.net>
Mon, 26 Jan 2004 16:19:29 +0000 (16:19 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 26 Jan 2004 16:19:29 +0000 (16:19 +0000)
ext/soap/TODO
ext/soap/php_packet_soap.c
ext/soap/soap.c

index efa3f150aff52b107be023fb5e524c300dd0b543..80cbea48eb6d366ec877f8926b93c28e399ffbe2 100644 (file)
@@ -14,7 +14,7 @@ SOAP
 + SOAP 1.1 fault codes ("client","server"), SOAP 1.1 fault codes ("Sender","Receiver")
 + SOAP 1.1 Content-Type - "text/xml", SOAP 1.2 - "application/soap+xml"
 + support for SOAP 1.2 <rpc:result> (ignore it)
-- SOAP 1.2 uses the element names env:Code and env:Reason, respectively, for what used to be called faultcode and faultstring in SOAP 1.1.
++ SOAP 1.2 uses the element names env:Code and env:Reason, respectively, for what used to be called faultcode and faultstring in SOAP 1.1.
 - support for SOAP headers
   - actor attribute
   - mustUnderstend attribute
index 327597ca0a12bcaafbe556480b6cac8570d4731c..9bc874efeb26d4cd0902dd85cd507acb85957ac7 100644 (file)
@@ -8,6 +8,7 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction
        xmlNodePtr trav, env, head, body, resp, cur, fault;
        int param_count = 0;
        int old_error_reporting;
+       int soap_version;
 
        ZVAL_NULL(return_value);
 
@@ -37,9 +38,11 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction
                        if (env == NULL && node_is_equal_ex(trav,"Envelope",SOAP_1_1_ENV_NAMESPACE)) {
                                env = trav;
                                envelope_ns = SOAP_1_1_ENV_NAMESPACE;
+                               soap_version = SOAP_1_1;
                        } else if (env == NULL && node_is_equal_ex(trav,"Envelope",SOAP_1_2_ENV_NAMESPACE)) {
                                env = trav;
                                envelope_ns = SOAP_1_2_ENV_NAMESPACE;
+                               soap_version = SOAP_1_2;
                        } else {
                                add_soap_fault(this_ptr, "Client", "looks like we got bad SOAP response\n", NULL, NULL TSRMLS_CC);
                                xmlFreeDoc(response);
@@ -92,26 +95,42 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction
                zval *details = NULL;
                xmlNodePtr tmp;
 
-               tmp = get_node(fault->children,"faultcode");
-               if (tmp != NULL && tmp->children != NULL) {
-                       faultcode = tmp->children->content;
-               }
+               if (soap_version == SOAP_1_1) {
+                       tmp = get_node(fault->children,"faultcode");
+                       if (tmp != NULL && tmp->children != NULL) {
+                               faultcode = tmp->children->content;
+                       }
 
-               tmp = get_node(fault->children,"faultstring");
-               if (tmp != NULL && tmp->children != NULL) {
-                       faultstring = tmp->children->content;
-               }
+                       tmp = get_node(fault->children,"faultstring");
+                       if (tmp != NULL && tmp->children != NULL) {
+                               faultstring = tmp->children->content;
+                       }
 
-               tmp = get_node(fault->children,"faultactor");
-               if (tmp != NULL && tmp->children != NULL) {
-                       faultactor = tmp->children->content;
-               }
+                       tmp = get_node(fault->children,"faultactor");
+                       if (tmp != NULL && tmp->children != NULL) {
+                               faultactor = tmp->children->content;
+                       }
 
-               tmp = get_node(fault->children,"detail");
-               if (tmp != NULL) {
-                       details = master_to_zval(NULL, tmp);
-               }
+                       tmp = get_node(fault->children,"detail");
+                       if (tmp != NULL) {
+                               details = master_to_zval(NULL, tmp);
+                       }
+               } else {
+                       tmp = get_node(fault->children,"Code");
+                       if (tmp != NULL && tmp->children != NULL) {
+                               faultcode = tmp->children->content;
+                       }
 
+                       tmp = get_node(fault->children,"Reason");
+                       if (tmp != NULL && tmp->children != NULL) {
+                               faultstring = tmp->children->content;
+                       }
+
+                       tmp = get_node(fault->children,"Detail");
+                       if (tmp != NULL) {
+                               details = master_to_zval(NULL, tmp);
+                       }
+               }
                add_soap_fault(this_ptr, faultcode, faultstring, faultactor, details TSRMLS_CC);
                xmlFreeDoc(response);
                return FALSE;
index 6be76495d0510e6658ef85c309c08ba1357c9f46..0e31a9fee7617229aab9180724d5171b051bfe14 100644 (file)
@@ -1687,7 +1687,6 @@ static void soap_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_proper
 static void clear_soap_fault(zval *obj TSRMLS_DC)
 {
        if (obj != NULL && obj->type == IS_OBJECT) {
-/*             zend_hash_del(obj->value.obj.properties, "__soap_fault", sizeof("__soap_fault"));*/
                zend_hash_del(Z_OBJPROP_P(obj), "__soap_fault", sizeof("__soap_fault"));
        }
 }
@@ -1945,9 +1944,62 @@ static xmlDocPtr seralize_response_call(sdlFunctionPtr function, char *function_
                Z_OBJCE_P(ret) == soap_fault_class_entry) {
                use = SOAP_ENCODED;
                if (version == SOAP_1_1) {
-                       param = seralize_zval(ret, NULL, SOAP_1_1_ENV_NS_PREFIX":Fault", use TSRMLS_CC);
+                       HashTable* prop;
+                       zval **tmp;
+
+                       prop = Z_OBJPROP_P(ret);
+                       param = xmlNewNode(NULL, SOAP_1_1_ENV_NS_PREFIX":Fault");
+                       if (zend_hash_find(prop, "faultcode", sizeof("faultcode"), (void**)&tmp) == SUCCESS) {
+                               int new_len;
+                               xmlNodePtr node = xmlNewChild(param, NULL, "faultcode", NULL);
+                               char *str = php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
+                               xmlNodeSetContentLen(node, str, new_len);
+                               efree(str);
+                       }
+                       if (zend_hash_find(prop, "faultstring", sizeof("faultstring"), (void**)&tmp) == SUCCESS) {
+                               int new_len;
+                               xmlNodePtr node = xmlNewChild(param, NULL, "faultstring", NULL);
+                               char *str = php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
+                               xmlNodeSetContentLen(node, str, new_len);
+                               efree(str);
+                       }
+                       if (zend_hash_find(prop, "faultactor", sizeof("faultactor"), (void**)&tmp) == SUCCESS) {
+                               int new_len;
+                               xmlNodePtr node = xmlNewChild(param, NULL, "faultactor", NULL);
+                               char *str = php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
+                               xmlNodeSetContentLen(node, str, new_len);
+                               efree(str);
+                       }
+                       if (zend_hash_find(prop, "detail", sizeof("detail"), (void**)&tmp) == SUCCESS &&
+                           Z_TYPE_PP(tmp) != IS_NULL) {
+                               xmlNodePtr node = seralize_zval(*tmp, NULL, "detail", use TSRMLS_CC);
+                               xmlAddChild(param,node);
+                       }
                } else {
-                       param = seralize_zval(ret, NULL, SOAP_1_2_ENV_NS_PREFIX":Fault", use TSRMLS_CC);
+                       HashTable* prop;
+                       zval **tmp;
+
+                       prop = Z_OBJPROP_P(ret);
+                       param = xmlNewNode(NULL, SOAP_1_2_ENV_NS_PREFIX":Fault");
+                       if (zend_hash_find(prop, "faultcode", sizeof("faultcode"), (void**)&tmp) == SUCCESS) {
+                               int new_len;
+                               xmlNodePtr node = xmlNewChild(param, NULL, SOAP_1_2_ENV_NS_PREFIX":Code", NULL);
+                               char *str = php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
+                               xmlNodeSetContentLen(node, str, new_len);
+                               efree(str);
+                       }
+                       if (zend_hash_find(prop, "faultstring", sizeof("faultstring"), (void**)&tmp) == SUCCESS) {
+                               int new_len;
+                               xmlNodePtr node = xmlNewChild(param, NULL, SOAP_1_2_ENV_NS_PREFIX":Reason", NULL);
+                               char *str = php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
+                               xmlNodeSetContentLen(node, str, new_len);
+                               efree(str);
+                       }
+                       if (zend_hash_find(prop, "detail", sizeof("detail"), (void**)&tmp) == SUCCESS &&
+                           Z_TYPE_PP(tmp) != IS_NULL) {
+                               xmlNodePtr node = seralize_zval(*tmp, NULL, SOAP_1_2_ENV_NS_PREFIX":Detail", use TSRMLS_CC);
+                               xmlAddChild(param,node);
+                       }
                }
                xmlAddChild(body, param);
        } else {