Exemplo n.º 1
0
AXIS2_EXTERN axis2_char_t *AXIS2_CALL 
remote_registry_rest_client_get(
								remote_registry_rest_client_t *rest_client,
								const axutil_env_t *env,
								const axis2_char_t *url,
								const axutil_array_list_t *params,
								int relative,
								int *content_len)
{
	axis2_char_t *ret = NULL;
	int size = 0, i = 0;
	axis2_char_t *params_str = NULL;
	axis2_char_t *temp_str = NULL;
	axis2_status_t status = AXIS2_FAILURE;
	axis2_char_t *url_modified = NULL;
	long status_code;
	axis2_char_t *uname_passwd = NULL;

	/* to indicate the current request is cached */
	int cached = 0;
	int retrieved_from_cached = 0;
	remote_registry_conf_t *conf = NULL;

	conf  = rest_client->conf;
	if(params)
	{
		size = axutil_array_list_size((axutil_array_list_t *) params, env);
		params_str = axutil_strdup(env, "?");
	}

	/* preparing the url from the parameters */
	for(i = 0; i < size; i++)
	{
		remote_registry_url_param_t *url_param = NULL;
		axis2_char_t *key = NULL;
		axis2_char_t *encoded_key = NULL;
		axis2_char_t *value = NULL;
		axis2_char_t *encoded_value = NULL;

		url_param = axutil_array_list_get((axutil_array_list_t *) params, env, i);
		key = url_param->key;
		value = url_param->value;

		encoded_key = (axis2_char_t *) AXIS2_MALLOC (env->allocator, strlen (key));
		memset (encoded_key, 0, strlen (key));
		encoded_key = axutil_url_encode (env, encoded_key, key, (int)strlen (key));

		encoded_value = (axis2_char_t *) AXIS2_MALLOC (env->allocator, strlen (value));
		memset (encoded_value, 0, strlen (value));
		encoded_value = axutil_url_encode (env, encoded_value, value, (int)strlen (value));
		temp_str = params_str;
		params_str = axutil_strcat(env, temp_str, encoded_key, "=", encoded_value, "&", NULL);
		if(temp_str)
		{
			AXIS2_FREE(env->allocator, temp_str);
			temp_str = NULL;
		}

		if(encoded_key)
		{
			AXIS2_FREE(env->allocator, encoded_key);
			encoded_key = NULL;
		}

		if(encoded_value)
		{
			AXIS2_FREE(env->allocator, encoded_value);
			encoded_value = NULL;
		}
	}
	if(relative) 
	{
		url_modified = axutil_strcat(env, remote_registry_conf_get_reg_url(rest_client->conf, env), 
			REMOTE_REGISTRY_BASE_URL_POSTFIX, url, params_str, NULL);
	}
	else
	{
		url_modified = axutil_strcat(env, url, params_str, NULL);
	}


	/* setting the username password */
	if(conf && remote_registry_conf_get_username(conf, env))
	{

		uname_passwd = axutil_strcat(env, remote_registry_conf_get_username(conf, env),
			":",
			remote_registry_conf_get_password(conf, env), 
			NULL);

	}

	/* TODO: check the caching here */
	status_code = remote_registry_rest_client_get_only_if_modified(
		rest_client, env, url_modified, 
		uname_passwd, &ret, content_len);

	if(status_code == 304) {
		/* retrive it from the cache */

		/* no modifications, so use the cache */

		axis2_char_t *prev_cache = NULL;
		axis2_char_t *prev_cache_dup = NULL;
		int prev_cache_len = 0;
		axis2_char_t *prev_cache_time = NULL;

		/* retrieving the values from the cache */
		prev_cache = axutil_hash_get(rest_client->cached_entries, url_modified, AXIS2_HASH_KEY_STRING);
		prev_cache_len = (int)axutil_hash_get(rest_client->cached_entries_len, url_modified, AXIS2_HASH_KEY_STRING);

		if(prev_cache) {
			/* when caching we keep a null character at the end, need to retrieve with that */
			prev_cache_dup = (axis2_char_t*)AXIS2_MALLOC(env->allocator, prev_cache_len + sizeof(axis2_char_t));
			memcpy(prev_cache_dup, prev_cache, prev_cache_len + sizeof(axis2_char_t));

			ret = prev_cache_dup;
			*content_len = prev_cache_len;

			retrieved_from_cached = 1;
			rest_client->last_response_status = AXIS2_SUCCESS;
		}
		else {
			/* if the cache doesn't exist, we anyway need to call the service */
			retrieved_from_cached = 0;
		}

	}

	if(!retrieved_from_cached && status_code != 200) {

		/* otherwise (including 200 OK,  we  better go and check for the server */
		remote_registry_rest_client_get_internal(rest_client, env, 
			url_modified, 
			uname_passwd, &ret, content_len, NULL);
	}

	if(uname_passwd) 
	{
		AXIS2_FREE(env->allocator, uname_passwd);
	}
	if(params_str)
	{
		AXIS2_FREE(env->allocator, params_str);
	}
	AXIS2_FREE(env->allocator, url_modified);

	return ret;
}
Exemplo n.º 2
0
AXIS2_EXTERN axis2_char_t* AXIS2_CALL
service_admin_util_get_uname(axutil_env_t *env,char mode)
{
	char *unameval;
	char tmp_uname[256];
#ifdef WIN32
	DWORD dwBuild=0;
	DWORD dwVersion = GetVersion();
	DWORD dwWindowsMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
	DWORD dwWindowsMinorVersion =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
	DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
	TCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
	SYSTEM_INFO SysInfo;

	GetComputerName(ComputerName, &dwSize);
	GetSystemInfo(&SysInfo);

	if (mode == 's') {
		if (dwVersion < 0x80000000) {
			unameval = "Windows NT";
		} else {
			unameval = "Windows 9x";
		}
	} else if (mode == 'r') {
		snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d", dwWindowsMajorVersion, dwWindowsMinorVersion);
		unameval = tmp_uname;
	} else if (mode == 'n') {
		unameval = ComputerName;
	} else if (mode == 'v') {
		dwBuild = (DWORD)(HIWORD(dwVersion));
		snprintf(tmp_uname, sizeof(tmp_uname), "build %d", dwBuild);
		unameval = tmp_uname;
	} else if (mode == 'm') {
		switch (SysInfo.wProcessorArchitecture) {
			case PROCESSOR_ARCHITECTURE_INTEL :
				snprintf(tmp_uname, sizeof(tmp_uname), "i%d", SysInfo.dwProcessorType);
				unameval = tmp_uname;
				break;
			case PROCESSOR_ARCHITECTURE_MIPS :
				snprintf(tmp_uname, sizeof(tmp_uname), "MIPS R%d000", SysInfo.wProcessorLevel);
				unameval = tmp_uname;
				break;
			case PROCESSOR_ARCHITECTURE_ALPHA :
				snprintf(tmp_uname, sizeof(tmp_uname), "Alpha %d", SysInfo.wProcessorLevel);
				unameval = tmp_uname;
				break;
			case PROCESSOR_ARCHITECTURE_PPC :
				snprintf(tmp_uname, sizeof(tmp_uname), "PPC 6%02d", SysInfo.wProcessorLevel);
				unameval = tmp_uname;
				break;
			case PROCESSOR_ARCHITECTURE_IA64 :
				unameval = "IA64";
				break;
#if defined(PROCESSOR_ARCHITECTURE_IA32_ON_WIN64)
			case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 :
				unameval = "IA32";
				break;
#endif
#if defined(PROCESSOR_ARCHITECTURE_AMD64)
			case PROCESSOR_ARCHITECTURE_AMD64 :
				unameval = "AMD64";
				break;
#endif
			case PROCESSOR_ARCHITECTURE_UNKNOWN :
			default :
				unameval = "Unknown";
				break;
		}
	} else { /* assume mode == 'a' */
		/* Get build numbers for Windows NT or Win95 */
		if (dwVersion < 0x80000000){
			dwBuild = (DWORD)(HIWORD(dwVersion));
			snprintf(tmp_uname, sizeof(tmp_uname), "%s %d.%d build %d",
					 "Windows NT", 
					 dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild);
		} else {
			snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d",
					 "Windows 9x",
					 dwWindowsMajorVersion, dwWindowsMinorVersion);
		}
		unameval = tmp_uname;
	}
#else
#ifdef HAVE_SYS_UTSNAME_H
	struct utsname buf;
	if (uname((struct utsname *)&buf) == -1) {
		unameval = "Linux";
	} else {
		if (mode == 's') {
			unameval = buf.sysname;
		} else if (mode == 'r') {
			unameval = buf.release;
		} else if (mode == 'n') {
			unameval = buf.nodename;
		} else if (mode == 'v') {
			unameval = buf.version;
		} else if (mode == 'm') {
			unameval = buf.machine;
		} else { /* assume mode == 'a' */
			snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %s %s %s",
					 buf.sysname, buf.nodename, buf.release, buf.version,
					 buf.machine);
			unameval = tmp_uname;
		}

	}
#endif
#endif
	return axutil_strdup(env,unameval);

}
            /**
             * setter for return
             */
            axis2_status_t AXIS2_CALL
            adb_getBindingOperationMessagePolicyResponse_set_return(
                    adb_getBindingOperationMessagePolicyResponse_t* _getBindingOperationMessagePolicyResponse,
                    const axutil_env_t *env,
                    const axis2_char_t*  arg_return)
             {
                

                AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
                AXIS2_PARAM_CHECK(env->error, _getBindingOperationMessagePolicyResponse, AXIS2_FAILURE);
                
                if(_getBindingOperationMessagePolicyResponse->is_valid_return &&
                        arg_return == _getBindingOperationMessagePolicyResponse->property_return)
                {
                    
                    return AXIS2_SUCCESS; 
                }

                adb_getBindingOperationMessagePolicyResponse_reset_return(_getBindingOperationMessagePolicyResponse, env);

                
                if(NULL == arg_return)
                {
                    /* We are already done */
                    return AXIS2_SUCCESS;
                }
                _getBindingOperationMessagePolicyResponse->property_return = (axis2_char_t *)axutil_strdup(env, arg_return);
                        if(NULL == _getBindingOperationMessagePolicyResponse->property_return)
                        {
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error allocating memeory for return");
                            return AXIS2_FAILURE;
                        }
                        _getBindingOperationMessagePolicyResponse->is_valid_return = AXIS2_TRUE;
                    
                return AXIS2_SUCCESS;
             }
Exemplo n.º 4
0
AXIS2_EXTERN void AXIS2_CALL
remote_registry_resource_load_metadata_from_feed_node(const axutil_env_t *env,
                                remote_registry_resource_t *resource,
                                axiom_node_t *feed_node)
{
    axiom_children_iterator_t *node_it = NULL;
    axiom_element_t *feed_ele = NULL;
    
    feed_ele = axiom_node_get_data_element(feed_node, env);

    node_it = axiom_element_get_children(feed_ele, env, feed_node);

    /* iterate all the children */
    while(axiom_children_iterator_has_next(node_it, env)) 
    {
        axiom_node_t *child = NULL;
        axiom_element_t *child_ele = NULL;
        axis2_char_t *local_name = NULL;

        child = axiom_children_iterator_next(node_it, env);

        if(axiom_node_get_node_type(child, env) != AXIOM_ELEMENT) 
        {
            continue;
        }
        child_ele = (axiom_element_t *)axiom_node_get_data_element(child, env);
        
        local_name = axiom_element_get_localname(child_ele, env);

        /* retriving the attribute one by one */
        if(!axutil_strcmp(local_name, REMOTE_REGISTRY_FEED_KEY_ID)) 
        {
            axis2_char_t *id_text = NULL;

            id_text = axiom_element_get_text(child_ele, env, child);

            resource->id = id_text;
        }
        else if(!axutil_strcmp(local_name, REMOTE_REGISTRY_FEED_KEY_MEDIA_TYPE))
        {
            axis2_char_t *media_type = NULL;

            media_type = axiom_element_get_text(child_ele, env, child);

            /* for the root feed the feed xml is NULL */
            if(media_type != NULL) {
                if(!axutil_strcmp(media_type, REMOTE_REGISTRY_FEED_KEY_DIR)) 
                {
                    resource->is_collection = 1;
                }
                resource->media_type = media_type;
            }
        }
        else if(!axutil_strcmp(local_name, REMOTE_REGISTRY_FEED_KEY_ENTRY)) 
        {
            /* now iterate through the entries */
            axutil_array_list_t *entry_arr = NULL;
            remote_registry_resource_t *entry_resource = NULL;
			axis2_char_t *child_path = NULL;

            entry_arr = resource->entries;
            if(!entry_arr) {
                entry_arr = axutil_array_list_create(env, 5);
                resource->entries = entry_arr;
            }

            entry_resource = remote_registry_resource_create_from_entry_node(env, child);
            axutil_array_list_add(entry_arr, env, entry_resource);

			/* adding child as a path */
			child_path = entry_resource->link_path;
			if(!resource->child_paths)
			{
				resource->child_paths = axutil_array_list_create(env, 10);
			}
			axutil_array_list_add(resource->child_paths, env, child_path);
        }
        else if(!axutil_strcmp(local_name, REMOTE_REGISTRY_FEED_KEY_LINK))
        {
            /* loading all the links */
            axis2_char_t *href = NULL;
            axis2_char_t *rel = NULL;
                
            href = axiom_element_get_attribute_value_by_name(child_ele, env, REMOTE_REGISTRY_FEED_ATTR_HREF);
            rel = axiom_element_get_attribute_value_by_name(child_ele, env, REMOTE_REGISTRY_FEED_ATTR_REL);

            if(!axutil_strcmp(rel, REMOTE_REGISTRY_FEED_ATTR_SELF)) 
            {
                resource->link_self = axutil_strdup(env, href);
            }
            else if(!axutil_strcmp(rel, REMOTE_REGISTRY_FEED_ATTR_ALTERNATE))
            {
                resource->link_alternate = axutil_strdup(env, href);
            }
            else if(!axutil_strcmp(rel, REMOTE_REGISTRY_FEED_ATTR_PATH))
            {
                remote_registry_resource_set_link_path(resource, env, href);
            }
            else if(!axutil_strcmp(rel, REMOTE_REGISTRY_FEED_ATTR_EDIT))
            {
                resource->link_edit = axutil_strdup(env, href);
            }
            else if(!axutil_strcmp(rel, REMOTE_REGISTRY_FEED_ATTR_EDIT_MEDIA))
            {
                resource->link_edit_media = axutil_strdup(env, href);
            }

        }
        else if(!axutil_strcmp(local_name, REMOTE_REGISTRY_FEED_KEY_CONTENT))
        {
            axis2_char_t *content_src_url = NULL;

            content_src_url = axiom_element_get_attribute_value_by_name(child_ele, env, REMOTE_REGISTRY_FEED_ATTR_SRC);
            remote_registry_resource_set_content_src_url(resource, env, content_src_url);
			if(content_src_url != NULL) {
				resource->is_collection = 0;
			}
        }
        else if(!axutil_strcmp(local_name, REMOTE_REGISTRY_FEED_KEY_AUTHOR))
        {
            axiom_node_t *name_node = NULL;
            axiom_element_t *name_element = NULL;

            name_node = axiom_node_get_first_child(child, env);

            /* get the first child (with type AXIOM_ELEMENT) where we can find the name */
            if(name_node && axiom_node_get_node_type(name_node, env) != AXIOM_ELEMENT)
            {
                name_node = axiom_node_get_next_sibling(name_node, env);
            }

            if(name_node)
            {
                axis2_char_t *name = NULL;
                name_element = axiom_node_get_data_element(name_node, env);

                name = axiom_element_get_text(name_element, env, name_node);

                remote_registry_resource_set_author_name(resource, env, name);
            }
        }
		else if(!axutil_strcmp(local_name, REMOTE_REGISTRY_FEED_KEY_PROPERTIES))
		{
			axiom_children_iterator_t *properties_it = NULL;
			axiom_element_t *properties_ele = NULL;

			if(!resource->properties)
			{
				resource->properties = axutil_hash_make(env);
			}
		    
			properties_ele = axiom_node_get_data_element(child, env);

			properties_it = axiom_element_get_children(properties_ele, env, child);

			/* iterate all the properties */
			while(axiom_children_iterator_has_next(properties_it, env)) 
			{
				axiom_node_t *property_node = NULL;
				axiom_node_t *name_node = NULL;
				axiom_node_t *value_node = NULL;
				axiom_element_t *name_element = NULL;
				axiom_element_t *value_element = NULL;

				axis2_char_t *name = NULL;
				axis2_char_t *value = NULL;

				property_node = axiom_children_iterator_next(properties_it, env);

				if(axiom_node_get_node_type(property_node, env) != AXIOM_ELEMENT) 
				{
					continue;
				}
		        
				name_node = axiom_node_get_first_child(property_node, env);
				while(name_node && axiom_node_get_node_type(name_node, env) != AXIOM_ELEMENT) 
				{
					name_node = axiom_node_get_next_sibling(name_node, env);
				}

				if(!name_node) 
				{
					continue;
				}

				value_node = axiom_node_get_next_sibling(name_node, env);
				while(value_node && axiom_node_get_node_type(value_node, env) != AXIOM_ELEMENT) 
				{
					value_node = axiom_node_get_next_sibling(value_node, env);
				}

				if(!value_node) 
				{
					continue;
				}

				name_element = axiom_node_get_data_element(name_node, env);
				value_element = axiom_node_get_data_element(value_node, env);

				name = axiom_element_get_text(name_element, env, name_node);
				value = axiom_element_get_text(value_element, env, value_node);
				
				axutil_hash_set(resource->properties, name, AXIS2_HASH_KEY_STRING, value);
			}
		}
    }
}
Exemplo n.º 5
0
        axiom_node_t* AXIS2_CALL
        adb_ProductComplete_serialize(
                adb_ProductComplete_t* _ProductComplete,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
         
         axiom_node_t *current_node = NULL;
         int tag_closed = 0;

         
         
                axiom_namespace_t *ns1 = NULL;

                axis2_char_t *qname_uri = NULL;
                axis2_char_t *qname_prefix = NULL;
                axis2_char_t *p_prefix = NULL;
                axis2_bool_t ns_already_defined;
            
                    axis2_char_t text_value_1[64];
                    
               axis2_char_t *start_input_str = NULL;
               axis2_char_t *end_input_str = NULL;
               unsigned int start_input_str_len = 0;
               unsigned int end_input_str_len = 0;
            
            
               axiom_data_source_t *data_source = NULL;
               axutil_stream_t *stream = NULL;

             
                int next_ns_index_value = 0;
            

            AXIS2_ENV_CHECK(env, NULL);
            AXIS2_PARAM_CHECK(env->error, _ProductComplete, NULL);
            
             
                    namespaces = axutil_hash_make(env);
                    next_ns_index = &next_ns_index_value;
                     
                           ns1 = axiom_namespace_create (env,
                                             "http://webser.com",
                                             "n"); 
                           axutil_hash_set(namespaces, "http://webser.com", AXIS2_HASH_KEY_STRING, axutil_strdup(env, "n"));
                       
                     
                    parent_element = axiom_element_create (env, NULL, "ProductComplete", ns1 , &parent);
                    
                    
                    axiom_element_set_namespace(parent_element, env, ns1, parent);


            
                    data_source = axiom_data_source_create(env, parent, &current_node);
                    stream = axiom_data_source_get_stream(data_source, env);
                  
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://webser.com", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://webser.com", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://webser.com",
                                            p_prefix));
                       }
                      

                   if (!_ProductComplete->is_valid_productInfo)
                   {
                      
                           /* no need to complain for minoccurs=0 element */
                            
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("productInfo"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("productInfo")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     
                     /*
                      * parsing productInfo element
                      */

                    
                    
                            sprintf(start_input_str, "<%s%sproductInfo",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); 
                            
                        start_input_str_len = axutil_strlen(start_input_str);
                        sprintf(end_input_str, "</%s%sproductInfo>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                        end_input_str_len = axutil_strlen(end_input_str);
                     
                            if(!adb_ProductCompleteType_is_particle())
                            {
                                axutil_stream_write(stream, env, start_input_str, start_input_str_len);
                            }
                            
                            adb_ProductCompleteType_serialize(_ProductComplete->property_productInfo, 
                                                                                 env, current_node, parent_element,
                                                                                 adb_ProductCompleteType_is_particle() || AXIS2_FALSE, namespaces, next_ns_index);
                            
                            if(!adb_ProductCompleteType_is_particle())
                            {
                                axutil_stream_write(stream, env, end_input_str, end_input_str_len);
                            }
                            
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 
                   if(namespaces)
                   {
                       axutil_hash_index_t *hi;
                       void *val;
                       for (hi = axutil_hash_first(namespaces, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, NULL, NULL, &val);
                           AXIS2_FREE(env->allocator, val);
                       }
                       axutil_hash_free(namespaces, env);
                   }
                

            return parent;
        }
            /**
             * setter for transport
             */
            axis2_status_t AXIS2_CALL
            adb_getServiceSpecificOutParameters_set_transport(
                    adb_getServiceSpecificOutParameters_t* _getServiceSpecificOutParameters,
                    const axutil_env_t *env,
                    const axis2_char_t*  arg_transport)
             {
                

                AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
                AXIS2_PARAM_CHECK(env->error, _getServiceSpecificOutParameters, AXIS2_FAILURE);
                
                if(_getServiceSpecificOutParameters->is_valid_transport &&
                        arg_transport == _getServiceSpecificOutParameters->property_transport)
                {
                    
                    return AXIS2_SUCCESS; 
                }

                adb_getServiceSpecificOutParameters_reset_transport(_getServiceSpecificOutParameters, env);

                
                if(NULL == arg_transport)
                {
                    /* We are already done */
                    return AXIS2_SUCCESS;
                }
                _getServiceSpecificOutParameters->property_transport = (axis2_char_t *)axutil_strdup(env, arg_transport);
                        if(NULL == _getServiceSpecificOutParameters->property_transport)
                        {
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error allocating memeory for transport");
                            return AXIS2_FAILURE;
                        }
                        _getServiceSpecificOutParameters->is_valid_transport = AXIS2_TRUE;
                    
                return AXIS2_SUCCESS;
             }
Exemplo n.º 7
0
int main()
{
    FILE *outf;
    /*FILE *outf2;
    oxs_buffer_ptr encoded_buf = NULL;
    oxs_buffer_ptr out = NULL;
    */
    axutil_env_t *env = NULL;
    oxs_buffer_ptr in = NULL;
    axis2_char_t *plain_text = NULL;
    unsigned char *out_main_buf = NULL , *out_main_buf2 = NULL;

    unsigned char key[EVP_MAX_KEY_LENGTH] = "012345670123456701234567";
    unsigned char iv[EVP_MAX_IV_LENGTH] = "01234567";

    unsigned char *cipher_name = NULL;

    openssl_evp_block_cipher_ctx_ptr bc1_ctx = NULL;
    openssl_evp_block_cipher_ctx_ptr bc2_ctx = NULL;
    int ret, encrypted_len, decrypted_len;


    env = test_init();
    printf("--Testing started Openssl Block Cipher--------------------------------------------\n");
#if 0
    plain_text =  "Upon successful completion, fread() returns the number of ...END"
                  "Upon successful completion, fread() returns the number of ...END";
    /*"This is an additional block :)";*/

#else

    plain_text = "PLAINTEXT";
#endif
    in =  oxs_string_to_buffer(env, plain_text);

    cipher_name = (unsigned char*)OPENSSL_EVP_des_ede3_cbc;

    bc1_ctx = openssl_evp_block_cipher_ctx_create(env);
    if (!bc1_ctx) return(-1);
    /*Set the key*/
    bc1_ctx->key = key; /*axutil_strdup(key, env);*/
    bc1_ctx->key_initialized = 1;
    /*Set the IV*/
    bc1_ctx->iv =  axutil_strdup(env, iv);
    ret =  openssl_evp_block_cipher_ctx_init(env, bc1_ctx,
            OPENSSL_ENCRYPT, cipher_name);
    if (ret < 0)
    {
        printf("openssl_evp_block_cipher_ctx_init failed\n");
        return -1;
    }

    ret =    openssl_block_cipher_crypt(env, bc1_ctx,
                                        in->data, strlen((char*)in->data), &out_main_buf, OPENSSL_ENCRYPT);
    if (ret < 0)
    {
        printf("openssl_block_cipher_crypt OPENSSL_ENCRYPT failed\n");
        return -1;
    }
    encrypted_len = ret;

    printf("\nEncrypted data size =%d \n ", ret);
    outf = fopen("outbuf", "wb");
    fwrite(out_main_buf, 1, ret, outf);

    /*    out = oxs_create_buffer(env, ret);*/

    /*********************Decrypt***********************/
    bc2_ctx = openssl_evp_block_cipher_ctx_create(env);
    if (!bc2_ctx) return(-1);
    /*Set the key*/
    bc2_ctx->key = key; /*axutil_strdup(key, env);*/
    bc2_ctx->key_initialized = 1;
    /*Set the IV*/
    bc2_ctx->iv =  axutil_strdup(env, iv);
    ret =  openssl_evp_block_cipher_ctx_init(env, bc2_ctx,
            OPENSSL_DECRYPT, cipher_name);
    if (ret < 0)
    {
        printf("openssl_evp_block_cipher_ctx_init failed\n");
        return -1;
    }

    ret =    openssl_block_cipher_crypt(env, bc2_ctx,
                                        out_main_buf, encrypted_len,  &out_main_buf, OPENSSL_DECRYPT);

    if (ret < 0)
    {
        printf("openssl_block_cipher_crypt  OPENSSL_DECRYPT failed\n");
        return -1;
    }
    decrypted_len = ret;

    printf("\nDecrypted data[%d] %s\n ", ret, out_main_buf2);


#if 0
    /*Now Encode */
    encoded_buf = oxs_base64_encode(env, out);

    if (!encoded_buf) return -1;


    printf("\nencrypted_encoded_buf Size =\n %d ", encoded_buf->size);
    printf("\nencrypted_encoded_buf Data =\n %s ", encoded_buf->data);

    /*Now we need to decrypt*/
    /*===============================================================*/

    ret = decrypt(env, encoded_buf, key, iv);
    if (ret < 0) return -1;
#endif
    return (0);
}
Exemplo n.º 8
0
            /**
             * Set the ith element of return.
             */
            axis2_status_t AXIS2_CALL
            adb_getInternalUsersResponse_set_return_at(
                    adb_getInternalUsersResponse_t* _getInternalUsersResponse,
                    const axutil_env_t *env, int i,
                    const axis2_char_t* arg_return)
            {
                void *element = NULL;
                int size = 0;
                int j;
                int non_nil_count;
                axis2_bool_t non_nil_exists = AXIS2_FALSE;

                

                AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
                AXIS2_PARAM_CHECK(env->error, _getInternalUsersResponse, AXIS2_FAILURE);
                
                if( _getInternalUsersResponse->is_valid_return &&
                    _getInternalUsersResponse->property_return &&
                
                    arg_return == (axis2_char_t*)axutil_array_list_get(_getInternalUsersResponse->property_return, env, i))
                  
                {
                    
                    return AXIS2_SUCCESS; 
                }

                
                    if(NULL != arg_return)
                    {
                        non_nil_exists = AXIS2_TRUE;
                    }
                    else {
                        if(_getInternalUsersResponse->property_return != NULL)
                        {
                            size = axutil_array_list_size(_getInternalUsersResponse->property_return, env);
                            for(j = 0, non_nil_count = 0; j < size; j ++ )
                            {
                                if(i == j) continue; 
                                if(NULL != axutil_array_list_get(_getInternalUsersResponse->property_return, env, i))
                                {
                                    non_nil_count ++;
                                    non_nil_exists = AXIS2_TRUE;
                                    if(non_nil_count >= 0)
                                    {
                                        break;
                                    }
                                }
                            }

                        
                        }
                    }
                  

                if(_getInternalUsersResponse->property_return == NULL)
                {
                    _getInternalUsersResponse->property_return = axutil_array_list_create(env, 10);
                }
                
                /* check whether there already exist an element */
                element = axutil_array_list_get(_getInternalUsersResponse->property_return, env, i);
                if(NULL != element)
                {
                  
                  
                  
                       /* This is an unknown type or a primitive. Please free this manually*/
                     
                }

                
                    if(!non_nil_exists)
                    {
                        
                        _getInternalUsersResponse->is_valid_return = AXIS2_FALSE;
                        axutil_array_list_set(_getInternalUsersResponse->property_return , env, i, NULL);
                        
                        return AXIS2_SUCCESS;
                    }
                
                   axutil_array_list_set(_getInternalUsersResponse->property_return , env, i, axutil_strdup(env, arg_return));
                  _getInternalUsersResponse->is_valid_return = AXIS2_TRUE;
                
                return AXIS2_SUCCESS;
            }
Exemplo n.º 9
0
            /**
             * Add to return.
             */
            axis2_status_t AXIS2_CALL
            adb_getInternalUsersResponse_add_return(
                    adb_getInternalUsersResponse_t* _getInternalUsersResponse,
                    const axutil_env_t *env,
                    const axis2_char_t* arg_return)
             {
                

                AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
                AXIS2_PARAM_CHECK(env->error, _getInternalUsersResponse, AXIS2_FAILURE);

                
                    if(NULL == arg_return)
                    {
                      
                           return AXIS2_SUCCESS; 
                        
                    }
                  

                if(_getInternalUsersResponse->property_return == NULL)
                {
                    _getInternalUsersResponse->property_return = axutil_array_list_create(env, 10);
                }
                if(_getInternalUsersResponse->property_return == NULL)
                {
                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed in allocatting memory for return");
                    return AXIS2_FAILURE;
                    
                }
                
                   axutil_array_list_add(_getInternalUsersResponse->property_return , env, axutil_strdup(env, arg_return));
                  _getInternalUsersResponse->is_valid_return = AXIS2_TRUE;
                return AXIS2_SUCCESS;
             }
        axiom_node_t* AXIS2_CALL
        adb_listPublishedOperationsResponse_serialize_obj(
                adb_listPublishedOperationsResponse_t* _listPublishedOperationsResponse,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
         
         axiom_node_t* current_node = NULL;
         int tag_closed = 0;
         
                axiom_namespace_t *ns1 = NULL;

                axis2_char_t *qname_uri = NULL;
                axis2_char_t *qname_prefix = NULL;
                axis2_char_t *p_prefix = NULL;
                axis2_bool_t ns_already_defined;
            
               int i = 0;
               int count = 0;
               void *element = NULL;
             
                    axis2_char_t text_value_1[ADB_DEFAULT_DIGIT_LIMIT];
                    
               axis2_char_t *start_input_str = NULL;
               axis2_char_t *end_input_str = NULL;
               unsigned int start_input_str_len = 0;
               unsigned int end_input_str_len = 0;
            
            
               axiom_data_source_t *data_source = NULL;
               axutil_stream_t *stream = NULL;

             
                int next_ns_index_value = 0;
            

            AXIS2_ENV_CHECK(env, NULL);
            AXIS2_PARAM_CHECK(env->error, _listPublishedOperationsResponse, NULL);
            
             
                    namespaces = axutil_hash_make(env);
                    next_ns_index = &next_ns_index_value;
                     
                           ns1 = axiom_namespace_create (env,
                                             "http://org.apache.axis2/xsd",
                                             "n"); 
                           axutil_hash_set(namespaces, "http://org.apache.axis2/xsd", AXIS2_HASH_KEY_STRING, axutil_strdup(env, "n"));
                       
                     
                    parent_element = axiom_element_create (env, NULL, "listPublishedOperationsResponse", ns1 , &parent);
                    
                    
                    axiom_element_set_namespace(parent_element, env, ns1, parent);


            
                    data_source = axiom_data_source_create(env, parent, &current_node);
                    stream = axiom_data_source_get_stream(data_source, env);
                  
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://org.apache.axis2/xsd", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://org.apache.axis2/xsd", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://org.apache.axis2/xsd",
                                            p_prefix));
                       }
                      

                   if (!_listPublishedOperationsResponse->is_valid_return)
                   {
                      
                           /* no need to complain for minoccurs=0 element */
                            
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("return"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("return")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     /*
                      * Parsing return array
                      */
                     if (_listPublishedOperationsResponse->property_return != NULL)
                     {
                        

                            sprintf(start_input_str, "<%s%sreturn",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                            
                         start_input_str_len = axutil_strlen(start_input_str);

                         sprintf(end_input_str, "</%s%sreturn>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                         end_input_str_len = axutil_strlen(end_input_str);

                         count = axutil_array_list_size(_listPublishedOperationsResponse->property_return, env);
                         for(i = 0; i < count; i ++)
                         {
                            element = axutil_array_list_get(_listPublishedOperationsResponse->property_return, env, i);

                            if(NULL == element) 
                            {
                                continue;
                            }
                    
                     
                     /*
                      * parsing return element
                      */

                    
                     
                            if(!adb_OperationMetaData_is_particle())
                            {
                                axutil_stream_write(stream, env, start_input_str, start_input_str_len);
                            }
                            adb_OperationMetaData_serialize((adb_OperationMetaData_t*)element, 
                                                                                 env, current_node, parent_element,
                                                                                 adb_OperationMetaData_is_particle() || AXIS2_FALSE, namespaces, next_ns_index);
                            
                            if(!adb_OperationMetaData_is_particle())
                            {
                                axutil_stream_write(stream, env, end_input_str, end_input_str_len);
                            }
                            
                         }
                     }
                   
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 
                   if(namespaces)
                   {
                       axutil_hash_index_t *hi;
                       void *val;
                       for (hi = axutil_hash_first(namespaces, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, NULL, NULL, &val);
                           AXIS2_FREE(env->allocator, val);
                       }
                       axutil_hash_free(namespaces, env);
                   }
                

            return parent;
        }
Exemplo n.º 11
0
        axis2_status_t AXIS2_CALL
        adb_getInternalUsersResponse_deserialize_obj(
                adb_getInternalUsersResponse_t* _getInternalUsersResponse,
                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;
           
             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, _getInternalUsersResponse, 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 getInternalUsersResponse : "
                            "NULL element can not be passed to deserialize");
                return AXIS2_FAILURE;
              }
              

                    current_element = (axiom_element_t *)axiom_node_get_data_element(parent, env);
                    qname = axiom_element_get_qname(current_element, env, parent);
                    if (axutil_qname_equals(qname, env, _getInternalUsersResponse-> qname))
                    {
                        
                          first_node = axiom_node_get_first_child(parent, env);
                          
                    }
                    else
                    {
                        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                              "Failed in building adb object for getInternalUsersResponse : "
                              "Expected %s but returned %s",
                              axutil_qname_to_string(_getInternalUsersResponse-> qname, env),
                              axutil_qname_to_string(qname, env));
                        
                        return AXIS2_FAILURE;
                    }
                    
                    /*
                     * building return array
                     */
                       arr_list = axutil_array_list_create(env, 10);
                   

                     
                     /*
                      * building return element
                      */
                     
                     
                     
                                    element_qname = axutil_qname_create(env, "return", "http://service.mgt.user.carbon.wso2.org", NULL);
                                  
                               
                               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;
                                  }
                                  
                                  current_element = (axiom_element_t *)axiom_node_get_data_element(current_node, env);
                                  qname = axiom_element_get_qname(current_element, env, current_node);

                                  if ( 
                                    (current_node && current_element && (axutil_qname_equals(element_qname, env, qname))))
                                  {
                                  
                                      if( current_node && current_element && (axutil_qname_equals(element_qname, env, qname)))
                                      {
                                          is_early_node_valid = AXIS2_TRUE;
                                      }
                                      
                                     
                                          text_value = axiom_element_get_text(current_element, env, current_node);
                                          if(text_value != NULL)
                                          {
                                              axutil_array_list_add_at(arr_list, env, i, axutil_strdup(env, text_value));
                                          }
                                          
                                     if(AXIS2_FAILURE ==  status)
                                     {
                                         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "failed in setting the value for return ");
                                         if(element_qname)
                                         {
                                            axutil_qname_free(element_qname, env);
                                         }
                                         if(arr_list)
                                         {
                                            axutil_array_list_free(arr_list, env);
                                         }
                                         return AXIS2_FAILURE;
                                     }

                                     i ++;
                                    current_node = axiom_node_get_next_sibling(current_node, env);
                                  }
                                  else
                                  {
                                      is_early_node_valid = AXIS2_FALSE;
                                      sequence_broken = 1;
                                  }
                                  
                               }

                               
                                   if (i < 0)
                                   {
                                     /* found element out of order */
                                     AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "return (@minOccurs = '0') only have %d elements", i);
                                     if(element_qname)
                                     {
                                        axutil_qname_free(element_qname, env);
                                     }
                                     if(arr_list)
                                     {
                                        axutil_array_list_free(arr_list, env);
                                     }
                                     return AXIS2_FAILURE;
                                   }
                               

                               if(0 == axutil_array_list_size(arr_list,env))
                               {
                                    axutil_array_list_free(arr_list, env);
                               }
                               else
                               {
                                    status = adb_getInternalUsersResponse_set_return(_getInternalUsersResponse, env,
                                                                   arr_list);
                               }

                             
                  if(element_qname)
                  {
                     axutil_qname_free(element_qname, env);
                     element_qname = NULL;
                  }
                 
          return status;
       }
Exemplo n.º 12
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_ws_info_list_add_ws_info_item(
    axis2_ws_info_list_t * ws_info_list,
    const axutil_env_t * env,
    axutil_file_t * file,
    int type)
{
    axis2_status_t status = AXIS2_FAILURE;
    axis2_char_t *file_name = NULL;
    axis2_char_t *temp_name = NULL;

    AXIS2_PARAM_CHECK(env->error, file, AXIS2_FAILURE);

    temp_name = axutil_file_get_name(file, env);
    file_name = axutil_strdup(env, temp_name);
    if(!file_name)
    {
        return AXIS2_FAILURE;
    }

    switch(type)
    {
        case AXIS2_SVC:
        {
            axis2_ws_info_t *ws_info = NULL;
            long last_modified_date = 0;
            axis2_arch_file_data_t *file_data = NULL;

            last_modified_date = (long)axutil_file_get_timestamp(file, env);
            /* We are sure that the difference lies within the long range */
            ws_info = axis2_ws_info_create_with_file_name_and_last_modified_date_and_type(env,
                file_name, last_modified_date, AXIS2_SVC);
            status = axutil_array_list_add(ws_info_list->ws_info_list, env, ws_info);

            if(AXIS2_SUCCESS != status)
            {
                return status;
            }
            file_data = axis2_arch_file_data_create_with_type_and_file(env, AXIS2_SVC, file);
            /* To inform that new web service is to be deployed */
            status = axis2_dep_engine_add_ws_to_deploy(ws_info_list->dep_engine, env, file_data);
            if(AXIS2_SUCCESS != status)
            {
                return status;
            }
            break;
        }
        case AXIS2_MODULE:
        {
            axis2_ws_info_t *ws_info = NULL;
            long last_modified_date = 0;
            axis2_arch_file_data_t *file_data = NULL;

            last_modified_date = (long)axutil_file_get_timestamp(file, env);
            /* We are sure that the difference lies within the long range */
            ws_info = axis2_ws_info_create_with_file_name_and_last_modified_date_and_type(env,
                file_name, last_modified_date, AXIS2_MODULE);
            status = axutil_array_list_add(ws_info_list->ws_info_list, env, ws_info);

            if(AXIS2_SUCCESS != status)
            {
                return status;
            }
            file_data = axis2_arch_file_data_create_with_type_and_file(env, AXIS2_MODULE, file);
            /* To inform that new module is to be deployed */
            status = axis2_dep_engine_add_ws_to_deploy(ws_info_list->dep_engine, env, file_data);
            if(AXIS2_SUCCESS != status)
            {
                return status;
            }

            break;
        }
    }
    return axutil_array_list_add(ws_info_list->current_info_list, env, file_name);
}
Exemplo n.º 13
0
axis2_status_t static
remote_registry_rest_client_set_cache(
									  remote_registry_rest_client_t *rest_client,
									  const axutil_env_t *env,
									  const axis2_char_t *url,
									  axis2_char_t *buffer, 
									  int buffer_len, 
									  axis2_char_t* new_etag)
{
	axis2_char_t *prev_cache = NULL;
	axis2_char_t *prev_cache_etag = NULL;
	int cache_replacing = 0;
	axis2_char_t *early_url = NULL;
	axis2_char_t *url_dup = NULL;
	axis2_char_t *buffer_dup = NULL;

    /* updating the env for all the hashes */
    axutil_hash_set_env(rest_client->cached_entries, env);
    axutil_hash_set_env(rest_client->cached_entries_len, env);
    axutil_hash_set_env(rest_client->etags, env);
    axutil_hash_set_env(rest_client->reverse_cached_order, env);

	/* check wether there were any old entries, if so free them */
	prev_cache = axutil_hash_get(rest_client->cached_entries, url, AXIS2_HASH_KEY_STRING);

	/* freeing the old entries */
	if(prev_cache)
	{
		int prev_cache_index;
		/* set a flag to identify that we replace already existed one */
		cache_replacing = 1;
		AXIS2_FREE(env->allocator, prev_cache);

		/* now we are going to check the place of it in the cached index */
		prev_cache_index = (int)axutil_hash_get(rest_client->reverse_cached_order, url, AXIS2_HASH_KEY_STRING);

		/* the value of the url and early_url is same, but different pointers */
		early_url = axutil_array_list_get(rest_client->cached_order, env, prev_cache_index);
		AXIS2_FREE(env->allocator, early_url);

        /* the reverse cache order will be cleard at the time it is overwritten */

		/* checking the next to clear (because of out of LIMIT) */
		early_url = axutil_array_list_get(rest_client->cached_order, env, rest_client->cached_order_index);
		if(early_url)
		{
			/* so actually we need to erase the existing one, rather we promot it to the prev_cache_index
			   so non of the cache will be erased other than the one that got replaced */
			axutil_array_list_set(rest_client->cached_order, env, prev_cache_index, early_url);
            early_url = axutil_strdup(env, early_url);
			axutil_hash_set(rest_client->reverse_cached_order, early_url, AXIS2_HASH_KEY_STRING, (void*)prev_cache_index);
		}

		/* and we are going to put our current url to the rest_client->cached_order_index */
		url_dup = axutil_strdup(env, url);
		axutil_array_list_set(rest_client->cached_order, env, rest_client->cached_order_index, url_dup);
		url_dup = axutil_strdup(env, url);
		axutil_hash_set(rest_client->reverse_cached_order, url_dup, AXIS2_HASH_KEY_STRING, (void*)rest_client->cached_order_index);
	}

	if(!cache_replacing)
	{
		int prev_cache_len;

		/* now we have to consider the limit of the cache for non-replacing case */
		early_url = axutil_array_list_get(rest_client->cached_order, env, rest_client->cached_order_index);
		if(early_url)
		{
			/* we have to remove this url for fit within the cache url */
			prev_cache = axutil_hash_get(rest_client->cached_entries, early_url, AXIS2_HASH_KEY_STRING);
			if(prev_cache)
			{
				AXIS2_FREE(env->allocator, prev_cache);
				axutil_hash_set(rest_client->cached_entries, early_url, AXIS2_HASH_KEY_STRING, NULL);
			}

			prev_cache_etag = axutil_hash_get(rest_client->etags, early_url, AXIS2_HASH_KEY_STRING);
			if(prev_cache_etag)
			{
				AXIS2_FREE(env->allocator, prev_cache_etag);
				axutil_hash_set(rest_client->etags, early_url, AXIS2_HASH_KEY_STRING, NULL);
			}

			prev_cache_len = (int)axutil_hash_get(rest_client->cached_entries_len, early_url, AXIS2_HASH_KEY_STRING);
			if(prev_cache_len)
			{
				axutil_hash_set(rest_client->cached_entries_len, early_url, AXIS2_HASH_KEY_STRING, NULL);
			}

			/* as the last we remove it from the order as well */
			axutil_hash_set(rest_client->reverse_cached_order, early_url, AXIS2_HASH_KEY_STRING, NULL);
			AXIS2_FREE(env->allocator, early_url);

            /* and we put our values in there */
            url_dup = axutil_strdup(env, url);
            axutil_array_list_set(rest_client->cached_order, env, rest_client->cached_order_index, url_dup);
            url_dup = axutil_strdup(env, url);
            axutil_hash_set(rest_client->reverse_cached_order, url_dup, AXIS2_HASH_KEY_STRING, (void*)rest_client->cached_order_index);
		}
        else {
            /* if no replacing is hapenning we can add the url to cached_order */
            url_dup = axutil_strdup(env, url);
            axutil_array_list_add(rest_client->cached_order, env, url_dup);
            url_dup = axutil_strdup(env, url);
            axutil_hash_set(rest_client->reverse_cached_order, url_dup, AXIS2_HASH_KEY_STRING, (void*)rest_client->cached_order_index);
        }
	}
    if(buffer)
    {
		buffer_dup = (axis2_char_t*)AXIS2_MALLOC(env->allocator, buffer_len + sizeof(axis2_char_t));
		memcpy(buffer_dup, buffer, buffer_len + sizeof(axis2_char_t));

		url_dup = axutil_strdup(env, url);
		axutil_hash_set(rest_client->cached_entries, url_dup, AXIS2_HASH_KEY_STRING, buffer_dup);
		url_dup = axutil_strdup(env, url);
		axutil_hash_set(rest_client->cached_entries_len, url_dup, AXIS2_HASH_KEY_STRING, (void*)buffer_len);
	}
	else 
	{
		url_dup = axutil_strdup(env, url);
		axutil_hash_set(rest_client->cached_entries, url_dup, AXIS2_HASH_KEY_STRING, NULL);
		url_dup = axutil_strdup(env, url);
		axutil_hash_set(rest_client->cached_entries_len, url_dup, AXIS2_HASH_KEY_STRING, (void*)0);
	}
	url_dup = axutil_strdup(env, url);
	axutil_hash_set(rest_client->etags, url_dup, AXIS2_HASH_KEY_STRING, new_etag);

	/* we need to increment the cached_order_index in cyclic manner .. */

	rest_client->cached_order_index ++;
	if(rest_client->cached_order_index >= remote_registry_conf_get_cache_entries_limit(rest_client->conf, env))
	{
		rest_client->cached_order_index = 0;
	}

	return AXIS2_SUCCESS;
}
Exemplo n.º 14
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL 
remote_registry_rest_client_delete(
								   remote_registry_rest_client_t *rest_client,
								   const axutil_env_t *env,
								   const axis2_char_t *url,
								   const axutil_array_list_t *params)
{
	CURL *curl_handle;
	CURLcode res;
	int size = 0, i = 0;
	axis2_char_t *params_str = NULL;
	axis2_char_t *url_modified = NULL;
	axis2_status_t status = AXIS2_FAILURE;
	remote_registry_conf_t *conf = NULL;
	axis2_char_t *uname_passwd = NULL;

	conf  = rest_client->conf;

	if(params)
	{
		size = axutil_array_list_size((axutil_array_list_t *) params, env);
		params_str = axutil_strdup(env, "?");
	}

	for(i = 0; i < size; i++)
	{
		remote_registry_url_param_t *url_param = NULL;
		axis2_char_t *key = NULL;
		axis2_char_t *encoded_key = NULL;
		axis2_char_t *value = NULL;
		axis2_char_t *encoded_value = NULL;
		axis2_char_t *temp_str = NULL;

		url_param = axutil_array_list_get((axutil_array_list_t *) params, env, i);
		key = url_param->key;
		value = url_param->value;

		encoded_key = (axis2_char_t *) AXIS2_MALLOC (env->allocator, strlen (key));
		memset (encoded_key, 0, strlen (key));
		encoded_key = axutil_url_encode (env, encoded_key, key, (int)strlen (key));

		encoded_value = (axis2_char_t *) AXIS2_MALLOC (env->allocator, strlen (value));
		memset (encoded_value, 0, strlen (value));
		encoded_value = axutil_url_encode (env, encoded_value, value, (int)strlen (value));
		temp_str = params_str;
		params_str = axutil_strcat(env, temp_str, encoded_key, "=", encoded_value, "&", NULL);
		if(temp_str)
		{
			AXIS2_FREE(env->allocator, temp_str);
			temp_str = NULL;
		}

		if(encoded_key)
		{
			AXIS2_FREE(env->allocator, encoded_key);
			encoded_key = NULL;
		}

		if(encoded_value)
		{
			AXIS2_FREE(env->allocator, encoded_value);
			encoded_value = NULL;
		}
	}

	url_modified = axutil_strcat(env, remote_registry_conf_get_reg_url(rest_client->conf, env), 
		REMOTE_REGISTRY_BASE_URL_POSTFIX, url, params_str, NULL);

	if(!url_modified)
	{
		return AXIS2_FAILURE;
	}

	curl_handle = curl_easy_init();
	if(curl_handle)
	{
		curl_easy_setopt(curl_handle, CURLOPT_URL, url_modified);
		curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, "DELETE");
		curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, REMOTE_REGISTRY_USER_AGENT);

		if(conf && remote_registry_conf_get_username(conf, env))
		{

			uname_passwd = axutil_strcat(env, remote_registry_conf_get_username(conf, env),
				":",
				remote_registry_conf_get_password(conf, env), 
				NULL);

			curl_easy_setopt(curl_handle, CURLOPT_USERPWD, uname_passwd);
		}



		res = curl_easy_perform(curl_handle);
		if(res == CURLE_OK)
		{
			res = curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &rest_client->last_response_status);
			if(res != CURLE_OK)
			{
				status = AXIS2_FAILURE;
			}
		}

		/* always cleanup */
		curl_easy_cleanup(curl_handle);
	}
	if(uname_passwd)
	{
		AXIS2_FREE(env->allocator, uname_passwd);
	}
	AXIS2_FREE(env->allocator, url_modified);

	return status;
}
            /**
             * Set the ith element of protocol.
             */
            axis2_status_t AXIS2_CALL
            adb_additionalTransferProtocols_type0_set_protocol_at(
                    adb_additionalTransferProtocols_type0_t* _additionalTransferProtocols_type0,
                    const axutil_env_t *env, int i,
                    const axis2_char_t* arg_protocol)
            {
                void *element = NULL;
                int size = 0;
                int j;
                int non_nil_count;
                axis2_bool_t non_nil_exists = AXIS2_FALSE;

                

                AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
                AXIS2_PARAM_CHECK(env->error, _additionalTransferProtocols_type0, AXIS2_FAILURE);
                
                if( _additionalTransferProtocols_type0->is_valid_protocol &&
                    _additionalTransferProtocols_type0->property_protocol &&
                
                    arg_protocol == (axis2_char_t*)axutil_array_list_get(_additionalTransferProtocols_type0->property_protocol, env, i))
                  
                {
                    
                    return AXIS2_SUCCESS; 
                }

                
                    if(NULL != arg_protocol)
                    {
                        non_nil_exists = AXIS2_TRUE;
                    }
                    else {
                        if(_additionalTransferProtocols_type0->property_protocol != NULL)
                        {
                            size = axutil_array_list_size(_additionalTransferProtocols_type0->property_protocol, env);
                            for(j = 0, non_nil_count = 0; j < size; j ++ )
                            {
                                if(i == j) continue; 
                                if(NULL != axutil_array_list_get(_additionalTransferProtocols_type0->property_protocol, env, i))
                                {
                                    non_nil_count ++;
                                    non_nil_exists = AXIS2_TRUE;
                                    if(non_nil_count >= 1)
                                    {
                                        break;
                                    }
                                }
                            }

                         
                            if( non_nil_count < 1)
                            {
                                   AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Size of the array of protocol is beinng set to be smaller than the specificed number of minOccurs(1)");
                                   return AXIS2_FAILURE;
                            }
                        
                        }
                    }
                  
                   if(!non_nil_exists)
                   {
                       AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "All the elements in the array of protocol is being set to NULL, but it is not a nullable or minOccurs=0 element");
                       return AXIS2_FAILURE;
                   }
                

                if(_additionalTransferProtocols_type0->property_protocol == NULL)
                {
                    _additionalTransferProtocols_type0->property_protocol = axutil_array_list_create(env, 10);
                }
                
                /* check whether there already exist an element */
                element = axutil_array_list_get(_additionalTransferProtocols_type0->property_protocol, env, i);
                if(NULL != element)
                {
                  
                  
                  
                       /* This is an unknown type or a primitive. Please free this manually*/
                     
                }

                
                   axutil_array_list_set(_additionalTransferProtocols_type0->property_protocol , env, i, axutil_strdup(env, arg_protocol));
                  _additionalTransferProtocols_type0->is_valid_protocol = AXIS2_TRUE;
                
                return AXIS2_SUCCESS;
            }
Exemplo n.º 16
0
int main(int argc, char** argv)
{
    const axutil_env_t *env = NULL;
    const axis2_char_t *address = NULL;
    axis2_endpoint_ref_t* endpoint_ref = NULL;
    axis2_endpoint_ref_t* reply_to = NULL;
    axis2_options_t *options = NULL;
    const axis2_char_t *client_home = NULL;
    axis2_svc_client_t* svc_client = NULL;
    axiom_node_t *payload = NULL;
    axutil_property_t *property = NULL;
    axis2_listener_manager_t *listener_manager = NULL;
    axis2_char_t *offered_seq_id = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    axiom_node_t *result = NULL;
    neethi_policy_t *policy = NULL;
    
    /* Set up the environment */
    env = axutil_env_create_all("rm_echo_single_1_1_amqp.log", AXIS2_LOG_LEVEL_TRACE);
 

    /* Set end point reference of echo service */
    address = "amqp://127.0.0.1:5672/axis2/services/RM11SampleService";
    if (argc > 1)
    {
        if (axutil_strcmp(argv[1], "-h") == 0)
        {
            printf("Usage : %s [endpoint_url]\n", argv[0]);
            printf("use -h for help\n");
            return 0;
        }
        else
        {
            address = argv[1];
        }
    }
    printf ("Using endpoint : %s\n", address);
    
    /* Create EPR with given address */
    endpoint_ref = axis2_endpoint_ref_create(env, address);

    /* Setup options */
    options = axis2_options_create(env);
    axis2_options_set_to(options, env, endpoint_ref);
    
    /* Seperate listner needs addressing, hence addressing stuff in options */
    axis2_options_set_action(options, env,
        "http://127.0.0.1:8080/axis2/services/RM11SampleService/anonOutInOp");

    reply_to = axis2_endpoint_ref_create(env, AXIS2_WSA_ANONYMOUS_URL);
    axis2_options_set_reply_to(options, env, reply_to);

    /* Set up deploy folder. It is from the deploy folder, the configuration is 
     * picked up using the axis2.xml file.
     * In this sample client_home points to the Axis2/C default deploy folder. 
     * The client_home can be different from this folder on your system. For 
     * example, you may have a different folder (say, my_client_folder) with its 
     * own axis2.xml file. my_client_folder/modules will have the modules that 
     * the client uses
     */
    client_home = AXIS2_GETENV("AXIS2C_HOME");
    if (!client_home)
    {
        client_home = "../../..";
    }

    /* Create service client */
    svc_client = axis2_svc_client_create(env, client_home);
    if (!svc_client)
    {
        printf("Error creating service client\n");
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code:%d :: %s", 
                env->error->error_number, AXIS2_ERROR_GET_MESSAGE(env->error));

        return -1;
    }

    policy = neethi_util_create_policy_from_file(env, "../policy/rm11-policy.xml");
    if(!policy)
    {
        printf("\nPolicy creation failed from the file");
        return 0;
    }

    status = axis2_svc_client_set_policy(svc_client, env, policy);

    if(status == AXIS2_FAILURE)
    {
        printf("Policy setting failed\n");
    }


    /* Set service client options */
    axis2_svc_client_set_options(svc_client, env, options);    
    
    axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);  
    axis2_svc_client_engage_module(svc_client, env, "sandesha2");

    listener_manager = axis2_listener_manager_create(env);
    if (!listener_manager)
    {
        return AXIS2_FAILURE;
    }

    /* Offer sequence */
    offered_seq_id = axutil_uuid_gen(env);
    property = axutil_property_create(env);
    if(property)
    {
        axutil_property_set_value(property, env, axutil_strdup(env, offered_seq_id));
        axis2_options_set_property(options, env, SANDESHA2_CLIENT_OFFERED_SEQ_ID, property);
    }

    /* RM Version 1.1 */
    property = axutil_property_create_with_args(env, 3, 0, 0, SANDESHA2_SPEC_VERSION_1_1);
    if(property)
    {
        axis2_options_set_property(options, env, SANDESHA2_CLIENT_RM_SPEC_VERSION, property);
    }

    payload = build_om_payload_for_echo_svc(env, "echo1");
    /*status = axis2_svc_client_send_robust(svc_client, env, payload);
    if(status)
    {
        printf("\necho client single channel invoke SUCCESSFUL!\n");
    }
    payload = NULL;*/
    result = axis2_svc_client_send_receive(svc_client, env, payload);
    if(result)
    {
        axis2_char_t *om_str = NULL;
        om_str = axiom_node_to_string(result, env);
        if (om_str)
        {
            printf("\nReceived OM : %s\n", om_str);
            AXIS2_FREE(env->allocator, om_str);
        }
        printf("\necho client two way single channel invoke SUCCESSFUL!\n");
        result = NULL;
    }
    else
    {
        printf("\necho client two way single channel invoke FAILED!\n");
    }

    payload = build_om_payload_for_echo_svc(env, "echo2");
    /*status = axis2_svc_client_send_robust(svc_client, env, payload);
    if(status)
    {
        printf("\necho client single channel invoke SUCCESSFUL!\n");
    }
    payload = NULL;*/
    result = axis2_svc_client_send_receive(svc_client, env, payload);
    if(result)
    {
        axis2_char_t *om_str = NULL;
        om_str = axiom_node_to_string(result, env);
        if (om_str)
        {
            printf("\nReceived OM : %s\n", om_str);
            AXIS2_FREE(env->allocator, om_str);
        }
        printf("\necho client two way single channel invoke SUCCESSFUL!\n");
        result = NULL;
    }
    else
    {
        printf("\necho client two way single channel invoke FAILED!\n");
    }

    payload = build_om_payload_for_echo_svc(env, "echo3");
    /*status = axis2_svc_client_send_robust(svc_client, env, payload);
    if(status)
    {
        printf("\necho client single channel invoke SUCCESSFUL!\n");
    }
    payload = NULL;*/
    
    result = axis2_svc_client_send_receive(svc_client, env, payload);
    if(result)
    {
        axis2_char_t *om_str = NULL;
        om_str = axiom_node_to_string(result, env);
        if (om_str)
        {
            printf("\nReceived OM : %s\n", om_str);
            AXIS2_FREE(env->allocator, om_str);
        }
        printf("\necho client two way single channel invoke SUCCESSFUL!\n");
        result = NULL;
    }
    else
    {
        printf("\necho client two way single channel invoke FAILED!\n");
    }

    AXIS2_SLEEP(SANDESHA2_SLEEP); 

    sandesha2_client_terminate_seq_with_svc_client_and_seq_key(env, svc_client, NULL, NULL);

    AXIS2_SLEEP(6 * SANDESHA2_SLEEP);

    if (svc_client)
    {
        axis2_svc_client_free(svc_client, env);
        svc_client = NULL;
    }
    
    return 0;
}
            /**
             * Add to protocol.
             */
            axis2_status_t AXIS2_CALL
            adb_additionalTransferProtocols_type0_add_protocol(
                    adb_additionalTransferProtocols_type0_t* _additionalTransferProtocols_type0,
                    const axutil_env_t *env,
                    const axis2_char_t* arg_protocol)
             {
                

                AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
                AXIS2_PARAM_CHECK(env->error, _additionalTransferProtocols_type0, AXIS2_FAILURE);

                
                    if(NULL == arg_protocol)
                    {
                      
                           AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "All the elements in the array of protocol is being set to NULL, but it is not a nullable or minOccurs=0 element");
                           return AXIS2_FAILURE;
                        
                    }
                  

                if(_additionalTransferProtocols_type0->property_protocol == NULL)
                {
                    _additionalTransferProtocols_type0->property_protocol = axutil_array_list_create(env, 10);
                }
                if(_additionalTransferProtocols_type0->property_protocol == NULL)
                {
                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed in allocatting memory for protocol");
                    return AXIS2_FAILURE;
                    
                }
                
                   axutil_array_list_add(_additionalTransferProtocols_type0->property_protocol , env, axutil_strdup(env, arg_protocol));
                  _additionalTransferProtocols_type0->is_valid_protocol = AXIS2_TRUE;
                return AXIS2_SUCCESS;
             }
        axiom_node_t* AXIS2_CALL
        adb_choice_type0_serialize_obj(
                adb_choice_type0_t* _choice_type0,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
               axiom_attribute_t *text_attri = NULL;
             
             axis2_char_t *string_to_stream;
            
         
         axiom_node_t* current_node = NULL;
         int tag_closed = 0;
         axis2_char_t* xsi_prefix = NULL;
         axiom_namespace_t* xsi_ns = NULL;
         axiom_attribute_t* xsi_type_attri = NULL;
         
         axis2_char_t* type_attrib = NULL;
         
                axiom_namespace_t *ns1 = NULL;

                axis2_char_t *qname_uri = NULL;
                axis2_char_t *qname_prefix = NULL;
                axis2_char_t *p_prefix = NULL;
                axis2_bool_t ns_already_defined;
            
                    axis2_char_t text_value_1[ADB_DEFAULT_DIGIT_LIMIT];
                    
                    axis2_char_t *text_value_2;
                    axis2_char_t *text_value_2_temp;
                    
                axis2_char_t *text_value = NULL;
             
               axis2_char_t *start_input_str = NULL;
               axis2_char_t *end_input_str = NULL;
               unsigned int start_input_str_len = 0;
               unsigned int end_input_str_len = 0;
            
            
               axiom_data_source_t *data_source = NULL;
               axutil_stream_t *stream = NULL;

            

            AXIS2_ENV_CHECK(env, NULL);
            AXIS2_PARAM_CHECK(env->error, _choice_type0, NULL);
            
            
                    current_node = parent;
                    data_source = (axiom_data_source_t *)axiom_node_get_data_element(current_node, env);
                    if (!data_source)
                        return NULL;
                    stream = axiom_data_source_get_stream(data_source, env); /* assume parent is of type data source */
                    if (!stream)
                        return NULL;
                  
            if(!parent_tag_closed)
            {
            
                if(_choice_type0->is_valid_id)
                {
                
                        p_prefix = NULL;
                      
                           text_value = (axis2_char_t*) AXIS2_MALLOC (env-> allocator, sizeof (axis2_char_t) * 
                                                            (5  + ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT +
                                                             axutil_strlen(_choice_type0->property_id) + 
                                                                axutil_strlen("id")));
                           sprintf(text_value, " %s%s%s=\"%s\"", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":"",
                                                "id", _choice_type0->property_id);
                           axutil_stream_write(stream, env, text_value, axutil_strlen(text_value));
                           AXIS2_FREE(env-> allocator, text_value);
                        
                   }
                   
                   else
                   {
                      AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-optional attribute id");
                      return NULL;
                   }
                   
              
 
              if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING)))
              {
                  /* it is better to stick with the standard prefix */
                  xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi");
                  
                  axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix);

                  if(parent_element)
                  {
                        axiom_namespace_t *element_ns = NULL;
                        element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance",
                                                            xsi_prefix);
                        axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns);
                        if(element_ns)
                        {
                            axiom_namespace_free(element_ns, env);
                        }
                  }
              }
              type_attrib = axutil_strcat(env, " ", xsi_prefix, ":type=\"choice_type0\"", NULL);
              axutil_stream_write(stream, env, type_attrib, axutil_strlen(type_attrib));

              AXIS2_FREE(env->allocator, type_attrib);
                
              string_to_stream = ">"; 
              axutil_stream_write(stream, env, string_to_stream, axutil_strlen(string_to_stream));
              tag_closed = 1;
            
            }
            else {
              /* if the parent tag closed we would be able to declare the type directly on the parent element */ 
              if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING)))
              {
                  /* it is better to stick with the standard prefix */
                  xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi");
                  
                  axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix);

                  if(parent_element)
                  {
                        axiom_namespace_t *element_ns = NULL;
                        element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance",
                                                            xsi_prefix);
                        axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns);
                        if(element_ns)
                        {
                            axiom_namespace_free(element_ns, env);
                        }
                  }
              }
            }
            xsi_ns = axiom_namespace_create (env,
                                 "http://www.daisy.org/ns/daisy-online/",
                                 xsi_prefix);
            xsi_type_attri = axiom_attribute_create (env, "type", "choice_type0", xsi_ns);
            
            axiom_element_add_attribute (parent_element, env, xsi_type_attri, parent);
        
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.daisy.org/ns/daisy-online/", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://www.daisy.org/ns/daisy-online/", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://www.daisy.org/ns/daisy-online/",
                                            p_prefix));
                       }
                      

                   if (!_choice_type0->is_valid_label)
                   {
                      
                            
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-nillable property label");
                            return NULL;
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("label"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("label")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     
                     /*
                      * parsing label element
                      */

                    
                    
                            sprintf(start_input_str, "<%s%slabel",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); 
                            
                        start_input_str_len = axutil_strlen(start_input_str);
                        sprintf(end_input_str, "</%s%slabel>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                        end_input_str_len = axutil_strlen(end_input_str);
                     
                            if(!adb_label_type0_is_particle())
                            {
                                axutil_stream_write(stream, env, start_input_str, start_input_str_len);
                            }
                            adb_label_type0_serialize(_choice_type0->property_label, 
                                                                                 env, current_node, parent_element,
                                                                                 adb_label_type0_is_particle() || AXIS2_FALSE, namespaces, next_ns_index);
                            
                            if(!adb_label_type0_is_particle())
                            {
                                axutil_stream_write(stream, env, end_input_str, end_input_str_len);
                            }
                            
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 
                    
                    if(parent_tag_closed)
                    {
                       if(_choice_type0->is_valid_id)
                       {
                       
                           p_prefix = NULL;
                           ns1 = NULL;
                         
                           text_value = _choice_type0->property_id;
                           text_attri = axiom_attribute_create (env, "id", text_value, ns1);
                           axiom_element_add_attribute (parent_element, env, text_attri, parent);
                        
                      }
                      
                      else
                      {
                         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-optional attribute id");
                         return NULL;
                      }
                       
                  }
                

            return parent;
        }
Exemplo n.º 19
0
        axiom_node_t* AXIS2_CALL
        adb_item_serialize_obj(
                adb_item_t* _item,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
         
         axiom_node_t* current_node = NULL;
         int tag_closed = 0;
         axis2_char_t* xsi_prefix = NULL;
         axiom_namespace_t* xsi_ns = NULL;
         axiom_attribute_t* xsi_type_attri = NULL;
         
                axiom_namespace_t *ns1 = NULL;

                axis2_char_t *qname_uri = NULL;
                axis2_char_t *qname_prefix = NULL;
                axis2_char_t *p_prefix = NULL;
                axis2_bool_t ns_already_defined;
            
                    axis2_char_t *text_value_1;
                    axis2_char_t *text_value_1_temp;
                    
               axis2_char_t *start_input_str = NULL;
               axis2_char_t *end_input_str = NULL;
               unsigned int start_input_str_len = 0;
               unsigned int end_input_str_len = 0;
            
            
               axiom_data_source_t *data_source = NULL;
               axutil_stream_t *stream = NULL;

             
                int next_ns_index_value = 0;
            

            AXIS2_ENV_CHECK(env, NULL);
            AXIS2_PARAM_CHECK(env->error, _item, NULL);
            
             
                    namespaces = axutil_hash_make(env);
                    next_ns_index = &next_ns_index_value;
                     
                           ns1 = axiom_namespace_create (env,
                                             "http://www.daisy.org/ns/daisy-online/",
                                             "n"); 
                           axutil_hash_set(namespaces, "http://www.daisy.org/ns/daisy-online/", AXIS2_HASH_KEY_STRING, axutil_strdup(env, "n"));
                       
                     
                    parent_element = axiom_element_create (env, NULL, "item", ns1 , &parent);
                    
                    
                    axiom_element_set_namespace(parent_element, env, ns1, parent);


            
                    data_source = axiom_data_source_create(env, parent, &current_node);
                    stream = axiom_data_source_get_stream(data_source, env);
                  
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.daisy.org/ns/daisy-online/", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://www.daisy.org/ns/daisy-online/", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://www.daisy.org/ns/daisy-online/",
                                            p_prefix));
                       }
                      

                   if (!_item->is_valid_item)
                   {
                      
                            
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-nillable property item");
                            return NULL;
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("item"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("item")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     
                     /*
                      * parsing item element
                      */

                    
                    
                            sprintf(start_input_str, "<%s%sitem>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                            
                        start_input_str_len = axutil_strlen(start_input_str);
                        sprintf(end_input_str, "</%s%sitem>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                        end_input_str_len = axutil_strlen(end_input_str);
                    
                           text_value_1 = _item->property_item;
                           
                            
                           text_value_1_temp = axutil_xml_quote_string(env, text_value_1, AXIS2_TRUE);
                           if (text_value_1_temp)
                           {
                               axutil_stream_write(stream, env, text_value_1_temp, axutil_strlen(text_value_1_temp));
                               AXIS2_FREE(env->allocator, text_value_1_temp);
                           }
                           else
                           {
                               axutil_stream_write(stream, env, text_value_1, axutil_strlen(text_value_1));
                           }
                           
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 
                   if(namespaces)
                   {
                       axutil_hash_index_t *hi;
                       void *val;
                       for (hi = axutil_hash_first(namespaces, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, NULL, NULL, &val);
                           AXIS2_FREE(env->allocator, val);
                       }
                       axutil_hash_free(namespaces, env);
                   }
                

            return parent;
        }
Exemplo n.º 20
0
AXIS2_EXTERN const axis2_char_t *AXIS2_CALL
axiom_mime_part_get_content_type_for_mime(
    const axutil_env_t *env,
    axis2_char_t *boundary,
    axis2_char_t *content_id,
    axis2_char_t *char_set_encoding,
    const axis2_char_t *soap_content_type)
{
    axis2_char_t *content_type_string = NULL;
    axis2_char_t *temp_content_type_string = NULL;

    content_type_string = axutil_strdup(env, AXIOM_MIME_TYPE_MULTIPART_RELATED);
    if(!content_type_string)
    {
        AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "Creation of Content-Type string failed");
        return NULL;
    }
    temp_content_type_string = axutil_stracat(env, content_type_string, "; ");
    AXIS2_FREE(env->allocator, content_type_string);
    content_type_string = temp_content_type_string;
    if(boundary)
    {
        temp_content_type_string =
        axutil_stracat(env, content_type_string,
            AXIOM_MIME_HEADER_FIELD_BOUNDARY "=");
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
        temp_content_type_string = axutil_stracat(env, content_type_string, boundary);
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
        temp_content_type_string = axutil_stracat(env, content_type_string, "; ");
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
    } temp_content_type_string =
    axutil_stracat(env, content_type_string,
        AXIOM_MIME_HEADER_FIELD_TYPE "=\"" AXIOM_MIME_TYPE_XOP_XML "\"");
    AXIS2_FREE(env->allocator, content_type_string);
    content_type_string = temp_content_type_string;
    temp_content_type_string = axutil_stracat(env, content_type_string, "; ");
    AXIS2_FREE(env->allocator, content_type_string);
    content_type_string = temp_content_type_string;
    if(content_id)
    {
        temp_content_type_string =
        axutil_stracat(env, content_type_string,
            AXIOM_MIME_HEADER_FIELD_START "=\"<");
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
        temp_content_type_string = axutil_stracat(env, content_type_string, content_id);
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
        temp_content_type_string = axutil_stracat(env, content_type_string, ">\"");
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
        temp_content_type_string = axutil_stracat(env, content_type_string, "; ");
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
    }
    if(soap_content_type)
    {
        temp_content_type_string =
        axutil_stracat(env, content_type_string,
            AXIOM_MIME_HEADER_FIELD_START_INFO "=\"");
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
        temp_content_type_string = axutil_stracat(env, content_type_string, soap_content_type);
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
        temp_content_type_string = axutil_stracat(env, content_type_string, "\"; ");
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
    }
    if(char_set_encoding)
    {
        temp_content_type_string =
        axutil_stracat(env, content_type_string,
            AXIOM_MIME_HEADER_FIELD_CHARSET "=\"");
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
        temp_content_type_string = axutil_stracat(env, content_type_string, char_set_encoding);
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
        temp_content_type_string = axutil_stracat(env, content_type_string, "\"");
        AXIS2_FREE(env->allocator, content_type_string);
        content_type_string = temp_content_type_string;
    }

    return content_type_string;
}
        axiom_node_t* AXIS2_CALL
        prf_internalServerErrorFault_serialize_obj(
                prf_internalServerErrorFault_t* _internalServerErrorFault,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
         
         axiom_node_t* current_node = NULL;
         int tag_closed = 0;
         axis2_char_t* xsi_prefix = NULL;
         axiom_namespace_t* xsi_ns = NULL;
         axiom_attribute_t* xsi_type_attri = NULL;
         
                axiom_namespace_t *ns1 = NULL;

                axis2_char_t *qname_uri = NULL;
                axis2_char_t *qname_prefix = NULL;
                axis2_char_t *p_prefix = NULL;
                axis2_bool_t ns_already_defined;
            
                    axis2_char_t text_value_1[PRF_DEFAULT_DIGIT_LIMIT];
                    
               axis2_char_t *start_input_str = NULL;
               axis2_char_t *end_input_str = NULL;
               unsigned int start_input_str_len = 0;
               unsigned int end_input_str_len = 0;
            
            
               axiom_data_source_t *data_source = NULL;
               axutil_stream_t *stream = NULL;

             
                int next_ns_index_value = 0;
            

            AXIS2_ENV_CHECK(env, NULL);
            AXIS2_PARAM_CHECK(env->error, _internalServerErrorFault, NULL);
            
             
                    namespaces = axutil_hash_make(env);
                    next_ns_index = &next_ns_index_value;
                     
                           ns1 = axiom_namespace_create (env,
                                             "http://www.pratsam.org/ns/profile/",
                                             "n"); 
                           axutil_hash_set(namespaces, "http://www.pratsam.org/ns/profile/", AXIS2_HASH_KEY_STRING, axutil_strdup(env, "n"));
                       
                     
                    parent_element = axiom_element_create (env, NULL, "internalServerErrorFault", ns1 , &parent);
                    
                    
                    axiom_element_set_namespace(parent_element, env, ns1, parent);


            
                    data_source = axiom_data_source_create(env, parent, &current_node);
                    stream = axiom_data_source_get_stream(data_source, env);
                  
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.pratsam.org/ns/profile/", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * PRF_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://www.pratsam.org/ns/profile/", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://www.pratsam.org/ns/profile/",
                                            p_prefix));
                       }
                      

                   if (!_internalServerErrorFault->is_valid_internalServerErrorFault)
                   {
                      
                            
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-nillable property internalServerErrorFault");
                            return NULL;
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("internalServerErrorFault"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("internalServerErrorFault")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     
                     /*
                      * parsing internalServerErrorFault element
                      */

                    
                    
                            sprintf(start_input_str, "<%s%sinternalServerErrorFault",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); 
                            
                        start_input_str_len = axutil_strlen(start_input_str);
                        sprintf(end_input_str, "</%s%sinternalServerErrorFault>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                        end_input_str_len = axutil_strlen(end_input_str);
                    prf_internalServerErrorFaultType_serialize(_internalServerErrorFault->property_internalServerErrorFault, 
                                                                                 env, current_node, parent_element,
                                                                                 prf_internalServerErrorFaultType_is_particle() || AXIS2_TRUE, namespaces, next_ns_index);
                            
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 
                   if(namespaces)
                   {
                       axutil_hash_index_t *hi;
                       void *val;
                       for (hi = axutil_hash_first(namespaces, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, NULL, NULL, &val);
                           AXIS2_FREE(env->allocator, val);
                       }
                       axutil_hash_free(namespaces, env);
                   }
                

            return parent;
        }
Exemplo n.º 22
0
AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL
axiom_mime_part_create_part_list(
    const axutil_env_t *env,
    axis2_char_t *soap_body,
    axutil_array_list_t *binary_node_list,
    axis2_char_t *boundary,
    axis2_char_t *content_id,
    axis2_char_t *char_set_encoding,
    const axis2_char_t *soap_content_type)
{
    axis2_status_t status = AXIS2_FAILURE;
    axis2_char_t *header_value = NULL;
    axis2_char_t *temp_header_value = NULL;
    axis2_char_t *content_id_string = NULL;
    axis2_char_t *temp_content_id_string = NULL;
    axiom_mime_body_part_t *root_mime_body_part = NULL;
    axis2_char_t *soap_body_buffer = NULL;
    axutil_array_list_t *part_list = NULL;
    axiom_mime_part_t *soap_part = NULL;

    part_list = axutil_array_list_create(env, 0);

    if(!part_list)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create part list array");
        return NULL;
    }

    /* This mime_body part just keeps the mime_headers of the 
     * SOAP part. Since it is not created from an axiom_text
     * this will not contain an attachment*/

    root_mime_body_part = axiom_mime_body_part_create(env);

    if(!root_mime_body_part)
    {
        return NULL;
    }

    /* In order to understand the following code which creates 
     * mime_headers go through the code with a sample mtom message */

    /* Adding Content-Type Header */
    header_value = axutil_strdup(env, AXIOM_MIME_TYPE_XOP_XML
        ";" AXIOM_MIME_HEADER_FIELD_CHARSET "=");
    temp_header_value = axutil_stracat(env, header_value, char_set_encoding);
    AXIS2_FREE(env->allocator, header_value);
    header_value = temp_header_value;
    temp_header_value = axutil_stracat(env, header_value, ";"
        AXIOM_MIME_HEADER_FIELD_TYPE "=\"");
    AXIS2_FREE(env->allocator, header_value);
    header_value = temp_header_value;
    temp_header_value = axutil_stracat(env, header_value, soap_content_type);
    AXIS2_FREE(env->allocator, header_value);
    header_value = temp_header_value;
    temp_header_value = axutil_stracat(env, header_value, "\";");
    AXIS2_FREE(env->allocator, header_value);
    header_value = temp_header_value;
    axiom_mime_body_part_add_header(root_mime_body_part, env, AXIOM_MIME_HEADER_CONTENT_TYPE,
        header_value);

    /* Adding Content Transfer Encoding header */

    axiom_mime_body_part_add_header(root_mime_body_part, env,
        AXIOM_MIME_HEADER_CONTENT_TRANSFER_ENCODING, axutil_strdup(env,
            AXIOM_MIME_CONTENT_TRANSFER_ENCODING_BINARY));

    /* Adding Content ID header */

    content_id_string = (axis2_char_t *)"<";
    content_id_string = axutil_stracat(env, content_id_string, content_id);
    temp_content_id_string = axutil_stracat(env, content_id_string, ">");
    AXIS2_FREE(env->allocator, content_id_string);
    content_id_string = temp_content_id_string;
    axiom_mime_body_part_add_header(root_mime_body_part, env, AXIOM_MIME_HEADER_CONTENT_ID,
        content_id_string);

    /* Now first insert the headers needed for SOAP */

    /* After calling this method we have mime_headers of the SOAP envelope
     * as a mime_part in the array_list */

    status = axiom_mime_part_write_body_part_to_list(env, part_list, root_mime_body_part, boundary);

    if(status == AXIS2_FAILURE)
    {
        return NULL;
    }

    /* Now add the SOAP body */

    axiom_mime_body_part_free(root_mime_body_part, env);
    root_mime_body_part = NULL;

    soap_part = axiom_mime_part_create(env);

    if(!soap_part)
    {
        return NULL;
    }

    /* The atachment's mime_boundary will start after a new line charator */

    soap_body_buffer = axutil_stracat(env, soap_body, AXIS2_CRLF);

    soap_part->part = (axis2_byte_t *)soap_body_buffer;
    soap_part->part_size = (int)axutil_strlen(soap_body_buffer);
    soap_part->type = AXIOM_MIME_PART_BUFFER;

    axutil_array_list_add(part_list, env, soap_part);

    /* Now we need to add each binary attachment to the array_list */

    if(binary_node_list)
    {
        int j = 0;
        for(j = 0; j < axutil_array_list_size(binary_node_list, env); j++)
        {
            /* Getting each attachment text node from the node list */

            axiom_text_t *text = (axiom_text_t *)axutil_array_list_get(binary_node_list, env, j);
            if(text)
            {
                axiom_mime_body_part_t *mime_body_part = NULL;
                mime_body_part = axiom_mime_body_part_create_from_om_text(env, text);

                /* Let's fill the mime_part arraylist with attachment data*/
                if(!mime_body_part)
                {
                    return NULL;
                }

                /* This call will create mime_headers for the attachment and put 
                 * them to the array_list. Then put the attachment file_name to the 
                 * list */

                status = axiom_mime_part_write_body_part_to_list(env, part_list, mime_body_part,
                    boundary);

                if(status == AXIS2_FAILURE)
                {
                    return NULL;
                }

                axiom_mime_body_part_free(mime_body_part, env);
                mime_body_part = NULL;
            }
        }
    }

    /* Now we have the SOAP message, all the attachments and headers are added to the  list.
     * So let's add the final mime_boundary with -- at the end */

    status = axiom_mime_part_finish_adding_parts(env, part_list, boundary);
    if(status == AXIS2_FAILURE)
    {
        return NULL;
    }
    return part_list;
}
        axiom_node_t* AXIS2_CALL
        adb_lang_type0_serialize_obj(
                adb_lang_type0_t* _lang_type0,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
         
         axiom_node_t* current_node = NULL;
         int tag_closed = 0;
         axis2_char_t* xsi_prefix = NULL;
         axiom_namespace_t* xsi_ns = NULL;
         axiom_attribute_t* xsi_type_attri = NULL;
         
            axiom_data_source_t *data_source = NULL;
            axutil_stream_t *stream = NULL;
            axis2_char_t *text_value;
             
                    current_node = parent;
                    data_source = (axiom_data_source_t *)axiom_node_get_data_element(current_node, env);
                    if (!data_source)
                        return NULL;
                    stream = axiom_data_source_get_stream(data_source, env); /* assume parent is of type data source */
                    if (!stream)
                        return NULL;
                  
            /* here we need to declare the union type in the xsi:type field */
            
            if(axutil_strcmp(_lang_type0->current_value, ""))
            {

                if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING)))
                {
                    /* it is better to stick with the standard prefix */
                    xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi");
                    
                    axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix);

                    if(parent_element)
                    {
                          axiom_namespace_t *element_ns = NULL;
                          element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance",
                                                              xsi_prefix);
                          axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns);
                    }
                }

                

                    if(!axutil_strcmp(_lang_type0->current_value, "language"))
                    {
                        axis2_char_t *ns_prefix = NULL;

                        if(!(ns_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema", AXIS2_HASH_KEY_STRING)))
                        {
                            ns_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                            
                            sprintf(ns_prefix, "q%d", (*next_ns_index)++); 
                            axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema", AXIS2_HASH_KEY_STRING, ns_prefix);

                            if(parent_element)
                            {
                                  axiom_namespace_t *element_ns = NULL;
                                  element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema",
                                                                      ns_prefix);
                                  axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns);
                            }
                        }

                        /* now we will set the xsi:type="ns:type" value */

                       if(!parent_tag_closed && !tag_closed)
                       {
                            text_value = axutil_strcat(env, xsi_prefix, ":type=", ns_prefix, ":", _lang_type0->current_value, NULL);
                            axutil_stream_write(stream, env, text_value, axutil_strlen(text_value));

                            AXIS2_FREE(env->allocator, text_value);
                        }
                        else 
                        {
                            /* otherwise set it to the prarent itself */

                             axiom_namespace_t *ns1 = NULL;
                             axiom_attribute_t *attrib = NULL;
                        
                             ns1 = axiom_namespace_create (env,
                                                         "http://www.w3.org/2001/XMLSchema-instance",
                                                         xsi_prefix);
                        
                             text_value = axutil_strcat(env, ns_prefix, ":", _lang_type0->current_value, NULL);
                             attrib = axiom_attribute_create (env, "type", text_value, ns1);
                             axiom_element_add_attribute (parent_element, env, attrib, parent);
                            
                             AXIS2_FREE(env->allocator, text_value);
                        }
                    }
                
            }
            
               if(!parent_tag_closed && !tag_closed)
               {
                  text_value = ">"; 
                  axutil_stream_write(stream, env, text_value, axutil_strlen(text_value));
               }
               
               text_value = adb_lang_type0_serialize_to_string(_lang_type0, env, namespaces);
               if(text_value)
               {
                    axutil_stream_write(stream, env, text_value, axutil_strlen(text_value));
                    AXIS2_FREE(env->allocator, text_value);
               }
            

            return parent;
        }
        axiom_node_t* AXIS2_CALL
        adb_additionalTransferProtocols_type0_serialize_obj(
                adb_additionalTransferProtocols_type0_t* _additionalTransferProtocols_type0,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
             axis2_char_t *string_to_stream;
            
         
         axiom_node_t* current_node = NULL;
         int tag_closed = 0;
         axis2_char_t* xsi_prefix = NULL;
         axiom_namespace_t* xsi_ns = NULL;
         axiom_attribute_t* xsi_type_attri = NULL;
         
         axis2_char_t* type_attrib = NULL;
         
                axiom_namespace_t *ns1 = NULL;

                axis2_char_t *qname_uri = NULL;
                axis2_char_t *qname_prefix = NULL;
                axis2_char_t *p_prefix = NULL;
                axis2_bool_t ns_already_defined;
            
               int i = 0;
               int count = 0;
               void *element = NULL;
             
                    axis2_char_t *text_value_1;
                    axis2_char_t *text_value_1_temp;
                    
               axis2_char_t *start_input_str = NULL;
               axis2_char_t *end_input_str = NULL;
               unsigned int start_input_str_len = 0;
               unsigned int end_input_str_len = 0;
            
            
               axiom_data_source_t *data_source = NULL;
               axutil_stream_t *stream = NULL;

            

            AXIS2_ENV_CHECK(env, NULL);
            AXIS2_PARAM_CHECK(env->error, _additionalTransferProtocols_type0, NULL);
            
            
                    current_node = parent;
                    data_source = (axiom_data_source_t *)axiom_node_get_data_element(current_node, env);
                    if (!data_source)
                        return NULL;
                    stream = axiom_data_source_get_stream(data_source, env); /* assume parent is of type data source */
                    if (!stream)
                        return NULL;
                  
            if(!parent_tag_closed)
            {
            
              
 
              if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING)))
              {
                  /* it is better to stick with the standard prefix */
                  xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi");
                  
                  axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix);

                  if(parent_element)
                  {
                        axiom_namespace_t *element_ns = NULL;
                        element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance",
                                                            xsi_prefix);
                        axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns);
                        if(element_ns)
                        {
                            axiom_namespace_free(element_ns, env);
                        }
                  }
              }
              type_attrib = axutil_strcat(env, " ", xsi_prefix, ":type=\"additionalTransferProtocols_type0\"", NULL);
              axutil_stream_write(stream, env, type_attrib, axutil_strlen(type_attrib));

              AXIS2_FREE(env->allocator, type_attrib);
                
              string_to_stream = ">"; 
              axutil_stream_write(stream, env, string_to_stream, axutil_strlen(string_to_stream));
              tag_closed = 1;
            
            }
            else {
              /* if the parent tag closed we would be able to declare the type directly on the parent element */ 
              if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING)))
              {
                  /* it is better to stick with the standard prefix */
                  xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi");
                  
                  axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix);

                  if(parent_element)
                  {
                        axiom_namespace_t *element_ns = NULL;
                        element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance",
                                                            xsi_prefix);
                        axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns);
                        if(element_ns)
                        {
                            axiom_namespace_free(element_ns, env);
                        }
                  }
              }
            }
            xsi_ns = axiom_namespace_create (env,
                                 "http://www.daisy.org/ns/daisy-online/",
                                 xsi_prefix);
            xsi_type_attri = axiom_attribute_create (env, "type", "additionalTransferProtocols_type0", xsi_ns);
            
            axiom_element_add_attribute (parent_element, env, xsi_type_attri, parent);
        
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.daisy.org/ns/daisy-online/", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://www.daisy.org/ns/daisy-online/", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://www.daisy.org/ns/daisy-online/",
                                            p_prefix));
                       }
                      

                   if (!_additionalTransferProtocols_type0->is_valid_protocol)
                   {
                      
                            
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-nillable property protocol");
                            return NULL;
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("protocol"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("protocol")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     /*
                      * Parsing protocol array
                      */
                     if (_additionalTransferProtocols_type0->property_protocol != NULL)
                     {
                        
                            sprintf(start_input_str, "<%s%sprotocol>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); 
                            
                         start_input_str_len = axutil_strlen(start_input_str);

                         sprintf(end_input_str, "</%s%sprotocol>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                         end_input_str_len = axutil_strlen(end_input_str);

                         count = axutil_array_list_size(_additionalTransferProtocols_type0->property_protocol, env);
                         for(i = 0; i < count; i ++)
                         {
                            element = axutil_array_list_get(_additionalTransferProtocols_type0->property_protocol, env, i);

                            if(NULL == element) 
                            {
                                continue;
                            }
                    
                     
                     /*
                      * parsing protocol element
                      */

                    
                    
                           text_value_1 = (axis2_char_t*)element;
                           
                           axutil_stream_write(stream, env, start_input_str, start_input_str_len);
                           
                            
                           text_value_1_temp = axutil_xml_quote_string(env, text_value_1, AXIS2_TRUE);
                           if (text_value_1_temp)
                           {
                               axutil_stream_write(stream, env, text_value_1_temp, axutil_strlen(text_value_1_temp));
                               AXIS2_FREE(env->allocator, text_value_1_temp);
                           }
                           else
                           {
                               axutil_stream_write(stream, env, text_value_1, axutil_strlen(text_value_1));
                           }
                           
                           axutil_stream_write(stream, env, end_input_str, end_input_str_len);
                           
                         }
                     }
                   
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 

            return parent;
        }
Exemplo n.º 25
0
/**
 * Create a new create_seq_msg
 * @param env
 * @param application_rm_msg
 * @param internal_seq_id
 * @param acks_to
 * @param seq_prop_mgr
 * @return sandesha2_msg_ctx_t
 */
sandesha2_msg_ctx_t *AXIS2_CALL
sandesha2_msg_creator_create_create_seq_msg(
    const axutil_env_t *env,
    sandesha2_msg_ctx_t *application_rm_msg, 
    axis2_char_t *internal_seq_id,
    axis2_char_t *acks_to,
    sandesha2_seq_property_mgr_t *seq_prop_mgr)
{
    axis2_msg_ctx_t *application_msg_ctx = NULL;
    axis2_msg_ctx_t *create_seq_msg_ctx = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_op_t *app_msg_op_desc = NULL;
    axis2_op_ctx_t *op_ctx = NULL;
    axis2_char_t *create_seq_msg_id = NULL;
    axis2_char_t *rm_version = NULL;
    axis2_char_t *rm_ns_value = NULL;
    axis2_char_t *addressing_ns_value = NULL;
    axis2_char_t *anonymous_uri = NULL;
    axis2_char_t *temp_value = NULL;
    axis2_char_t *temp_action = NULL;
    axutil_string_t *temp_soap_action = NULL;
    axis2_endpoint_ref_t *to_epr = NULL;
    axis2_endpoint_ref_t *temp_to = NULL;
    axis2_endpoint_ref_t *acks_to_epr = NULL;
    axis2_endpoint_ref_t *temp_reply_to = NULL;
    sandesha2_create_seq_t *create_seq_part = NULL;
    sandesha2_seq_property_bean_t *reply_to_bean = NULL;
    sandesha2_seq_property_bean_t *to_bean = NULL;
    sandesha2_msg_ctx_t *create_seq_rm_msg = NULL;
    sandesha2_address_t *temp_address = NULL;
    sandesha2_acks_to_t *temp_acks_to = NULL;
    axutil_property_t *property = NULL;
    const axis2_char_t *reply_to_address = NULL;

    application_msg_ctx = sandesha2_msg_ctx_get_msg_ctx(application_rm_msg, env);
    if(!application_msg_ctx)
    {
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_APPLICATION_MSG_NULL, AXIS2_FAILURE);
        return NULL;
    }

    conf_ctx = axis2_msg_ctx_get_conf_ctx(application_msg_ctx, env);
    if(!conf_ctx)
    {
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_CONF_CTX_NULL, AXIS2_FAILURE);
        return NULL;
    }

    /* Creating by copying common contents.
     */
    create_seq_msg_ctx = sandesha2_utils_create_new_related_msg_ctx(env, application_rm_msg);

    sandesha2_msg_creator_init_creation(env, application_msg_ctx, create_seq_msg_ctx);

    create_seq_msg_id = axutil_uuid_gen(env);
    axis2_msg_ctx_set_message_id(create_seq_msg_ctx, env, create_seq_msg_id);
    AXIS2_FREE(env->allocator, create_seq_msg_id);

    app_msg_op_desc = axis2_msg_ctx_get_op(application_msg_ctx, env);

    property = axis2_msg_ctx_get_property(application_msg_ctx, env, AXIS2_TARGET_EPR);
    if(property)
    {
        temp_to = axutil_property_get_value(property, env);
        to_epr = axis2_endpoint_ref_create(env, axis2_endpoint_ref_get_address(temp_to, env));
    }

    if (!to_epr)
    {
        temp_to = sandesha2_msg_ctx_get_to(application_rm_msg, env); 
        if (temp_to)
        {
            to_epr = axis2_endpoint_ref_create(env, axis2_endpoint_ref_get_address(temp_to, env));
        }
    }

    if (to_epr)
    {
        axis2_msg_ctx_set_to(create_seq_msg_ctx, env, to_epr);
        to_epr = NULL;
    }
    
    temp_reply_to = sandesha2_msg_ctx_get_reply_to(application_rm_msg, env); 
    if(temp_reply_to)
    {
        axis2_endpoint_ref_t *reply_to_epr = NULL;

        reply_to_address = axis2_endpoint_ref_get_address(temp_reply_to, env);
        reply_to_epr = axis2_endpoint_ref_create(env, reply_to_address);
        if(reply_to_epr)
        {
            axis2_msg_ctx_set_reply_to(create_seq_msg_ctx, env, reply_to_epr);
        }
    }

    create_seq_rm_msg = sandesha2_msg_ctx_create(env, create_seq_msg_ctx);

        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "create_seq_internal_seq_id:%s", internal_seq_id);
    rm_version = sandesha2_utils_get_rm_version(env, application_msg_ctx);

    if(!rm_version)
    {
        AXIS2_ERROR_SET(env->error, 
                SANDESHA2_ERROR_CANNOT_FIND_RM_VERSION_OF_GIVEN_MSG, AXIS2_FAILURE);
        return NULL;
    }

    rm_ns_value = sandesha2_spec_specific_consts_get_rm_ns_val(env, rm_version);

    addressing_ns_value = sandesha2_utils_get_seq_property(env, internal_seq_id, 
        SANDESHA2_SEQ_PROP_ADDRESSING_NAMESPACE_VALUE, seq_prop_mgr);

    create_seq_part = sandesha2_create_seq_create(env, addressing_ns_value, rm_ns_value);
    if(!create_seq_part)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] creating create sequence message failed");
        return NULL;
    }

    /* Adding sequence offer if present */
    op_ctx = axis2_msg_ctx_get_op_ctx(application_msg_ctx, env);
    if(op_ctx)
    {
        axis2_op_t *operation = NULL;
        int mep = -1;
        axis2_char_t *offered_seq_id = NULL;
        /*axutil_property_t *property = NULL;
        axis2_ctx_t *ctx = NULL;

        ctx = axis2_msg_ctx_get_base(application_msg_ctx, env);
        property = axis2_ctx_get_property(ctx, env, SANDESHA2_CLIENT_OFFERED_SEQ_ID);
        if(property)
        {
            offered_seq_id = axutil_property_get_value(property, env);
        }*/
        operation = axis2_op_ctx_get_op(op_ctx, env);
        mep = axis2_op_get_axis_specific_mep_const(operation, env);
        if(mep == AXIS2_MEP_CONSTANT_OUT_IN)
        {
            offered_seq_id = axutil_uuid_gen(env);
        }

        /*if(offered_seq_id && 0 != axutil_strcmp("", offered_seq_id))*/
        if(offered_seq_id)
        {
            sandesha2_seq_offer_t *offer_part = NULL;
            sandesha2_identifier_t *identifier = NULL;
            sandesha2_endpoint_t *endpoint = NULL;

            offer_part = sandesha2_seq_offer_create(env, rm_ns_value, addressing_ns_value);
            identifier = sandesha2_identifier_create(env, rm_ns_value);
            sandesha2_identifier_set_identifier(identifier, env, offered_seq_id);
            sandesha2_seq_offer_set_identifier(offer_part, env, identifier);

            if(!axutil_strcmp(SANDESHA2_SPEC_VERSION_1_1, rm_version))
            {
                axis2_endpoint_ref_t *reply_to_epr = NULL;
                sandesha2_address_t *address = NULL;

                reply_to_epr = axis2_endpoint_ref_create(env, reply_to_address);
                address = sandesha2_address_create(env, addressing_ns_value, reply_to_epr);
                endpoint = sandesha2_endpoint_create(env, address, rm_ns_value, 
                        addressing_ns_value);

                sandesha2_seq_offer_set_endpoint(offer_part, env, endpoint);
            }

            sandesha2_create_seq_set_seq_offer(create_seq_part, env, offer_part);
        }
    }

    reply_to_bean = sandesha2_seq_property_mgr_retrieve(seq_prop_mgr, env, internal_seq_id, 
            SANDESHA2_SEQ_PROP_REPLY_TO_EPR);

    to_bean = sandesha2_seq_property_mgr_retrieve(seq_prop_mgr, env, internal_seq_id, 
            SANDESHA2_SEQ_PROP_TO_EPR);
    if (to_bean)
    {
        temp_value = sandesha2_seq_property_bean_get_value(to_bean, env);
    
        if (temp_value)
        {
            to_epr = axis2_endpoint_ref_create(env, temp_value);
        }

        sandesha2_seq_property_bean_free(to_bean, env);
    }

    anonymous_uri = sandesha2_spec_specific_consts_get_anon_uri(env, addressing_ns_value);
    if(reply_to_bean)
    {
        axis2_endpoint_ref_t *reply_to_epr = NULL;

        temp_value = sandesha2_seq_property_bean_get_value(reply_to_bean, env);
        if(temp_value)
        {
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "dam_reply_to:%s", temp_value);
            reply_to_epr = axis2_endpoint_ref_create(env, temp_value);
            acks_to = axutil_strdup(env, temp_value);
        }

        if(reply_to_epr)
        {
            sandesha2_msg_ctx_set_reply_to(create_seq_rm_msg, env, reply_to_epr);
        }
        
        sandesha2_seq_property_bean_free(reply_to_bean, env);
    }
    
    if(!acks_to || !axutil_strcmp("", acks_to))
    {
        acks_to = axutil_strdup(env, anonymous_uri);
    }

    acks_to_epr = axis2_endpoint_ref_create(env, acks_to);

    temp_to = sandesha2_msg_ctx_get_to(create_seq_rm_msg, env);
    if(!temp_to && to_epr)
    {
        sandesha2_msg_ctx_set_to(create_seq_rm_msg, env, to_epr);
    }
    else
    {
        axis2_endpoint_ref_free(to_epr, env);
    }


    temp_address = sandesha2_address_create(env, addressing_ns_value, acks_to_epr);
    temp_acks_to = sandesha2_acks_to_create(env, temp_address, rm_ns_value, addressing_ns_value);

    if(addressing_ns_value)
    {
        AXIS2_FREE(env->allocator, addressing_ns_value);
    }

    sandesha2_create_seq_set_acks_to(create_seq_part, env,  temp_acks_to);
    sandesha2_msg_ctx_set_create_seq(create_seq_rm_msg, env, create_seq_part);
    sandesha2_msg_ctx_add_soap_envelope(create_seq_rm_msg, env);
    temp_action = sandesha2_spec_specific_consts_get_create_seq_action(env, rm_version);

    sandesha2_msg_ctx_set_wsa_action(create_seq_rm_msg, env, temp_action);

    temp_soap_action = axutil_string_create(env, temp_action);
    if(temp_soap_action)
    {
        sandesha2_msg_ctx_set_soap_action(create_seq_rm_msg, env, temp_soap_action);
        axutil_string_free(temp_soap_action, env);
    }

    /*sandesha2_msg_creator_finalize_creation(env, application_msg_ctx, create_seq_msg_ctx);*/

    return create_seq_rm_msg;
}
        axiom_node_t* AXIS2_CALL
        adb_UserNotRegisteredException1_serialize(
                adb_UserNotRegisteredException1_t* _UserNotRegisteredException1,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
         
         axiom_node_t *current_node = NULL;
         int tag_closed = 0;

         
         
                axiom_namespace_t *ns1 = NULL;

                axis2_char_t *qname_uri = NULL;
                axis2_char_t *qname_prefix = NULL;
                axis2_char_t *p_prefix = NULL;
                axis2_bool_t ns_already_defined;
            
                    axis2_char_t text_value_1[64];
                    
               axis2_char_t *start_input_str = NULL;
               axis2_char_t *end_input_str = NULL;
               unsigned int start_input_str_len = 0;
               unsigned int end_input_str_len = 0;
            
            
               axiom_data_source_t *data_source = NULL;
               axutil_stream_t *stream = NULL;

             
                int next_ns_index_value = 0;
            

            AXIS2_ENV_CHECK(env, NULL);
            AXIS2_PARAM_CHECK(env->error, _UserNotRegisteredException1, NULL);
            
             
                    namespaces = axutil_hash_make(env);
                    next_ns_index = &next_ns_index_value;
                     
                           ns1 = axiom_namespace_create (env,
                                             "http://esb.callbackservice.services.hdviper.psnc.pl/",
                                             "n"); 
                           axutil_hash_set(namespaces, "http://esb.callbackservice.services.hdviper.psnc.pl/", AXIS2_HASH_KEY_STRING, axutil_strdup(env, "n"));
                       
                     
                    parent_element = axiom_element_create (env, NULL, "UserNotRegisteredException", ns1 , &parent);
                    
                    
                    axiom_element_set_namespace(parent_element, env, ns1, parent);


            
                    data_source = axiom_data_source_create(env, parent, &current_node);
                    stream = axiom_data_source_get_stream(data_source, env);
                  
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://esb.callbackservice.services.hdviper.psnc.pl/", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://esb.callbackservice.services.hdviper.psnc.pl/", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://esb.callbackservice.services.hdviper.psnc.pl/",
                                            p_prefix));
                       }
                      

                   if (!_UserNotRegisteredException1->is_valid_UserNotRegisteredException)
                   {
                      
                            
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-nillable property UserNotRegisteredException");
                            return NULL;
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("UserNotRegisteredException"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("UserNotRegisteredException")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     
                     /*
                      * parsing UserNotRegisteredException element
                      */

                    
                    
                            sprintf(start_input_str, "<%s%sUserNotRegisteredException",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); 
                            
                        start_input_str_len = axutil_strlen(start_input_str);
                        sprintf(end_input_str, "</%s%sUserNotRegisteredException>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                        end_input_str_len = axutil_strlen(end_input_str);
                    
                            adb_UserNotRegisteredException_serialize(_UserNotRegisteredException1->property_UserNotRegisteredException, 
                                                                                 env, current_node, parent_element,
                                                                                 adb_UserNotRegisteredException_is_particle() || AXIS2_TRUE, namespaces, next_ns_index);
                            
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 
                   if(namespaces)
                   {
                       axutil_hash_index_t *hi;
                       void *val;
                       for (hi = axutil_hash_first(namespaces, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, NULL, NULL, &val);
                           AXIS2_FREE(env->allocator, val);
                       }
                       axutil_hash_free(namespaces, env);
                   }
                

            return parent;
        }
        axiom_node_t* AXIS2_CALL
        adb_getBindingOperationMessagePolicyResponse_serialize_obj(
                adb_getBindingOperationMessagePolicyResponse_t* _getBindingOperationMessagePolicyResponse,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
         
         axiom_node_t* current_node = NULL;
         int tag_closed = 0;
         
                axiom_namespace_t *ns1 = NULL;

                axis2_char_t *qname_uri = NULL;
                axis2_char_t *qname_prefix = NULL;
                axis2_char_t *p_prefix = NULL;
                axis2_bool_t ns_already_defined;
            
                    axis2_char_t *text_value_1;
                    axis2_char_t *text_value_1_temp;
                    
               axis2_char_t *start_input_str = NULL;
               axis2_char_t *end_input_str = NULL;
               unsigned int start_input_str_len = 0;
               unsigned int end_input_str_len = 0;
            
            
               axiom_data_source_t *data_source = NULL;
               axutil_stream_t *stream = NULL;

             
                int next_ns_index_value = 0;
            

            AXIS2_ENV_CHECK(env, NULL);
            AXIS2_PARAM_CHECK(env->error, _getBindingOperationMessagePolicyResponse, NULL);
            
             
                    namespaces = axutil_hash_make(env);
                    next_ns_index = &next_ns_index_value;
                     
                           ns1 = axiom_namespace_create (env,
                                             "http://org.apache.axis2/xsd",
                                             "n"); 
                           axutil_hash_set(namespaces, "http://org.apache.axis2/xsd", AXIS2_HASH_KEY_STRING, axutil_strdup(env, "n"));
                       
                     
                    parent_element = axiom_element_create (env, NULL, "getBindingOperationMessagePolicyResponse", ns1 , &parent);
                    
                    
                    axiom_element_set_namespace(parent_element, env, ns1, parent);


            
                    data_source = axiom_data_source_create(env, parent, &current_node);
                    stream = axiom_data_source_get_stream(data_source, env);
                  
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://org.apache.axis2/xsd", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://org.apache.axis2/xsd", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://org.apache.axis2/xsd",
                                            p_prefix));
                       }
                      

                   if (!_getBindingOperationMessagePolicyResponse->is_valid_return)
                   {
                      
                           /* no need to complain for minoccurs=0 element */
                            
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("return"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("return")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     
                     /*
                      * parsing return element
                      */

                    
                    
                            sprintf(start_input_str, "<%s%sreturn>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                            
                        start_input_str_len = axutil_strlen(start_input_str);
                        sprintf(end_input_str, "</%s%sreturn>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                        end_input_str_len = axutil_strlen(end_input_str);
                    
                           text_value_1 = _getBindingOperationMessagePolicyResponse->property_return;
                           
                           axutil_stream_write(stream, env, start_input_str, start_input_str_len);
                           
                            
                           text_value_1_temp = axutil_xml_quote_string(env, text_value_1, AXIS2_TRUE);
                           if (text_value_1_temp)
                           {
                               axutil_stream_write(stream, env, text_value_1_temp, axutil_strlen(text_value_1_temp));
                               AXIS2_FREE(env->allocator, text_value_1_temp);
                           }
                           else
                           {
                               axutil_stream_write(stream, env, text_value_1, axutil_strlen(text_value_1));
                           }
                           
                           axutil_stream_write(stream, env, end_input_str, end_input_str_len);
                           
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 
                   if(namespaces)
                   {
                       axutil_hash_index_t *hi;
                       void *val;
                       for (hi = axutil_hash_first(namespaces, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, NULL, NULL, &val);
                           AXIS2_FREE(env->allocator, val);
                       }
                       axutil_hash_free(namespaces, env);
                   }
                

            return parent;
        }
        axis2_status_t AXIS2_CALL
        adb_additionalTransferProtocols_type0_deserialize_obj(
                adb_additionalTransferProtocols_type0_t* _additionalTransferProtocols_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;
           
             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, _additionalTransferProtocols_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 additionalTransferProtocols_type0 : "
                            "NULL element can not be passed to deserialize");
                return AXIS2_FAILURE;
              }
              
                      
                      first_node = axiom_node_get_first_child(parent, env);
                      
                    
                    /*
                     * building protocol array
                     */
                       arr_list = axutil_array_list_create(env, 10);
                   

                     
                     /*
                      * building protocol element
                      */
                     
                     
                     
                                    element_qname = axutil_qname_create(env, "protocol", "http://www.daisy.org/ns/daisy-online/", NULL);
                                  
                               
                               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;
                                  }
                                  
                                  current_element = (axiom_element_t *)axiom_node_get_data_element(current_node, env);
                                  qname = axiom_element_get_qname(current_element, env, current_node);

                                  if ( 
                                    (current_node && current_element && (axutil_qname_equals(element_qname, env, qname))))
                                  {
                                  
                                      if( current_node && current_element && (axutil_qname_equals(element_qname, env, qname)))
                                      {
                                          is_early_node_valid = AXIS2_TRUE;
                                      }
                                      
                                     
                                          text_value = axiom_element_get_text(current_element, env, current_node);
                                          if(text_value != NULL)
                                          {
                                              axutil_array_list_add_at(arr_list, env, i, axutil_strdup(env, text_value));
                                          }
                                          
                                          else
                                          {
                                              /*
                                               * axis2_qname_t *qname = NULL;
                                               * axiom_attribute_t *the_attri = NULL;
                                               * 
                                               * qname = axutil_qname_create(env, "nil", "http://www.w3.org/2001/XMLSchema-instance", "xsi");
                                               * the_attri = axiom_element_get_attribute(current_element, env, qname);
                                               */
                                           
                                              /* currently thereis a bug in the axiom_element_get_attribute, so we have to go to this bad method */
                                             
                                              axiom_attribute_t *the_attri = NULL;
                                              axis2_char_t *attrib_text = NULL;
                                              axutil_hash_t *attribute_hash = NULL;
                                             
                                              attribute_hash = axiom_element_get_all_attributes(current_element, env);
                                             
                                              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(strstr((axis2_char_t*)key, "nil|http://www.w3.org/2001/XMLSchema-instance"))
                                                       {
                                                           the_attri = (axiom_attribute_t*)val;
                                                           break;
                                                       }
                                                   }
                                              }
                                             
                                              if(the_attri)
                                              {
                                                  attrib_text = axiom_attribute_get_value(the_attri, env);
                                              }
                                              else
                                              {
                                                  /* this is hoping that attribute is stored in "http://www.w3.org/2001/XMLSchema-instance", this happnes when name is in default namespace */
                                                  attrib_text = axiom_element_get_attribute_value_by_name(current_element, env, "nil");
                                              }
                                             
                                              if(attrib_text && 0 == axutil_strcmp(attrib_text, "1"))
                                              {
                                                  AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "NULL value is set to a non nillable element protocol");
                                                  status = AXIS2_FAILURE;
                                              }
                                              else
                                              {
                                                  /* after all, we found this is a empty string */
                                                  axutil_array_list_add_at(arr_list, env, i, axutil_strdup(env, ""));
                                              }
                                          }
                                          
                                     if(AXIS2_FAILURE ==  status)
                                     {
                                         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "failed in setting the value for protocol ");
                                         if(element_qname)
                                         {
                                            axutil_qname_free(element_qname, env);
                                         }
                                         if(arr_list)
                                         {
                                            axutil_array_list_free(arr_list, env);
                                         }
                                         return AXIS2_FAILURE;
                                     }

                                     i ++;
                                    current_node = axiom_node_get_next_sibling(current_node, env);
                                  }
                                  else
                                  {
                                      is_early_node_valid = AXIS2_FALSE;
                                      sequence_broken = 1;
                                  }
                                  
                               }

                               
                                   if (i < 1)
                                   {
                                     /* found element out of order */
                                     AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "protocol (@minOccurs = '1') only have %d elements", i);
                                     if(element_qname)
                                     {
                                        axutil_qname_free(element_qname, env);
                                     }
                                     if(arr_list)
                                     {
                                        axutil_array_list_free(arr_list, env);
                                     }
                                     return AXIS2_FAILURE;
                                   }
                               

                               if(0 == axutil_array_list_size(arr_list,env))
                               {
                                    axutil_array_list_free(arr_list, env);
                               }
                               else
                               {
                                    status = adb_additionalTransferProtocols_type0_set_protocol(_additionalTransferProtocols_type0, env,
                                                                   arr_list);
                               }

                             
                  if(element_qname)
                  {
                     axutil_qname_free(element_qname, env);
                     element_qname = NULL;
                  }
                 
          return status;
       }
Exemplo n.º 29
0
        axiom_node_t* AXIS2_CALL
        adb_TransportData_serialize_obj(
                adb_TransportData_t* _TransportData,
                const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index)
        {
            
            
             axis2_char_t *string_to_stream;
            
         
         axiom_node_t* current_node = NULL;
         int tag_closed = 0;
         
         axis2_char_t* xsi_prefix = NULL;
         
         axis2_char_t* type_attrib = NULL;
         axiom_namespace_t* xsi_ns = NULL;
         axiom_attribute_t* xsi_type_attri = NULL;
         
                axiom_namespace_t *ns1 = NULL;

                axis2_char_t *qname_uri = NULL;
                axis2_char_t *qname_prefix = NULL;
                axis2_char_t *p_prefix = NULL;
                axis2_bool_t ns_already_defined;
            
                    axis2_char_t text_value_1[ADB_DEFAULT_DIGIT_LIMIT];
                    
                    axis2_char_t text_value_2[ADB_DEFAULT_DIGIT_LIMIT];
                    
               axis2_char_t *start_input_str = NULL;
               axis2_char_t *end_input_str = NULL;
               unsigned int start_input_str_len = 0;
               unsigned int end_input_str_len = 0;
            
            
               axiom_data_source_t *data_source = NULL;
               axutil_stream_t *stream = NULL;

            

            AXIS2_ENV_CHECK(env, NULL);
            AXIS2_PARAM_CHECK(env->error, _TransportData, NULL);
            
            
                    current_node = parent;
                    data_source = (axiom_data_source_t *)axiom_node_get_data_element(current_node, env);
                    if (!data_source)
                        return NULL;
                    stream = axiom_data_source_get_stream(data_source, env); /* assume parent is of type data source */
                    if (!stream)
                        return NULL;
                  
            if(!parent_tag_closed)
            {
            
              
 
              if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING)))
              {
                  /* it is better to stick with the standard prefix */
                  xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi");
                  
                  axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix);

                  if(parent_element)
                  {
                        axiom_namespace_t *element_ns = NULL;
                        element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance",
                                                            xsi_prefix);
                        axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns);
                  }
              }
              type_attrib = axutil_strcat(env, " ", xsi_prefix, ":type=\"TransportData\"", NULL);
              axutil_stream_write(stream, env, type_attrib, axutil_strlen(type_attrib));

              AXIS2_FREE(env->allocator, type_attrib);
                
              string_to_stream = ">"; 
              axutil_stream_write(stream, env, string_to_stream, axutil_strlen(string_to_stream));
              tag_closed = 1;
            
            }
            else {
              /* if the parent tag closed we would be able to declare the type directly on the parent element */ 
              if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING)))
              {
                  /* it is better to stick with the standard prefix */
                  xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi");
                  
                  axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix);

                  if(parent_element)
                  {
                        axiom_namespace_t *element_ns = NULL;
                        element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance",
                                                            xsi_prefix);
                        axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns);
                  }
              }
            }
            xsi_ns = axiom_namespace_create (env,
                                 "http://mgt.transport.carbon.wso2.org/xsd",
                                 xsi_prefix);
            xsi_type_attri = axiom_attribute_create (env, "type", "TransportData", xsi_ns);
            
            axiom_element_add_attribute (parent_element, env, xsi_type_attri, parent);
        
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://mgt.transport.carbon.wso2.org/xsd", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://mgt.transport.carbon.wso2.org/xsd", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://mgt.transport.carbon.wso2.org/xsd",
                                            p_prefix));
                       }
                      

                   if (!_TransportData->is_valid_details)
                   {
                      
                           /* no need to complain for minoccurs=0 element */
                            
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("details"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("details")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     
                     /*
                      * parsing details element
                      */

                    
                    
                            sprintf(start_input_str, "<%s%sdetails",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); 
                            
                        start_input_str_len = axutil_strlen(start_input_str);
                        sprintf(end_input_str, "</%s%sdetails>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                        end_input_str_len = axutil_strlen(end_input_str);
                     
                            if(!adb_TransportDetails_is_particle())
                            {
                                axutil_stream_write(stream, env, start_input_str, start_input_str_len);
                            }
                            adb_TransportDetails_serialize(_TransportData->property_details, 
                                                                                 env, current_node, parent_element,
                                                                                 adb_TransportDetails_is_particle() || AXIS2_FALSE, namespaces, next_ns_index);
                            
                            if(!adb_TransportDetails_is_particle())
                            {
                                axutil_stream_write(stream, env, end_input_str, end_input_str_len);
                            }
                            
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 
                       if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://mgt.transport.carbon.wso2.org/xsd", AXIS2_HASH_KEY_STRING)))
                       {
                           p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT);
                           sprintf(p_prefix, "n%d", (*next_ns_index)++);
                           axutil_hash_set(namespaces, "http://mgt.transport.carbon.wso2.org/xsd", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://mgt.transport.carbon.wso2.org/xsd",
                                            p_prefix));
                       }
                      

                   if (!_TransportData->is_valid_summary)
                   {
                      
                           /* no need to complain for minoccurs=0 element */
                            
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("summary"))); 
                                 
                                 /* axutil_strlen("<:>") + 1 = 4 */
                     end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (5 + axutil_strlen(p_prefix) + axutil_strlen("summary")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     
                     /*
                      * parsing summary element
                      */

                    
                    
                            sprintf(start_input_str, "<%s%ssummary",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); 
                            
                        start_input_str_len = axutil_strlen(start_input_str);
                        sprintf(end_input_str, "</%s%ssummary>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                        end_input_str_len = axutil_strlen(end_input_str);
                     
                            if(!adb_TransportSummary_is_particle())
                            {
                                axutil_stream_write(stream, env, start_input_str, start_input_str_len);
                            }
                            adb_TransportSummary_serialize(_TransportData->property_summary, 
                                                                                 env, current_node, parent_element,
                                                                                 adb_TransportSummary_is_particle() || AXIS2_FALSE, namespaces, next_ns_index);
                            
                            if(!adb_TransportSummary_is_particle())
                            {
                                axutil_stream_write(stream, env, end_input_str, end_input_str_len);
                            }
                            
                     
                     AXIS2_FREE(env->allocator,start_input_str);
                     AXIS2_FREE(env->allocator,end_input_str);
                 } 

                 

            return parent;
        }
Exemplo n.º 30
0
static long
remote_registry_rest_client_get_internal(
	remote_registry_rest_client_t *rest_client,
	const axutil_env_t *env,
	const axis2_char_t *url,
	axis2_char_t *uname_passwd,
	axis2_char_t **buffer,
	int *content_len,
	struct curl_slist *headers)
{
	long status_code = -1;
	CURL *curl_handle;
	CURLcode res;

	curl_handle = curl_easy_init();
	if(curl_handle)
	{
		axis2_char_t *response_content_type = NULL;

		remote_registry_rest_client_callbk_param_t callbk_param;
		memset(&callbk_param, 0, sizeof(callbk_param));

		curl_easy_setopt(curl_handle, CURLOPT_URL, url);
		//curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
		curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);
		curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, REMOTE_REGISTRY_USER_AGENT);

		/* we need to know the headers as well */
		curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1);

		if(uname_passwd)
		{
			curl_easy_setopt(curl_handle, CURLOPT_USERPWD, uname_passwd);
		}

		if(remote_registry_conf_get_conn_timeout(rest_client->conf, env)) 
		{
#ifdef CURLOPT_TIMEOUT_MS
			curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, remote_registry_conf_get_conn_timeout(rest_client->conf, env));
#endif
		}
		/* setting the callback */
		curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, remote_registry_rest_client_write_data);
		if(headers)
		{
			curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
		}

		/* preparing the parameter for the callback */
		callbk_param.env = env;
		curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &callbk_param);

		curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
		curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
		res = curl_easy_perform(curl_handle);

		if(res == CURLE_OK) 
		{
			axis2_char_t *new_etag = NULL;
			int header_len= 0;
			axis2_char_t *headers_buffer = NULL;
			axis2_char_t *content = NULL;
			curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &status_code);
			curl_easy_getinfo(curl_handle, CURLINFO_CONTENT_TYPE, &response_content_type);
			curl_easy_getinfo(curl_handle, CURLINFO_HEADER_SIZE, &header_len);
			if(status_code == 200)
			{
				rest_client->last_response_status = AXIS2_SUCCESS;
				rest_client->last_response_content_type = axutil_strdup(env, response_content_type);

				if(header_len > 0 && callbk_param.buffer)
				{
					/* deviding the output to header and content */
					*(callbk_param.buffer + header_len -1) = '\0';
					callbk_param.buffer_len -= header_len;

					content = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t*)* (callbk_param.buffer_len + 1));
					memcpy(content, callbk_param.buffer + header_len, callbk_param.buffer_len + 1);
					headers_buffer = callbk_param.buffer;
					new_etag = remote_registry_rest_client_extract_etag_info(env, headers_buffer);
					AXIS2_FREE(env->allocator, callbk_param.buffer);
				}
				else {
					/* no header is retrieved */
					content = callbk_param.buffer;
				}
				*buffer = content;

				if(content_len)
				{
					*content_len = callbk_param.buffer_len;
				}

				/* do the caching */
				remote_registry_rest_client_set_cache(rest_client, env, url, *buffer, *content_len, new_etag);
			}
			else
			{
				rest_client->last_response_status = AXIS2_FAILURE;
			}
		}
		else 
		{
			AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
		}

		/* always cleanup */
		curl_easy_cleanup(curl_handle);
	}
	return status_code;
}