Example #1
0
AXIS2_EXTERN axis2_char_t* AXIS2_CALL
oxs_util_generate_nonce(const axutil_env_t *env, int length)
{
    oxs_buffer_t *buffer = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    char *rand_str = NULL;
    axis2_char_t* encoded_str = NULL;

    buffer = oxs_buffer_create(env);
    status = openssl_generate_random_data(env, buffer, length);
    rand_str = (char*)oxs_buffer_get_data(buffer, env);
    encoded_str = AXIS2_MALLOC(env->allocator, sizeof(char) * (axutil_base64_encode_len(length)+1));
    axutil_base64_encode(encoded_str, rand_str, oxs_buffer_get_size(buffer, env));
    oxs_buffer_free(buffer, env);

    return encoded_str;
}
Example #2
0
AXIS2_EXTERN const axis2_char_t *AXIS2_CALL
axiom_text_get_text(
    axiom_text_t * om_text,
    const axutil_env_t * env)
{
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, om_text, NULL);
    if(om_text->value)
    {
        return axutil_string_get_buffer(om_text->value, env);
    }
    else
    {
        axis2_char_t *data_handler_stream = NULL;
        size_t data_handler_stream_size = 0;
        if(om_text->data_handler)
        {
            size_t encoded_len = 0;
            axis2_char_t *encoded_str = NULL;
            axiom_data_handler_read_from(om_text->data_handler, env, &data_handler_stream,
                &data_handler_stream_size);
            if(data_handler_stream)
            {
                encoded_len = (size_t)axutil_base64_encode_len((int)data_handler_stream_size);
                encoded_str = AXIS2_MALLOC(env->allocator, encoded_len + 2);
                if(encoded_str)
                {
                    encoded_len = (size_t)axutil_base64_encode(encoded_str, data_handler_stream,
                        (int)data_handler_stream_size);
                    encoded_str[encoded_len] = '\0';
                    return encoded_str;
                }
            }
        }
    }
    return NULL;
}
Example #3
0
AXIS2_EXTERN axiom_node_t *AXIS2_CALL
remote_registry_resource_serialize(
    remote_registry_resource_t *resource,
    const axutil_env_t *env)
{
    axiom_node_t *entry_node = NULL;
    axiom_element_t *entry_element = NULL;
    axiom_namespace_t *ns1 = NULL;
    axiom_namespace_t *ns2 = NULL;
    axis2_char_t *description = NULL;
    axis2_char_t *author = NULL;
    axutil_hash_t *properties = NULL;
    axis2_char_t *content = NULL;
    int collection = 0;
    int content_modified= 0;
	axis2_char_t *id = NULL;
	axis2_char_t *title = NULL;
	
    axis2_char_t *media_type = NULL;
    axis2_char_t *parent_path = NULL;
	axutil_date_time_t *modified_date = NULL;

    ns1 = axiom_namespace_create(env, REMOTE_REGISTRY_ATOM_NS, REMOTE_REGISTRY_ATOM_NS_PREFIX);
    ns2 = axiom_namespace_create(env, REMOTE_REGISTRY_REGISTRY_NS, REMOTE_REGISTRY_REGISTRY_NS_PREFIX);

	if(resource->is_collection)
	{
		entry_element = axiom_element_create(env, NULL, REMOTE_REGISTRY_FEED_KEY_FEED, ns1, &entry_node);
	}
	else
	{
		entry_element = axiom_element_create(env, NULL, REMOTE_REGISTRY_FEED_KEY_ENTRY, ns1, &entry_node);
	}

	axiom_element_declare_namespace(entry_element, env, entry_node, ns1);
	axiom_element_declare_namespace(entry_element, env, entry_node, ns2);

    /* getting variables from the structure and rendering into an XML */
	id = remote_registry_resource_get_id(resource, env);
	if(id)
	{
		axiom_node_t *id_node = NULL;
		axiom_element_t *id_element = NULL;

		id_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_ID, ns1, &id_node);
		axiom_element_set_text(id_element, env, id, id_node);
	}


    title = remote_registry_resource_get_title(resource, env);
    if(title)
    {
        axiom_node_t *title_node = NULL;
        axiom_element_t *title_element = NULL;
        axiom_attribute_t *type_attr = NULL;

        title_element = axiom_element_create(env, entry_node,
						REMOTE_REGISTRY_FEED_KEY_TITLE, ns1, &title_node);
        axiom_element_set_text(title_element, env, title, title_node);

        type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE,
						REMOTE_REGISTRY_FEED_ATTR_TYPE_TEXT, NULL); 
        axiom_element_add_attribute(title_element, env, type_attr, title_node);
    }

    description = remote_registry_resource_get_description(resource, env);
    if(description)
    {
        axiom_node_t *summary_node = NULL;
        axiom_element_t *summary_element = NULL;
        axiom_attribute_t *type_attr = NULL;

        summary_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_SUMMARY, ns1, &summary_node);
        axiom_element_set_text(summary_element, env, description, summary_node);

        type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE,
					REMOTE_REGISTRY_FEED_ATTR_TYPE_TEXT, NULL); 
        axiom_element_add_attribute(summary_element, env, type_attr, summary_node);
    }

    author = remote_registry_resource_get_author_name(resource, env);
    if(author)
    {
        axiom_node_t *author_node = NULL;
        axiom_node_t *name_node = NULL;
        axiom_element_t *name_ele = NULL;

        axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_AUTHOR, ns1, &author_node);
        name_ele = axiom_element_create(env, author_node, REMOTE_REGISTRY_FEED_KEY_NAME, ns1, &name_node);

        axiom_element_set_text(name_ele, env, author, name_node);
    }

	modified_date = remote_registry_resource_get_last_modified_time(resource, env);
	if(!modified_date) {
		modified_date = axutil_date_time_create(env);
		remote_registry_resource_set_last_modified_time(resource, env, modified_date);
	}
	if(modified_date) 
	{
        axiom_node_t *date_node = NULL;
        axiom_element_t *date_ele = NULL;
		axis2_char_t *modified_date_str = NULL;

		modified_date_str = axutil_date_time_serialize_date_time(modified_date, env);
        date_ele = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_UPDATED, ns1, &date_node);
        axiom_element_set_text(date_ele, env, modified_date_str, date_node);

		AXIS2_FREE(env->allocator, modified_date_str);
	}
	

    content = remote_registry_resource_get_content(resource, env);
    if(content)
    {
        axiom_node_t *content_node = NULL;
        axiom_element_t *content_element = NULL;
        axiom_attribute_t *type_attr = NULL;
		axis2_char_t *base64_content = NULL;

		int base64_len = 0;
		int content_len = -1;

		content_len = remote_registry_resource_get_content_len(resource, env);
		if(content_len == -1) /* which mean we have to derive the content length */
		{
			content_len = axutil_strlen(content);
		}

		base64_len = axutil_base64_encode_len(content_len);
		base64_content = AXIS2_MALLOC(env->allocator, base64_len+ 1);

		if(base64_content) 
		{
			axutil_base64_encode(base64_content, content, content_len);
			base64_content[base64_len] = '\0';


			content_element = axiom_element_create(env, entry_node, 
							REMOTE_REGISTRY_FEED_KEY_CONTENT, ns1, &content_node);
			axiom_element_set_text(content_element, env, base64_content, content_node);


			type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE, 
							REMOTE_REGISTRY_FEED_ATTR_TYPE_BASE64_VALUE, NULL); 
			axiom_element_add_attribute(content_element, env, type_attr, content_node);
			
			AXIS2_FREE(env->allocator, base64_content);
		}
    }
    else if(!resource->is_collection)
    {
        axiom_node_t *content_node = NULL;
        axiom_element_t *content_element = NULL;
        axiom_attribute_t *type_attr = NULL;

        content_element = axiom_element_create(env, entry_node, 
						REMOTE_REGISTRY_FEED_KEY_CONTENT, ns1, &content_node);
        axiom_element_set_text(content_element, env, 
						REMOTE_REGISTRY_FEED_VALUE_EMPTY_CONTENT, content_node);


        type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE, 
						REMOTE_REGISTRY_FEED_ATTR_TYPE_TEXT_VALUE, NULL); 
        axiom_element_add_attribute(content_element, env, type_attr, content_node);
    }

    properties = remote_registry_resource_get_properties(resource, env);
    if(properties)
    {
        axiom_node_t *properties_node = NULL;
        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;
        axutil_hash_index_t *hi;
        void *val;
        void *key;
        int sum = 0;

        axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_PROPERTIES, ns2, &properties_node);
        
        for (hi = axutil_hash_first(resource->properties, env); hi; hi = axutil_hash_next(env, hi)) {
            axutil_hash_this(hi, (const void**)&key, NULL, &val);
            
            axiom_element_create(env, properties_node, REMOTE_REGISTRY_FEED_KEY_PROPERTY, ns2, &property_node);

            name_element = axiom_element_create(env, property_node, 
								REMOTE_REGISTRY_FEED_KEY_PROPERTY_KEY_NAME, ns2, &name_node);
            axiom_element_set_text(name_element, env, (axis2_char_t*)key, name_node);
            value_element = axiom_element_create(env, property_node, 
								REMOTE_REGISTRY_FEED_KEY_PROPERTY_KEY_VALUE, ns2, &value_node);
            axiom_element_set_text(value_element, env, (axis2_char_t*)val, value_node);
        }
    }
	
	media_type = remote_registry_resource_get_media_type(resource, env);
	if(media_type) 
	{
		axiom_element_t *media_element = NULL;
		axiom_node_t *media_node = NULL;
		media_element = axiom_element_create(env, entry_node, 
								REMOTE_REGISTRY_FEED_KEY_MEDIA_TYPE, ns2, &media_node);
		axiom_element_set_text(media_element, env, media_type, media_node);

	}

    parent_path = remote_registry_resource_get_parent_path(resource, env);
	if(parent_path) 
	{
		axiom_element_t *parent_path_element = NULL;
		axiom_node_t *parent_path_node = NULL;
		parent_path_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_PARENT_PATH, ns2, &parent_path_node);
		if(resource->is_collection) 
		{
			/* for collection parent path is always sent at the http request header */
			parent_path = "";
		}
		axiom_element_set_text(parent_path_element, env, parent_path, parent_path_node);
	}
	if(resource->is_collection)
	{
		axiom_element_t *content_modified_element = NULL;
		axiom_node_t *content_modified_node = NULL;
		content_modified_element = axiom_element_create(env, entry_node, 
				REMOTE_REGISTRY_FEED_KEY_CONTENT_MODIFIED, ns2, &content_modified_node);
		axiom_element_set_text(content_modified_element, env, 
				REMOTE_REGISTRY_FEED_KEY_TRUE_VALUE, content_modified_node);
	}

    return entry_node;
}