You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sh...@apache.org on 2009/01/05 12:10:32 UTC
svn commit: r731527 - in /webservices/axis2/trunk/c/tools/tcpmon:
include/tcpmon_util.h src/entry.c src/session.c src/tcpmon.c src/util.c
Author: shankar
Date: Mon Jan 5 03:10:32 2009
New Revision: 731527
URL: http://svn.apache.org/viewvc?rev=731527&view=rev
Log:
Fix for issue AXIS2C-1230
Modified:
webservices/axis2/trunk/c/tools/tcpmon/include/tcpmon_util.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_util.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/tools/tcpmon/include/tcpmon_util.h?rev=731527&r1=731526&r2=731527&view=diff
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/include/tcpmon_util.h (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/include/tcpmon_util.h Mon Jan 5 03:10:32 2009
@@ -21,6 +21,7 @@
#include <axutil_env.h>
#include <axutil_string.h>
+#include <axutil_stream.h>
/**
* @file tcpmon_util.h
@@ -53,6 +54,33 @@
const char *search,
const char *replace);
+ axis2_char_t * tcpmon_util_strcat(
+ axis2_char_t * dest,
+ axis2_char_t * source,
+ int *buff_size,
+ const axutil_env_t * env);
+
+ axis2_char_t *
+ tcpmon_util_read_current_stream(
+ const axutil_env_t * env,
+ axutil_stream_t * stream,
+ int *stream_size,
+ axis2_char_t ** header,
+ axis2_char_t ** data);
+
+ char *
+ tcpmon_util_str_replace(
+ const axutil_env_t *env,
+ char *str,
+ const char *search,
+ const char *replace);
+
+ int
+ tcpmon_util_write_to_file(
+ char *filename,
+ char *buffer);
+
+
/** @} */
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=731527&r1=731526&r2=731527&view=diff
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/src/entry.c (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/src/entry.c Mon Jan 5 03:10:32 2009
@@ -57,6 +57,7 @@
/************************* Function prototypes ********************************/
+
axis2_status_t AXIS2_CALL tcpmon_entry_free(
tcpmon_entry_t * entry,
const axutil_env_t * env);
@@ -94,20 +95,10 @@
const axutil_env_t * env);
axis2_char_t *get_current_stream_to_buffer(
- axutil_stream_t * stream,
const axutil_env_t * env,
+ axutil_stream_t * stream,
int *stream_size);
-axis2_char_t *read_current_stream(
- axutil_stream_t * stream,
- const axutil_env_t * env,
- int *stream_size,
- axis2_char_t ** header,
- axis2_char_t ** data);
-
-int write_to_file(
- char *filename,
- char *buffer);
int AXIS2_CALL tcpmon_entry_get_format_bit(
tcpmon_entry_t * entry,
@@ -507,15 +498,15 @@
return NULL;
}
- buffer = read_current_stream(client_stream, env, &buffer_size,
+ buffer = tcpmon_util_read_current_stream(env, client_stream, &buffer_size,
&headers, &content);
- headers =(char *) str_replace(headers,"localhost", target_host);
+ headers =(char *) tcpmon_util_str_replace(env, headers,"localhost", target_host);
test_bit = TCPMON_SESSION_GET_TEST_BIT(session, env);
if (test_bit)
{
- write_to_file("reqest", buffer);
+ tcpmon_util_write_to_file("reqest", buffer);
}
format_bit = TCPMON_SESSION_GET_FORMAT_BIT(session, env);
@@ -596,13 +587,13 @@
axutil_stream_write(host_stream, env, buffer, buffer_size);
AXIS2_FREE(env->allocator, buffer);
- buffer = read_current_stream(host_stream, env, &buffer_size,
+ buffer = tcpmon_util_read_current_stream(env, host_stream, &buffer_size,
&headers, &content);
test_bit = TCPMON_SESSION_GET_TEST_BIT(session, env);
if (test_bit)
{
- write_to_file("response", buffer);
+ tcpmon_util_write_to_file("response", buffer);
}
now = time(NULL);
@@ -662,249 +653,4 @@
return NULL;
}
-axis2_char_t *
-read_current_stream(
- axutil_stream_t * stream,
- const axutil_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;
- int mtom_optimized = 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;
- int is_get = 0;
- int zero_content_length = 0;
-
- buffer = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t));
- *data = NULL;
- *header = NULL;
- do
- {
- 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)
- {
- 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 (!mtom_optimized && strstr(current_line, "multipart/related"))
- mtom_optimized = 1;
- if (strstr(current_line, "Content-Length"))
- {
- length_char = strstr(current_line, ":");
- if (length_char)
- {
- length_char++;
- length = atoi(length_char);
- if (length == 0)
- {
- zero_content_length = 1;
- }
- }
- }
- if (strstr(current_line, "GET") || strstr(current_line, "HEAD")
- || strstr(current_line, "DELETE"))
- {
- is_get = 1;
- /** Captures GET style requests */
- }
- *(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';
- 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 (is_get && length == -1)
- {
- break;
- }
- }
- 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';
- 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);
-
- if (is_get)
- {
- read_size++;
- }
- else if (zero_content_length)
- {
- read_size += 3;
- }
-
- 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;
- if (body_ptr && *body_ptr)
- {
- if (mtom_optimized)
- {
- int count = read_size - (int)strlen(header_ptr) - 4;
- int copied = 0;
- int plen = 0;
- axis2_char_t *temp = NULL;
- temp = AXIS2_MALLOC(env->allocator,
- sizeof(axis2_char_t) * count + 1);
- while(count > copied)
- {
- plen = 0;
- plen = ((int)strlen(body_ptr) + 1);
- if (plen != 1)
- {
- sprintf(temp, "%s", body_ptr);
- }
- copied += plen;
- if (count > copied)
- {
- temp += plen;
- body_ptr += plen;
- }
- }
- copied -= plen;
- temp -= copied;
- temp[count] = '\0';
- *data = temp;
- }
- else
- {
- *data = (axis2_char_t *) axutil_strdup(env, body_ptr);
- }
- }
- body_ptr = NULL;
- }
- else
- {
- /** soap body part is unavailable */
- if (is_get)
- {
- *data = (axis2_char_t *) axutil_strdup(env, "\n");
- *(buffer + read_size - 1) = '\n';
- }
- else if (zero_content_length)
- {
- *data = (axis2_char_t *) axutil_strdup(env, "\n");
- *(buffer + read_size - 3) = '\n';
- *(buffer + read_size - 2) = '\r';
- *(buffer + read_size - 1) = '\n';
- }
- if (header_ptr)
- {
- AXIS2_FREE(env->allocator, header_ptr);
- }
- header_ptr = (axis2_char_t *) axutil_strdup(env, buffer);
- }
-
- *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, "ab");
- size = (int)fwrite(buffer, 1, strlen(buffer), fp);
- /* We are sure that the difference lies within the int range */
- 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?rev=731527&r1=731526&r2=731527&view=diff
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/src/session.c (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/src/session.c Mon Jan 5 03:10:32 2009
@@ -27,6 +27,7 @@
#include "tcpmon_session_local.h"
#include "tcpmon_entry_local.h"
+#include "tcpmon_util.h"
/**
* @brief
@@ -131,7 +132,7 @@
/** internal implementations */
-void *AXIS2_THREAD_FUNC server_funct(
+static void *AXIS2_THREAD_FUNC server_funct(
axutil_thread_t * thd,
void *data);
@@ -487,7 +488,7 @@
}
/** internal implementations */
-void *AXIS2_THREAD_FUNC
+static void *AXIS2_THREAD_FUNC
server_funct(
axutil_thread_t * thd,
void *data)
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=731527&r1=731526&r2=731527&view=diff
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/src/tcpmon.c (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/src/tcpmon.c Mon Jan 5 03:10:32 2009
@@ -345,11 +345,12 @@
fprintf(file, "---------------------\n");
convert = axutil_strdup(env, TCPMON_ENTRY_SENT_HEADERS(entry, env));
- convert = str_replace(convert, "; ", ";\n\t");
+ convert = tcpmon_util_str_replace(env, convert, "; ", ";\n\t");
fprintf(file, "%s\r\n\r\n", convert);
if (convert)
{
- free(convert);
+ AXIS2_FREE(env->allocator, convert);
+ convert = NULL;
}
if (strcmp(formated_buffer, "") != 0)
{
@@ -358,11 +359,12 @@
(int)strlen(formated_buffer) + 4)
{
convert = axutil_strdup(env, formated_buffer);
- convert = str_replace(convert, "><", ">\n<");
+ convert = tcpmon_util_str_replace(env, convert, "><", ">\n<");
fprintf(file, "%s", convert);
if (convert)
{
- free(convert);
+ AXIS2_FREE(env->allocator, convert);
+ convert = NULL;
}
}
else
@@ -457,11 +459,12 @@
fprintf(file, "---------------------\n");
convert = axutil_strdup(env, TCPMON_ENTRY_ARRIVED_HEADERS(entry, env));
- convert = str_replace(convert, "; ", ";\n\t");
+ convert = tcpmon_util_str_replace(env, convert, "; ", ";\n\t");
fprintf(file, "%s\r\n\r\n", convert);
if (convert)
{
- free(convert);
+ AXIS2_FREE(env->allocator, convert);
+ convert = NULL;
}
if (strcmp(formated_buffer, "") != 0)
{
@@ -470,11 +473,12 @@
(int)strlen(formated_buffer) + 4)
{
convert = axutil_strdup(env, formated_buffer);
- convert = str_replace(convert, "><", ">\n<");
+ convert = tcpmon_util_str_replace(env, convert, "><", ">\n<");
fprintf(file, "%s", convert);
if (convert)
{
- free(convert);
+ AXIS2_FREE(env->allocator, convert);
+ convert = NULL;
}
}
else
@@ -710,7 +714,7 @@
req_payload = tmp1 + 2;
tmp1 = axutil_strdup(env, request_buffer);
req_content_len -= (int)strlen(tmp1);
- tmp1 = str_replace(tmp1, ";\n\t", "; ");
+ tmp1 = tcpmon_util_str_replace(env, tmp1, ";\n\t", "; ");
req_header = tmp1;
tmp2 = strstr(req_header, AXIS2_HTTP_HEADER_USER_AGENT ":");
if (tmp2)
@@ -730,7 +734,7 @@
tmp2 = AXIS2_MALLOC(env->allocator,
sizeof(axis2_char_t) * (header_len + 1));
sprintf(tmp2, "%s\r\n", user_agent);
- req_header = str_replace(req_header, tmp1, tmp2);
+ req_header = tcpmon_util_str_replace(env, req_header, tmp1, tmp2);
AXIS2_FREE(env->allocator, tmp1);
AXIS2_FREE(env->allocator, tmp2);
tmp1 = NULL;
@@ -756,7 +760,7 @@
req_content_len = (int)strlen(req_payload);
sprintf(tmp2, "%s%d\r\n", AXIS2_HTTP_HEADER_CONTENT_LENGTH
": ", req_content_len);
- req_header = str_replace(req_header, tmp1, tmp2);
+ req_header = tcpmon_util_str_replace(env, req_header, tmp1, tmp2);
AXIS2_FREE(env->allocator, tmp1);
AXIS2_FREE(env->allocator, tmp2);
tmp1 = NULL;
@@ -781,7 +785,7 @@
sizeof(axis2_char_t) * (header_len + 1));
sprintf(tmp2, "%s%s:%d\r\n", AXIS2_HTTP_HEADER_HOST ": ", target_host,
TCPMON_SESSION_GET_LISTEN_PORT(session, env));
- req_header = str_replace(req_header, tmp1, tmp2);
+ req_header = tcpmon_util_str_replace(env, req_header, tmp1, tmp2);
AXIS2_FREE(env->allocator, tmp1);
AXIS2_FREE(env->allocator, tmp2);
tmp1 = NULL;
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?rev=731527&r1=731526&r2=731527&view=diff
==============================================================================
--- webservices/axis2/trunk/c/tools/tcpmon/src/util.c (original)
+++ webservices/axis2/trunk/c/tools/tcpmon/src/util.c Mon Jan 5 03:10:32 2009
@@ -16,10 +16,11 @@
* limitations under the License.
*/
-#include <tcpmon_util.h>
#include <axiom.h>
#include <stdlib.h>
+#include <tcpmon_util.h>
+
#define START_ELEMENT 1
#define CHAR_VALUE 2
#define END_ELEMENT 3
@@ -33,12 +34,6 @@
}
tcpmon_util_allocator_t;
-axis2_char_t *tcpmon_strcat(
- char *dest,
- char *source,
- int *cur_buf_s,
- const axutil_env_t * env);
-
/*static void add_string(const axutil_env_t* env,
tcpmon_util_allocator_t* allocator,
axis2_char_t* string);
@@ -95,7 +90,7 @@
{
int ix;
- tcpmon_strcat(out, "<?xml ", &buffer_size, env);
+ tcpmon_util_strcat(out, "<?xml ", &buffer_size, env);
ix = axiom_xml_reader_get_attribute_count(xml_reader, env);
for (; ix > 0; ix--)
@@ -110,8 +105,8 @@
(xml_reader, env, ix);
if (attr_prefix)
{
- tcpmon_strcat(out, attr_prefix, &buffer_size, env);
- tcpmon_strcat(out, ":", &buffer_size, env);
+ tcpmon_util_strcat(out, attr_prefix, &buffer_size, env);
+ tcpmon_util_strcat(out, ":", &buffer_size, env);
}
attr_name =
@@ -120,8 +115,8 @@
(xml_reader, env, ix);
if (attr_name)
{
- tcpmon_strcat(out, attr_name, &buffer_size, env);
- tcpmon_strcat(out, "=\"", &buffer_size, env);
+ tcpmon_util_strcat(out, attr_name, &buffer_size, env);
+ tcpmon_util_strcat(out, "=\"", &buffer_size, env);
}
attr_value =
@@ -130,8 +125,8 @@
(xml_reader, env, ix);
if (attr_value)
{
- tcpmon_strcat(out, attr_value, &buffer_size, env);
- tcpmon_strcat(out, "\"", &buffer_size, env);
+ tcpmon_util_strcat(out, attr_value, &buffer_size, env);
+ tcpmon_util_strcat(out, "\"", &buffer_size, env);
}
}
@@ -153,20 +148,20 @@
has_space = 0;
if (start_ele != 0)
- tcpmon_strcat(out, "\n", &buffer_size, env);
+ tcpmon_util_strcat(out, "\n", &buffer_size, env);
for (i = 0; i < tab_pos; i++)
- tcpmon_strcat(out, "\t", &buffer_size, env);
+ tcpmon_util_strcat(out, "\t", &buffer_size, env);
- tcpmon_strcat(out, "<", &buffer_size, env);
+ tcpmon_util_strcat(out, "<", &buffer_size, env);
ele_prefix =
(axis2_char_t *) axiom_xml_reader_get_prefix(xml_reader,
env);
if (ele_prefix)
{
- tcpmon_strcat(out, ele_prefix, &buffer_size, env);
- tcpmon_strcat(out, ":", &buffer_size, env);
+ tcpmon_util_strcat(out, ele_prefix, &buffer_size, env);
+ tcpmon_util_strcat(out, ":", &buffer_size, env);
}
ele_name =
@@ -174,7 +169,7 @@
env);
if (ele_name)
{
- tcpmon_strcat(out, ele_name, &buffer_size, env);
+ tcpmon_util_strcat(out, ele_name, &buffer_size, env);
}
ix = axiom_xml_reader_get_attribute_count(xml_reader, env);
@@ -191,9 +186,9 @@
if (attr_prefix)
{
has_prefix = 1;
- tcpmon_strcat(out, " ", &buffer_size, env);
- tcpmon_strcat(out, attr_prefix, &buffer_size, env);
- tcpmon_strcat(out, ":", &buffer_size, env);
+ tcpmon_util_strcat(out, " ", &buffer_size, env);
+ tcpmon_util_strcat(out, attr_prefix, &buffer_size, env);
+ tcpmon_util_strcat(out, ":", &buffer_size, env);
}
attr_name =
@@ -204,16 +199,16 @@
{
if (has_prefix)
{
- tcpmon_strcat(out, attr_name, &buffer_size,
+ tcpmon_util_strcat(out, attr_name, &buffer_size,
env);
- tcpmon_strcat(out, "=\"", &buffer_size, env);
+ tcpmon_util_strcat(out, "=\"", &buffer_size, env);
}
else
{
- tcpmon_strcat(out, " ", &buffer_size, env);
- tcpmon_strcat(out, attr_name, &buffer_size,
+ tcpmon_util_strcat(out, " ", &buffer_size, env);
+ tcpmon_util_strcat(out, attr_name, &buffer_size,
env);
- tcpmon_strcat(out, "=\"", &buffer_size, env);
+ tcpmon_util_strcat(out, "=\"", &buffer_size, env);
}
has_prefix = 0;
@@ -225,12 +220,12 @@
(xml_reader, env, ix);
if (attr_value)
{
- tcpmon_strcat(out, attr_value, &buffer_size, env);
- tcpmon_strcat(out, "\"", &buffer_size, env);
+ tcpmon_util_strcat(out, attr_value, &buffer_size, env);
+ tcpmon_util_strcat(out, "\"", &buffer_size, env);
}
}
- tcpmon_strcat(out, ">", &buffer_size, env);
+ tcpmon_util_strcat(out, ">", &buffer_size, env);
tab_pos++;
start_ele = 1;
@@ -244,7 +239,7 @@
ele_value = axiom_xml_reader_get_value(xml_reader, env);
if (ele_value)
- tcpmon_strcat(out, ele_value, &buffer_size, env);
+ tcpmon_util_strcat(out, ele_value, &buffer_size, env);
has_value = 1;
@@ -265,27 +260,27 @@
has_space = 0;
if (start_ele != 0)
- tcpmon_strcat(out, "\n", &buffer_size, env);
+ tcpmon_util_strcat(out, "\n", &buffer_size, env);
for (i = 0; i < tab_pos; i++)
- tcpmon_strcat(out, "\t", &buffer_size, env);
+ tcpmon_util_strcat(out, "\t", &buffer_size, env);
- tcpmon_strcat(out, "<", &buffer_size, env);
+ tcpmon_util_strcat(out, "<", &buffer_size, env);
ele_prefix =
(axis2_char_t *) axiom_xml_reader_get_prefix(xml_reader,
env);
if (ele_prefix)
{
- tcpmon_strcat(out, ele_prefix, &buffer_size, env);
- tcpmon_strcat(out, ":", &buffer_size, env);
+ tcpmon_util_strcat(out, ele_prefix, &buffer_size, env);
+ tcpmon_util_strcat(out, ":", &buffer_size, env);
}
ele_name =
(axis2_char_t *) axiom_xml_reader_get_name(xml_reader,
env);
if (ele_name)
- tcpmon_strcat(out, ele_name, &buffer_size, env);
+ tcpmon_util_strcat(out, ele_name, &buffer_size, env);
ix = axiom_xml_reader_get_attribute_count(xml_reader, env);
for (; ix > 0; ix--)
@@ -301,9 +296,9 @@
if (attr_prefix)
{
has_prefix = 1;
- tcpmon_strcat(out, " ", &buffer_size, env);
- tcpmon_strcat(out, attr_prefix, &buffer_size, env);
- tcpmon_strcat(out, ":", &buffer_size, env);
+ tcpmon_util_strcat(out, " ", &buffer_size, env);
+ tcpmon_util_strcat(out, attr_prefix, &buffer_size, env);
+ tcpmon_util_strcat(out, ":", &buffer_size, env);
}
attr_name =
@@ -314,16 +309,16 @@
{
if (has_prefix)
{
- tcpmon_strcat(out, attr_name, &buffer_size,
+ tcpmon_util_strcat(out, attr_name, &buffer_size,
env);
- tcpmon_strcat(out, "=\"", &buffer_size, env);
+ tcpmon_util_strcat(out, "=\"", &buffer_size, env);
}
else
{
- tcpmon_strcat(out, " ", &buffer_size, env);
- tcpmon_strcat(out, attr_name, &buffer_size,
+ tcpmon_util_strcat(out, " ", &buffer_size, env);
+ tcpmon_util_strcat(out, attr_name, &buffer_size,
env);
- tcpmon_strcat(out, "=\"", &buffer_size, env);
+ tcpmon_util_strcat(out, "=\"", &buffer_size, env);
}
has_prefix = 0;
}
@@ -334,12 +329,12 @@
(xml_reader, env, ix);
if (attr_value)
{
- tcpmon_strcat(out, attr_value, &buffer_size, env);
- tcpmon_strcat(out, "\"", &buffer_size, env);
+ tcpmon_util_strcat(out, attr_value, &buffer_size, env);
+ tcpmon_util_strcat(out, "\"", &buffer_size, env);
}
}
- tcpmon_strcat(out, "/>", &buffer_size, env);
+ tcpmon_util_strcat(out, "/>", &buffer_size, env);
start_ele = 1;
}
break;
@@ -354,22 +349,22 @@
if (has_value == 0 && prev_case != START_ELEMENT)
{
- tcpmon_strcat(out, "\n", &buffer_size, env);
+ tcpmon_util_strcat(out, "\n", &buffer_size, env);
for (i = 0; i < tab_pos; i++)
- tcpmon_strcat(out, "\t", &buffer_size, env);
+ tcpmon_util_strcat(out, "\t", &buffer_size, env);
}
has_value = 0;
- tcpmon_strcat(out, "</", &buffer_size, env);
+ tcpmon_util_strcat(out, "</", &buffer_size, env);
ele_prefix =
(axis2_char_t *) axiom_xml_reader_get_prefix(xml_reader,
env);
if (ele_prefix)
{
- tcpmon_strcat(out, ele_prefix, &buffer_size, env);
- tcpmon_strcat(out, ":", &buffer_size, env);
+ tcpmon_util_strcat(out, ele_prefix, &buffer_size, env);
+ tcpmon_util_strcat(out, ":", &buffer_size, env);
}
ele_name =
@@ -377,8 +372,8 @@
env);
if (ele_name)
{
- tcpmon_strcat(out, ele_name, &buffer_size, env);
- tcpmon_strcat(out, ">", &buffer_size, env);
+ tcpmon_util_strcat(out, ele_name, &buffer_size, env);
+ tcpmon_util_strcat(out, ">", &buffer_size, env);
}
prev_case = END_ELEMENT;
@@ -457,7 +452,7 @@
} */
axis2_char_t *
-tcpmon_strcat(
+tcpmon_util_strcat(
axis2_char_t * dest,
axis2_char_t * source,
int *buff_size,
@@ -490,31 +485,39 @@
}
char *
-str_replace(
+tcpmon_util_str_replace(
+ const axutil_env_t *env,
char *str,
const char *search,
const char *replace)
{
+ char *str_return = NULL;
+ char *str_tmp = NULL;
+ char *str_relic = NULL;
int size = ((int)strlen(str)) * 2;
/* We are sure that the difference lies within the int range */
int addmem = size;
int diff = (int)(strlen(replace) - strlen(search));
/* We are sure that the difference lies within the int range */
- char *str_return = (char *) malloc((size + 1) * sizeof(char));
- char *str_tmp = (char *) malloc(size * sizeof(char));
- char *str_relic;
+ str_return = (char *) AXIS2_MALLOC(env->allocator, ((size + 1) * sizeof(char)));
+ str_tmp = (char *) AXIS2_MALLOC(env->allocator, (size * sizeof(char)));
+
if (str_return == NULL || str_tmp == NULL)
{
- free(str_return);
- free(str_tmp);
- return "function str_replace : give me more memory";
+ AXIS2_FREE(env->allocator, str_return);
+ str_return = NULL;
+ AXIS2_FREE(env->allocator, str_tmp);
+ str_tmp = NULL;
+ return "function tcpmon_util_str_replace : give me more memory";
}
if (!strcmp(search, replace))
{
- free(str_return);
- free(str_tmp);
+ AXIS2_FREE(env->allocator, str_return);
+ str_return = NULL;
+ AXIS2_FREE(env->allocator, str_tmp);
+ str_tmp = NULL;
return str;
}
@@ -530,9 +533,11 @@
if (str_return == NULL || str_tmp == NULL)
{
- free(str_return);
- free(str_tmp);
- return "function str_replace : gimme more memory";
+ AXIS2_FREE(env->allocator, str_return);
+ str_return = NULL;
+ AXIS2_FREE(env->allocator, str_tmp);
+ str_tmp = NULL;
+ return "function tcpmon_str_replace : gimme more memory";
}
}
@@ -543,9 +548,259 @@
strcat(str_return, str_tmp);
}
- free(str_tmp);
+ AXIS2_FREE(env->allocator, str_tmp);
+ str_tmp = NULL;
/* free(str); */ /* we are not allocating memory using str */
str_return[addmem] = '\0';
return (str_return);
}
+
+axis2_char_t *
+tcpmon_util_read_current_stream(
+ const axutil_env_t * env,
+ axutil_stream_t * stream,
+ 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;
+ int mtom_optimized = 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;
+ int is_get = 0;
+ int zero_content_length = 0;
+
+ buffer = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t));
+ *data = NULL;
+ *header = NULL;
+ do
+ {
+ 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)
+ {
+ 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 (!mtom_optimized && strstr(current_line, "multipart/related"))
+ mtom_optimized = 1;
+ if (strstr(current_line, "Content-Length"))
+ {
+ length_char = strstr(current_line, ":");
+ if (length_char)
+ {
+ length_char++;
+ length = atoi(length_char);
+ if (length == 0)
+ {
+ zero_content_length = 1;
+ }
+ }
+ }
+ if (strstr(current_line, "GET") || strstr(current_line, "HEAD")
+ || strstr(current_line, "DELETE"))
+ {
+ is_get = 1;
+ /** Captures GET style requests */
+ }
+ *(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';
+ 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 (is_get && length == -1)
+ {
+ break;
+ }
+ }
+ 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';
+ 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);
+
+ if (is_get)
+ {
+ read_size++;
+ }
+ else if (zero_content_length)
+ {
+ read_size += 3;
+ }
+
+ 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;
+ if (body_ptr && *body_ptr)
+ {
+ if (mtom_optimized)
+ {
+ int count = read_size - (int)strlen(header_ptr) - 4;
+ int copied = 0;
+ int plen = 0;
+ axis2_char_t *temp = NULL;
+ temp = AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_char_t) * count + 1);
+ while(count > copied)
+ {
+ plen = 0;
+ plen = ((int)strlen(body_ptr) + 1);
+ if (plen != 1)
+ {
+ sprintf(temp, "%s", body_ptr);
+ }
+ copied += plen;
+ if (count > copied)
+ {
+ temp += plen;
+ body_ptr += plen;
+ }
+ }
+ copied -= plen;
+ temp -= copied;
+ temp[count] = '\0';
+ *data = temp;
+ }
+ else
+ {
+ *data = (axis2_char_t *) axutil_strdup(env, body_ptr);
+ }
+ }
+ body_ptr = NULL;
+ }
+ else
+ {
+ /** soap body part is unavailable */
+ if (is_get)
+ {
+ *data = (axis2_char_t *) axutil_strdup(env, "\n");
+ *(buffer + read_size - 1) = '\n';
+ }
+ else if (zero_content_length)
+ {
+ *data = (axis2_char_t *) axutil_strdup(env, "\n");
+ *(buffer + read_size - 3) = '\n';
+ *(buffer + read_size - 2) = '\r';
+ *(buffer + read_size - 1) = '\n';
+ }
+ if (header_ptr)
+ {
+ AXIS2_FREE(env->allocator, header_ptr);
+ }
+ header_ptr = (axis2_char_t *) axutil_strdup(env, buffer);
+ }
+
+ *header = header_ptr;
+ *stream_size = read_size;
+ return buffer;
+}
+
+
+int
+tcpmon_util_write_to_file(
+ char *filename,
+ char *buffer)
+{
+ int size = 0;
+ if (filename)
+ {
+ FILE *fp = fopen(filename, "ab");
+ size = (int)fwrite(buffer, 1, strlen(buffer), fp);
+ /* We are sure that the difference lies within the int range */
+ fclose(fp);
+ }
+ return size;
+}
+