Ejemplo n.º 1
0
/**
 * Verify that an addressing element is located in <Envelope>/<Header>
 */
int verify_addr_hdr_elem_loc(axiom_node_t *signed_node, const axutil_env_t *env, axis2_char_t *ref) {

    axiom_node_t *parent = axiom_node_get_parent(signed_node,env);

    if(axutil_strcmp(OXS_NODE_HEADER, axiom_util_get_localname(parent, env))) {
       AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[euca-rampart] parent of addressing elem is %s", axiom_node_to_string(parent, env));
       oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Unexpected location of signed addressing elem with ID = %s", ref);
       return 1;

    }
     parent = axiom_node_get_parent(parent,env);

    if(axutil_strcmp(OXS_NODE_ENVELOPE, axiom_util_get_localname(parent, env))) {
       AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[euca-rampart] second parent of addressing elem is %s", axiom_node_to_string(parent, env));
       oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Unexpected location of signed addressing elem with ID = %s", ref);
       return 1;

    }

     parent = axiom_node_get_parent(parent,env);
     if(parent) {
       AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[euca-rampart] parent of Envelope = %s", axiom_node_to_string(parent, env));
       oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Unexpected location of signed Body with ID = %s", ref);
       return 1;
     }

     return 0;
}
Ejemplo n.º 2
0
/**
 * First find the root of the scope node. Traverse thru the root node and its 
 * children. Check if the element has the given qname and has a attribute 
 * equal to the given values.
 * @param env Environment. MUST NOT be NULL,
 * @param node the node to be searched
 * @param e_name element name
 * @param e_ns element namespace. If NULL doesn't consider the namespaces
 * @param attr_name the attribute name of the node
 * @param attr_val the attribute value of the node
 * @param attr_ns the attribute namespace. If NULL doesn't consider namespaces.
 * @return the node if found, else NULL
 */
AXIS2_EXTERN axiom_node_t * AXIS2_CALL
oxs_axiom_get_first_node_by_name_and_attr_val_from_xml_doc(
    const axutil_env_t *env,
    axiom_node_t *node,
    axis2_char_t *e_name,
    axis2_char_t *e_ns,
    axis2_char_t *attr_name,
    axis2_char_t *attr_val,
    axis2_char_t *attr_ns)
{
	axiom_node_t *p = NULL;	
	axiom_node_t *root = NULL;

    /* find the root node */
	p = node;
	do 
	{
		root = p;
		p = axiom_node_get_parent(root, env);	
	} while (p);

    /* from the root node, find the node with name and attribute value */
	return oxs_axiom_get_first_node_by_name_and_attr_val(
        env, root, e_name, e_ns, attr_name, attr_val, attr_ns);
}
Ejemplo n.º 3
0
static axiom_node_t *
axiom_stax_builder_create_om_element(
    axiom_stax_builder_t * om_builder,
    const axutil_env_t * env,
    axis2_bool_t is_empty)
{
    axiom_node_t *element_node = NULL;
    axiom_element_t *om_ele = NULL;
    axis2_char_t *temp_localname = NULL;
    axiom_node_t *parent = NULL;

    temp_localname = axiom_xml_reader_get_name(om_builder->parser, env);
    if(!temp_localname)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_XML_READER_ELEMENT_NULL, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot find name of the element");
        return NULL;
    }

    om_builder->element_level++;
    if(om_builder->lastnode)
    {
        if(axiom_node_is_complete(om_builder->lastnode, env))
        {
            /*previous node building is finished. This node should be a sibling of previous node */
            parent = axiom_node_get_parent(om_builder->lastnode, env);
        }
        else
        {
            /*previous node building is not finished. This should be child of previous node */
            parent = om_builder->lastnode;
        }
    }

    om_ele = axiom_element_create(env, parent, temp_localname, NULL, &element_node);
    axiom_xml_reader_xml_free(om_builder->parser, env, temp_localname);
    if((!om_ele) || (!element_node))
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create axiom element");
        return NULL;
    }
    axiom_node_set_builder(element_node, env, om_builder);
    axiom_element_set_is_empty(om_ele, env, is_empty);

    if(!om_builder->lastnode)
    {
        /* since last node is null, this should be the root node */
        om_builder->root_node = element_node;
        axiom_document_set_root_element(om_builder->document, env, element_node);
    }

    /* order of processing name spaces first (before processing attributes) is important */
    axiom_stax_builder_process_namespaces(om_builder, env, element_node, 0);
    axiom_stax_builder_process_attributes(om_builder, env, element_node);

    om_builder->lastnode = element_node;
    return element_node;
}
Ejemplo n.º 4
0
static axiom_node_t *
axiom_stax_builder_create_om_text(
    axiom_stax_builder_t * om_builder,
    const axutil_env_t * env)
{
    axis2_char_t *temp_value = NULL;
    axutil_string_t *temp_value_str = NULL;
    axiom_node_t *node = NULL;
    axiom_node_t *parent = om_builder->lastnode;

    if(!parent)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_BUILDER_STATE_LAST_NODE_NULL, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create OM Text without a node");
        return NULL;
    }

    temp_value = axiom_xml_reader_get_value(om_builder->parser, env);
    if(!temp_value)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_XML_READER_VALUE_NULL, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid OM Text value");
        return NULL;
    }

#ifdef AXIS2_LIBXML2_ENABLED
    temp_value_str = axutil_string_create(env, temp_value);
    axiom_xml_reader_xml_free(om_builder->parser, env, temp_value);
#else
    temp_value_str = axutil_string_create_assume_ownership(env, &temp_value);
#endif

    if(!temp_value_str)
    {
        /* axutil_string_create will have set an error number */
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create OM Text value");
        return NULL;
    }

    if(axiom_node_is_complete(parent, env))
    {
        parent = axiom_node_get_parent(om_builder->lastnode, env);
    }

    axiom_text_create_str(env, parent, temp_value_str, &node);
    axutil_string_free(temp_value_str, env);

    if(!node)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create axiom_text");
        return NULL;
    }
    axiom_node_set_builder(node, env, om_builder);
    axiom_node_set_complete(node, env, AXIS2_TRUE);
    om_builder->lastnode = node;
    return node;
}
Ejemplo n.º 5
0
/** this method encapsulate searching logic */
static void
axiom_navigator_update_next_node(
    axiom_navigator_t * om_navigator,
    const axutil_env_t * env)
{
    if (!om_navigator)
    {
        return;
    }

    if (!om_navigator->next)
    {
        return;
    }

    if ((AXIOM_ELEMENT == axiom_node_get_node_type(om_navigator->next, env)) &&
        !(om_navigator->visited))
    {
        if (axiom_node_get_first_child(om_navigator->next, env))
        {
            om_navigator->next =
                axiom_node_get_first_child(om_navigator->next, env);
        }
        else if (AXIS2_TRUE == axiom_node_is_complete(om_navigator->next, env))
        {
            om_navigator->backtracked = AXIS2_TRUE;
        }
        else
        {
            om_navigator->next = NULL;
        }
    }
    else
    {
        axiom_node_t *parent = NULL;
        axiom_node_t *next_sibling = NULL;

        next_sibling = axiom_node_get_next_sibling(om_navigator->next, env);

        parent = axiom_node_get_parent(om_navigator->next, env);

        if (next_sibling)
        {
            om_navigator->next = next_sibling;
        }
        else if ((parent) && axiom_node_is_complete(parent, env))
        {
            om_navigator->next = parent;
            om_navigator->backtracked = AXIS2_TRUE;
        }
        else
        {
            om_navigator->next = NULL;
        }
    }
}
Ejemplo n.º 6
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
oxs_xml_enc_decrypt_node(
    const axutil_env_t *env,
    oxs_ctx_t * enc_ctx,
    axiom_node_t *enc_type_node,
    axiom_node_t **decrypted_node)
{
    axiom_node_t *deserialized_node = NULL;
    axiom_node_t *parent_of_enc_node = NULL;
    oxs_buffer_t *result_buf = NULL;
    axis2_char_t *decrypted_data = NULL;/*Can be either am XML-Element or XML-Content*/
    axis2_status_t status = AXIS2_FAILURE;

    /*Create an empty buffer for results*/
    result_buf = oxs_buffer_create(env);

    /*Decrypt*/
    status = oxs_xml_enc_decrypt_data(env, enc_ctx, enc_type_node, result_buf);
    if(AXIS2_FAILURE == status)
    {
        oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ENCRYPT_FAILED, "Data encryption failed");
        return AXIS2_FAILURE;
    }
    decrypted_data = axutil_strmemdup(oxs_buffer_get_data(result_buf, env), oxs_buffer_get_size(
        result_buf, env), env);
    /*De-serialize the decrypted content to build the node*/
    deserialized_node = (axiom_node_t*)oxs_axiom_deserialize_node(env, decrypted_data);
    if(!deserialized_node)
    {
        oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ENCRYPT_FAILED,
            "Cannot deserialize a node from the content.\n%s", decrypted_data);
        return AXIS2_FAILURE;
    }
    /*Assign deserialized_node to the reference passed*/
    *decrypted_node = deserialized_node;

    /*Replace the encrypted node with the de-serialized node*/
    parent_of_enc_node = axiom_node_get_parent(enc_type_node, env);

    axiom_node_insert_sibling_after(enc_type_node, env, deserialized_node);
    axiom_node_free_tree(enc_type_node, env);
    enc_type_node = NULL;

    /*Free result buf*/

    oxs_buffer_free(result_buf, env);
    result_buf = NULL;

    AXIS2_FREE(env->allocator, decrypted_data);
    decrypted_data = NULL;

    return AXIS2_SUCCESS;
}
Ejemplo n.º 7
0
static axiom_node_t *
axiom_stax_builder_create_om_processing_instruction(
    axiom_stax_builder_t * om_builder,
    const axutil_env_t * env)
{
    axiom_node_t *pi_node = NULL;
    axis2_char_t *target = NULL;
    axis2_char_t *value = NULL;

    target = axiom_xml_reader_get_pi_target(om_builder->parser, env);
    value = axiom_xml_reader_get_pi_data(om_builder->parser, env);
    if(!target)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_XML_READER_ELEMENT_NULL, AXIS2_FAILURE);
        return NULL;
    }
    if(!om_builder->lastnode)
    {
        /* do nothing */
        axiom_xml_reader_xml_free(om_builder->parser, env, target);
        axiom_xml_reader_xml_free(om_builder->parser, env, value);
        return NULL;
    }
    else if(axiom_node_is_complete(om_builder->lastnode, env)
        || (axiom_node_get_node_type(om_builder->lastnode, env) == AXIOM_TEXT))
    {
        axiom_processing_instruction_create(env, axiom_node_get_parent(om_builder-> lastnode, env),
            target, value, &pi_node);

        axiom_node_set_next_sibling(om_builder->lastnode, env, pi_node);
        axiom_node_set_previous_sibling(pi_node, env, om_builder->lastnode);
    }
    else
    {
        axiom_processing_instruction_create(env, om_builder->lastnode, target, value, &pi_node);
        axiom_node_set_first_child(om_builder->lastnode, env, pi_node);
        axiom_node_set_parent(pi_node, env, om_builder->lastnode);
    }
    axiom_node_set_builder(pi_node, env, om_builder);
    om_builder->element_level++;

    if(target)
    {
        axiom_xml_reader_xml_free(om_builder->parser, env, target);
    }
    if(value)
    {
        axiom_xml_reader_xml_free(om_builder->parser, env, value);
    }

    om_builder->lastnode = pi_node;
    return pi_node;
}
Ejemplo n.º 8
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axiom_stax_builder_discard_current_element(
    axiom_stax_builder_t * om_builder,
    const axutil_env_t * env)
{
    axiom_node_t *element = NULL;
    axiom_node_t *prev_node = NULL;
    axiom_node_t *parent = NULL;

    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);

    element = om_builder->lastnode;

    if(axiom_node_is_complete(element, env) || !(om_builder->cache))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_BUILDER_STATE_CANNOT_DISCARD, AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }

    om_builder->cache = AXIS2_FALSE;
    do
    {
        while(axiom_xml_reader_next(om_builder->parser, env) != AXIOM_XML_READER_END_ELEMENT)
            ;
    }
    while(!(axiom_node_is_complete(element, env)));

    /*All children of this element is pulled now */

    prev_node = axiom_node_get_previous_sibling(element, env);
    if(prev_node)
    {
        axiom_node_free_tree(axiom_node_get_next_sibling(prev_node, env), env);
        axiom_node_set_next_sibling(prev_node, env, NULL);
    }
    else
    {
        parent = axiom_node_get_parent(element, env);
        axiom_node_free_tree(axiom_node_get_first_child(parent, env), env);
        axiom_node_set_first_child(parent, env, NULL);
        om_builder->lastnode = parent;
    }
    om_builder->cache = AXIS2_TRUE;

    return AXIS2_SUCCESS;
}
Ejemplo n.º 9
0
static axiom_node_t *
axiom_stax_builder_create_om_comment(
    axiom_stax_builder_t * om_builder,
    const axutil_env_t * env)
{
    axiom_node_t *comment_node = NULL;
    axis2_char_t *comment_value = NULL;
    axiom_node_t *parent = NULL;

    comment_value = axiom_xml_reader_get_value(om_builder->parser, env);
    if(!comment_value)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_XML_READER_ELEMENT_NULL, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in reading comment");
        return NULL;
    }

    if(axiom_node_is_complete(om_builder->lastnode, env))
    {
        /* Last node is completed means, this node should be a sibling of last node */
        parent = axiom_node_get_parent(om_builder->lastnode, env);
    }
    else
    {
        /* this node should be a child of last node */
        parent = om_builder->lastnode;
    }

    axiom_comment_create(env, parent, comment_value, &comment_node);
    axiom_xml_reader_xml_free(om_builder->parser,env,comment_value);
    if(!comment_node)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create axiom element");
        return NULL;
    }

    axiom_node_set_builder(comment_node, env, om_builder);
    om_builder->element_level++;
    om_builder->lastnode = comment_node;

    return comment_node;
}
Ejemplo n.º 10
0
static axis2_status_t
axiom_stax_builder_end_element(
    axiom_stax_builder_t * om_builder,
    const axutil_env_t * env)
{
    /* if last node is not set, that means end_element is called before start_element,
     * which is an error */
    if(!om_builder->lastnode)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Invalid XML. End element is received before start element.");
        return AXIS2_FAILURE;
    }

    om_builder->element_level--;
    if(axiom_node_is_complete(om_builder->lastnode, env))
    {
        /* Last node completed means, this end element should be parent of the last node. */
        axiom_node_t *parent = axiom_node_get_parent(om_builder->lastnode, env);
        if(parent)
        {
            axiom_node_set_complete(parent, env, AXIS2_TRUE);
            om_builder->lastnode = parent;
        }
    }
    else
    {
        axiom_node_set_complete((om_builder->lastnode), env, AXIS2_TRUE);
    }

    /* if we finish building the root node, then we can set the complete status of om_builder */
    if(axiom_node_is_complete(om_builder->root_node, env))
    {
        om_builder->done = AXIS2_TRUE;
    }

    return AXIS2_SUCCESS;
}
Ejemplo n.º 11
0
  /*
  * This method invokes the target service method 
  */
  static axiom_node_t* AXIS2_CALL
    Axis2Service_invoke(axis2_svc_skeleton_t* /*pServiceSkeleton*/,
    const axutil_env_t* pEnv,
    axiom_node_t* pAxiomNode,
    axis2_msg_ctx_t* pMsgCtx)
  {
    if (pAxiomNode == NULL)
    {
      staff::LogError() << "AxiOM node is NULL\n";
      return NULL;
    }

    if (axiom_node_get_node_type(pAxiomNode, pEnv) != AXIOM_ELEMENT)
    {
      staff::LogError() << "Can't get AxiOM node type";
      return NULL;
    }

    axiom_element_t* pAxiomElement = (axiom_element_t*)axiom_node_get_data_element(pAxiomNode, pEnv);
    if (pAxiomElement == NULL)
    {
      staff::LogError() << "Can't get AxiOM node element\n";
      return NULL;
    }

    const axis2_char_t* szServiceName = reinterpret_cast<const axis2_char_t*>
        (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "ServiceName"));
#ifndef WITHOUT_SECURITY
    const axis2_char_t* szSessionId = reinterpret_cast<const axis2_char_t*>
        (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "SessionId"));
    const axis2_char_t* szInstanceId = reinterpret_cast<const axis2_char_t*>
        (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "InstanceId"));
#endif

    if (szServiceName == NULL)
    {
      staff::LogError() << "Cannot process message: Failed to get service name.";
      return NULL;
    }

#ifndef WITHOUT_SECURITY
    if (szSessionId == NULL)
    {
      staff::LogError() << "Cannot process message: Failed to get session id.";
      return NULL;
    }

    if (szInstanceId == NULL)
    {
      staff::LogError() << "Cannot process message: Failed to get instance id.";
      return NULL;
    }
#endif

#ifdef _DEBUG
    staff::LogDebug1() << "Service name: [" << szServiceName << "]";
#ifndef WITHOUT_SECURITY
    staff::LogDebug1() << "Session id: [" << szSessionId << "]";
    staff::LogDebug1() << "Instance id: [" << szInstanceId << "]";
#endif

    {
      axiom_node_t* panBody = axiom_node_get_parent(pAxiomNode, pEnv);
      axiom_node_t* panEnv = axiom_node_get_parent(panBody, pEnv);

      staff::LogDebug2() << "request SOAP Envelope: \n" << staff::ColorTextBlue
                  << staff::DataObject(panEnv).ToString() << "\n" << staff::ColorDefault;
    }
#endif

    staff::Operation tOperation;
    staff::MessageContext tMessageContext(pEnv, pMsgCtx);

    std::string sServiceName(szServiceName);
#ifndef WITHOUT_SECURITY
    std::string sSessionId(szSessionId);
    std::string sInstanceId(szInstanceId);
#else
    static std::string sSessionId;
    static std::string sInstanceId;
#endif

    try
    {
      tOperation.SetRequest(pAxiomNode);
      tOperation.SetMessageContext(tMessageContext);

      if (axis2_msg_ctx_get_doing_rest(pMsgCtx, pEnv))
      {
        const axis2_char_t* szOperation = reinterpret_cast<const axis2_char_t*>
            (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "Operation"));
        if (szOperation != NULL)
        {
          tOperation.SetName(szOperation);
        }
      }

      if (sServiceName == "StaffService")
      {
        staff::ServiceDispatcher::Inst().InvokeSelf(tOperation);
      }
      else
      {
        staff::ServiceWrapper* pServiceWrapper =
            staff::SharedContext::Inst().GetService(sServiceName);
        STAFF_ASSERT(pServiceWrapper, "Service [" + sServiceName + "] is not found: ");
        pServiceWrapper->Invoke(tOperation, sSessionId, sInstanceId);
      }
    }
    catch (const staff::SoapUserFaultException& rEx)
    {
      try
      {
        staff::DataObject tdoFault;
        tdoFault.FromString(rEx.GetFault());
        tOperation.SetUserFault(tdoFault);
      }
      catch (...)
      {
        tOperation.SetFault("server", "Invalid format of user soap fault",
                            "Failed to invoke service " + sServiceName
                            + "." + tOperation.GetName()
#ifndef WITHOUT_SECURITY
                            + "#" + sInstanceId + "(" + sSessionId + ")"
#endif
                            );
      }
    }
    catch (const staff::SoapFaultException& rEx)
    {
      tOperation.SetFault(rEx.GetCode(), rEx.GetString(), rEx.GetDetail());
    }
    catch (const std::exception& rEx)
    {
      tOperation.SetFault("server", rEx.what(), "Failed to invoke service " + sServiceName
                          + "." + tOperation.GetName()
#ifndef WITHOUT_SECURITY
                          + "#" + sInstanceId + "(" + sSessionId + ")"
#endif
                          );
    }
    catch (...)
    {
      tOperation.SetFault("server", "Unknown exception", "Failed to invoke service " + sServiceName
                          + "." + tOperation.GetName()
#ifndef WITHOUT_SECURITY
                          + "#" + sInstanceId + "(" + sSessionId + ")"
#endif
                          );
    }

    if (tOperation.IsFault())
    {
      staff::ScopedLock tLock(m_tFaultDetailsMutex);

      m_mFaultDetails[staff::Thread::GetCurrentId()] = tOperation.GetFaultDetail();
      staff::LogWarning() << "Fault: \n" << tOperation.GetFaultDescr() << "\n";
      AXIS2_ERROR_SET_MESSAGE(pEnv->error, static_cast<axis2_char_t*>(axutil_strdup(pEnv, tOperation.GetFaultString().c_str())));
      AXIS2_ERROR_SET_ERROR_NUMBER(pEnv->error, static_cast<axutil_error_codes_t>(AXUTIL_ERROR_MAX + 1));
      AXIS2_ERROR_SET_STATUS_CODE(pEnv->error, AXIS2_FAILURE);
      if (!m_bHttp200OnFault)
        return NULL;
    }

    if(!IsNeedReply(pMsgCtx, pEnv))
    {
      return NULL;
    }

    tOperation.PrepareResult();
    staff::DataObject& rResponse = tOperation.GetResponse();
    rResponse.SetOwner(false);

#ifdef _DEBUG
    staff::LogDebug2() << "Sending Response: \n" <<  staff::ColorTextBlue << rResponse.ToString() << "\n" << staff::ColorDefault;
#endif

    return rResponse;
  }
Ejemplo n.º 12
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axiom_soap11_builder_helper_handle_event(
    axiom_soap11_builder_helper_t * builder_helper,
    const axutil_env_t * env,
    axiom_node_t * om_element_node,
    int element_level)
{
    axiom_element_t *om_ele = NULL;
    axis2_char_t *ele_localname = NULL;
    axiom_soap_envelope_t *soap_envelope = NULL;
    axiom_soap_body_t *soap_body = NULL;
    axiom_soap_fault_t *soap_fault = NULL;

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

    om_ele = (axiom_element_t *)axiom_node_get_data_element(om_element_node, env);

    ele_localname = axiom_element_get_localname(om_ele, env);
    if(!ele_localname)
    {
        return AXIS2_FAILURE;
    }

    soap_envelope = axiom_soap_builder_get_soap_envelope(builder_helper->soap_builder, env);

    if(!soap_envelope)
    {
        return AXIS2_FAILURE;
    }

    soap_body = axiom_soap_envelope_get_body(soap_envelope, env);
    if(!soap_body)
    {
        return AXIS2_FAILURE;
    }

    soap_fault = axiom_soap_body_get_fault(soap_body, env);
    if(!soap_fault)
    {
        return AXIS2_FAILURE;
    }

    if(element_level == 4)
    {
        axiom_soap_fault_code_t *fault_code = NULL;
        axiom_soap_fault_value_t *fault_value = NULL;
        axiom_node_t *fault_value_node = NULL;
        axiom_element_t *fault_value_ele = NULL;

        if(axutil_strcmp(ele_localname, AXIOM_SOAP11_SOAP_FAULT_CODE_LOCAL_NAME) == 0)
        {
            axis2_status_t status = AXIS2_SUCCESS;

            if(builder_helper->fault_string_present)
            {
                axiom_soap_builder_set_bool_processing_mandatory_fault_elements(
                    builder_helper->soap_builder, env, AXIS2_FALSE);
            }

            fault_code = axiom_soap_fault_code_create(env);
            if(!fault_code)
            {
                return AXIS2_FAILURE;
            }
            axiom_soap_fault_code_set_base_node(fault_code, env, om_element_node);

            axiom_soap_fault_set_code(soap_fault, env, fault_code);

            axiom_soap_fault_code_set_builder(fault_code, env, builder_helper->soap_builder);

            axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME);

            fault_value = axiom_soap_fault_value_create_with_code(env, fault_code);
            if(!fault_value)
            {
                return AXIS2_FAILURE;
            }
            fault_value_node = axiom_soap_fault_value_get_base_node(fault_value, env);
            if(!fault_value_node)
            {
                return AXIS2_FAILURE;
            }
            fault_value_ele = (axiom_element_t *)axiom_node_get_data_element(fault_value_node, env);

            axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, fault_value_node);

            status = axiom_soap11_builder_helper_process_text(builder_helper, env);
            if(status == AXIS2_FAILURE)
            {
                return AXIS2_FAILURE;
            }
            axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, om_element_node);
            axiom_node_set_complete(om_element_node, env, AXIS2_TRUE);

            axiom_stax_builder_set_element_level(builder_helper->om_builder, env, (element_level
                - 1));
            builder_helper->fault_code_present = AXIS2_TRUE;
        }
        else if(axutil_strcmp(AXIOM_SOAP11_SOAP_FAULT_STRING_LOCAL_NAME, ele_localname) == 0)
        {

            axiom_soap_fault_reason_t *fault_reason = NULL;
            axiom_soap_fault_text_t *fault_text = NULL;
            axiom_node_t *fault_text_node = NULL;
            int status = AXIS2_SUCCESS;
            if(builder_helper->fault_code_present)
            {
                axiom_soap_builder_set_bool_processing_mandatory_fault_elements(
                    builder_helper->soap_builder, env, AXIS2_FALSE);
            }

            axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME);

            fault_reason = axiom_soap_fault_reason_create(env);
            if(!fault_reason)
            {
                return AXIS2_FAILURE;
            }
            axiom_soap_fault_reason_set_base_node(fault_reason, env, om_element_node);

            axiom_soap_fault_set_reason(soap_fault, env, fault_reason);

            fault_text = axiom_soap_fault_text_create_with_parent(env, fault_reason);
            if(!fault_text)
            {
                return AXIS2_FAILURE;
            }
            fault_text_node = axiom_soap_fault_text_get_base_node(fault_text, env);
            if(!fault_text_node)
            {
                return AXIS2_FAILURE;
            }
            axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, fault_text_node);

            status = axiom_soap11_builder_helper_process_text(builder_helper, env);
            if(status == AXIS2_FAILURE)
            {
                return AXIS2_FAILURE;
            }
            axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, om_element_node);

            axiom_node_set_complete(om_element_node, env, AXIS2_TRUE);

            axiom_stax_builder_set_element_level(builder_helper->om_builder, env, (element_level
                - 1));

            builder_helper->fault_string_present = AXIS2_TRUE;

        }
        else if(axutil_strcmp(AXIOM_SOAP11_SOAP_FAULT_ACTOR_LOCAL_NAME, ele_localname) == 0)
        {
            axiom_soap_fault_role_t *fault_role = NULL;
            fault_role = axiom_soap_fault_role_create(env);
            if(!fault_role)
            {
                return AXIS2_FAILURE;
            }
            axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME);

            axiom_soap_fault_role_set_base_node(fault_role, env, om_element_node);

            axiom_soap_fault_set_role(soap_fault, env, fault_role);
            /*
             Role element may not have a namespace associated, hence commented, else it segfaults here - Samisa
             status = axiom_soap_builder_process_namespace_data(
             builder_helper->soap_builder, env, om_element_node, AXIS2_TRUE);
             if(status == AXIS2_FAILURE)
             return AXIS2_FAILURE; */
        }
        else if(axutil_strcmp(AXIOM_SOAP11_SOAP_FAULT_DETAIL_LOCAL_NAME, ele_localname) == 0)
        {
            axiom_soap_fault_detail_t *fault_detail = NULL;
            fault_detail = axiom_soap_fault_detail_create(env);
            if(!fault_detail)
            {
                return AXIS2_FAILURE;
            }
            axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME);

            axiom_soap_fault_detail_set_base_node(fault_detail, env, om_element_node);

            axiom_soap_fault_set_detail(soap_fault, env, fault_detail);
        }
        else
        {
            return AXIS2_SUCCESS;
        }
    }
    else if(element_level == 5)
    {
        axiom_node_t *parent_node = NULL;
        axiom_element_t *parent_element = NULL;
        axis2_char_t *parent_localname = NULL;

        parent_node = axiom_node_get_parent(om_element_node, env);
        if(!parent_node)
        {
            return AXIS2_FAILURE;
        }
        parent_element = (axiom_element_t *)axiom_node_get_data_element(om_element_node, env);
        parent_localname = axiom_element_get_localname(parent_element, env);

        if(!parent_localname)
        {
            return AXIS2_FAILURE;
        }
        if(axutil_strcmp(parent_localname, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME) == 0)
        {
            AXIS2_ERROR_SET(env->error,
                AXIS2_ERROR_SOAP11_FAULT_ACTOR_SHOULD_NOT_HAVE_CHILD_ELEMENTS, AXIS2_FAILURE);
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "SOAP 1.1 Actor should not have child elements");
            return AXIS2_FAILURE;
        }
    }
    return AXIS2_SUCCESS;
}
Ejemplo n.º 13
0
/**
 * Verifies XPath location of signed elements.
 */ 
int verify_node(axiom_node_t *signed_node, const axutil_env_t *env, axis2_msg_ctx_t *msg_ctx, axis2_char_t *ref, short *signed_elems) {

  if(!axutil_strcmp(OXS_NODE_BODY, axiom_util_get_localname(signed_node, env))) {
    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[euca-rampart] node %s is Body", ref); 
    signed_elems[0] = 1;

    axiom_node_t *parent = axiom_node_get_parent(signed_node,env);
    if(axutil_strcmp(OXS_NODE_ENVELOPE, axiom_util_get_localname(parent, env))) {
       oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Unexpected parent element for Body with ID = %s", ref);
       return 1;
    }

     parent = axiom_node_get_parent(parent,env);
     if(parent) {
       AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[euca-rampart] parent of Envelope = %s", axiom_node_to_string(parent, env));
       oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Unexpected location of signed Body with ID = %s", ref);
       return 1;
     }

  } else if(!axutil_strcmp(RAMPART_SECURITY_TIMESTAMP, axiom_util_get_localname(signed_node, env))) {
    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[euca-rampart] node %s is Timestamp", ref); 
    signed_elems[1] = 1;

    /* Regardless of the location of the Timestamp, verify the one that is signed */
    if(AXIS2_FAILURE == rampart_timestamp_token_validate(env, msg_ctx, signed_node, 20)) {
       oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Validation failed for Timestamp with ID = %s", ref);
      return 1;
    }

  } else if(!axutil_strcmp(AXIS2_WSA_ACTION, axiom_util_get_localname(signed_node, env))) {
    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[euca-rampart] node %s is Action", ref); 
    signed_elems[2] = 1;

    if(verify_addr_hdr_elem_loc(signed_node, env, ref)) {
	oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Validation failed for Action with ID = %s", ref);
	return 1;
      }

  } else if(!axutil_strcmp(AXIS2_WSA_TO, axiom_util_get_localname(signed_node, env))) {
    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[euca-rampart] node %s is To", ref); 
    signed_elems[3] = 1;
 
    if(verify_addr_hdr_elem_loc(signed_node, env, ref)) {
	oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Validation failed for To with ID = %s", ref);
	return 1;
      }


  } else if(!axutil_strcmp(AXIS2_WSA_MESSAGE_ID, axiom_util_get_localname(signed_node, env))) {
    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[euca-rampart] node %s is MessageId", ref); 
    signed_elems[4] = 1;

    if(verify_addr_hdr_elem_loc(signed_node, env, ref)) {
	oxs_error(env, OXS_ERROR_LOCATION, OXS_ERROR_ELEMENT_FAILED, "Validation failed for MessageId with ID = %s", ref);
	return 1;
      }

  } else {
    AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "[euca-rampart] node %s is UNKNOWN", ref); 
  }

    return 0;
}
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axiom_soap12_builder_helper_handle_event(
    axiom_soap12_builder_helper_t * builder_helper,
    const axutil_env_t * env,
    axiom_node_t * om_ele_node,
    int element_level)
{
    axis2_char_t *ele_localname = NULL;
    axiom_element_t *om_ele = NULL;

    axiom_soap_body_t *soap_body = NULL;
    axiom_soap_fault_t *soap_fault = NULL;
    axiom_soap_envelope_t *soap_envelope = NULL;

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

    om_ele = (axiom_element_t *) axiom_node_get_data_element(om_ele_node, env);
    if (!om_ele)
    {
        return AXIS2_FAILURE;
    }

    ele_localname = axiom_element_get_localname(om_ele, env);
    if (!ele_localname)
    {
        return AXIS2_FAILURE;
    }

    soap_envelope =
        axiom_soap_builder_get_soap_envelope(builder_helper->soap_builder, env);
    if (!soap_envelope)
    {
        return AXIS2_FAILURE;
    }

    soap_body = axiom_soap_envelope_get_body(soap_envelope, env);
    if (!soap_body)
    {
        return AXIS2_FAILURE;
    }

    soap_fault = axiom_soap_body_get_fault(soap_body, env);
    if (!soap_fault)
    {
        return AXIS2_FAILURE;
    }

    if (element_level == 4)
    {
        if (axutil_strcmp
            (AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME, ele_localname) == 0)
        {
            if (builder_helper->code_present)
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_MULTIPLE_CODE_ELEMENTS_ENCOUNTERED,
                                AXIS2_FAILURE);
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                       "Multiple  fault code elements encountered in SOAP fault");
                return AXIS2_FAILURE;
            }
            else
            {
                axiom_soap_fault_code_t *soap_fault_code = NULL;
                soap_fault_code = axiom_soap_fault_code_create(env);
                if (!soap_fault_code)
                {
                    return AXIS2_FAILURE;
                }
                axiom_soap_fault_code_set_base_node(soap_fault_code, env,
                                                    om_ele_node);

                axiom_soap_fault_code_set_builder(soap_fault_code, env,
                                                  builder_helper->soap_builder);

                axiom_soap_fault_set_code(soap_fault, env, soap_fault_code);

                builder_helper->code_present = AXIS2_TRUE;
                builder_helper->code_processing = AXIS2_TRUE;
            }
        }
        else if (axutil_strcmp
                 (AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME,
                  ele_localname) == 0)
        {
            if (!(builder_helper->code_processing) &&
                !(builder_helper->sub_code_processing))
            {
                if (builder_helper->code_present)
                {
                    if (builder_helper->reason_present)
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_REASON_ELEMENTS_ENCOUNTERED,
                                        AXIS2_FAILURE);
                        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                            "Multiple fault reason elements encountered in SOAP fault");

                        return AXIS2_FAILURE;
                    }
                    else
                    {
                        axiom_soap_fault_reason_t *fault_reason = NULL;
                        fault_reason = axiom_soap_fault_reason_create(env);
                        if (!fault_reason)
                        {
                            return AXIS2_FAILURE;
                        }

                        axiom_soap_fault_reason_set_base_node(fault_reason, env,
                                                              om_ele_node);

                        axiom_soap_fault_set_reason(soap_fault, env,
                                                    fault_reason);

                        axiom_soap_fault_reason_set_builder(fault_reason, env,
                                                            builder_helper->
                                                            soap_builder);

                        builder_helper->reason_present = AXIS2_TRUE;
                        builder_helper->reason_processing = AXIS2_TRUE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
            else
            {
                if (builder_helper->code_processing)
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_SOAP_FAULT_CODE_DOES_NOT_HAVE_A_VALUE,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_SOAP_FAULT_CODE_DOES_NOT_HAVE_A_VALUE,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
        }
        else if (axutil_strcmp
                 (ele_localname, AXIOM_SOAP12_SOAP_FAULT_NODE_LOCAL_NAME) == 0)
        {
            if (!(builder_helper->reason_processing))
            {
                if (builder_helper->reason_present &&
                    !(builder_helper->role_present) &&
                    !(builder_helper->detail_present))
                {
                    if (builder_helper->node_present)
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_NODE_ELEMENTS_ENCOUNTERED,
                                        AXIS2_FAILURE);
                        return AXIS2_FAILURE;
                    }
                    else
                    {
                        axiom_soap_fault_node_t *soap_fault_node = NULL;
                        soap_fault_node = axiom_soap_fault_node_create(env);
                        if (!soap_fault_node)
                        {
                            return AXIS2_FAILURE;
                        }

                        axiom_soap_fault_node_set_base_node(soap_fault_node,
                                                            env, om_ele_node);

                        axiom_soap_fault_set_node(soap_fault, env,
                                                  soap_fault_node);

                        builder_helper->node_present = AXIS2_TRUE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED,
                                    AXIS2_FALSE);

                    return AXIS2_FAILURE;
                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_SOAP_FAULT_REASON_ELEMENT_SHOULD_HAVE_A_TEXT,
                                AXIS2_FALSE);
                return AXIS2_FAILURE;
            }

        }
        else if (axutil_strcmp
                 (ele_localname, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME) == 0)
        {
            if (!(builder_helper->reason_processing))
            {
                if (builder_helper->reason_present &&
                    !(builder_helper->detail_present))
                {
                    if (builder_helper->role_present)
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_ROLE_ELEMENTS_ENCOUNTERED,
                                        AXIS2_FAILURE);

                        return AXIS2_FAILURE;
                    }
                    else
                    {
                        axiom_soap_fault_role_t *soap_fault_role = NULL;
                        soap_fault_role = axiom_soap_fault_role_create(env);
                        if (!soap_fault_role)
                            return AXIS2_FAILURE;

                        axiom_soap_fault_role_set_base_node(soap_fault_role,
                                                            env, om_ele_node);

                        axiom_soap_fault_set_role(soap_fault, env,
                                                  soap_fault_role);
                        builder_helper->role_present = AXIS2_TRUE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
            else
            {

                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_SOAP_FAULT_ROLE_ELEMENT_SHOULD_HAVE_A_TEXT,
                                AXIS2_FAILURE);
                return AXIS2_FAILURE;
            }
        }
        else if (axutil_strcmp
                 (ele_localname,
                  AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME) == 0)
        {
            if (!(builder_helper->reason_processing))
            {
                if (builder_helper->reason_present)
                {
                    if (builder_helper->detail_present)
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_DETAIL_ELEMENTS_ENCOUNTERED,
                                        AXIS2_FAILURE);
                        return AXIS2_FAILURE;
                    }
                    else
                    {

                        axiom_soap_fault_detail_t *soap_fault_detail = NULL;
                        soap_fault_detail = axiom_soap_fault_detail_create(env);
                        if (!soap_fault_detail)
                            return AXIS2_FAILURE;

                        axiom_soap_fault_detail_set_base_node(soap_fault_detail,
                                                              env, om_ele_node);

                        axiom_soap_fault_set_detail(soap_fault, env,
                                                    soap_fault_detail);
                        builder_helper->detail_present = AXIS2_TRUE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED,
                                    AXIS2_FAILURE);

                    return AXIS2_FAILURE;

                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_SOAP_FAULT_REASON_ELEMENT_SHOULD_HAVE_A_TEXT,
                                AXIS2_FAILURE);
                return AXIS2_FAILURE;
            }

        }
        else
        {
            AXIS2_ERROR_SET(env->error,
                            AXIS2_ERROR_UNSUPPORTED_ELEMENT_IN_SOAP_FAULT_ELEMENT,
                            AXIS2_FAILURE);
            return AXIS2_FAILURE;
        }
    }
    else if (element_level == 5)
    {
        axiom_node_t *parent_node = NULL;
        axiom_element_t *parent_ele = NULL;
        axis2_char_t *parent_localname = NULL;
        parent_node = axiom_node_get_parent(om_ele_node, env);
        if (!parent_node)
        {
            return AXIS2_FAILURE;
        }
        parent_ele =
            (axiom_element_t *) axiom_node_get_data_element(parent_node, env);
        if (!parent_ele)
        {
            return AXIS2_FAILURE;
        }
        parent_localname = axiom_element_get_localname(parent_ele, env);
        if (!parent_localname)
        {
            return AXIS2_FAILURE;
        }

        if (axutil_strcmp(parent_localname,
                          AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME) == 0)
        {
            if (axutil_strcmp
                (ele_localname, AXIOM_SOAP12_SOAP_FAULT_VALUE_LOCAL_NAME) == 0)
            {
                if (!(builder_helper->value_present))
                {
                    axiom_soap_fault_value_t *soap_fault_value = NULL;
                    axiom_soap_fault_code_t *parent_fcode = NULL;

                    soap_fault_value = axiom_soap_fault_value_create(env);
                    if (!soap_fault_value)
                    {
                        return AXIS2_FAILURE;
                    }
                    axiom_soap_fault_value_set_base_node(soap_fault_value, env,
                                                         om_ele_node);

                    parent_fcode = axiom_soap_fault_get_code(soap_fault, env);
                    if (!parent_fcode)
                    {
                        return AXIS2_FAILURE;
                    }
                    axiom_soap_fault_code_set_value(parent_fcode, env,
                                                    soap_fault_value);

                    builder_helper->value_present = AXIS2_TRUE;
                    builder_helper->code_processing = AXIS2_FALSE;

                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_MULTIPLE_VALUE_ENCOUNTERED_IN_CODE_ELEMENT,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
            else if (axutil_strcmp(ele_localname,
                                   AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME)
                     == 0)
            {
                if (!(builder_helper->sub_code_present))
                {
                    if (builder_helper->value_present)
                    {

                        axiom_soap_fault_sub_code_t *fault_subcode = NULL;
                        axiom_soap_fault_code_t *fault_code = NULL;

                        fault_subcode = axiom_soap_fault_sub_code_create(env);
                        if (!fault_subcode)
                        {
                            return AXIS2_FAILURE;
                        }
                        axiom_soap_fault_sub_code_set_base_node(fault_subcode,
                                                                env,
                                                                om_ele_node);

                        fault_code = axiom_soap_fault_get_code(soap_fault, env);
                        if (!fault_code)
                        {
                            return AXIS2_FAILURE;
                        }
                        axiom_soap_fault_code_set_sub_code(fault_code, env,
                                                           fault_subcode);

                        axiom_soap_fault_sub_code_set_builder(fault_subcode,
                                                              env,
                                                              builder_helper->
                                                              soap_builder);

                        builder_helper->sub_code_present = AXIS2_TRUE;
                        builder_helper->sub_code_processing = AXIS2_TRUE;
                    }
                    else
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_SOAP_FAULT_VALUE_SHOULD_BE_PRESENT_BEFORE_SUB_CODE,
                                        AXIS2_FAILURE);
                        return AXIS2_FAILURE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_THIS_LOCALNAME_NOT_SUPPORTED_INSIDE_THE_CODE_ELEMENT,
                                AXIS2_FAILURE);
                return AXIS2_FAILURE;
            }
        }
        else if (axutil_strcmp
                 (parent_localname,
                  AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME) == 0)
        {
            if (axutil_strcmp
                (ele_localname, AXIOM_SOAP12_SOAP_FAULT_TEXT_LOCAL_NAME) == 0)
            {
                axiom_soap_fault_text_t *soap_fault_text = NULL;
                axiom_soap_fault_reason_t *fault_reason = NULL;

                soap_fault_text = axiom_soap_fault_text_create(env);
                if (!soap_fault_text)
                {
                    return AXIS2_FAILURE;
                }
                axiom_soap_fault_text_set_base_node(soap_fault_text, env,
                                                    om_ele_node);

                fault_reason = axiom_soap_fault_get_reason(soap_fault, env);
                if (!fault_reason)
                {
                    return AXIS2_FAILURE;
                }

                axiom_soap_fault_reason_add_soap_fault_text(fault_reason, env,
                                                            soap_fault_text);
                builder_helper->reason_processing = AXIS2_FALSE;

                axiom_soap_builder_set_bool_processing_mandatory_fault_elements
                    (builder_helper->soap_builder, env, AXIS2_FALSE);

            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_REASON_ELEMENT,
                                AXIS2_FAILURE);
                return AXIS2_FAILURE;
            }

        }
        else if (axutil_strcmp
                 (parent_localname,
                  AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME) == 0)
        {
            axiom_soap_builder_set_processing_detail_elements(builder_helper->
                                                              soap_builder, env,
                                                              AXIS2_TRUE);

            if (!(builder_helper->detail_element_names))
            {
                builder_helper->detail_element_names =
                    axutil_array_list_create(env, 20);
            }

            axutil_array_list_add(builder_helper->detail_element_names, env,
                                  ele_localname);

        }
        else
        {

            return AXIS2_FAILURE;
        }

    }
    else if (element_level > 5)
    {
        axiom_node_t *parent_node = NULL;
        axiom_element_t *parent_ele = NULL;
        axis2_char_t *parent_localname = NULL;

        parent_node = axiom_node_get_parent(om_ele_node, env);
        if (!parent_node)
        {
            return AXIS2_FAILURE;
        }
        parent_ele =
            (axiom_element_t *) axiom_node_get_data_element(parent_node, env);
        if (!parent_ele)
        {
            return AXIS2_FAILURE;
        }

        parent_localname = axiom_element_get_localname(parent_ele, env);
        if (!parent_localname)
        {
            return AXIS2_FAILURE;
        }
        if (axutil_strcmp
            (parent_localname,
             AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME) == 0)
        {
            if (axutil_strcmp
                (ele_localname, AXIOM_SOAP12_SOAP_FAULT_VALUE_LOCAL_NAME) == 0)
            {
                if (builder_helper->subcode_value_present)
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
                else
                {

                    axiom_soap_fault_sub_code_t *sub_code = NULL;
                    axiom_soap_fault_code_t *code = NULL;
                    axiom_soap_fault_value_t *value = NULL;
                    code = axiom_soap_fault_get_code(soap_fault, env);

                    if (!code)
                    {
                        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                                        "fault code null when it should not be null");
                        return AXIS2_FAILURE;
                    }

                    sub_code = axiom_soap_fault_code_get_sub_code(code, env);
                    if (!sub_code)
                    {
                        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                                        "fault subcode null when it should not be null");
                        return AXIS2_FAILURE;
                    }
                    value = axiom_soap_fault_value_create(env);
                    if (!value)
                    {
                        return AXIS2_FAILURE;
                    }

                    axiom_soap_fault_value_set_base_node(value, env,
                                                         om_ele_node);

                    axiom_soap_fault_sub_code_set_value(sub_code, env, value);

                    builder_helper->subcode_value_present = AXIS2_TRUE;
                    builder_helper->sub_sub_code_present = AXIS2_FALSE;
                    builder_helper->sub_code_processing = AXIS2_FALSE;
                }
            }
            else if (axutil_strcmp
                     (ele_localname,
                      AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME) == 0)
            {
                if (builder_helper->subcode_value_present)
                {
                    if (!(builder_helper->sub_sub_code_present))
                    {
                        axiom_soap_fault_code_t *fault_code = NULL;
                        axiom_soap_fault_sub_code_t *parent_subcode = NULL;
                        axiom_soap_fault_sub_code_t *subcode = NULL;

                        subcode = axiom_soap_fault_sub_code_create(env);
                        if (!subcode)
                        {
                            return AXIS2_FAILURE;
                        }

                        axiom_soap_fault_sub_code_set_base_node(subcode, env,
                                                                om_ele_node);

                        fault_code = axiom_soap_fault_get_code(soap_fault, env);
                        if (!fault_code)
                        {
                            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                                            "fault code null when it should not be null");
                            return AXIS2_FAILURE;
                        }
                        parent_subcode =
                            axiom_soap_fault_code_get_sub_code(fault_code, env);
                        if (!parent_subcode)
                        {
                            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                                            "fault subcode null when it should not be null");
                            return AXIS2_FAILURE;
                        }

                        axiom_soap_fault_sub_code_set_sub_code(parent_subcode,
                                                               env, subcode);

                        builder_helper->subcode_value_present = AXIS2_FALSE;
                        builder_helper->sub_sub_code_present = AXIS2_TRUE;
                        builder_helper->sub_code_processing = AXIS2_TRUE;
                    }
                    else
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED,
                                        AXIS2_FAILURE);

                        return AXIS2_FAILURE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_SOAP_FAULT_VALUE_SHOULD_BE_PRESENT_BEFORE_SUB_CODE,
                                    AXIS2_FAILURE);

                    return AXIS2_FAILURE;

                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_SUB_CODE_ELEMENT,
                                AXIS2_FAILURE);

                return AXIS2_FAILURE;
            }
        }
        else if (axiom_soap_builder_is_processing_detail_elements
                 (builder_helper->soap_builder, env))
        {

            int detail_element_level = 0;
            axis2_bool_t local_name_exists = AXIS2_FALSE;
            int i = 0;
            if (!(builder_helper->detail_element_names))
            {
                return AXIS2_FAILURE;
            }

            for (i = 0;
                 i <
                 axutil_array_list_size(builder_helper->detail_element_names,
                                        env); i++)
            {
                if (axutil_strcmp
                    (parent_localname,
                     axutil_array_list_get(builder_helper->detail_element_names,
                                           env, i)) == 0)
                {
                    local_name_exists = AXIS2_TRUE;
                    detail_element_level = i + 1;
                }
            }
            if (local_name_exists)
            {
                axutil_array_list_add(builder_helper->detail_element_names, env,
                                      ele_localname);
            }
            else
            {
                return AXIS2_FAILURE;
            }
        }
    }
    return AXIS2_SUCCESS;
}
Ejemplo n.º 15
0
Archivo: util.c Proyecto: AdrianRys/wsf
axis2_status_t
wsclient_set_attachment (const axutil_env_t *env,
						 axiom_node_t *node,
						 axis2_char_t *base_dir,
						 int is_mtom_enabled)
{
	axiom_node_t *child_node = NULL;
	axiom_element_t *element;
	if (!node || !env)
		return AXIS2_FAILURE;

	if (axiom_node_get_node_type (node, env) == AXIOM_ELEMENT)
	{
		axis2_char_t *local_name;
		axiom_namespace_t *ns;
		axis2_char_t *ns_uri;
		element = (axiom_element_t *) axiom_node_get_data_element (node, env);
		local_name = axiom_element_get_localname (element, env);
		if (local_name)
		{
			if (!strcmp (local_name, "Include"))
			{
				ns = axiom_element_get_namespace(element, env, node);
				if (ns && (ns_uri = axiom_namespace_get_uri (ns, env))
					&& (!strcmp (ns_uri, "http://www.w3.org/2004/08/xop/include")))
				{
					axis2_char_t *file_path;
					axiom_data_handler_t *data_handler;
					axiom_text_t *data_text;
					axiom_node_t *data_node;
					axiom_node_t *parent;
					axutil_uri_t *file_uri = NULL;
					axutil_uri_t *base_uri = NULL;
					axutil_uri_t *real_uri = NULL;
					axis2_char_t *real_path = NULL;

					parent = axiom_node_get_parent (node, env);
					axiom_node_detach (node, env);
					file_path = axiom_element_get_attribute_value_by_name (element, env, "href");
					file_uri = axutil_uri_parse_string (env, file_path);

					if (base_dir)
						base_uri = axutil_uri_parse_string (env, base_dir);
					else 
						return AXIS2_FAILURE;


					if (base_uri)
						real_uri = axutil_uri_parse_relative (env, base_uri, file_path);
					else
						return AXIS2_FAILURE;

					if (real_uri)
						real_path = axutil_uri_to_string (real_uri, env, 1);
					else 
						return AXIS2_FAILURE;


					if (real_path)
						data_handler = axiom_data_handler_create (env, real_path, "image/jpeg");
					else
						return AXIS2_FAILURE;

					if (data_handler)
						data_text = axiom_text_create_with_data_handler (env, parent, data_handler, &data_node);
					else
						return AXIS2_FAILURE;

					if (data_text)
					{
						if (!is_mtom_enabled)
							axiom_text_set_optimize (data_text, env, AXIS2_FALSE);
					}
				}
			}
		}

		child_node = axiom_node_get_first_element (node, env);
		while (child_node)
		{
			wsclient_set_attachment (env, child_node, base_dir, is_mtom_enabled); 
			child_node = axiom_node_get_next_sibling (child_node, env);
		}
	}
	else
		return AXIS2_FAILURE;

	return AXIS2_SUCCESS;
}