diff options
author | Dmitry Stogov <dmitry@php.net> | 2004-01-14 15:36:01 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2004-01-14 15:36:01 +0000 |
commit | 51cbc1f84fbe2b6e762e527608e62835f2baa753 (patch) | |
tree | 8a375084eedcd7e80391b25e4a49522190bcc2b2 /ext/soap/php_sdl.c | |
parent | fc69cc8ccf5ef153745e3a5cc43476664474fc75 (diff) | |
download | php-git-51cbc1f84fbe2b6e762e527608e62835f2baa753.tar.gz |
array/object encoding
Diffstat (limited to 'ext/soap/php_sdl.c')
-rw-r--r-- | ext/soap/php_sdl.c | 248 |
1 files changed, 3 insertions, 245 deletions
diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index bb28fd4980..1a6a688336 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -115,248 +115,6 @@ encodePtr create_encoder(sdlPtr sdl, sdlTypePtr cur_type, const char *ns, const return enc; } -static xmlNodePtr sdl_to_xml_object(encodeType enc_type, zval *data, int style) -{ - sdlTypePtr type = enc_type.sdl_type; - xmlNodePtr ret; - sdlTypePtr *t, tmp; - TSRMLS_FETCH(); - - ret = xmlNewNode(NULL, "BOGUS"); - FIND_ZVAL_NULL(data, ret, style); - - if (Z_TYPE_P(data) != IS_OBJECT) { - return ret; - } - - zend_hash_internal_pointer_reset(type->elements); - while (zend_hash_get_current_data(type->elements, (void **)&t) != FAILURE) { - zval **prop; - tmp = *t; - if (zend_hash_find(Z_OBJPROP_P(data), tmp->name, strlen(tmp->name) + 1, (void **)&prop) == FAILURE) { - if (tmp->nillable == FALSE) { - php_error(E_ERROR, "Error encoding object to xml missing property \"%s\"", tmp->name); - } - } else { - xmlNodePtr newNode; - encodePtr enc; - - if (tmp->encode) { - enc = tmp->encode; - } else { - enc = get_conversion((*prop)->type); - } - newNode = master_to_xml(enc, (*prop), style); - xmlNodeSetName(newNode, tmp->name); - xmlAddChild(ret, newNode); - } - zend_hash_move_forward(type->elements); - } - if (style == SOAP_ENCODED) { - set_ns_and_type(ret, enc_type); - } - - return ret; -} - -static void add_xml_array_elements(xmlNodePtr xmlParam, - sdlTypePtr type, - encodePtr enc, - int dimension , - int* dims, - zval* data, - int style) -{ - int j; - - if (Z_TYPE_P(data) == IS_ARRAY) { - zend_hash_internal_pointer_reset(data->value.ht); - for (j=0; j<dims[0]; j++) { - zval **zdata; - zend_hash_get_current_data(data->value.ht, (void **)&zdata); - if (dimension == 1) { - xmlNodePtr xparam; - if (enc == NULL) { - TSRMLS_FETCH(); - xparam = master_to_xml(get_conversion((*zdata)->type), (*zdata), style); - } else { - xparam = master_to_xml(enc, (*zdata), style); - } - - xmlNodeSetName(xparam, type->name); - xmlAddChild(xmlParam, xparam); - } else { - add_xml_array_elements(xmlParam, type, enc, dimension-1, dims+1, *zdata, style); - } - zend_hash_move_forward(data->value.ht); - } - } -} - -static xmlNodePtr sdl_to_xml_array(encodeType enc_type, zval *data, int style) -{ - sdlTypePtr type = enc_type.sdl_type; - smart_str array_type_and_size = {0}, array_type = {0}; - int i; - int dimension = 1; - int* dims; - xmlNodePtr xmlParam; - sdlTypePtr elementType; - encodePtr enc = NULL; - TSRMLS_FETCH(); - - xmlParam = xmlNewNode(NULL,"BOGUS"); - - FIND_ZVAL_NULL(data, xmlParam, style); - - if (Z_TYPE_P(data) == IS_ARRAY) { - sdlAttributePtr *arrayType; - i = zend_hash_num_elements(Z_ARRVAL_P(data)); - -/* FIXME: Is arrayType needed? What about enc? */ - if (style == SOAP_ENCODED) { - xmlAttrPtr *wsdl; - if (type->attributes && - zend_hash_find(type->attributes, SOAP_ENC_NAMESPACE":arrayType", - sizeof(SOAP_ENC_NAMESPACE":arrayType"), - (void **)&arrayType) == SUCCESS && - zend_hash_find((*arrayType)->extraAttributes, WSDL_NAMESPACE":arrayType", sizeof(WSDL_NAMESPACE":arrayType"), (void **)&wsdl) == SUCCESS) { - - char *ns = NULL, *value, *end; - xmlNsPtr myNs; - zval** el; - - parse_namespace((*wsdl)->children->content, &value, &ns); - myNs = xmlSearchNs((*wsdl)->doc, (*wsdl)->parent, ns); - - end = strrchr(value,'['); - if (end) { - *end = '\0'; - end++; - while (*end != ']' && *end != '\0') { - if (*end == ',') { - dimension++; - } - end++; - } - } - if (myNs != NULL) { - enc = get_encoder(SOAP_GLOBAL(sdl), myNs->href, value); - - if (strcmp(myNs->href,XSD_NAMESPACE) == 0) { - smart_str_appendl(&array_type_and_size, XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX) - 1); - smart_str_appendc(&array_type_and_size, ':'); - } else { - smart_str *prefix = encode_new_ns(); - smart_str smart_ns = {0}; - - smart_str_appendl(&smart_ns, "xmlns:", sizeof("xmlns:") - 1); - smart_str_appendl(&smart_ns, prefix->c, prefix->len); - smart_str_0(&smart_ns); - xmlSetProp(xmlParam, smart_ns.c, myNs->href); - smart_str_free(&smart_ns); - - smart_str_appends(&array_type_and_size, prefix->c); - smart_str_appendc(&array_type_and_size, ':'); - smart_str_free(prefix); - efree(prefix); - } - } - - dims = emalloc(sizeof(int)*dimension); - dims[0] = i; - el = &data; - for (i = 1; i < dimension; i++) { - if (el != NULL && Z_TYPE_PP(el) == IS_ARRAY && Z_ARRVAL_PP(el)->pListHead) { - el = (zval**)Z_ARRVAL_PP(el)->pListHead->pData; - if (Z_TYPE_PP(el) == IS_ARRAY) { - dims[i] = zend_hash_num_elements(Z_ARRVAL_PP(el)); - } else { - dims[i] = 0; - } - } - } - - smart_str_appends(&array_type_and_size, value); - smart_str_appendc(&array_type_and_size, '['); - smart_str_append_long(&array_type_and_size, dims[0]); - for (i=1; i<dimension; i++) { - smart_str_appendc(&array_type_and_size, ','); - smart_str_append_long(&array_type_and_size, dims[i]); - } - smart_str_appendc(&array_type_and_size, ']'); - smart_str_0(&array_type_and_size); - - efree(value); - if (ns) efree(ns); - } else if (type->elements && - zend_hash_num_elements(type->elements) == 1 && - (elementType = *(sdlTypePtr*)type->elements->pListHead->pData) != NULL && - elementType->encode && elementType->encode->details.type_str) { - char* ns = elementType->encode->details.ns; - - if (ns) { - if (strcmp(ns,XSD_NAMESPACE) == 0) { - smart_str_appendl(&array_type_and_size, XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX) - 1); - smart_str_appendc(&array_type_and_size, ':'); - } else { - smart_str *prefix = encode_new_ns(); - smart_str smart_ns = {0}; - - smart_str_appendl(&smart_ns, "xmlns:", sizeof("xmlns:") - 1); - smart_str_appendl(&smart_ns, prefix->c, prefix->len); - smart_str_0(&smart_ns); - xmlSetProp(xmlParam, smart_ns.c, ns); - smart_str_free(&smart_ns); - - smart_str_appends(&array_type_and_size, prefix->c); - smart_str_appendc(&array_type_and_size, ':'); - smart_str_free(prefix); - efree(prefix); - } - } - enc = elementType->encode; - smart_str_appends(&array_type_and_size, elementType->encode->details.type_str); - smart_str_free(&array_type); - smart_str_appendc(&array_type_and_size, '['); - smart_str_append_long(&array_type_and_size, i); - smart_str_appendc(&array_type_and_size, ']'); - smart_str_0(&array_type_and_size); - - dims = emalloc(sizeof(int)*dimension); - dims[0] = i; - } else { - smart_str array_type = {0}; - get_array_type(data, &array_type TSRMLS_CC); - enc = get_encoder_ex(SOAP_GLOBAL(sdl), array_type.c); - smart_str_append(&array_type_and_size, &array_type); - smart_str_free(&array_type); - smart_str_appendc(&array_type_and_size, '['); - smart_str_append_long(&array_type_and_size, i); - smart_str_appendc(&array_type_and_size, ']'); - smart_str_0(&array_type_and_size); - dims = emalloc(sizeof(int)*dimension); - dims[0] = i; - } - xmlSetProp(xmlParam, SOAP_ENC_NS_PREFIX":arrayType", array_type_and_size.c); - - smart_str_free(&array_type_and_size); - smart_str_free(&array_type); - } else { - dims = emalloc(sizeof(int)*dimension); - dims[0] = i; - } - - add_xml_array_elements(xmlParam, type, enc, dimension, dims, data, style); - efree(dims); - if (style == SOAP_ENCODED) { - set_ns_and_type(xmlParam, enc_type); - } - } - - return xmlParam; -} - zval *sdl_guess_convert_zval(encodeType enc, xmlNodePtr data) { sdlTypePtr type; @@ -404,10 +162,10 @@ xmlNodePtr sdl_guess_convert_xml(encodeType enc, zval *data, int style) if (type->encode) { if (type->encode->details.type == IS_ARRAY || type->encode->details.type == SOAP_ENC_ARRAY) { - ret = sdl_to_xml_array(enc, data, style); + ret = to_xml_array(enc, data, style); } else if (type->encode->details.type == IS_OBJECT || type->encode->details.type == SOAP_ENC_OBJECT) { - ret = sdl_to_xml_object(enc, data, style); + ret = to_xml_object(enc, data, style); } else { if (memcmp(&type->encode->details,&enc,sizeof(enc))!=0) { ret = master_to_xml(type->encode, data, style); @@ -418,7 +176,7 @@ xmlNodePtr sdl_guess_convert_xml(encodeType enc, zval *data, int style) } } else if (type->elements) { - ret = sdl_to_xml_object(enc, data, style); + ret = to_xml_object(enc, data, style); } else { ret = guess_xml_convert(enc, data, style); } |