diff options
author | Dmitry Stogov <dmitry@php.net> | 2004-01-15 16:56:29 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2004-01-15 16:56:29 +0000 |
commit | d0f5bd0b68daa921ac75bf2164d1ec3dcd96f040 (patch) | |
tree | 16c0d2f1db207f25c73967fdb5802e15840514ab | |
parent | 32007b19d8d9d4fc05310b6cf3200bad40618f21 (diff) | |
download | php-git-d0f5bd0b68daa921ac75bf2164d1ec3dcd96f040.tar.gz |
SOAP 1.2 support was improved
-rw-r--r-- | ext/soap/TODO | 1 | ||||
-rw-r--r-- | ext/soap/php_encoding.c | 102 | ||||
-rw-r--r-- | ext/soap/php_xml.c | 10 | ||||
-rw-r--r-- | ext/soap/soap.c | 99 |
4 files changed, 147 insertions, 65 deletions
diff --git a/ext/soap/TODO b/ext/soap/TODO index c195a97b70..b4a744d97f 100644 --- a/ext/soap/TODO +++ b/ext/soap/TODO @@ -62,6 +62,7 @@ Encoding SOAP 1.2 doesn't support partially transmitted and sparse arrays - full support for structures??? + references (id,href) +- SOAP 1.2 (enc:id,enc:ref) - references to external resources - default values - root attribute diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 14e5e4fc9a..38d6114335 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -335,8 +335,12 @@ static zval *to_zval_string(encodeType type, xmlNodePtr data) zval *ret; MAKE_STD_ZVAL(ret); FIND_XML_NULL(data, ret); - if (data && data->children && data->children->content) { - ZVAL_STRING(ret, data->children->content, 1); + if (data && data->children) { + if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + ZVAL_STRING(ret, data->children->content, 1); + } else { + php_error(E_ERROR,"Violation of encoding rules"); + } } else { ZVAL_EMPTY_STRING(ret); } @@ -348,9 +352,13 @@ static zval *to_zval_stringr(encodeType type, xmlNodePtr data) zval *ret; MAKE_STD_ZVAL(ret); FIND_XML_NULL(data, ret); - if (data && data->children && data->children->content) { - whiteSpace_replace(data->children->content); - ZVAL_STRING(ret, data->children->content, 1); + if (data && data->children) { + if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + whiteSpace_replace(data->children->content); + ZVAL_STRING(ret, data->children->content, 1); + } else { + php_error(E_ERROR,"Violation of encoding rules"); + } } else { ZVAL_EMPTY_STRING(ret); } @@ -362,9 +370,13 @@ static zval *to_zval_stringc(encodeType type, xmlNodePtr data) zval *ret; MAKE_STD_ZVAL(ret); FIND_XML_NULL(data, ret); - if (data && data->children && data->children->content) { - whiteSpace_collapse(data->children->content); - ZVAL_STRING(ret, data->children->content, 1); + if (data && data->children) { + if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + whiteSpace_collapse(data->children->content); + ZVAL_STRING(ret, data->children->content, 1); + } else { + php_error(E_ERROR,"Violation of encoding rules"); + } } else { ZVAL_EMPTY_STRING(ret); } @@ -435,9 +447,13 @@ static zval *to_zval_double(encodeType type, xmlNodePtr data) MAKE_STD_ZVAL(ret); FIND_XML_NULL(data, ret); - if (data && data->children && data->children->content) { - whiteSpace_collapse(data->children->content); - ZVAL_DOUBLE(ret, atof(data->children->content)); + if (data && data->children) { + if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + whiteSpace_collapse(data->children->content); + ZVAL_DOUBLE(ret, atof(data->children->content)); + } else { + php_error(E_ERROR,"Violation of encoding rules"); + } } else { ZVAL_NULL(ret); } @@ -450,9 +466,13 @@ static zval *to_zval_long(encodeType type, xmlNodePtr data) MAKE_STD_ZVAL(ret); FIND_XML_NULL(data, ret); - if (data && data->children && data->children->content) { - whiteSpace_collapse(data->children->content); - ZVAL_LONG(ret, atol(data->children->content)); + if (data && data->children) { + if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + whiteSpace_collapse(data->children->content); + ZVAL_LONG(ret, atol(data->children->content)); + } else { + php_error(E_ERROR,"Violation of encoding rules"); + } } else { ZVAL_NULL(ret); } @@ -465,19 +485,23 @@ static zval *to_zval_ulong(encodeType type, xmlNodePtr data) MAKE_STD_ZVAL(ret); FIND_XML_NULL(data, ret); - if (data && data->children && data->children->content) { - unsigned long val = 0; - char *s; - whiteSpace_collapse(data->children->content); - s = data->children->content; - while (*s >= '0' && *s <= '9') { - val = (val*10)+(*s-'0'); - s++; - } - if ((long)val >= 0) { - ZVAL_LONG(ret, val); + if (data && data->children) { + if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + unsigned long val = 0; + char *s; + whiteSpace_collapse(data->children->content); + s = data->children->content; + while (*s >= '0' && *s <= '9') { + val = (val*10)+(*s-'0'); + s++; + } + if ((long)val >= 0) { + ZVAL_LONG(ret, val); + } else { + ZVAL_STRING(ret, data->children->content, 1); + } } else { - ZVAL_STRING(ret, data->children->content, 1); + php_error(E_ERROR,"Violation of encoding rules"); } } else { ZVAL_NULL(ret); @@ -561,14 +585,18 @@ static zval *to_zval_bool(encodeType type, xmlNodePtr data) MAKE_STD_ZVAL(ret); FIND_XML_NULL(data, ret); - if (data && data->children && data->children->content) { - whiteSpace_collapse(data->children->content); - if (stricmp(data->children->content,"true") == 0 || - stricmp(data->children->content,"t") == 0 || - strcmp(data->children->content,"1") == 0) { - ZVAL_BOOL(ret, 1); + if (data && data->children) { + if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) { + whiteSpace_collapse(data->children->content); + if (stricmp(data->children->content,"true") == 0 || + stricmp(data->children->content,"t") == 0 || + strcmp(data->children->content,"1") == 0) { + ZVAL_BOOL(ret, 1); + } else { + ZVAL_BOOL(ret, 0); + } } else { - ZVAL_BOOL(ret, 0); + php_error(E_ERROR,"Violation of encoding rules"); } } else { ZVAL_NULL(ret); @@ -800,6 +828,10 @@ static int calc_dimension_12(const char* str) i++; flag = 1; } + } else if (*str == '*') { + if (i > 0) { + php_error(E_ERROR,"* may only be first arraySize value in list"); + } } else { flag = 0; } @@ -825,6 +857,10 @@ static int* get_position_12(int dimension, const char* str) flag = 1; } pos[i] = (pos[i]*10)+(*str-'0'); + } else if (*str == '*') { + if (i > 0) { + php_error(E_ERROR,"* may only be first arraySize value in list"); + } } else { flag = 0; } diff --git a/ext/soap/php_xml.c b/ext/soap/php_xml.c index d609ea4d1a..ce560b6f35 100644 --- a/ext/soap/php_xml.c +++ b/ext/soap/php_xml.c @@ -158,9 +158,15 @@ xmlNodePtr check_and_resolve_href(xmlNodePtr data) if (href) { /* Internal href try and find node */ if (href->children->content[0] == '#') { - return get_node_with_attribute_recursive(data->doc->children, NULL, "id", &href->children->content[1]); + xmlNodePtr ret = get_node_with_attribute_recursive(data->doc->children, NULL, "id", &href->children->content[1]); + if (!ret) { + php_error(E_ERROR,"Unresolved reference '%s'",href->children->content); + } + data = ret; + } else { + /* TODO: External href....? */ + php_error(E_ERROR,"External reference '%s'",href->children->content); } - /* TODO: External href....? */ } } return data; diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 9722c8083d..53afa15f4c 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1734,7 +1734,6 @@ static void deseralize_function_call(sdlPtr sdl, xmlDocPtr request, zval *functi int cur_param = 0,num_of_params = 0; zval tmp_function_name, **tmp_parameters = NULL; sdlFunctionPtr function; - sdlBindingPtr binding; ZVAL_EMPTY_STRING(function_name); @@ -1812,40 +1811,76 @@ static void deseralize_function_call(sdlPtr sdl, xmlDocPtr request, zval *functi function = get_function(sdl, php_strtolower((char *)func->name, strlen(func->name))); if (sdl != NULL && function == NULL) { - php_error(E_ERROR, "Error function \"%s\" doesn't exists for this service \"%s\"", func->name, binding->location); + php_error(E_ERROR, "Error function \"%s\" doesn't exists for this service", func->name); } - if (func->children) { - trav = func->children; - if (function == NULL) { - do { - if (trav->type == XML_ELEMENT_NODE) { - num_of_params++; - } - } while ((trav = trav->next)); - } else { - num_of_params = zend_hash_num_elements(function->requestParameters); + if (function != NULL) { + sdlParamPtr *param; + xmlNodePtr val; + int use_names = 0; + + num_of_params = zend_hash_num_elements(function->requestParameters); + zend_hash_internal_pointer_reset(function->requestParameters); + while (zend_hash_get_current_data(function->requestParameters, (void **)¶m) == SUCCESS) { + zend_hash_move_forward(function->requestParameters); + if (get_node(func->children, (*param)->paramName) != NULL) { + use_names = 1; + } + zend_hash_move_forward(function->requestParameters); } + if (use_names) { + tmp_parameters = emalloc(num_of_params * sizeof(zval *)); + zend_hash_internal_pointer_reset(function->requestParameters); + while (zend_hash_get_current_data(function->requestParameters, (void **)¶m) == SUCCESS) { + val = get_node(func->children, (*param)->paramName); + if (!val) { + /* TODO: may be "nil" is not OK? */ + MAKE_STD_ZVAL(tmp_parameters[cur_param]); + ZVAL_NULL(tmp_parameters[cur_param]); + } else { + tmp_parameters[cur_param] = master_to_zval((*param)->encode, val); + } + cur_param++; - tmp_parameters = emalloc(num_of_params * sizeof(zval *)); + zend_hash_move_forward(function->requestParameters); + } + (*parameters) = tmp_parameters; + (*num_params) = num_of_params; + return; + } + } + if (func->children) { + num_of_params = 0; trav = func->children; - do { + while (trav != NULL) { if (trav->type == XML_ELEMENT_NODE) { - encodePtr enc; - sdlParamPtr *param = NULL; - if (function != NULL && - zend_hash_index_find(function->requestParameters, cur_param, (void **)¶m) == FAILURE) { - php_error(E_ERROR, "Error cannot find parameter"); - } - if (param == NULL) { - enc = get_conversion(UNKNOWN_TYPE); - } else { - enc = (*param)->encode; + num_of_params++; + } + trav = trav->next; + } + if (num_of_params > 0) { + tmp_parameters = emalloc(num_of_params * sizeof(zval *)); + + trav = func->children; + while (trav != 0 && cur_param < num_of_params) { + if (trav->type == XML_ELEMENT_NODE) { + encodePtr enc; + sdlParamPtr *param = NULL; + if (function != NULL && + zend_hash_index_find(function->requestParameters, cur_param, (void **)¶m) == FAILURE) { + php_error(E_ERROR, "Error cannot find parameter"); + } + if (param == NULL) { + enc = get_conversion(UNKNOWN_TYPE); + } else { + enc = (*param)->encode; + } + tmp_parameters[cur_param] = master_to_zval(enc, trav); + cur_param++; } - tmp_parameters[cur_param] = master_to_zval(enc, trav); - cur_param++; + trav = trav->next; } - } while ((trav = trav->next)); + } } (*parameters) = tmp_parameters; (*num_params) = num_of_params; @@ -1854,7 +1889,7 @@ static void deseralize_function_call(sdlPtr sdl, xmlDocPtr request, zval *functi static xmlDocPtr seralize_response_call(sdlFunctionPtr function, char *function_name, char *uri, zval *ret, int version TSRMLS_DC) { xmlDoc *doc; - xmlNode *envelope,*body,*method, *param; + xmlNode *envelope,*body,*method = NULL, *param; xmlNs *ns; sdlParamPtr parameter = NULL; smart_str *gen_ns = NULL; @@ -1984,7 +2019,9 @@ static xmlDocPtr seralize_response_call(sdlFunctionPtr function, char *function_ xmlSetProp(envelope, SOAP_1_1_ENV_NS_PREFIX":encodingStyle", SOAP_1_1_ENC_NAMESPACE); } else if (version == SOAP_1_2) { xmlSetProp(envelope, "xmlns:"SOAP_1_2_ENC_NS_PREFIX, SOAP_1_2_ENC_NAMESPACE); - /*xmlSetProp(envelope, SOAP_1_2_ENV_NS_PREFIX"encodingStyle", SOAP_1_2_ENC_NAMESPACE);*/ + if (method) { + xmlSetProp(method, SOAP_1_2_ENV_NS_PREFIX":encodingStyle", SOAP_1_2_ENC_NAMESPACE); + } } } @@ -2073,7 +2110,9 @@ static xmlDocPtr seralize_function_call(zval *this_ptr, sdlFunctionPtr function, xmlSetProp(envelope, SOAP_1_1_ENV_NS_PREFIX":encodingStyle", SOAP_1_1_ENC_NAMESPACE); } else if (version == SOAP_1_2) { xmlSetProp(envelope, "xmlns:"SOAP_1_2_ENC_NS_PREFIX, SOAP_1_2_ENC_NAMESPACE); - /*xmlSetProp(envelope, SOAP_1_2_ENV_NS_PREFIX":encodingStyle", SOAP_1_2_ENC_NAMESPACE);*/ + if (method) { + xmlSetProp(method, SOAP_1_2_ENV_NS_PREFIX":encodingStyle", SOAP_1_2_ENC_NAMESPACE); + } } } |