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 na...@apache.org on 2008/09/16 11:43:35 UTC

svn commit: r695795 - in /webservices/axis2/trunk/c/src/core/transport/http/server/CGI: ./ axis2_cgi_main.c axis2_cgi_out_transport_info.c axis2_cgi_out_transport_info.h axis2_cgi_stream.c axis2_cgi_stream.h axis2_cgi_types.h

Author: nandika
Date: Tue Sep 16 02:43:34 2008
New Revision: 695795

URL: http://svn.apache.org/viewvc?rev=695795&view=rev
Log:
cgi transport module added

Added:
    webservices/axis2/trunk/c/src/core/transport/http/server/CGI/
    webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_main.c
    webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.c
    webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.h
    webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.c
    webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.h
    webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_types.h

Added: webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_main.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_main.c?rev=695795&view=auto
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_main.c (added)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_main.c Tue Sep 16 02:43:34 2008
@@ -0,0 +1,274 @@
+
+/*
+ * 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_cgi_out_transport_info.h"
+#include "axis2_cgi_stream.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <axutil_error_default.h>
+#include <axutil_log_default.h>
+#include <axutil_thread_pool.h>
+#include <axutil_types.h>
+#include <axutil_version.h>
+#include <axutil_file_handler.h>
+#include <axutil_url.h>
+#include <axutil_string.h>
+#include <platforms/axutil_platform_auto_sense.h>
+
+#include <axis2_engine.h>
+#include <axis2_conf_init.h>
+#include <axis2_http_transport_utils.h>
+
+axis2_char_t *axis2_cgi_default_url_prefix = "/cgi-bin/axis2.cgi/";
+
+/***************************** Function headers *******************************/
+
+void axis2_cgi_system_exit(
+    axutil_env_t * env,
+    int status);
+    
+void axis2_cgi_set_request_vars(
+    axis2_cgi_request_t *cgi_request);
+    
+axis2_status_t axis2_cgi_write_response(
+    const void *buffer,
+    unsigned int length);
+
+/***************************** End of function headers ************************/
+
+int
+main(
+    int argc,
+    char *argv[])
+{    
+    axutil_allocator_t *allocator = NULL;
+    axutil_env_t *env = NULL;
+    const axis2_char_t *repo_path;	
+    axis2_conf_ctx_t *conf_ctx;
+    axis2_cgi_request_t *cgi_request = NULL;
+    int content_length = 0;
+    axis2_char_t *request_url = NULL;
+    axutil_stream_t *request_body_stream = NULL;
+    axutil_stream_t *out_stream = NULL;
+    axis2_transport_in_desc_t *in_desc = NULL;
+    axis2_transport_out_desc_t *out_desc = NULL;
+    axis2_msg_ctx_t *msg_ctx = NULL;
+    axis2_bool_t processed = AXIS2_FALSE;
+    axis2_http_transport_in_t request;	
+    axis2_http_transport_out_t response;
+    axis2_http_header_t* http_header = NULL;
+    axutil_hash_t *headers = NULL;
+    axis2_char_t *axis2_cgi_url_prefix = NULL;
+    
+	if (!(repo_path = AXIS2_GETENV("AXIS2C_HOME")))
+	{
+		fprintf(stderr, "Error: AXIS2C_HOME environment variable not set!");
+		axis2_cgi_system_exit(env, -1);
+	}
+
+    allocator = axutil_allocator_init(NULL);
+    env = axutil_env_create(allocator);
+    
+    if (axutil_file_handler_access (repo_path, AXIS2_R_OK) != AXIS2_SUCCESS)
+    {
+		fprintf(stderr, "Error reading repository: %s\nPlease check AXIS2C_HOME var", repo_path);
+		axis2_cgi_system_exit(env, -1);
+    }
+    
+    // Set configuration
+
+	conf_ctx = axis2_build_conf_ctx(env, repo_path);
+	if (!conf_ctx)
+	{
+		fprintf(stderr, "Error: Configuration not builded propertly\n");
+	    axis2_cgi_system_exit(env, -1);
+	}
+		
+	axis2_http_transport_utils_transport_out_init(&response, env);
+    axis2_http_transport_utils_transport_in_init(&request, env);
+
+    // Get input info    
+    
+    cgi_request = AXIS2_MALLOC(allocator, sizeof(axis2_cgi_request_t));
+    axis2_cgi_set_request_vars(cgi_request);
+    
+    request_url = (axis2_char_t *) AXIS2_MALLOC(allocator, 
+           (7 + // "http://"
+		    strlen(cgi_request->server_name) + 
+			((strlen(cgi_request->server_port))?1:0) + // ":"
+		    strlen(cgi_request->server_port) +
+			strlen(cgi_request->script_name) + 
+            strlen(cgi_request->path_info) +
+            ((strlen(cgi_request->path_info))?1:0) + // "?"
+            strlen(cgi_request->query_string) ) * sizeof(axis2_char_t));
+            
+    request_url[0] = '\0';
+	
+	strcat(request_url, "http://");
+	strcat(request_url, cgi_request->server_name);
+	if (strlen(cgi_request->server_port)) strcat(request_url, ":");
+	strcat(request_url, cgi_request->server_port);
+    strcat(request_url, cgi_request->script_name); 
+    strcat(request_url, cgi_request->path_info);
+    if (strlen(cgi_request->query_string)) strcat(request_url, "?");
+    strcat(request_url, cgi_request->query_string);
+    
+    if (cgi_request->content_length) content_length = axutil_atoi(cgi_request->content_length);
+    else content_length = 0;
+    
+    // Set streams
+
+    out_stream = axutil_stream_create_basic(env);
+        
+	// Set message contexts
+        
+    out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf
+                                            (conf_ctx, env),
+                                            env, AXIS2_TRANSPORT_ENUM_HTTP);
+    in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf
+                                            (conf_ctx, env),
+                                            env, AXIS2_TRANSPORT_ENUM_HTTP);     
+
+    request.msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc);                                
+
+    axis2_msg_ctx_set_server_side(request.msg_ctx, env, AXIS2_TRUE);
+    axis2_msg_ctx_set_transport_out_stream(request.msg_ctx, env, out_stream);
+    axis2_msg_ctx_set_transport_headers(request.msg_ctx, env, NULL);
+
+    // Set request parameters
+
+    request.soap_action = cgi_request->soap_action;
+    request.in_stream = axutil_stream_create_cgi(env, content_length);
+    request.remote_ip = cgi_request->remote_addr;
+    request.content_length = content_length;
+    request.content_type = cgi_request->content_type;
+    request.request_uri = request_url;
+    request.svr_port = cgi_request->server_port;
+    request.accept_header = AXIS2_GETENV("HTTP_ACCEPT");
+    request.accept_language_header = AXIS2_GETENV("HTTP_ACCEPT_LANGUAGE");
+    request.accept_charset_header = AXIS2_GETENV("HTTP_ACCEPT_CHARSET");
+    request.request_url_prefix = (AXIS2_GETENV("AXIS2C_URL_PREFIX"))?
+                                  AXIS2_GETENV("AXIS2C_URL_PREFIX"):
+                                  axis2_cgi_default_url_prefix;
+            
+    if (axutil_strcasecmp(cgi_request->request_method, "POST") == 0)
+	{
+		request.request_method = AXIS2_HTTP_METHOD_POST;
+	}
+	else if (axutil_strcasecmp(cgi_request->request_method, "GET") == 0)
+	{
+		request.request_method = AXIS2_HTTP_METHOD_GET;
+	}
+	else if (axutil_strcasecmp(cgi_request->request_method, "HEAD") == 0)
+	{
+		request.request_method = AXIS2_HTTP_METHOD_HEAD;
+	}
+	else if (axutil_strcasecmp(cgi_request->request_method, "PUT") == 0)
+	{
+		request.request_method = AXIS2_HTTP_METHOD_PUT;
+	}
+	else if (axutil_strcasecmp(cgi_request->request_method, "DELETE") == 0)
+	{
+		request.request_method = AXIS2_HTTP_METHOD_DELETE;
+	}
+	
+	request.out_transport_info = axis2_cgi_out_transport_info_create(env, cgi_request);
+        
+    //Process request
+    fprintf(stderr, "ok\n");
+    axis2_http_transport_utils_process_request(env, conf_ctx, &request, &response);
+    fprintf(stderr, "ok\n");
+    //Send status
+    
+    fprintf(stdout, "Status: %d %s \r\n", response.http_status_code, response.http_status_code_name);
+
+    if (response.content_type)
+    {
+        fprintf(stdout, "Content-type: %s \r\n", response.content_type);
+    }
+    else if (strlen(axis2_cgi_out_transport_get_content(request.out_transport_info))
+               && axis2_cgi_out_transport_get_content(request.out_transport_info))
+    {
+        fprintf(stdout, "Content-type: %s \r\n", axis2_cgi_out_transport_get_content(request.out_transport_info));
+    }
+    
+    fprintf(stdout, "\r\n"); // End of headers for server
+    
+    // Write data body
+    if (!axis2_cgi_write_response(response.response_data, response.response_data_length))
+    {
+        fprintf(stderr, "Error writing output data\n");
+    }
+        
+    axis2_http_transport_utils_transport_in_uninit(&request, env);
+	axis2_http_transport_utils_transport_out_uninit(&response, env);
+	
+	return 0;
+}
+
+axis2_status_t axis2_cgi_write_response(
+    const void *buffer,
+    unsigned int length)
+{
+    if (buffer && length)
+    {
+        unsigned int completed = 0;
+        unsigned int written = 0;
+        
+        while (completed < length)
+        {
+            written = fwrite(buffer, sizeof(char), length - completed, stdout);
+            if (written < 0) return AXIS2_FALSE;
+            completed += written;
+        }
+    }
+    return AXIS2_TRUE;
+}
+
+void
+axis2_cgi_set_request_vars(
+    axis2_cgi_request_t *cgi_request)
+{
+    cgi_request->server_name = (AXIS2_GETENV("SERVER_NAME"))?AXIS2_GETENV("SERVER_NAME"):"";
+	cgi_request->script_name = (AXIS2_GETENV("SCRIPT_NAME"))?AXIS2_GETENV("SCRIPT_NAME"):"";
+	cgi_request->path_info = (AXIS2_GETENV("PATH_INFO"))?AXIS2_GETENV("PATH_INFO"):"";
+	cgi_request->server_port = (AXIS2_GETENV("SERVER_PORT"))?AXIS2_GETENV("SERVER_PORT"):"";
+	cgi_request->server_protocol = (AXIS2_GETENV("SERVER_PROTOCOL"))?AXIS2_GETENV("SERVER_PROTOCOL"):"";
+	cgi_request->content_length = (AXIS2_GETENV("CONTENT_LENGTH"))?AXIS2_GETENV("CONTENT_LENGTH"):"";
+	cgi_request->content_type = (AXIS2_GETENV("CONTENT_TYPE"))?AXIS2_GETENV("CONTENT_TYPE"):"";
+	cgi_request->request_method = (AXIS2_GETENV("REQUEST_METHOD"))?AXIS2_GETENV("REQUEST_METHOD"):"";
+	cgi_request->remote_addr = (AXIS2_GETENV("REMOTE_ADDR"))?AXIS2_GETENV("REMOTE_ADDR"):"";
+	cgi_request->soap_action = (AXIS2_GETENV("HTTP_SOAPACTION"))?AXIS2_GETENV("HTTP_SOAPACTION"):NULL;
+	cgi_request->query_string = (AXIS2_GETENV("QUERY_STRING"))?AXIS2_GETENV("QUERY_STRING"):"";
+}
+
+void
+axis2_cgi_system_exit(
+    axutil_env_t * env,
+    int status)
+{
+    axutil_allocator_t *allocator = NULL;
+	
+    if (env)
+    {
+        allocator = env->allocator;
+        axutil_env_free(env);
+    }
+    exit(status);
+}

Added: webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.c?rev=695795&view=auto
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.c (added)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.c Tue Sep 16 02:43:34 2008
@@ -0,0 +1,162 @@
+
+/*
+ * 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_cgi_out_transport_info.h"
+#include <axutil_string.h>
+#include <axis2_http_transport.h>
+
+/**
+ * @brief CIG Out transport info impl structure
+ * Axis2 cgi_out_transport_info_impl
+ */
+
+typedef struct axis2_cgi_out_transport_info_s
+{
+    axis2_http_out_transport_info_t out_transport_info;
+    axis2_cgi_request_t *request;
+    axis2_char_t *encoding;
+} axis2_cgi_out_transport_info_t;   
+
+#define AXIS2_INTF_TO_IMPL(out_transport_info) \
+                ((axis2_cgi_out_transport_info_t *)(out_transport_info))
+               
+void AXIS2_CALL
+axis2_cgi_out_transport_info_free(
+    axis2_http_out_transport_info_t * info,
+    const axutil_env_t * env)
+{
+    axis2_cgi_out_transport_info_t *info_impl = NULL;
+    AXIS2_ENV_CHECK(env, void);
+
+    info_impl = AXIS2_INTF_TO_IMPL(info);
+    
+    info_impl->request = NULL; // doesn't belong here so no need to free it here
+    if (info_impl->encoding)
+    {
+        AXIS2_FREE(env->allocator, info_impl->encoding);
+        info_impl->encoding = NULL;
+    }
+
+    AXIS2_FREE(env->allocator, info_impl);
+    return;
+}
+
+void AXIS2_CALL
+axis2_cgi_out_transport_info_free_void_arg(
+    void *transport_info,
+    const axutil_env_t * env)
+{
+    axis2_http_out_transport_info_t *transport_info_l = NULL;
+
+    AXIS2_ENV_CHECK(env, void);
+    transport_info_l = (axis2_http_out_transport_info_t *) transport_info;
+    axis2_http_out_transport_info_free(transport_info_l, env);
+    return;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_cgi_out_transport_info_set_content_type(
+    axis2_http_out_transport_info_t *info,
+    const axutil_env_t *env,
+    const axis2_char_t *content_type)
+{
+    axis2_cgi_out_transport_info_t *info_impl = NULL;
+
+    axis2_char_t *temp1 = NULL;
+    axis2_char_t *temp2 = NULL;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, content_type, AXIS2_FAILURE);
+    info_impl = AXIS2_INTF_TO_IMPL(info);
+    if (info_impl->encoding)
+    {
+        temp1 = axutil_stracat(env, content_type, ";charset=");
+        temp2 = axutil_stracat(env, temp1, info_impl->encoding);
+        info_impl->request->content_type = axutil_strdup(env, temp2);
+        AXIS2_FREE(env->allocator, temp1);
+        AXIS2_FREE(env->allocator, temp2);
+    }
+    else
+    {
+        info_impl->request->content_type = axutil_strdup(env, content_type);
+    }
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_cgi_out_transport_info_set_char_encoding(
+    axis2_http_out_transport_info_t * info,
+    const axutil_env_t * env,
+    const axis2_char_t * encoding)
+{    
+    axis2_cgi_out_transport_info_t *info_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, encoding, AXIS2_FAILURE);
+
+    info_impl = AXIS2_INTF_TO_IMPL(info);
+    
+    if (info_impl->encoding)
+    {
+        AXIS2_FREE(env->allocator, info_impl->encoding);
+    }
+    info_impl->encoding = axutil_strdup(env, encoding);
+    
+    return AXIS2_SUCCESS;
+}
+
+axis2_http_out_transport_info_t *AXIS2_CALL
+axis2_cgi_out_transport_info_create(
+    const axutil_env_t * env,
+    axis2_cgi_request_t * request)
+{
+    axis2_cgi_out_transport_info_t *info = NULL;
+    axis2_http_out_transport_info_t *out_transport_info = NULL;
+
+    AXIS2_ENV_CHECK(env, NULL);
+
+    info = (axis2_cgi_out_transport_info_t *) AXIS2_MALLOC
+        (env->allocator, sizeof(axis2_cgi_out_transport_info_t));
+
+    if (!info)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    info->request = request;
+    info->encoding = NULL;
+
+    out_transport_info = &(info->out_transport_info);
+
+    axis2_http_out_transport_info_set_char_encoding_func(out_transport_info,
+                                                         env,
+                                                         axis2_cgi_out_transport_info_set_char_encoding);
+    axis2_http_out_transport_info_set_content_type_func(out_transport_info, env,
+                                                        axis2_cgi_out_transport_info_set_content_type);
+
+    return out_transport_info;
+}
+
+axis2_char_t *
+axis2_cgi_out_transport_get_content(
+    axis2_http_out_transport_info_t * info)
+{
+    axis2_cgi_out_transport_info_t *info_impl = NULL;
+    info_impl = AXIS2_INTF_TO_IMPL(info);
+    return info_impl->request->content_type;
+}
+

Added: webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.h?rev=695795&view=auto
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.h (added)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_out_transport_info.h Tue Sep 16 02:43:34 2008
@@ -0,0 +1,62 @@
+
+/*
+ * 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.
+ */
+
+#ifndef AXIS2_CGI_OUT_TRANSPORT_INFO_H
+#define AXIS2_CGI_OUT_TRANSPORT_INFO_H
+
+/**
+ * @ingroup axis2_core_transport_http
+ * @{
+ */
+
+/**
+ * @file axis2_cgi_out_transport_info.h
+ * @brief axis2 CGI Out Transport Info
+ */
+
+#include "axis2_cgi_types.h"
+#include <axis2_http_out_transport_info.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+    axis2_http_out_transport_info_t *AXIS2_CALL
+
+    axis2_cgi_out_transport_info_create(
+        const axutil_env_t * env,
+        axis2_cgi_request_t * request);
+
+    /**
+     * Free http_out_transport_info passed as void pointer. This will be
+     * cast into appropriate type and then pass the cast object
+     * into the http_out_transport_info structure's free method
+     */
+    void AXIS2_CALL
+    axis2_cgi_out_transport_info_free_void_arg(
+        void *transport_info,
+        const axutil_env_t * env);
+
+    axis2_char_t *axis2_cgi_out_transport_get_content(
+        axis2_http_out_transport_info_t * out_transport_info);
+
+#ifdef __cplusplus
+}
+#endif
+#endif                          /* AXIS2_SGI_OUT_TRANSPORT_INFO_H */

Added: webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.c?rev=695795&view=auto
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.c (added)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.c Tue Sep 16 02:43:34 2008
@@ -0,0 +1,166 @@
+
+/*
+ * 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 <string.h>
+#include <stdlib.h>
+#include "axis2_cgi_stream.h"
+
+/**
+ * @brief Stream struct impl
+ * Streaming mechanisms for cgi
+ */
+
+typedef struct cgi_stream_impl
+{
+    axutil_stream_t stream;
+    axutil_stream_type_t stream_type;
+    unsigned int cur_pos;
+    unsigned int content_length;
+}
+cgi_stream_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(stream) ((cgi_stream_impl_t *)(stream))
+
+axutil_stream_type_t AXIS2_CALL cgi_stream_get_type(
+    axutil_stream_t * stream,
+    const axutil_env_t * env);
+
+int AXIS2_CALL cgi_stream_write(
+    axutil_stream_t * stream,
+    const axutil_env_t * env,
+    const void *buffer,
+    size_t count);
+
+int AXIS2_CALL cgi_stream_read(
+    axutil_stream_t * stream,
+    const axutil_env_t * env,
+    void *buffer,
+    size_t count);
+
+int AXIS2_CALL cgi_stream_skip(
+    axutil_stream_t * stream,
+    const axutil_env_t * env,
+    int count);
+
+int AXIS2_CALL cgi_stream_get_char(
+    axutil_stream_t * stream,
+    const axutil_env_t * env);
+
+axutil_stream_t *AXIS2_CALL
+axutil_stream_create_cgi(
+    const axutil_env_t * env,
+	unsigned int content_length)
+{
+    cgi_stream_impl_t *stream_impl = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+	AXIS2_PARAM_CHECK(env->error, content_length, NULL);
+
+    stream_impl =
+        (cgi_stream_impl_t *) AXIS2_MALLOC(env->allocator,
+                                           sizeof(cgi_stream_impl_t));
+
+    if (!stream_impl)
+    {
+        return NULL;
+    }
+    stream_impl->cur_pos = 0;
+	stream_impl->content_length = content_length;
+    stream_impl->stream_type = AXIS2_STREAM_MANAGED;
+
+    axutil_stream_set_read(&(stream_impl->stream), env, cgi_stream_read);
+    axutil_stream_set_write(&(stream_impl->stream), env, cgi_stream_write);
+    axutil_stream_set_skip(&(stream_impl->stream), env, cgi_stream_skip);
+
+    return &(stream_impl->stream);
+}
+int AXIS2_CALL
+cgi_stream_read(
+    axutil_stream_t * stream,
+    const axutil_env_t * env,
+    void *buffer,
+    size_t count)
+{
+    void *temp_buff = NULL;
+    unsigned int data_to_read = 0;
+    unsigned int read_bytes = 0;
+	axis2_bool_t ret_ok = AXIS2_TRUE;
+
+    cgi_stream_impl_t *stream_impl = NULL;
+    char *temp = NULL;
+
+    AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+    stream_impl = (cgi_stream_impl_t *) stream;
+	
+	if (count < stream_impl->content_length)
+	{
+		read_bytes = fread(buffer, sizeof(char), count, stdin);
+	}
+	else
+	{
+		read_bytes = fread(buffer, sizeof(char), stream_impl->content_length, stdin);
+	}
+
+    return read_bytes;
+}
+
+int AXIS2_CALL
+cgi_stream_write(
+    axutil_stream_t * stream,
+    const axutil_env_t * env,
+    const void *buf,
+    size_t count)
+{	
+	// Cannot write on cgi stdin, explicitly an input stream
+
+	return -1;
+}
+
+int AXIS2_CALL
+cgi_stream_skip(
+    axutil_stream_t * stream,
+    const axutil_env_t * env,
+    int count)
+{
+	cgi_stream_impl_t *stream_impl = NULL;
+    int skipped = -1;
+    AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+    stream_impl = AXIS2_INTF_TO_IMPL(stream);
+	
+	if (fseek(stdin, count, SEEK_CUR)==0) skipped = count;
+    return skipped;
+}
+
+int AXIS2_CALL
+cgi_stream_get_char(
+    axutil_stream_t * stream,
+    const axutil_env_t * env)
+{
+    int ret = -1;
+    AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+
+    return ret;
+}
+
+axutil_stream_type_t AXIS2_CALL
+cgi_stream_get_type(
+    axutil_stream_t * stream,
+    const axutil_env_t * env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+    return AXIS2_INTF_TO_IMPL(stream)->stream_type;
+}

Added: webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.h?rev=695795&view=auto
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.h (added)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_stream.h Tue Sep 16 02:43:34 2008
@@ -0,0 +1,44 @@
+
+/*
+ * 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.
+ */
+
+#ifndef CGI_STREAM_H
+#define CGI_STREAM_H
+
+#include <axis2_const.h>
+#include <axis2_defines.h>
+#include <axutil_env.h>
+#include <axutil_stream.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+    /** brief Constructor for creating CGI stream
+      * @return axutil_stream (CGI)
+      */
+    axutil_stream_t *AXIS2_CALL
+    axutil_stream_create_cgi(
+        const axutil_env_t * env,
+		unsigned int content_length);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif                          /* CGI_STREAM_H */

Added: webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_types.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_types.h?rev=695795&view=auto
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_types.h (added)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/CGI/axis2_cgi_types.h Tue Sep 16 02:43:34 2008
@@ -0,0 +1,34 @@
+
+/*
+ * 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_const.h>
+
+typedef struct axis2_cgi_request
+{
+    axis2_char_t *server_name;
+    axis2_char_t *server_port;
+    axis2_char_t *script_name;
+    axis2_char_t *path_info;
+    axis2_char_t *server_protocol;
+    axis2_char_t *content_length;
+    axis2_char_t *content_type;
+    axis2_char_t *request_method;
+    axis2_char_t *remote_addr;
+    axis2_char_t *soap_action;
+    axis2_char_t *query_string;
+} axis2_cgi_request_t;