Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2008-04-29 18:24:00


Author: drrngrvy
Date: 2008-04-29 18:24:00 EDT (Tue, 29 Apr 2008)
New Revision: 44899
URL: http://svn.boost.org/trac/boost/changeset/44899

Log:
Moved a couple of common bits from cgi_service_impl_base and fcgi_request_service into common::request_base<>.
Added:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp | 4 +-
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp | 46 ++---------------------
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp | 80 ++++++++++++++-------------------------
   3 files changed, 35 insertions(+), 95 deletions(-)

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp 2008-04-29 18:24:00 EDT (Tue, 29 Apr 2008)
@@ -72,8 +72,8 @@
           , role_type Role
           , typename Allocator>
   class basic_request
- : public request_base
- , public boost::mpl::if_c<is_async<typename RequestService::protocol_type>::value
+ : //public request_base
+ public boost::mpl::if_c<is_async<typename RequestService::protocol_type>::value
                              , basic_io_object<RequestService>
                              , basic_sync_io_object<RequestService>
>::type

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp 2008-04-29 18:24:00 EDT (Tue, 29 Apr 2008)
@@ -0,0 +1,65 @@
+#ifndef CGI_COMMON_REQUEST_BASE_HPP_INCLUDE_
+#define CGI_COMMON_REQUEST_BASE_HPP_INCLUDE_
+
+#include "boost/cgi/detail/extract_params.hpp"
+
+namespace cgi {
+ namespace common {
+
+ /// ABC that defines the common interface for basic_request<>s
+ /**
+ * This class provides generic member functions that can be used by any
+ * request type.
+ */
+ template<typename T>
+ class request_base
+ {
+ protected:
+
+ /// Read and parse the cgi GET meta variables
+ template<typename ImplType>
+ boost::system::error_code
+ parse_get_vars(ImplType& impl, boost::system::error_code& ec)
+ {
+ // Make sure the request is in a pre-loaded state
+ //BOOST_ASSERT (impl.status() <= unloaded);
+
+ std::string& vars(impl.env_vars_["QUERY_STRING"]);
+ if (vars.empty())
+ return ec;
+
+ detail::extract_params(vars, impl.get_vars_
+ , boost::char_separator<char>
+ ("", "=&", boost::keep_empty_tokens)
+ , ec);
+
+ return ec;
+ }
+
+ /// Read and parse the HTTP_COOKIE meta variable
+ template<typename ImplType>
+ boost::system::error_code
+ parse_cookie_vars(ImplType& impl, boost::system::error_code& ec)
+ {
+ // Make sure the request is in a pre-loaded state
+ //BOOST_ASSERT (impl.status() <= unloaded);
+
+ std::string& vars(impl.env_vars_["HTTP_COOKIE"]);
+ if (vars.empty())
+ return ec;
+
+ detail::extract_params(vars, impl.cookie_vars_
+ , boost::char_separator<char>
+ ("", "=;", boost::keep_empty_tokens)
+ , ec);
+
+ return ec;
+ }
+
+ };
+
+ } // namespace common
+} // namespace cgi
+
+#endif // CGI_COMMON_REQUEST_BASE_HPP_INCLUDE_
+

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp 2008-04-29 18:24:00 EDT (Tue, 29 Apr 2008)
@@ -30,6 +30,7 @@
 #include "boost/cgi/detail/throw_error.hpp"
 
 #include "boost/cgi/common/form_parser.hpp"
+#include "boost/cgi/common/request_base.hpp"
 
 namespace cgi {
 
@@ -41,6 +42,7 @@
 
   template<typename RequestImplType>
   class cgi_service_impl_base
+ : common::request_base<cgi_service_impl_base<RequestImplType> >
   {
   public:
     //typedef RequestImplType implementation_type;
@@ -124,14 +126,14 @@
 
       const std::string& request_method = var(impl.env_vars(), "REQUEST_METHOD", ec);
       if (request_method == "GET")
- parse_get_vars(impl, ec);
+ this->parse_get_vars(impl, ec);
       else
       if (request_method == "POST" && parse_stdin)
         parse_post_vars(impl, ec);
 
       if (ec) return ec;
 
- parse_cookie_vars(impl, ec);
+ this->parse_cookie_vars(impl, ec);
       impl.status() = loaded;
 
       //BOOST_ASSERT(impl.status() >= loaded);
@@ -280,46 +282,6 @@
     }
 
   protected:
- /// Read and parse the cgi GET meta variables
- template<typename RequestImpl>
- boost::system::error_code
- parse_get_vars(RequestImpl& impl, boost::system::error_code& ec)
- {
- // Make sure the request is in a pre-loaded state
- //BOOST_ASSERT (impl.status() <= unloaded);
-
- std::string& vars = impl.env_vars()["QUERY_STRING"];
- if (vars.empty())
- return ec;
-
- detail::extract_params(vars, impl.get_vars()
- , boost::char_separator<char>
- ("", "=&", boost::keep_empty_tokens)
- , ec);
-
- return ec;
- }
-
- /// Read and parse the HTTP_COOKIE meta variable
- template<typename RequestImpl>
- boost::system::error_code
- parse_cookie_vars(RequestImpl& impl, boost::system::error_code& ec)
- {
- // Make sure the request is in a pre-loaded state
- //BOOST_ASSERT (impl.status() <= unloaded);
-
- std::string& vars(impl.env_vars()["HTTP_COOKIE"]);
- if (vars.empty())
- return ec;
-
- detail::extract_params(vars, impl.cookie_vars()
- , boost::char_separator<char>
- ("", "=;", boost::keep_empty_tokens)
- , ec);
-
- return ec;
- }
-
     /// Read and parse the cgi POST meta variables (greedily)
     template<typename RequestImpl>
     boost::system::error_code

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp 2008-04-29 18:24:00 EDT (Tue, 29 Apr 2008)
@@ -13,6 +13,7 @@
 
 //#include "boost/cgi/scgi/request_impl.hpp"
 #include "boost/cgi/common/map.hpp"
+#include "boost/cgi/common/request_base.hpp"
 #include "boost/cgi/tags.hpp"
 #include "boost/cgi/read.hpp"
 #include "boost/cgi/role_type.hpp"
@@ -58,6 +59,7 @@
   /// The IoObjectService class for a FCGI basic_request<>s
   class fcgi_request_service
     : public detail::service_base<fcgi_request_service>
+ , common::request_base<fcgi_request_service>
   {
   public:
     /// The actual implementation date for an FCGI request.
@@ -422,7 +424,7 @@
         return _data[_name.c_str()];
       return "";
     }
-
+/*
     /// Read and parse the cgi GET meta variables
     boost::system::error_code&
     parse_get_vars(implementation_type& impl, boost::system::error_code& ec)
@@ -455,7 +457,7 @@
 
       return ec;
     }
-
+*/
     /// Read and parse the cgi POST meta variables (greedily)
     template<typename RequestImpl>
     boost::system::error_code&
@@ -718,13 +720,10 @@
       }else
       if (!state)
       { // The header is confusing; something's wrong. Abort.
- //std::cerr<< "Bad header received (this isn't implemented properly yet"
- // << std::endl;
         return error::bad_header_type;
       }
       // else route (ie. state == boost::indeterminate)
 
- //std::cerr<< "Got to read more stuff now I think." << std::endl;
       implementation_type::mutable_buffers_type buf
         = impl.prepare(fcgi::spec::get_length(impl.header_buf_));
 
@@ -755,62 +754,41 @@
       parse_body(implementation_type& impl, const MutableBuffersType& buffer
                 , boost::system::error_code& ec)
     {
- return //ec;/*
+ return
         (this->* proc_funcs[fcgi::spec::get_type(impl.header_buf_)])
             (impl, fcgi::spec::get_request_id(impl.header_buf_)
             , boost::asio::buffer_cast<unsigned char*>(buffer)
             , boost::asio::buffer_size(buffer), ec);
     }
 
-/*
- implementation_type::request_type&
- get_or_make_request(implementation_type& impl, boost::uint16_t id);
 
- request_type::pointer ret
-
- try {
- ret = &requests.at(id - 1);
- BOOST_ASSERT(req != 0); // should throw
- return *ret;
- }catch(...){
- req = request_type::create(impl.service_);
- if (requests.size() < (id - 1))
- requests.resize(id);
- requests.at(id-1) = *req;
- return req->impl(); // same as *ret
- }
- }
-*/
- boost::system::error_code
- begin_request_helper(implementation_type& impl
- , implementation_type::header_buffer_type& header
- , boost::system::error_code& ec)
- {
- impl.client_.request_id_ = fcgi::spec::get_request_id(header);
+ boost::system::error_code
+ begin_request_helper(implementation_type& impl
+ , implementation_type::header_buffer_type& header
+ , boost::system::error_code& ec)
+ {
+ impl.client_.request_id_ = fcgi::spec::get_request_id(header);
 
         BOOST_STATIC_ASSERT((
- fcgi::spec::begin_request::body::size::value
- == fcgi::spec::header_length::value));
+ fcgi::spec::begin_request::body::size::value
+ == fcgi::spec::header_length::value));
+
+ // A begin request body is as long as a header, so we can optimise:
+ if (read_header(impl, ec))
+ return ec;
         
- // A begin request body is as long as a header, so we can optimise:
- if (read_header(impl, ec))
- return ec;
-
- impl.request_role_
- = fcgi::spec::begin_request::get_role(impl.header_buf_);
- // **FIXME** (rm impl.request_role_)
- impl.client_.role_ = impl.request_role_;
- //std::cerr<< "[hw] New request role: " << impl.request_role_
- // << " (" << fcgi::spec::role_type::to_string(impl.header_buf_) << ")"
- // << std::endl;
- impl.client_.keep_connection_
- = fcgi::spec::begin_request::get_flags(impl.header_buf_)
- & fcgi::spec::keep_connection;
-
- impl.client_.status_ = common::constructed;
- return ec;
- }
- };
+ impl.request_role_
+ = fcgi::spec::begin_request::get_role(impl.header_buf_);
+ // **FIXME** (rm impl.request_role_)
+ impl.client_.role_ = impl.request_role_;
+ impl.client_.keep_connection_
+ = fcgi::spec::begin_request::get_flags(impl.header_buf_)
+ & fcgi::spec::keep_connection;
+ impl.client_.status_ = common::constructed;
+
+ return ec;
+ }
+ };
 
   //template<>
   const fcgi_request_service::proc_func_t fcgi_request_service::proc_funcs[] =


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