void xt_net_post_system_destroy(void *post_object) { assert(post_object); xt_net_post_system_t *post; xt_core_message_t *message; post = post_object; xt_case_list_iterate_start(post->inbox); while ((message = xt_case_list_iterate_next(post->inbox))) { xt_core_message_destroy(message); } xt_case_list_destroy(post->inbox); xt_case_list_destroy(post->outbox); if (post->in_buffer) { free(post->in_buffer); } if (post->out_buffer) { free(post->out_buffer); } free(post); }
void xt_net_http_post_create_rollback(xt_net_http_post_t *http_post) { assert(http_post); if (http_post->inbox) { xt_case_list_destroy(http_post->inbox); } if (http_post->outbox) { xt_case_list_destroy(http_post->outbox); } free(http_post); }
void xt_net_post_system_create_rollback(xt_net_post_system_t *post) { if (post) { if (post->in_buffer) { free(post->in_buffer); } if (post->inbox) { xt_case_list_destroy(post->inbox); } if (post->outbox) { xt_case_list_destroy(post->outbox); } } }
ta_identity_t *ta_identity_create(char *name, xt_core_log_t *log) { assert(name); assert(log); ta_identity_t *identity; xt_core_bool_t so_far_so_good; identity = malloc(sizeof *identity); if (identity) { identity->log = log; identity->phrases_qutex = NULL; identity->phrases = NULL; identity->name = xt_core_string_copy(name); if (identity->name) { so_far_so_good = xt_core_bool_true; } else { so_far_so_good = xt_core_bool_false; xt_core_log_trace(log, " ta ", "xt_core_string_copy"); } } else { so_far_so_good = xt_core_bool_false; xt_core_log_trace(log, " ta ", "malloc"); } if (so_far_so_good) { identity->phrases = xt_case_list_create(ta_phrase_compare, ta_phrase_copy, ta_phrase_destroy); if (identity->phrases) { so_far_so_good = xt_core_bool_true; xt_case_list_set_size_limit(identity->phrases, MAX_PHRASES_SIZE); } else { so_far_so_good = xt_core_bool_false; xt_core_log_enter(log, " ta ", "xt_case_list_create"); } } if (so_far_so_good) { identity->phrases_qutex = xt_sync_qutex_create(); if (!identity->phrases_qutex) { so_far_so_good = xt_core_bool_false; xt_core_log_enter(log, " ta ", "xt_sync_qutex_create"); } } if (identity && !so_far_so_good) { if (identity->name) { xt_core_string_destroy(identity->name); } if (identity->phrases) { xt_case_list_destroy(identity->phrases); } if (identity->phrases_qutex) { xt_sync_qutex_destroy(identity->phrases_qutex); } free(identity); identity = NULL; } return identity; }
xt_case_array_t *create_index_to_name_array(xt_file_csv_t *csv, xt_file_basic_t *file) { assert(csv); assert(file); xt_case_array_t *index_to_name; char *first_line; xt_case_list_t *line_list; xt_case_list_t *field_names; char *field_name; unsigned long field_index; index_to_name = xt_case_array_create(csv->field_count, xt_core_string_compare, xt_core_string_copy, xt_core_string_destroy); if (index_to_name) { line_list = xt_file_basic_get_as_line_list(file); if (line_list) { first_line = xt_case_list_find_first(line_list); if (first_line) { field_names = xt_case_list_create_strings_from_string (first_line, ","); if (field_names) { field_index = 0; xt_case_list_iterate_start(field_names); while ((field_name = xt_case_list_iterate_next(field_names))) { xt_case_array_add(index_to_name, field_index, field_name); field_index++; } xt_case_list_dont_destroy_objects(field_names); xt_case_list_destroy(field_names); } else { xt_core_trace("x_case_list_create_strings_from_string"); } } else { xt_core_trace_exit(""); } xt_case_list_destroy(line_list); } else { xt_core_trace("x_file_basic_get_as_line_list"); } } else { xt_core_trace("x_case_array_add"); } return index_to_name; }
xt_case_array_t *create_objects_array(xt_file_csv_t *csv, xt_file_basic_t *file, unsigned long start_object, unsigned long end_object) { assert(csv); assert(file); xt_case_array_t *objects_array; xt_case_list_t *lines; xt_case_array_t *values; char *line; unsigned long total_object_index; unsigned long relative_object_index; unsigned long total_object_count; objects_array = NULL; lines = xt_file_basic_get_as_line_list(file); if (lines) { total_object_count = xt_case_list_get_size(lines) - 1; if ((0 == start_object) && (0 == end_object)) { end_object = total_object_count - 1; } csv->object_count = (end_object - start_object) + 1; objects_array = xt_case_array_create(csv->object_count, xt_case_array_compare, xt_case_array_copy, xt_case_array_destroy); if (objects_array) { xt_case_list_iterate_start(lines); xt_case_list_iterate_next(lines); total_object_index = 0; relative_object_index = 0; while ((line = xt_case_list_iterate_next(lines))) { if ((total_object_index >= start_object) && (total_object_index <= end_object)) { values = xt_case_array_create_strings_from_string(line, ","); if (values) { xt_case_array_add(objects_array, relative_object_index, values); } else { xt_core_trace("x_case_array_create_strings_from_string"); xt_case_array_destroy(values); } relative_object_index++; } total_object_index++; } } else { xt_core_trace("x_case_array_create"); } xt_case_list_destroy(lines); } else { xt_core_trace("x_file_basic_get_as_line_list"); } return objects_array; }
void ta_identity_destroy(void *identity_object) { assert(identity_object); ta_identity_t *identity = identity_object; xt_core_string_destroy(identity->name); xt_case_list_destroy(identity->phrases); xt_sync_qutex_destroy(identity->phrases_qutex); free(identity); }
void xt_net_http_post_destroy(void *http_post_object) { assert(http_post_object); xt_net_http_post_t *http_post; xt_net_http_message_t *http_message; http_post = http_post_object; xt_case_list_iterate_start(http_post->inbox); while ((http_message = xt_case_list_iterate_next(http_post->inbox))) { xt_net_http_message_destroy(http_message); } xt_case_list_destroy(http_post->inbox); xt_case_list_destroy(http_post->outbox); xt_case_set_destroy(http_post->in_http_headers); if (http_post->in_resource_path) { free(http_post->in_resource_path); } free(http_post); }
xt_case_set_t *xt_net_http_message_get_uri_parameter_as_uuid_set (xt_net_http_message_t *http_message, char *parameter_name) { assert(http_message); assert(parameter_name); xt_core_uuid_t *uuid; char *uuid_string; char *parameter_string; xt_case_list_t *uuid_strings; xt_case_set_t *uuid_set; uuid_set = xt_case_set_create(&http_message->uuid_iobject); if (uuid_set) { parameter_string = xt_net_http_message_get_uri_parameter(http_message, parameter_name); if (parameter_string) { uuid_strings = xt_case_list_create_strings_from_string(parameter_string, ","); if (uuid_strings) { xt_case_list_iterate_start(uuid_strings); while ((uuid_string = xt_case_list_iterate_next(uuid_strings))) { uuid = xt_core_uuid_create_from_string(uuid_string); if (uuid) { if (!xt_case_set_find(uuid_set, uuid)) { if (!xt_case_set_add(uuid_set, uuid)) { xt_core_uuid_destroy(uuid); xt_core_trace("x_case_set_add"); } } else { xt_core_uuid_destroy(uuid); } } else { xt_core_trace("x_core_uuid_create_from_string"); } } xt_case_list_destroy(uuid_strings); } else { xt_core_trace("x_case_list_create_string_from_strings"); } } else { xt_core_trace("x_net_http_message_get_uri_parameter"); } } else { xt_core_trace("x_case_set_create"); } return uuid_set; }
void xt_net_client_system_destroy(void *client_object) { assert(client_object); xt_net_client_system_t *client; client = client_object; xt_net_client_socket_destroy(client->socket); if (client->post) { xt_net_post_system_destroy(client->post); } xt_net_exchange_destroy(client->exchange); free(client->server_ip_address); xt_case_list_destroy(client->engines); pthread_mutex_destroy(&client->messaging_mutex); free(client); }
xt_net_client_system_t *xt_net_client_system_create (const char *server_ip_address, unsigned short server_min_port, unsigned short server_max_port, xt_net_engine_get_name_f get_engine_name, void *custom_client_context, xt_core_log_t *log) { assert(server_ip_address); xt_net_client_system_t *client; xt_core_bool_t success; unsigned long each_engine_id; xt_core_bool_t messaging_mutex_needs_destroy; xt_core_bool_t connected; messaging_mutex_needs_destroy = xt_core_bool_false; connected = xt_core_bool_false; client = malloc(sizeof *client); if (client) { client->log = log; client->post = NULL; client->get_engine_name = get_engine_name; client->custom_client_context = custom_client_context; client->server_min_port = server_min_port; client->server_max_port = server_max_port; client->server_socket_closed = xt_core_bool_true; for (each_engine_id = 0; each_engine_id < XT_NET_ENGINE_TYPE_COUNT; each_engine_id++) { *(client->engines_array + each_engine_id) = NULL; } xt_net_post_ipost_init(&client->ipost, xt_net_post_system_compare, xt_net_post_system_create, xt_net_post_system_create_decoy, xt_net_post_system_destroy, xt_net_post_system_destroy_decoy, xt_net_post_system_get_last_receive_activity_time, xt_net_post_system_get_socket, xt_net_post_system_get_stats, xt_net_post_system_receive_message, xt_net_post_system_receive_messages, xt_net_post_system_send_message, xt_net_post_system_send_messages, xt_net_post_system_is_socket_closed, xt_net_post_system_mod, xt_net_post_system_compare_equal); success = xt_core_bool_true; } else { success = xt_core_bool_false; xt_core_log_trace(client->log, "xnet", "malloc"); } if (success) { client->server_ip_address = strdup(server_ip_address); if (!client->server_ip_address) { success = xt_core_bool_false; } } if (success) { client->exchange = xt_net_exchange_create(&client->ipost); if (!client->exchange) { success = xt_core_bool_false; } } if (success) { client->engines = xt_case_list_create(XT_CORE_OBJECT_NO_COMPARE_F, XT_CORE_OBJECT_NO_COPY_F, destroy_engine_container); if (!client->engines) { success = xt_core_bool_false; } } if (success) { if (0 == pthread_mutex_init(&client->messaging_mutex, NULL)) { messaging_mutex_needs_destroy = xt_core_bool_true; } else { success = xt_core_bool_false; xt_core_log_trace(client->log, "xnet", "pthread_mutex_init"); } } if (success) { connected = connect_to_server(client); if (!connected) { success = xt_core_bool_false; xt_core_log_trace(client->log, "xnet", "connect_to_server"); } } if (!success && client) { if (connected) { xt_net_client_socket_destroy(client->socket); } if (client->exchange) { xt_net_exchange_destroy(client->exchange); } if (client->server_ip_address) { free(client->server_ip_address); } if (client->engines) { xt_case_list_destroy(client->engines); } if (messaging_mutex_needs_destroy) { pthread_mutex_destroy(&client->messaging_mutex); } free(client); client = NULL; } return client; }
xt_case_map_t *create_name_to_index_map(xt_file_csv_t *csv, xt_file_basic_t *file) { assert(csv); assert(file); xt_case_list_t *line_list; xt_case_map_t *map; xt_case_list_t *field_names; char *first_line; char *name_object; unsigned long index; unsigned long *index_object; char *name; map = NULL; line_list = xt_file_basic_get_as_line_list(file); if (line_list) { first_line = xt_case_list_find_first(line_list); if (first_line) { field_names = xt_case_list_create_strings_from_string (first_line, ","); if (field_names) { csv->field_count = xt_case_list_get_size(field_names); map = xt_case_map_create(&xt_core_objects.string_iobject, &xt_core_objects.unsigned_long_iobject, XT_CASE_MAP_DESTROY); if (map) { index = 0; xt_case_list_iterate_start(field_names); while ((name = xt_case_list_iterate_next(field_names))) { name_object = xt_core_string_copy(name); if (name_object) { index_object = malloc(sizeof *index_object); if (index_object) { *index_object = index; if (!xt_case_map_add(map, name_object, index_object)) { xt_core_trace("x_case_map_add"); } } else { xt_core_trace("malloc"); } } else { xt_core_trace("x_core_string_copy"); } index++; } } else { xt_core_trace("x_case_map_create"); } xt_case_list_destroy(field_names); } else { xt_core_trace("x_case_list_create_strings_from_string"); } } else { xt_core_trace("x_case_list_find_first"); } xt_case_list_destroy(line_list); } else { xt_core_trace("x_file_basic_get_as_line_list"); } return map; }