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 2007/02/13 05:53:22 UTC

svn commit: r506856 - in /webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender: http_header.c http_request_line.c http_simple_request.c http_simple_response.c http_status_line.c

Author: dinesh
Date: Mon Feb 12 20:53:21 2007
New Revision: 506856

URL: http://svn.apache.org/viewvc?view=rev&rev=506856
Log:
axis2c-486: working on axis2c transport refactoring, moving sender releated files to sender and receiver releated files to receiver

Added:
    webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_header.c
    webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_request_line.c
    webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_request.c
    webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_response.c
    webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_status_line.c

Added: webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_header.c
URL: http://svn.apache.org/viewvc/webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_header.c?view=auto&rev=506856
==============================================================================
--- webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_header.c (added)
+++ webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_header.c Mon Feb 12 20:53:21 2007
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axis2_http_header.h>
+#include <axis2_string.h>
+#include <axis2_http_transport.h>
+#include <stdio.h>
+#include <string.h>
+
+/**
+ * @brief HTTP Header struct impl
+ *   Axis2 HTTP Header impl
+ */
+
+typedef struct axis2_http_header_impl
+{
+    axis2_http_header_t http_header;
+    axis2_char_t *name;
+    axis2_char_t *value;
+}
+axis2_http_header_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(http_header) \
+                ((axis2_http_header_impl_t *)(http_header))
+
+/***************************** Function headers *******************************/
+axis2_char_t *AXIS2_CALL
+axis2_http_header_to_external_form(
+    axis2_http_header_t *header,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_header_get_name(
+    const axis2_http_header_t *header,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_header_get_value(
+    const axis2_http_header_t *header,
+    const axis2_env_t *env);
+
+axis2_status_t AXIS2_CALL
+axis2_http_header_free(
+    axis2_http_header_t *header,
+    const axis2_env_t *env);
+
+/***************************** End of function headers ************************/
+
+AXIS2_EXTERN axis2_http_header_t *AXIS2_CALL
+axis2_http_header_create(
+    const axis2_env_t *env,
+    const axis2_char_t *name,
+    const axis2_char_t *value)
+{
+    axis2_http_header_impl_t *http_header_impl = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    AXIS2_ENV_CHECK(env, NULL);
+    AXIS2_ENV_CHECK(env, NULL);
+
+    http_header_impl = (axis2_http_header_impl_t *)AXIS2_MALLOC
+            (env->allocator, sizeof(
+                        axis2_http_header_impl_t));
+
+    if (NULL == http_header_impl)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    http_header_impl->name = (axis2_char_t *)AXIS2_STRDUP(name, env);
+    http_header_impl->value = (axis2_char_t *)AXIS2_STRDUP(value, env);
+
+    http_header_impl->http_header.ops = AXIS2_MALLOC(env->allocator,
+            sizeof(axis2_http_header_ops_t));
+    if (NULL == http_header_impl->http_header.ops)
+    {
+        axis2_http_header_free((axis2_http_header_t *)
+                http_header_impl, env);
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    http_header_impl->http_header.ops->to_external_form =
+        axis2_http_header_to_external_form;
+    http_header_impl->http_header.ops->get_name = axis2_http_header_get_name;
+    http_header_impl->http_header.ops->get_value = axis2_http_header_get_value;
+    http_header_impl->http_header.ops->free = axis2_http_header_free;
+
+    return &(http_header_impl->http_header);
+}
+
+AXIS2_EXTERN axis2_http_header_t *AXIS2_CALL AXIS2_CALL
+axis2_http_header_create_by_str(
+    const axis2_env_t *env,
+    const axis2_char_t *str)
+{
+    axis2_char_t *tmp_str = NULL;
+    axis2_char_t *ch = NULL;
+    axis2_char_t *ch2 = NULL;
+    axis2_http_header_t *ret = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    AXIS2_ENV_CHECK(env, NULL);
+
+    tmp_str = AXIS2_STRDUP(str, env);
+    if (NULL == tmp_str)
+    {
+        return NULL;
+    }
+    /* remove trailing \r\n */
+    if ('\r' == tmp_str[AXIS2_STRLEN(tmp_str)-2])
+    {
+        tmp_str[AXIS2_STRLEN(tmp_str)-2] = '\0';
+    }
+
+    ch = strchr((const char *)tmp_str, ':');
+    if (NULL == ch)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_HEADER,
+                AXIS2_FAILURE);
+        AXIS2_FREE(env->allocator, tmp_str);
+        return NULL;
+    }
+    ch2 = ch + sizeof(axis2_char_t);
+    /* skip spaces */
+    while (' ' == *ch2)
+    {
+        ch2 += sizeof(axis2_char_t);
+    }
+    *ch = '\0';
+    ret = axis2_http_header_create(env, tmp_str, ch2);
+    AXIS2_FREE(env->allocator, tmp_str);
+    return ret;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_http_header_free(
+    axis2_http_header_t *header,
+    const axis2_env_t *env)
+{
+    axis2_http_header_impl_t *http_header_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    http_header_impl = AXIS2_INTF_TO_IMPL(header);
+
+    if (http_header_impl->name)
+    {
+        AXIS2_FREE(env->allocator, http_header_impl->name);
+        http_header_impl->name = NULL;
+    }
+    if (http_header_impl->value)
+    {
+        AXIS2_FREE(env->allocator, http_header_impl->value);
+        http_header_impl->value = NULL;
+    }
+    if (header->ops)
+        AXIS2_FREE(env->allocator, header->ops);
+
+    AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(header));
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_header_to_external_form(
+    axis2_http_header_t *header,
+    const axis2_env_t *env)
+{
+    axis2_http_header_impl_t *http_header_impl = NULL;
+    axis2_ssize_t len = 0;
+    axis2_char_t *external_form = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    http_header_impl = AXIS2_INTF_TO_IMPL(header);
+    len = AXIS2_STRLEN(http_header_impl->name) +
+            AXIS2_STRLEN(http_header_impl->value) + 8;
+    external_form = (axis2_char_t *) AXIS2_MALLOC(env->allocator,
+            len);
+    sprintf(external_form, "%s: %s%s", http_header_impl->name,
+            http_header_impl->value, AXIS2_HTTP_CRLF);
+    return external_form;
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_header_get_name(
+    const axis2_http_header_t *header,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(header)->name;
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_header_get_value(
+    const axis2_http_header_t *header,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(header)->value;
+}

Added: webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_request_line.c
URL: http://svn.apache.org/viewvc/webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_request_line.c?view=auto&rev=506856
==============================================================================
--- webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_request_line.c (added)
+++ webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_request_line.c Mon Feb 12 20:53:21 2007
@@ -0,0 +1,291 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axis2_http_request_line.h>
+#include <axis2_string.h>
+#include <string.h>
+#include <axis2_http_transport.h>
+#include <stdio.h>
+/**
+ * @brief HTTP Request Line struct impl
+ *   Axis2 HTTP Request Line impl
+ */
+
+typedef struct axis2_http_request_line_impl
+{
+    axis2_http_request_line_t request_line;
+    axis2_char_t *http_version;
+    axis2_char_t *method;
+    axis2_char_t *uri;
+}
+axis2_http_request_line_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(request_line) \
+                 ((axis2_http_request_line_impl_t *)(request_line))
+
+/***************************** Function headers *******************************/
+
+/*
+ *  This is just a function
+ *  Not assciated with an ops struct
+ */
+axis2_http_request_line_t *AXIS2_CALL
+axis2_http_request_line_parse_line(
+    const axis2_env_t *env,
+    const axis2_char_t *str);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_request_line_get_method(
+    const axis2_http_request_line_t *request_line,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_request_line_get_http_version(
+    const axis2_http_request_line_t *request_line,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_request_line_get_uri(
+    const axis2_http_request_line_t *request_line,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_request_line_to_string(
+    axis2_http_request_line_t *request_line,
+    const axis2_env_t *env);
+
+axis2_status_t AXIS2_CALL
+axis2_http_request_line_free(
+    axis2_http_request_line_t *request_line,
+    const axis2_env_t *env);
+
+/***************************** End of function headers ************************/
+
+AXIS2_EXTERN axis2_http_request_line_t *AXIS2_CALL
+axis2_http_request_line_create(
+    const axis2_env_t *env,
+    const axis2_char_t *method,
+    const axis2_char_t *uri,
+    const axis2_char_t *http_version)
+{
+    axis2_http_request_line_impl_t *request_line_impl = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    AXIS2_PARAM_CHECK(env->error, method, NULL);
+    AXIS2_PARAM_CHECK(env->error, uri, NULL);
+    AXIS2_PARAM_CHECK(env->error, http_version, NULL);
+
+    request_line_impl = (axis2_http_request_line_impl_t *)AXIS2_MALLOC
+            (env->allocator, sizeof(
+                        axis2_http_request_line_impl_t));
+
+    if (NULL == request_line_impl)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    request_line_impl->method = (axis2_char_t *)AXIS2_STRDUP(method, env);
+    request_line_impl->uri = (axis2_char_t *)AXIS2_STRDUP(uri, env);
+    request_line_impl->http_version = (axis2_char_t *)AXIS2_STRDUP(
+                http_version, env);
+
+    request_line_impl->request_line.ops = AXIS2_MALLOC(env->allocator,
+            sizeof(axis2_http_request_line_ops_t));
+    if (NULL == request_line_impl->request_line.ops)
+    {
+        axis2_http_request_line_free((axis2_http_request_line_t *)
+                request_line_impl, env);
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    request_line_impl->request_line.ops->get_method =
+        axis2_http_request_line_get_method;
+    request_line_impl->request_line.ops->get_http_version =
+        axis2_http_request_line_get_http_version;
+    request_line_impl->request_line.ops->get_uri =
+        axis2_http_request_line_get_uri;
+    request_line_impl->request_line.ops->to_string =
+        axis2_http_request_line_to_string;
+    request_line_impl->request_line.ops->free =
+        axis2_http_request_line_free;
+    return &(request_line_impl->request_line);
+}
+
+axis2_status_t AXIS2_CALL
+axis2_http_request_line_free(
+    axis2_http_request_line_t *request_line,
+    const axis2_env_t *env)
+{
+    axis2_http_request_line_impl_t *request_line_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    request_line_impl = AXIS2_INTF_TO_IMPL(request_line);
+
+    if (request_line_impl->method)
+    {
+        AXIS2_FREE(env->allocator, request_line_impl->method);
+        request_line_impl->method = NULL;
+    }
+    if (request_line_impl->uri)
+    {
+        AXIS2_FREE(env->allocator, request_line_impl->uri);
+        request_line_impl->uri = NULL;
+    }
+    if (request_line_impl->http_version)
+    {
+        AXIS2_FREE(env->allocator, request_line_impl->http_version);
+        request_line_impl->http_version = NULL;
+    }
+    if (request_line->ops)
+        AXIS2_FREE(env->allocator, request_line->ops);
+
+    AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(request_line));
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_http_request_line_t *AXIS2_CALL
+axis2_http_request_line_parse_line(
+    const axis2_env_t *env,
+    const axis2_char_t *str)
+{
+    axis2_char_t *req_line = NULL;
+    axis2_char_t *method = NULL;
+    axis2_char_t *uri = NULL;
+    axis2_char_t *http_version = NULL;
+    axis2_http_request_line_t *ret = NULL;
+    axis2_char_t *tmp = NULL;
+    int i = 0;
+
+    AXIS2_PARAM_CHECK(env->error, str, NULL);
+
+    tmp = AXIS2_STRSTR(str, AXIS2_HTTP_CRLF);
+
+
+    if (NULL == tmp)
+    {
+        AXIS2_ERROR_SET(env->error,
+                AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE,
+                AXIS2_FAILURE);
+        return NULL;
+    }
+    i = tmp - str;
+    req_line = AXIS2_MALLOC(env->allocator, i * sizeof(axis2_char_t) + 1);
+    if (NULL == req_line)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    memcpy(req_line, str, i * sizeof(axis2_char_t));
+    req_line[i] = '\0';
+    tmp = req_line;
+
+    method = tmp;
+    tmp = strchr(tmp, ' ');
+    if (NULL == tmp)
+    {
+        AXIS2_FREE(env->allocator, req_line);
+        AXIS2_ERROR_SET(env->error,
+                AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE,
+                AXIS2_FAILURE);
+        return NULL;
+    }
+    *tmp++ = '\0';
+    uri = tmp;
+    tmp = strrchr(tmp, ' ');
+    if (NULL == tmp)
+    {
+        AXIS2_FREE(env->allocator, req_line);
+        AXIS2_ERROR_SET(env->error,
+                AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE,
+                AXIS2_FAILURE);
+        return NULL;
+    }
+    *tmp++ = '\0';
+    http_version = tmp;
+    ret = axis2_http_request_line_create(env, method, uri, http_version);
+    AXIS2_FREE(env->allocator, req_line);
+
+    return ret;
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_request_line_get_method(
+    const axis2_http_request_line_t *request_line,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(request_line)->method;
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_request_line_get_http_version(
+    const axis2_http_request_line_t *request_line,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(request_line)->http_version;
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_request_line_get_uri(
+    const axis2_http_request_line_t *request_line,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(request_line)->uri;
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_request_line_to_string(
+    axis2_http_request_line_t *request_line,
+    const axis2_env_t *env)
+{
+    axis2_http_request_line_impl_t *req_line_impl = NULL;
+    int alloc_len = 0;
+    axis2_char_t *ret = NULL;
+
+    AXIS2_ENV_CHECK(env, NULL);
+
+    req_line_impl = AXIS2_INTF_TO_IMPL(
+                request_line);
+    alloc_len = AXIS2_STRLEN(req_line_impl->method) +
+            AXIS2_STRLEN(req_line_impl->uri) +
+            AXIS2_STRLEN(req_line_impl->http_version) + 6;
+    /* 5 = 2 * spaces + '/' +CR + LF + '\0' */
+
+    ret = AXIS2_MALLOC(env->allocator,
+            alloc_len * sizeof(axis2_char_t));
+    if (NULL == ret)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    if (req_line_impl->uri[0] != '/')
+    {
+        sprintf(ret, "%s /%s %s%s", req_line_impl->method, req_line_impl->uri,
+                req_line_impl->http_version, AXIS2_HTTP_CRLF);
+    }
+    else
+    {
+        sprintf(ret, "%s %s %s%s", req_line_impl->method, req_line_impl->uri,
+                req_line_impl->http_version, AXIS2_HTTP_CRLF);
+    }
+    return ret;
+}

Added: webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_request.c
URL: http://svn.apache.org/viewvc/webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_request.c?view=auto&rev=506856
==============================================================================
--- webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_request.c (added)
+++ webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_request.c Mon Feb 12 20:53:21 2007
@@ -0,0 +1,597 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axis2_http_simple_request.h>
+#include <axis2_array_list.h>
+#include <axis2_http_transport.h>
+#include <axis2_string.h>
+#include <string.h>
+#include <axis2_types.h>
+
+/**
+ * @brief HTTP Simple Request struct impl
+ *   Axis2 HTTP Simple Request impl
+ */
+
+typedef struct axis2_http_simple_request_impl
+{
+    axis2_http_simple_request_t simple_request;
+    axis2_http_request_line_t *request_line;
+    axis2_array_list_t *header_group;
+    axis2_stream_t *stream;
+    axis2_bool_t owns_stream;
+}
+axis2_http_simple_request_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(simple_request) \
+                 ((axis2_http_simple_request_impl_t *)(simple_request))
+
+/***************************** Function headers *******************************/
+
+axis2_http_request_line_t *AXIS2_CALL
+axis2_http_simple_request_get_request_line(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_set_request_line(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    axis2_http_request_line_t *request_line);
+
+axis2_bool_t AXIS2_CALL
+axis2_http_simple_request_contains_header(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    const axis2_char_t *name);
+
+axis2_array_list_t *AXIS2_CALL
+axis2_http_simple_request_get_headers(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env);
+
+axis2_http_header_t *AXIS2_CALL
+axis2_http_simple_request_get_first_header(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    const axis2_char_t *str);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_remove_headers(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    const axis2_char_t *str);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_add_header(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    axis2_http_header_t *header);
+
+const axis2_char_t *AXIS2_CALL
+axis2_http_simple_request_get_content_type(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env);
+
+const axis2_char_t *AXIS2_CALL
+axis2_http_simple_request_get_charset(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env);
+
+axis2_ssize_t AXIS2_CALL
+axis2_http_simple_request_get_content_length(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env);
+
+axis2_stream_t *AXIS2_CALL
+axis2_http_simple_request_get_body(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env);
+
+axis2_ssize_t AXIS2_CALL
+axis2_http_simple_request_get_body_bytes(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    char **buf);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_set_body_string(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    void *str,
+    unsigned int str_len);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_free(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env);
+
+/***************************** End of function headers ************************/
+
+axis2_http_simple_request_t *AXIS2_CALL
+axis2_http_simple_request_create(
+    const axis2_env_t *env,
+    axis2_http_request_line_t *request_line,
+    axis2_http_header_t **http_headers,
+    axis2_ssize_t http_hdr_count,
+    axis2_stream_t *content)
+{
+    axis2_http_simple_request_impl_t *simple_request_impl = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    AXIS2_ENV_CHECK(env, NULL);
+
+    simple_request_impl = (axis2_http_simple_request_impl_t *)AXIS2_MALLOC
+            (env->allocator, sizeof(
+                        axis2_http_simple_request_impl_t));
+
+    if (NULL == simple_request_impl)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    simple_request_impl->request_line = request_line;
+    simple_request_impl->stream = content;
+    simple_request_impl->header_group = NULL;
+    simple_request_impl->owns_stream = AXIS2_FALSE;
+
+    if (!(simple_request_impl->stream))
+    {
+        simple_request_impl->stream = axis2_stream_create_basic(env);
+        if (NULL == simple_request_impl->stream)
+        {
+            axis2_http_simple_request_free((axis2_http_simple_request_t *)
+                    simple_request_impl, env);
+            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+            return NULL;
+        }
+        simple_request_impl->owns_stream = AXIS2_TRUE;
+    }
+
+    if (http_hdr_count > 0 &&  http_headers)
+    {
+        int i = 0;
+        simple_request_impl->header_group = axis2_array_list_create(env,
+                http_hdr_count);
+
+        for (i = 0; i < http_hdr_count; i++)
+        {
+            AXIS2_ARRAY_LIST_ADD(simple_request_impl->header_group, env,
+                    (void *)http_headers[i]);
+        }
+    }
+    /*
+        TODO : handle chunked streams
+    */
+    simple_request_impl->simple_request.ops = AXIS2_MALLOC(env->allocator,
+            sizeof(axis2_http_simple_request_ops_t));
+    if (NULL == simple_request_impl->simple_request.ops)
+    {
+        axis2_http_simple_request_free((axis2_http_simple_request_t*)
+                simple_request_impl, env);
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    simple_request_impl->simple_request.ops->get_request_line =
+        axis2_http_simple_request_get_request_line;
+    simple_request_impl->simple_request.ops->set_request_line =
+        axis2_http_simple_request_set_request_line;
+    simple_request_impl->simple_request.ops->contains_header =
+        axis2_http_simple_request_contains_header;
+    simple_request_impl->simple_request.ops->get_headers =
+        axis2_http_simple_request_get_headers;
+    simple_request_impl->simple_request.ops->get_first_header =
+        axis2_http_simple_request_get_first_header;
+    simple_request_impl->simple_request.ops->remove_headers =
+        axis2_http_simple_request_remove_headers;
+    simple_request_impl->simple_request.ops->add_header =
+        axis2_http_simple_request_add_header;
+    simple_request_impl->simple_request.ops->get_content_type =
+        axis2_http_simple_request_get_content_type;
+    simple_request_impl->simple_request.ops->get_charset =
+        axis2_http_simple_request_get_charset;
+    simple_request_impl->simple_request.ops->get_content_length =
+        axis2_http_simple_request_get_content_length;
+    simple_request_impl->simple_request.ops->get_body =
+        axis2_http_simple_request_get_body;
+    simple_request_impl->simple_request.ops->get_body_bytes =
+        axis2_http_simple_request_get_body_bytes;
+    simple_request_impl->simple_request.ops->set_body_string =
+        axis2_http_simple_request_set_body_string;
+    simple_request_impl->simple_request.ops->free =
+        axis2_http_simple_request_free;
+
+    return &(simple_request_impl->simple_request);
+}
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_free(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env)
+{
+    axis2_http_simple_request_impl_t *simple_request_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    simple_request_impl = AXIS2_INTF_TO_IMPL(simple_request);
+    if (AXIS2_TRUE == simple_request_impl->owns_stream)
+    {
+        AXIS2_STREAM_FREE(simple_request_impl->stream, env);
+        simple_request_impl->stream = NULL;
+    }
+    /*
+        Don't free the stream since it belongs to the socket
+        TODO : if chunked remove the chunked stream.
+    */
+    if (simple_request_impl->request_line)
+    {
+        AXIS2_HTTP_REQUEST_LINE_FREE(simple_request_impl->request_line, env);
+        simple_request_impl->request_line = NULL;
+    }
+    if (simple_request_impl->header_group)
+    {
+        int i = 0;
+        axis2_http_header_t *tmp = NULL;
+        for (i = 0; i < AXIS2_ARRAY_LIST_SIZE(simple_request_impl->header_group,
+                env); i++)
+        {
+            tmp = (axis2_http_header_t *)AXIS2_ARRAY_LIST_GET(
+                        simple_request_impl->header_group, env, i);
+            AXIS2_HTTP_HEADER_FREE(tmp, env);
+
+        }
+        AXIS2_ARRAY_LIST_FREE(simple_request_impl->header_group, env);
+        simple_request_impl->header_group = NULL;
+    }
+
+    if (simple_request->ops)
+        AXIS2_FREE(env->allocator, simple_request->ops);
+
+    AXIS2_FREE(env->allocator, simple_request_impl);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_http_request_line_t *AXIS2_CALL
+axis2_http_simple_request_get_request_line(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(simple_request)->request_line;
+}
+
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_set_request_line(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    axis2_http_request_line_t *request_line)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, request_line, AXIS2_FAILURE);
+    AXIS2_INTF_TO_IMPL(simple_request)->request_line = request_line;
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_bool_t AXIS2_CALL
+axis2_http_simple_request_contains_header(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    const axis2_char_t *name)
+{
+    int i = 0;
+    axis2_char_t *header_name = NULL;
+    axis2_http_simple_request_impl_t *simple_request_impl = NULL;
+    int count = 0;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE);
+
+    simple_request_impl = AXIS2_INTF_TO_IMPL(simple_request);
+
+    if (NULL == simple_request_impl->header_group)
+    {
+        return AXIS2_FALSE;
+    }
+
+    count = AXIS2_ARRAY_LIST_SIZE(simple_request_impl->header_group, env);
+
+    if (0 == count)
+    {
+        return AXIS2_FALSE;
+    }
+
+    for (i = 0; i < count; i++)
+    {
+        header_name = AXIS2_HTTP_HEADER_GET_NAME((axis2_http_header_t *)
+                AXIS2_ARRAY_LIST_GET(simple_request_impl->header_group,
+                        env, i), env);
+        if (0 == AXIS2_STRCASECMP(name, header_name))
+            return AXIS2_TRUE;
+    }
+    return AXIS2_FALSE;
+}
+
+
+axis2_array_list_t *AXIS2_CALL
+axis2_http_simple_request_get_headers(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(simple_request)->header_group;
+}
+
+
+axis2_http_header_t *AXIS2_CALL
+axis2_http_simple_request_get_first_header(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    const axis2_char_t *str)
+{
+    axis2_http_simple_request_impl_t *simple_request_impl = NULL;
+    axis2_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_ENV_CHECK(env, NULL);
+    AXIS2_PARAM_CHECK(env->error, str, NULL);
+
+    simple_request_impl = AXIS2_INTF_TO_IMPL(simple_request);
+
+    header_group = simple_request_impl->header_group;
+    if (NULL == simple_request_impl->header_group)
+    {
+        return NULL;
+    }
+    if (0 == AXIS2_ARRAY_LIST_SIZE(header_group, env))
+    {
+        return NULL;
+    }
+
+
+    count = AXIS2_ARRAY_LIST_SIZE(header_group, env);
+
+
+    for (i = 0; i < count; i++)
+    {
+
+        tmp_header = (axis2_http_header_t *)AXIS2_ARRAY_LIST_GET(header_group,
+                env, i);
+        tmp_name = AXIS2_HTTP_HEADER_GET_NAME(tmp_header, env);
+        if (0 == AXIS2_STRCASECMP(str, tmp_name))
+        {
+            return tmp_header;
+        }
+    }
+    return NULL;
+}
+
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_remove_headers(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    const axis2_char_t *str)
+{
+    axis2_http_header_t *tmp_header = NULL;
+    axis2_char_t *tmp_name = NULL;
+    int i = 0;
+    int count = 0;
+    axis2_array_list_t *header_group = NULL;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, str, AXIS2_FAILURE);
+
+    header_group = AXIS2_INTF_TO_IMPL(simple_request)->header_group;
+
+    if (NULL == 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
+         * problem.
+         */
+        return AXIS2_SUCCESS;
+    }
+
+    count = AXIS2_ARRAY_LIST_SIZE(header_group, env);
+
+    for (i = 0; i < count; i++)
+    {
+        tmp_header = (axis2_http_header_t *)AXIS2_ARRAY_LIST_GET(header_group,
+                env, i);
+        tmp_name = AXIS2_HTTP_HEADER_GET_NAME(tmp_header, env);
+        if (0 == AXIS2_STRCASECMP(str, tmp_name))
+        {
+            AXIS2_HTTP_HEADER_FREE(tmp_header, env);
+            AXIS2_ARRAY_LIST_REMOVE(header_group, env, i);
+            break;
+        }
+    }
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_add_header(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    axis2_http_header_t *header)
+{
+    axis2_http_simple_request_impl_t *simple_request_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, header, AXIS2_FAILURE);
+
+    simple_request_impl = AXIS2_INTF_TO_IMPL(
+                simple_request);
+    if (NULL == simple_request_impl->header_group)
+    {
+        simple_request_impl->header_group = axis2_array_list_create(env, 1);
+    }
+    return AXIS2_ARRAY_LIST_ADD(AXIS2_INTF_TO_IMPL(simple_request)->header_group,
+            env, header);
+}
+
+
+const axis2_char_t *AXIS2_CALL
+axis2_http_simple_request_get_content_type(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env)
+{
+    axis2_http_header_t *tmp_header = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    tmp_header = axis2_http_simple_request_get_first_header
+            (simple_request, env, AXIS2_HTTP_HEADER_CONTENT_TYPE);
+    if (tmp_header)
+        return AXIS2_HTTP_HEADER_GET_VALUE(tmp_header, env);
+
+    return AXIS2_HTTP_HEADER_ACCEPT_TEXT_PLAIN;
+}
+
+
+const axis2_char_t *AXIS2_CALL
+axis2_http_simple_request_get_charset(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env)
+{
+    axis2_http_header_t *tmp_header  = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    tmp_header = axis2_http_simple_request_get_first_header
+            (simple_request, env, AXIS2_HTTP_HEADER_CONTENT_TYPE);
+    if (tmp_header)
+    {
+        axis2_char_t *value = AXIS2_HTTP_HEADER_GET_VALUE(tmp_header, env);
+        axis2_char_t *charset = (axis2_char_t *)strstr((char *)value,
+                (char *)AXIS2_HTTP_CHAR_SET_ENCODING);
+        if (charset)
+        {
+            charset = strchr((char *)charset, '=');
+            return charset;
+        }
+    }
+
+    return AXIS2_HTTP_DEFAULT_CONTENT_CHARSET;
+}
+
+
+axis2_ssize_t AXIS2_CALL
+axis2_http_simple_request_get_content_length(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env)
+{
+    axis2_http_header_t *tmp_header = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    tmp_header = axis2_http_simple_request_get_first_header
+            (simple_request, env, AXIS2_HTTP_HEADER_CONTENT_LENGTH);
+    if (tmp_header)
+    {
+        return AXIS2_ATOI(AXIS2_HTTP_HEADER_GET_VALUE(tmp_header, env));
+    }
+    return -1;
+}
+
+
+axis2_stream_t *AXIS2_CALL
+axis2_http_simple_request_get_body(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(simple_request)->stream;
+}
+
+
+axis2_ssize_t AXIS2_CALL
+axis2_http_simple_request_get_body_bytes(
+    const axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    char **buf)
+{
+    axis2_stream_t *body = NULL;
+    char *tmp_buf = NULL;
+    char *tmp_buf2 = NULL;
+    char *tmp_buf3 = NULL;
+    int length = 0;
+    int read_len = 0;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    body = AXIS2_INTF_TO_IMPL(simple_request)->stream;
+    if (NULL == body)
+    {
+        *buf = (char*)AXIS2_MALLOC(env->allocator, 1);
+        *buf[0] = '\0';
+        return 0;
+    }
+    length = AXIS2_HTTP_SIMPLE_REQUEST_GET_CONTENT_LENGTH(simple_request, env);
+    if (length > 0)
+    {
+        *buf = (char*)AXIS2_MALLOC(env->allocator, length + 1);
+        read_len = AXIS2_STREAM_READ(body, env, *buf, length + 1);
+        return read_len;
+    }
+    tmp_buf2 = AXIS2_MALLOC(env->allocator, 128 * sizeof(char));
+    while (AXIS2_STREAM_READ(body, env, tmp_buf2, 128) > 0)
+    {
+        tmp_buf3 = AXIS2_STRACAT(tmp_buf, tmp_buf2, env);
+        if (tmp_buf)
+        {
+            AXIS2_FREE(env->allocator, tmp_buf);
+            tmp_buf = NULL;
+        }
+        tmp_buf = tmp_buf3;
+
+    }
+    /*
+        TODO :STREAM_READ => STREAM_READ_BYTES
+    */
+    if (tmp_buf)
+    {
+        *buf = tmp_buf;
+        return AXIS2_STRLEN(tmp_buf);
+    }
+    return -1;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_request_set_body_string(
+    axis2_http_simple_request_t *simple_request,
+    const axis2_env_t *env,
+    void *str,
+    unsigned int str_len)
+{
+    axis2_stream_t *body_stream = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, str, AXIS2_FAILURE);
+
+    body_stream = AXIS2_INTF_TO_IMPL(simple_request)->stream;
+    if (NULL == body_stream)
+    {
+        body_stream = axis2_stream_create_basic(env);
+        if (NULL == body_stream)
+        {
+            return AXIS2_FAILURE;
+        }
+        AXIS2_INTF_TO_IMPL(simple_request)->stream = body_stream;
+        AXIS2_INTF_TO_IMPL(simple_request)->owns_stream = AXIS2_TRUE;
+    }
+    AXIS2_STREAM_WRITE(body_stream, env, str, str_len);
+    return AXIS2_SUCCESS;
+}

Added: webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_response.c
URL: http://svn.apache.org/viewvc/webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_response.c?view=auto&rev=506856
==============================================================================
--- webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_response.c (added)
+++ webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_simple_response.c Mon Feb 12 20:53:21 2007
@@ -0,0 +1,734 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <axis2_http_simple_response.h>
+#include <axis2_http_transport.h>
+#include <axis2_string.h>
+#include <stdio.h>
+#include <string.h>
+#include <axis2_types.h>
+
+/**
+ * @brief HTTP Simple Response struct impl
+ *   Axis2 HTTP Simple Response impl
+ */
+#define READ_SIZE 2048
+
+
+typedef struct axis2_http_simple_response_impl
+{
+    axis2_http_simple_response_t simple_response;
+    axis2_http_status_line_t *status_line;
+    axis2_array_list_t *header_group;
+    axis2_stream_t *stream;
+}
+axis2_http_simple_response_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(simple_response) \
+                 ((axis2_http_simple_response_impl_t *)(simple_response))
+
+/***************************** Function headers *******************************/
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_set_status_line(
+    struct axis2_http_simple_response *simple_response,
+    const axis2_env_t *env,
+    const axis2_char_t *http_ver,
+    const int status_code,
+    const axis2_char_t *phrase);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_phrase(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+int AXIS2_CALL
+axis2_http_simple_response_get_status_code(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_http_version(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_status_line(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+axis2_bool_t AXIS2_CALL
+axis2_http_simple_response_contains_header(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    const axis2_char_t *name);
+
+axis2_array_list_t *AXIS2_CALL
+axis2_http_simple_response_get_headers(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+axis2_http_header_t *AXIS2_CALL
+axis2_http_simple_response_get_first_header(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    const axis2_char_t *str);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_remove_headers(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    const axis2_char_t *str);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_set_header(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    axis2_http_header_t *header);
+
+const axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_charset(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+axis2_ssize_t AXIS2_CALL
+axis2_http_simple_response_get_content_length(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+const axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_content_type(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_set_body_string(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    axis2_char_t *str);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_set_body_stream(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    axis2_stream_t *stream);
+
+axis2_stream_t *AXIS2_CALL
+axis2_http_simple_response_get_body(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+axis2_ssize_t AXIS2_CALL
+axis2_http_simple_response_get_body_bytes(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    axis2_char_t **buf);
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_free(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env);
+
+/***************************** End of function headers ************************/
+
+AXIS2_EXTERN axis2_http_simple_response_t *AXIS2_CALL
+axis2_http_simple_response_create(
+    const axis2_env_t *env,
+    axis2_http_status_line_t *status_line,
+    const axis2_http_header_t **http_headers,
+    const axis2_ssize_t http_hdr_count,
+    axis2_stream_t *content)
+{
+    axis2_http_simple_response_t *ret = NULL;
+    axis2_http_simple_response_impl_t *simple_response_impl = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    AXIS2_ENV_CHECK(env, NULL);
+
+    ret = axis2_http_simple_response_create_default(env);
+    if (NULL == ret)
+    {
+        return NULL;
+    }
+    simple_response_impl = AXIS2_INTF_TO_IMPL(ret);
+
+    if (NULL == simple_response_impl)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    simple_response_impl->status_line = status_line;
+    if (http_hdr_count > 0 &&  http_headers)
+    {
+        int i = 0;
+        simple_response_impl->header_group = axis2_array_list_create(env,
+                http_hdr_count);
+
+        for (i = 0; i < http_hdr_count; i++)
+        {
+            AXIS2_ARRAY_LIST_ADD(simple_response_impl->header_group, env,
+                    (void *)http_headers[i]);
+        }
+    }
+    simple_response_impl->stream = content;
+
+    return ret;
+}
+
+
+AXIS2_EXTERN axis2_http_simple_response_t *AXIS2_CALL
+axis2_http_simple_response_create_default(
+    const axis2_env_t *env)
+{
+    axis2_http_simple_response_impl_t *simple_response_impl = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+
+    simple_response_impl = (axis2_http_simple_response_impl_t *)AXIS2_MALLOC
+            (env->allocator, sizeof(
+                        axis2_http_simple_response_impl_t));
+
+    simple_response_impl->simple_response.ops = AXIS2_MALLOC(env->allocator,
+            sizeof(axis2_http_simple_response_ops_t));
+    if (NULL == simple_response_impl->simple_response.ops)
+    {
+        axis2_http_simple_response_free((axis2_http_simple_response_t *)
+                simple_response_impl, env);
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    simple_response_impl->status_line = NULL;
+    simple_response_impl->header_group = NULL;
+    simple_response_impl->stream = NULL;
+
+    simple_response_impl->simple_response.ops->set_status_line =
+        axis2_http_simple_response_set_status_line;
+    simple_response_impl->simple_response.ops->get_phrase =
+        axis2_http_simple_response_get_phrase;
+    simple_response_impl->simple_response.ops->get_status_code =
+        axis2_http_simple_response_get_status_code;
+    simple_response_impl->simple_response.ops->get_http_version =
+        axis2_http_simple_response_get_http_version;
+    simple_response_impl->simple_response.ops->get_status_line =
+        axis2_http_simple_response_get_status_line;
+    simple_response_impl->simple_response.ops->contains_header =
+        axis2_http_simple_response_contains_header;
+    simple_response_impl->simple_response.ops->get_headers =
+        axis2_http_simple_response_get_headers;
+    simple_response_impl->simple_response.ops->get_first_header =
+        axis2_http_simple_response_get_first_header;
+    simple_response_impl->simple_response.ops->remove_headers =
+        axis2_http_simple_response_remove_headers;
+    simple_response_impl->simple_response.ops->set_header =
+        axis2_http_simple_response_set_header;
+    simple_response_impl->simple_response.ops->get_charset =
+        axis2_http_simple_response_get_charset;
+    simple_response_impl->simple_response.ops->get_content_type =
+        axis2_http_simple_response_get_content_type;
+    simple_response_impl->simple_response.ops->get_content_length =
+        axis2_http_simple_response_get_content_length;
+    simple_response_impl->simple_response.ops->set_body_string =
+        axis2_http_simple_response_set_body_string;
+    simple_response_impl->simple_response.ops->set_body_stream =
+        axis2_http_simple_response_set_body_stream;
+    simple_response_impl->simple_response.ops->get_body =
+        axis2_http_simple_response_get_body;
+    simple_response_impl->simple_response.ops->get_body_bytes =
+        axis2_http_simple_response_get_body_bytes;
+    simple_response_impl->simple_response.ops->free =
+        axis2_http_simple_response_free;
+
+    return &(simple_response_impl->simple_response);
+}
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_free(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    axis2_http_simple_response_impl_t *simple_response_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    simple_response_impl = AXIS2_INTF_TO_IMPL(simple_response);
+
+    if (simple_response_impl->status_line)
+    {
+        AXIS2_HTTP_STATUS_LINE_FREE(simple_response_impl->status_line, env);
+        simple_response_impl->status_line = NULL;
+    }
+    if (simple_response_impl->header_group)
+    {
+        int i = 0;
+        axis2_http_header_t *tmp = NULL;
+        for (i = 0; i < AXIS2_ARRAY_LIST_SIZE(simple_response_impl->header_group,
+                env); i++)
+        {
+            tmp = (axis2_http_header_t *)AXIS2_ARRAY_LIST_GET(
+                        simple_response_impl->header_group, env, i);
+            if (tmp)
+            {
+                AXIS2_HTTP_HEADER_FREE(tmp, env);
+            }
+        }
+        AXIS2_ARRAY_LIST_FREE(simple_response_impl->header_group, env);
+        simple_response_impl->header_group = NULL;
+    }
+    if (simple_response->ops)
+        AXIS2_FREE(env->allocator, simple_response->ops);
+
+    AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(simple_response));
+    /* Stream is not freed
+     * Assumption : stream doesn't belong to the response
+     */
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_set_status_line(
+    struct axis2_http_simple_response *simple_response,
+    const axis2_env_t *env,
+    const axis2_char_t *http_ver,
+    const int status_code,
+    const axis2_char_t *phrase)
+{
+    axis2_char_t *tmp_status_line_str = NULL;
+    axis2_http_simple_response_impl_t *simple_response_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    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,
+            (AXIS2_STRLEN(http_ver) + AXIS2_STRLEN(phrase) + 8) *
+            sizeof(axis2_char_t *));
+    sprintf(tmp_status_line_str, "%s %3d %s%s", http_ver, status_code, phrase,
+            AXIS2_HTTP_CRLF);
+    simple_response_impl = AXIS2_INTF_TO_IMPL
+            (simple_response);
+    if (simple_response_impl->status_line)
+    {
+        AXIS2_HTTP_STATUS_LINE_FREE(simple_response_impl->status_line, env);
+        simple_response_impl->status_line = NULL;
+    }
+    simple_response_impl->status_line = axis2_http_status_line_create(env,
+            tmp_status_line_str);
+    AXIS2_FREE(env->allocator, tmp_status_line_str);
+
+    if (NULL == simple_response_impl->status_line)
+    {
+        return AXIS2_FAILURE;
+    }
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_phrase(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    if (NULL == AXIS2_INTF_TO_IMPL(simple_response)->status_line)
+    {
+        return NULL;
+    }
+    return AXIS2_HTTP_STATUS_LINE_GET_REASON_PHRASE(AXIS2_INTF_TO_IMPL(
+                simple_response)->status_line, env);
+}
+
+
+int AXIS2_CALL
+axis2_http_simple_response_get_status_code(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    if (NULL == AXIS2_INTF_TO_IMPL(simple_response)->status_line)
+    {
+        return -1;
+    }
+    return AXIS2_HTTP_STATUS_LINE_GET_STATUS_CODE(AXIS2_INTF_TO_IMPL(
+                simple_response)->status_line, env);
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_http_version(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    if (NULL == AXIS2_INTF_TO_IMPL(simple_response)->status_line)
+    {
+        return NULL;
+    }
+    return AXIS2_HTTP_STATUS_LINE_GET_HTTP_VERSION(AXIS2_INTF_TO_IMPL(
+                simple_response)->status_line, env);
+}
+
+
+axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_status_line(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    if (NULL == AXIS2_INTF_TO_IMPL(simple_response)->status_line)
+    {
+        return NULL;
+    }
+    return AXIS2_HTTP_STATUS_LINE_TO_STRING(AXIS2_INTF_TO_IMPL(
+                simple_response)->status_line, env);
+}
+
+axis2_array_list_t *AXIS2_CALL
+axis2_http_simple_response_get_headers(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(simple_response)->header_group;
+}
+
+axis2_http_header_t *AXIS2_CALL
+axis2_http_simple_response_get_first_header(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    const axis2_char_t *str)
+{
+    axis2_http_simple_response_impl_t *simple_response_impl = NULL;
+    axis2_http_header_t *tmp_header = NULL;
+    axis2_char_t *tmp_name = NULL;
+    int i = 0;
+    int count = 0;
+    axis2_array_list_t *header_group = NULL;
+
+    AXIS2_ENV_CHECK(env, NULL);
+    AXIS2_PARAM_CHECK(env->error, str, NULL);
+
+    simple_response_impl = AXIS2_INTF_TO_IMPL(simple_response);
+    header_group = simple_response_impl->header_group;
+    if (NULL == simple_response_impl->header_group)
+    {
+        return NULL;
+    }
+    if (0 == AXIS2_ARRAY_LIST_SIZE(header_group, env))
+    {
+        return NULL;
+    }
+
+    count = AXIS2_ARRAY_LIST_SIZE(header_group, env);
+
+    for (i = 0; i < count; i++)
+    {
+        tmp_header = (axis2_http_header_t *)AXIS2_ARRAY_LIST_GET(header_group,
+                env, i);
+        tmp_name = AXIS2_HTTP_HEADER_GET_NAME(tmp_header, env);
+        if (0 == AXIS2_STRCASECMP(str, tmp_name))
+        {
+            return tmp_header;
+        }
+    }
+    return NULL;
+
+}
+
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_remove_headers(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    const axis2_char_t *str)
+{
+    axis2_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;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, str, AXIS2_FAILURE);
+
+    header_group = AXIS2_INTF_TO_IMPL(simple_response)->
+            header_group;
+    if (NULL == 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
+         * problem.
+         */
+        return AXIS2_SUCCESS;
+    }
+
+    count = AXIS2_ARRAY_LIST_SIZE(header_group, env);
+
+
+    for (i = 0; i < count; i++)
+    {
+        tmp_header = (axis2_http_header_t *)AXIS2_ARRAY_LIST_GET(header_group,
+                env, i);
+        tmp_name = AXIS2_HTTP_HEADER_GET_NAME(tmp_header, env);
+        if (0 == AXIS2_STRCASECMP(str, tmp_name))
+        {
+            AXIS2_HTTP_HEADER_FREE(tmp_header, env);
+            AXIS2_ARRAY_LIST_REMOVE(header_group, env, i);
+            break;
+        }
+    }
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_set_header(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    axis2_http_header_t *header)
+{
+    int i = 0;
+    int count = 0;
+    axis2_http_header_t *tmp_header = NULL;
+    axis2_char_t *tmp_name = NULL;
+    axis2_array_list_t *header_group = NULL;
+    axis2_http_simple_response_impl_t *simple_response_impl = NULL;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, header, AXIS2_FAILURE);
+
+    simple_response_impl = AXIS2_INTF_TO_IMPL
+            (simple_response);
+
+    if (NULL == simple_response_impl->header_group)
+    {
+        simple_response_impl->header_group = axis2_array_list_create(env, 10);
+        AXIS2_ARRAY_LIST_ADD(simple_response_impl->header_group, env, header);
+        return AXIS2_SUCCESS;
+    }
+
+    /* If a header with the same name exists
+     * search and remove the old header
+     */
+    header_group = AXIS2_INTF_TO_IMPL(simple_response)->header_group;
+
+    count = AXIS2_ARRAY_LIST_SIZE(header_group, env);
+    for (i = 0; i < count; i++)
+    {
+        tmp_header = (axis2_http_header_t *)AXIS2_ARRAY_LIST_GET(header_group,
+                env, i);
+        tmp_name = AXIS2_HTTP_HEADER_GET_NAME(tmp_header, env);
+        if (0 == AXIS2_STRCASECMP(AXIS2_HTTP_HEADER_GET_NAME(header, env),
+                tmp_name))
+        {
+            AXIS2_HTTP_HEADER_FREE(tmp_header, env);
+            AXIS2_ARRAY_LIST_REMOVE(header_group, env, i);
+            break;
+        }
+    }
+    AXIS2_ARRAY_LIST_ADD(simple_response_impl->header_group, env,
+            (void *)header);
+    return AXIS2_SUCCESS;
+}
+
+
+const axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_charset(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    axis2_http_header_t *tmp_header = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    tmp_header = axis2_http_simple_response_get_first_header
+            (simple_response, env, AXIS2_HTTP_HEADER_CONTENT_TYPE);
+    if (tmp_header)
+    {
+        axis2_char_t *value = AXIS2_HTTP_HEADER_GET_VALUE(tmp_header, env);
+        axis2_char_t *charset = (axis2_char_t *)strstr((char *)value,
+                (char *)AXIS2_HTTP_CHAR_SET_ENCODING);
+        if (charset)
+        {
+            charset = strchr((char *)charset, '=');
+            return charset;
+        }
+    }
+
+    return AXIS2_HTTP_DEFAULT_CONTENT_CHARSET;
+}
+
+
+axis2_ssize_t AXIS2_CALL
+axis2_http_simple_response_get_content_length(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    axis2_http_header_t *tmp_header = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    tmp_header = axis2_http_simple_response_get_first_header
+            (simple_response, env, AXIS2_HTTP_HEADER_CONTENT_LENGTH);
+    if (tmp_header)
+    {
+        return AXIS2_ATOI(AXIS2_HTTP_HEADER_GET_VALUE(tmp_header, env));
+    }
+    return -1;
+}
+
+
+const axis2_char_t *AXIS2_CALL
+axis2_http_simple_response_get_content_type(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    axis2_http_header_t *tmp_header = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    tmp_header =  axis2_http_simple_response_get_first_header
+            (simple_response, env, AXIS2_HTTP_HEADER_CONTENT_TYPE);
+    if (tmp_header)
+        return AXIS2_HTTP_HEADER_GET_VALUE(tmp_header, env);
+
+    return AXIS2_HTTP_HEADER_ACCEPT_TEXT_PLAIN;
+}
+
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_set_body_string(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    axis2_char_t *str)
+{
+    axis2_stream_t *body_stream = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, str, AXIS2_FAILURE);
+
+    body_stream = AXIS2_INTF_TO_IMPL(simple_response)->stream;
+    if (NULL == body_stream)
+    {
+        body_stream = axis2_stream_create_basic(env);
+        if (NULL == body_stream)
+        {
+            return AXIS2_FAILURE;
+        }
+        AXIS2_INTF_TO_IMPL(simple_response)->stream = body_stream;
+    }
+    AXIS2_STREAM_WRITE(body_stream, env, str, AXIS2_STRLEN(str));
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_http_simple_response_set_body_stream(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    axis2_stream_t *stream)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    /*
+     * We don't free the stream
+     * Problem in freeing is most of the time the stream doesn't belong
+     * to the http_simple_response
+     */
+    AXIS2_INTF_TO_IMPL(simple_response)->stream = stream;
+    return AXIS2_SUCCESS;
+}
+
+axis2_stream_t *AXIS2_CALL
+axis2_http_simple_response_get_body(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(simple_response)->stream;
+}
+
+
+axis2_ssize_t AXIS2_CALL
+axis2_http_simple_response_get_body_bytes(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    axis2_char_t **buffer)
+{
+    axis2_http_simple_response_impl_t *response_impl = NULL;
+    axis2_stream_t *tmp_stream = NULL;
+    int return_size = -1;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+
+    response_impl = AXIS2_INTF_TO_IMPL(simple_response);
+    if (NULL == response_impl->stream)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NULL_BODY, AXIS2_FAILURE);
+        return -1;
+    }
+    tmp_stream = axis2_stream_create_basic(env);
+    while (1)
+    {
+        int read = 0;
+        int write = 0;
+        /*   int READ_SIZE = 32; */
+        char buf[READ_SIZE];
+        read = AXIS2_STREAM_READ(response_impl->stream, env, buf, READ_SIZE);
+        if (read < 0)
+        {
+            break;
+        }
+        write = AXIS2_STREAM_WRITE(tmp_stream, env, buf, read);
+        if (read < (READ_SIZE - 1))
+        {
+            break;
+        }
+    }
+    return_size = AXIS2_STREAM_BASIC_GET_LEN(tmp_stream, env);
+
+    if (return_size > 0)
+    {
+        *buffer = (char *)AXIS2_MALLOC(env->allocator, sizeof(char) *
+                (return_size + 1));
+        return_size = AXIS2_STREAM_READ(tmp_stream, env, *buffer,
+                return_size + 1);
+    }
+    AXIS2_STREAM_FREE(tmp_stream, env);
+    return return_size;
+}
+
+axis2_bool_t AXIS2_CALL
+axis2_http_simple_response_contains_header(
+    axis2_http_simple_response_t *simple_response,
+    const axis2_env_t *env,
+    const axis2_char_t *name)
+{
+    axis2_char_t *header_name = NULL;
+    axis2_http_simple_response_impl_t *simple_response_impl = NULL;
+    int count = 0;
+    int i = 0;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE);
+    simple_response_impl = AXIS2_INTF_TO_IMPL(
+                simple_response);
+    if (NULL == simple_response_impl->header_group)
+    {
+        return AXIS2_FALSE;
+    }
+    count = AXIS2_ARRAY_LIST_SIZE(simple_response_impl->header_group, env);
+    if (0 == count)
+    {
+        return AXIS2_FALSE;
+    }
+
+    for (i = 0; i < count; i++)
+    {
+        header_name = AXIS2_HTTP_HEADER_GET_NAME((axis2_http_header_t *)
+                AXIS2_ARRAY_LIST_GET(simple_response_impl->header_group,
+                        env, i), env);
+        if (0 == AXIS2_STRCASECMP(name, header_name))
+            return AXIS2_TRUE;
+    }
+    return AXIS2_FALSE;
+}

Added: webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_status_line.c
URL: http://svn.apache.org/viewvc/webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_status_line.c?view=auto&rev=506856
==============================================================================
--- webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_status_line.c (added)
+++ webservices/axis2/scratch/c/dinesh/486/c/modules/core/transport/http/sender/http_status_line.c Mon Feb 12 20:53:21 2007
@@ -0,0 +1,291 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axis2_http_status_line.h>
+#include <axis2_string.h>
+#include <axis2_http_transport.h>
+#include <string.h>
+#include <axis2_types.h>
+
+/**
+ * @brief HTTP Status Line struct impl
+ * Axis2 HTTP Status Line impl
+ */
+
+typedef struct axis2_http_status_line_impl
+{
+    axis2_http_status_line_t status_line;
+    axis2_char_t *line;
+    axis2_char_t *http_version;
+    axis2_char_t *status_code;
+    axis2_char_t *reason_phrase;
+}
+axis2_http_status_line_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(status_line) \
+                    ((axis2_http_status_line_impl_t *)(status_line))
+
+/***************************** Function headers *******************************/
+int AXIS2_CALL
+axis2_http_status_line_get_status_code(
+    const axis2_http_status_line_t *status_line,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_status_line_get_http_version(
+    const axis2_http_status_line_t *status_line,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_status_line_get_reason_phrase(
+    const axis2_http_status_line_t *status_line,
+    const axis2_env_t *env);
+
+axis2_bool_t AXIS2_CALL
+axis2_http_status_line_starts_with_http(
+    axis2_http_status_line_t *status_line,
+    const axis2_env_t *env);
+
+axis2_char_t *AXIS2_CALL
+axis2_http_status_line_to_string(
+    axis2_http_status_line_t *status_line,
+    const axis2_env_t *env);
+
+axis2_status_t AXIS2_CALL
+axis2_http_status_line_free(
+    axis2_http_status_line_t *status_line,
+    const axis2_env_t *env);
+
+/***************************** End of function headers ************************/
+
+AXIS2_EXTERN axis2_http_status_line_t *AXIS2_CALL
+axis2_http_status_line_create(
+    const axis2_env_t *env,
+    const axis2_char_t *str)
+{
+    axis2_char_t *tmp_status_line = NULL;
+    axis2_char_t *reason_phrase = NULL;
+    axis2_char_t *status_code = NULL;
+    axis2_char_t *http_version = NULL;
+    int i = 0;
+    axis2_char_t *tmp = NULL;
+    axis2_http_status_line_impl_t *status_line_impl  = NULL;
+
+    AXIS2_ENV_CHECK(env, NULL);
+
+    status_line_impl = (axis2_http_status_line_impl_t *)AXIS2_MALLOC
+            (env->allocator, sizeof(
+                        axis2_http_status_line_impl_t));
+
+    if (NULL == status_line_impl)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    status_line_impl->status_line.ops = NULL;
+    status_line_impl->line = (axis2_char_t *)AXIS2_STRDUP(str, env);
+    status_line_impl->http_version = NULL;
+    status_line_impl->reason_phrase = NULL;
+    status_line_impl->status_code = NULL;
+
+    tmp = strstr(str, AXIS2_HTTP_CRLF);
+    if (NULL == tmp)
+    {
+        axis2_http_status_line_free((axis2_http_status_line_t *)
+                status_line_impl, env);
+        AXIS2_ERROR_SET(env->error,
+                AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE,
+                AXIS2_FAILURE);
+        return NULL;
+    }
+    i = tmp - str;
+    tmp_status_line = AXIS2_MALLOC(env->allocator,
+            i * sizeof(axis2_char_t) + 1);
+    if (NULL == tmp_status_line)
+    {
+        axis2_http_status_line_free((axis2_http_status_line_t *)
+                status_line_impl, env);
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    memcpy(tmp_status_line, str, i *sizeof(axis2_char_t));
+    tmp_status_line[i] = '\0';
+    tmp = tmp_status_line;
+
+    http_version = tmp;
+    tmp = strchr(tmp, ' ');
+    if (NULL == tmp)
+    {
+        AXIS2_FREE(env->allocator, tmp_status_line);
+        axis2_http_status_line_free((axis2_http_status_line_t *)
+                status_line_impl, env);
+        AXIS2_ERROR_SET(env->error,
+                AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE,
+                AXIS2_FAILURE);
+        return NULL;
+    }
+    *tmp++ = '\0';
+    status_code = tmp;
+    tmp = strchr(tmp, ' ');
+    if (NULL == tmp)
+    {
+        AXIS2_FREE(env->allocator, tmp_status_line);
+        axis2_http_status_line_free((axis2_http_status_line_t *)
+                status_line_impl, env);
+        AXIS2_ERROR_SET(env->error,
+                AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE,
+                AXIS2_FAILURE);
+        return NULL;
+    }
+    *tmp++ = '\0';
+    reason_phrase = tmp;
+    status_line_impl->http_version = (axis2_char_t *)
+            AXIS2_STRDUP(http_version, env);
+    status_line_impl->status_code = (axis2_char_t *)
+            AXIS2_STRDUP(status_code, env);
+    status_line_impl->reason_phrase = (axis2_char_t *)
+            AXIS2_STRDUP(reason_phrase, env);
+
+    if (NULL == status_line_impl->http_version ||
+            NULL == status_line_impl->reason_phrase)
+    {
+        AXIS2_FREE(env->allocator, tmp_status_line);
+        axis2_http_status_line_free((axis2_http_status_line_t *)
+                status_line_impl, env);
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    AXIS2_FREE(env->allocator, tmp_status_line);
+
+    status_line_impl->status_line.ops = AXIS2_MALLOC(env->allocator,
+            sizeof(axis2_http_status_line_ops_t));
+    if (NULL == status_line_impl->status_line.ops)
+    {
+        axis2_http_status_line_free((axis2_http_status_line_t *)
+                status_line_impl, env);
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    status_line_impl->status_line.ops->get_status_code =
+        axis2_http_status_line_get_status_code;
+    status_line_impl->status_line.ops->get_http_version =
+        axis2_http_status_line_get_http_version;
+    status_line_impl->status_line.ops->get_reason_phrase =
+        axis2_http_status_line_get_reason_phrase;
+    status_line_impl->status_line.ops->starts_with_http =
+        axis2_http_status_line_starts_with_http;
+    status_line_impl->status_line.ops->to_string =
+        axis2_http_status_line_to_string;
+    status_line_impl->status_line.ops->free =
+        axis2_http_status_line_free;
+    return &(status_line_impl->status_line);
+}
+
+axis2_status_t AXIS2_CALL
+axis2_http_status_line_free(
+    axis2_http_status_line_t *status_line,
+    const axis2_env_t *env)
+{
+    axis2_http_status_line_impl_t *status_line_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    status_line_impl = AXIS2_INTF_TO_IMPL(status_line);
+
+    if (status_line_impl->line)
+    {
+        AXIS2_FREE(env->allocator, status_line_impl->line);
+        status_line_impl->line = NULL;
+    }
+    if (status_line_impl->http_version)
+    {
+        AXIS2_FREE(env->allocator, status_line_impl->http_version);
+        status_line_impl->http_version = NULL;
+    }
+    if (status_line_impl->status_code)
+    {
+        AXIS2_FREE(env->allocator, status_line_impl->status_code);
+        status_line_impl->status_code = NULL;
+    }
+    if (status_line_impl->reason_phrase)
+    {
+        AXIS2_FREE(env->allocator, status_line_impl->reason_phrase);
+        status_line_impl->reason_phrase = NULL;
+    }
+    if (status_line->ops)
+        AXIS2_FREE(env->allocator, status_line->ops);
+
+    AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(status_line));
+    return AXIS2_SUCCESS;
+}
+
+int AXIS2_CALL
+axis2_http_status_line_get_status_code(
+    const axis2_http_status_line_t *status_line,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+    if (AXIS2_INTF_TO_IMPL(status_line)->status_code)
+    {
+        return AXIS2_ATOI(AXIS2_INTF_TO_IMPL(status_line)->status_code);
+    }
+    else
+    {
+        return AXIS2_CRITICAL_FAILURE;
+    }
+
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_http_status_line_get_http_version(
+    const axis2_http_status_line_t *status_line,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(status_line)->http_version;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_http_status_line_get_reason_phrase(
+    const axis2_http_status_line_t *status_line,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(status_line)->reason_phrase;
+}
+
+
+axis2_bool_t AXIS2_CALL
+axis2_http_status_line_starts_with_http(
+    axis2_http_status_line_t *status_line,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    if (0 == AXIS2_STRNCASECMP(AXIS2_INTF_TO_IMPL(status_line)->line, "HTTP", 4))
+    {
+        return AXIS2_TRUE;
+    }
+    return AXIS2_FALSE;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_http_status_line_to_string(
+    axis2_http_status_line_t *status_line,
+    const axis2_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+    return AXIS2_INTF_TO_IMPL(status_line)->line;
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org