diff options
author | Dmitry Stogov <dmitry@php.net> | 2004-01-26 09:51:07 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2004-01-26 09:51:07 +0000 |
commit | e3cfa02b4e7b26cd153783109533ed75b943d57d (patch) | |
tree | 3a304b3ecbbc7b02fda6a5e3788e0db52f79aa96 /ext/soap/php_sdl.c | |
parent | 7e6b108a96919e88e7f62d3a3a3d1904ca191546 (diff) | |
download | php-git-e3cfa02b4e7b26cd153783109533ed75b943d57d.tar.gz |
XML Schema support (decoding of xsi:nil with attributes)
Source Cleanup
Diffstat (limited to 'ext/soap/php_sdl.c')
-rw-r--r-- | ext/soap/php_sdl.c | 381 |
1 files changed, 0 insertions, 381 deletions
diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 30ca6383b5..bf2d457fa6 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -98,259 +98,6 @@ encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat) return enc; } -encodePtr get_create_encoder(sdlPtr sdl, sdlTypePtr cur_type, const char *ns, const char *type) -{ - encodePtr enc = NULL; - smart_str nscat = {0}; - TSRMLS_FETCH(); - - smart_str_appends(&nscat, ns); - smart_str_appendc(&nscat, ':'); - smart_str_appends(&nscat, type); - smart_str_0(&nscat); - - enc = get_conversion_from_href_type(nscat.c); - if (enc == NULL) { - enc = get_conversion_from_href_type_ex(sdl->encoders, nscat.c, nscat.len); - } - if (enc == NULL) { - enc = create_encoder(sdl, cur_type, ns, type); - } - - smart_str_free(&nscat); - return enc; -} - -encodePtr create_encoder(sdlPtr sdl, sdlTypePtr cur_type, const char *ns, const char *type) -{ - smart_str nscat = {0}; - encodePtr enc, *enc_ptr; - - if (sdl->encoders == NULL) { - sdl->encoders = malloc(sizeof(HashTable)); - zend_hash_init(sdl->encoders, 0, NULL, delete_encoder, 1); - } - smart_str_appends(&nscat, ns); - smart_str_appendc(&nscat, ':'); - smart_str_appends(&nscat, type); - smart_str_0(&nscat); - if (zend_hash_find(sdl->encoders, nscat.c, nscat.len + 1, (void**)&enc_ptr) == SUCCESS) { - enc = *enc_ptr; - if (enc->details.ns) { - free(enc->details.ns); - } - if (enc->details.type_str) { - free(enc->details.type_str); - } - } else { - enc_ptr = NULL; - enc = malloc(sizeof(encode)); - } - memset(enc, 0, sizeof(encode)); - - enc->details.ns = strdup(ns); - enc->details.type_str = strdup(type); - enc->details.sdl_type = cur_type; - enc->to_xml = sdl_guess_convert_xml; - enc->to_zval = sdl_guess_convert_zval; - - if (enc_ptr == NULL) { - zend_hash_update(sdl->encoders, nscat.c, nscat.len + 1, &enc, sizeof(encodePtr), NULL); - } - smart_str_free(&nscat); - return enc; -} - -static zval* to_zval_list(encodeTypePtr enc, xmlNodePtr data) { - zval *ret; - MAKE_STD_ZVAL(ret); - FIND_XML_NULL(data, ret); - 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); - } - return ret; -} - -static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style) { - xmlNodePtr ret; - - ret = xmlNewNode(NULL, "BOGUS"); - FIND_ZVAL_NULL(data, ret, style); - if (Z_TYPE_P(data) == IS_ARRAY) { - zval **tmp; - smart_str list = {0}; - HashTable *ht = Z_ARRVAL_P(data); - - zend_hash_internal_pointer_reset(ht); - while (zend_hash_get_current_data(ht, (void**)&tmp) == SUCCESS) { - if (list.len != 0) { - smart_str_appendc(&list, ' '); - } - if (Z_TYPE_PP(tmp) == IS_STRING) { - smart_str_appendl(&list, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); - } else { - zval copy = **tmp; - zval_copy_ctor(©); - convert_to_string(©); - smart_str_appendl(&list, Z_STRVAL(copy), Z_STRLEN(copy)); - zval_dtor(©); - } - zend_hash_move_forward(ht); - } - smart_str_0(&list); - xmlNodeSetContentLen(ret, list.c, list.len); - smart_str_free(&list); - } else if (Z_TYPE_P(data) == IS_STRING) { - xmlNodeSetContentLen(ret, Z_STRVAL_P(data), Z_STRLEN_P(data)); - } else { - zval tmp = *data; - - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - xmlNodeSetContentLen(ret, Z_STRVAL(tmp), Z_STRLEN(tmp)); - zval_dtor(&tmp); - } - return ret; -} - -static zval* to_zval_union(encodeTypePtr enc, xmlNodePtr data) { - /*FIXME*/ - return to_zval_list(enc, data); -} - -static xmlNodePtr to_xml_union(encodeTypePtr enc, zval *data, int style) { - /*FIXME*/ - return to_xml_list(enc,data,style); -} - -zval *sdl_guess_convert_zval(encodeTypePtr enc, xmlNodePtr data) -{ - sdlTypePtr type; - - type = enc->sdl_type; - - if (type && type->restrictions && - data && data->children && data->children->content) { - if (type->restrictions->whiteSpace && type->restrictions->whiteSpace->value) { - if (strcmp(type->restrictions->whiteSpace->value,"replace") == 0) { - whiteSpace_replace(data->children->content); - } else if (strcmp(type->restrictions->whiteSpace->value,"collapse") == 0) { - whiteSpace_collapse(data->children->content); - } - } - if (type->restrictions->enumeration) { - if (!zend_hash_exists(type->restrictions->enumeration,data->children->content,strlen(data->children->content)+1)) { - php_error(E_WARNING,"Restriction: invalid enumeration value \"%s\"",data->children->content); - } - } - if (type->restrictions->minLength && - strlen(data->children->content) < type->restrictions->minLength->value) { - php_error(E_WARNING,"Restriction: length less then 'minLength'"); - } - if (type->restrictions->maxLength && - strlen(data->children->content) > type->restrictions->maxLength->value) { - php_error(E_WARNING,"Restriction: length greater then 'maxLength'"); - } - if (type->restrictions->length && - strlen(data->children->content) != type->restrictions->length->value) { - php_error(E_WARNING,"Restriction: length is not equal to 'length'"); - } - } - switch (type->kind) { - case XSD_TYPEKIND_SIMPLE: - if (type->encode && enc != &type->encode->details) { - return master_to_zval(type->encode, data); - } - break; - case XSD_TYPEKIND_LIST: - return to_zval_list(enc, data); - case XSD_TYPEKIND_UNION: - return to_zval_union(enc, data); - case XSD_TYPEKIND_COMPLEX: - case XSD_TYPEKIND_RESTRICTION: - case XSD_TYPEKIND_EXTENSION: - if (type->encode && - (type->encode->details.type == IS_ARRAY || - type->encode->details.type == SOAP_ENC_ARRAY)) { - return to_zval_array(enc, data); - } - return to_zval_object(enc, data); - default: - break; - } - return guess_zval_convert(enc, data); -} - -xmlNodePtr sdl_guess_convert_xml(encodeTypePtr enc, zval *data, int style) -{ - sdlTypePtr type; - xmlNodePtr ret = NULL; - - type = enc->sdl_type; - - if (type) { - if (type->restrictions && Z_TYPE_P(data) == IS_STRING) { - if (type->restrictions->enumeration) { - if (!zend_hash_exists(type->restrictions->enumeration,Z_STRVAL_P(data),Z_STRLEN_P(data)+1)) { - php_error(E_WARNING,"Restriction: invalid enumeration value \"%s\".",Z_STRVAL_P(data)); - } - } - if (type->restrictions->minLength && - Z_STRLEN_P(data) < type->restrictions->minLength->value) { - php_error(E_WARNING,"Restriction: length less then 'minLength'"); - } - if (type->restrictions->maxLength && - Z_STRLEN_P(data) > type->restrictions->maxLength->value) { - php_error(E_WARNING,"Restriction: length greater then 'maxLength'"); - } - if (type->restrictions->length && - Z_STRLEN_P(data) != type->restrictions->length->value) { - php_error(E_WARNING,"Restriction: length is not equal to 'length'"); - } - } - } - switch(type->kind) { - case XSD_TYPEKIND_SIMPLE: - if (type->encode && enc != &type->encode->details) { - ret = master_to_xml(type->encode, data, style); - } - break; - case XSD_TYPEKIND_LIST: - ret = to_xml_list(enc, data, style); - break; - case XSD_TYPEKIND_UNION: - ret = to_xml_union(enc, data, style); - break; - case XSD_TYPEKIND_COMPLEX: - case XSD_TYPEKIND_RESTRICTION: - case XSD_TYPEKIND_EXTENSION: - if (type->encode && - (type->encode->details.type == IS_ARRAY || - type->encode->details.type == SOAP_ENC_ARRAY)) { - ret = to_xml_array(enc, data, style); - } else { - ret = to_xml_object(enc, data, style); - } - break; - default: - break; - } - if (ret == NULL) { - ret = guess_xml_convert(enc, data, style); - } - if (style == SOAP_ENCODED) { - set_ns_and_type(ret, enc); - } - return ret; -} - sdlBindingPtr get_binding_from_type(sdlPtr sdl, int type) { sdlBindingPtr *binding; @@ -1087,134 +834,6 @@ static void delete_paramater(void *data) free(param); } -void delete_mapping(void *data) -{ - soapMappingPtr map = (soapMappingPtr)data; - - if (map->ns) { - efree(map->ns); - } - if (map->ctype) { - efree(map->ctype); - } - - if (map->type == SOAP_MAP_FUNCTION) { - if (map->map_functions.to_xml_before) { - zval_ptr_dtor(&map->map_functions.to_xml_before); - } - if (map->map_functions.to_xml) { - zval_ptr_dtor(&map->map_functions.to_xml); - } - if (map->map_functions.to_xml_after) { - zval_ptr_dtor(&map->map_functions.to_xml_after); - } - if (map->map_functions.to_zval_before) { - zval_ptr_dtor(&map->map_functions.to_zval_before); - } - if (map->map_functions.to_zval) { - zval_ptr_dtor(&map->map_functions.to_zval); - } - if (map->map_functions.to_zval_after) { - zval_ptr_dtor(&map->map_functions.to_zval_after); - } - } - efree(map); -} - -void delete_type(void *data) -{ - sdlTypePtr type = *((sdlTypePtr*)data); - if (type->name) { - free(type->name); - } - if (type->namens) { - free(type->namens); - } - if (type->elements) { - zend_hash_destroy(type->elements); - free(type->elements); - } - if (type->attributes) { - zend_hash_destroy(type->attributes); - free(type->attributes); - } - if (type->restrictions) { - delete_restriction_var_int(&type->restrictions->minExclusive); - delete_restriction_var_int(&type->restrictions->minInclusive); - delete_restriction_var_int(&type->restrictions->maxExclusive); - delete_restriction_var_int(&type->restrictions->maxInclusive); - delete_restriction_var_int(&type->restrictions->totalDigits); - delete_restriction_var_int(&type->restrictions->fractionDigits); - delete_restriction_var_int(&type->restrictions->length); - delete_restriction_var_int(&type->restrictions->minLength); - delete_restriction_var_int(&type->restrictions->maxLength); - delete_schema_restriction_var_char(&type->restrictions->whiteSpace); - delete_schema_restriction_var_char(&type->restrictions->pattern); - if (type->restrictions->enumeration) { - zend_hash_destroy(type->restrictions->enumeration); - free(type->restrictions->enumeration); - } - free(type->restrictions); - } - free(type); -} - -void delete_attribute(void *attribute) -{ - sdlAttributePtr attr = *((sdlAttributePtr*)attribute); - - if (attr->def) { - free(attr->def); - } - if (attr->fixed) { - free(attr->fixed); - } - if (attr->form) { - free(attr->form); - } - if (attr->id) { - free(attr->id); - } - if (attr->name) { - free(attr->name); - } - if (attr->ref) { - free(attr->ref); - } - if (attr->use) { - free(attr->use); - } - if (attr->extraAttributes) { - zend_hash_destroy(attr->extraAttributes); - free(attr->extraAttributes); - } -} - -void delete_restriction_var_int(void *rvi) -{ - sdlRestrictionIntPtr ptr = *((sdlRestrictionIntPtr*)rvi); - if (ptr) { - if (ptr->id) { - free(ptr->id); - } - free(ptr); - } -} - -void delete_schema_restriction_var_char(void *srvc) -{ - sdlRestrictionCharPtr ptr = *((sdlRestrictionCharPtr*)srvc); - if (ptr) { - if (ptr->id) { - free(ptr->id); - } - if (ptr->value) { - free(ptr->value); - } - free(ptr); - } -} - static void delete_document(void *doc_ptr) { xmlDocPtr doc = *((xmlDocPtr*)doc_ptr); |