/** @brief test uri * * create URI and get the values of it's components * */ void test_uri(axutil_env_t *env) { axis2_char_t * uri_str = "http://*****:*****@example.com:80/foo?bar#item5"; axis2_char_t * host = "home.netscape.com:443"; axis2_char_t * uri_str_base = "http://*****:*****@example.com:80/foo?bar"; axis2_char_t * scheme_str = "http"; axutil_uri_t * base = NULL; axutil_uri_t * hostinfo = NULL; axutil_uri_t * uri = NULL; axutil_uri_t * clone = NULL; axutil_uri_t * rel = NULL; axis2_port_t scheme_port; axis2_port_t port; axis2_char_t * str; hostinfo = axutil_uri_parse_hostinfo(env,host); CUT_ASSERT_PTR_NOT_EQUAL(hostinfo, NULL, 0); scheme_port = axutil_uri_port_of_scheme(scheme_str); CUT_ASSERT_INT_NOT_EQUAL(scheme_port, 0, 0); uri = axutil_uri_parse_string(env,uri_str); CUT_ASSERT_PTR_NOT_EQUAL(uri, NULL, 0); str = axutil_uri_get_protocol(uri,env); CUT_ASSERT_STR_EQUAL(str, "http", 0); port = axutil_uri_get_port(uri,env); CUT_ASSERT_INT_EQUAL(port, 80, 0); str = axutil_uri_get_path(uri,env); CUT_ASSERT_STR_EQUAL(str, "/foo", 0); str = axutil_uri_get_host(uri,env); CUT_ASSERT_STR_EQUAL(str, "example.com", 0); base = axutil_uri_parse_string(env,uri_str_base); CUT_ASSERT_PTR_NOT_EQUAL(base, NULL, 0); if (base) { str = axutil_uri_to_string(base,env,0); CUT_ASSERT_STR_EQUAL(str, "http://*****:*****@example.com/foo?bar", 0); } clone = axutil_uri_clone(uri,env); CUT_ASSERT_PTR_NOT_EQUAL(clone, NULL, 0); if (clone) { str = axutil_uri_to_string(clone,env,0); CUT_ASSERT_STR_EQUAL(str, "http://*****:*****@example.com/foo?bar#item5", 0); axutil_uri_free(clone,env); } rel = axutil_uri_resolve_relative(env,base,uri); CUT_ASSERT_PTR_NOT_EQUAL(rel, NULL, 0); if (rel) { str = axutil_uri_to_string(rel,env,0); CUT_ASSERT_STR_EQUAL(str, "http://*****:*****@example.com/foo?bar#item5", 0); } axutil_uri_free(uri,env); }
AXIS2_EXTERN axutil_uri_t *AXIS2_CALL axutil_url_to_uri( axutil_url_t *url, const axutil_env_t *env) { axis2_char_t *url_str = NULL; axutil_uri_t *uri = NULL; AXIS2_ENV_CHECK(env, NULL); AXIS2_PARAM_CHECK(env->error, url, NULL); url_str = axutil_url_to_external_form(url, env); uri = axutil_uri_parse_string(env, url_str); return uri; }
/** @brief test uri * * create URI and get the values of it's components * */ axis2_status_t test_uri(axutil_env_t *env) { axis2_char_t * uri_str = "http://*****:*****@example.com:80/foo?bar#item5"; axis2_char_t * host = "home.netscape.com:443"; axis2_char_t * uri_str_base = "http://*****:*****@example.com:80/foo?bar"; axis2_char_t * scheme_str = "http"; axutil_uri_t * base = NULL; axutil_uri_t * hostinfo = NULL; axutil_uri_t * uri = NULL; axutil_uri_t * clone = NULL; axutil_uri_t * rel = NULL; axis2_char_t * protocol = NULL; axis2_char_t * server = NULL; axis2_char_t * path = NULL; axis2_port_t scheme_port; axis2_port_t port; hostinfo = axutil_uri_parse_hostinfo(env,host); if(hostinfo) { printf("The host information of uri is %s\n",axutil_uri_to_string(hostinfo,env,0)); } else { printf("Test hostinfo faild\n"); } scheme_port = axutil_uri_port_of_scheme(scheme_str); if(scheme_port) { printf("port of scheme is %u\n", scheme_port); } else { printf("Test port failed\n"); } uri = axutil_uri_parse_string(env,uri_str); if(uri) { printf("The uri is %s\n",axutil_uri_to_string(uri,env,0)); axutil_uri_free(uri, env); } else { return AXIS2_FAILURE; } base = axutil_uri_parse_string(env,uri_str_base); if(base) { printf("The base of uri is %s\n",axutil_uri_to_string(base,env,0)); } else { printf("Test base failed\n"); } clone = axutil_uri_clone(uri,env); if(clone) { printf("The clone of uri is %s\n",axutil_uri_to_string(clone,env,0)); axutil_uri_free(clone,env); } else { printf("Test clone failed"); } rel = axutil_uri_resolve_relative(env,base,clone); if(rel) { printf("The resolved relative uri is %s\n",axutil_uri_to_string(rel,env,0)); } else { printf("Test resolve relative failed"); } protocol = axutil_uri_get_protocol(uri,env); if (!protocol) { axutil_uri_free(uri,env); return AXIS2_FAILURE; } server = axutil_uri_get_server(uri,env); if (!server) { axutil_uri_free(uri,env); return AXIS2_FAILURE; } port = axutil_uri_get_port(uri,env); if (!port) { axutil_uri_free(uri,env); return AXIS2_FAILURE; } path = axutil_uri_get_path(uri,env); if (!path) { axutil_uri_free(uri,env); return AXIS2_FAILURE; } printf("The protocol is %s\n",protocol); printf("The server is %s \n",server); printf("The port is %u \n",port); printf("The path is %s\n",path); axutil_uri_free(uri,env); return AXIS2_SUCCESS; }
axis2_status_t AXIS2_CALL adb_CanonicalizationMethodType_deserialize_obj( adb_CanonicalizationMethodType_t* _CanonicalizationMethodType, const axutil_env_t *env, axiom_node_t **dp_parent, axis2_bool_t *dp_is_early_node_valid, axis2_bool_t dont_care_minoccurs) { axiom_node_t *parent = *dp_parent; axis2_status_t status = AXIS2_SUCCESS; axiom_attribute_t *parent_attri = NULL; axiom_element_t *parent_element = NULL; axis2_char_t *attrib_text = NULL; axutil_hash_t *attribute_hash = NULL; const axis2_char_t* text_value = NULL; axutil_qname_t *qname = NULL; int i = 0; axutil_array_list_t *arr_list = NULL; int sequence_broken = 0; axiom_node_t *tmp_node = NULL; axutil_qname_t *element_qname = NULL; axiom_node_t *first_node = NULL; axis2_bool_t is_early_node_valid = AXIS2_TRUE; axiom_node_t *current_node = NULL; axiom_element_t *current_element = NULL; AXIS2_ENV_CHECK(env, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, _CanonicalizationMethodType, AXIS2_FAILURE); while(parent && axiom_node_get_node_type(parent, env) != AXIOM_ELEMENT) { parent = axiom_node_get_next_sibling(parent, env); } if (NULL == parent) { /* This should be checked before everything */ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed in building adb object for CanonicalizationMethodType : " "NULL element can not be passed to deserialize"); return AXIS2_FAILURE; } first_node = axiom_node_get_first_child(parent, env); parent_element = (axiom_element_t *)axiom_node_get_data_element(parent, env); attribute_hash = axiom_element_get_all_attributes(parent_element, env); /* * building extraElement array */ arr_list = axutil_array_list_create(env, 10); /* * building extraElement element */ /* 'any' arrays are not handling correctly when there are other elements mixed with the 'any' element. */ for (i = 0, sequence_broken = 0, current_node = first_node; !sequence_broken && current_node != NULL;) { if(axiom_node_get_node_type(current_node, env) != AXIOM_ELEMENT) { current_node =axiom_node_get_next_sibling(current_node, env); is_early_node_valid = AXIS2_FALSE; continue; } if( current_node && current_element && (axutil_qname_equals(element_qname, env, qname) || !axutil_strcmp("extraElement", axiom_element_get_localname(current_element, env)))) { is_early_node_valid = AXIS2_TRUE; } text_value = NULL; /* just to avoid warning */ { axiom_node_t *current_property_node = current_node; current_node = axiom_node_get_next_sibling(current_node, env); axiom_node_detach(current_property_node, env); axutil_array_list_add_at(arr_list, env, i, (void*)current_property_node); } if(AXIS2_FAILURE == status) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "failed in setting the value for extraElement "); if(element_qname) { axutil_qname_free(element_qname, env); } if(arr_list) { axutil_array_list_free(arr_list, env); } return AXIS2_FAILURE; } i ++; } if(0 == axutil_array_list_size(arr_list,env)) { axutil_array_list_free(arr_list, env); } else { status = adb_CanonicalizationMethodType_set_extraElement(_CanonicalizationMethodType, env, arr_list); } if(element_qname) { axutil_qname_free(element_qname, env); element_qname = NULL; } parent_attri = NULL; attrib_text = NULL; if(attribute_hash) { axutil_hash_index_t *hi; void *val; const void *key; for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) { axutil_hash_this(hi, &key, NULL, &val); if(!strcmp((axis2_char_t*)key, "Algorithm")) { parent_attri = (axiom_attribute_t*)val; AXIS2_FREE(env->allocator, hi); break; } } } if(parent_attri) { attrib_text = axiom_attribute_get_value(parent_attri, env); } else { /* this is hoping that attribute is stored in "Algorithm", this happnes when name is in default namespace */ attrib_text = axiom_element_get_attribute_value_by_name(parent_element, env, "Algorithm"); } if(attrib_text != NULL) { adb_CanonicalizationMethodType_set_Algorithm(_CanonicalizationMethodType, env, axutil_uri_parse_string(env, attrib_text)); } else if(!dont_care_minoccurs) { if(element_qname) { axutil_qname_free(element_qname, env); } /* this is not a nillable element*/ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "required attribute Algorithm missing"); return AXIS2_FAILURE; } if(element_qname) { axutil_qname_free(element_qname, env); element_qname = NULL; } return status; }
axis2_status_t AXIS2_CALL adb_audio_type0_deserialize_obj( adb_audio_type0_t* _audio_type0, const axutil_env_t *env, axiom_node_t **dp_parent, axis2_bool_t *dp_is_early_node_valid, axis2_bool_t dont_care_minoccurs) { axiom_node_t *parent = *dp_parent; axis2_status_t status = AXIS2_SUCCESS; axiom_attribute_t *parent_attri = NULL; axiom_element_t *parent_element = NULL; axis2_char_t *attrib_text = NULL; axutil_hash_t *attribute_hash = NULL; const axis2_char_t* text_value = NULL; axutil_qname_t *qname = NULL; axutil_qname_t *element_qname = NULL; axiom_node_t *first_node = NULL; axis2_bool_t is_early_node_valid = AXIS2_TRUE; axiom_node_t *current_node = NULL; axiom_element_t *current_element = NULL; AXIS2_ENV_CHECK(env, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, _audio_type0, AXIS2_FAILURE); while(parent && axiom_node_get_node_type(parent, env) != AXIOM_ELEMENT) { parent = axiom_node_get_next_sibling(parent, env); } if (NULL == parent) { /* This should be checked before everything */ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed in building adb object for audio_type0 : " "NULL element can not be passed to deserialize"); return AXIS2_FAILURE; } first_node = axiom_node_get_first_child(parent, env); parent_element = (axiom_element_t *)axiom_node_get_data_element(parent, env); attribute_hash = axiom_element_get_all_attributes(parent_element, env); parent_attri = NULL; attrib_text = NULL; if(attribute_hash) { axutil_hash_index_t *hi; void *val; const void *key; for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) { axutil_hash_this(hi, &key, NULL, &val); if(!strcmp((axis2_char_t*)key, "uri")) { parent_attri = (axiom_attribute_t*)val; AXIS2_FREE(env->allocator, hi); break; } } } if(parent_attri) { attrib_text = axiom_attribute_get_value(parent_attri, env); } else { /* this is hoping that attribute is stored in "uri", this happnes when name is in default namespace */ attrib_text = axiom_element_get_attribute_value_by_name(parent_element, env, "uri"); } if(attrib_text != NULL) { adb_audio_type0_set_uri(_audio_type0, env, axutil_uri_parse_string(env, attrib_text)); } else if(!dont_care_minoccurs) { if(element_qname) { axutil_qname_free(element_qname, env); } /* this is not a nillable element*/ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "required attribute uri missing"); return AXIS2_FAILURE; } if(element_qname) { axutil_qname_free(element_qname, env); element_qname = NULL; } parent_attri = NULL; attrib_text = NULL; if(attribute_hash) { axutil_hash_index_t *hi; void *val; const void *key; for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) { axutil_hash_this(hi, &key, NULL, &val); if(!strcmp((axis2_char_t*)key, "rangeBegin")) { parent_attri = (axiom_attribute_t*)val; AXIS2_FREE(env->allocator, hi); break; } } } if(parent_attri) { attrib_text = axiom_attribute_get_value(parent_attri, env); } else { /* this is hoping that attribute is stored in "rangeBegin", this happnes when name is in default namespace */ attrib_text = axiom_element_get_attribute_value_by_name(parent_element, env, "rangeBegin"); } if(attrib_text != NULL) { adb_audio_type0_set_rangeBegin(_audio_type0, env, axutil_strtol(attrib_text, (char**)NULL, 0)); } if(element_qname) { axutil_qname_free(element_qname, env); element_qname = NULL; } parent_attri = NULL; attrib_text = NULL; if(attribute_hash) { axutil_hash_index_t *hi; void *val; const void *key; for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) { axutil_hash_this(hi, &key, NULL, &val); if(!strcmp((axis2_char_t*)key, "rangeEnd")) { parent_attri = (axiom_attribute_t*)val; AXIS2_FREE(env->allocator, hi); break; } } } if(parent_attri) { attrib_text = axiom_attribute_get_value(parent_attri, env); } else { /* this is hoping that attribute is stored in "rangeEnd", this happnes when name is in default namespace */ attrib_text = axiom_element_get_attribute_value_by_name(parent_element, env, "rangeEnd"); } if(attrib_text != NULL) { adb_audio_type0_set_rangeEnd(_audio_type0, env, axutil_strtol(attrib_text, (char**)NULL, 0)); } if(element_qname) { axutil_qname_free(element_qname, env); element_qname = NULL; } parent_attri = NULL; attrib_text = NULL; if(attribute_hash) { axutil_hash_index_t *hi; void *val; const void *key; for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) { axutil_hash_this(hi, &key, NULL, &val); if(!strcmp((axis2_char_t*)key, "size")) { parent_attri = (axiom_attribute_t*)val; AXIS2_FREE(env->allocator, hi); break; } } } if(parent_attri) { attrib_text = axiom_attribute_get_value(parent_attri, env); } else { /* this is hoping that attribute is stored in "size", this happnes when name is in default namespace */ attrib_text = axiom_element_get_attribute_value_by_name(parent_element, env, "size"); } if(attrib_text != NULL) { adb_audio_type0_set_size(_audio_type0, env, axutil_strtol(attrib_text, (char**)NULL, 0)); } if(element_qname) { axutil_qname_free(element_qname, env); element_qname = NULL; } return status; }
axis2_status_t wsclient_set_attachment (const axutil_env_t *env, axiom_node_t *node, axis2_char_t *base_dir, int is_mtom_enabled) { axiom_node_t *child_node = NULL; axiom_element_t *element; if (!node || !env) return AXIS2_FAILURE; if (axiom_node_get_node_type (node, env) == AXIOM_ELEMENT) { axis2_char_t *local_name; axiom_namespace_t *ns; axis2_char_t *ns_uri; element = (axiom_element_t *) axiom_node_get_data_element (node, env); local_name = axiom_element_get_localname (element, env); if (local_name) { if (!strcmp (local_name, "Include")) { ns = axiom_element_get_namespace(element, env, node); if (ns && (ns_uri = axiom_namespace_get_uri (ns, env)) && (!strcmp (ns_uri, "http://www.w3.org/2004/08/xop/include"))) { axis2_char_t *file_path; axiom_data_handler_t *data_handler; axiom_text_t *data_text; axiom_node_t *data_node; axiom_node_t *parent; axutil_uri_t *file_uri = NULL; axutil_uri_t *base_uri = NULL; axutil_uri_t *real_uri = NULL; axis2_char_t *real_path = NULL; parent = axiom_node_get_parent (node, env); axiom_node_detach (node, env); file_path = axiom_element_get_attribute_value_by_name (element, env, "href"); file_uri = axutil_uri_parse_string (env, file_path); if (base_dir) base_uri = axutil_uri_parse_string (env, base_dir); else return AXIS2_FAILURE; if (base_uri) real_uri = axutil_uri_parse_relative (env, base_uri, file_path); else return AXIS2_FAILURE; if (real_uri) real_path = axutil_uri_to_string (real_uri, env, 1); else return AXIS2_FAILURE; if (real_path) data_handler = axiom_data_handler_create (env, real_path, "image/jpeg"); else return AXIS2_FAILURE; if (data_handler) data_text = axiom_text_create_with_data_handler (env, parent, data_handler, &data_node); else return AXIS2_FAILURE; if (data_text) { if (!is_mtom_enabled) axiom_text_set_optimize (data_text, env, AXIS2_FALSE); } } } } child_node = axiom_node_get_first_element (node, env); while (child_node) { wsclient_set_attachment (env, child_node, base_dir, is_mtom_enabled); child_node = axiom_node_get_next_sibling (child_node, env); } } else return AXIS2_FAILURE; return AXIS2_SUCCESS; }