Ejemplo n.º 1
0
AXIS2_EXTERN axis2_op_t *AXIS2_CALL
axis2_svc_get_op_with_qname(
    const axis2_svc_t * svc,
    const axutil_env_t * env,
    const axutil_qname_t * op_qname)
{
    axis2_op_t *op = NULL;
    axis2_char_t *nc_name = NULL;

    axis2_char_t *nc_tmp = NULL;
    /* This is just for the sake of comparison,
     * and must not be used to change the passed value
     */
    axis2_bool_t is_matched = AXIS2_FALSE;

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

    nc_name = axutil_qname_get_localpart(op_qname, env);
    nc_tmp = nc_name;

    op = axutil_hash_get(svc->op_alias_map, nc_tmp, AXIS2_HASH_KEY_STRING);
    if(op)
    {
        return op;
    }
    op = axutil_hash_get(svc->op_action_map, nc_tmp, AXIS2_HASH_KEY_STRING);
    if(op)
    {
        return op;
    }

    if(*nc_tmp && svc->op_action_map)
    {
        axutil_hash_index_t *hi = NULL;
        const void *key = NULL;

        for(hi = axutil_hash_first(svc->op_action_map, env); hi; hi = axutil_hash_next(env, hi))
        {
            axutil_hash_this(hi, &key, NULL, NULL);

            nc_tmp = nc_name;

            if(key)
            {
                axis2_char_t *search = NULL;
                axis2_bool_t match_start = AXIS2_TRUE;
                axis2_char_t *search_tmp = NULL;

                search = (axis2_char_t *)key;

                if(!axutil_strchr(search, '*'))
                {
                    if(axutil_strstr(nc_tmp, search))
                    {
                        axis2_char_t *comp_tmp = NULL;

                        comp_tmp = axutil_strstr(nc_tmp, search);
                        if(strlen(comp_tmp) == strlen(search))
                        {
                            nc_tmp = (axis2_char_t *)key;
                            is_matched = AXIS2_TRUE;
                            break;
                        }
                    }
                    continue;
                }

                if(search[0] == '*')
                {
                    search++;
                    if(!*search)
                    {
                        nc_tmp = (axis2_char_t *)key;
                        is_matched = AXIS2_TRUE;
                        break;
                    }
                    else if(axutil_strchr(search, '*'))
                    {
                        continue;
                    }
                    match_start = AXIS2_FALSE;
                }
                while(search && *search)
                {
                    size_t length = 0;
                    axis2_char_t *loc_tmp = NULL;

                    if(search_tmp)
                    {
                        AXIS2_FREE(env->allocator, search_tmp);
                        search_tmp = NULL;
                    }
                    loc_tmp = axutil_strchr(search, '*');
                    if(loc_tmp && *loc_tmp)
                    {
                        if(!loc_tmp[1])
                        {
                            is_matched = AXIS2_TRUE;
                            break;
                        }
                        length = (size_t)(loc_tmp - search);
                        /* We are sure that the difference lies within the int range */
                        search_tmp = (axis2_char_t *)(AXIS2_MALLOC(env->allocator,
                                                      sizeof(axis2_char_t) * (length + 1)));
                        strncpy(search_tmp, search, length);
                        search_tmp[length] = '\0';
                    }
                    else if(axutil_strstr(nc_tmp, search))
                    {
                        axis2_char_t *comp_tmp = NULL;

                        comp_tmp = axutil_strstr(nc_tmp, search);
                        if(strlen(comp_tmp) == strlen(search))
                        {
                            nc_tmp = (axis2_char_t *)key;
                            is_matched = AXIS2_TRUE;
                            break;
                        }
                        break;
                    }
                    else
                    {
                        break;
                    }
                    if(search_tmp && axutil_strstr(nc_tmp, search_tmp))
                    {
                        if(match_start && !(axutil_strncmp(nc_tmp, search, (int)length) == 0))
                        {
                            break;
                        }
                        else if(!match_start)
                        {
                            match_start = AXIS2_TRUE;
                        }
                    }
                    else
                    {
                        break;
                    }
                    search += axutil_strlen(search_tmp) + 1;
                    nc_tmp = axutil_strstr(nc_tmp, search_tmp) + axutil_strlen(search_tmp);
                }
                if(search_tmp)
                {
                    AXIS2_FREE(env->allocator, search_tmp);
                    search_tmp = NULL;
                }
                if(is_matched || !search || !*search)
                {
                    nc_tmp = (axis2_char_t *)key;
                    is_matched = AXIS2_TRUE;
                    break;
                }
            }
        }
    }
    if(!is_matched)
    {
        nc_tmp = nc_name;
    }

    op = axutil_hash_get(svc->op_alias_map, nc_tmp, AXIS2_HASH_KEY_STRING);
    if(op)
    {
        return op;
    }
    return (axis2_op_t *)axutil_hash_get(svc->op_action_map, nc_tmp, AXIS2_HASH_KEY_STRING);
}
Ejemplo n.º 2
0
/** f_add_PostEncodingSOAP
 * Add the element
 *      <ns:Value>SOAP</ns:Value>
 *  at all nodes
 *    Constraint[@name="PostEncoding"]/AllowedValues
 *  (See OGC 09-148r1 and OGC 09-149r1).
 *
* This function may be invoked via sp_func_at_nodes() if needed.
 *
 */
static int f_add_PostEncodingSOAP(
    const axutil_env_t * env,
    axiom_node_t *target_node,
    void *arg3
 )
{
	//
    // Find the path
    //   Constraint[@name="PostEncoding"]/AllowedValues
    //   and add
    //      <ns:Value>SOAP</ns:Value>
    //   where ns is the namespace of the enclosing AllowedValues element.
	//

    const axis2_char_t *constrIdStr = "Constraint";

    axiom_node_t *constraint_node =
    		rp_find_named_child(env, target_node, constrIdStr, 1);
    if (NULL == constraint_node)
    {
    	axiom_element_t *el      = NULL;
    	axis2_char_t    *el_name = NULL;
    	axis2_char_t    *op_name = NULL;
        if (axiom_node_get_node_type(target_node, env) == AXIOM_ELEMENT)
        {
            el = (axiom_element_t *)
              axiom_node_get_data_element (target_node, env);
            el_name = el ?
            		axiom_element_get_localname( el, env) :
            		NULL;
    		op_name = el ?
    				axiom_element_get_attribute_value_by_name(el, env, "name"):
            		NULL;
        }
    	rp_log_error(env,
    			"*** S2P(%s:%d): %s node not found under %s/name='%s'.\n",
    			__FILE__, __LINE__,  constrIdStr,
    			el_name ? el_name : "<UNKNOWN>",
    			op_name ? op_name : "<UNKNOWN>");
    	return 1;
    }

    // check that constr_node is "PostEncoding", otherwise try to find it

    axiom_element_t *el = axiom_node_get_data_element(constraint_node, env);
    const axis2_char_t *nameAttr = axiom_element_get_attribute_value_by_name
    		(el, env, "name");
    while (nameAttr == NULL ||  axutil_strncmp(nameAttr, "PostEncoding", 12) )
    {
    	// loop through siblings trying find the "PostEncoding" constraint
    	constraint_node = axiom_node_get_next_sibling (constraint_node, env);
    	el = axiom_node_get_data_element(constraint_node, env);
    	if (axiom_node_get_node_type(constraint_node, env) == AXIOM_ELEMENT)
    	{
    		nameAttr =
    				axiom_element_get_attribute_value_by_name(el, env, "name");
    	}
    }

    if (nameAttr == NULL ||  axutil_strncmp(nameAttr, "PostEncoding", 12) )
    {
    	// Did not find a "PostEncoding" constraint, bail out.
    	// TODO: Future enhancement: could add a "PostEncoding" constraint
    	//   element.

    	rp_log_error(env,
    			"*** S2P(%s:%d): 'PostEncoding' constraint not found.\n",
    			__FILE__, __LINE__,  constrIdStr);
    	return 1;
    }

    axiom_node_t *allowedValues_node =
      rp_find_named_child(env, constraint_node, "AllowedValues", 1);
    if (NULL == allowedValues_node)
    {
    	// TODO: Future enhancement: insert an "AllowedValues" node.
    	rp_log_error(env,
    			"*** S2P(%s:%d): 'AllowedValues' node not found.\n",
    			__FILE__, __LINE__,  constrIdStr);
    	return 1;
    }

    // Insert <ns:Value>SOAP</ns:Value>

    Name_value value_nv_n;
    value_nv_n.name  = "Value";
    value_nv_n.value = "SOAP";
    rp_add_child (env, allowedValues_node, &value_nv_n, NULL, NULL);

    return 0;
}