Author: pini Date: Thu Jan 24 01:26:46 2008 New Revision: 614828 URL: http://svn.apache.org/viewvc?rev=614828&view=rev Log: Fixing jira issue 296
Modified: webservices/axis2/trunk/c/tools/tcpmon/src/entry.c webservices/axis2/trunk/c/tools/tcpmon/src/session.c webservices/axis2/trunk/c/tools/tcpmon/src/tcpmon.c Modified: webservices/axis2/trunk/c/tools/tcpmon/src/entry.c URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/tools/tcpmon/src/entry.c?rev=614828&r1=614827&r2=614828&view=diff ============================================================================== --- webservices/axis2/trunk/c/tools/tcpmon/src/entry.c (original) +++ webservices/axis2/trunk/c/tools/tcpmon/src/entry.c Thu Jan 24 01:26:46 2008 @@ -431,6 +431,14 @@ { (on_trans_fault_funct) (env, "Missing target port and host"); } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } return NULL; } client_stream = axutil_stream_create_socket(env, client_socket); @@ -445,6 +453,14 @@ { (on_trans_fault_funct) (env, "error in creating the client stream"); } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } return NULL; } @@ -495,6 +511,14 @@ { (on_trans_fault_funct) (env, "error in creating the host socket"); } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } return NULL; } @@ -513,6 +537,14 @@ { (on_trans_fault_funct) (env, "error in creating the host stream"); } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } return NULL; } @@ -569,6 +601,18 @@ axutil_network_handler_close_socket(env, client_socket); axutil_network_handler_close_socket(env, host_socket); + if (entry_impl) + { + tcpmon_entry_free(&(entry_impl->entry), env); + } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } return NULL; } @@ -589,6 +633,7 @@ int read = 0; int header_width = 0; int current_line_offset = 0; + int mtom_optimized = 0; axis2_char_t *current_line = NULL; int line_just_ended = 1; axis2_char_t *length_char = 0; @@ -600,6 +645,7 @@ { buffer = AXIS2_REALLOC(env->allocator, buffer, sizeof(axis2_char_t) * (read_size + 1)); + *(buffer + read_size) = '\0'; read = axutil_stream_read(stream, env, buffer + read_size, 1); if (header_just_finished) @@ -613,6 +659,8 @@ { *(buffer + read_size) = '\0'; current_line = buffer + current_line_offset; + if (!mtom_optimized && strstr(current_line, "multipart/related")) + mtom_optimized = 1; if (strstr(current_line, "Content-Length")) { if ((length_char = strstr(current_line, ":"))) @@ -659,6 +707,10 @@ { header_found = 1; *(buffer + read_size - 3) = '\0'; + if (header_ptr) + { + AXIS2_FREE(env->allocator, header_ptr); + } header_ptr = (axis2_char_t *) axutil_strdup(env, buffer); header_just_finished = 1; *(buffer + read_size - 3) = '\r'; @@ -673,24 +725,50 @@ chunked_encoded = 1; header_found = 1; *(buffer + read_size - 3) = '\0'; + if (header_ptr) + { + AXIS2_FREE(env->allocator, header_ptr); + } header_ptr = (axis2_char_t *) axutil_strdup(env, buffer); header_just_finished = 1; *(buffer + read_size - 3) = '\r'; } + if (!(*(buffer + read_size - 1))) + { + if (!mtom_optimized) + { + read_size--; + length = 0; + } + else + { + *(buffer + read_size - 1) = ' '; + } + } } while (length != 0); + buffer = AXIS2_REALLOC(env->allocator, buffer, + sizeof(axis2_char_t) * (read_size + 1)); + *(buffer + read_size) = '\0'; + if (header_width != 0) { body_ptr = buffer + header_width; - *data = (axis2_char_t *) axutil_strdup(env, body_ptr); + if (body_ptr && *body_ptr) + { + *data = (axis2_char_t *) axutil_strdup(env, body_ptr); + } + body_ptr = NULL; } else { - *(buffer + read_size) = '\0'; + if (header_ptr) + { + AXIS2_FREE(env->allocator, header_ptr); + } header_ptr = (axis2_char_t *) axutil_strdup(env, buffer); - - /** soap body part is unavailable */ + /** soap body part is unavailable */ *data = NULL; } Modified: webservices/axis2/trunk/c/tools/tcpmon/src/session.c URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/tools/tcpmon/src/session.c?rev=614828&r1=614827&r2=614828&view=diff ============================================================================== --- webservices/axis2/trunk/c/tools/tcpmon/src/session.c (original) +++ webservices/axis2/trunk/c/tools/tcpmon/src/session.c Thu Jan 24 01:26:46 2008 @@ -56,6 +56,9 @@ #define AXIS2_INTF_TO_IMPL(session) \ ((tcpmon_session_impl_t *) session) +axutil_thread_t *server_thread = NULL; +tcpmon_session_server_thread_data_t *thread_data = NULL; + /************************* Function prototypes ********************************/ @@ -393,8 +396,6 @@ const axutil_env_t * env) { tcpmon_session_impl_t *session_impl = NULL; - axutil_thread_t *server_thread = NULL; - tcpmon_session_server_thread_data_t *thread_data = NULL; AXIS2_ENV_CHECK(env, AXIS2_FAILURE); @@ -438,6 +439,17 @@ session_impl = AXIS2_INTF_TO_IMPL(session); session_impl->is_running = AXIS2_FALSE; + if (server_thread) + { + AXIS2_FREE(env->allocator, server_thread); + server_thread = NULL; + } + if (thread_data) + { + AXIS2_FREE(env->allocator, (tcpmon_session_server_thread_data_t *)thread_data); + thread_data = NULL; + } + return AXIS2_SUCCESS; } @@ -504,6 +516,16 @@ "error in creating the server socket, " "port may be already occupied"); } + if (thd) + { + AXIS2_FREE(env->allocator, server_thread); + server_thread = NULL; + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_session_server_thread_data_t *)data); + thread_data = NULL; + } return NULL; } while (session_impl->is_running) @@ -548,7 +570,16 @@ axutil_thread_pool_thread_detach(env->thread_pool, request_thread); } axutil_network_handler_close_socket(env, listen_socket); - + if (thd) + { + AXIS2_FREE(env->allocator, server_thread); + server_thread = NULL; + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_session_server_thread_data_t *)data); + thread_data = NULL; + } return NULL; } Modified: webservices/axis2/trunk/c/tools/tcpmon/src/tcpmon.c URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/tools/tcpmon/src/tcpmon.c?rev=614828&r1=614827&r2=614828&view=diff ============================================================================== --- webservices/axis2/trunk/c/tools/tcpmon/src/tcpmon.c (original) +++ webservices/axis2/trunk/c/tools/tcpmon/src/tcpmon.c Thu Jan 24 01:26:46 2008 @@ -23,19 +23,25 @@ #include <tcpmon_session.h> #include <tcpmon_entry.h> #include <tcpmon_util.h> +#include <signal.h> #include <stdio.h> #define SIZE 1024 axis2_char_t *tcpmon_traffic_log = "tcpmon_traffic.log"; +axutil_env_t *system_env = NULL; +tcpmon_session_t *session = NULL; +char *target_host = NULL; int on_new_entry( const axutil_env_t * env, tcpmon_entry_t * entry, int status); + int on_new_entry_to_file( const axutil_env_t * env, tcpmon_entry_t * entry, int status); + int on_error_func( const axutil_env_t * env, char *error_message); @@ -45,35 +51,22 @@ const char *search, const char *replace); +void sig_handler( + int signal); + int main( int argc, char **argv) { axutil_env_t *env = NULL; - axutil_allocator_t *allocator = NULL; - axutil_error_t *error = NULL; - axutil_log_t *log = NULL; - axutil_thread_pool_t *thread_pool = NULL; - tcpmon_session_t *session = NULL; int c; int listen_port = 9090, target_port = 8080; - char *target_host = NULL; int test_bit = 0; int format_bit = 0; int ii = 1; - allocator = axutil_allocator_init(NULL); - - error = axutil_error_create(allocator); - log = axutil_log_create(allocator, NULL, "axis2_tcpmon.log"); - thread_pool = axutil_thread_pool_init(allocator); - - env = axutil_env_create_with_error_log_thread_pool(allocator, error, log, - thread_pool); - target_host = axutil_strdup(env, "localhost"); - if (!axutil_strcmp(argv[1], "-h")) { printf @@ -93,6 +86,16 @@ return 0; } + env = axutil_env_create_all("axis2_tcpmon.log", AXIS2_LOG_LEVEL_DEBUG); + +#ifndef WIN32 + signal(SIGINT, sig_handler); + signal(SIGPIPE, sig_handler); + system_env = env; +#endif + + target_host = axutil_strdup(env, "localhost"); + while (ii < argc) { if (!strcmp("-lp", argv[ii])) @@ -103,6 +106,12 @@ { printf("INVALID value for listen port\n"); printf("Use -h for help\n"); + AXIS2_FREE(env->allocator, target_host); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } return 0; } @@ -115,12 +124,19 @@ { printf("INVALID value for target port\n"); printf("Use -h for help\n"); + AXIS2_FREE(env->allocator, target_host); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } return 0; } } else if (!strcmp("-th", argv[ii])) { ii++; + AXIS2_FREE(env->allocator, target_host); target_host = (char *) axutil_strdup(env, argv[ii++]); } else if (!strcmp("--test", argv[ii])) @@ -142,6 +158,12 @@ { printf("INVALID value for tcpmon \n"); printf("Use -h for help\n"); + AXIS2_FREE(env->allocator, target_host); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } return 0; } } @@ -151,6 +173,12 @@ printf("ERROR: essential argument missing \n"); printf ("Please recheck values of listen_port (-lp), target_port(-tp) and target_host (-th)\n"); + AXIS2_FREE(env->allocator, target_host); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } return 0; } @@ -178,8 +206,11 @@ TCPMON_SESSION_STOP(session, env); TCPMON_SESSION_FREE(session, env); AXIS2_FREE(env->allocator, target_host); - axutil_allocator_free(allocator); - axutil_env_free(env); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } return 0; } @@ -234,14 +265,22 @@ TCPMON_ENTRY_SENT_TIME(entry, env)); fprintf(file, "---------------------\n"); - convert = TCPMON_ENTRY_SENT_HEADERS(entry, env); + convert = axutil_strdup(env, TCPMON_ENTRY_SENT_HEADERS(entry, env)); convert = str_replace(convert, "; ", ";\n\t"); fprintf(file, "%s", convert); + if (convert) + { + free(convert); + } - convert = formated_buffer; + convert = axutil_strdup(env, formated_buffer); convert = str_replace(convert, "; ", ";\n\t"); convert = str_replace(convert, "><", ">\n<"); fprintf(file, "%s", convert); + if (convert) + { + free(convert); + } } if (status == 1) @@ -275,14 +314,21 @@ TCPMON_ENTRY_TIME_DIFF(entry, env)); fprintf(file, "---------------------\n"); - convert = TCPMON_ENTRY_ARRIVED_HEADERS(entry, env); + convert = axutil_strdup(env, TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)); convert = str_replace(convert, "; ", ";\n\t"); fprintf(file, "%s", convert); - - convert = formated_buffer; + if (convert) + { + free(convert); + } + convert = axutil_strdup(env, formated_buffer); convert = str_replace(convert, "; ", ";\n\t"); convert = str_replace(convert, "><", ">\n<"); fprintf(file, "%s", convert); + if (convert) + { + free(convert); + } } fclose(file); @@ -401,5 +447,53 @@ } free(str_tmp); + free(str); return (str_return); } + +/** + * Signal handler + */ +#ifndef WIN32 +void +sig_handler( + int signal) +{ + + if (!system_env) + { + AXIS2_LOG_ERROR(system_env->log, AXIS2_LOG_SI, + "Received signal %d, unable to proceed system_env is NULL,\ + system exit with -1", signal); + _exit (-1); + } + + switch (signal) + { + case SIGINT: + { + AXIS2_LOG_INFO(system_env->log, "Received signal SIGINT. Utility " + "shutting down"); + TCPMON_SESSION_STOP(session, system_env); + TCPMON_SESSION_FREE(session, system_env); + AXIS2_FREE(system_env->allocator, target_host); + if (system_env) + { + axutil_env_free(system_env); + } + exit(0); + } + case SIGPIPE: + { + AXIS2_LOG_INFO(system_env->log, "Received signal SIGPIPE. Operation " + "aborted"); + return; + } + case SIGSEGV: + { + fprintf(stderr, "Received deadly signal SIGSEGV. Terminating\n"); + _exit(-1); + } + } +} +#endif --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]