You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2006/10/16 06:46:25 UTC
svn commit: r464375 - in /webservices/axis2/trunk/c/tools/tcpmon:
include/tcpmon_session.h src/entry.c src/session.c src/tcpmon.c src/util.c
Author: dinesh
Date: Sun Oct 15 21:46:22 2006
New Revision: 464375
URL: http://svn.apache.org/viewvc?view=rev&rev=464375
Log:
tcpmon options changed
Modified:
webservices/axis2/trunk/c/tools/tcpmon/include/tcpmon_session.h
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
webservices/axis2/trunk/c/tools/tcpmon/src/util.c
Modified: webservices/axis2/trunk/c/tools/tcpmon/include/tcpmon_session.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/tools/tcpmon/include/tcpmon_session.h?view=diff&rev=464375&r1=464374&r2=464375
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/include/tcpmon_session.h (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/include/tcpmon_session.h Sun Oct 15 21:46:22 2006
@@ -64,6 +64,16 @@
axis2_status_t (AXIS2_CALL *
free)(tcpmon_session_t *session,
const axis2_env_t *env);
+
+
+ axis2_status_t (AXIS2_CALL *
+ set_test_bit) (tcpmon_session_t *session,
+ const axis2_env_t *env,
+ int test_bit);
+
+ axis2_status_t (AXIS2_CALL *
+ get_test_bit) (tcpmon_session_t *session,
+ axis2_env_t *env);
/**
* configure the listening port.
@@ -73,9 +83,9 @@
* @return AXIS2_SUCCESS on success, else AXIS2_FAILURE.
*/
axis2_status_t (AXIS2_CALL *
- set_listen_port) (tcpmon_session_t *session,
- const axis2_env_t *env,
- int listen_port);
+ set_listen_port) (tcpmon_session_t *session,
+ const axis2_env_t *env,
+ int listen_port);
/**
* retrieve the listening port
@@ -188,6 +198,12 @@
#define TCPMON_SESSION_FREE(session, env) \
((session)->ops->free (session, env))
+
+#define TCPMON_SESSION_SET_TEST_BIT(session, env, test_bit) \
+ ((session)->ops->set_test_bit(session, env, test_bit))
+
+#define TCPMON_SESSION_GET_TEST_BIT(session, env) \
+ ((session)->ops->get_test_bit(session, env))
#define TCPMON_SESSION_SET_LISTEN_PORT(session, env, listen_port) \
((session)->ops->set_listen_port(session, env, listen_port))
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?view=diff&rev=464375&r1=464374&r2=464375
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/src/entry.c (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/src/entry.c Sun Oct 15 21:46:22 2006
@@ -31,16 +31,17 @@
*/
typedef struct tcpmon_entry_impl
{
- tcpmon_entry_t entry;
+ tcpmon_entry_t entry;
- axis2_char_t* arrived_time;
- axis2_char_t* sent_time;
- axis2_char_t* sent_data;
- axis2_char_t* arrived_data;
- axis2_char_t* sent_headers;
- axis2_char_t* arrived_headers;
- axis2_bool_t is_success;
- axis2_char_t* time_diff;
+ axis2_char_t* arrived_time;
+ axis2_char_t* sent_time;
+ axis2_char_t* sent_data;
+ axis2_char_t* arrived_data;
+ axis2_char_t* sent_headers;
+ axis2_char_t* arrived_headers;
+ axis2_bool_t is_success;
+ axis2_char_t* time_diff;
+ axis2_char_t* test_file_name;
}
tcpmon_entry_impl_t;
@@ -51,100 +52,103 @@
axis2_status_t AXIS2_CALL
tcpmon_entry_free(tcpmon_entry_t *entry,
- const axis2_env_t *env);
+ const axis2_env_t *env);
axis2_char_t* AXIS2_CALL
-tcpmon_entry_arrived_time(tcpmon_entry_t *entry,
- const axis2_env_t *env);
+tcpmon_entry_arrived_time( tcpmon_entry_t *entry,
+ const axis2_env_t *env);
axis2_char_t* AXIS2_CALL
tcpmon_entry_sent_time(tcpmon_entry_t *entry,
- const axis2_env_t *env);
+ const axis2_env_t *env);
axis2_char_t* AXIS2_CALL
tcpmon_entry_time_diff(tcpmon_entry_t *entry,
- const axis2_env_t *env);
+ const axis2_env_t *env);
axis2_char_t* AXIS2_CALL
tcpmon_entry_sent_data(tcpmon_entry_t *entry,
- const axis2_env_t *env);
+ const axis2_env_t *env);
axis2_char_t* AXIS2_CALL
tcpmon_entry_sent_headers(tcpmon_entry_t *entry,
- const axis2_env_t *env);
+ const axis2_env_t *env);
axis2_char_t* AXIS2_CALL
tcpmon_entry_arrived_data(tcpmon_entry_t *entry,
- const axis2_env_t *env);
+ const axis2_env_t *env);
axis2_char_t* AXIS2_CALL
tcpmon_entry_arrived_headers(tcpmon_entry_t *entry,
- const axis2_env_t *env);
+ const axis2_env_t *env);
axis2_bool_t AXIS2_CALL
tcpmon_entry_is_success(tcpmon_entry_t *entry,
- const axis2_env_t *env);
+ const axis2_env_t *env);
axis2_char_t*
get_current_stream_to_buffer(axis2_stream_t* stream,
- const axis2_env_t* env,
- int* stream_size);
+ const axis2_env_t* env,
+ int* stream_size);
axis2_char_t*
read_current_stream(axis2_stream_t *stream,
- const axis2_env_t *env,
- int *stream_size,
- axis2_char_t** header,
- axis2_char_t** data);
-
+ const axis2_env_t *env,
+ int *stream_size,
+ axis2_char_t** header,
+ axis2_char_t** data);
+
+int
+write_to_file (char *filename,
+ char *buffer);
/************************** End of function prototypes ************************/
AXIS2_EXTERN tcpmon_entry_t * AXIS2_CALL
tcpmon_entry_create(const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, NULL);
+ AXIS2_ENV_CHECK(env, NULL);
- entry_impl = (tcpmon_entry_impl_t *) AXIS2_MALLOC(env->
- allocator, sizeof(tcpmon_entry_impl_t));
+ entry_impl = (tcpmon_entry_impl_t *) AXIS2_MALLOC(env->
+ allocator, sizeof(tcpmon_entry_impl_t));
- if (NULL == entry_impl)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- return NULL;
- }
-
- entry_impl -> arrived_time = AXIS2_MALLOC(env->allocator, 32);
- entry_impl -> sent_time = AXIS2_MALLOC(env->allocator, 32);
- entry_impl -> time_diff = AXIS2_MALLOC(env->allocator, 32);
- entry_impl -> arrived_data = NULL;
- entry_impl -> sent_data = NULL;
- entry_impl -> arrived_headers = NULL;
- entry_impl -> sent_headers = NULL;
- entry_impl -> is_success = AXIS2_FALSE;
-
- entry_impl->entry.ops =
- AXIS2_MALLOC(env->allocator, sizeof(tcpmon_entry_ops_t));
- if (NULL == entry_impl->entry.ops)
- {
- tcpmon_entry_free(&(entry_impl->entry), env);
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- return NULL;
- }
-
- entry_impl->entry.ops->free = tcpmon_entry_free;
- entry_impl->entry.ops->arrived_time = tcpmon_entry_arrived_time;
- entry_impl->entry.ops->sent_time = tcpmon_entry_sent_time;
- entry_impl->entry.ops->time_diff = tcpmon_entry_time_diff;
- entry_impl->entry.ops->sent_data = tcpmon_entry_sent_data;
- entry_impl->entry.ops->sent_headers = tcpmon_entry_sent_headers;
- entry_impl->entry.ops->arrived_data = tcpmon_entry_arrived_data;
- entry_impl->entry.ops->arrived_headers = tcpmon_entry_arrived_headers;
- entry_impl->entry.ops->is_success = tcpmon_entry_is_success;
+ if (NULL == entry_impl)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ entry_impl -> arrived_time = AXIS2_MALLOC(env->allocator, 32);
+ entry_impl -> sent_time = AXIS2_MALLOC(env->allocator, 32);
+ entry_impl -> time_diff = AXIS2_MALLOC(env->allocator, 32);
+ entry_impl -> arrived_data = NULL;
+ entry_impl -> sent_data = NULL;
+ entry_impl -> arrived_headers = NULL;
+ entry_impl -> sent_headers = NULL;
+ entry_impl -> is_success = AXIS2_FALSE;
+
+ entry_impl->entry.ops =
+ AXIS2_MALLOC(env->allocator, sizeof(tcpmon_entry_ops_t));
+ if (NULL == entry_impl->entry.ops)
+ {
+ tcpmon_entry_free(&(entry_impl->entry), env);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ entry_impl->entry.ops->free = tcpmon_entry_free;
+ entry_impl->entry.ops->arrived_time = tcpmon_entry_arrived_time;
+ entry_impl->entry.ops->sent_time = tcpmon_entry_sent_time;
+ entry_impl->entry.ops->time_diff = tcpmon_entry_time_diff;
+ entry_impl->entry.ops->sent_data = tcpmon_entry_sent_data;
+ entry_impl->entry.ops->sent_headers = tcpmon_entry_sent_headers;
+ entry_impl->entry.ops->arrived_data = tcpmon_entry_arrived_data;
+ entry_impl->entry.ops->arrived_headers = tcpmon_entry_arrived_headers;
+ entry_impl->entry.ops->is_success = tcpmon_entry_is_success;
- return &(entry_impl->entry);
+ return &(entry_impl->entry);
}
@@ -152,167 +156,167 @@
axis2_status_t AXIS2_CALL
tcpmon_entry_free(tcpmon_entry_t *entry,
- const axis2_env_t *env)
+ const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
- if (entry->ops)
- {
- AXIS2_FREE(env->allocator, entry->ops);
- entry->ops = NULL;
- }
-
- if (entry_impl -> arrived_time)
- {
- AXIS2_FREE(env-> allocator, entry_impl -> arrived_time);
- entry_impl -> arrived_time = NULL;
- }
- if (entry_impl -> sent_time)
- {
- AXIS2_FREE(env-> allocator, entry_impl -> sent_time);
- entry_impl -> sent_time = NULL;
- }
- if (entry_impl -> time_diff)
- {
- AXIS2_FREE(env-> allocator, entry_impl -> time_diff);
- entry_impl -> time_diff = NULL;
- }
- if (entry_impl -> arrived_data)
- {
- AXIS2_FREE(env-> allocator, entry_impl -> arrived_data);
- entry_impl -> arrived_data = NULL;
- }
- if (entry_impl -> sent_data)
- {
- AXIS2_FREE(env-> allocator, entry_impl -> sent_data);
- entry_impl -> sent_data = NULL;
- }
- if (entry_impl -> arrived_headers)
- {
- AXIS2_FREE(env-> allocator, entry_impl -> arrived_headers);
- entry_impl -> arrived_headers = NULL;
- }
- if (entry_impl -> sent_headers)
- {
- AXIS2_FREE(env-> allocator, entry_impl -> sent_headers);
- entry_impl -> sent_headers = NULL;
- }
-
- if (entry_impl)
- {
- AXIS2_FREE(env->allocator, entry_impl);
- entry_impl = NULL;
- }
+ if (entry->ops)
+ {
+ AXIS2_FREE(env->allocator, entry->ops);
+ entry->ops = NULL;
+ }
+
+ if (entry_impl -> arrived_time)
+ {
+ AXIS2_FREE(env-> allocator, entry_impl -> arrived_time);
+ entry_impl -> arrived_time = NULL;
+ }
+ if (entry_impl -> sent_time)
+ {
+ AXIS2_FREE(env-> allocator, entry_impl -> sent_time);
+ entry_impl -> sent_time = NULL;
+ }
+ if (entry_impl -> time_diff)
+ {
+ AXIS2_FREE(env-> allocator, entry_impl -> time_diff);
+ entry_impl -> time_diff = NULL;
+ }
+ if (entry_impl -> arrived_data)
+ {
+ AXIS2_FREE(env-> allocator, entry_impl -> arrived_data);
+ entry_impl -> arrived_data = NULL;
+ }
+ if (entry_impl -> sent_data)
+ {
+ AXIS2_FREE(env-> allocator, entry_impl -> sent_data);
+ entry_impl -> sent_data = NULL;
+ }
+ if (entry_impl -> arrived_headers)
+ {
+ AXIS2_FREE(env-> allocator, entry_impl -> arrived_headers);
+ entry_impl -> arrived_headers = NULL;
+ }
+ if (entry_impl -> sent_headers)
+ {
+ AXIS2_FREE(env-> allocator, entry_impl -> sent_headers);
+ entry_impl -> sent_headers = NULL;
+ }
+
+ if (entry_impl)
+ {
+ AXIS2_FREE(env->allocator, entry_impl);
+ entry_impl = NULL;
+ }
- return AXIS2_SUCCESS;
+ return AXIS2_SUCCESS;
}
axis2_char_t* AXIS2_CALL
tcpmon_entry_arrived_time(tcpmon_entry_t *entry,
- const axis2_env_t *env)
+ const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
- return entry_impl-> arrived_time;
+ return entry_impl-> arrived_time;
}
axis2_char_t* AXIS2_CALL
tcpmon_entry_sent_time(tcpmon_entry_t *entry,
- const axis2_env_t *env)
+ const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
- return entry_impl-> sent_time;
+ return entry_impl-> sent_time;
}
axis2_char_t* AXIS2_CALL
tcpmon_entry_time_diff(tcpmon_entry_t *entry,
- const axis2_env_t *env)
+ const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
- return entry_impl-> time_diff;
+ return entry_impl-> time_diff;
}
axis2_char_t* AXIS2_CALL
tcpmon_entry_sent_data(tcpmon_entry_t *entry,
- const axis2_env_t *env)
+ const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
- return entry_impl-> sent_data;
+ return entry_impl-> sent_data;
}
axis2_char_t* AXIS2_CALL
tcpmon_entry_sent_headers(tcpmon_entry_t *entry,
- const axis2_env_t *env)
+ const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
- return entry_impl-> sent_headers;
+ return entry_impl-> sent_headers;
}
axis2_char_t* AXIS2_CALL
tcpmon_entry_arrived_data(tcpmon_entry_t *entry,
- const axis2_env_t *env)
+ const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
- return entry_impl-> arrived_data;
+ return entry_impl-> arrived_data;
}
axis2_char_t* AXIS2_CALL
tcpmon_entry_arrived_headers(tcpmon_entry_t *entry,
- const axis2_env_t *env)
+ const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
- return entry_impl-> arrived_headers;
+ return entry_impl-> arrived_headers;
}
axis2_bool_t AXIS2_CALL
tcpmon_entry_is_success(tcpmon_entry_t *entry,
- const axis2_env_t *env)
+ const axis2_env_t *env)
{
- tcpmon_entry_impl_t *entry_impl = NULL;
+ tcpmon_entry_impl_t *entry_impl = NULL;
- AXIS2_ENV_CHECK(env, AXIS2_FALSE);
+ AXIS2_ENV_CHECK(env, AXIS2_FALSE);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
- return entry_impl-> is_success;
+ return entry_impl-> is_success;
}
/** implimentations for protected methods */
@@ -320,306 +324,342 @@
/** executes as new entry arises */
void* tcpmon_entry_new_entry_funct(axis2_thread_t *thd, void* data)
{
- tcpmon_entry_request_data_t* req_data = data;
- const axis2_env_t* env = NULL;
- int client_socket = -1;
- int host_socket = -1;
- tcpmon_session_t* session;
- TCPMON_SESSION_TRANS_ERROR_FUNCT on_trans_fault_funct;
- TCPMON_SESSION_NEW_ENTRY_FUNCT on_new_entry;
-
- axis2_stream_t* client_stream = NULL;
- axis2_stream_t* host_stream = NULL;
- int buffer_size = 0;
- axis2_char_t* headers = NULL;
- axis2_char_t* content = NULL;
- axis2_char_t* buffer = NULL;
- time_t now;
- struct tm* localTime = NULL;
- int arrived_secs = 0;
- int sent_secs = 0;
- int time_diff_i = 0;
- int target_port = 0;
- axis2_char_t* target_host = NULL;
-
-
- env = req_data -> env;
- client_socket = req_data-> socket;
- session = req_data-> session;
- on_trans_fault_funct =
- tcpmon_session_get_on_trans_fault(session, env);
- on_new_entry =
- tcpmon_session_get_on_new_entry(session, env);
-
- tcpmon_entry_t* entry = NULL;
- tcpmon_entry_impl_t* entry_impl = NULL;
-
- entry = tcpmon_entry_create(env);
- entry_impl = AXIS2_INTF_TO_IMPL(entry);
-
- target_port = TCPMON_SESSION_GET_TARGET_PORT(session, env);
- target_host = TCPMON_SESSION_GET_TARGET_HOST(session, env);
-
- if (target_port == -1 || target_host == NULL)
- {
- axis2_network_handler_close_socket(env, client_socket);
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Missing target port and host"
- "input missing");
- if (on_trans_fault_funct)
- {
- (on_trans_fault_funct)(env,
- "Missing target port and host");
- }
- return NULL;
- }
- client_stream = axis2_stream_create_socket(env, client_socket);
- if (NULL == client_stream)
- {
- axis2_network_handler_close_socket(env, client_socket);
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in creating client stream"
- "handling response");
- /** call the callback */
- if (on_trans_fault_funct)
- {
- (on_trans_fault_funct)(env,
- "error in creating the client stream");
- }
- return NULL;
- }
-
-
- buffer = read_current_stream(client_stream, env, &buffer_size,
- &headers, &content);
-
- now = time(NULL);
- localTime = localtime(&now);
-
- sprintf(entry_impl-> sent_time, "%d:%d:%d" , localTime-> tm_hour, localTime-> tm_min,
- localTime-> tm_sec);
- sent_secs = localTime-> tm_hour * 60 * 60 +
- localTime-> tm_min * 60 +
- localTime-> tm_sec;
-
- /*free ( localTime); */
-
- entry_impl-> sent_headers = headers;
- entry_impl-> sent_data = content;
-
- if (on_new_entry)
- {
- (on_new_entry)(env, entry, 0);
- }
-
-
-
- host_socket = axis2_network_handler_open_socket(env, target_host, target_port);
- if (-1 == host_socket)
- {
- AXIS2_STREAM_WRITE(client_stream, env, NULL, 0);
- AXIS2_STREAM_FREE(client_stream, env);
- axis2_network_handler_close_socket(env, client_socket);
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in creating host_socket"
- "creating socket");
- /** call the callback */
- if (on_trans_fault_funct)
- {
- (on_trans_fault_funct)(env,
- "error in creating the host socket");
- }
- return NULL;
- }
-
- host_stream = axis2_stream_create_socket(env, host_socket);
- if (NULL == host_stream)
- {
- AXIS2_STREAM_WRITE(client_stream, env, NULL, 0);
- AXIS2_STREAM_FREE(client_stream, env);
- axis2_network_handler_close_socket(env, client_socket);
- axis2_network_handler_close_socket(env, host_socket);
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in creating host stream"
- "handling response");
- /** call the callback */
- if (on_trans_fault_funct)
- {
- (on_trans_fault_funct)(env,
- "error in creating the host stream");
- }
- return NULL;
- }
-
- AXIS2_STREAM_WRITE(host_stream, env, buffer , buffer_size);
- AXIS2_FREE(env-> allocator, buffer);
-
- buffer = read_current_stream(host_stream, env, &buffer_size,
- &headers, &content);
-
-
- now = time(NULL);
- localTime = localtime(&now);
-
- sprintf(entry_impl-> arrived_time, "%d:%d:%d" , localTime-> tm_hour, localTime-> tm_min,
- localTime-> tm_sec);
- arrived_secs = localTime-> tm_hour * 60 * 60 +
- localTime-> tm_min * 60 +
- localTime-> tm_sec;
- /*free ( localTime); */
-
-
- time_diff_i = arrived_secs - sent_secs;
- if (time_diff_i < 0)
- {
- time_diff_i += 24 * 60 * 60 ;
- }
- sprintf(entry_impl-> time_diff, "%d sec(s)", time_diff_i);
-
- entry_impl-> arrived_headers = headers;
- entry_impl-> arrived_data = content;
- if (buffer == NULL || buffer_size == 0)
- {
- entry_impl->is_success = 0;
- }
- else
- {
- entry_impl->is_success = 1;
- }
-
- if (on_new_entry)
- {
- (on_new_entry)(env, entry, 1);
- }
-
-
- AXIS2_STREAM_WRITE(client_stream, env, buffer, buffer_size);
- AXIS2_FREE(env-> allocator, buffer);
-
- AXIS2_STREAM_FREE(client_stream, env);
- AXIS2_STREAM_FREE(host_stream, env);
- axis2_network_handler_close_socket(env, client_socket);
- axis2_network_handler_close_socket(env, host_socket);
+ tcpmon_entry_request_data_t* req_data = data;
+ const axis2_env_t* env = NULL;
+ int client_socket = -1;
+ int host_socket = -1;
+ tcpmon_session_t* session;
+ TCPMON_SESSION_TRANS_ERROR_FUNCT on_trans_fault_funct;
+ TCPMON_SESSION_NEW_ENTRY_FUNCT on_new_entry;
+
+ axis2_stream_t* client_stream = NULL;
+ axis2_stream_t* host_stream = NULL;
+ int buffer_size = 0;
+ axis2_char_t* headers = NULL;
+ axis2_char_t* content = NULL;
+ axis2_char_t* buffer = NULL;
+ time_t now;
+ struct tm* localTime = NULL;
+ int arrived_secs = 0;
+ int sent_secs = 0;
+ int time_diff_i = 0;
+ int target_port = 0;
+ axis2_char_t* target_host = NULL;
+ int test_bit = 0;
+
+ env = req_data -> env;
+ client_socket = req_data-> socket;
+ session = req_data-> session;
+ on_trans_fault_funct =
+ tcpmon_session_get_on_trans_fault(session, env);
+ on_new_entry =
+ tcpmon_session_get_on_new_entry(session, env);
+
+ tcpmon_entry_t* entry = NULL;
+ tcpmon_entry_impl_t* entry_impl = NULL;
+
+ entry = tcpmon_entry_create(env);
+ entry_impl = AXIS2_INTF_TO_IMPL(entry);
+
+ target_port = TCPMON_SESSION_GET_TARGET_PORT(session, env);
+ target_host = TCPMON_SESSION_GET_TARGET_HOST(session, env);
+
+ if (target_port == -1 || target_host == NULL)
+ {
+ axis2_network_handler_close_socket(env, client_socket);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Missing target port and host"
+ "input missing");
+ if (on_trans_fault_funct)
+ {
+ (on_trans_fault_funct)(env,
+ "Missing target port and host");
+ }
+ return NULL;
+ }
+ client_stream = axis2_stream_create_socket(env, client_socket);
+ if (NULL == client_stream)
+ {
+ axis2_network_handler_close_socket(env, client_socket);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in creating client stream"
+ "handling response");
+ /** call the callback */
+ if (on_trans_fault_funct)
+ {
+ (on_trans_fault_funct)(env,
+ "error in creating the client stream");
+ }
+ return NULL;
+ }
+
+
+ buffer = read_current_stream(client_stream, env, &buffer_size,
+ &headers, &content);
+
+ test_bit = TCPMON_SESSION_GET_TEST_BIT(session, env);
+
+ if (test_bit)
+ {
+ write_to_file ("reqest", buffer);
+ }
+
+ now = time(NULL);
+ localTime = localtime(&now);
+
+ sprintf(entry_impl-> sent_time, "%d:%d:%d" , localTime-> tm_hour, localTime-> tm_min,
+ localTime-> tm_sec);
+ sent_secs = localTime-> tm_hour * 60 * 60 +
+ localTime-> tm_min * 60 +
+ localTime-> tm_sec;
+
+ /*free ( localTime); */
+
+ entry_impl-> sent_headers = headers;
+ entry_impl-> sent_data = content;
+
+ if (on_new_entry)
+ {
+ (on_new_entry)(env, entry, 0);
+ }
+
+
+
+ host_socket = axis2_network_handler_open_socket(env, target_host, target_port);
+ if (-1 == host_socket)
+ {
+ AXIS2_STREAM_WRITE(client_stream, env, NULL, 0);
+ AXIS2_STREAM_FREE(client_stream, env);
+ axis2_network_handler_close_socket(env, client_socket);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in creating host_socket"
+ "creating socket");
+ /** call the callback */
+ if (on_trans_fault_funct)
+ {
+ (on_trans_fault_funct)(env,
+ "error in creating the host socket");
+ }
+ return NULL;
+ }
+
+ host_stream = axis2_stream_create_socket(env, host_socket);
+ if (NULL == host_stream)
+ {
+ AXIS2_STREAM_WRITE(client_stream, env, NULL, 0);
+ AXIS2_STREAM_FREE(client_stream, env);
+ axis2_network_handler_close_socket(env, client_socket);
+ axis2_network_handler_close_socket(env, host_socket);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in creating host stream"
+ "handling response");
+ /** call the callback */
+ if (on_trans_fault_funct)
+ {
+ (on_trans_fault_funct)(env,
+ "error in creating the host stream");
+ }
+ return NULL;
+ }
+
+ AXIS2_STREAM_WRITE(host_stream, env, buffer , buffer_size);
+ AXIS2_FREE(env-> allocator, buffer);
+
+ buffer = read_current_stream(host_stream, env, &buffer_size,
+ &headers, &content);
+
+ test_bit = TCPMON_SESSION_GET_TEST_BIT (session, env);
+ if (test_bit)
+ {
+ write_to_file ("response", buffer);
+ }
+
+ now = time(NULL);
+ localTime = localtime(&now);
+
+ sprintf(entry_impl-> arrived_time, "%d:%d:%d" , localTime-> tm_hour, localTime-> tm_min,
+ localTime-> tm_sec);
+ arrived_secs = localTime-> tm_hour * 60 * 60 +
+ localTime-> tm_min * 60 +
+ localTime-> tm_sec;
+ /*free ( localTime); */
+
+
+ time_diff_i = arrived_secs - sent_secs;
+ if (time_diff_i < 0)
+ {
+ time_diff_i += 24 * 60 * 60 ;
+ }
+ sprintf(entry_impl-> time_diff, "%d sec(s)", time_diff_i);
+
+ entry_impl-> arrived_headers = headers;
+ entry_impl-> arrived_data = content;
+ if (buffer == NULL || buffer_size == 0)
+ {
+ entry_impl->is_success = 0;
+ }
+ else
+ {
+ entry_impl->is_success = 1;
+ }
+
+ if (on_new_entry)
+ {
+ (on_new_entry)(env, entry, 1);
+ }
+
+
+ AXIS2_STREAM_WRITE(client_stream, env, buffer, buffer_size);
+ AXIS2_FREE(env-> allocator, buffer);
+
+ AXIS2_STREAM_FREE(client_stream, env);
+ AXIS2_STREAM_FREE(host_stream, env);
+ axis2_network_handler_close_socket(env, client_socket);
+ axis2_network_handler_close_socket(env, host_socket);
- return NULL;
+ return NULL;
}
axis2_char_t*
read_current_stream(axis2_stream_t *stream,
- const axis2_env_t *env,
- int *stream_size,
- axis2_char_t **header,
- axis2_char_t **data)
-{
- int read_size = 0;
- axis2_char_t *buffer = NULL;
- axis2_char_t *header_ptr = NULL;
- axis2_char_t *body_ptr = NULL;
- int header_found = 0;
- int header_just_finished = 0;
- int read = 0;
- int header_width = 0;
- int current_line_offset = 0;
- axis2_char_t *current_line = NULL;
- int line_just_ended = 1;
- axis2_char_t *length_char = 0;
- int length = -1;
- int chunked_encoded = 0;
-
-
- buffer = AXIS2_MALLOC(env-> allocator, sizeof(axis2_char_t));
- do
- {
- buffer = AXIS2_REALLOC(env-> allocator, buffer,
- sizeof(axis2_char_t) * (read_size + 1));
- read = AXIS2_STREAM_READ(stream, env , buffer + read_size, 1);
-
- if (header_just_finished)
- {
- header_just_finished = 0;
- header_width = read_size;
- }
- /** identify the content lenth*/
- if (!header_found && *(buffer + read_size) == '\r')
- {
- *(buffer + read_size) = '\0';
- current_line = buffer + current_line_offset;
- if (strstr(current_line, "Content-Length"))
- {
- if ((length_char = strstr(current_line, ":")))
- {
- length_char++;
- length = atoi(length_char);
- }
- }
- *(buffer + read_size) = '\r';
- }
- if (!header_found && line_just_ended)
- {
- line_just_ended = 0;
- current_line_offset = read_size;
- }
- if (!header_found && *(buffer + read_size) == '\n')
- {
- line_just_ended = 1; /* set for the next loop to read*/
- }
- if (header_found)
- {
- length--;
- }
- if (header_found &&
- read_size >= 4 &&
- chunked_encoded == 1 &&
- *(buffer + read_size) == '\n' &&
- *(buffer + read_size - 1) == '\r' &&
- *(buffer + read_size - 2) == '\n' &&
- *(buffer + read_size - 3) == '\r' &&
- *(buffer + read_size - 4) == '0')
- {
- length = 0; /** this occurs in chunked transfer encoding */
- }
-
- /** identify the end of the header */
- if (!header_found &&
- read_size >= 3 &&
- *(buffer + read_size) == '\n' &&
- *(buffer + read_size - 1) == '\r' &&
- *(buffer + read_size - 2) == '\n' &&
- *(buffer + read_size - 3) == '\r')
- {
- header_found = 1;
- *(buffer + read_size - 3) = '\0';
- header_ptr = (axis2_char_t*)AXIS2_STRDUP(buffer, env);
- header_just_finished = 1;
- *(buffer + read_size - 3) = '\r';
- }
- read_size ++;
- if (!chunked_encoded && length < -1)
- {
- header_width = 0;
- /* break;*/
- /** this is considered as transfer-encoding = chunked */
- chunked_encoded = 1;
- header_found = 1;
- *(buffer + read_size - 3) = '\0';
- header_ptr = (axis2_char_t*)AXIS2_STRDUP(buffer, env);
- header_just_finished = 1;
- *(buffer + read_size - 3) = '\r';
- }
- }
- while (length != 0);
-
- if (header_width != 0)
- {
- body_ptr = buffer + header_width;
- *data = (axis2_char_t*) AXIS2_STRDUP(body_ptr, env);
- }
- else
- {
- *(buffer + read_size) = '\0';
- header_ptr = (axis2_char_t*)AXIS2_STRDUP(buffer, env);
- /** soap body part is unavailable */
- *data = NULL;
- }
-
- *header = header_ptr;
- *stream_size = read_size;
- return buffer;
+ const axis2_env_t *env,
+ int *stream_size,
+ axis2_char_t **header,
+ axis2_char_t **data)
+{
+ int read_size = 0;
+ axis2_char_t *buffer = NULL;
+ axis2_char_t *header_ptr = NULL;
+ axis2_char_t *body_ptr = NULL;
+ int header_found = 0;
+ int header_just_finished = 0;
+ int read = 0;
+ int header_width = 0;
+ int current_line_offset = 0;
+ axis2_char_t *current_line = NULL;
+ int line_just_ended = 1;
+ axis2_char_t *length_char = 0;
+ int length = -1;
+ int chunked_encoded = 0;
+
+
+ buffer = AXIS2_MALLOC(env-> allocator, sizeof(axis2_char_t));
+ do
+ {
+ buffer = AXIS2_REALLOC(env-> allocator, buffer,
+ sizeof(axis2_char_t) * (read_size + 1));
+ read = AXIS2_STREAM_READ(stream, env , buffer + read_size, 1);
+
+ if (header_just_finished)
+ {
+ header_just_finished = 0;
+ header_width = read_size;
+ }
+ /** identify the content lenth*/
+ if (!header_found && *(buffer + read_size) == '\r')
+ {
+ *(buffer + read_size) = '\0';
+ current_line = buffer + current_line_offset;
+ if (strstr(current_line, "Content-Length"))
+ {
+ if ((length_char = strstr(current_line, ":")))
+ {
+ length_char++;
+ length = atoi(length_char);
+ }
+ }
+ *(buffer + read_size) = '\r';
+ }
+ if (!header_found && line_just_ended)
+ {
+ line_just_ended = 0;
+ current_line_offset = read_size;
+ }
+ if (!header_found && *(buffer + read_size) == '\n')
+ {
+ line_just_ended = 1; /* set for the next loop to read*/
+ }
+ if (header_found)
+ {
+ length--;
+ }
+ if (header_found &&
+ read_size >= 4 &&
+ chunked_encoded == 1 &&
+ *(buffer + read_size) == '\n' &&
+ *(buffer + read_size - 1) == '\r' &&
+ *(buffer + read_size - 2) == '\n' &&
+ *(buffer + read_size - 3) == '\r' &&
+ *(buffer + read_size - 4) == '0')
+ {
+ length = 0; /** this occurs in chunked transfer encoding */
+ }
+
+ /** identify the end of the header */
+ if (!header_found &&
+ read_size >= 3 &&
+ *(buffer + read_size) == '\n' &&
+ *(buffer + read_size - 1) == '\r' &&
+ *(buffer + read_size - 2) == '\n' &&
+ *(buffer + read_size - 3) == '\r')
+ {
+ header_found = 1;
+ *(buffer + read_size - 3) = '\0';
+ header_ptr = (axis2_char_t*)AXIS2_STRDUP(buffer, env);
+ header_just_finished = 1;
+ *(buffer + read_size - 3) = '\r';
+ }
+ read_size ++;
+ if (!chunked_encoded && length < -1)
+ {
+ header_width = 0;
+ /* break;*/
+ /** this is considered as transfer-encoding = chunked */
+ chunked_encoded = 1;
+ header_found = 1;
+ *(buffer + read_size - 3) = '\0';
+ header_ptr = (axis2_char_t*)AXIS2_STRDUP(buffer, env);
+ header_just_finished = 1;
+ *(buffer + read_size - 3) = '\r';
+ }
+ }
+ while (length != 0);
+
+ if (header_width != 0)
+ {
+ body_ptr = buffer + header_width;
+ *data = (axis2_char_t*) AXIS2_STRDUP(body_ptr, env);
+ }
+ else
+ {
+ *(buffer + read_size) = '\0';
+ header_ptr = (axis2_char_t*)AXIS2_STRDUP(buffer, env);
+ /** soap body part is unavailable */
+ *data = NULL;
+ }
+
+ *header = header_ptr;
+ *stream_size = read_size;
+ return buffer;
+}
+
+
+
+
+int
+write_to_file (char *filename,
+ char *buffer)
+{
+ int size = 0;
+ if (filename)
+ {
+ FILE *fp = fopen (filename, "w");
+ size = fwrite (buffer, 1, strlen (buffer), fp);
+ fclose (fp);
+ }
+ return size;
}
+
+
+
+
+
+
+
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?view=diff&rev=464375&r1=464374&r2=464375
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/src/session.c (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/src/session.c Sun Oct 15 21:46:22 2006
@@ -34,6 +34,7 @@
tcpmon_session_t session;
int listen_port;
int target_port;
+ int test_bit;
axis2_char_t *target_host;
TCPMON_SESSION_NEW_ENTRY_FUNCT on_new_entry_funct;
TCPMON_SESSION_TRANS_ERROR_FUNCT on_trans_fault_funct;
@@ -104,6 +105,15 @@
const axis2_env_t *env,
TCPMON_SESSION_TRANS_ERROR_FUNCT on_trans_fault_funct);
+int AXIS2_CALL
+tcpmon_session_get_test_bit (tcpmon_session_t *session,
+ const axis2_env_t *env);
+
+int AXIS2_CALL
+tcpmon_session_set_test_bit (tcpmon_session_t *session,
+ const axis2_env_t *env,
+ int test_bit);
+
/** internal implementations */
void * AXIS2_THREAD_FUNC
@@ -129,6 +139,7 @@
session_impl -> listen_port = -1;
session_impl -> target_port = -1;
+ session_impl->test_bit = -1;
session_impl -> target_host = NULL;
session_impl -> on_new_entry_funct = NULL;
@@ -146,6 +157,8 @@
session_impl-> is_running = AXIS2_FALSE;
session_impl->session.ops->free = tcpmon_session_free;
+ session_impl->session.ops->set_test_bit = tcpmon_session_set_test_bit;
+ session_impl->session.ops->get_test_bit = tcpmon_session_get_test_bit;
session_impl->session.ops->set_listen_port = tcpmon_session_set_listen_port;
session_impl->session.ops->get_listen_port = tcpmon_session_get_listen_port;
session_impl->session.ops->set_target_port = tcpmon_session_set_target_port;
@@ -202,6 +215,36 @@
return AXIS2_SUCCESS;
}
+
+
+axis2_status_t AXIS2_CALL
+tcpmon_session_set_test_bit (tcpmon_session_t *session,
+ const axis2_env_t *env,
+ int test_bit)
+{
+ tcpmon_session_impl_t *session_impl = NULL;
+
+ AXIS2_ENV_CHECK (env, AXIS2_FAILURE);
+
+ session_impl = AXIS2_INTF_TO_IMPL (session);
+ session_impl -> test_bit = test_bit;
+ return AXIS2_SUCCESS;
+}
+
+
+axis2_status_t AXIS2_CALL
+tcpmon_session_get_test_bit (tcpmon_session_t *session,
+ const axis2_env_t *env)
+{
+ tcpmon_session_impl_t *session_impl = NULL;
+
+ AXIS2_ENV_CHECK (env, AXIS2_FAILURE);
+
+ session_impl = AXIS2_INTF_TO_IMPL (session);
+
+ return session_impl->test_bit;
+}
+
axis2_status_t AXIS2_CALL
tcpmon_session_set_listen_port(tcpmon_session_t *session,
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?view=diff&rev=464375&r1=464374&r2=464375
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/src/tcpmon.c (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/src/tcpmon.c Sun Oct 15 21:46:22 2006
@@ -11,145 +11,181 @@
#define SIZE 1024
int on_new_entry(const axis2_env_t *env,
- tcpmon_entry_t* entry,
- int status);
+ tcpmon_entry_t* entry,
+ int status);
int on_error_func(const axis2_env_t *env,
- char* error_message);
-
-
+ char* error_message);
int main(int argc, char** argv)
{
- axis2_env_t* env = NULL;
- axis2_allocator_t* allocator = NULL;
- axis2_error_t *error = NULL;
- axis2_log_t *log = NULL;
- axis2_thread_pool_t *thread_pool = NULL;
- tcpmon_session_t* session = NULL;
- int c;
- int listen_port, target_port;
- char *target_host;
-
- allocator = axis2_allocator_init(NULL);
-
- error = axis2_error_create(allocator);
- log = axis2_log_create(allocator, NULL, "axis2_tcpmon.log");
- thread_pool = axis2_thread_pool_init(allocator);
-
- env = axis2_env_create_with_error_log_thread_pool(allocator, error, log,
- thread_pool);
-
- if ((argc == 2 && AXIS2_STRCMP(argv[1], "-h")) ||
- !(argc == 3 || argc == 4))
- {
- printf("Usage : %s LISTEN_PORT TARGET_PORT [TARGET_HOST]\n", argv[0]);
- printf("use -h for help\n");
- return 0;
- }
- if (argc > 1)
- {
- listen_port = atoi(argv[1]);
- if (listen_port == 0)
- {
- printf("INVALID value for listen port\n");
- printf("use -h for help\n");
- return 0;
- }
- }
- if (argc > 2)
- {
- target_port = atoi(argv[2]);
- if (target_port == 0)
- {
- printf("INVALID value for target port\n");
- printf("use -h for help\n");
- return 0;
- }
- }
- /* if the target_host is not given fill with the default */
- if (argc > 3)
- {
- target_host = (char*)AXIS2_STRDUP(argv[3], env);
- }
- else
- {
- target_host = (char*)AXIS2_STRDUP("localhost", env);
- }
- session = tcpmon_session_create(env);
-
- TCPMON_SESSION_SET_LISTEN_PORT(session, env, listen_port);
- TCPMON_SESSION_SET_TARGET_PORT(session, env, target_port);
- TCPMON_SESSION_SET_TARGET_HOST(session, env, target_host);
- TCPMON_SESSION_ON_TRANS_FAULT(session, env, on_error_func);
- TCPMON_SESSION_ON_NEW_ENTRY(session, env, on_new_entry);
-
- TCPMON_SESSION_START(session, env);
-
- do
- {
- c = getchar();
- }
- while (c != 'q');
-
- TCPMON_SESSION_STOP(session, env);
- TCPMON_SESSION_FREE(session, env);
- AXIS2_FREE(env-> allocator, target_host);
- axis2_allocator_free(allocator);
- axis2_env_free(env);
- return 0;
+ axis2_env_t* env = NULL;
+ axis2_allocator_t* allocator = NULL;
+ axis2_error_t *error = NULL;
+ axis2_log_t *log = NULL;
+ axis2_thread_pool_t *thread_pool = NULL;
+ tcpmon_session_t* session = NULL;
+ int c;
+ int listen_port = 0, target_port = 0;
+ char *target_host = NULL;
+ int test_bit = 0;
+ int ii = 1;
+
+ allocator = axis2_allocator_init(NULL);
+
+ error = axis2_error_create(allocator);
+ log = axis2_log_create(allocator, NULL, "axis2_tcpmon.log");
+ thread_pool = axis2_thread_pool_init(allocator);
+
+ env = axis2_env_create_with_error_log_thread_pool(allocator, error, log,
+ thread_pool);
+
+ if (argc < 2 || !AXIS2_STRCMP(argv[1], "-h"))
+ {
+ printf("Usage : %s [OPTIONS] -lp LISTEN_PORT -tp TARGET_PORT -th [TARGET_HOST]\n", argv[0]);
+ printf("use -h for help\n");
+ return 0;
+ }
+
+ while (ii < argc)
+ {
+ if (!strcmp ("-lp", argv[ii]))
+ {
+ ii++;
+ listen_port = atoi(argv[ii++]);
+ if (listen_port == 0)
+ {
+ printf("INVALID value for listen port\n");
+ printf("use -h for help\n");
+ return 0;
+ }
+
+ }
+ else if (!strcmp ("-tp", argv[ii]))
+ {
+ ii++;
+ target_port = atoi(argv[ii++]);
+ if (target_port == 0)
+ {
+ printf("INVALID value for target port\n");
+ printf("use -h for help\n");
+ return 0;
+ }
+ }
+ else if (!strcmp ("-th", argv[ii]))
+ {
+ ii++;
+ target_host = (char*)AXIS2_STRDUP(argv[ii++], env);
+ }
+ else if (!strcmp ("--test", argv [ii]))
+ {
+ ii++;
+ test_bit = 1;
+ }
+ else
+ {
+ printf("INVALID value for tcpmon \n");
+ printf("use -h for help\n");
+ return 0;
+ }
+ }
+
+ if (!(listen_port && target_port && target_host))
+ {
+ printf ("ERROR: essential argument missing \n");
+ printf ("Please recheck values of listen_port (-lp), target_port(-tp) and target_host (-th)\n");
+ return 0;
+ }
+
+ session = tcpmon_session_create(env);
+
+ TCPMON_SESSION_SET_LISTEN_PORT(session, env, listen_port);
+ TCPMON_SESSION_SET_TARGET_PORT(session, env, target_port);
+ TCPMON_SESSION_SET_TARGET_HOST(session, env, target_host);
+ TCPMON_SESSION_ON_TRANS_FAULT(session, env, on_error_func);
+ TCPMON_SESSION_ON_NEW_ENTRY(session, env, on_new_entry);
+ TCPMON_SESSION_SET_TEST_BIT (session, env, test_bit);
+ TCPMON_SESSION_START(session, env);
+
+ do
+ {
+ c = getchar();
+ }
+ while (c != 'q');
+
+ TCPMON_SESSION_STOP(session, env);
+ TCPMON_SESSION_FREE(session, env);
+ AXIS2_FREE(env-> allocator, target_host);
+ axis2_allocator_free(allocator);
+ axis2_env_free(env);
+ return 0;
}
int on_new_entry(const axis2_env_t *env,
- tcpmon_entry_t* entry,
- int status)
+ tcpmon_entry_t* entry,
+ int status)
{
- char* plain_buffer = NULL;
- char* formated_buffer = NULL;
- if (status == 0)
- {
- plain_buffer = TCPMON_ENTRY_SENT_DATA(entry, env);
- if (plain_buffer) /* this can be possible as no xml present */
- {
- formated_buffer = tcpmon_util_format_as_xml
- (env, plain_buffer);
- }
- else
- {
- formated_buffer = "";
- }
- printf("%s\n", "SENDING DATA..");
- printf("/* sending time = %s*/\n", TCPMON_ENTRY_SENT_TIME(entry, env));
- printf("---------------------\n");
-
- printf("%s\n\n%s\n\n", TCPMON_ENTRY_SENT_HEADERS(entry, env),
- formated_buffer);
- }
- if (status == 1)
- {
- plain_buffer = TCPMON_ENTRY_ARRIVED_DATA(entry, env);
- if (plain_buffer) /* this can be possible as no xml present */
- {
- formated_buffer = tcpmon_util_format_as_xml
- (env, plain_buffer);
- }
- else
- {
- formated_buffer = "";
- }
- printf("%s\n", "RETRIEVING DATA..");
- printf("/* retrieving time = %s*/\n", TCPMON_ENTRY_ARRIVED_TIME(entry, env));
- printf("/* time throughput = %s*/\n", TCPMON_ENTRY_TIME_DIFF(entry, env));
- printf("---------------------\n");
-
- printf("%s\n\n%s\n\n", TCPMON_ENTRY_ARRIVED_HEADERS(entry, env),
- formated_buffer);
- }
- return 0;
+ char* plain_buffer = NULL;
+ char* formated_buffer = NULL;
+ if (status == 0)
+ {
+ plain_buffer = TCPMON_ENTRY_SENT_DATA(entry, env);
+ if (plain_buffer) /* this can be possible as no xml present */
+ {
+ formated_buffer = tcpmon_util_format_as_xml
+ (env, plain_buffer);
+ }
+ else
+ {
+ formated_buffer = "";
+ }
+ printf("%s\n", "SENDING DATA..");
+ printf("/* sending time = %s*/\n", TCPMON_ENTRY_SENT_TIME(entry, env));
+ printf("---------------------\n");
+
+ printf("%s\n\n%s\n\n", TCPMON_ENTRY_SENT_HEADERS(entry, env),
+ formated_buffer);
+ }
+ if (status == 1)
+ {
+ plain_buffer = TCPMON_ENTRY_ARRIVED_DATA(entry, env);
+ if (plain_buffer) /* this can be possible as no xml present */
+ {
+ formated_buffer = tcpmon_util_format_as_xml
+ (env, plain_buffer);
+ }
+ else
+ {
+ formated_buffer = "";
+ }
+ printf("%s\n", "RETRIEVING DATA..");
+ printf("/* retrieving time = %s*/\n", TCPMON_ENTRY_ARRIVED_TIME(entry, env));
+ printf("/* time throughput = %s*/\n", TCPMON_ENTRY_TIME_DIFF(entry, env));
+ printf("---------------------\n");
+
+ printf("%s\n\n%s\n\n", TCPMON_ENTRY_ARRIVED_HEADERS(entry, env),
+ formated_buffer);
+ }
+ return 0;
}
int on_error_func(const axis2_env_t *env,
- char* error_message)
+ char* error_message)
{
- fprintf(stderr, "ERROR: %s\n", error_message);
- return 0;
+ fprintf(stderr, "ERROR: %s\n", error_message);
+ return 0;
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Modified: webservices/axis2/trunk/c/tools/tcpmon/src/util.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/tools/tcpmon/src/util.c?view=diff&rev=464375&r1=464374&r2=464375
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/src/util.c (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/src/util.c Sun Oct 15 21:46:22 2006
@@ -22,162 +22,7 @@
AXIS2_EXTERN axis2_char_t* AXIS2_CALL
tcpmon_util_format_as_xml(const axis2_env_t* env, axis2_char_t* data)
{
- tcpmon_util_allocator_t* allocator = NULL;
- axis2_char_t* p = NULL;
- axis2_char_t* flag = NULL;
- axis2_char_t tmp;
- int tabs = 0;
- int xml_part_found = 0;
- int indent_on_next_it = 0;
-
- allocator = (tcpmon_util_allocator_t*) AXIS2_MALLOC(env->
- allocator, sizeof(tcpmon_util_allocator_t));
- allocator-> buffer = NULL;
- allocator-> allocated = 0;
- allocator-> index = 0;
-
- for (p = flag = data, tabs = 0 ; *p ; p ++)
- {
- /** dont do anything until this is seen */
- for (;!xml_part_found && *p && !(*p == '<' && *(p + 1) == '?'); p ++)
- {
- /** just a new line */
- if (*p == '\n')
- {
- tmp = *(p + 1);
- *(p + 1) = '\0';
- add_string(env, allocator, flag);
- *(p + 1) = tmp;
- flag = p + 1;
- }
- }
- xml_part_found = 1; /* we come here after we found xml */
- /** ignore cases nothing to process */
- for (; *p == ' ' || *p == '\n' || *p == '\r' || *p == '\t' ||
- (*p > 'a' && *p < 'z') || /* simple letters */
- (*p > 'A' && *p < 'Z') || /* capital letters */
- (*p > '0' && *p < '9'); p ++)
- {
- /** new lines handle specially to keept the indentation */
- if (*p == '\n')
- {
- /* surly there will be an iteration in next line, so dont do explicitly */
- if (indent_on_next_it)
- {
- flag = p + 1;
- }
- else
- {
- tmp = *(p + 1);
- *(p + 1) = '\0';
- add_string(env, allocator, flag);
- *(p + 1) = tmp;
- flag = p + 1;
- add_axis2_char_t(env, allocator, '\n', 1);
- add_axis2_char_t(env, allocator, '\t', tabs);
- }
- }
- }
- indent_on_next_it = 0;
- /** found a comment */
- if (*p == '<' && *(p + 1) == '!' /**just continue since string conts */
- && *(p + 2) == '-'
- && *(p + 3) == '-')
- {
- for (; *p ; p ++)
- {
-
- /** end the comment */
- if (*p == '-' && *(p + 1) == '-'
- && *(p + 2) == '>')
- {
- break;
- }
- /** just a new line */
- if (*p == '\n')
- {
- tmp = *(p + 1);
- *(p + 1) = '\0';
- add_string(env, allocator, flag);
- *(p + 1) = tmp;
- flag = p + 1;
- add_axis2_char_t(env, allocator, '\n', 1);
- add_axis2_char_t(env, allocator, '\t', tabs);
- }
- }
- /** end the strig insdie the comment:| */
- if (!*p)
- {
- break;
- }
- }
- /** found a quote*/
- if (*p == '"')
- {
- for (; *p && *p != '"'; p ++);
- if (!*p)
- {
- break;
- }
- }
-
- /** open tag */
- if (*p == '<' && !(*(p + 1) == '/' || *(p + 1) == '?'))
- {
- tabs ++;
- }
- /** close tag */
- if (*p == '<' && *(p + 1) == '/')
- {
- tabs --;
- tmp = *p;
- *p = '\0';
- add_string(env, allocator, flag);
- add_axis2_char_t(env, allocator, '\n', 1);
- add_axis2_char_t(env, allocator, '\t', tabs);
- *p = tmp;
- flag = p;
- }
- /** found '>' go to a new line */
- if (*p == '>')
- {
- /** ignore spaces */
- for (; *p && *p == ' '; p ++);
- if (!*p)
- {
- break;
- }
-
- /** places like <this/> */
- if (p != data && *(p - 1) == '/')
- {
- tabs --;
- }
-
- /** these are special case - new line would be set on next iterate */
- if (*(p + 1) == '<' && *(p + 2) == '/')
- {}
- else
- {
- tmp = *(p + 1);
- *(p + 1) = '\0';
- add_string(env, allocator, flag);
- *(p + 1) = tmp;
- flag = p + 1;
-
- add_axis2_char_t(env, allocator, '\n', 1);
- add_axis2_char_t(env, allocator, '\t', tabs);
- indent_on_next_it = 1;
- }
- }
- }
- if ( !xml_part_found)
- {
- return AXIS2_STRDUP( data, env);
- }
- add_axis2_char_t (env, allocator, '\0', 1);
- /**(allocator-> buffer + allocator-> index) = '\0';*/
- return allocator-> buffer;
+ return data;
}
void add_string(const axis2_env_t* env,
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org