AXIS2_EXTERN axiom_node_t* AXIS2_CALL
oxs_token_build_security_token_reference_element(
    const axutil_env_t *env,
    axiom_node_t *parent)
{
    axiom_node_t *security_token_reference_node = NULL;
    axiom_element_t *security_token_reference_ele = NULL;
    axiom_namespace_t *ns_obj = NULL;

    ns_obj = axiom_namespace_create(env, OXS_WSSE_XMLNS, OXS_WSSE);

    /* We especially pass parent=NULL in order to add WSSE namespace to the SECURITY_TOKEN_REFRENCE 
     * node. Otherwise if we encrypt the signature , the dercyption fails to build the node as the 
     * namespace is not within the doc */
    security_token_reference_ele = axiom_element_create(
        env, NULL, OXS_NODE_SECURITY_TOKEN_REFRENCE, ns_obj, &security_token_reference_node);
    if(!security_token_reference_ele)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
            "[rampart]Error creating SecurityTokenReference element.");
        axiom_namespace_free(ns_obj, env);
        return NULL;
    }

    if(parent)
    {
        axiom_node_add_child(parent, env, security_token_reference_node);
    }

    return security_token_reference_node;
}
Esempio n. 2
0
/**
* Creates <ds:Transform> element
*/
AXIS2_EXTERN axiom_node_t* AXIS2_CALL
oxs_token_build_transform_element(
    const axutil_env_t *env,
    axiom_node_t *parent,
    axis2_char_t* algorithm)
{
    axiom_node_t *transform_node = NULL, *tr_para_node = NULL, *tr_can_node = NULL;
    axiom_element_t *transform_ele = NULL, *tr_para_ele = NULL, *tr_can_ele = NULL;
    axiom_attribute_t *algo_attr = NULL;
    int ret;
    axiom_namespace_t *ns_obj = NULL;

    ns_obj = axiom_namespace_create(env, OXS_DSIG_NS, OXS_DS);
    transform_ele = axiom_element_create(env, parent, OXS_NODE_TRANSFORM, ns_obj, &transform_node);
    if (!transform_ele)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart]Error creating transform element.");
        axiom_namespace_free(ns_obj, env);
        return NULL;
    }

    /* If transform algorithm is NULL then use the default */
    if(!algorithm)
    {
        algorithm = (axis2_char_t*)OXS_HREF_XML_EXC_C14N;
    }

    algo_attr =  axiom_attribute_create(env, OXS_ATTR_ALGORITHM, algorithm, NULL);
    ret = axiom_element_add_attribute(transform_ele, env, algo_attr, transform_node);
   
    if (!axutil_strcmp(algorithm, OXS_HREF_TRANSFORM_STR_TRANSFORM))
    {
        ns_obj = axiom_namespace_create(env, OXS_WSSE_NS, OXS_WSSE);
        tr_para_ele = axiom_element_create(
            env, NULL, OXS_NODE_TRANSFORMATIONPARAMETERS, ns_obj, &tr_para_node);
        if (!tr_para_ele)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                "[rampart]Error creating TransformationParameters element.");
            axiom_namespace_free(ns_obj, env);
            return NULL;
        }

        ns_obj = axiom_namespace_create(env, OXS_DSIG_NS, OXS_DS);
        tr_can_ele = axiom_element_create(
            env, tr_para_node, OXS_NODE_CANONICALIZATION_METHOD, ns_obj, &tr_can_node);
        if (!tr_can_ele)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                "[rampart]Error creating CanonicalizationMethod element.");
            axiom_namespace_free(ns_obj, env);
            return NULL;
        }

        algo_attr =  axiom_attribute_create(env, OXS_ATTR_ALGORITHM, OXS_HREF_XML_EXC_C14N, NULL);		
		axiom_element_add_attribute(tr_can_ele, env, algo_attr, tr_can_node);
		axiom_node_add_child(transform_node, env, tr_para_node);
    }
    return transform_node;
}
Esempio n. 3
0
AXIS2_EXTERN axiom_node_t * AXIS2_CALL
trust_rst_build_rst_with_issued_token_assertion(
		trust_rst_t *rst,
		const axutil_env_t *env,
		rp_issued_token_t *issued_token)
{
	axiom_node_t *rst_node = NULL;
	axiom_node_t *rst_template_node = NULL;
	axiom_element_t * rst_template_element = NULL;
	axiom_children_iterator_t *rst_template_children_iter = NULL;
	axiom_node_t *rst_template_child = NULL;


	/*Attr Context is NULL -?*/
	rst_node = (axiom_node_t*)trust_util_create_rst_element(env, rst->wst_ns_uri, rst->attr_context);
	rst_template_node = rp_issued_token_get_requested_sec_token_template(issued_token, env);
	rst_template_node = axiom_node_detach(rst_template_node, env);	/*Detaching RSTTemplate from the original location- FIX - Detaching problem with NS'*/
	rst_template_element = axiom_node_get_data_element(rst_template_node, env);

	rst_template_children_iter = axiom_element_get_children(rst_template_element, env, rst_template_node);


	while(axiom_children_iterator_has_next(rst_template_children_iter, env))
	{
		rst_template_child = axiom_children_iterator_next(rst_template_children_iter, env);
		if(rst_template_node)
			axiom_node_add_child(rst_node, env, rst_template_child);
	}

	if(rst_node)
		return rst_node;
	

	return NULL;
}
Esempio n. 4
0
AXIS2_EXTERN axiom_node_t *AXIS2_CALL
axiom_soap_header_get_base_node(
    axiom_soap_header_t * soap_header,
    const axutil_env_t * env)
{
    if(!soap_header->om_ele_node)
    {
        axiom_node_t *parent_node = NULL;
        axiom_element_t *parent_ele = NULL;
        axiom_namespace_t *parent_ns = NULL;
        axiom_element_t *this_ele = NULL;
        axiom_node_t *this_node = NULL;
        axiom_soap_body_t *soap_body = NULL;
        axiom_node_t *body_node = NULL;

        parent_node = axiom_soap_envelope_get_base_node(soap_header->soap_envelope, env);

        if(!parent_node || axiom_node_get_node_type(parent_node, env) != AXIOM_ELEMENT)
        {
            axiom_soap_header_free(soap_header, env);
            return NULL;
        }

        parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env);
        if(!parent_ele)
        {
            axiom_soap_header_free(soap_header, env);
            return NULL;
        }

        parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node);
        this_ele = axiom_element_create(env, NULL, AXIOM_SOAP_HEADER_LOCAL_NAME, parent_ns,
            &this_node);
        if(!this_ele)
        {
            axiom_soap_header_free(soap_header, env);
            return NULL;
        }

        soap_body = axiom_soap_envelope_get_body(soap_header->soap_envelope, env);
        if(soap_body)
        {
            body_node = axiom_soap_body_get_base_node(soap_body, env);
            axiom_node_insert_sibling_before(body_node, env, this_node);
        }
        else
        {
            axiom_node_add_child(parent_node, env, this_node);
        }
        soap_header->om_ele_node = this_node;
    }

    return soap_header->om_ele_node;
}
Esempio n. 5
0
AXIS2_EXTERN axiom_text_t *AXIS2_CALL
axiom_text_create(
    const axutil_env_t * env,
    axiom_node_t * parent,
    const axis2_char_t * value,
    axiom_node_t ** node)
{
    axiom_text_t *om_text = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, node, NULL);

    *node = axiom_node_create(env);

    if(!(*node))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }
    om_text = (axiom_text_t *)AXIS2_MALLOC(env->allocator, sizeof(axiom_text_t));
    if(!om_text)
    {
        AXIS2_FREE(env->allocator, *node);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    om_text->mime_type = NULL;
    om_text->optimize = AXIS2_FALSE;
    om_text->is_binary = AXIS2_FALSE;
    om_text->is_swa = AXIS2_FALSE;
    om_text->content_id = NULL;
    om_text->om_attribute = NULL;
    om_text->value = NULL;
    om_text->ns = NULL;
    om_text->data_handler = NULL;
    om_text->mime_type = NULL;

    if(value)
    {
        om_text->value = axutil_string_create(env, value);
    }

    axiom_node_set_data_element((*node), env, om_text);
    axiom_node_set_node_type((*node), env, AXIOM_TEXT);
    axiom_node_set_complete((*node), env, AXIS2_FALSE);

    if(parent && axiom_node_get_node_type(parent, env) == AXIOM_ELEMENT)
    {
        axiom_node_add_child(parent, env, (*node));
    }

    return om_text;
}
Esempio n. 6
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axiom_soap_body_add_child(
    axiom_soap_body_t * soap_body,
    const axutil_env_t * env,
    axiom_node_t * child)
{
    AXIS2_PARAM_CHECK(env->error, child, AXIS2_FAILURE);

    if(soap_body->om_ele_node)
    {
        return axiom_node_add_child(soap_body->om_ele_node, env, child);
    }
    return AXIS2_FAILURE;
}
Esempio n. 7
0
AXIS2_EXTERN axiom_text_t *AXIS2_CALL
axiom_text_create_str(
    const axutil_env_t * env,
    axiom_node_t * parent,
    axutil_string_t * value,
    axiom_node_t ** node)
{
    axiom_text_t *om_text = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, node, NULL);

    *node = axiom_node_create(env);
    if(!(*node))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unable to create node needed by om text");
        return NULL;
    }

    om_text = (axiom_text_t *)AXIS2_MALLOC(env->allocator, sizeof(axiom_text_t));
    if(!om_text)
    {
        AXIS2_FREE(env->allocator, *node);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Insufficient memory to create om text");
        return NULL;
    }

    memset(om_text, 0, sizeof(axiom_text_t));
    if(value)
    {
        om_text->value = axutil_string_clone(value, env);
    }

    axiom_node_set_data_element((*node), env, om_text);
    axiom_node_set_node_type((*node), env, AXIOM_TEXT);

    if(parent && axiom_node_get_node_type(parent, env) == AXIOM_ELEMENT)
    {
        axiom_node_add_child(parent, env, (*node));
    }

    return om_text;
}
Esempio n. 8
0
/** Add a node with an element to root_node, either as child or as sibling.
 *   The element name is in the same namespace as the root node's name.
 *   The element may optionally include one attribute; if no attribute
 *   is desired then pass 'NULL'.
 *
 *  Example with attribute:
 *     node_id.name="foo";     node.value="bar";
 *     attribute.name="attr";  attribute.value="Zar";
 *  Result :  <ns:foo attr="Zar">bar</ns:foo>
 *
 * @param env
 * @param root_node
 * @param node_id
 *   node_id.name:  name of element to be added,
 *   node_id.value: text of element
 * @param attribute optional Name_value pair for setting an attribute,
 *   may be NULL.
 * @param sibling 1: add as sibling, 0: add as child.
 * @param whitespace: whitespace added before the newly added element (the
 *  newly added element is indented by this space.
 * @return ptr to the the newly added node.
 */
static axiom_node_t *rp_add_node(
    const axutil_env_t *env,
    axiom_node_t       *root_node,
    Name_value         *node_id,
    Name_value         *attribute,
    int                sibling,
    const axis2_char_t *whitespace
 )
{

	sp_add_whspace(env, root_node, whitespace);

    axiom_namespace_t * ns = rp_get_namespace (env, root_node);

    axiom_node_t    *new_node = axiom_node_create(env);
    axiom_element_t *new_ele =
      axiom_element_create(env, NULL, node_id->name, ns, &new_node);
    if (NULL != node_id->value)
    {
    	axiom_element_set_text(new_ele, env, node_id->value, new_node);
    }

    if (NULL != attribute)
    {
        axiom_attribute_t *attr =
          axiom_attribute_create (env, attribute->name, attribute->value, NULL);
        axiom_element_add_attribute (new_ele, env, attr, new_node);
    }

    axis2_status_t success = (
    		sibling ?
    				axiom_node_insert_sibling_after (root_node, env, new_node) :
    				axiom_node_add_child            (root_node, env, new_node)
    );

    if (AXIS2_SUCCESS != success)
    {
    	rp_log_error(env, "*** S2P(%s:%d): Failed to add node name='%s'\n",
    			__FILE__, __LINE__, node_id->name);
    }

    return new_node;
}
Esempio n. 9
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
neethi_assertion_serialize(
    neethi_assertion_t *assertion,
    axiom_node_t *parent,
    const axutil_env_t *env)
{
    axiom_node_t *node = NULL;
    if(assertion->node)
    {
        node = axiom_util_clone_node(env, assertion->node);
    }

    if(!node)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "assertion node creation failed. Cannot serialize assertion");
        return AXIS2_FAILURE;
    }

    axiom_node_add_child(parent, env, node);
    return AXIS2_SUCCESS;
}
Esempio n. 10
0
axiom_node_t* AXIS2_CALL 
sandesha2_address_to_om_node(
    sandesha2_address_t *address,
   	const axutil_env_t *env, 
    void *om_node)
{
    axiom_namespace_t *rm_ns = NULL;
    axiom_element_t *addr_element = NULL;
    axiom_node_t *addr_node = NULL;
    
    AXIS2_PARAM_CHECK(env->error, om_node, NULL);
    if(!address->epr || !axis2_endpoint_ref_get_address(
            address->epr, env) || 0 == axutil_strlen(
            axis2_endpoint_ref_get_address(address->epr, env)))
    {
        AXIS2_ERROR_SET(env->error, (axutil_error_codes_t)SANDESHA2_ERROR_TO_OM_NULL_ELEMENT, 
            AXIS2_FAILURE);
        return NULL;
    }
    rm_ns = axiom_namespace_create(env, address->ns_val,
        AXIS2_WSA_DEFAULT_PREFIX);
    if(!rm_ns)
    {
        return NULL;
    }
    addr_element = axiom_element_create(env, NULL, 
            SANDESHA2_WSA_ADDRESS, rm_ns, &addr_node);
    if(!addr_element)
    {
        return NULL;
    }
    axiom_element_set_text(addr_element, env, 
            axis2_endpoint_ref_get_address(address->epr, env), 
            addr_node);
    axiom_node_add_child((axiom_node_t*)om_node, env, addr_node);
    return (axiom_node_t*)om_node;
}
Esempio n. 11
0
axis2_status_t
axis2_addr_out_handler_add_to_soap_header(
    const axutil_env_t * env,
    axis2_endpoint_ref_t * endpoint_ref,
    const axis2_char_t * type,
    axiom_soap_header_t * soap_header,
    const axis2_char_t * addr_ns)
{
    axiom_soap_header_block_t *header_block = NULL;
    const axis2_char_t *address = NULL;
    axutil_array_list_t *ref_param_list = NULL;
    axutil_array_list_t *meta_data_list = NULL;
    axutil_array_list_t *extension_list = NULL;
    axiom_node_t *header_block_node = NULL;
    axiom_node_t *header_node = NULL;
    axiom_namespace_t *addr_ns_obj = NULL;
    int size = 0;

    AXIS2_PARAM_CHECK(env->error, endpoint_ref, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, type, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, soap_header, AXIS2_FAILURE);

    header_node = axiom_soap_header_get_base_node(soap_header, env);

    addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
    header_block = axiom_soap_header_add_header_block(soap_header, env, type, addr_ns_obj);
    if(addr_ns_obj)
    {
        axiom_namespace_free(addr_ns_obj, env);
        addr_ns_obj = NULL;
    }

    address = axis2_endpoint_ref_get_address(endpoint_ref, env);
    if(address && *address)
    {
        axiom_node_t *hb_node = NULL;
        axiom_element_t *hb_ele = NULL;
        axiom_node_t *address_node = NULL;
        axiom_element_t *address_ele = NULL;
        hb_node = axiom_soap_header_block_get_base_node(header_block, env);
        hb_ele = (axiom_element_t *)axiom_node_get_data_element(hb_node, env);

        addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);

        address_ele = axiom_element_create(env, hb_node, EPR_ADDRESS, addr_ns_obj, &address_node);
		axiom_namespace_free(addr_ns_obj, env);
        if(address_ele)
        {
            axiom_namespace_t *dec_ns = NULL;
            axiom_element_set_text(address_ele, env, address, address_node);
            dec_ns = axiom_element_find_declared_namespace(address_ele, env, addr_ns,
                AXIS2_WSA_DEFAULT_PREFIX);
        }
    }

    header_block_node = axiom_soap_header_block_get_base_node(header_block, env);
    axis2_addr_out_handler_add_to_header(env, endpoint_ref, &header_block_node, addr_ns);

    ref_param_list = axis2_endpoint_ref_get_ref_param_list(endpoint_ref, env);
    if(ref_param_list && axutil_array_list_size(ref_param_list, env) > 0)
    {
        axiom_node_t *reference_node = NULL;
        axiom_element_t *reference_ele = NULL;
        axutil_array_list_t *ref_attribute_list = NULL;
        int i = 0;

        addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);

        reference_ele = axiom_element_create(env, header_block_node, EPR_REFERENCE_PARAMETERS,
            addr_ns_obj, &reference_node);
		axiom_namespace_free(addr_ns_obj, env);

        ref_attribute_list = axis2_endpoint_ref_get_ref_attribute_list(endpoint_ref, env);
        if(ref_attribute_list)
        {
            int j = 0;

            size = axutil_array_list_size(ref_attribute_list, env);
            for(j = 0; j < size; j++)
            {
                axiom_attribute_t *attr = (axiom_attribute_t *)axutil_array_list_get(
                    ref_attribute_list, env, j);
                if(attr)
                {
                    axiom_element_add_attribute(reference_ele, env, attr, reference_node);
                }
            }
        }

        size = axutil_array_list_size(ref_param_list, env);
        for(i = 0; i < size; i++)
        {
            axiom_node_t *ref_node = (axiom_node_t *)axutil_array_list_get(ref_param_list, env, i);
            if(ref_node)
            {
                axiom_node_add_child(reference_node, env, ref_node);
            }
        }

    }

    meta_data_list = axis2_endpoint_ref_get_metadata_list(endpoint_ref, env);
    if(meta_data_list && axutil_array_list_size(meta_data_list, env) > 0)
    {
        axiom_node_t *reference_node = NULL;
        axiom_element_t *reference_ele = NULL;
        axutil_array_list_t *meta_attribute_list = NULL;
        int i = 0;

        if(!reference_node) /* may be we alredy created this in ref params block */
        {
            addr_ns_obj = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);

            reference_ele = axiom_element_create(env, header_block_node, AXIS2_WSA_METADATA,
                addr_ns_obj, &reference_node);
			axiom_namespace_free(addr_ns_obj, env);
        }

        meta_attribute_list = axis2_endpoint_ref_get_metadata_attribute_list(endpoint_ref, env);
        if(meta_attribute_list)
        {
            int j = 0;
            size = axutil_array_list_size(meta_attribute_list, env);
            for(j = 0; j < size; j++)
            {
                axiom_attribute_t *attr = (axiom_attribute_t *)axutil_array_list_get(
                    meta_attribute_list, env, j);
                if(attr)
                {
                    axiom_element_add_attribute(reference_ele, env, attr, reference_node);
                }
            }
        }

        size = axutil_array_list_size(meta_data_list, env);
        for(i = 0; i < size; i++)
        {
            axiom_node_t *ref_node = (axiom_node_t *)axutil_array_list_get(meta_data_list, env, i);
            if(ref_node)
            {
                axiom_node_add_child(reference_node, env, ref_node);
            }
        }
    }

    extension_list = axis2_endpoint_ref_get_extension_list(endpoint_ref, env);
    if(extension_list && axutil_array_list_size(extension_list, env) > 0)
    {
        int i = 0;

        size = axutil_array_list_size(extension_list, env);
        for(i = 0; i < size; i++)
        {
            axiom_node_t *ref_node = (axiom_node_t *)axutil_array_list_get(extension_list, env, i);
            if(ref_node)
            {
                axiom_node_add_child(header_block_node, env, ref_node);
            }
        }
    }

    return AXIS2_SUCCESS;
}
Esempio n. 12
0
axis2_status_t AXIS2_CALL
wsf_xml_msg_recv_invoke_business_logic_sync(
        axis2_msg_recv_t * msg_recv,
        const axutil_env_t * env,
        axis2_msg_ctx_t * in_msg_ctx,
        axis2_msg_ctx_t * out_msg_ctx)
{

    axis2_op_ctx_t *op_ctx = NULL;
    axis2_op_t *op_desc = NULL;

    axiom_namespace_t *env_ns = NULL;

    int soap_version = AXIOM_SOAP12;
    axis2_status_t status = AXIS2_SUCCESS;
    axis2_bool_t skel_invoked = AXIS2_FALSE;

    const axis2_char_t *style = NULL;
    axis2_char_t *local_name = NULL;
    axis2_char_t *soap_ns = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI;
    axis2_char_t *operation_name = NULL;
    char *classname = NULL;

    axutil_property_t *svc_info_prop = NULL;
    axutil_property_t *req_info_prop = NULL;
    wsf_svc_info_t *svc_info = NULL;
    wsf_request_info_t *req_info = NULL;

    /** store in_msg_ctx envelope */
    axiom_soap_envelope_t *envelope = NULL;
    axiom_soap_body_t *body = NULL;
    axiom_node_t *in_body_node = NULL;

    /* store out_msg_ctx envelope */
    axiom_soap_envelope_t *default_envelope = NULL;
    axiom_soap_body_t *out_body = NULL;
    axiom_soap_header_t *out_header = NULL;
    axiom_soap_fault_t *out_soap_fault = NULL;

    axiom_node_t *result_node = NULL;

    axiom_node_t *out_body_content_node = NULL;
    axiom_element_t *out_body_content_element = NULL;
    axiom_node_t *out_node = NULL;

    zval **output_headers_zval = NULL;

    TSRMLS_FETCH();

    AXIS2_PARAM_CHECK(env->error, in_msg_ctx, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, out_msg_ctx, AXIS2_FAILURE);

    op_ctx = axis2_msg_ctx_get_op_ctx(in_msg_ctx, env);
    op_desc = axis2_op_ctx_get_op(op_ctx, env);
    style = axis2_op_get_style(op_desc, env);

    envelope = axis2_msg_ctx_get_soap_envelope(in_msg_ctx, env);

    body = axiom_soap_envelope_get_body(envelope, env);

    in_body_node = axiom_soap_body_get_base_node(body, env);


    if (0 == axutil_strcmp(AXIS2_STYLE_DOC, style))
    {
        local_name = wsf_xml_msg_recv_get_method_name(in_msg_ctx, env);
        if (!local_name)
        {
            return AXIS2_FAILURE;
        }
    } else if (0 == axutil_strcmp(AXIS2_STYLE_RPC, style))
    {

        axiom_node_t *op_node = NULL;
        axiom_element_t *op_element = NULL;
        op_node = axiom_node_get_first_child(in_body_node, env);
        if (!op_node)
        {
            return AXIS2_FAILURE;
        }
        op_element = axiom_node_get_data_element(op_node, env);

        if (!op_element)
        {
            return AXIS2_FAILURE;
        }
        local_name = axiom_element_get_localname(op_element, env);
        if (!local_name)
        {
            return AXIS2_FAILURE;
        }
    }

    /** set soap version and soap namespace to local variables */
    if (in_msg_ctx && axis2_msg_ctx_get_is_soap_11(in_msg_ctx, env))
    {
        soap_ns = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; /* default is 1.2 */
        soap_version = AXIOM_SOAP11;
    }

    svc_info_prop = axis2_msg_ctx_get_property(in_msg_ctx, env, WSF_SVC_INFO);
    if (svc_info_prop)
    {
        svc_info = (wsf_svc_info_t *) axutil_property_get_value(svc_info_prop, env);
        if (svc_info)
        {
            operation_name = axutil_hash_get(svc_info->ops_to_functions, local_name,
                    AXIS2_HASH_KEY_STRING);
            if (!operation_name)
            {
                return AXIS2_FAILURE;
            }
        } else
        {
            return AXIS2_FAILURE;
        }
        if (svc_info->ops_to_classes)
        {
            classname = axutil_hash_get(svc_info->ops_to_classes, local_name, AXIS2_HASH_KEY_STRING);
        }
    }

    req_info_prop = axis2_msg_ctx_get_property(in_msg_ctx, env, WSF_REQ_INFO);
    if (req_info_prop)
    {
        req_info = (wsf_request_info_t *) axutil_property_get_value(req_info_prop, env);

        if (axis2_msg_ctx_get_doing_rest(in_msg_ctx, env))
        {
            axis2_op_t *op = NULL;
            axiom_node_t *body_child_node = NULL;
            axiom_element_t *body_child = NULL;
            int i = 0;

            body_child_node = axiom_node_get_first_child(in_body_node, env);

            if (!body_child_node)
            {
                op = axis2_msg_ctx_get_op(in_msg_ctx, env);
                if (op)
                {
                    body_child = axiom_element_create_with_qname(env, NULL,
                            axis2_op_get_qname(op, env), &body_child_node);
                    axiom_soap_body_add_child(body, env, body_child_node);
                }
            }
            if (req_info->param_keys && req_info->param_values)
            {
                int i = 0;
                for (i = 0; i < axutil_array_list_size(req_info->param_keys, env); i++)
                {
                    axiom_node_t *node = NULL;
                    axiom_element_t *element = NULL;

                    axis2_char_t *param_key = NULL;
                    axis2_char_t *param_value = NULL;

                    param_key = axutil_array_list_get(req_info->param_keys, env, i);
                    param_value = axutil_array_list_get(req_info->param_values, env, i);

                    element = axiom_element_create(env, NULL, param_key,
                            NULL, &node);
                    axiom_element_set_text(element, env, param_value, node);
                    axiom_node_add_child(body_child_node, env, node);

                    AXIS2_FREE(env->allocator, param_key);
                    AXIS2_FREE(env->allocator, param_value);
                }
                axutil_array_list_free(req_info->param_keys, env);
                axutil_array_list_free(req_info->param_values, env);
            }
        }
    }

    if (svc_info->ht_op_params)
    {
        zval **tmp;
        char *function_type = NULL;
        if (zend_hash_find(svc_info->ht_op_params,
                operation_name, strlen(operation_name) + 1,
                (void **) & tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_STRING)
        {
            function_type = Z_STRVAL_PP(tmp);

            if (strcmp(function_type, WSF_MIXED) == 0)
            {
                result_node = wsf_xml_msg_recv_invoke_mixed(env, svc_info,
                        in_msg_ctx, out_msg_ctx, operation_name,
                        classname, &output_headers_zval TSRMLS_CC);

            } else if (strcmp(function_type, WSF_WSMESSAGE) == 0)
            {
                result_node = wsf_xml_msg_recv_invoke_wsmsg(env, operation_name,
                        in_msg_ctx, out_msg_ctx, svc_info, classname, req_info->content_type TSRMLS_CC);
            }
        }
    } else
    {
        /* this is where the default value for opParam is set,
           If the wsdl option is set go for the MIXED mode by default */
		if (svc_info->wsdl == NULL || svc_info->omit_wsdl)
        {
            result_node = wsf_xml_msg_recv_invoke_wsmsg(env, operation_name,
                    in_msg_ctx, out_msg_ctx, svc_info, classname, req_info->content_type TSRMLS_CC);
        } else
        {
            result_node = wsf_xml_msg_recv_invoke_mixed(env, svc_info,
                    in_msg_ctx, out_msg_ctx, operation_name,
                    classname, &output_headers_zval TSRMLS_CC);
        }
    }
    if (!result_node)
    {
        status = AXIS2_ERROR_GET_STATUS_CODE(env->error);
    } else
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "Response node is not null");
    }

    if (result_node)
    {
        if (0 == axutil_strcmp(style, AXIS2_STYLE_RPC))
        {
            axiom_namespace_t *ns = NULL;
            axis2_char_t *response_name = NULL;

            response_name = axutil_stracat(env, local_name, "Response");
            ns = axiom_namespace_create(env, "http://soapenc/", "res");
            if (!ns)
            {
                return AXIS2_FAILURE;
            }

            out_body_content_element = axiom_element_create(env, NULL, response_name,
                    ns, &out_body_content_node);
            axiom_node_add_child(out_body_content_node, env, result_node);

        } else
        {
            out_body_content_node = result_node;
        }
    }

    if (axis2_msg_ctx_get_soap_envelope(out_msg_ctx, env))
    {
        /* service implementation has set the envelope, useful when setting a SOAP fault.
           No need to further process */
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "soap fault is set");
        return AXIS2_SUCCESS;
    }

    /* create the soap envelope here */
    env_ns = axiom_namespace_create(env, soap_ns, AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX);
    if (!env_ns)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] error seting the namespces for the "
                AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX);
        return AXIS2_FAILURE;
    }

    default_envelope = axiom_soap_envelope_create(env, env_ns);

    if (!default_envelope)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "failed in creating the response soap envelope");
        return AXIS2_FAILURE;
    }


    out_body = axiom_soap_body_create_with_parent(env, default_envelope);
    if (!out_body)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] failed in creating the response soap body");
        return AXIS2_FAILURE;
    }

    out_header = axiom_soap_header_create_with_parent(env, default_envelope);
    if (!out_header)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "failed in creating the response soap headers");
        return AXIS2_FAILURE;
    }

    if (output_headers_zval)
    {
        axiom_node_t *header_base_node = NULL;

        HashPosition pos;
        zval **param;
        char *header_str;
        axiom_node_t *header_node;

        for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(output_headers_zval), &pos);
                zend_hash_get_current_data_ex(Z_ARRVAL_PP(output_headers_zval),
                (void **) & param, &pos) == SUCCESS;
                zend_hash_move_forward_ex(Z_ARRVAL_PP(output_headers_zval), &pos))
        {

            if (Z_TYPE_PP(param) == IS_STRING)
            {

                header_base_node = axiom_soap_header_get_base_node(out_header, env);

                if (header_base_node)
                {
                    header_str = Z_STRVAL_PP(param);
                    header_node = wsf_util_deserialize_buffer(env, header_str);
                    axiom_node_add_child(header_base_node, env, header_node);
                } else
                {
                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] failed in retrieving the response soap headers node");
                    return AXIS2_FAILURE;
                }
            }
        }
    }

    out_node = axiom_soap_body_get_base_node(out_body, env);
    if (!out_node)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] failed in retrieving the response soap body node");
        return AXIS2_FAILURE;
    }

    if (status != AXIS2_SUCCESS)
    {
        /* something went wrong, set a SOAP Fault */
        axis2_char_t *fault_value_str =
                AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" AXIOM_SOAP12_SOAP_FAULT_VALUE_SENDER;

        axis2_char_t *fault_reason_str = NULL;
        axis2_char_t *err_msg = NULL;

        if (!skel_invoked)
            fault_value_str = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" AXIOM_SOAP12_SOAP_FAULT_VALUE_RECEIVER;
        ;

        err_msg = (char *) AXIS2_ERROR_GET_MESSAGE(env->error);

        if (err_msg)
        {
            fault_reason_str = err_msg;
        } else
        {
            fault_reason_str = "Error occurred while processing SOAP message";
        }

        out_soap_fault = axiom_soap_fault_create_default_fault(env, out_body,
                fault_value_str, fault_reason_str, soap_version);
    }

    if (out_body_content_node)
    {
        axiom_node_add_child(out_node, env, out_body_content_node);
        status = axis2_msg_ctx_set_soap_envelope(out_msg_ctx, env,
                default_envelope);
    } else if (out_soap_fault)
    {
        axis2_msg_ctx_set_soap_envelope(out_msg_ctx, env, default_envelope);
        status = AXIS2_FAILURE; /* if there is a failure we have to return a failure code */
    } else
    {
        /* we should free the memory as the envelope is not used, one way case */
        axiom_soap_envelope_free(default_envelope, env);
        default_envelope = NULL;
    }
    return AXIS2_SUCCESS;
}
Esempio n. 13
0
AXIS2_EXTERN axiom_soap_header_t *AXIS2_CALL
axiom_soap_header_create_with_parent(
    const axutil_env_t * env,
    axiom_soap_envelope_t * envelope)
{
    axiom_soap_header_t *soap_header = NULL;

    /*axiom_element_t *this_ele = NULL;
     axiom_node_t *this_node = NULL;*/
    axiom_node_t *body_node = NULL;
    axiom_node_t *parent_node = NULL;
    axiom_element_t *parent_ele = NULL;

    /*axiom_namespace_t *parent_ns = NULL;*/

    AXIS2_PARAM_CHECK(env->error, envelope, NULL);

    soap_header = axiom_soap_header_create(env);
    if(!soap_header)
    {
        return NULL;
    }
    soap_header->soap_version = axiom_soap_envelope_get_soap_version(envelope, env);

    parent_node = axiom_soap_envelope_get_base_node(envelope, env);

    if(!parent_node || axiom_node_get_node_type(parent_node, env) != AXIOM_ELEMENT)
    {
        axiom_soap_header_free(soap_header, env);
        return NULL;
    }

    parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env);
    if(!parent_ele)
    {
        axiom_soap_header_free(soap_header, env);
        return NULL;
    }
    if(axiom_node_get_first_element(parent_node, env))
    {
        body_node = axiom_node_get_first_element(parent_node, env);
        axiom_node_detach(body_node, env);
    }

    /*parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node);
     this_ele = axiom_element_create(env, parent_node,
     AXIOM_SOAP_HEADER_LOCAL_NAME, parent_ns,
     &this_node);
     if (!this_ele)
     {
     axiom_soap_header_free(soap_header, env);
     return NULL;
     }

     soap_header->om_ele_node = this_node;*/

    axiom_soap_envelope_set_header(envelope, env, soap_header);

    if(body_node)
    {
        axiom_node_add_child(parent_node, env, body_node);
    }

    soap_header->soap_envelope = envelope;

    return soap_header;
}
Esempio n. 14
0
axis2_op_t *AXIS2_CALL
axis2_rest_disp_find_op(
    axis2_msg_ctx_t * msg_ctx,
    const axutil_env_t * env,
    axis2_svc_t * svc)
{
    axis2_endpoint_ref_t *endpoint_ref = NULL;
    axis2_op_t *op = NULL;
    axiom_soap_envelope_t *soap_env = NULL;
    axiom_soap_body_t *soap_body = NULL;
    axiom_element_t *body_child = NULL;
    axiom_node_t *body_child_node = NULL;
    axiom_node_t *body_element_node = NULL;
    axis2_bool_t soap_env_exists = AXIS2_TRUE;
    int i = 0;

    axutil_array_list_t *param_keys = NULL;
    axutil_array_list_t *param_values = NULL;

    AXIS2_PARAM_CHECK(env->error, svc, NULL);

    if(!axis2_msg_ctx_get_doing_rest(msg_ctx, env))
        return NULL;

    endpoint_ref = axis2_msg_ctx_get_to(msg_ctx, env);

    if(endpoint_ref)
    {
        const axis2_char_t *address = NULL;

        address = axis2_endpoint_ref_get_address(endpoint_ref, env);
        if(address)
        {
            axis2_char_t **url_tokens = NULL;

            url_tokens = axutil_parse_request_url_for_svc_and_op(env, address);

            if(url_tokens)
            {
                if(url_tokens[0])
                {
                    axis2_char_t *location = NULL;

                    location = strstr(address, url_tokens[0]);
                    if(location)
                    {
                        const axis2_char_t *method = NULL;

                        location += strlen(url_tokens[0]);
                        param_keys = axutil_array_list_create(env, 10);
                        if(!param_keys)
                        {
                            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                                "No memory. Cannot create the live rest parameter maps");
                            return NULL;
                        }
                        param_values = axutil_array_list_create(env, 10);

                        if(!param_values)
                        {
                            axutil_array_list_free(param_keys, env);
                            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                                "No memory. Cannot create the live rest parameter maps");
                            return NULL;
                        }
                        method = axis2_msg_ctx_get_rest_http_method(msg_ctx, env);
                        op = axis2_core_utils_get_rest_op_with_method_and_location(svc, env,
                            method, location, param_keys, param_values);
                    }
                }
                if(url_tokens[0])
                    AXIS2_FREE(env->allocator, url_tokens[0]);
                if(url_tokens[1])
                    AXIS2_FREE(env->allocator, url_tokens[1]);
                AXIS2_FREE(env->allocator, url_tokens);
            }
        }
    }

    if(!op)
    {
        if(param_keys)
        {
            for(i = 0; i < axutil_array_list_size(param_keys, env); i++)
            {
                void *value = axutil_array_list_get(param_keys, env, i);
                AXIS2_FREE(env->allocator, value);
            }
            axutil_array_list_free(param_keys, env);
        }
        if(param_values)
        {
            for(i = 0; i < axutil_array_list_size(param_values, env); i++)
            {
                void *value = axutil_array_list_get(param_values, env, i);
                AXIS2_FREE(env->allocator, value);
            }
            axutil_array_list_free(param_values, env);
        }
        return NULL;
    }

    soap_env = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);

    if(!soap_env)
    {
        soap_env_exists = AXIS2_FALSE;
        soap_env = axiom_soap_envelope_create_default_soap_envelope(env, AXIOM_SOAP11);
    }
    if(soap_env)
    {
        soap_body = axiom_soap_envelope_get_body(soap_env, env);
    }
    if(!soap_body)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL, AXIS2_FAILURE);

        if(param_keys)
        {
            for(i = 0; i < axutil_array_list_size(param_keys, env); i++)
            {
                void *value = axutil_array_list_get(param_keys, env, i);
                AXIS2_FREE(env->allocator, value);
            }
            axutil_array_list_free(param_keys, env);
        }
        if(param_values)
        {
            for(i = 0; i < axutil_array_list_size(param_values, env); i++)
            {
                void *value = axutil_array_list_get(param_values, env, i);
                AXIS2_FREE(env->allocator, value);
            }
            axutil_array_list_free(param_values, env);
        }
        return NULL;
    }

    body_element_node = axiom_soap_body_get_base_node(soap_body, env);

    if(body_element_node)
    {
        body_child_node = axiom_node_get_first_child(body_element_node, env);
    }

    if(!body_child_node)
    {
        body_child = axiom_element_create_with_qname(env, NULL, axis2_op_get_qname(op, env),
            &body_child_node);
        axiom_soap_body_add_child(soap_body, env, body_child_node);
    }

    if(param_keys && param_values)
    {
        for(i = 0; i < axutil_array_list_size(param_keys, env); i++)
        {
            axis2_char_t *param_key = NULL;
            axis2_char_t *param_value = NULL;

            axiom_node_t *node = NULL;
            axiom_element_t *element = NULL;

            param_key = axutil_array_list_get(param_keys, env, i);
            param_value = axutil_array_list_get(param_values, env, i);

            element = axiom_element_create(env, NULL, param_key, NULL, &node);
            axiom_element_set_text(element, env, param_value, node);
            axiom_node_add_child(body_child_node, env, node);

            AXIS2_FREE(env->allocator, param_key);
            AXIS2_FREE(env->allocator, param_value);
        }

        axutil_array_list_free(param_keys, env);
        axutil_array_list_free(param_values, env);
    }

    if(!soap_env_exists)
    {
        axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_env);
    }

    return op;
}
Esempio n. 15
0
//-----------------------------------------------------------------------------
void
sp_update_lineage(
    const axutil_env_t * env,
    const sp_props     *props,
    axiom_node_t *return_node,
    axiom_node_t *request_node,
    time_t        request_time)
{
    axiom_node_t *eom_node =
    		rp_find_named_child(env, return_node, "EOMetadata", 1);
    if (NULL == eom_node)
    {
    	rp_log_error(env, "*Warning S2P(%s:%d): %s node not found.\n",
    			__FILE__, __LINE__,  "EOMetadata");
    	return;
    }

    time_t lineage_time = 0;
    axiom_node_t *curr_lineage =
    		sp_latest_named(env, eom_node, "lineage", &lineage_time);

    // TODO: should improve handling of insignificant whitespace.

    // grab some whitespace for future use
    axiom_node_t *lin_whsp_node = sp_get_last_text_node(curr_lineage, env);
    axiom_node_t *eom_whsp_node = sp_get_last_text_node(eom_node,     env);

    const axis2_char_t *lin_whsp_str = sp_get_text_text(lin_whsp_node, env);
    const axis2_char_t *eom_whsp_str = sp_get_text_text(eom_whsp_node, env);
    int whspace_indent = SP_DEFAULT_WHSPACE;
    if (NULL != lin_whsp_str && NULL != eom_whsp_str)
    {
    	whspace_indent =
    			axutil_strlen(lin_whsp_str) - axutil_strlen(eom_whsp_str);
    	if (whspace_indent < 0 || whspace_indent >12)
    	{
    		rp_log_error(env,
    				"*Warning S2P: funny whitespace indent (%d) calculated.\n",
    				whspace_indent);
    		whspace_indent = SP_DEFAULT_WHSPACE;
    	}
    }

    axis2_char_t curr_whspace[SP_MAX_LOCAL_STR_LEN];
    strncpy(curr_whspace, lin_whsp_str, SP_MAX_LOCAL_STR_LEN-1);
    curr_whspace[SP_MAX_LOCAL_STR_LEN-1] = '\0';

    // The most recent Lineage data is deleted only if it has been added
    // in the time period since we started processing this request.
    if (NULL != curr_lineage && lineage_time >= request_time)
    {
    	// OK to delete lineage
    	axiom_node_detach    (curr_lineage, env);
		axiom_node_free_tree (curr_lineage, env);
		curr_lineage  = NULL;
		lin_whsp_node = NULL;
		lin_whsp_str  = NULL;
    }
    else
    {
    	sp_add_whspace(env, eom_node, curr_whspace);
    }

    // Add a new lineage.  here is an example:
    //    <wcseo:lineage>
    //        <wcseo:referenceGetCoverage>
    //            <ows:ServiceReference xlink:href="http://www.someWCS.org">
    //                <ows:RequestMessage>
    //                    <wcs:GetCoverage service="WCS" version="2.0.0">
    //                        <wcs:format>application/gml+xml</wcs:format>
    //                        <wcs:CoverageId>someEOCoverage1</wcs:CoverageId>
    //                    </wcs:GetCoverage>
    //                </ows:RequestMessage>
    //            </ows:ServiceReference>
    //        </wcseo:referenceGetCoverage>
    //        <gml:timePosition>2011-08-24T14:18:52Z</gml:timePosition>
    //    </wcseo:lineage>


    // <wcseo:lineage>
    axiom_node_t *lineage_node =
    		rp_add_child_el(env, eom_node, "lineage", NULL);

    sp_inc_whspace(curr_whspace, whspace_indent);
    sp_add_whspace(env, lineage_node, curr_whspace);

    // comment
    axiom_node_t *comment  = axiom_node_create(env);
    axiom_comment_create (
    		env,
    		lineage_node,
    		"POST GetCoverage request added by SOAP-TO-POST proxy.",
    		&comment);

	//<wcseo:referenceGetCoverage>
	axiom_node_t *ref_g1_node =
			rp_add_child_el(env, lineage_node, "referenceGetCoverage", curr_whspace);

	// <ows:ServiceReference xlink:href="http://www.someWCS.org">
    sp_inc_whspace(curr_whspace, whspace_indent);
    sp_add_whspace(env, ref_g1_node, curr_whspace);
	axiom_namespace_t *ows_ns =
			sp_find_or_create_ns(env, return_node, SP_OWS_NAMESPACE_STR, "ows");

    axiom_node_t    *service_ref_node = axiom_node_create(env);
    axiom_element_t *service_ref_el =
      axiom_element_create(
    		  env, ref_g1_node, "ServiceReference", ows_ns, &service_ref_node);

	axiom_namespace_t *xlink_ns = sp_find_or_create_ns(
			env, return_node, SP_XLINK_NAMESPACE_STR, "xlink");

    axiom_attribute_t *attr =
      axiom_attribute_create (env, "type", "simple", xlink_ns);
    axiom_element_add_attribute (service_ref_el, env, attr, service_ref_node);

    attr = axiom_attribute_create (env, "href", rp_getSoapOpsURL(env, props), xlink_ns);
    axiom_element_add_attribute (service_ref_el, env, attr, service_ref_node);

    //<ows:RequestMessage>
    axiom_node_t *req_msg_node =
    		rp_add_child_el(env,
    				service_ref_node, "RequestMessage", curr_whspace);
    sp_inc_whspace(curr_whspace, whspace_indent);


    // Detach the request GetCoverage element from its parent
    //  and attach it here.
    axiom_node_t *gc_node =
    		rp_find_named_node(env, request_node, "GetCoverage", 1);
    if (gc_node)
    {
    	// TODO - pretty-up the the indentation to match current.
        sp_add_whspace(env, req_msg_node, curr_whspace);
    	axiom_node_detach    (gc_node, env);
    	axiom_node_add_child (req_msg_node, env, gc_node);
    }

    // Adjust the indentation of closing tags
    sp_inc_whspace(curr_whspace, -whspace_indent);
    sp_add_whspace(env, req_msg_node, curr_whspace);
    sp_inc_whspace(curr_whspace, -whspace_indent);
    sp_add_whspace(env, service_ref_node, curr_whspace);
    sp_inc_whspace(curr_whspace, -whspace_indent);
    sp_add_whspace(env, ref_g1_node, curr_whspace);
    sp_inc_whspace(curr_whspace, -whspace_indent);

    //<gml:timePosition>2011-08-24T14:18:52Z</gml:timePosition>
    sp_add_whspace(env, lineage_node, curr_whspace);
	axiom_namespace_t *gml_ns = sp_find_or_create_ns(
			env, return_node, SP_GML_NAMESPACE_STR, "gml");

    axiom_node_t    *time_pos_node = axiom_node_create(env);
    axiom_element_t *time_pos_el = axiom_element_create(
    		env, lineage_node, "timePosition", gml_ns, &time_pos_node);

    char tmbuf[22];
    sp_time_str(tmbuf, time(NULL));
    axiom_element_set_text(time_pos_el, env, tmbuf, time_pos_node);

    // Adjust the indentation of remaining closing tags
    sp_inc_whspace(curr_whspace, -whspace_indent);
    sp_add_whspace(env, lineage_node, curr_whspace);

    // Adjust whitespace before the element
    // that follows our new lineage element, whatever it may be.
    sp_add_whspace(env, eom_node, eom_whsp_str);

    // Delete the whitespace before any our insertions.
	axiom_node_detach    (eom_whsp_node, env);
	axiom_node_free_tree (eom_whsp_node, env);
}
AXIS2_EXTERN axis2_status_t AXIS2_CALL
rampart_shb_build_message(
    const axutil_env_t *env,
    axis2_msg_ctx_t *msg_ctx,
    rampart_context_t *rampart_context,
    axiom_soap_envelope_t *soap_envelope)
{
    axis2_status_t status = AXIS2_SUCCESS;
    axiom_soap_header_t *soap_header = NULL;
    axiom_node_t *soap_header_node = NULL;
    axiom_element_t *soap_header_ele = NULL;
    axiom_soap_header_block_t *sec_header_block = NULL;
    axiom_namespace_t *sec_ns_obj = NULL;
    axiom_node_t *sec_node =  NULL;
    axiom_element_t *sec_ele = NULL;
    axis2_bool_t server_side = AXIS2_FALSE;
	/* 
	 * sign parts list. Moved this up the building process. This was originally 
	 * in the rampart_sig_sign_message 
	 */ 
    axutil_array_list_t *sign_parts_list = NULL;
    AXIS2_ENV_CHECK(env,AXIS2_FAILURE);
    soap_header  = axiom_soap_envelope_get_header(soap_envelope, env);
    soap_header_node = axiom_soap_header_get_base_node(soap_header, env);
    soap_header_ele = (axiom_element_t *)axiom_node_get_data_element(
                          soap_header_node, env);


    sec_ns_obj =  axiom_namespace_create(env, RAMPART_WSSE_XMLNS,
                                         RAMPART_WSSE);
    sec_header_block = axiom_soap_header_add_header_block(soap_header,
                       env, RAMPART_SECURITY, sec_ns_obj); /* sec_ns_obj is cloned there */
    server_side = axis2_msg_ctx_get_server_side(msg_ctx, env);
    if(!sec_header_block)
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart][shb] Security header block is NULL");
		axiom_namespace_free(sec_ns_obj, env);
        return AXIS2_SUCCESS;
    }

    axiom_soap_header_block_set_must_understand_with_bool(sec_header_block,
            env, AXIS2_TRUE);

    sec_node = axiom_soap_header_block_get_base_node(sec_header_block, env);
    sec_ele = (axiom_element_t *)
              axiom_node_get_data_element(sec_node, env);

    sign_parts_list = axutil_array_list_create(env, 4);
    /*Timestamp Inclusion*/
    if(rampart_context_is_include_timestamp(rampart_context,env))
    {
        int ttl = -1;
        axis2_bool_t need_millisecond = AXIS2_TRUE;

        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart][shb] Building Timestamp Token");
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart][shb] Using default timeToLive value %d",
                       RAMPART_TIMESTAMP_TOKEN_DEFAULT_TIME_TO_LIVE);
        ttl = rampart_context_get_ttl(rampart_context,env);
        need_millisecond = rampart_context_get_need_millisecond_precision(rampart_context, env);

        status = rampart_timestamp_token_build(env, sec_node, ttl, need_millisecond);
        if (status == AXIS2_FAILURE)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                            "[rampart][shb] Timestamp Token build failed. ERROR");
			axiom_namespace_free(sec_ns_obj, env);
            return AXIS2_FAILURE;
        }
    }

    /*Check whether we need username token*/
    /*User name tokens includes in messages sent from client to server*/
    if(!axis2_msg_ctx_get_server_side(msg_ctx,env))
    {
        if(rampart_context_is_include_username_token(rampart_context,env))
        {

            /*Now we are passing rampart_context here so inside this method
            relevant parameters are extracted. */

            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart][shb] Building UsernameToken");
            status = rampart_username_token_build(
                        env,
                        rampart_context,
                        sec_node,
                        sec_ns_obj);
            if (status == AXIS2_FAILURE)
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                                "[rampart][shb] UsernameToken build failed. ERROR");
				axiom_namespace_free(sec_ns_obj, env);
                return AXIS2_FAILURE;
            }
        }
    }

    /*Custom tokens are included if its available in the rampart context*/
    if(!axis2_msg_ctx_get_server_side(msg_ctx,env))
    {
        axutil_array_list_t *token_list = NULL;

        token_list = rampart_context_get_custom_tokens(rampart_context, env);
        if(token_list){
            int size = 0, i = 0;
            size = axutil_array_list_size(token_list, env);
            for (i = 0; i < size; i++){
                axiom_node_t *token_node = NULL;
                token_node = (axiom_node_t*)axutil_array_list_get(token_list, env, i);
                if(token_node){
                    axis2_status_t status = AXIS2_FAILURE;
                    status = axiom_node_add_child(sec_node, env, token_node); 
                    if(status != AXIS2_SUCCESS){
                        return AXIS2_FAILURE;
                    }
                }
            }
        }
    }

    if (rampart_context_is_include_supporting_token(rampart_context, env, server_side, AXIS2_FALSE, RP_PROPERTY_SAML_TOKEN))
    {        
        status = rampart_saml_supporting_token_build(env, rampart_context, sec_node, sign_parts_list);    
        if (status == AXIS2_FAILURE)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                            "[rampart][shb] SAML Supporting token build failed. ERROR");
            axutil_array_list_free(sign_parts_list, env);
			axiom_namespace_free(sec_ns_obj, env);
            return AXIS2_FAILURE;
        }
    }

	if (rampart_context_is_include_supporting_token(rampart_context, env, server_side, AXIS2_FALSE, RP_PROPERTY_ISSUED_TOKEN))
	{
		status = rampart_issued_supporting_token_build(rampart_context, env, sec_node, sign_parts_list);					
        if (status == AXIS2_FAILURE)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                            "[rampart][shb] Issued supporting token build failed. ERROR");
            axutil_array_list_free(sign_parts_list, env);
			axiom_namespace_free(sec_ns_obj, env);
            return AXIS2_FAILURE;
        }
	}

    /*Signature Confirmation support. Only in the server side*/
    if(axis2_msg_ctx_get_server_side(msg_ctx,env)){
        axis2_bool_t sign_conf_reqd = AXIS2_FALSE;
        /*Sign_conf_reqd <- Get from context <- policy*/
        sign_conf_reqd = rampart_context_is_sig_confirmation_reqd(rampart_context, env);
        if(sign_conf_reqd){
            status = rampart_sig_confirm_signature(env, msg_ctx, rampart_context, sec_node);
        }
    }


    /*check the binding*/
    if((rampart_context_get_binding_type(rampart_context,env)) == RP_PROPERTY_ASYMMETRIC_BINDING)
    {
        axis2_status_t status = AXIS2_FAILURE;

        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart][shb] Asymmetric Binding. ");
        status = rampart_shb_do_asymmetric_binding(env, msg_ctx, rampart_context, soap_envelope, sec_node, sec_ns_obj, sign_parts_list);
		axiom_namespace_free(sec_ns_obj, env);
        if(AXIS2_FAILURE == status){
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart][shb] Asymmetric Binding failed");
            if(axis2_msg_ctx_get_server_side(msg_ctx,env)){
                AXIS2_ERROR_SET(env->error, RAMPART_ERROR_INVALID_SECURITY , AXIS2_FAILURE);
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,  "[rampart][shb] %s", AXIS2_ERROR_GET_MESSAGE(env->error));
                rampart_create_fault_envelope(env, RAMPART_FAULT_INVALID_SECURITY,
                                  " Asymmetric Binding failed. Check configurations ", RAMPART_FAULT_IN_POLICY, msg_ctx);
            }
            axutil_array_list_free(sign_parts_list, env);
            return AXIS2_FAILURE;
        }else{
            axutil_array_list_free(sign_parts_list, env);
            return AXIS2_SUCCESS;
        }

    }
    else if((rampart_context_get_binding_type(rampart_context,env)) == RP_PROPERTY_SYMMETRIC_BINDING)
    {
        axis2_status_t status = AXIS2_FAILURE;

        /*Do Symmetric_binding specific things*/
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart][shb] Symmetric Binding. ");
        status = rampart_shb_do_symmetric_binding(env, msg_ctx, rampart_context, soap_envelope, sec_node, sec_ns_obj, sign_parts_list);
		axiom_namespace_free(sec_ns_obj, env);
        if(AXIS2_FAILURE == status){
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart][shb] Symmetric Binding failed");
            if(axis2_msg_ctx_get_server_side(msg_ctx,env)){
                AXIS2_ERROR_SET(env->error, RAMPART_ERROR_INVALID_SECURITY, AXIS2_FAILURE);
                rampart_create_fault_envelope(env, RAMPART_FAULT_INVALID_SECURITY,
                                  " Symmetric Binding failed. Check configurations ", RAMPART_FAULT_IN_POLICY, msg_ctx);
            }
            axutil_array_list_free(sign_parts_list, env);
            return AXIS2_FAILURE;
        }else{
            axutil_array_list_free(sign_parts_list, env);
            return AXIS2_SUCCESS;
        }
    }
    else if((rampart_context_get_binding_type(rampart_context,env)) == RP_PROPERTY_TRANSPORT_BINDING)
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart][shb] Using transport binding");
		axiom_namespace_free(sec_ns_obj, env);
        axutil_array_list_free(sign_parts_list, env);
        return AXIS2_SUCCESS;
    }else{
        axutil_array_list_free(sign_parts_list, env);
		axiom_namespace_free(sec_ns_obj, env);
        return AXIS2_FAILURE;
    }
}
Esempio n. 17
0
        axiom_node_t* AXIS2_CALL
        adb_source_serialize_obj(
                adb_source_t* _source,
                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, _source, NULL);
            
             
                    namespaces = axutil_hash_make(env);
                    next_ns_index = &next_ns_index_value;
                     
                           ns1 = axiom_namespace_create (env,
                                             "http://purl.org/dc/elements/1.1/",
                                             "n"); 
                           axutil_hash_set(namespaces, "http://purl.org/dc/elements/1.1/", AXIS2_HASH_KEY_STRING, axutil_strdup(env, "n"));
                       
                     
                    parent_element = axiom_element_create (env, NULL, "source", 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://purl.org/dc/elements/1.1/", 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://purl.org/dc/elements/1.1/", AXIS2_HASH_KEY_STRING, p_prefix);
                           
                           axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env,
                                            "http://purl.org/dc/elements/1.1/",
                                            p_prefix));
                       }
                      

                   if (!_source->is_valid_source)
                   {
                      
                            
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-nillable property source");
                            return NULL;
                          
                   }
                   else
                   {
                     start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) *
                                 (4 + axutil_strlen(p_prefix) + 
                                  axutil_strlen("source"))); 
                                 
                                 /* 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("source")));
                                  /* axutil_strlen("</:>") + 1 = 5 */
                                  
                     

                   
                   
                     
                     /*
                      * parsing source element
                      */

                    
                    
                            sprintf(start_input_str, "<%s%ssource>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                            
                        start_input_str_len = axutil_strlen(start_input_str);
                        sprintf(end_input_str, "</%s%ssource>",
                                 p_prefix?p_prefix:"",
                                 (p_prefix && axutil_strcmp(p_prefix, ""))?":":"");
                        end_input_str_len = axutil_strlen(end_input_str);
                    
                                text_value_1 = NULL; /* just to bypass the warning unused variable */
                                axiom_node_add_child(parent, env, _source->property_source);
                              
                     
                     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;
        }
Esempio n. 18
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
oxs_xml_enc_encrypt_data(
    const axutil_env_t *env,
    oxs_ctx_t * enc_ctx,
    oxs_buffer_t *content_buf,
    axiom_node_t **enc_type_node,
    axiom_node_t *security_token_reference_node)
{
    oxs_buffer_t *result_buf = NULL;
    oxs_key_t *sym_key = NULL;
    axis2_char_t *sym_algo = NULL;
    axiom_node_t *enc_mtd_node = NULL;
    axiom_node_t *cd_node = NULL;
    axiom_node_t *cv_node = NULL;
    axis2_status_t ret = AXIS2_FAILURE;

    /*Determine the algorithm to be used*/
    sym_algo = oxs_ctx_get_enc_mtd_algorithm(enc_ctx, env);

    /*Determine the key to be used*/
    sym_key = oxs_ctx_get_key(enc_ctx, env);

    /*Set the operation to encrypt*/
    oxs_ctx_set_operation(enc_ctx, env, OXS_CTX_OPERATION_ENCRYPT);

    /*Create an empty buffer for encrypted data*/
    result_buf = oxs_buffer_create(env);
    /*Call encryption. Result should be base64 encoded*/
    ret = oxs_encryption_symmetric_crypt(env, enc_ctx, content_buf, result_buf);

    /*Create EncryptionMethod*/
    enc_mtd_node = oxs_token_build_encryption_method_element(env, *enc_type_node, sym_algo);

    /*If security_token_reference_node is given, then use it to build the key info*/
    /*if we are using any trust/sct related token, then the key reference is given with the token
     *and we are suppose to use it */
    if(security_token_reference_node)
    {
        axiom_node_t *key_info_node = NULL;
        key_info_node = oxs_token_build_key_info_element(env, *enc_type_node);
        axiom_node_add_child(key_info_node, env, security_token_reference_node);
    }
    /*If the enc_ctx has a key name, then build the KeyInfo element using key name*/
    else if(oxs_ctx_get_ref_key_name(enc_ctx, env))
    {
        axiom_node_t *key_info_node = NULL;
        axiom_node_t *str_node = NULL;
        axiom_node_t *ref_node = NULL;

        key_info_node = oxs_token_build_key_info_element(env, *enc_type_node);
        str_node = oxs_token_build_security_token_reference_element(env, key_info_node);
        ref_node = oxs_token_build_reference_element(env, str_node, oxs_ctx_get_ref_key_name(
            enc_ctx, env), NULL);
    }

    /*Create CipherData element and populate*/
    cd_node = oxs_token_build_cipher_data_element(env, *enc_type_node);
    cv_node = oxs_token_build_cipher_value_element(env, cd_node,
        (axis2_char_t*)oxs_buffer_get_data(result_buf, env));

    /*Free buffers*/
    oxs_buffer_free(result_buf, env);
    result_buf = NULL;

    return AXIS2_SUCCESS;
}
Esempio n. 19
0
/*Build RSTR */
AXIS2_EXTERN axiom_node_t * AXIS2_CALL
trust_rstr_build_rstr(
        trust_rstr_t *rstr,
        const axutil_env_t *env,
        axiom_node_t *parent)
{
    axiom_node_t *rstr_node = NULL;
    axis2_char_t *key_size = NULL;
    
    rstr_node = (axiom_node_t*)trust_util_create_rstr_element(env, rstr->wst_ns_uri, rstr->attr_context);

    if(rstr_node)
    {
        if(rstr->token_type)
        {
            if(NULL == (axiom_node_t*)trust_util_create_token_type_element(env, rstr->wst_ns_uri, rstr_node, rstr->token_type))
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[trust] RSTR TokenType element creation failed.");
                return NULL;
            }
        }
        
        if(rstr->requested_sec_token)
        {
            if(NULL == (axiom_node_t*)trust_util_create_requested_security_token_element(env, rstr->wst_ns_uri, rstr_node, rstr->requested_sec_token))
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[trust] RSTR ReqSecToken element creation failed.");
                return NULL;
            }
            
        }

		if(rstr->requested_proof_token)
		{
			/*Appending generic proof token node to RSTR - Here proof token can be just a session key, entropy node with binary secret
			 * Creating the proof token is completely up to the user. Eventhough, there are some default util methods provided by trust_util to create 
			 * proof tokens. 
			*/
			axiom_node_add_child(rstr_node, env, rstr->requested_proof_token);
		}

        if(rstr->applies_to)
        {
            if(NULL == (axiom_node_t*)trust_util_create_applies_to_element(env, rstr_node, rstr->applies_to, TRUST_WSA_XMLNS))
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[trust] RSTR AppliesTo element creation failed.");
                return NULL;
            }
        }
        if(rstr->requested_attached_ref)
        {
            axiom_node_t* attached_ref = NULL;
            attached_ref = trust_util_create_req_attached_reference_element(env, rstr->wst_ns_uri, rstr_node);
            if(NULL == attached_ref)
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[trust] RSTR AttachedReference element creation failed.");
                return NULL;   
            }
            axiom_node_add_child(attached_ref, env, rstr->requested_attached_ref);
            
        }
        if(rstr->requested_unattached_ref)
        {
            axiom_node_t* unattached_ref = NULL;
            unattached_ref = trust_util_create_req_unattached_reference_element(env, rstr->wst_ns_uri, rstr_node);
            if(NULL == unattached_ref)
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[trust] RSTR UnattachedReference element creation failed.");
                return NULL;   
            }
            axiom_node_add_child(unattached_ref, env, rstr->requested_unattached_ref);
        }
        
        if(rstr->entropy)
        {
            if(NULL == trust_entropy_serialize(rstr->entropy, env, rstr_node))
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[trust] RSTR Entropy element creation failed.");
                return NULL;
            }
        }
        
        if(rstr->life_time)
        {
            if(NULL == trust_life_time_serialize(rstr->life_time, env, rstr_node))
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[trust] RSTR LifeTime element creation failed.");
                return NULL;
            }
        }
        
        if(rstr->key_size > 0)
        {
            /*INFO -keysize Malloc Size = 128 */
            key_size = AXIS2_MALLOC( env->allocator, sizeof(char)*128);
            sprintf(key_size, "%d", rstr->key_size);
            if(NULL == (axiom_node_t*)trust_util_create_key_size_element(env, rstr->wst_ns_uri, rstr_node, key_size))
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[trust] KeySize element creation failed.");
                return NULL; 
            }
        }
        return rstr_node;
    }
	return NULL;
}
static axis2_status_t AXIS2_CALL
axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync(
    axis2_msg_recv_t * msg_recv,
    const axutil_env_t * env,
    axis2_msg_ctx_t * msg_ctx,
    axis2_msg_ctx_t * new_msg_ctx)
{
    axis2_svc_skeleton_t *svc_obj = NULL;
    axis2_op_ctx_t *op_ctx = NULL;
    axis2_op_t *op_desc = NULL;
    const axis2_char_t *style = NULL;
    axiom_node_t *om_node = NULL;
    axiom_element_t *om_element = NULL;
    axis2_char_t *local_name = NULL;
    axiom_node_t *result_node = NULL;
    axiom_node_t *body_content_node = NULL;
    axiom_element_t *body_content_element = NULL;
    axiom_soap_envelope_t *default_envelope = NULL;
    axiom_soap_body_t *out_body = NULL;
    axiom_soap_header_t *out_header = NULL;
    axiom_soap_fault_t *soap_fault = NULL;
    axiom_node_t *out_node = NULL;
    axis2_status_t status = AXIS2_SUCCESS;
    axis2_bool_t skel_invoked = AXIS2_FALSE;
    const axis2_char_t *soap_ns = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI;
    int soap_version = AXIOM_SOAP12;
    axiom_namespace_t *env_ns = NULL;
    axiom_node_t *fault_node = NULL;
    axiom_soap_fault_detail_t *fault_detail;
    axis2_bool_t is_fault = AXIS2_FALSE;

    AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, new_msg_ctx, AXIS2_FAILURE);

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
        "[axis2]Entry:axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync");

    /* get the implementation class for the Web Service */
    svc_obj = axis2_msg_recv_make_new_svc_obj(msg_recv, env, msg_ctx);

    if(!svc_obj)
    {
        const axis2_char_t *svc_name = NULL;
        axis2_svc_t *svc = axis2_msg_ctx_get_svc(msg_ctx, env);

        if(svc)
        {
            svc_name = axis2_svc_get_name(svc, env);
        }
        else
        {
            svc_name = "unknown";
        }

        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Impl object for service '%s' not set in message receiver. %d :: %s", svc_name,
            env->error->error_number, AXIS2_ERROR_GET_MESSAGE(env->error));

        status = AXIS2_FAILURE;
    }
    else
    {
        op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
        op_desc = axis2_op_ctx_get_op(op_ctx, env);

        style = axis2_op_get_style(op_desc, env);
        if(0 == axutil_strcmp(AXIS2_STYLE_DOC, style))
        {
            axiom_soap_envelope_t *envelope = NULL;
            axiom_soap_body_t *body = NULL;

            envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
            body = axiom_soap_envelope_get_body(envelope, env);
            om_node = axiom_soap_body_get_base_node(body, env);
            om_element = axiom_node_get_data_element(om_node, env);
            om_node = axiom_node_get_first_element(om_node, env);
        }
        else if(0 == axutil_strcmp(AXIS2_STYLE_RPC, style))
        {
            axiom_soap_envelope_t *envelope = NULL;
            axiom_soap_body_t *body = NULL;
            axiom_node_t *op_node = NULL;
            axiom_element_t *op_element = NULL;

            envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
            body = axiom_soap_envelope_get_body(envelope, env);
            op_node = axiom_soap_body_get_base_node(body, env);
            op_element = axiom_node_get_data_element(op_node, env);
            if(op_element)
            {
                local_name = axiom_element_get_localname(op_element, env);
                if(local_name)
                {
                    axutil_array_list_t *function_arr = NULL;
                    int i = 0;
                    int size = 0;
                    axis2_bool_t matches = AXIS2_FALSE;

                    function_arr = svc_obj->func_array;
                    if(function_arr)
                    {
                        size = axutil_array_list_size(function_arr, env);
                    }

                    for(i = 0; i < size; i++)
                    {
                        axis2_char_t *function_name = NULL;

                        function_name = (axis2_char_t *)axutil_array_list_get(function_arr, env, i);
                        if(!axutil_strcmp(function_name, local_name))
                        {
                            matches = AXIS2_TRUE;

                        }
                    }

                    if(matches)
                    {
                        om_node = axiom_node_get_first_child(op_node, env);
                        om_element = axiom_node_get_data_element(om_node, env);
                    }
                    else
                    {
                        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OM_ELEMENT_MISMATCH, AXIS2_FAILURE);
                        status = AXIS2_FAILURE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OM_ELEMENT_INVALID_STATE, AXIS2_FAILURE);
                    status = AXIS2_FAILURE;
                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error, AXIS2_ERROR_RPC_NEED_MATCHING_CHILD, AXIS2_FAILURE);
                status = AXIS2_FAILURE;
            }
        }
        else
        {
            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_UNKNOWN_STYLE, AXIS2_FAILURE);
            status = AXIS2_FAILURE;
        }

        if(status == AXIS2_SUCCESS)
        {
            skel_invoked = AXIS2_TRUE;
            result_node = AXIS2_SVC_SKELETON_INVOKE(svc_obj, env, om_node, new_msg_ctx);
        }

        if(result_node)
        {
            if(0 == axutil_strcmp(style, AXIS2_STYLE_RPC))
            {
                axiom_namespace_t *ns = NULL;
                axis2_char_t *res_name = NULL;

                res_name = axutil_stracat(env, local_name, "Response");
                ns = axiom_namespace_create(env, "http://soapenc/", "res");
                if(!ns)
                {
                    status = AXIS2_FAILURE;
                }
                else
                {
                    body_content_element = axiom_element_create(env, NULL, res_name, ns,
                        &body_content_node);
                    axiom_node_add_child(body_content_node, env, result_node);
                }
            }
            else
            {
                body_content_node = result_node;
            }
        }
        else
        {
            axis2_char_t *mep = (axis2_char_t *)axis2_op_get_msg_exchange_pattern(op_desc, env);
            if(axutil_strcmp(mep, AXIS2_MEP_URI_IN_ONLY) && axutil_strcmp(mep,
				AXIS2_MEP_URI_ROBUST_IN_ONLY) && axutil_strcmp(mep, AXIS2_MEP_URI_IN_ONLY_WSDL2) &&						axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY_WSDL2))
            {
                status = AXIS2_ERROR_GET_STATUS_CODE(env->error);
                if(status == AXIS2_SUCCESS)
                {
                    axis2_msg_ctx_set_no_content(new_msg_ctx, env, AXIS2_TRUE);
                }
                else
                {
                    axis2_msg_ctx_set_status_code(msg_ctx, env, axis2_msg_ctx_get_status_code(
                        new_msg_ctx, env));
                }
                /* The new_msg_ctx is passed to the service. The status code must
                 * be taken from here and set to the old message context which is
                 * used by the worker when the request processing fails.
                 */
                if(svc_obj->ops->on_fault)
                {
                    fault_node = AXIS2_SVC_SKELETON_ON_FAULT(svc_obj, env, om_node);
                }
                is_fault = AXIS2_TRUE;
            }
            else
            {
                /* If we have a in only message result node is NULL. We create fault only if
                 * an error is set
                 */
                status = AXIS2_ERROR_GET_STATUS_CODE(env->error);
                if(status == AXIS2_SUCCESS)
                {
                    axis2_msg_ctx_set_no_content(new_msg_ctx, env, AXIS2_TRUE);
                }
                else
                {
                    axis2_msg_ctx_set_status_code(msg_ctx, env, axis2_msg_ctx_get_status_code(
                        new_msg_ctx, env));
					if((!axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY)) || 
						(!axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY_WSDL2)))
                    {
                        /* The new_msg_ctx is passed to the service. The status code must
                         * be taken from here and set to the old message context which is
                         * used by the worker when the request processing fails.
                         */
                        if(svc_obj->ops->on_fault)
                        {
                            fault_node = AXIS2_SVC_SKELETON_ON_FAULT(svc_obj, env, om_node);
                        }
                        is_fault = AXIS2_TRUE;
                    }
                }
            }
        }
    }

    if(msg_ctx && axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
    {
        soap_ns = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; /* default is 1.2 */
        soap_version = AXIOM_SOAP11;
    }

    if(axis2_msg_ctx_get_soap_envelope(new_msg_ctx, env))
    {
        /* service implementation has set the envelope,
         useful when setting a SOAP fault.
         No need to further process */
        return AXIS2_SUCCESS;
    }

    /* create the soap envelope here */
    env_ns = axiom_namespace_create(env, soap_ns, "soapenv");
    if(!env_ns)
    {
        return AXIS2_FAILURE;
    }

    default_envelope = axiom_soap_envelope_create(env, env_ns);
	axiom_namespace_free(env_ns, env);

    if(!default_envelope)
    {
        return AXIS2_FAILURE;
    }

    out_header = axiom_soap_header_create_with_parent(env, default_envelope);
    if(!out_header)
    {
        return AXIS2_FAILURE;
    }

    out_body = axiom_soap_body_create_with_parent(env, default_envelope);
    if(!out_body)
    {
        return AXIS2_FAILURE;
    }

    out_node = axiom_soap_body_get_base_node(out_body, env);
    if(!out_node)
    {
        return AXIS2_FAILURE;
    }

    if(status != AXIS2_SUCCESS || is_fault)
    {
        /* something went wrong. set a SOAP Fault */
        const axis2_char_t *fault_value_str = "soapenv:Sender";
        const axis2_char_t *fault_reason_str = NULL;
        const axis2_char_t *err_msg = NULL;

        if(!skel_invoked)
        {
            if(axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
            {
fault_value_str            =
            AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
            AXIOM_SOAP11_FAULT_CODE_RECEIVER;
        }
        else
        {
            fault_value_str =
            AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
            AXIOM_SOAP12_SOAP_FAULT_VALUE_RECEIVER;
        }
    }

    err_msg = AXIS2_ERROR_GET_MESSAGE(env->error);
    if (err_msg && axutil_strcmp(err_msg, ""))
    {
        if(!axutil_strcmp(err_msg, "No Error"))
        {
            fault_reason_str = "An error has occurred, but could not determine exact details";
        }
        else
        {
            fault_reason_str = err_msg;
        }
    }
    else
    {
        fault_reason_str = "An error has occurred, but could not determine exact details";
    }

    soap_fault = axiom_soap_fault_create_default_fault(env, out_body, fault_value_str,
        fault_reason_str, soap_version);

    if (fault_node)
    {
        axiom_node_t *fault_detail_node = NULL;
        axis2_char_t *om_str = NULL;

        fault_detail = axiom_soap_fault_detail_create_with_parent(env, soap_fault);
        fault_detail_node = axiom_soap_fault_detail_get_base_node(fault_detail, env);

        om_str = axiom_node_to_string(fault_detail_node, env);
        if (om_str)
        {
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "fault_detail:%s", om_str);
            AXIS2_FREE(env->allocator, om_str);
        }

        axiom_soap_fault_detail_add_detail_entry(fault_detail, env, fault_node);
    }
}

if (body_content_node)
{
    axiom_node_add_child(out_node, env, body_content_node);
    status = axis2_msg_ctx_set_soap_envelope(new_msg_ctx, env, default_envelope);
}
else if (soap_fault)
{
    axis2_msg_ctx_set_soap_envelope(new_msg_ctx, env, default_envelope);
    status = AXIS2_SUCCESS;
}
else
{
    /* we should free the memory as the envelope is not used, one way case */
    axiom_soap_envelope_free(default_envelope, env);
    default_envelope = NULL;
}

AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
    "[axis2]Exit:axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync");

return status;
}
Esempio n. 21
0
/**
 * Creates <wsse:BinarySecurityToken> element
 */
AXIS2_EXTERN axiom_node_t* AXIS2_CALL
oxs_token_build_binary_security_token_element(
    const axutil_env_t *env,
    axiom_node_t *parent,
    axis2_char_t* id,
    axis2_char_t* encoding_type,
    axis2_char_t* value_type,
    axis2_char_t* data)
{
    axiom_node_t *binary_sec_token_node = NULL;
    axiom_node_t *first_child_of_parent = NULL;
    axiom_element_t *binary_security_token_ele = NULL;
    axiom_attribute_t *encoding_type_att = NULL;
    axiom_attribute_t *value_type_att = NULL;
    axiom_attribute_t *id_attr = NULL;
    axiom_namespace_t *ns_obj = NULL;
    axiom_namespace_t *ns = NULL;

    ns_obj = axiom_namespace_create(env, OXS_WSSE_NS, OXS_WSSE);
    ns = axiom_namespace_create(env, RAMPART_WSU_XMLNS, OXS_WSU);

    binary_security_token_ele = axiom_element_create(env, parent, OXS_NODE_BINARY_SECURITY_TOKEN,
        ns_obj, &binary_sec_token_node);
    if(!binary_security_token_ele)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart]Error creating %s element.",
            OXS_NODE_BINARY_SECURITY_TOKEN);
        axiom_namespace_free(ns_obj, env);
        axiom_namespace_free(ns, env);
        return NULL;
    }

    /* Binary security token must be added as the first child of the paretn */
    binary_sec_token_node = axiom_node_detach_without_namespaces(binary_sec_token_node, env);
    first_child_of_parent = axiom_node_get_first_element(parent, env);
    if(first_child_of_parent)
    {
        /* If there is a child add bst before it */
        axiom_node_insert_sibling_before(first_child_of_parent, env, binary_sec_token_node);
    }
    else
    {
        /* If there are no children just add the bst */
        axiom_node_add_child(parent, env, binary_sec_token_node);
    }

    if(!id)
    {
        id = oxs_util_generate_id(env, (axis2_char_t*)OXS_CERT_ID);
    }

    id_attr = axiom_attribute_create(env, OXS_ATTR_ID, id, ns);
    encoding_type_att = axiom_attribute_create(env, OXS_ATTR_ENCODING_TYPE, encoding_type, NULL);
    value_type_att = axiom_attribute_create(env, OXS_ATTR_VALUE_TYPE, value_type, NULL);

    axiom_element_add_attribute(binary_security_token_ele, env, id_attr,
        binary_sec_token_node);
    axiom_element_add_attribute(binary_security_token_ele, env, encoding_type_att,
        binary_sec_token_node);
    axiom_element_add_attribute(binary_security_token_ele, env, value_type_att,
        binary_sec_token_node);

    if(data)
    {
        axiom_element_set_text(binary_security_token_ele, env, data,
            binary_sec_token_node);
    }

    return binary_sec_token_node;
}
Esempio n. 22
0
static axis2_bool_t
axis2_svc_client_fill_soap_envelope(
    const axutil_env_t * env,
    axis2_svc_client_t * svc_client,
    axis2_msg_ctx_t * msg_ctx,
    const axiom_node_t * payload)
{
    const axis2_char_t *soap_version_uri;
    int soap_version;
    axiom_soap_envelope_t *envelope = NULL;
    AXIS2_PARAM_CHECK(env->error, svc_client, AXIS2_FAILURE);

    soap_version_uri = axis2_options_get_soap_version_uri(svc_client->options, env);

    if(!soap_version_uri)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot find soap version uri.");
        return AXIS2_FALSE;
    }

    if(axutil_strcmp(soap_version_uri, AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI) == 0)
    {
        soap_version = AXIOM_SOAP11;
    }
    else
    {
        soap_version = AXIOM_SOAP12;
    }

    envelope = axiom_soap_envelope_create_default_soap_envelope(env, soap_version);
    if(!envelope)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create default soap envelope.");
        return AXIS2_FALSE;
    }

    if(svc_client->headers)
    {
        axiom_soap_header_t *soap_header = NULL;
        soap_header = axiom_soap_envelope_get_header(envelope, env);

        if(soap_header)
        {
            axiom_node_t *header_node = NULL;
            header_node = axiom_soap_header_get_base_node(soap_header, env);

            if(header_node)
            {
                int size = 0;
                int i = 0;
                size = axutil_array_list_size(svc_client->headers, env);
                while(i < size)
                {
                    axiom_node_t *node = NULL;
                    node = axutil_array_list_remove(svc_client->headers, env, 0);
                    /* This removes and retrieves data. The order of the 
                     * removal is chosen such that the headers are appended
                     * in the order they were added.
                     */
                    size--;
                    if(node)
                    {
                        axiom_node_add_child(header_node, env, node);
                    }
                }
            }
        }
    }

    if(payload)
    {
        axiom_soap_body_t *soap_body = NULL;
        soap_body = axiom_soap_envelope_get_body(envelope, env);
        if(soap_body)
        {
            axiom_node_t *node = NULL;
            node = axiom_soap_body_get_base_node(soap_body, env);
            if(node)
            {
                axiom_node_add_child(node, env, (axiom_node_t *)payload);
            }
        }
    }

    axis2_msg_ctx_set_soap_envelope(msg_ctx, env, envelope);

    return AXIS2_TRUE;
}