//----------------------------------------------------------------------------- // Reads arbitrary binary data from the file fp. // fp is positioned at the start of the file. // char *sp_load_binary_file( const axutil_env_t *env, char *header_blob, axutil_stream_t *st, int *len) { *len = 0; char *bin_data = NULL; TmpStore *ts = NULL; axutil_linked_list_t *ll = axutil_linked_list_create(env); // pre-pend header-blob (if any) in front of the remaining data if (header_blob) { int hdr_size = strlen(header_blob); if ( (hdr_size) > SP_IMG_BUF_SIZE) { // failsafe - should never happen. axutil_linked_list_free(ll, env); return NULL; } ts = (TmpStore *)AXIS2_MALLOC(env->allocator, sizeof(TmpStore)); memcpy(ts->buf, header_blob, hdr_size); ts->size = hdr_size; *len += hdr_size; axutil_linked_list_add (ll, env, (void *)ts); } int n_read = 0; while ( 1 ) { ts = (TmpStore *)AXIS2_MALLOC(env->allocator, sizeof(TmpStore)); n_read = axutil_stream_read(st, env, ts->buf, SP_IMG_BUF_SIZE); if (0 == n_read) { AXIS2_FREE(env->allocator, ts); break; } ts->size = n_read; *len += n_read; axutil_linked_list_add (ll, env, (void *)ts); } bin_data = compose_buffer(env, *len, ll); axutil_linked_list_free(ll, env); return bin_data; }
//----------------------------------------------------------------------------- // Reads a binary image from the file fp. // The file should be composed of HTTP mime messages as received in the form of // an HTTP response. fp is already positioned at the start of the image. // The boundary is given by boundId. // char * rp_read_bin_mime_image( const axutil_env_t * env, FILE *fp, const char *boundId, int *len) { char *image_binary = NULL; int actual_filled = 0; TmpStore *ts = NULL; axutil_linked_list_t *ll = axutil_linked_list_create(env); *len = 0; Rp_cb_ctx fill_ctx; init_rp_cb_ctx(env, &fill_ctx); fill_ctx.fp = fp; fill_ctx.bound = boundId; while (!fill_ctx.done) { ts = (TmpStore *)AXIS2_MALLOC(env->allocator, sizeof(TmpStore)); actual_filled = rp_fill_buff_CB(ts->buf, SP_IMG_BUF_SIZE, &fill_ctx); if (0 == actual_filled) { AXIS2_FREE(env->allocator, ts); break; } ts->size = actual_filled; *len += actual_filled; axutil_linked_list_add (ll, env, (void *)ts); } image_binary = compose_buffer(env, *len, ll); axutil_linked_list_free(ll, env); return image_binary; }
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; } } }
void test_link_list(axutil_env_t *env,char * first_item,char * second_item,char * third_item,char *last_item,char *array) { int index_of_item; int index_of_last_item; entry_t * entry; void *get_item; axis2_status_t status; axis2_bool_t bresult; void **array_from_list; linked_list = axutil_linked_list_create(env); CUT_ASSERT(linked_list != NULL); if (!linked_list) return; status = axutil_linked_list_add_first(linked_list,env,(void *)first_item); CUT_ASSERT(status = AXIS2_SUCCESS); bresult = axutil_linked_list_contains(linked_list,env,(void *)second_item); CUT_ASSERT(bresult == AXIS2_FALSE); status = axutil_linked_list_add(linked_list,env,(void *)third_item); CUT_ASSERT(status = AXIS2_SUCCESS); status = axutil_linked_list_add_last(linked_list,env,(void *)last_item); CUT_ASSERT(status = AXIS2_SUCCESS); CUT_ASSERT(axutil_linked_list_size(linked_list,env) == 3); index_of_item = axutil_linked_list_index_of(linked_list,env,third_item); CUT_ASSERT(index_of_item == 1); index_of_last_item = axutil_linked_list_last_index_of(linked_list,env,last_item); CUT_ASSERT(index_of_last_item == 2); entry = axutil_linked_list_get_entry(linked_list,env,0); CUT_ASSERT(entry != NULL); get_item = axutil_linked_list_get(linked_list,env,1); CUT_ASSERT(get_item != NULL); CUT_ASSERT(strcmp((char*)get_item, third_item) == 0); get_item = axutil_linked_list_set(linked_list,env,1,(void *)array); CUT_ASSERT(get_item != NULL); CUT_ASSERT(strcmp((char*)get_item, third_item) == 0); array_from_list = axutil_linked_list_to_array(linked_list,env); CUT_ASSERT(array_from_list != NULL); status = axutil_linked_list_add_at_index(linked_list,env,1,(void *)second_item); CUT_ASSERT(status == AXIS2_SUCCESS); get_item = axutil_linked_list_remove_at_index(linked_list,env,1); CUT_ASSERT(get_item != NULL); bresult = axutil_linked_list_check_bounds_inclusive(linked_list,env,1); CUT_ASSERT(bresult == AXIS2_TRUE); status = axutil_linked_list_remove_entry(linked_list,env,entry); CUT_ASSERT(status == AXIS2_SUCCESS); get_item = axutil_linked_list_remove_first(linked_list,env); CUT_ASSERT(get_item != NULL); get_item = axutil_linked_list_remove_last(linked_list,env); CUT_ASSERT(get_item != NULL); CUT_ASSERT(axutil_linked_list_size(linked_list,env) == 0); bresult = axutil_linked_list_remove(linked_list,env,(void *)third_item); CUT_ASSERT(bresult == AXIS2_FALSE); /* To avoid warning of not using cut_ptr_equal */ CUT_ASSERT_PTR_EQUAL(NULL, NULL, 0); /* To avoid warning of not using cut_int_equal */ CUT_ASSERT_INT_EQUAL(0, 0, 0); /* To avoid warning of not using cut_str_equal */ CUT_ASSERT_STR_EQUAL("", "", 0); axutil_linked_list_free(linked_list,env); }