Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58477 - in sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi: . cgi common detail fcgi fwd impl
From: lists.drrngrvy_at_[hidden]
Date: 2009-12-21 10:45:45


Author: drrngrvy
Date: 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
New Revision: 58477
URL: http://svn.boost.org/trac/boost/changeset/58477

Log:
Some more refactoring into request_base.
Using request_status more (ie. to check if env / get / post / cookies have been read).
Added:
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fwd/form_parser_fwd.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_request.hpp | 42 ++++++++---
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_service.hpp | 86 +++++-------------------
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/form_parser.hpp | 4
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/form_part.hpp | 5
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/request_base.hpp | 135 ++++++++++++++++++++++++++++++++++-----
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/request_status.hpp | 17 ++--
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/protocol_traits.hpp | 23 +++--
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/acceptor_service_impl.hpp | 39 +++++-----
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/request_service.hpp | 53 +--------------
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/fcgi_request_service.ipp | 43 +++---------
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/form_parser.ipp | 6
   11 files changed, 233 insertions(+), 220 deletions(-)

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-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -20,25 +20,28 @@
 #include <boost/assert.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/noncopyable.hpp>
+#include <boost/optional.hpp>
 #include <boost/functional/hash.hpp>
 #include <boost/asio/io_service.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/utility/enable_if.hpp>
 ///////////////////////////////////////////////////////////
+#include "boost/cgi/common/data_map_proxy.hpp"
+#include "boost/cgi/common/form_part.hpp"
+#include "boost/cgi/common/has_hidden_io_service.hpp"
 #include "boost/cgi/common/map.hpp"
+#include "boost/cgi/common/parse_options.hpp"
 #include "boost/cgi/common/path_info.hpp"
-#include "boost/cgi/common/data_map_proxy.hpp"
+#include "boost/cgi/common/request_service.hpp"
+#include "boost/cgi/common/request_status.hpp"
 #include "boost/cgi/common/role_type.hpp"
 #include "boost/cgi/common/source_enums.hpp"
-#include "boost/cgi/common/parse_options.hpp"
-#include "boost/cgi/common/request_service.hpp"
-#include "boost/cgi/http/status_code.hpp"
-#include "boost/cgi/fwd/basic_request_fwd.hpp"
-#include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
 #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"
+#include "boost/cgi/fwd/basic_request_fwd.hpp"
+#include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
+#include "boost/cgi/http/status_code.hpp"
 
 #ifndef BOOST_CGI_POST_MAX
     /// Restrict POST data to less than 7MB per request.
@@ -609,9 +612,9 @@
      * different
      * eg. `authorizer`, or `filter`.
      */
- role_type& role()
+ role_type& role() const
     {
- return this->service.get_role(this->implementation);
+ return this->service.role(this->implementation);
     }
 
     /// Get a hashed interpretation of the request.
@@ -625,14 +628,29 @@
       return boost::hash<self_type>()(*this);
     }
 
- /// Set the status of a request.
+ /// Get / Set the status of a request.
     /**
      * The usual way to set the request status is to set it
      * when calling `close`.
      */
- void set_status(common::http::status_code const& status)
+ common::request_status status() const
+ {
+ return this->service.status(this->implementation);
+ }
+
+ void status(common::request_status const& status)
+ {
+ this->service.status(this->implementation, status);
+ }
+
+ common::http::status_code status(common::http::status_code const& status) const
+ {
+ return this->service.status(this->implementation);
+ }
+
+ void status(common::http::status_code const& status)
     {
- this->service.set_status(this->implementation, status);
+ this->service.status(this->implementation, status);
     }
     
     /// Get the form_part for the passed key, which may not exist.

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_service.hpp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -94,56 +94,30 @@
     {
     }
 
- void shutdown_service()
- {
- }
-
- void construct(implementation_type& impl)
+ template<typename ImplType>
+ void construct(ImplType& impl)
     {
       impl.client_.set_connection(
- implementation_type::connection_type::create(this->get_io_service())
+ typename ImplType::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)
+ void shutdown_service()
     {
- return impl.status() >= common::accepted
- && impl.status() <= common::aborted;
     }
 
     void clear(implementation_type& impl) { }
 
     int request_id(implementation_type& impl) { return 1; }
 
- /// Return the connection associated with the request
- implementation_type::client_type&
- client(implementation_type& impl)
- {
- return impl.client_;
- }
-
     // **FIXME** should return error_code
     int close(implementation_type& impl, common::http::status_code& http_s
- , int status, boost::system::error_code& ec)
+ , int program_status, boost::system::error_code& ec)
     {
- impl.status() = common::closed;
+ status(impl, common::closed);
       impl.http_status() = http_s;
- return status;
+ impl.all_done_ = true;
+ return program_status;
     }
 
     /// Synchronously read/parse the request data
@@ -186,24 +160,18 @@
           return ec;
       }
 
- set_status(impl, common::loaded);
+ status(impl, common::loaded);
 
       return ec;
     }
 
+ /// CGI is always a responser.
     common::role_type
- get_role(implementation_type& impl)
+ role(implementation_type& impl) const
     {
       return common::responder;
     }
 
- /// 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)
     {
@@ -217,9 +185,11 @@
     read_env_vars(RequestImpl& impl, boost::system::error_code& ec)
     {
       // Only call this once.
- if (!impl.env_parsed_)
+ if (!(status(impl) & common::env_read))
+ {
         detail::save_environment(env_vars(impl.vars_));
- impl.env_parsed_ = true;
+ status(impl, (common::request_status)(status(impl) | common::env_read));
+ }
       return ec;
     }
 
@@ -243,27 +213,11 @@
         else
           return ec;
 
- 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;
+ return base_type::parse_post_vars(
+ impl,
+ callback_functor<self_type>(impl, this),
+ ec
+ );
     }
   };
 

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/form_parser.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/form_parser.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/form_parser.hpp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -44,7 +44,7 @@
 #endif // BOOST_CGI_UPLOAD_DIRECTORY
 
 BOOST_CGI_NAMESPACE_BEGIN
- namespace detail {
+ namespace common {
 
   /// A class for parsing POST data sent to a CGI process.
   /**
@@ -151,7 +151,7 @@
     context* context_;
   };
 
- } // namespace detail
+ } // namespace common
 
 BOOST_CGI_NAMESPACE_END
 

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/form_part.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/form_part.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/form_part.hpp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -6,6 +6,7 @@
 #include <string>
 #include <boost/range.hpp>
 #include "boost/cgi/config.hpp"
+#include "boost/cgi/common/name.hpp"
 
 BOOST_CGI_NAMESPACE_BEGIN
  namespace common {
@@ -34,7 +35,7 @@
      bool operator==(form_part& other) {
         return this->name == other.name;
      }
-
+
      meta_data_map_type meta_data_;
 
      /// The boundary marker that's needed.
@@ -51,7 +52,7 @@
      string_type filename;
      // Where the actual uploaded file is stored.
      string_type path;
-
+
    public:
      /// TODO: Check that the uploaded file isn't empty too.
      bool empty() const { return value.empty(); }

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/request_base.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/request_base.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/request_base.hpp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -23,6 +23,7 @@
 #include "boost/cgi/common/map.hpp"
 #include "boost/cgi/common/form_part.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/protocol_traits.hpp"
 #include "boost/cgi/detail/save_environment.hpp"
@@ -88,7 +89,8 @@
       impl_base()
         : service_(NULL)
         , vars_(), post_buffer_()
- , get_parsed_(false), env_parsed_(false), stdin_parsed_(false)
+ , stdin_parsed_(false)
+ , all_done_(false)
         , bytes_left_(0)
         , http_status_(common::http::no_content)
         , request_status_(common::unloaded)
@@ -98,19 +100,18 @@
       
       bool stdin_parsed() { return stdin_parsed_; }
       common::http::status_code& http_status() { return http_status_; }
- common::request_status& status() { return request_status_; }
+ common::request_status status() const { return request_status_; }
+ void status(common::request_status& st) { request_status_ = st; }
 
       protocol_service_type* service_;
       
       var_map_type vars_;
       buffer_type post_buffer_;
- /// Whether the get data has been parsed yet.
- bool get_parsed_;
- /// Whether the environment has been parsed yet.
- bool env_parsed_;
       /// Whether the post data has been parsed yet.
       bool stdin_parsed_;
       
+ bool all_done_;
+
       // The number of bytes left to read (ie. content_length - bytes_read)
       std::size_t bytes_left_;
 
@@ -133,6 +134,25 @@
       }
     };
     
+ template<typename ImplType, typename Service>
+ struct callback_functor
+ {
+ callback_functor(ImplType& impl, Service* service)
+ : impl_(impl)
+ , service_(service)
+ {
+ }
+
+ std::size_t operator()(boost::system::error_code& ec)
+ {
+ return service_->read_some(impl_, ec);
+ }
+
+ private:
+ ImplType& impl_;
+ Service* service_;
+ };
+
     /// Load the base_environment into the current environment.
     /**
      * Parsed the base_environment and add it to the current request's
@@ -171,6 +191,52 @@
       return impl.client_.read_some(buf,ec);
     }
 
+ template<typename ImplType>
+ void destroy(ImplType& impl)
+ {
+ }
+
+ /// Return the connection associated with the request
+ template<typename ImplType>
+ typename ImplType::client_type&
+ client(ImplType& impl)
+ {
+ return impl.client_;
+ }
+
+ template<typename ImplType>
+ void set_service(
+ ImplType& impl,
+ typename ImplType::protocol_service_type& ps
+ )
+ {
+ impl.service_ = &ps;
+ }
+
+ /// Get the request status.
+ template<typename ImplType>
+ common::request_status status(ImplType& impl) const
+ {
+ return impl.status();
+ }
+
+ /// Set the request status.
+ template<typename ImplType>
+ void status(ImplType& impl, common::request_status status)
+ {
+ impl.status(status);
+ }
+
+ /// Return if the request is still open.
+ template<typename ImplType>
+ bool is_open(ImplType& impl)
+ {
+ return !impl.all_done_
+ && impl.status() >= common::accepted
+ && impl.status() <= common::aborted
+ && impl.client_.is_open();
+ }
+
     /// Check if a given POST variable represents a file upload.
     template<typename ImplType>
     bool is_file(ImplType& impl
@@ -240,7 +306,7 @@
           return ec;
       }
 
- set_status(impl, common::loaded);
+ status(impl, common::loaded);
 
       return ec;
     }
@@ -252,7 +318,7 @@
     {
       // Make sure the request is in a pre-loaded state
       //BOOST_ASSERT (impl.status() <= unloaded);
- if (!impl.get_parsed_)
+ if (!(status(impl) & common::get_read))
       {
         std::string const& vars (env_vars(impl.vars_)["QUERY_STRING"]);
         if (!vars.empty())
@@ -260,8 +326,8 @@
                                 , boost::char_separator<char>
                                    ("", "=&", boost::keep_empty_tokens)
                                 , ec);
- impl.get_parsed_ = true;
- }
+ status(impl, (common::request_status)(status(impl) | common::get_read));
+ }
       return ec;
     }
 
@@ -272,14 +338,47 @@
     {
       // Make sure the request is in a pre-loaded state
       //BOOST_ASSERT (impl.status() <= unloaded);
-
- std::string const& vars (env_vars(impl.vars_)["HTTP_COOKIE"]);
- if (!vars.empty())
- detail::extract_params(vars, cookie_vars(impl.vars_)
- , boost::char_separator<char>
- ("", "=;", boost::keep_empty_tokens)
- , ec);
-
+ if (!(status(impl) & common::cookies_read))
+ {
+ std::string const& vars (env_vars(impl.vars_)["HTTP_COOKIE"]);
+ if (!vars.empty())
+ detail::extract_params(vars, cookie_vars(impl.vars_)
+ , boost::char_separator<char>
+ ("", "=;", boost::keep_empty_tokens)
+ , ec);
+ status(impl, (common::request_status)(status(impl) | common::cookies_read));
+ }
+ return ec;
+ }
+
+ /// Read and parse the cgi POST meta variables.
+ template<typename ImplType, typename Callback>
+ boost::system::error_code&
+ parse_post_vars(ImplType& impl, Callback callback, boost::system::error_code& ec)
+ {
+ if (!(status(impl) & common::post_read))
+ {
+ if (!impl.fp_)
+ // Construct a form_parser instance.
+ impl.fp_.reset(new typename ImplType::form_parser_type());
+
+ // Create a context for this request.
+ typename ImplType::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
+ , impl.stdin_parsed_
+ , env_vars(impl.vars_)["REMOTE_ADDR"]
+ };
+
+ // Parse the current request.
+ impl.fp_->parse(context, ec);
+ status(impl, (common::request_status)(status(impl) | common::post_read));
+ }
       return ec;
     }
   };

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/request_status.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/request_status.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/request_status.hpp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -14,13 +14,16 @@
  namespace common {
 
    enum request_status
- { null
- , unloaded
- , activated
- , accepted = activated
- , env_read
- , loaded
- , ok = loaded
+ { null = 0
+ , unloaded = null
+ , activated = 1
+ , accepted = activated
+ , env_read = 2
+ , get_read = 4
+ , post_read = 8
+ , cookies_read = 16
+ , loaded = 32
+ , ok = loaded
      , aborted
      , closed
      };

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/protocol_traits.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/protocol_traits.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/protocol_traits.hpp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -16,17 +16,19 @@
 #ifndef CGI_REQUEST_TRAITS_HPP_INCLUDED__
 #define CGI_REQUEST_TRAITS_HPP_INCLUDED__
 
+#include <boost/asio/ip/tcp.hpp>
 #include <boost/none.hpp>
 #include <boost/shared_ptr.hpp>
 ///////////////////////////////////////////////////////////
-#include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
-#include "boost/cgi/common/tags.hpp"
-#include "boost/cgi/common/role_type.hpp"
 #include "boost/cgi/common/parse_options.hpp"
+#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/common/tags.hpp"
 #include "boost/cgi/fcgi/specification.hpp"
-#include "boost/cgi/fwd/basic_request_fwd.hpp"
-#include "boost/cgi/fwd/basic_connection_fwd.hpp"
 #include "boost/cgi/fwd/basic_client_fwd.hpp"
+#include "boost/cgi/fwd/basic_connection_fwd.hpp"
+#include "boost/cgi/fwd/basic_protocol_service_fwd.hpp"
+#include "boost/cgi/fwd/basic_request_fwd.hpp"
+#include "boost/cgi/fwd/form_parser_fwd.hpp"
 
 BOOST_CGI_NAMESPACE_BEGIN
 
@@ -58,8 +60,6 @@
 
    namespace tags = ::BOOST_CGI_NAMESPACE::common::tags;
    
- class form_parser;
-
    template<typename Protocol>
     struct protocol_traits
     {
@@ -85,7 +85,7 @@
                   connection_type,
                   tags::cgi
> client_type;
- typedef detail::form_parser form_parser_type;
+ typedef common::form_parser form_parser_type;
       typedef boost::none_t header_type;
       typedef char char_type;
       typedef std::basic_string<char_type> string_type;
@@ -116,11 +116,14 @@
       typedef common::basic_connection<
                   tags::shareable_tcp_socket
> connection_type;
+ typedef boost::asio::ip::tcp native_protocol_type;
+ typedef unsigned short port_number_type;
+ typedef boost::asio::ip::tcp::endpoint endpoint_type;
       typedef common::basic_client<
                   connection_type,
                   tags::fcgi
> client_type;
- typedef detail::form_parser form_parser_type;
+ typedef common::form_parser form_parser_type;
       typedef fcgi::spec::header header_type;
       typedef fcgi::spec_detail::role_types role_type;
 
@@ -151,7 +154,7 @@
                   connection_type,
                   tags::scgi
> client_type;
- typedef detail::form_parser form_parser_type;
+ typedef common::form_parser form_parser_type;
       typedef char char_type;
       typedef std::basic_string<char_type> string_type;
       typedef string_type buffer_type;

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/acceptor_service_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/acceptor_service_impl.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/acceptor_service_impl.hpp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -75,10 +75,10 @@
     * If the protocol isn't async then the class can be used without a
     * ProtocolService.
     */
- template<typename Protocol_ = common::tags::fcgi>
+ template<typename Protocol = common::tags::fcgi>
    class acceptor_service_impl
      : public detail::service_base<
- ::BOOST_CGI_NAMESPACE::fcgi::acceptor_service_impl<Protocol_>
+ ::BOOST_CGI_NAMESPACE::fcgi::acceptor_service_impl<Protocol>
>
    {
    public:
@@ -88,21 +88,20 @@
 
      struct implementation_type
      {
- typedef Protocol_ protocol_type;
- typedef common::basic_protocol_service<
- protocol_type
- > protocol_service_type;
- typedef boost::asio::ip::tcp native_protocol_type;
- typedef fcgi::request request_type;
+ typedef Protocol protocol_type;
+ typedef detail::protocol_traits<Protocol> traits;
+ typedef typename traits::protocol_service_type protocol_service_type;
+ typedef typename traits::native_protocol_type native_protocol_type;
+ typedef typename traits::request_type request_type;
        typedef boost::asio::socket_acceptor_service<
                  native_protocol_type
> acceptor_service_type;
- typedef unsigned short port_number_type;
- typedef boost::asio::ip::tcp::endpoint endpoint_type;
- //typedef typename
- // acceptor_service_type::native_type native_type;
+ typedef typename
+ acceptor_service_type::implementation_type acceptor_impl_type;
+ typedef typename traits::port_number_type port_number_type;
+ typedef typename traits::endpoint_type endpoint_type;
 
- acceptor_service_type::implementation_type acceptor_;
+ acceptor_impl_type acceptor_;
        boost::mutex mutex_;
        std::queue<boost::shared_ptr<request_type> > waiting_requests_;
        protocol_service_type* service_;
@@ -110,8 +109,8 @@
        endpoint_type endpoint_;
      };
 
- typedef acceptor_service_impl<Protocol_> type;
- typedef Protocol_ protocol_type;
+ typedef acceptor_service_impl<Protocol> type;
+ typedef Protocol protocol_type;
      typedef typename
        type::implementation_type::protocol_service_type
                                                          protocol_service_type;
@@ -129,9 +128,8 @@
 
 
      explicit acceptor_service_impl(::BOOST_CGI_NAMESPACE::common::io_service& ios)
- : detail::service_base< ::BOOST_CGI_NAMESPACE::fcgi::acceptor_service_impl<Protocol_> >(ios)
+ : detail::service_base< ::BOOST_CGI_NAMESPACE::fcgi::acceptor_service_impl<Protocol> >(ios)
        , acceptor_service_(boost::asio::use_service<acceptor_service_type>(ios))
- //, endpoint(boost::asio::ip::tcp::v4())
      {
      }
 
@@ -169,13 +167,11 @@
      void construct(implementation_type& impl)
      {
        acceptor_service_.construct(impl.acceptor_);
- //impl.acceptor_ptr().reset(impl::acceptor_type(this->io_service()));
      }
 
      void destroy(implementation_type& impl)
      {
        // close/reject all the waiting requests
- /***/
        acceptor_service_.destroy(impl.acceptor_);
      }
 
@@ -268,8 +264,11 @@
          return ec;
 
        // ...otherwise accept a new connection.
- return acceptor_service_.accept(impl.acceptor_,
+ ec = acceptor_service_.accept(impl.acceptor_,
                 request.client().connection()->next_layer(), endpoint, ec);
+ if (!ec)
+ request.status(common::accepted);
+ return ec;
      }
 
      /// Asynchronously accepts one request.

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/request_service.hpp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -46,7 +46,6 @@
       implementation_type()
         : id_(0)
         , request_role_(spec_detail::ANY)
- , all_done_(false)
       {
       }
 
@@ -54,8 +53,6 @@
 
       fcgi::spec_detail::role_types request_role_;
 
- bool all_done_;
-
       header_buffer_type header_buf_;
       header_type header_;
       
@@ -78,25 +75,6 @@
     typedef self_type::implementation_type::string_type string_type;
     typedef self_type::implementation_type::request_type request_type;
 
- 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_;
- };
-
     fcgi_request_service(::BOOST_CGI_NAMESPACE::common::io_service& ios)
       : detail::service_base<fcgi_request_service>(ios)
     {
@@ -106,37 +84,18 @@
     {
     }
 
- void construct(implementation_type& impl)
+ template<typename ImplType>
+ void construct(ImplType& impl)
     {
       impl.client_.set_connection(
- implementation_type::connection_type::create(this->io_service())
+ typename ImplType::connection_type::create(this->get_io_service())
       );
     }
 
- void destroy(implementation_type& impl)
- {
- //if (!impl.all_done_)
- // detail::abort_impl(impl); // this function isn't implemented yet!
- //impl.set_state(aborted);
- }
-
     void shutdown_service()
     {
     }
 
- void set_service(implementation_type& impl
- , implementation_type::protocol_service_type& ps)
- {
- impl.service_ = &ps;
- }
-
- /// Check if the request is still open.
- bool is_open(implementation_type& impl)
- {
- return impl.request_status_ != common::null
- && !impl.all_done_ && impl.client_.is_open();
- }
-
     /// Close the request.
     int close(implementation_type& impl, ::BOOST_CGI_NAMESPACE::common::http::status_code& hsc
               , int program_status);
@@ -145,7 +104,7 @@
     int close(implementation_type& impl, ::BOOST_CGI_NAMESPACE::common::http::status_code& hsc
              , int program_status, boost::system::error_code& ec);
 
- /// Clear all request data (object is then safe to remove).
+ /// Clear all request data (object is then safe to reuse).
     void clear(implementation_type& impl);
 
     /// Load the request to a point where it can be usefully used.
@@ -170,7 +129,7 @@
     /// Returns true if the request environment params have been read.
     bool params_read(implementation_type& impl);
 
- common::role_type get_role(implementation_type& impl)
+ common::role_type role(implementation_type& impl) const
     {
       return common::responder;
     }
@@ -181,8 +140,6 @@
       return impl.client_;
     }
 
- void set_status(implementation_type& impl, common::request_status status);
-
   protected:
     /// Read and parse the cgi POST meta variables (greedily)
     boost::system::error_code&

Added: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fwd/form_parser_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fwd/form_parser_fwd.hpp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,22 @@
+// -- form_parser_fwd.hpp --
+//
+// Copyright (c) Darren Garvey 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_FORM_PARSER_FWD_HPP_INCLUDED_
+#define CGI_FORM_PARSER_FWD_HPP_INCLUDED_
+
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace common {
+
+ /// The form_parser class for parsing POST data.
+ class form_parser;
+
+ } // namespace common
+BOOST_CGI_NAMESPACE_END
+
+#endif // CGI_FORM_PARSER_FWD_HPP_INCLUDED_

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/fcgi_request_service.ipp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/fcgi_request_service.ipp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/fcgi_request_service.ipp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -125,7 +125,6 @@
       common::cookie_vars(impl.vars_).clear();
       common::env_vars(impl.vars_).clear();
       impl.stdin_parsed_ = false;
- impl.get_parsed_ = false;
       impl.http_status_ = common::http::no_content;
       impl.request_status_ = common::null;
       impl.request_role_ = spec_detail::ANY;
@@ -257,44 +256,21 @@
       return impl.client_.status() >= common::params_read;
     }
 
- BOOST_CGI_INLINE
- void fcgi_request_service::set_status(
- implementation_type& impl, common::request_status status)
- {
- impl.request_status_ = status;
- }
-
     /// Read and parse the cgi POST meta variables (greedily)
     BOOST_CGI_INLINE boost::system::error_code&
     fcgi_request_service::parse_post_vars(
         implementation_type& impl
       , boost::system::error_code& ec)
     {
- if (!impl.fp_)
- // Construct a form_parser instance.
- impl.fp_.reset(new implementation_type::form_parser_type());
-
       impl.client_.bytes_left_
          = boost::lexical_cast<std::size_t>(
              env_vars(impl.vars_)["CONTENT_LENGTH"]);
       
- // Create a context for this request.
- 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;
+ return base_type::parse_post_vars(
+ impl,
+ callback_functor<implementation_type, self_type>(impl, this),
+ ec
+ );
     }
 
     /// Read and parse a single cgi POST meta variable (greedily)
@@ -335,7 +311,7 @@
     fcgi_request_service::read_env_vars(
         implementation_type& impl, boost::system::error_code& ec)
     {
- while(!ec && !params_read(impl))
+ while(!ec && !(status(impl) & common::env_read))
       {
         if (this->read_header(impl, ec))
           return ec;
@@ -343,12 +319,15 @@
         boost::tribool state = this->parse_header(impl);
 
         if (state)
- // the header has been handled and all is ok; continue.
+ { // the header has been handled and all is ok; continue.
           impl.client_.status(common::params_read);
+ status(impl, (common::request_status)(status(impl) | common::env_read));
+ }
         else
         if (!state)
- // The header is confusing; something's wrong. Abort.
+ { // The header is confusing; something's wrong. Abort.
           ec = error::bad_header_type;
+ }
         else // => (state == boost::indeterminate)
         {
           std::size_t remaining(

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/form_parser.ipp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/form_parser.ipp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/form_parser.ipp 2009-12-21 10:45:43 EST (Mon, 21 Dec 2009)
@@ -23,7 +23,7 @@
 
 BOOST_CGI_NAMESPACE_BEGIN
 
- namespace detail {
+ namespace common {
 
     BOOST_CGI_INLINE
     boost::system::error_code
@@ -78,7 +78,7 @@
            {
              char ch = *++iter; // need this because order of function arg
                                 // evaluation is UB.
- result.append(1, hex_to_char(ch, *++iter));
+ result.append(1, detail::hex_to_char(ch, *++iter));
            }
            break;
          case '=': // the name is complete, now get the corresponding value
@@ -252,7 +252,7 @@
       return ec;
     }
 
- } // namespace detail
+ } // namespace common
  
 BOOST_CGI_NAMESPACE_END
 


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