axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shan...@apache.org
Subject svn commit: r810531 [1/3] - in /webservices/axis2/trunk/c/src/core/transport/http: common/ receiver/ server/apache2/ util/
Date Wed, 02 Sep 2009 14:45:11 GMT
Author: shankar
Date: Wed Sep  2 14:45:10 2009
New Revision: 810531

URL: http://svn.apache.org/viewvc?rev=810531&view=rev
Log:
code formatting + refactor + improving performance

Modified:
    webservices/axis2/trunk/c/src/core/transport/http/common/http_header.c
    webservices/axis2/trunk/c/src/core/transport/http/common/http_request_line.c
    webservices/axis2/trunk/c/src/core/transport/http/common/http_response_writer.c
    webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_request.c
    webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_response.c
    webservices/axis2/trunk/c/src/core/transport/http/common/http_status_line.c
    webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c
    webservices/axis2/trunk/c/src/core/transport/http/common/simple_http_svr_conn.c
    webservices/axis2/trunk/c/src/core/transport/http/receiver/http_svr_thread.c
    webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_worker.c
    webservices/axis2/trunk/c/src/core/transport/http/util/http_transport_utils.c

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/http_header.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/http_header.c?rev=810531&r1=810530&r2=810531&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/http_header.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/http_header.c Wed Sep  2 14:45:10
2009
@@ -34,9 +34,7 @@
     const axis2_char_t * value)
 {
     axis2_http_header_t *http_header = NULL;
-
     http_header = (axis2_http_header_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_http_header_t));
-
     if(!http_header)
     {
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
@@ -49,6 +47,12 @@
     return http_header;
 }
 
+/**
+ * Creates http header object from a string having format "header_name:     header_value"
+ * (e.g. "SOAPAction: urn:hello")
+ * @param env pointer to environment struct
+ * @param str pointer to str
+ */
 AXIS2_EXTERN axis2_http_header_t *AXIS2_CALL
 axis2_http_header_create_by_str(
     const axutil_env_t * env,
@@ -58,37 +62,52 @@
     axis2_char_t *ch = NULL;
     axis2_char_t *ch2 = NULL;
     axis2_http_header_t *ret = NULL;
-
+    int tmp_str_len = 0;
     AXIS2_PARAM_CHECK(env->error, str, NULL);
 
+    /*
     tmp_str = axutil_strdup(env, str);
     if(!tmp_str)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "unable to strdup string, %s", str);
         return NULL;
     }
+    */
+    /*
+     * strdup is removed to increase the performance. This method is called from
+     * axis2_simple_http_svr_conn_read_request and axis2_http_client_recieve_header and both
of them
+     * passes a temporary string. hence we can modify the contents without doing a strdup.
+     * Above code is commented after 1.6.0 . If no issue is found until 1.8.0, above can
be removed
+     */
+    tmp_str = (axis2_char_t *)str;
+
     /* remove trailing \r\n */
-    if((axutil_strlen(tmp_str) >= 2) && (AXIS2_RETURN == tmp_str[axutil_strlen(tmp_str)
- 2]))
+    tmp_str_len = axutil_strlen(tmp_str);
+    if((tmp_str_len >= 2) && (AXIS2_RETURN == tmp_str[tmp_str_len - 2]))
     {
-        tmp_str[axutil_strlen(tmp_str) - 2] = AXIS2_ESC_NULL;
+        tmp_str[tmp_str_len - 2] = AXIS2_ESC_NULL;
     }
 
+    /* get http header */
     ch = strchr((const char *)tmp_str, AXIS2_COLON);
     if(!ch)
     {
-        AXIS2_FREE(env->allocator, tmp_str);
+        /*AXIS2_FREE(env->allocator, tmp_str);*/
         return NULL;
     }
+    *ch = AXIS2_ESC_NULL;
+
+    /* get http header value */
+    ch2 = ++ch;
 
-    ch2 = ch + sizeof(axis2_char_t);
     /* skip spaces */
     while(AXIS2_SPACE == *ch2)
     {
-        ch2 += sizeof(axis2_char_t);
+        ++ch2;
     }
-    *ch = AXIS2_ESC_NULL;
+
     ret = axis2_http_header_create(env, tmp_str, ch2);
-    AXIS2_FREE(env->allocator, tmp_str);
+    /*AXIS2_FREE(env->allocator, tmp_str);*/
     return ret;
 }
 

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/http_request_line.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/http_request_line.c?rev=810531&r1=810530&r2=810531&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/http_request_line.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/http_request_line.c Wed Sep 
2 14:45:10 2009
@@ -85,12 +85,19 @@
     return;
 }
 
+/**
+ * Parses a line "<http method> <uri location> <http version>CRLF" and
creates http_request_line
+ * object. E.g "POST /axis2/services/echo HTTP/1.1\r\n"
+ * @param env pointer to environment struct
+ * @param str pointer to the line to be parsed
+ * @return created object if success. NULL otherwise
+ */
 AXIS2_EXTERN axis2_http_request_line_t *AXIS2_CALL
 axis2_http_request_line_parse_line(
     const axutil_env_t * env,
     const axis2_char_t * str)
 {
-    axis2_char_t *req_line = NULL;
+    /*axis2_char_t *req_line = NULL;*/
     axis2_char_t *method = NULL;
     axis2_char_t *uri = NULL;
     axis2_char_t *http_version = NULL;
@@ -98,18 +105,22 @@
     axis2_char_t *tmp = NULL;
     int i = 0;
 
-    AXIS2_PARAM_CHECK(env->error, str, NULL);
+    if(!str)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid parameter is given to parse");
+        return NULL;
+    }
 
     tmp = axutil_strstr(str, AXIS2_HTTP_CRLF);
-
     if(!tmp)
     {
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE, AXIS2_FAILURE);
         return NULL;
     }
 
-    i = (int)(tmp - str);
-    /* We are sure that the difference lies within the int range */
+    i = (int)(tmp - str); /* We are sure that the difference lies within the int range */
+
+    /*
     req_line = AXIS2_MALLOC(env->allocator, i * sizeof(axis2_char_t) + 1);
     if(!req_line)
     {
@@ -119,28 +130,42 @@
     memcpy(req_line, str, i * sizeof(axis2_char_t));
     req_line[i] = AXIS2_ESC_NULL;
     tmp = req_line;
+    */
+    /* we don't need to do a malloc and memcpy, because this method is only used by
+     * axis2_simple_http_svr_conn_read_request and it passes a temporary string. So, we can
just
+     * set it as req_line and set the escape characters. this is done after 1.6.0 and if
no issues
+     * found until 1.8.0, above code comment can be removed after 1.8.0
+     */
+
+    tmp = (axis2_char_t *)str;
+    tmp[i] = AXIS2_ESC_NULL;
 
+    /* find http method */
     method = tmp;
     tmp = strchr(tmp, AXIS2_SPACE);
     if(!tmp)
     {
-        AXIS2_FREE(env->allocator, req_line);
+        /*AXIS2_FREE(env->allocator, req_line);*/
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE, AXIS2_FAILURE);
         return NULL;
     }
     *tmp++ = AXIS2_ESC_NULL;
+
+    /* find URI */
     uri = tmp;
     tmp = strrchr(tmp, AXIS2_SPACE);
     if(!tmp)
     {
-        AXIS2_FREE(env->allocator, req_line);
+        /*AXIS2_FREE(env->allocator, req_line);*/
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE, AXIS2_FAILURE);
         return NULL;
     }
     *tmp++ = AXIS2_ESC_NULL;
+
+    /* find HTTP version */
     http_version = tmp;
     ret = axis2_http_request_line_create(env, method, uri, http_version);
-    AXIS2_FREE(env->allocator, req_line);
+    /*AXIS2_FREE(env->allocator, req_line);*/
 
     return ret;
 }

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/http_response_writer.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/http_response_writer.c?rev=810531&r1=810530&r2=810531&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/http_response_writer.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/http_response_writer.c Wed Sep
 2 14:45:10 2009
@@ -33,7 +33,6 @@
 {
     return axis2_http_response_writer_create_with_encoding(env, stream,
         AXIS2_HTTP_DEFAULT_CONTENT_CHARSET);
-
 }
 
 AXIS2_EXTERN axis2_http_response_writer_t *AXIS2_CALL
@@ -43,21 +42,16 @@
     const axis2_char_t * encoding)
 {
     axis2_http_response_writer_t *response_writer = NULL;
-
-    AXIS2_PARAM_CHECK(env->error, encoding, NULL);
-
     response_writer = (axis2_http_response_writer_t *)AXIS2_MALLOC(env->allocator,
         sizeof(axis2_http_response_writer_t));
-
     if(!response_writer)
     {
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
         return NULL;
     }
-    memset((void *)response_writer, 0, sizeof(axis2_http_response_writer_t));
+
     response_writer->stream = stream;
     response_writer->encoding = (axis2_char_t *)axutil_strdup(env, encoding);
-
     return response_writer;
 }
 
@@ -66,15 +60,8 @@
     axis2_http_response_writer_t * response_writer,
     const axutil_env_t * env)
 {
-    if(!response_writer)
-    {
-        return;
-    }
-
     AXIS2_FREE(env->allocator, response_writer->encoding);
     AXIS2_FREE(env->allocator, response_writer);
-
-    return;
 }
 
 AXIS2_EXTERN axis2_char_t *AXIS2_CALL
@@ -92,12 +79,11 @@
     char c)
 {
     int write = -1;
-    AXIS2_PARAM_CHECK(env->error, response_writer, AXIS2_FAILURE);
-
     if(!response_writer->stream)
     {
         return AXIS2_FAILURE;
     }
+
     write = axutil_stream_write(response_writer->stream, env, &c, 1);
     if(write < 0)
     {
@@ -140,9 +126,6 @@
     int write = -1;
     int len = -1;
 
-    AXIS2_PARAM_CHECK(env->error, response_writer, AXIS2_FAILURE);
-    AXIS2_PARAM_CHECK(env->error, str, AXIS2_FAILURE);
-
     len = axutil_strlen(str);
     if(!response_writer->stream)
     {
@@ -153,8 +136,7 @@
     if(write < 0)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
-            "failed to write to stream\
-string %s of length %d", str, len);
+            "failed to write to stream string %s of length %d", str, len);
         return AXIS2_FAILURE;
     }
 
@@ -178,8 +160,6 @@
     const axutil_env_t * env,
     const char *str)
 {
-    AXIS2_PARAM_CHECK(env->error, str, AXIS2_FAILURE);
-
     if(AXIS2_SUCCESS == axis2_http_response_writer_print_str(response_writer, env, str))
     {
         return axis2_http_response_writer_print_str(response_writer, env, AXIS2_HTTP_CRLF);

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_request.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_request.c?rev=810531&r1=810530&r2=810531&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_request.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_request.c Wed Sep
 2 14:45:10 2009
@@ -39,27 +39,24 @@
     axutil_stream_t * content)
 {
     axis2_http_simple_request_t *simple_request = NULL;
-
     simple_request = (axis2_http_simple_request_t *)AXIS2_MALLOC(env->allocator,
         sizeof(axis2_http_simple_request_t));
-
     if(!simple_request)
     {
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
         return NULL;
     }
+
     memset((void *)simple_request, 0, sizeof(axis2_http_simple_request_t));
     simple_request->request_line = request_line;
     simple_request->stream = content;
-    simple_request->header_group = NULL;
-    simple_request->owns_stream = AXIS2_FALSE;
 
     if(!(simple_request->stream))
     {
         simple_request->stream = axutil_stream_create_basic(env);
         if(!simple_request->stream)
         {
-            axis2_http_simple_request_free((axis2_http_simple_request_t *)simple_request,
env);
+            axis2_http_simple_request_free(simple_request, env);
             AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
             return NULL;
         }
@@ -86,18 +83,13 @@
     axis2_http_simple_request_t * simple_request,
     const axutil_env_t * env)
 {
-    if(!simple_request)
-    {
-        return;
-    }
-
-    if(AXIS2_TRUE == simple_request->owns_stream)
+    /* free the stream only if we own it. Otherwise shouldn't free the stream
+     * since it belongs to the socket
+     */
+    if(simple_request->owns_stream)
     {
         axutil_stream_free(simple_request->stream, env);
     }
-    /*
-     Don't free the stream since it belongs to the socket
-     */
 
     if(simple_request->request_line)
     {
@@ -110,16 +102,12 @@
         axis2_http_header_t *tmp = NULL;
         for(i = 0; i < axutil_array_list_size(simple_request->header_group, env); i++)
         {
-            tmp = (axis2_http_header_t *)axutil_array_list_get(simple_request-> header_group,
env,
-                i);
+            tmp = (axis2_http_header_t*)axutil_array_list_get(simple_request->header_group,
env, i);
             axis2_http_header_free(tmp, env);
-
         }
         axutil_array_list_free(simple_request->header_group, env);
     }
     AXIS2_FREE(env->allocator, simple_request);
-
-    return;
 }
 
 AXIS2_EXTERN axis2_http_request_line_t *AXIS2_CALL
@@ -200,8 +188,6 @@
     axutil_array_list_t *header_group = NULL;
     int i = 0;
     int count = 0;
-    axis2_http_header_t *tmp_header = NULL;
-    axis2_char_t *tmp_name = NULL;
 
     AXIS2_PARAM_CHECK(env->error, str, NULL);
 
@@ -209,23 +195,22 @@
     if(!simple_request->header_group)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
-            "http simple request \
-does not contain headers, unable to find: %s header", str);
+            "http simple request does not contain any headers; unable to find: %s header",
str);
         return NULL;
     }
+
     if(0 == axutil_array_list_size(header_group, env))
     {
         AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI,
-            "http simple request \
- contain zero headers, unable to find: %s header", str);
+            "http simple request contain zero headers, unable to find: %s header", str);
         return NULL;
     }
 
     count = axutil_array_list_size(header_group, env);
-
     for(i = 0; i < count; i++)
     {
-
+        axis2_http_header_t *tmp_header = NULL;
+        axis2_char_t *tmp_name = NULL;
         tmp_header = (axis2_http_header_t *)axutil_array_list_get(header_group, env, i);
         tmp_name = axis2_http_header_get_name(tmp_header, env);
         if(0 == axutil_strcasecmp(str, tmp_name))

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_response.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_response.c?rev=810531&r1=810530&r2=810531&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_response.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/http_simple_response.c Wed Sep
 2 14:45:10 2009
@@ -42,36 +42,26 @@
     axutil_stream_t * content)
 {
     axis2_http_simple_response_t *ret = NULL;
-    axis2_http_simple_response_t *simple_response = NULL;
-
     ret = axis2_http_simple_response_create_default(env);
     if(!ret)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "axis2 http simple response creation failed");
         return NULL;
     }
-    simple_response = ret;
 
-    if(!simple_response)
-    {
-        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
-        return NULL;
-    }
-
-    simple_response->status_line = status_line;
+    ret->status_line = status_line;
     if(http_hdr_count > 0 && http_headers)
     {
         int i = 0;
-        simple_response->header_group = axutil_array_list_create(env, http_hdr_count);
+        ret->header_group = axutil_array_list_create(env, http_hdr_count);
 
         for(i = 0; i < (int)http_hdr_count; i++)
         /* We are sure that the difference lies within the int range */
         {
-            axutil_array_list_add(simple_response->header_group, env, (void *)http_headers[i]);
+            axutil_array_list_add(ret->header_group, env, (void *)http_headers[i]);
         }
     }
-    simple_response->stream = content;
-
+    ret->stream = content;
     return ret;
 }
 
@@ -80,22 +70,15 @@
     const axutil_env_t * env)
 {
     axis2_http_simple_response_t *simple_response = NULL;
-
     simple_response = (axis2_http_simple_response_t *)AXIS2_MALLOC(env->allocator,
         sizeof(axis2_http_simple_response_t));
-
     if(!simple_response)
     {
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
         return NULL;
     }
-    memset((void *)simple_response, 0, sizeof(axis2_http_simple_response_t));
-    simple_response->status_line = NULL;
-    simple_response->header_group = NULL;
-    simple_response->stream = NULL;
-    simple_response->mime_parts = NULL;
-    simple_response->mtom_sending_callback_name = NULL;
 
+    memset((void *)simple_response, 0, sizeof(axis2_http_simple_response_t));
     return simple_response;
 }
 
@@ -104,7 +87,6 @@
     axis2_http_simple_response_t * simple_response,
     const axutil_env_t * env)
 {
-
     if(simple_response->status_line)
     {
         axis2_http_status_line_free(simple_response->status_line, env);
@@ -113,14 +95,13 @@
     if(simple_response->header_group)
     {
         int i = 0;
-        axis2_http_header_t *tmp = NULL;
         for(i = 0; i < axutil_array_list_size(simple_response->header_group, env);
i++)
         {
-            tmp = (axis2_http_header_t *)axutil_array_list_get(simple_response-> header_group,
env,
-                i);
+            void *tmp = NULL;
+            tmp = axutil_array_list_get(simple_response-> header_group, env, i);
             if(tmp)
             {
-                axis2_http_header_free(tmp, env);
+                axis2_http_header_free((axis2_http_header_t *)tmp, env);
             }
         }
         axutil_array_list_free(simple_response->header_group, env);
@@ -131,23 +112,19 @@
         int i = 0;
         for(i = 0; i < axutil_array_list_size(simple_response->mime_parts, env); i++)
         {
-            axiom_mime_part_t *mime_part = NULL;
-            mime_part = (axiom_mime_part_t *)axutil_array_list_get(simple_response->mime_parts,
-                env, i);
+            void *mime_part = NULL;
+            mime_part = axutil_array_list_get(simple_response->mime_parts, env, i);
             if(mime_part)
             {
-                axiom_mime_part_free(mime_part, env);
+                axiom_mime_part_free((axiom_mime_part_t *)mime_part, env);
             }
         }
         axutil_array_list_free(simple_response->mime_parts, env);
     }
 
+     /* Stream is not freed. Assumption : stream doesn't belong to the response */
+
     AXIS2_FREE(env->allocator, simple_response);
-    /* 
-     * Stream is not freed
-     * Assumption : stream doesn't belong to the response
-     */
-    return;
 }
 
 axis2_status_t AXIS2_CALL
@@ -158,35 +135,23 @@
     const int status_code,
     const axis2_char_t * phrase)
 {
-    axis2_char_t *tmp_status_line_str = NULL;
-
-    AXIS2_PARAM_CHECK(env->error, http_ver, AXIS2_FAILURE);
-    AXIS2_PARAM_CHECK(env->error, status_code, AXIS2_FAILURE);
-    AXIS2_PARAM_CHECK(env->error, phrase, AXIS2_FAILURE);
-
-    tmp_status_line_str = AXIS2_MALLOC(env->allocator, (axutil_strlen(http_ver) + axutil_strlen(
-        phrase) + 8) * sizeof(axis2_char_t *));
-
-    if(!tmp_status_line_str)
+    if(!http_ver || !phrase || !status_code)
     {
-        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "invalid parameter given");
+        return AXIS2_FAILURE;
     }
 
-    sprintf(tmp_status_line_str, "%s %3d %s%s", http_ver, status_code, phrase, AXIS2_HTTP_CRLF);
-
     if(simple_response->status_line)
     {
         axis2_http_status_line_free(simple_response->status_line, env);
-        simple_response->status_line = NULL;
     }
-    simple_response->status_line = axis2_http_status_line_create(env, tmp_status_line_str);
-    AXIS2_FREE(env->allocator, tmp_status_line_str);
 
+    simple_response->status_line = axis2_http_status_line_create_with_values(
+        env, http_ver, status_code, phrase);
     if(!simple_response->status_line)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
-            "axis2 http status line creation failed for tmp \
-string %s", tmp_status_line_str);
+            "http status line creation failed for string %s %3d %s", http_ver, status_code,
phrase);
         return AXIS2_FAILURE;
     }
     return AXIS2_SUCCESS;
@@ -341,8 +306,6 @@
     const axis2_char_t * str)
 {
     axutil_array_list_t *header_group = NULL;
-    axis2_http_header_t *tmp_header = NULL;
-    axis2_char_t *tmp_name = NULL;
     int i = 0;
     int count = 0;
 
@@ -352,16 +315,17 @@
     if(!header_group)
     {
         /* Even though we couldn't complete the op, we are sure that the
-         * requred header is no more in the request. So we can proceed without a
+         * required header is no more in the request. So we can proceed without a
          * problem.
          */
         return AXIS2_SUCCESS;
     }
 
     count = axutil_array_list_size(header_group, env);
-
     for(i = 0; i < count; i++)
     {
+        axis2_http_header_t *tmp_header = NULL;
+        axis2_char_t *tmp_name = NULL;
         tmp_header = (axis2_http_header_t *)axutil_array_list_get(header_group, env, i);
         tmp_name = axis2_http_header_get_name(tmp_header, env);
         if(0 == axutil_strcasecmp(str, tmp_name))
@@ -382,8 +346,6 @@
 {
     int i = 0;
     int count = 0;
-    axis2_http_header_t *tmp_header = NULL;
-    axis2_char_t *tmp_name = NULL;
     axutil_array_list_t *header_group = NULL;
 
     AXIS2_PARAM_CHECK(env->error, header, AXIS2_FAILURE);
@@ -395,24 +357,25 @@
         return AXIS2_SUCCESS;
     }
 
-    /* If a header with the same name exists
-     * search and remove the old header
-     */
+    /* If a header with the same name exists search and remove the old header */
     header_group = simple_response->header_group;
-
     count = axutil_array_list_size(header_group, env);
     for(i = 0; i < count; i++)
     {
+        axis2_http_header_t *tmp_header = NULL;
+        axis2_char_t *tmp_name = NULL;
         tmp_header = (axis2_http_header_t *)axutil_array_list_get(header_group, env, i);
         tmp_name = axis2_http_header_get_name(tmp_header, env);
         if(0 == axutil_strcasecmp(axis2_http_header_get_name(header, env), tmp_name))
         {
             axis2_http_header_free(tmp_header, env);
-            axutil_array_list_remove(header_group, env, i);
-            break;
+            axutil_array_list_set(header_group, env, i, header);
+            return AXIS2_SUCCESS;
         }
     }
-    axutil_array_list_add(simple_response->header_group, env, (void *)header);
+
+    /* if header is not found, then we have to add it */
+    axutil_array_list_add(header_group, env, header);
     return AXIS2_SUCCESS;
 }
 
@@ -589,9 +552,9 @@
     if(!simple_response->header_group)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "axis2 simple response , headers not available");
-
         return AXIS2_FALSE;
     }
+
     count = axutil_array_list_size(simple_response->header_group, env);
     if(0 == count)
     {
@@ -601,10 +564,13 @@
 
     for(i = 0; i < count; i++)
     {
-        header_name = axis2_http_header_get_name((axis2_http_header_t *)axutil_array_list_get(
-            simple_response->header_group, env, i), env);
+        axis2_http_header_t *header = (axis2_http_header_t *)axutil_array_list_get(
+            simple_response->header_group, env, i);
+        header_name = axis2_http_header_get_name(header, env);
         if(0 == axutil_strcasecmp(name, header_name))
+        {
             return AXIS2_TRUE;
+        }
     }
     return AXIS2_FALSE;
 }

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/http_status_line.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/http_status_line.c?rev=810531&r1=810530&r2=810531&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/http_status_line.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/http_status_line.c Wed Sep  2
14:45:10 2009
@@ -19,6 +19,7 @@
 #include <axutil_string.h>
 #include <axis2_http_transport.h>
 #include <string.h>
+#include <stdio.h>
 #include <axutil_types.h>
 
 struct axis2_http_status_line
@@ -52,23 +53,22 @@
     }
     memset((void *)status_line, 0, sizeof(axis2_http_status_line_t));
     status_line->line = (axis2_char_t *)axutil_strdup(env, str);
-    status_line->http_version = NULL;
-    status_line->reason_phrase = NULL;
-    status_line->status_code = NULL;
 
+    /* extract status code, phrase and version from given string */
     tmp = strstr(str, AXIS2_HTTP_CRLF);
     if(!tmp)
     {
-        axis2_http_status_line_free((axis2_http_status_line_t *)status_line, env);
+        axis2_http_status_line_free(status_line, env);
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE, AXIS2_FAILURE);
         return NULL;
     }
-    i = (int)(tmp - str);
-    /* We are sure that the difference lies within the int range */
+
+    i = (int)(tmp - str); /* We are sure that the difference lies within the int range */
+
     tmp_status_line = AXIS2_MALLOC(env->allocator, i * sizeof(axis2_char_t) + 1);
     if(!tmp_status_line)
     {
-        axis2_http_status_line_free((axis2_http_status_line_t *)status_line, env);
+        axis2_http_status_line_free(status_line, env);
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
         return NULL;
     }
@@ -76,40 +76,92 @@
     tmp_status_line[i] = AXIS2_ESC_NULL;
     tmp = tmp_status_line;
 
+    /* get HTTP version */
     http_version = tmp;
     tmp = strchr(tmp, AXIS2_SPACE);
     if(!tmp)
     {
         AXIS2_FREE(env->allocator, tmp_status_line);
-        axis2_http_status_line_free((axis2_http_status_line_t *)status_line, env);
+        axis2_http_status_line_free(status_line, env);
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE, AXIS2_FAILURE);
         return NULL;
     }
-
     *tmp++ = AXIS2_ESC_NULL;
+
+    /* get status code */
     status_code = tmp;
     tmp = strchr(tmp, AXIS2_SPACE);
     if(!tmp)
     {
         AXIS2_FREE(env->allocator, tmp_status_line);
-        axis2_http_status_line_free((axis2_http_status_line_t *)status_line, env);
+        axis2_http_status_line_free(status_line, env);
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE, AXIS2_FAILURE);
         return NULL;
     }
     *tmp++ = AXIS2_ESC_NULL;
+
+    /* get reason phrase */
     reason_phrase = tmp;
+
+    /* populate values */
     status_line->http_version = (axis2_char_t *)axutil_strdup(env, http_version);
     status_line->status_code = (axis2_char_t *)axutil_strdup(env, status_code);
     status_line->reason_phrase = (axis2_char_t *)axutil_strdup(env, reason_phrase);
+    AXIS2_FREE(env->allocator, tmp_status_line);
+
+    if(!status_line->http_version || !status_line->reason_phrase || !status_line->status_code)
+    {
+        axis2_http_status_line_free(status_line, env);
+        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    return status_line;
+}
+
+AXIS2_EXTERN axis2_http_status_line_t *AXIS2_CALL
+axis2_http_status_line_create_with_values(
+    const axutil_env_t * env,
+    const axis2_char_t * http_ver,
+    const int status_code,
+    const axis2_char_t * phrase)
+{
+    axis2_http_status_line_t *status_line = NULL;
+    status_line = (axis2_http_status_line_t *)AXIS2_MALLOC(env->allocator,
+        sizeof(axis2_http_status_line_t));
+    if(!status_line)
+    {
+        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    memset((void *)status_line, 0, sizeof(axis2_http_status_line_t));
+
+    status_line->status_code = AXIS2_MALLOC(env->allocator, 6 * sizeof(axis2_char_t
*));
+    if(!status_line->status_code)
+    {
+        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        axis2_http_status_line_free(status_line, env);
+        return NULL;
+    }
+    sprintf(status_line->status_code, "%3d", status_code);
 
+    status_line->http_version = axutil_strdup(env, http_ver);
+    status_line->reason_phrase = axutil_strdup(env, phrase);
     if(!status_line->http_version || !status_line->reason_phrase)
     {
-        AXIS2_FREE(env->allocator, tmp_status_line);
-        axis2_http_status_line_free((axis2_http_status_line_t *)status_line, env);
+        axis2_http_status_line_free(status_line, env);
+        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    status_line->line = axutil_strcat(env, http_ver, " ", status_line->status_code,
" ", phrase,
+        AXIS2_HTTP_CRLF, NULL);
+    if(!status_line->line)
+    {
+        axis2_http_status_line_free(status_line, env);
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
         return NULL;
     }
-    AXIS2_FREE(env->allocator, tmp_status_line);
 
     return status_line;
 }



Mime
View raw message