|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58191 - in sandbox/SOC/2007/cgi/branches/pickmeup: boost/cgi boost/cgi/acgi boost/cgi/cgi boost/cgi/common boost/cgi/detail libs/cgi/build/msvc/9.0/Boost.CGI
From: lists.drrngrvy_at_[hidden]
Date: 2009-12-06 10:46:19
Author: drrngrvy
Date: 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
New Revision: 58191
URL: http://svn.boost.org/trac/boost/changeset/58191
Log:
Merging acgi and cgi, step 1. Still to remove acgi elements, rewrite docs and remove acgi examples.
Added:
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/acceptor.hpp (contents, props changed)
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request.hpp (contents, props changed)
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_impl.hpp (contents, props changed)
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_service.hpp (contents, props changed)
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/service.hpp (contents, props changed)
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/has_hidden_io_service.hpp (contents, props changed)
Binary files modified:
sandbox/SOC/2007/cgi/branches/pickmeup/libs/cgi/build/msvc/9.0/Boost.CGI/Boost.CGI.suo
Text files modified:
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi/request_impl.hpp | 34 +++++
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi/request_service.hpp | 226 +++++++++++++++++++++++++++++++++++++++
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_request.hpp | 32 ++---
sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/basic_io_object.hpp | 14 +
4 files changed, 273 insertions(+), 33 deletions(-)
Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi/request_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi/request_impl.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi/request_impl.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -22,24 +22,48 @@
namespace acgi {
class request_impl
- : public detail::cgi_request_impl_base<connections::async_stdio>
{
public:
- typedef ::BOOST_CGI_NAMESPACE::acgi::service protocol_service_type;
- typedef protocol_service_type::protocol_type protocol_type;
- typedef connections::async_stdio connection_type;
+ typedef ::BOOST_CGI_NAMESPACE::common::map map_type;
+ typedef ::BOOST_CGI_NAMESPACE::acgi::service protocol_service_type;
+ typedef protocol_service_type::protocol_type protocol_type;
+ typedef connections::async_stdio connection_type;
typedef
::BOOST_CGI_NAMESPACE::common::basic_client<
connection_type, common::tags::acgi
>
client_type;
+ typedef connection_type::pointer conn_ptr;
+ /// Constructor
request_impl()
- : detail::cgi_request_impl_base<connection_type>()
+ : stdin_parsed_(false)
+ , stdin_data_read_(false)
+ , stdin_bytes_left_(-1)
+ , http_status_(common::http::ok)
+ , request_status_(common::unloaded)
{
}
protocol_service_type* service_;
+
+ bool stdin_parsed() { return stdin_parsed_; }
+ common::http::status_code& http_status() { return http_status_; }
+ common::request_status& status() { return request_status_; }
+
+ conn_ptr& connection() { return connection_; }
+
+ bool stdin_parsed_;
+ bool stdin_data_read_;
+ std::size_t stdin_bytes_left_;
+
+ private:
+
+ common::http::status_code http_status_;
+ common::request_status request_status_;
+
+ conn_ptr connection_;
+
};
} // namespace acgi
Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi/request_service.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -18,19 +18,83 @@
#include "boost/cgi/detail/service_base.hpp"
#include "boost/cgi/detail/extract_params.hpp"
#include "boost/cgi/connections/async_stdio.hpp"
-#include "boost/cgi/detail/cgi_service_impl_base.hpp"
+
+#include <boost/bind.hpp>
+#include <boost/assert.hpp>
+#include <boost/regex.hpp>
+#include <boost/tokenizer.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/algorithm/string/find.hpp>
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/map.hpp"
+#include "boost/cgi/basic_client.hpp"
+#include "boost/cgi/common/is_async.hpp"
+#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/common/form_part.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+#include "boost/cgi/common/form_parser.hpp"
+#include "boost/cgi/common/request_base.hpp"
+#include "boost/cgi/common/parse_options.hpp"
+#include "boost/cgi/common/request_status.hpp"
+#include "boost/cgi/detail/extract_params.hpp"
+#include "boost/cgi/detail/save_environment.hpp"
BOOST_CGI_NAMESPACE_BEGIN
namespace acgi {
class request_service
- : public cgi_service_impl_base<acgi::request_impl>
+ : public common::request_base<acgi::request_impl>
, public detail::service_base<request_service>
{
public:
- typedef request_service type;
- typedef common::tags::acgi protocol_type;
- typedef acgi::service protocol_service_type;
+ typedef common::tags::acgi protocol_type;
+ typedef acgi::service protocol_service_type;
+ typedef acgi::request_impl impl_type;
+ typedef acgi::request_service self_type;
+ typedef common::request_base<self_type> base_type;
+ typedef ::BOOST_CGI_NAMESPACE::common::map map_type;
+
+ struct implementation_type
+ : impl_type
+ , base_type::impl_base
+ {
+ typedef impl_type::client_type client_type;
+ typedef detail::form_parser form_parser_type;
+
+ implementation_type()
+ : fp_(NULL)
+ {
+ }
+
+ client_type client_;
+
+ // The number of characters left to read (ie. "content_length -
+ // bytes_read")
+ std::size_t characters_left_;
+
+ boost::scoped_ptr<form_parser_type> fp_;
+ };
+
+ template<typename Service>
+ struct callback_functor
+ {
+ callback_functor(implementation_type& impl, Service* service)
+ : impl_(impl)
+ , service_(service)
+ {
+ }
+
+ std::size_t operator()(boost::system::error_code& ec)
+ {
+ return service_->read_some(impl_, ec);
+ }
+
+ private:
+ implementation_type& impl_;
+ Service* service_;
+ };
+
request_service(common::io_service& ios)
: detail::service_base<request_service>(ios)
@@ -56,6 +120,158 @@
{
impl.service_ = &ps;
}
+
+ /// Return if the request is still open
+ /**
+ * For CGI, this always returns true. However, in the case that a
+ * "Location: xxx" header is sent and the header is terminated, the
+ * request can be taken to be 'closed'.
+ */
+ bool is_open(implementation_type& impl)
+ {
+ return impl.status() >= common::accepted
+ && impl.status() <= common::aborted;
+ }
+
+ /// Return the connection associated with the request
+ implementation_type::client_type&
+ client(implementation_type& impl)
+ {
+ return impl.client_;
+ }
+
+ void clear(implementation_type& impl) { }
+
+ int request_id(implementation_type& impl) { return 1; }
+
+ // **FIXME** should return error_code
+ int close(implementation_type& impl, common::http::status_code& http_s
+ , int status, boost::system::error_code& ec)
+ {
+ impl.status() = common::closed;
+ impl.http_status() = http_s;
+ return status;
+ }
+
+ /// Synchronously read/parse the request data
+ boost::system::error_code&
+ load(implementation_type& impl, common::parse_options parse_opts
+ , boost::system::error_code& ec)
+ {
+ if (parse_opts & common::parse_env)
+ {
+ if (read_env_vars(impl, ec)) // returns an error_code
+ return ec;
+ }
+
+ std::string const& cl = env_vars(impl.vars_)["CONTENT_LENGTH"];
+ impl.characters_left_
+ = cl.empty() ? 0 : boost::lexical_cast<std::size_t>(cl);
+ impl.client_.bytes_left()
+ = impl.characters_left_;
+ std::string const& request_method
+ = env_vars(impl.vars_)["REQUEST_METHOD"];
+
+ if ((request_method == "GET" || request_method == "HEAD")
+ && parse_opts > common::parse_env
+ && parse_opts & common::parse_get_only)
+ {
+ parse_get_vars(impl, ec);
+ }
+ else
+ if (request_method == "POST"
+ && (parse_opts & common::parse_post_only))
+ {
+ parse_post_vars(impl, ec);
+ }
+
+ if (ec) return ec;
+
+ if (parse_opts & common::parse_cookie_only)
+ {
+ if (parse_cookie_vars(impl, ec)) // returns an error_code
+ return ec;
+ }
+
+ set_status(impl, common::loaded);
+
+ return ec;
+ }
+
+ common::role_type
+ get_role(implementation_type& impl)
+ {
+ return common::responder;
+ }
+
+ /// Set the http status (this does nothing for aCGI)
+ void set_status(
+ implementation_type& impl, common::http::status_code&)
+ {
+ // **FIXME**
+ }
+
+ /// Set the request status
+ void set_status(
+ implementation_type& impl, common::request_status status)
+ {
+ impl.status() = status;
+ }
+
+ std::size_t
+ read_some(implementation_type& impl, boost::system::error_code& ec)
+ {
+ return impl.client_.read_some(impl.prepare(64), ec);
+ }
+
+ protected:
+ /// Read the environment variables into an internal map.
+ template<typename RequestImpl>
+ boost::system::error_code
+ read_env_vars(RequestImpl& impl, boost::system::error_code& ec)
+ {
+ // Only call this once.
+ if (!impl.env_parsed_)
+ detail::save_environment(env_vars(impl.vars_));
+ impl.env_parsed_ = true;
+ return ec;
+ }
+
+ /// Read and parse the cgi POST meta variables (greedily)
+ template<typename RequestImpl>
+ boost::system::error_code
+ parse_post_vars(RequestImpl& impl, boost::system::error_code& ec)
+ {
+ // **FIXME** use callback_functor<> in form_parser instead.
+ std::size_t& bytes_left (impl.client_.bytes_left_);
+ std::size_t bytes_read (0);
+ do {
+ bytes_read = read_some(impl, ec);
+ bytes_left -= bytes_read;
+ } while (!ec && bytes_left);
+
+ if (!impl.fp_)
+ // Construct a form_parser instance.
+ impl.fp_.reset(new typename implementation_type::form_parser_type());
+
+ // Create a context for this request.
+ typename implementation_type::form_parser_type::context
+ context
+ = { env_vars(impl.vars_)["CONTENT_TYPE"]
+ , impl.post_buffer_
+ , impl.form_parts_
+ , impl.client_.bytes_left_
+ , post_vars(impl.vars_)
+ , callback_functor<self_type>(impl, this)
+ , impl.stdin_parsed_
+ , env_vars(impl.vars_)["REMOTE_ADDR"]
+ };
+
+ // Parse the current request.
+ impl.fp_->parse(context, ec);
+
+ return ec;
+ }
};
} // namespace acgi
Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_request.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_request.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -37,6 +37,7 @@
#include "boost/cgi/detail/basic_io_object.hpp"
#include "boost/cgi/detail/throw_error.hpp"
#include "boost/cgi/detail/protocol_traits.hpp"
+#include "boost/cgi/common/has_hidden_io_service.hpp"
#ifndef BOOST_CGI_POST_MAX
/// Restrict POST data to less than 7MB per request.
@@ -82,27 +83,18 @@
basic_request<
RequestService, ProtocolService
, Allocator
- > self_type;
- typedef ::BOOST_CGI_NAMESPACE::common::map map_type;
- typedef RequestService service_type;
- typedef typename service_type::protocol_type protocol_type;
- typedef ProtocolService protocol_service_type;
- typedef boost::shared_ptr<self_type> pointer;
- typedef typename RequestService::implementation_type implementation_type;
- typedef typename implementation_type::char_type char_type;
- typedef typename implementation_type::string_type string_type;
- typedef typename implementation_type::client_type client_type;
- typedef typename implementation_type::buffer_type buffer_type;
+ > self_type;
+ typedef ::BOOST_CGI_NAMESPACE::common::map map_type;
+ typedef RequestService service_type;
+ typedef typename service_type::protocol_type protocol_type;
+ typedef ProtocolService protocol_service_type;
+ typedef boost::shared_ptr<self_type> pointer;
+ typedef typename service_type::implementation_type implementation_type;
+ typedef typename implementation_type::char_type char_type;
+ typedef typename implementation_type::string_type string_type;
+ typedef typename implementation_type::client_type client_type;
+ typedef typename implementation_type::buffer_type buffer_type;
- /*
- boost::enable_if<
- boost::type_traits::is_same<
- typename RequestService::protocol_type,
- ::BOOST_CGI_NAMESPACE::common::tags::acgi
- >
- > ios;
- */
-
/// A proxy class to provide access to the data maps as member variables.
/**
* This wraps the underlying data map and exposes a std::map-like
Added: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/acceptor.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/acceptor.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -0,0 +1,32 @@
+// -- acgi/acceptor.hpp --
+//
+// Copyright (c) Darren Garvey 2007.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_ACGI_ACCEPTOR_HPP_INCLUDED__
+#define CGI_ACGI_ACCEPTOR_HPP_INCLUDED__
+
+#include "boost/cgi/detail/push_options.hpp"
+
+#include "boost/cgi/basic_request_acceptor.hpp"
+#include "boost/cgi/acgi/request_acceptor_service.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace acgi {
+
+ /// Typedef for common usage (ACGI)
+ typedef
+ ::BOOST_CGI_NAMESPACE::common::basic_request_acceptor<
+ acgi_request_acceptor_service<>
+ >
+ acceptor;
+
+ } // namespace acgi
+BOOST_CGI_NAMESPACE_END
+
+#include "boost/cgi/detail/pop_options.hpp"
+
+#endif // CGI_ACGI_ACCEPTOR_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -0,0 +1,38 @@
+// -- cgi/request.hpp --
+//
+// Copyright (c) Darren Garvey 2007-2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_CGI_REQUEST_HPP_INCLUDED__
+#define CGI_CGI_REQUEST_HPP_INCLUDED__
+
+#include "boost/cgi/detail/push_options.hpp"
+
+#include "boost/cgi/detail/protocol_traits.hpp"
+#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/cgi/service.hpp"
+#include "boost/cgi/cgi/request_impl.hpp"
+#include "boost/cgi/cgi/request_service.hpp"
+#include "boost/cgi/fwd/basic_request_fwd.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+ typedef
+ common::basic_request<
+ ::BOOST_CGI_NAMESPACE::cgi_request_service,
+ ::BOOST_CGI_NAMESPACE::cgi_service
+ >
+ cgi_request;
+
+ typedef cgi_request request;
+
+BOOST_CGI_NAMESPACE_END
+
+#include "boost/cgi/basic_request.hpp"
+
+#include "boost/cgi/detail/pop_options.hpp"
+
+#endif // CGI_CGI_REQUEST_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_impl.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_impl.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -0,0 +1,72 @@
+// -- cgi_request_impl.hpp --
+//
+// Copyright (c) Darren Garvey 2007-2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_CGI_REQUEST_IMPL_HPP_INCLUDED__
+#define CGI_CGI_REQUEST_IMPL_HPP_INCLUDED__
+
+#include "boost/cgi/detail/push_options.hpp"
+
+#include "boost/cgi/cgi/service.hpp"
+#include "boost/cgi/basic_client.hpp"
+#include "boost/cgi/connections/async_stdio.hpp"
+
+// Make this ProtocolService-independent
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+ class cgi_request_impl
+ {
+ public:
+ typedef ::BOOST_CGI_NAMESPACE::common::map map_type;
+ typedef ::BOOST_CGI_NAMESPACE::cgi::service protocol_service_type;
+ typedef protocol_service_type::protocol_type protocol_type;
+ typedef connections::async_stdio connection_type;
+ typedef
+ ::BOOST_CGI_NAMESPACE::common::basic_client<
+ connection_type, common::tags::cgi
+ >
+ client_type;
+ typedef connection_type::pointer conn_ptr;
+
+ /// Constructor
+ cgi_request_impl()
+ : stdin_parsed_(false)
+ , stdin_data_read_(false)
+ , stdin_bytes_left_(-1)
+ , http_status_(common::http::ok)
+ , request_status_(common::unloaded)
+ {
+ }
+
+ protocol_service_type* service_;
+
+ bool stdin_parsed() { return stdin_parsed_; }
+ common::http::status_code& http_status() { return http_status_; }
+ common::request_status& status() { return request_status_; }
+
+ conn_ptr& connection() { return connection_; }
+
+ bool stdin_parsed_;
+ bool stdin_data_read_;
+ std::size_t stdin_bytes_left_;
+
+ private:
+
+ common::http::status_code http_status_;
+ common::request_status request_status_;
+
+ conn_ptr connection_;
+
+ };
+
+BOOST_CGI_NAMESPACE_END
+
+#include "boost/cgi/detail/pop_options.hpp"
+
+#endif // CGI_CGI_REQUEST_IMPL_HPP_INCLUDED__
+
Added: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_service.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_service.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -0,0 +1,280 @@
+// -- cgi_service_impl.hpp --
+//
+// Copyright (c) Darren Garvey 2007-2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_CGI_SERVICE_IMPL_HPP_INCLUDED__
+#define CGI_CGI_SERVICE_IMPL_HPP_INCLUDED__
+
+#include "boost/cgi/detail/push_options.hpp"
+
+#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/common/map.hpp"
+#include "boost/cgi/acgi/request_impl.hpp"
+#include "boost/cgi/import/io_service.hpp"
+#include "boost/cgi/detail/service_base.hpp"
+#include "boost/cgi/detail/extract_params.hpp"
+#include "boost/cgi/connections/async_stdio.hpp"
+
+#include <boost/bind.hpp>
+#include <boost/assert.hpp>
+#include <boost/regex.hpp>
+#include <boost/tokenizer.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/algorithm/string/find.hpp>
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/map.hpp"
+#include "boost/cgi/basic_client.hpp"
+#include "boost/cgi/common/is_async.hpp"
+#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/common/form_part.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+#include "boost/cgi/common/form_parser.hpp"
+#include "boost/cgi/common/request_base.hpp"
+#include "boost/cgi/common/parse_options.hpp"
+#include "boost/cgi/common/request_status.hpp"
+#include "boost/cgi/detail/extract_params.hpp"
+#include "boost/cgi/detail/save_environment.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+ class cgi_request_service
+ : public common::request_base<cgi_request_impl>
+ , public detail::service_base<cgi_request_service>
+ {
+ public:
+ typedef common::tags::cgi protocol_type;
+ typedef cgi_service protocol_service_type;
+ typedef cgi_request_impl impl_type;
+ typedef cgi_request_service self_type;
+ typedef common::request_base<self_type> base_type;
+ typedef ::BOOST_CGI_NAMESPACE::common::map map_type;
+
+ struct implementation_type
+ : impl_type
+ , base_type::impl_base
+ {
+ typedef impl_type::client_type client_type;
+ typedef detail::form_parser form_parser_type;
+
+ implementation_type()
+ : fp_(NULL)
+ {
+ }
+
+ client_type client_;
+
+ // The number of characters left to read (ie. "content_length -
+ // bytes_read")
+ std::size_t characters_left_;
+
+ boost::scoped_ptr<form_parser_type> fp_;
+ };
+
+ template<typename Service>
+ struct callback_functor
+ {
+ callback_functor(implementation_type& impl, Service* service)
+ : impl_(impl)
+ , service_(service)
+ {
+ }
+
+ std::size_t operator()(boost::system::error_code& ec)
+ {
+ return service_->read_some(impl_, ec);
+ }
+
+ private:
+ implementation_type& impl_;
+ Service* service_;
+ };
+
+
+ cgi_request_service(common::io_service& ios)
+ : detail::service_base<cgi_request_service>(ios)
+ {
+ }
+
+ void shutdown_service()
+ {
+ }
+
+ void construct(implementation_type& impl)
+ {
+ impl.client_.set_connection(
+ implementation_type::connection_type::create(this->get_io_service())
+ );
+ }
+
+ void destroy(implementation_type& impl)
+ {
+ }
+
+ void set_service(implementation_type& impl, protocol_service_type& ps)
+ {
+ impl.service_ = &ps;
+ }
+
+ /// Return if the request is still open
+ /**
+ * For CGI, this always returns true. However, in the case that a
+ * "Location: xxx" header is sent and the header is terminated, the
+ * request can be taken to be 'closed'.
+ */
+ bool is_open(implementation_type& impl)
+ {
+ return impl.status() >= common::accepted
+ && impl.status() <= common::aborted;
+ }
+
+ /// Return the connection associated with the request
+ implementation_type::client_type&
+ client(implementation_type& impl)
+ {
+ return impl.client_;
+ }
+
+ void clear(implementation_type& impl) { }
+
+ int request_id(implementation_type& impl) { return 1; }
+
+ // **FIXME** should return error_code
+ int close(implementation_type& impl, common::http::status_code& http_s
+ , int status, boost::system::error_code& ec)
+ {
+ impl.status() = common::closed;
+ impl.http_status() = http_s;
+ return status;
+ }
+
+ /// Synchronously read/parse the request data
+ boost::system::error_code&
+ load(implementation_type& impl, common::parse_options parse_opts
+ , boost::system::error_code& ec)
+ {
+ if (parse_opts & common::parse_env)
+ {
+ if (read_env_vars(impl, ec)) // returns an error_code
+ return ec;
+ }
+
+ std::string const& cl = env_vars(impl.vars_)["CONTENT_LENGTH"];
+ impl.characters_left_
+ = cl.empty() ? 0 : boost::lexical_cast<std::size_t>(cl);
+ impl.client_.bytes_left()
+ = impl.characters_left_;
+ std::string const& request_method
+ = env_vars(impl.vars_)["REQUEST_METHOD"];
+
+ if ((request_method == "GET" || request_method == "HEAD")
+ && parse_opts > common::parse_env
+ && parse_opts & common::parse_get_only)
+ {
+ parse_get_vars(impl, ec);
+ }
+ else
+ if (request_method == "POST"
+ && (parse_opts & common::parse_post_only))
+ {
+ parse_post_vars(impl, ec);
+ }
+
+ if (ec) return ec;
+
+ if (parse_opts & common::parse_cookie_only)
+ {
+ if (parse_cookie_vars(impl, ec)) // returns an error_code
+ return ec;
+ }
+
+ set_status(impl, common::loaded);
+
+ return ec;
+ }
+
+ common::role_type
+ get_role(implementation_type& impl)
+ {
+ return common::responder;
+ }
+
+ /// Set the http status (this does nothing for aCGI)
+ void set_status(
+ implementation_type& impl, common::http::status_code&)
+ {
+ // **FIXME**
+ }
+
+ /// Set the request status
+ void set_status(
+ implementation_type& impl, common::request_status status)
+ {
+ impl.status() = status;
+ }
+
+ std::size_t
+ read_some(implementation_type& impl, boost::system::error_code& ec)
+ {
+ return impl.client_.read_some(impl.prepare(64), ec);
+ }
+
+ protected:
+ /// Read the environment variables into an internal map.
+ template<typename RequestImpl>
+ boost::system::error_code
+ read_env_vars(RequestImpl& impl, boost::system::error_code& ec)
+ {
+ // Only call this once.
+ if (!impl.env_parsed_)
+ detail::save_environment(env_vars(impl.vars_));
+ impl.env_parsed_ = true;
+ return ec;
+ }
+
+ /// Read and parse the cgi POST meta variables (greedily)
+ template<typename RequestImpl>
+ boost::system::error_code
+ parse_post_vars(RequestImpl& impl, boost::system::error_code& ec)
+ {
+ // **FIXME** use callback_functor<> in form_parser instead.
+ std::size_t& bytes_left (impl.client_.bytes_left_);
+ std::size_t bytes_read (0);
+ do {
+ bytes_read = read_some(impl, ec);
+ bytes_left -= bytes_read;
+ } while (!ec && bytes_left);
+
+ if (!impl.fp_)
+ // Construct a form_parser instance.
+ impl.fp_.reset(new typename implementation_type::form_parser_type());
+
+ // Create a context for this request.
+ typename implementation_type::form_parser_type::context
+ context
+ = { env_vars(impl.vars_)["CONTENT_TYPE"]
+ , impl.post_buffer_
+ , impl.form_parts_
+ , impl.client_.bytes_left_
+ , post_vars(impl.vars_)
+ , callback_functor<self_type>(impl, this)
+ , impl.stdin_parsed_
+ , env_vars(impl.vars_)["REMOTE_ADDR"]
+ };
+
+ // Parse the current request.
+ impl.fp_->parse(context, ec);
+
+ return ec;
+ }
+ };
+
+BOOST_CGI_NAMESPACE_END
+
+#include "boost/cgi/detail/pop_options.hpp"
+
+#endif // CGI_CGI_SERVICE_IMPL_HPP_INCLUDED__
Added: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/service.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/service.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -0,0 +1,28 @@
+// -- cgi_service.hpp --
+//
+// Copyright (c) Darren Garvey 2007-2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_CGI_SERVICE_HPP_INCLUDED__
+#define CGI_CGI_SERVICE_HPP_INCLUDED__
+
+#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+
+ typedef common::basic_protocol_service<common::tags::cgi> cgi_service;
+ /// typedef for typical usage
+ namespace cgi {
+ typedef cgi_service service;
+ }
+
+BOOST_CGI_NAMESPACE_END
+
+#include "boost/cgi/common/basic_protocol_service.hpp"
+
+#endif // CGI_CGI_SERVICE_HPP_INCLUDED__
+
Added: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/has_hidden_io_service.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/has_hidden_io_service.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -0,0 +1,36 @@
+// -- common/is_async.hpp --
+//
+// Copyright (c) Darren Garvey 2007.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_COMMON_HAS_HIDDEN_IO_SERVICE_HPP_INCLUDED_20091203_
+#define CGI_COMMON_HAS_HIDDEN_IO_SERVICE_HPP_INCLUDED_20091203_
+
+#include <boost/mpl/bool.hpp>
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/config.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace common {
+
+ template<typename Protocol>
+ struct has_hidden_io_service
+ : boost::mpl::bool_<false>
+ {
+ };
+
+ template<>
+ struct has_hidden_io_service<tags::acgi>
+ : boost::mpl::bool_<false>
+ {
+ };
+
+ } // namespace common
+BOOST_CGI_NAMESPACE_END
+
+#endif // CGI_COMMON_HAS_HIDDEN_IO_SERVICE_HPP_INCLUDED_20091203_
+
Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/basic_io_object.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/basic_io_object.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/basic_io_object.hpp 2009-12-06 10:46:18 EST (Sun, 06 Dec 2009)
@@ -14,6 +14,7 @@
#include <boost/type_traits/is_same.hpp>
#include "boost/cgi/common/is_async.hpp"
#include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/common/has_hidden_io_service.hpp"
BOOST_CGI_NAMESPACE_BEGIN
@@ -115,9 +116,14 @@
class basic_io_object<
Service,
typename boost::enable_if<
- boost::is_same<
- typename Service::protocol_type, tags::acgi
- >
+ boost::mpl::or_<
+ boost::is_same<
+ typename Service::protocol_type, tags::cgi
+ >,
+ boost::is_same<
+ typename Service::protocol_type, tags::acgi
+ >
+ >
>::type
>
: private boost::noncopyable
@@ -162,6 +168,8 @@
implementation_type implementation;
};
+
+
} // namespace detail
BOOST_CGI_NAMESPACE_END
Modified: sandbox/SOC/2007/cgi/branches/pickmeup/libs/cgi/build/msvc/9.0/Boost.CGI/Boost.CGI.suo
==============================================================================
Binary files. No diff available.
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk