Esempio n. 1
0
AXIS2_EXTERN int AXIS2_CALL
oxs_token_get_length_value(
    const axutil_env_t *env,
    axiom_node_t *length_node)
{
    axis2_char_t *value = NULL;
    value = (axis2_char_t*)oxs_axiom_get_node_content(env, length_node);
    return axutil_atoi(value);
}
Esempio n. 2
0
axis2_status_t 
buy(const axutil_env_t *env,
        axis2_char_t *user,
        axis2_char_t *password,
        axis2_char_t *symbol,
        axis2_char_t *qty,
        axis2_char_t *epr,
        axis2_char_t *client_home)
{

    axis2_buyRequest_t *buy_request = NULL;
    axis2_buyResponse_t *buy_response = NULL;
    axis2_stub_t *trader_client = NULL;

    buy_request = axis2_buyRequest_create(env);

    axis2_buyRequest_set_userid(buy_request, env, user);
    axis2_buyRequest_set_password(buy_request, env, password);
    axis2_buyRequest_set_symbol(buy_request, env, symbol);    
    axis2_buyRequest_set_qty(buy_request, env, axutil_atoi(qty));
    
    trader_client = axis2_stub_TraderClient_create(env, client_home, epr);

    buy_response = axis2_stub_TraderClient_buy(trader_client, env, buy_request);
    if(buy_response)
    {
        axis2_TradeStatus_t *trade_status = NULL;
        trade_status = axis2_buyResponse_get_trade_status(buy_response, env);
        if(trade_status)
        {
            printf("RESULTS : %s\n", axis2_TradeStatus_get_reason(trade_status, env));
            if(axis2_TradeStatus_get_status(trade_status, env))
                return AXIS2_SUCCESS;
            else
                return AXIS2_FAILURE;
        }
        else 
            return AXIS2_FAILURE;
    }
    else
        return AXIS2_FAILURE;
}
AXIS2_EXTERN axis2_status_t AXIS2_CALL
rampart_replay_detector_with_flat_file(
    rampart_replay_detector_t *rrd,
	const axutil_env_t *env,
    axis2_msg_ctx_t* msg_ctx,
    rampart_context_t *rampart_context)
{
    axutil_linked_list_t *ll = NULL;
    const axis2_char_t *msg_id = NULL;
    const axis2_char_t *ts = NULL;
    const axis2_char_t *addr_msg_id = NULL;
    int max_rcds = RAMPART_RD_DEF_MAX_RCDS;
    axis2_status_t status = AXIS2_FAILURE;
    axutil_hash_t *sec_process_result = NULL;

    /*Get timestamp from security processed results */
    sec_process_result = rampart_get_all_security_processed_results(env, msg_ctx);
    ts = axutil_hash_get(sec_process_result, RAMPART_SPR_TS_CREATED, AXIS2_HASH_KEY_STRING);

    /* get message id from addressing headers */
    addr_msg_id = axis2_msg_ctx_get_wsa_message_id(msg_ctx, env);

    if(!ts && addr_msg_id)
	{
        msg_id = addr_msg_id;
    }
	else if(ts && !addr_msg_id)
	{
        msg_id = ts;
    }
	else if(ts && addr_msg_id)
	{
        msg_id = axutil_strcat(env, addr_msg_id, ts, NULL);
    }
	else
	{
        msg_id = NULL;
    }

    if(!msg_id)
	{
        /* using default msg id */
        msg_id = "RAMPART-DEFAULT-TS";
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
            "[rampart]No msg_id specified, using default = %s", msg_id);
    }


    ll = axutil_linked_list_create(env);
    if(!ll)
	{
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart]Linked list creation failed.");
        return AXIS2_FAILURE;
    }

	status = rampart_replay_detector_read_file(env, ll);
	if(status != AXIS2_SUCCESS)
	{
        /* we have to clear linked list. We don't need to write the contents. So pass false to 
         * denote whether to write the content */
		rampart_replay_detector_write_file(env, ll, AXIS2_FALSE);
        return AXIS2_FAILURE;
    }
	else
	{
        /* Get the number of records to be kept */
        if(rampart_context_get_rd_val(rampart_context, env))
		{
            max_rcds = axutil_atoi(rampart_context_get_rd_val(rampart_context, env));
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
                "[rampart]Using the specified max_rcds  %d\n", max_rcds );
        }
		else
		{
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
                "[rampart]Using the default max_rcds  %d\n", max_rcds );
        }

        /* If the table already have the same key it's a replay */
        if(rampart_replay_detector_check_in_linked_list(ll, env, (void*)msg_id))
		{
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart]For ID=%s, a replay detected", msg_id);
			rampart_replay_detector_write_file(env, ll, AXIS2_FALSE);
            return AXIS2_FAILURE;
        }

        /* if number of records saved are more than allowed, we have to remove them */
        while(axutil_linked_list_size(ll, env) >= max_rcds)
		{
            axis2_char_t *tmp_msg_id = NULL;
            tmp_msg_id = (axis2_char_t*)axutil_linked_list_remove_first(ll, env);
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart]Deleting record  %s\n", tmp_msg_id );
            AXIS2_FREE(env->allocator, tmp_msg_id);
            tmp_msg_id = NULL;
        }

        /* Add current record */
        status = axutil_linked_list_add(ll, env, (void*)axutil_strdup(env,msg_id));
        if(status == AXIS2_SUCCESS)
		{
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart]Adding record  %s\n", msg_id );
        }
		else
		{
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,"[rampart]Cannot add record %s\n", msg_id);
			rampart_replay_detector_write_file(env, ll, AXIS2_FALSE);
            return AXIS2_FAILURE;
        }
		status =  rampart_replay_detector_write_file(env, ll, AXIS2_TRUE);
		axutil_linked_list_free(ll, env);
        if(status == AXIS2_SUCCESS)
		{
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[rampart]Writing records to file succeed." );
			return AXIS2_SUCCESS;
        }
		else
		{
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,"[rampart]Writing records to file failed");
            return AXIS2_FAILURE;
        }
    }
}