Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2008-04-29 22:31:10


Author: drrngrvy
Date: 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
New Revision: 44908
URL: http://svn.boost.org/trac/boost/changeset/44908

Log:
Refactoring/housekeeping. Lots of common stuff has moved into common::request_base<> (this *isn't* the same as ::cgi::request_base - an old class that will be removed/replaced).
Text files modified:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_impl.hpp | 1
   sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_service.hpp | 2
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp | 87 +++-------------
   sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_impl.hpp | 36 ------
   sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_service.hpp | 2
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/form_parser.hpp | 9
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/form_parser.ipp | 36 +++---
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp | 93 +++++++++++++++++
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_request_impl_base.hpp | 16 --
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp | 115 +---------------------
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp | 1
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp | 206 ++++-----------------------------------
   12 files changed, 167 insertions(+), 437 deletions(-)

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_impl.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_impl.hpp 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -32,7 +32,6 @@
         connection_type, tags::acgi
>
     client_type;
- //typedef async_stdio_connection client_type;
 
     acgi_request_impl()
       : cgi_request_impl_base<connection_type>()

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_service.hpp 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -28,8 +28,6 @@
   {
   public:
     typedef acgi_request_service type;
- typedef acgi_request_impl impl_type;
- typedef ::cgi::common::map map_type;
     typedef tags::acgi protocol_type;
     typedef acgi_service protocol_service_type;
 

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 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -261,34 +261,6 @@
       return this->service.client(this->implementation);
     }
 
- /// Set the output for the request
- /**
- * Not Implemented Yet ******************
- *
- * Set the output sink as `stdout_`, `stderr_`, or `stdout_ | stderr_`
- */
- /*
- void set_output(cgi::sink dest = stdout_)
- {
- boost::system::error_code ec;
- this->service(this->implementation, dest, ec);
- detail::throw_error(ec);
- }
- */
-/*
- void read_some()
- {
- boost::system::error_code ec;
- this->service.read_some(this->implementationementation,ec);
- detail::throw_error(ec);
- }
-
- boost::system::error_code
- read_some(boost::system::error_code& ec)
- {
- return this->service.read_some(this->implementationementation, ec);
- }
-*/
     template<typename MutableBufferSequence>
     void read_some(const MutableBufferSequence& buf)
     {
@@ -318,12 +290,6 @@
     }
     */
 
- /// Get a `cgi::map&` corresponding to all of the GET variables
- map_type& GET()
- {
- return this->service.GET(this->implementation);
- }
-
     /// Find the get meta-variable matching name
     /**
      * @throws `boost::system::system_error` if an error occurred. This may
@@ -349,12 +315,6 @@
       return this->service.GET(this->implementation, name, ec);
     }
 
- /// Get a `cgi::map&` corresponding to all of the POST variables
- map_type& POST()
- {
- return this->service.POST(this->implementation);
- }
-
     /// Find the post meta-variable matching name
     /**
      * @param greedy This determines whether more data can be read to find
@@ -385,15 +345,6 @@
       return this->service.POST(this->implementation, name, ec, greedy);
     }
 
- /// Get a `cgi::map&` corresponding to all of the form variables
- map_type& form(bool greedy = true)
- {
- boost::system::error_code ec;
- map_type& data = this->service.form(this->implementation, ec, greedy);
- detail::throw_error(ec);
- return data;
- }
-
     /// Find the form variable matching name
     /**
      * Depending on the request's request_method, either the GET or the POST
@@ -429,12 +380,6 @@
         return "";
     }
 
- /// Get a `cgi::map&` corresponding to all of the HTTP_COOKIE variables
- map_type& cookie()
- {
- return this->service.cookie(this->implementation);
- }
-
     /// Find the cookie meta-variable matching name
     /**
      * @throws `boost::system::system_error` if an error occurred. This may
@@ -461,12 +406,6 @@
       return this->service.cookie(this->implementation, name, ec);
     }
 
- /// Get a `cgi::map&` corresponding to all of the environment variables
- map_type& env()
- {
- return this->service.env(this->implementation);
- }
-
     /// Find the environment meta-variable matching name
     /**
      * @throws `boost::system::system_error` if an error occurred. This may
@@ -632,38 +571,50 @@
     // compile-time (I hope) retrieval of different data
     // maps.
     //
+ /// Get a `common::env_map&` of all the environment variables.
     env_map& operator[](common::env_data_type const&)
     {
- return this->implementation.env_vars_;
+ return this->implementation.env_vars();
     }
 
+ /// Get a `common::get_map&` of all the GET variables.
     get_map& operator[](common::get_data_type const&)
     {
- return this->implementation.get_vars_;
+ return this->implementation.get_vars();
     }
 
+ /// Get a `common::post_map&` of all the POST variables.
     post_map& operator[](common::post_data_type const&)
     {
- return this->implementation.post_vars_;
+ return this->implementation.post_vars();
     }
 
+ /// Get a `common::cookie_map&` of all the cookies.
     cookie_map& operator[](common::cookie_data_type const&)
     {
- return this->implementation.cookie_vars_;
+ return this->implementation.cookie_vars();
     }
 
+ /// Get a `common::form_map&` of either the GET or POST variables.
     form_map& operator[](common::form_data_type const&)
     {
       if (request_method() == "GET")
- return this->implementation.get_vars_;
+ return this->implementation.get_vars();
       else
       if (request_method() == "POST")
- return this->implementation.post_vars_;
+ return this->implementation.post_vars();
       else
- return this->implementation.env_vars_;
+ return this->implementation.env_vars();
     }
     ////////////////////////////////////////////////////////////
 
+ /// The id of this request.
+ /**
+ * This is 1 for CGI/aCGI requests, but may be != 1 for FastCGI requests.
+ * Note that for FastCGI requests, the id's are assigned on a
+ * *per-connection* policy, so in one application you may have several
+ * requests with the same id.
+ */
     int id()
     {
       return this->service.request_id(this->implementation);

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_impl.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_impl.hpp 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -41,7 +41,6 @@
     : public cgi_request_impl_base<common::stdio_connection>
   {
   public:
- //typedef stdio_connection client_type;
     typedef ::cgi::common::basic_client<common::stdio_connection, tags::cgi> client_type;
 
     /// Constructor
@@ -61,42 +60,9 @@
     }
 
   protected:
- friend class cgi_service_impl;//<cgi_request_impl>;
+ friend class cgi_service_impl;
   };
 
- //template<> inline const std::string&
- //cgi_request_impl::var<tags::ENV>(const std::string& name)
- //{
- // return ::getenv(name.c_str());
- //}
-
- /// Get a request map of all the environment meta-variables (slow)
- /**
- * -- NOT IMPLEMENTED FOR NOW --
- *
- * In the case of a CGI request, the environment meta-data is usually stored
- * in the process environment, which means there is no direct access to all
- * of them as a map_type&. In other words, this function call will have to
- * load all of the variables into memory and then return the map
- */
- //template<> inline cgi_request_impl::map_type&
- //cgi_request_impl::var<tags::ENV>()
- //{
- // throw std::logic_error("Can't get all environment vars as a map_type&");
- //}
-
- //template<> inline cgi_request_impl::map_type&
- //cgi_request_impl::var<tags::HTTP>() { return http_map_; }
-
- //template<> inline cgi_request_impl::map_type&
- //cgi_request_impl::var<tags::COOKIE>() { return cookie_map_; }
-
- //template<> inline cgi_request_impl::map_type&
- //cgi_request_impl::var<tags::GET>() { return get_map_; }
-
- //template<> inline cgi_request_impl::map_type&
- //cgi_request_impl::var<tags::POST>() { return post_map_; }
-
 } // namespace cgi
 
 #endif // CGI_CGI_REQUEST_IMPL_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_service.hpp 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -26,11 +26,9 @@
   class cgi_request_service
    : public cgi_service_impl_base<cgi_request_impl>
   {
- typedef ::cgi::common::map map_type;
   public:
     typedef cgi_request_impl impl_type;
     typedef tags::cgi protocol_type;
- //typedef cgi_service_impl_base<cgi_request_impl> base;
 
     cgi_request_service()
       : cgi_service_impl_base<cgi_request_impl>()

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/form_parser.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/form_parser.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/form_parser.hpp 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -19,6 +19,7 @@
 #include <boost/asio/error.hpp>
 #include <boost/function.hpp>
 #include <boost/system/error_code.hpp>
+#include <boost/algorithm/string/find.hpp>
 #include "boost/cgi/common/form_part.hpp"
 #include "boost/cgi/basic_client.hpp"
 
@@ -48,14 +49,14 @@
 
     mutable_buffers_type prepare(std::size_t size)
     {
- std::size_t bufsz(impl_.buf_.size());
- impl_.buf_.resize(bufsz + size);
- return boost::asio::buffer(&impl_.buf_[bufsz], size);
+ std::size_t bufsz(impl_.buffer_.size());
+ impl_.buffer_.resize(bufsz + size);
+ return boost::asio::buffer(&impl_.buffer_[bufsz], size);
     }
       
     std::string buffer_string()
     {
- return std::string(impl_.buf_.begin() + offset_, impl_.buf_.end());
+ return std::string(impl_.buffer_.begin() + offset_, impl_.buffer_.end());
     }
     
     boost::system::error_code

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/form_parser.ipp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/form_parser.ipp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/form_parser.ipp 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -30,7 +30,7 @@
     boost::system::error_code
       form_parser<T>::parse(boost::system::error_code& ec)
     {
- std::string content_type (impl_.env_vars_["CONTENT_TYPE"]);
+ std::string content_type (impl_.env_vars()["CONTENT_TYPE"]);
 
       BOOST_ASSERT(!content_type.empty());
 
@@ -94,7 +94,7 @@
             break;
         case '&': // we now have the name/value pair, so save it
             // **FIXME** have to have .c_str() ?
- impl_.post_vars_[name.c_str()] = str;
+ impl_.post_vars()[name.c_str()] = str;
             str.clear();
             name.clear();
            break;
@@ -105,7 +105,7 @@
       // save the last param (it won't have a trailing &)
       if( !name.empty() )
           // **FIXME** have to have .c_str() ?
- impl_.post_vars_[name.c_str()] = str;
+ impl_.post_vars()[name.c_str()] = str;
 
       return ec;
     }
@@ -175,8 +175,8 @@
       std::size_t offset = offset_;
 
       //int runs = 0;
- buffer_iter begin(impl_.buf_.begin() + offset);
- buffer_iter end(impl_.buf_.end());
+ buffer_iter begin(impl_.buffer_.begin() + offset);
+ buffer_iter end(impl_.buffer_.end());
 
       for(;;)
       {
@@ -194,7 +194,7 @@
              // = boost::range_iterator<;
              = std::make_pair(matches[1].first, matches[1].second);
             // **FIXME**
- impl_.post_vars_[form_parts_.back().name.c_str()] = matches[1];
+ impl_.post_vars()[form_parts_.back().name.c_str()] = matches[1];
             //std::ofstream of("c:/cc/log/post_vars.log");
             //of<< "var == " << matches[1] << std::endl;
             offset_ = offset + matches[0].length();
@@ -217,8 +217,8 @@
               return ec;
             }
 
- begin = impl_.buf_.begin() + offset;
- end = impl_.buf_.end();
+ begin = impl_.buffer_.begin() + offset;
+ end = impl_.buffer_.end();
 
             if (ec)
               return ec;
@@ -285,14 +285,14 @@
       boost::match_results<buffer_iter> matches;
 
       std::size_t offset = offset_;
- pos_ = impl_.buf_.begin();
+ pos_ = impl_.buffer_.begin();
       int runs = 0;
 
       std::size_t bytes_read = 0;
       for(;;)
       {
- buffer_iter begin(impl_.buf_.begin() + offset);
- buffer_iter end(impl_.buf_.end());
+ buffer_iter begin(impl_.buffer_.begin() + offset);
+ buffer_iter end(impl_.buffer_.end());
 
         if (!boost::regex_search(begin, end, matches, re
                                 , boost::match_default | boost::match_partial))
@@ -377,21 +377,21 @@
         bytes_read = impl_.client_.read_some(prepare(32), ec);
         if (ec || (bytes_read == 0))
           return ec;
- buffer_iter begin(impl_.buf_.begin());// + offset);
- buffer_iter end(impl_.buf_.end());
- if (!boost::regex_search(begin, end //impl.buf_.begin(), impl.buf_.end()
+ buffer_iter begin(impl_.buffer_.begin());// + offset);
+ buffer_iter end(impl_.buffer_.end());
+ if (!boost::regex_search(begin, end //impl.buffer_.begin(), impl.buffer_.end()
                                 , matches, re, boost::match_default | boost::match_partial))
         {
- offset = impl_.buf_.size();
+ offset = impl_.buffer_.size();
           continue;
         }
         else
         {
           if (matches[2].matched)
           {
- impl_.buf_.erase(impl_.buf_.begin(), matches[0].second);
+ impl_.buffer_.erase(impl_.buffer_.begin(), matches[0].second);
             offset_ = 0;
- pos_ = impl_.buf_.begin();
+ pos_ = impl_.buffer_.begin();
             return ec;
           }
           else
@@ -411,7 +411,7 @@
       form_parser<T>::parse_boundary_marker(boost::system::error_code& ec)
     {
       // get the meta-data appended to the content_type
- std::string content_type_(impl_.env_vars_["CONTENT_TYPE"]);
+ std::string content_type_(impl_.env_vars()["CONTENT_TYPE"]);
       //BOOST_ASSERT(!content_type.empty());
 
       boost::regex re("; ?boundary=\"?([^\"\n\r]+)\"?");

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/request_base.hpp 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -1,6 +1,24 @@
+// -- common/request_base.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)
+//
+////////////////////////////////////////////////////////////////
+//
+// Defines `request_base` - a base class for all CGI requests.
+// Contains common data members and functionality.
+//
 #ifndef CGI_COMMON_REQUEST_BASE_HPP_INCLUDE_
 #define CGI_COMMON_REQUEST_BASE_HPP_INCLUDE_
 
+#include <string>
+////////////////////////////////////////////////////////////////
+#include <boost/asio/buffer.hpp>
+#include <boost/system/error_code.hpp>
+////////////////////////////////////////////////////////////////
+#include "boost/cgi/common/map.hpp"
 #include "boost/cgi/detail/extract_params.hpp"
 
 namespace cgi {
@@ -14,7 +32,73 @@
   template<typename T>
   class request_base
   {
+ public:
+ /// Find the environment meta-variable matching name
+ template<typename ImplType>
+ std::string& env(ImplType& impl, std::string const& name
+ , boost::system::error_code& ec)
+ {
+ return impl.env_vars()[name.c_str()];
+ }
+
+ template<typename ImplType>
+ std::string& GET(ImplType& impl, std::string const& name
+ , boost::system::error_code& ec)
+ {
+ return impl.get_vars()[name.c_str()];
+ }
+
+ /// Find the post meta-variable matching name
+ /**
+ * @param greedy This determines whether more data can be read to find
+ * the variable. The default is true to cause least surprise in the common
+ * case of having not parsed any of the POST data.
+ */
+ template<typename ImplType>
+ std::string& POST(ImplType& impl, std::string const& name
+ , boost::system::error_code& ec, bool greedy)
+ {
+ // **FIXME** greedy isn't used: it may be unnecessary now though...
+ return impl.post_vars()[name.c_str()];
+ }
+
+ /// Find the cookie meta-variable matching name
+ template<typename ImplType>
+ std::string&
+ cookie(ImplType& impl, std::string const& name
+ , boost::system::error_code& ec)
+ {
+ return impl.cookie_vars()[name.c_str()];
+ }
+
+ template<typename ImplType>
+ int request_id(ImplType& impl)
+ {
+ return impl.client_.request_id_;
+ }
+
   protected:
+ // impl_base is the common base class for all request types'
+ // implementation_type and should be inherited by it.
+ struct impl_base
+ {
+ typedef std::vector<char> buffer_type;
+ typedef boost::asio::const_buffers_1 const_buffers_type;
+ typedef boost::asio::mutable_buffers_1 mutable_buffers_type;
+
+ common::env_map& env_vars() { return boost::fusion::at_c<0>(vars_); }
+ common::get_map& get_vars() { return boost::fusion::at_c<1>(vars_); }
+ common::post_map& post_vars() { return boost::fusion::at_c<2>(vars_); }
+ common::cookie_map& cookie_vars() { return boost::fusion::at_c<3>(vars_); }
+
+ typedef boost::fusion::vector<
+ common::env_map, common::get_map
+ , common::post_map, common::cookie_map
+ > var_map_type;
+
+ var_map_type vars_;
+ buffer_type buffer_;
+ };
     
     /// Read and parse the cgi GET meta variables
     template<typename ImplType>
@@ -24,11 +108,11 @@
       // Make sure the request is in a pre-loaded state
       //BOOST_ASSERT (impl.status() <= unloaded);
 
- std::string& vars(impl.env_vars_["QUERY_STRING"]);
+ std::string const& vars(impl.env_vars()["QUERY_STRING"]);
       if (vars.empty())
         return ec;
 
- detail::extract_params(vars, impl.get_vars_
+ detail::extract_params(vars, impl.get_vars()
                             , boost::char_separator<char>
                                 ("", "=&", boost::keep_empty_tokens)
                             , ec);
@@ -44,18 +128,17 @@
       // Make sure the request is in a pre-loaded state
       //BOOST_ASSERT (impl.status() <= unloaded);
 
- std::string& vars(impl.env_vars_["HTTP_COOKIE"]);
+ std::string const& vars(impl.env_vars()["HTTP_COOKIE"]);
       if (vars.empty())
         return ec;
 
- detail::extract_params(vars, impl.cookie_vars_
+ detail::extract_params(vars, impl.cookie_vars()
                             , boost::char_separator<char>
                                 ("", "=;", boost::keep_empty_tokens)
                             , ec);
 
       return ec;
     }
-
   };
 
  } // namespace common

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_request_impl_base.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_request_impl_base.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_request_impl_base.hpp 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -19,7 +19,9 @@
 #include "boost/cgi/role_type.hpp"
 #include "boost/cgi/status_type.hpp"
 #include "boost/cgi/common/map.hpp"
-//#include
+
+#include <boost/fusion/include/vector.hpp>
+#include <boost/fusion/support.hpp>
 
 // Make this ProtocolService-independent
 
@@ -38,6 +40,7 @@
    */
   template<typename Connection>
   class cgi_request_impl_base
+
   {
   public:
     typedef ::cgi::common::map map_type;
@@ -56,28 +59,17 @@
     {
     }
 
- map_type& env_vars() { return env_vars_; }
- map_type& get_vars() { return get_vars_; }
- map_type& post_vars() { return post_vars_; }
- map_type& cookie_vars() { return cookie_vars_; }
-
     bool stdin_parsed() { return stdin_parsed_; }
     http::status_code& http_status() { return http_status_; }
     status_type& status() { return request_status_; }
 
     conn_ptr& connection() { return connection_; }
- //std::string& null_str() { return null_str_; }
 
   public:
     //conn_ptr connection() { return connection_; }
 
     //friend class cgi_service_impl_base<RequestImpl>;
 
- map_type env_vars_;
- map_type get_vars_;
- map_type post_vars_;
- map_type cookie_vars_;
-
   public:
     bool stdin_parsed_;
     bool stdin_data_read_;

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 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -42,7 +42,7 @@
 
   template<typename RequestImplType>
   class cgi_service_impl_base
- : common::request_base<cgi_service_impl_base<RequestImplType> >
+ : public common::request_base<cgi_service_impl_base<RequestImplType> >
   {
   public:
     //typedef RequestImplType implementation_type;
@@ -59,11 +59,11 @@
 
     struct implementation_type
       : RequestImplType
+ , common::request_base<
+ cgi_service_impl_base<RequestImplType>
+ >::impl_base
     {
- typedef boost::asio::const_buffers_1 const_buffers_type;
- typedef boost::asio::mutable_buffers_1 mutable_buffers_type;
       typedef typename RequestImplType::client_type client_type;
- typedef std::vector<char> buffer_type;
       typedef detail::form_parser<implementation_type> form_parser_type;
 
       implementation_type()
@@ -76,12 +76,7 @@
       // The number of characters left to read (ie. "content_length - bytes_read")
       std::size_t characters_left_;
       
- buffer_type buf_;
-
- std::vector<common::form_part> form_parts_;
-
       boost::scoped_ptr<form_parser_type> fp_;
-
     };
 
     /// Return if the request is still open
@@ -120,11 +115,11 @@
           , boost::system::error_code& ec)
     {
       detail::save_environment(impl.env_vars());
- const std::string& cl = var(impl.env_vars(), "CONTENT_LENGTH", ec);
+ std::string const& cl = impl.env_vars()["CONTENT_LENGTH"];
       impl.characters_left_ = cl.empty() ? 0 : boost::lexical_cast<std::size_t>(cl);
       impl.client_.bytes_left() = impl.characters_left_;
 
- const std::string& request_method = var(impl.env_vars(), "REQUEST_METHOD", ec);
+ std::string const& request_method = impl.env_vars()["REQUEST_METHOD"];
       if (request_method == "GET")
         this->parse_get_vars(impl, ec);
       else
@@ -141,69 +136,6 @@
       return ec;
     }
 
- std::string&
- var(map_type& meta_data, const std::string& name
- , boost::system::error_code& ec)
- {
- return meta_data[name.c_str()];
- }
-
- std::string
- GET(implementation_type& impl, const std::string& name
- , boost::system::error_code& ec)
- {
- //BOOST_ASSERT(impl.status() >= loaded);
- return var(impl.get_vars(), name, ec);
- }
-
- map_type&
- GET(implementation_type& impl)
- {
- //BOOST_ASSERT(impl.status() >= loaded);
- return impl.get_vars();
- }
-
- /// Find the post meta-variable matching name
- /**
- * @param greedy This determines whether more data can be read to find
- * the variable. The default is true to cause least surprise in the common
- * case of having not parsed any of the POST data.
-
- -----------------------------------------------
- Should this return a pair of iterators instead?
- What about url_decoding?
- -----------------------------------------------
-
- */
- std::string
- POST(implementation_type& impl, const std::string& name
- , boost::system::error_code& ec, bool greedy = true)
- {
- //BOOST_ASSERT(impl.status() >= loaded);
- const std::string& val = var(impl.post_vars(), name, ec);
- if (val.empty() && greedy && !ec)
- {
-
- }
-
- return val;
- }
-
- map_type&
- POST(implementation_type& impl)
- {
- //BOOST_ASSERT(impl.status() >= loaded);
- return impl.post_vars();
- }
-
- // prefer this to the above
- map_type&
- POST(implementation_type& impl, boost::system::error_code& ec)
- {
- //BOOST_ASSERT(impl.status() >= loaded);
- return impl.post_vars();
- }
-
     // TODO: use `greedy`
     std::string
       form(implementation_type& impl, const std::string& name
@@ -235,41 +167,6 @@
                           return POST(impl, ec);
                 }
 
- /// Find the cookie meta-variable matching name
- std::string
- cookie(implementation_type& impl, const std::string& name
- , boost::system::error_code& ec)
- {
- //BOOST_ASSERT(impl.status() >= loaded);
- return var(impl.cookie_vars(), name, ec);
- }
-
- map_type&
- cookie(implementation_type& impl)
- {
- //BOOST_ASSERT(impl.status() >= loaded);
- return impl.cookie_vars();
- }
-
-
- /// Find the environment meta-variable matching name
- std::string
- env(implementation_type& impl, const std::string& name
- , boost::system::error_code& ec)
- {
- //BOOST_ASSERT(impl.status() >= loaded);
- const char* c = ::getenv(name.c_str());
- return c ? c : std::string();
- }
-
- map_type&
- env(implementation_type& impl)
- {
- //BOOST_ASSERT(impl.status() >= loaded);
- return impl.env_vars();
- }
-
-
     role_type
       get_role(implementation_type& impl)
     {

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp 2008-04-29 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -260,6 +260,7 @@
     friend class fcgi_request_service;
     boost::uint16_t request_id_;
     client_status status_;
+ std::size_t bytes_left_;
     //request_impl_type* current_request_;
     
     /// A marker to say if the final STDIN (and/or DATA) packets have been

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 22:31:09 EDT (Tue, 29 Apr 2008)
@@ -10,8 +10,9 @@
 #define CGI_FCGI_REQUEST_SERVICE_HPP_INCLUDED__
 
 #include <boost/system/error_code.hpp>
-
-//#include "boost/cgi/scgi/request_impl.hpp"
+#include <boost/fusion/include/vector.hpp>
+#include <boost/fusion/support.hpp>
+////////////////////////////////////////////////////////////////
 #include "boost/cgi/common/map.hpp"
 #include "boost/cgi/common/request_base.hpp"
 #include "boost/cgi/tags.hpp"
@@ -20,9 +21,8 @@
 #include "boost/cgi/io_service.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
 #include "boost/cgi/detail/service_base.hpp"
-#include "boost/cgi/detail/extract_params.hpp"
-//#include "boost/cgi/basic_request.hpp"
 #include "boost/cgi/fcgi/client.hpp"
+#include "boost/cgi/common/form_parser.hpp"
 
 namespace cgi {
 
@@ -59,22 +59,16 @@
   /// 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 common::request_base<fcgi_request_service>
   {
   public:
     /// The actual implementation date for an FCGI request.
     struct implementation_type
+ : common::request_base<fcgi_request_service>::impl_base
     {
- typedef ::cgi::common::map map_type;
- //typedef shareable_tcp_connection connection_type;
       typedef ::cgi::fcgi_ protocol_type;
- //typedef basic_client<
- // connection_type, protocol_type
- //> client_type;
       typedef ::cgi::fcgi::client client_type;
       typedef client_type::connection_type connection_type;
- typedef std::vector<char> buffer_type;
- typedef boost::asio::mutable_buffers_1 mutable_buffers_type;
       typedef client_type::header_buffer_type header_buffer_type;
       typedef detail::protocol_traits<
         protocol_type
@@ -102,14 +96,6 @@
       status_type request_status_;
       fcgi::spec_detail::role_t request_role_;
 
- buffer_type buffer_;
-
- map_type env_vars_;
- map_type get_vars_;
- map_type post_vars_;
- map_type cookie_vars_;
-
- std::string null_str_;
       bool all_done_;
 
       mutable_buffers_type prepare(std::size_t size)
@@ -131,12 +117,14 @@
      /************** New stuff *****************/
       header_buffer_type header_buf_;
       boost::uint16_t id_;
- };
+ typedef detail::form_parser<implementation_type> form_parser_type;
+
+ boost::scoped_ptr<form_parser_type> fp_;
+ };
 
     typedef fcgi_request_service type;
     typedef ::cgi::fcgi::fcgi_request_service full_type;
     typedef type::implementation_type::protocol_type protocol_type;
- typedef type::implementation_type::map_type map_type;
     typedef type::implementation_type::request_type request_type;
 
     fcgi_request_service(::cgi::io_service& ios)
@@ -177,11 +165,6 @@
       return !impl.all_done_ && impl.client_.is_open();
     }
 
- int request_id(implementation_type& impl)
- {
- return impl.client_.request_id_;
- }
-
     /// Close the request.
     int close(implementation_type& impl, http::status_code& hsc
               , int program_status)
@@ -208,10 +191,10 @@
       );
                 
       impl.buffer_.clear();
- impl.get_vars_.clear();
- impl.post_vars_.clear();
- impl.cookie_vars_.clear();
- impl.env_vars_.clear();
+ impl.get_vars().clear();
+ impl.post_vars().clear();
+ impl.cookie_vars().clear();
+ impl.env_vars().clear();
       impl.stdin_parsed_ = false;
       impl.http_status_ = http::no_content;
       impl.request_status_ = null;
@@ -237,7 +220,6 @@
           , boost::system::error_code& ec)
     {
       //int header_len( get_length_of_header(impl, ec) );
- //std::cerr<< "Loading request...";
       BOOST_ASSERT(!ec && "Can't load request due to previous errors.");
 
       impl.client_.construct(impl, ec);
@@ -286,15 +268,13 @@
       if (request_method == "GET")
         if (parse_get_vars(impl, ec))
           return ec;
-/** FIXME **
       else
       if (request_method == "POST" && parse_stdin)
         if (parse_post_vars(impl, ec))
               return ec;
-*/
+
       parse_cookie_vars(impl, ec);
 
- //std::cerr<< "done!" << std::endl;
       return ec;
     }
 
@@ -307,93 +287,6 @@
       );
     }
 
- /* These Don't Belong Here.
- template<typename MutableBufferSequence>
- std::size_t read_some(implementation_type& impl
- , const MutableBufferSequence& buf
- , boost::system::error_code& ec)
- {
- std::size_t s = impl.connection()->read_some(buf, ec);
- return s;
- }
-
- template<typename ConstBufferSequence>
- std::size_t write_some(implementation_type& impl
- , const ConstBufferSequence& buf
- , boost::system::error_code& ec)
- {
- return impl.connection()->write_some(buf, ec);
- }
-
- //template<typename VarType> map_type& var(implementation_type&) const;
- ********************************************/
-
- std::string GET(implementation_type& impl, const std::string& name
- , boost::system::error_code& ec)
- {
- return var(impl.get_vars_, name, ec);
- }
-
- map_type& GET(implementation_type& impl)
- {
- return impl.get_vars_;
- }
-
- /// Find the post meta-variable matching name
- /**
- * @param greedy This determines whether more data can be read to find
- * the variable. The default is true to cause least surprise in the common
- * case of having not parsed any of the POST data.
-
- -----------------------------------------------
- Should this return a pair of iterators instead?
- What about url_decoding?
- -----------------------------------------------
-
- */
- std::string POST(implementation_type& impl, const std::string& name
- , boost::system::error_code& ec
- , bool greedy = true)
- {
- const std::string& val = var(impl.post_vars_, name, ec);
- if (val.empty() && greedy && !ec)
- {
-
- }
-
- return val;
- }
-
- map_type& POST(implementation_type& impl)
- {
- return impl.post_vars_;
- }
-
-
- /// Find the cookie meta-variable matching name
- std::string cookie(implementation_type& impl, const std::string& name
- , boost::system::error_code& ec)
- {
- return var(impl.cookie_vars_, name, ec);
- }
-
- map_type& cookie(implementation_type& impl)
- {
- return impl.cookie_vars_;
- }
-
- /// Find the environment meta-variable matching name
- std::string env(implementation_type& impl, const std::string& name
- , boost::system::error_code& ec)
- {
- return var(impl.env_vars_, name, ec);
- }
-
- map_type& env(implementation_type& impl)
- {
- return impl.env_vars_;
- }
-
     role_type get_role(implementation_type& impl)
     {
       return responder;
@@ -406,71 +299,22 @@
     }
 
   protected:
- /// Extract the var value from
- std::string var(map_type& _data, const std::string& _name
- , boost::system::error_code& ec)
- {
- /* Alt:
- if ((typename map_type::iterator pos = meta_data.find(name))
- != meta_data.end())
- {
- return *pos;
- }
- return std::string();
- **/
-
- if( _data.find(_name.c_str()) != _data.end() )
- // **FIXME**
- 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)
- {
- detail::extract_params(env(impl, "QUERY_STRING", ec)
- , impl.get_vars_
- , boost::char_separator<char>
- ("", "=&", boost::keep_empty_tokens)
- , ec);
-
- return ec;
- }
-
- /// Read and parse the HTTP_COOKIE meta variable
- boost::system::error_code&
- parse_cookie_vars(implementation_type& impl, boost::system::error_code& ec)
- {
- // Make sure this function hasn't already been called
- //BOOST_ASSERT( impl.cookie_vars_.empty() );
-
- std::string vars = env(impl, "HTTP_COOKIE", ec);
- if (vars.empty())
- return ec;
-
- detail::extract_params(env(impl, "HTTP_COOKIE", ec)
- , 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&
     parse_post_vars(implementation_type& impl, boost::system::error_code& ec)
     {
       // Make sure this function hasn't already been called
- //BOOST_ASSERT( impl.post_vars_.empty() );
+ //BOOST_ASSERT( impl.post_vars().empty() );
           
       //# error "Not implemented"
-
- if (impl.stdin_parsed_)
- {
- }
+/*
+ impl.fp_.reset
+ (
+ new typename implementation_type::form_parser_type
+ ( impl )
+ );
+ impl.fp_->parse(ec);
+*/
 
       return ec;
     }
@@ -645,7 +489,7 @@
         //std::cerr<< "[hw] data := " << data << std::endl;
 
         // **FIXME**
- impl.env_vars_[name.c_str()] = data;
+ impl.env_vars()[name.c_str()] = data;
       }
 
       return ec;


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