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 se...@apache.org on 2008/03/19 18:11:41 UTC
svn commit: r638938 - in /webservices/axis2/trunk/c/axiom:
include/axiom_mime_parser.h src/attachments/mime_parser.c
Author: senaka
Date: Wed Mar 19 10:11:26 2008
New Revision: 638938
URL: http://svn.apache.org/viewvc?rev=638938&view=rev
Log:
Axis2/C Hackathon: Improving AXIOM
Modified:
webservices/axis2/trunk/c/axiom/include/axiom_mime_parser.h
webservices/axis2/trunk/c/axiom/src/attachments/mime_parser.c
Modified: webservices/axis2/trunk/c/axiom/include/axiom_mime_parser.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/include/axiom_mime_parser.h?rev=638938&r1=638937&r2=638938&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/include/axiom_mime_parser.h (original)
+++ webservices/axis2/trunk/c/axiom/include/axiom_mime_parser.h Wed Mar 19 10:11:26 2008
@@ -38,6 +38,12 @@
{
#endif
+#define AXIOM_MIME_PARSER_BUFFER_SIZE (1024 * 1024)
+#define AXIOM_MIME_PARSER_MAX_CHUNK_BUFFERS 1000
+
+#define AXIOM_MIME_PARSER_END_OF_MIME_MAX_COUNT 100
+
+
typedef struct axiom_mime_parser axiom_mime_parser_t;
/** @defgroup axiom_mime_parser Flow
Modified: webservices/axis2/trunk/c/axiom/src/attachments/mime_parser.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/attachments/mime_parser.c?rev=638938&r1=638937&r2=638938&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/attachments/mime_parser.c (original)
+++ webservices/axis2/trunk/c/axiom/src/attachments/mime_parser.c Wed Mar 19 10:11:26 2008
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -32,34 +31,27 @@
int max_chunk_buffers;
};
-#define AXIOM_MIME_PARSER_BUFFER_SIZE (1024 * 1024)
-#define AXIOM_MIME_PARSER_MAX_CHUNK_BUFFERS 1000
-
-#define AXIOM_MIME_PARSER_CONTENT_ID "content-id"
-#define AXIOM_MIME_PARSER_CONTENT_TYPE "content-type"
-
-#define AXIOM_MIME_PARSER_END_OF_MIME_MAX_COUNT 100
-
AXIS2_EXTERN axiom_mime_parser_t *AXIS2_CALL
axiom_mime_parser_create(
- const axutil_env_t * env)
+ const axutil_env_t *env)
{
axiom_mime_parser_t *mime_parser = NULL;
AXIS2_ENV_CHECK(env, NULL);
- mime_parser = (axiom_mime_parser_t *) AXIS2_MALLOC(env->allocator,
- sizeof
- (axiom_mime_parser_t));
+ mime_parser = (axiom_mime_parser_t *)
+ AXIS2_MALLOC(env->allocator, sizeof(axiom_mime_parser_t));
if (!mime_parser)
{
AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Cannot create MIME parser");
return NULL;
}
mime_parser->mime_parts_map = NULL;
mime_parser->soap_body_len = 0;
- mime_parser->soap_body_str = NULL; /* shallow copy */
+ mime_parser->soap_body_str = NULL;
mime_parser->chunk_buffer_size = 1;
mime_parser->max_chunk_buffers = AXIOM_MIME_PARSER_MAX_CHUNK_BUFFERS;
@@ -67,6 +59,8 @@
if (!(mime_parser->mime_parts_map))
{
axiom_mime_parser_free(mime_parser, env);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "Failed in creating MIME parts map. Cannot create MIME parser");
return NULL;
}
@@ -75,13 +69,16 @@
AXIS2_EXTERN void AXIS2_CALL
axiom_mime_parser_free(
- axiom_mime_parser_t * mime_parser,
- const axutil_env_t * env)
+ axiom_mime_parser_t *mime_parser,
+ const axutil_env_t *env)
{
- AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
-
/* This map is passed on to SOAP builder, and SOAP builder take over the
- ownership of the map */
+ * ownership of the map
+ */
+ mime_parser->mime_parts_map = NULL;
+
+ /* The MIME parser doesn't own the SOAP Body string */
+ mime_parser->soap_body_str = NULL;
if (mime_parser)
{
@@ -93,11 +90,11 @@
AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
axiom_mime_parser_parse(
- axiom_mime_parser_t * mime_parser,
- const axutil_env_t * env,
+ axiom_mime_parser_t *mime_parser,
+ const axutil_env_t *env,
AXIS2_READ_INPUT_CALLBACK callback,
void *callback_ctx,
- axis2_char_t * mime_boundary)
+ axis2_char_t *mime_boundary)
{
axis2_char_t *buffer = NULL;
int size = AXIOM_MIME_PARSER_BUFFER_SIZE;
@@ -118,55 +115,67 @@
axis2_char_t **buf_array = NULL;
int *len_array = NULL;
-
cb_ctx = (axis2_callback_info_t *) callback_ctx;
- AXIS2_ENV_CHECK(env, NULL);
-
- if(cb_ctx->chunked_stream)
+ if (cb_ctx->chunked_stream)
{
- buf_array = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t *) * (
- mime_parser->max_chunk_buffers));
+ buf_array = AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_char_t *) * (mime_parser->max_chunk_buffers));
- len_array = AXIS2_MALLOC(env->allocator, sizeof(int) * (
- mime_parser->max_chunk_buffers));
+ if (!buf_array)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Failed in creating buffer array");
+ return NULL;
+ }
- size = (mime_parser->chunk_buffer_size) * AXIOM_MIME_PARSER_BUFFER_SIZE;
+ len_array = AXIS2_MALLOC(env->allocator,
+ sizeof(int) * (mime_parser->max_chunk_buffers));
+
+ if (!len_array)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Failed in creating length array");
+ return NULL;
+ }
+ size = (mime_parser->chunk_buffer_size) * AXIOM_MIME_PARSER_BUFFER_SIZE;
- while(!axutil_http_chunked_stream_get_end_of_chunks(
- cb_ctx->chunked_stream, env))
+ while (!axutil_http_chunked_stream_get_end_of_chunks(
+ cb_ctx->chunked_stream, env))
{
read = 0;
- if(buf_num > (mime_parser->max_chunk_buffers - 1))
+ if (buf_num > (mime_parser->max_chunk_buffers - 1))
{
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "Attachment size exceeds the system MTOM configuration parameters");
+ "Attachment size exceeds "
+ "the system MTOM configuration parameters");
return NULL;
}
- buf_array[buf_num] = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (size + 1));
+ buf_array[buf_num] = AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_char_t) * (size + 1));
+ if (!buf_array[buf_num])
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Failed in creating buffer");
+ return NULL;
+ }
do
{
- len = callback(buf_array[buf_num] + read, size - read, (void *) callback_ctx);
- if (len > 0)
- {
- read += len;
- }
- else
- {
- break;
- }
+ read += len;
+ len = callback(buf_array[buf_num] + read, size - read,
+ (void *) callback_ctx);
}
- while(read < (size-1));
+ while ((read < (size-1)) && (len > 0));
*(buf_array[buf_num] + read) = '\0';
len_array[buf_num] = read;
buf_num++;
}
-
- if(buf_num == 1)
+ /* If we have only one buffer */
+ if (buf_num == 1)
{
buffer = buf_array[buf_num - 1];
}
@@ -175,21 +184,26 @@
int i = 0;
int temp = 0;
buf_len = 0;
- buffer = NULL;
- for(i=0; i < buf_num; i++)
+ for (i = 0; i < buf_num; i++)
{
- if(buf_array[i])
+ if (buf_array[i])
{
buf_len += len_array[i];
}
}
- buffer = AXIS2_MALLOC(env->allocator,
- sizeof(char) * (buf_len+1));
+ buffer = AXIS2_MALLOC(env->allocator, sizeof(char) * (buf_len + 1));
+
+ if (!buffer)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Failed in creating buffer");
+ return NULL;
+ }
- for(i=0; i < buf_num; i++)
+ for (i = 0; i < buf_num; i++)
{
- if(buf_array[i])
+ if (buf_array[i])
{
memcpy(buffer + temp, buf_array[i], len_array[i]);
temp += len_array[i];
@@ -200,48 +214,45 @@
*(buffer + temp) = '\0';
}
}
-
else
{
size = cb_ctx->content_length + 100;
- buffer = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (size + 1));
+ buffer = AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_char_t) * (size + 1));
+ if (!buffer)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Failed in creating buffer");
+ return NULL;
+ }
do
{
+ read += len;
len = callback(buffer + read, size - read, (void *) callback_ctx);
- if (len > 0)
- {
- read += len;
- }
- else
- {
- break;
- }
}
- while(read < size);
+ while ((read < size) && (len > 0));
buffer[read+1] = '\0';
buf_len = read;
- if(buf_len < cb_ctx->content_length)
+ if (buf_len < cb_ctx->content_length)
{
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "All the data in the message does not recieved");
+ "Some data in the message was not recieved");
return NULL;
}
}
if (buffer)
{
- pos = axutil_strstr(buffer, "\r\n\r\n");
+ pos = axutil_strstr(buffer, AXIS2_CRLF AXIS2_CRLF);
if (pos)
{
- pos = pos + 4;
- root_mime = pos;
+ root_mime = pos + 4;
+ pos = NULL;
}
}
- pos = NULL;
-
if (root_mime)
{
pos = axutil_strstr(root_mime, mime_boundary);
@@ -252,71 +263,67 @@
pos -= 2;
soap_body_len = pos - root_mime;
soap_body_str = AXIS2_MALLOC(env->allocator,
- sizeof(char) * (soap_body_len + 1));
+ sizeof(char) * (soap_body_len + 1));
+ if (!soap_body_str)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Failed in SOAP body string");
+ return NULL;
+ }
memcpy(soap_body_str, root_mime, soap_body_len);
- soap_body_str[soap_body_len] = '\0';
- body_mime = pos;
- }
-
- if (soap_body_str)
- {
+ soap_body_str[soap_body_len] = '\0';
+ body_mime = pos;
mime_parser->soap_body_len = soap_body_len;
mime_parser->soap_body_str = soap_body_str;
}
-
+
while (!end_of_mime && count < AXIOM_MIME_PARSER_END_OF_MIME_MAX_COUNT)
{
axis2_char_t *temp_body_mime = NULL;
- axis2_char_t *old_pos = NULL;
axis2_char_t *temp_mime_binary = NULL;
axis2_char_t *temp_pos = NULL;
pos = NULL;
- /* keep trac of counter to ensure that we do not go in an infinite loop
- It is possible that we could fall into an infinite loop if there
- are problems in sender's message format
+ /* Keep track of the count to ensure that we do not go in an infinite
+ * loop. It is possible that we could fall into an infinite loop if
+ * there are problems in sender's message format
*/
count++;
if (body_mime)
{
- pos = axutil_strstr(body_mime, "\r\n\r\n");
+ pos = axutil_strstr(body_mime, AXIS2_CRLF AXIS2_CRLF);
}
if (pos)
{
- pos = pos + 4;
- temp_mime_binary = pos;
+ axis2_char_t *old_pos = NULL;
+
+ temp_mime_binary = pos + 4;
old_pos = temp_mime_binary;
- }
-
- do
- {
- pos = NULL;
-
- if (old_pos)
+ do
{
- pos = memchr(old_pos, AXIOM_MIME_BOUNDARY_BYTE,
- buffer + buf_len - old_pos);
- }
+ pos = NULL;
+
+ if (old_pos)
+ {
+ pos = memchr(old_pos, AXIOM_MIME_BOUNDARY_BYTE,
+ buffer + buf_len - old_pos);
+ }
- if (!pos)
- {
- break;
- }
- else
- {
- old_pos = pos + 1;
- temp_pos = axutil_strstr(pos + 1, mime_boundary);
+ if (pos)
+ {
+ old_pos = pos + 1;
+ temp_pos = axutil_strstr(pos + 1, mime_boundary);
+ }
}
-
+ while (pos && (*(pos + 1) != AXIOM_MIME_BOUNDARY_BYTE ||
+ temp_pos != pos + 2));
}
- while (*(pos + 1) != AXIOM_MIME_BOUNDARY_BYTE ||
- temp_pos != pos + 2);
- if (pos && *(pos + 1) == AXIOM_MIME_BOUNDARY_BYTE &&
- temp_pos == pos + 2)
+ if (pos && (*(pos + 1) == AXIOM_MIME_BOUNDARY_BYTE) &&
+ (temp_pos == pos + 2))
{
mime_binary_len = (int)(pos - temp_mime_binary);
temp_pos = pos + 2 + axutil_strlen(mime_boundary);
@@ -326,27 +333,33 @@
temp_body_mime = pos;
mime_binary = AXIS2_MALLOC(env->allocator,
- sizeof(char) * (mime_binary_len + 1));
+ sizeof(char) * (mime_binary_len + 1));
+ if (!mime_binary)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Failed in creating binary stream");
+ return NULL;
+ }
memcpy(mime_binary, temp_mime_binary, mime_binary_len);
mime_binary[mime_binary_len] = '\0';
}
if (mime_parser->mime_parts_map)
{
- /* get MIME ID */
axis2_char_t *id = NULL;
axis2_char_t *type = NULL;
+
+ /* Get the MIME ID */
if (body_mime)
{
- id = axutil_strcasestr(body_mime, AXIOM_MIME_PARSER_CONTENT_ID);
- type =
- axutil_strcasestr(body_mime,
- AXIOM_MIME_PARSER_CONTENT_TYPE);
+ id = axutil_strcasestr(body_mime, AXIOM_MIME_HEADER_CONTENT_ID);
+ type = axutil_strcasestr(body_mime,
+ AXIOM_MIME_HEADER_CONTENT_TYPE);
if (type)
{
axis2_char_t *end = NULL;
axis2_char_t *temp_type = NULL;
- type += axutil_strlen(AXIOM_MIME_PARSER_CONTENT_TYPE);
+ type += axutil_strlen(AXIOM_MIME_HEADER_CONTENT_TYPE);
while (type && *type && *type != ':')
{
type++;
@@ -364,8 +377,13 @@
if ((end - type) > 0)
{
temp_type = AXIS2_MALLOC(env->allocator,
- sizeof(axis2_char_t) *
- ((end - type) + 1));
+ sizeof(axis2_char_t) * ((end - type) + 1));
+ if (!temp_type)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Failed in creating Content-Type");
+ return NULL;
+ }
memcpy(temp_type, type, (end - type));
temp_type[end - type] = '\0';
type = temp_type;
@@ -374,44 +392,47 @@
}
if (id)
{
- id += axutil_strlen(AXIOM_MIME_PARSER_CONTENT_ID);
+ id += axutil_strlen(AXIOM_MIME_HEADER_CONTENT_ID);
while (id && *id && *id != ':')
+ {
id++;
+ }
if (id)
{
while (id && *id && *id != '<')
+ {
id++;
+ }
id++;
- if (id)
+ pos = axutil_strstr(id, ">");
+ if (pos)
{
- axis2_char_t *pos = NULL;
- pos = axutil_strstr(id, ">");
- if (pos)
+ axis2_char_t *mime_id = NULL;
+ int mime_id_len = 0;
+ mime_id_len = (int)(pos - id);
+ mime_id = AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_char_t) * mime_id_len + 1);
+ /* The MIME ID will be freed by the SOAP builder */
+ if (mime_id)
+ {
+ axiom_data_handler_t *data_handler = NULL;
+ memcpy(mime_id, id, mime_id_len);
+ mime_id[mime_id_len] = '\0';
+ data_handler =
+ axiom_data_handler_create(env, NULL, type);
+
+ AXIS2_FREE(env->allocator, type);
+
+ axiom_data_handler_set_binary_data(data_handler,
+ env, mime_binary, mime_binary_len - 2);
+ axutil_hash_set(mime_parser->mime_parts_map,
+ mime_id, AXIS2_HASH_KEY_STRING, data_handler);
+ }
+ else
{
- axis2_char_t *mime_id = NULL;
- int mime_id_len = 0;
- mime_id_len = (int)(pos - id);
- mime_id = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * mime_id_len + 1); /* this would be freed by SOAP builder */
- if (mime_id)
- {
-
- axiom_data_handler_t *data_handler = NULL;
- memcpy(mime_id, id, mime_id_len);
- mime_id[mime_id_len] = '\0';
- data_handler =
- axiom_data_handler_create(env, NULL, type);
-
- AXIS2_FREE(env->allocator, type);
-
- axiom_data_handler_set_binary_data(data_handler,
- env,
- mime_binary,
- mime_binary_len
- - 2);
- axutil_hash_set(mime_parser->mime_parts_map,
- mime_id, AXIS2_HASH_KEY_STRING,
- data_handler);
- }
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Failed in creating MIME ID");
+ return NULL;
}
}
}
@@ -419,9 +440,7 @@
else
{
axis2_char_t temp_boundry[1024];
- sprintf(temp_boundry, "%s", "--");
- sprintf(temp_boundry, "%s", mime_boundary);
- sprintf(temp_boundry, "%s", "--");
+ sprintf(temp_boundry, "--%s--", mime_boundary);
if (body_mime && axutil_strstr(body_mime, temp_boundry))
{
break;
@@ -431,13 +450,13 @@
}
} /* end while (!end_of_mime) */
- if(buf_array)
+ if (buf_array)
{
AXIS2_FREE(env->allocator, buf_array);
buf_array = NULL;
}
- if(len_array)
+ if (len_array)
{
AXIS2_FREE(env->allocator, len_array);
len_array = NULL;
@@ -450,41 +469,41 @@
AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
axiom_mime_parser_get_mime_parts_map(
- axiom_mime_parser_t * mime_parser,
- const axutil_env_t * env)
+ axiom_mime_parser_t *mime_parser,
+ const axutil_env_t *env)
{
return mime_parser->mime_parts_map;
}
AXIS2_EXTERN int AXIS2_CALL
axiom_mime_parser_get_soap_body_len(
- axiom_mime_parser_t * mime_parser,
- const axutil_env_t * env)
+ axiom_mime_parser_t *mime_parser,
+ const axutil_env_t *env)
{
return mime_parser->soap_body_len;
}
AXIS2_EXTERN axis2_char_t *AXIS2_CALL
axiom_mime_parser_get_soap_body_str(
- axiom_mime_parser_t * mime_parser,
- const axutil_env_t * env)
+ axiom_mime_parser_t *mime_parser,
+ const axutil_env_t *env)
{
return mime_parser->soap_body_str;
}
AXIS2_EXTERN void AXIS2_CALL
axiom_mime_parser_set_chunk_buffer_size(
- axiom_mime_parser_t * mime_parser,
- const axutil_env_t * env,
+ axiom_mime_parser_t *mime_parser,
+ const axutil_env_t *env,
int size)
{
- mime_parser->chunk_buffer_size = size ;
+ mime_parser->chunk_buffer_size = size;
}
AXIS2_EXTERN void AXIS2_CALL
axiom_mime_parser_set_max_chunk_buffers(
- axiom_mime_parser_t * mime_parser,
- const axutil_env_t * env,
+ axiom_mime_parser_t *mime_parser,
+ const axutil_env_t *env,
int num)
{
mime_parser->max_chunk_buffers = num;
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org