Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2008-04-29 17:08:36


Author: drrngrvy
Date: 2008-04-29 17:08:35 EDT (Tue, 29 Apr 2008)
New Revision: 44898
URL: http://svn.boost.org/trac/boost/changeset/44898

Log:
* Added basic_request<>::id() member function.
* Changed basic_request<>::operator[] so that it decides at compile-time rather than runtime what data map is being accessed.
* Added additional typedefs env_map, get_map, post_map, cookie_map, form_map corresponding to the dataset they obviously refer to - for now they are just typedefs to cgi::common::map, but eventually they may change - only to make code safer (eg. protect the user against XSS vulnerabilities).

Added:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/source_enums.hpp (contents, props changed)
Removed:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/data_sink.hpp
   sandbox/SOC/2007/cgi/trunk/boost/cgi/data_source.hpp
Text files modified:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp | 72 ++++++++++++++++++++++-----------------
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/map.hpp | 6 +++
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp | 2 +
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp | 2 +
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp | 19 ++-------
   5 files changed, 56 insertions(+), 45 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 17:08:35 EDT (Tue, 29 Apr 2008)
@@ -28,7 +28,7 @@
 #include "boost/cgi/detail/protocol_traits.hpp"
 #include "boost/cgi/request_base.hpp"
 #include "boost/cgi/role_type.hpp"
-#include "boost/cgi/data_source.hpp"
+#include "boost/cgi/common/source_enums.hpp"
 #include "boost/cgi/status_type.hpp"
 #include "boost/cgi/is_async.hpp"
 #include "boost/cgi/connection_base.hpp"
@@ -506,7 +506,7 @@
      * provide a meta_var_all() function which is greedy; the
      * ugly/long name there to discourage use.
      */
- std::string var(const std::string& name, bool greedy = false)
+ std::string var(std::string const& name, bool greedy = false)
     {
       boost::system::error_code ec;
       std::string ret = var(name, ec, greedy);
@@ -620,43 +620,53 @@
       return this->service.get_role(this->implementation);
     }
 
- /// Get the strand associated with the request (if any)
- // Not sure if the strand concept should be kept separate or a member
- // function like basic_request<>::wrap() should be provided: in the case of
- // a synchronous request type the wrapping would still function as expected
- // and there would be no need for protocol-specific code in user programs.
- /* boost::asio::strand* strand()
+ void set_status(http::status_code const& status)
     {
- return this->implementation.strand();
+ this->service.set_status(this->implementation, status);
     }
- */
 
- /// Get the implementation type for the request
- //implementation_type* impl()
- //{
- // return &(this->implementation);
- //}
+ ////////////////////////////////////////////////////////////
+ // Note on operator[]
+ // ------------------
+ // It is overloaded on different enum types to allow
+ // compile-time (I hope) retrieval of different data
+ // maps.
+ //
+ env_map& operator[](common::env_data_type const&)
+ {
+ return this->implementation.env_vars_;
+ }
 
- void set_status(http::status_code status)
+ get_map& operator[](common::get_data_type const&)
     {
- this->service.set_status(this->implementation, status);
+ return this->implementation.get_vars_;
     }
 
- map_type& operator[](common::data_source source)
+ post_map& operator[](common::post_data_type const&)
     {
- switch(source)
- {
- case get_data: return this->implementation.get_vars_;
- case post_data: return this->implementation.post_vars_;
- case cookie_data: return this->implementation.cookie_vars_;
- case env_data: return this->implementation.env_vars_;
- case form_data:
- default:
- std::string rm( request_method() );
- if (rm == "GET") return this->implementation.get_vars_;
- else if (rm == "POST") return this->implementation.post_vars_;
- else return this->implementation.env_vars_;
- }
+ return this->implementation.post_vars_;
+ }
+
+ cookie_map& operator[](common::cookie_data_type const&)
+ {
+ return this->implementation.cookie_vars_;
+ }
+
+ form_map& operator[](common::form_data_type const&)
+ {
+ if (request_method() == "GET")
+ return this->implementation.get_vars_;
+ else
+ if (request_method() == "POST")
+ return this->implementation.post_vars_;
+ else
+ return this->implementation.env_vars_;
+ }
+ ////////////////////////////////////////////////////////////
+
+ int id()
+ {
+ return this->service.request_id(this->implementation);
     }
   };
 

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/map.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/map.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/map.hpp 2008-04-29 17:08:35 EDT (Tue, 29 Apr 2008)
@@ -9,6 +9,12 @@
 
   typedef std::map< ::cgi::common::name, std::string> map;
 
+ typedef map env_map;
+ typedef map get_map;
+ typedef map post_map;
+ typedef map form_map;
+ typedef map cookie_map;
+
  } // namespace common
 } // namespace cgi
 

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/source_enums.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/source_enums.hpp 2008-04-29 17:08:35 EDT (Tue, 29 Apr 2008)
@@ -0,0 +1,18 @@
+
+#ifndef BOOST_CGI_COMMON_SOURCE_ENUMS_HPP_INCLUDED__
+#define BOOST_CGI_COMMON_SOURCE_ENUMS_HPP_INCLUDED__
+
+namespace cgi {
+ namespace common {
+
+ enum get_data_type { get_data };
+ enum post_data_type { post_data };
+ enum cookie_data_type { cookie_data };
+ enum env_data_type { env_data };
+ enum form_data_type { form_data };
+
+ } // namespace common
+} // namespace cgi
+
+#endif // BOOST_CGI_COMMON_SOURCE_ENUMS_HPP_INCLUDED__
+

Deleted: sandbox/SOC/2007/cgi/trunk/boost/cgi/data_sink.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/data_sink.hpp 2008-04-29 17:08:35 EDT (Tue, 29 Apr 2008)
+++ (empty file)
@@ -1,27 +0,0 @@
-// -- data_sink.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_DATA_SINK_HPP_INCLUDED__
-#define CGI_DATA_SINK_HPP_INCLUDED__
-
-namespace cgi {
-
- enum sink
- { stdout_ = 0
- , stderr_ = 1
- };
-
- namespace data_sink {
-
- //struct stdout_ {};
- //struct stderr_ {};
-
- } // namespace data_sink
-} // namespace cgi
-
-#endif // CGI_DATA_SINK_HPP_INCLUDED__

Deleted: sandbox/SOC/2007/cgi/trunk/boost/cgi/data_source.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/data_source.hpp 2008-04-29 17:08:35 EDT (Tue, 29 Apr 2008)
+++ (empty file)
@@ -1,30 +0,0 @@
-// -- data_source.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_DATA_SOURCE_HPP_INCLUDED__
-#define CGI_DATA_SOURCE_HPP_INCLUDED__
-
-namespace cgi {
-
- enum source
- { stdin_ };
-
- namespace common {
-
- enum data_source
- { get_data
- , post_data
- , cookie_data
- , env_data
- , form_data
- };
-
- } // namespace common
-} // namespace cgi
-
-#endif // CGI_DATA_SOURCE_HPP_INCLUDED__

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 17:08:35 EDT (Tue, 29 Apr 2008)
@@ -100,6 +100,8 @@
       return impl.client_;
     }
 
+ int request_id(implementation_type& impl) { return 1; }
+
     int close(implementation_type& impl, http::status_code& http_s, int status)
     {
       impl.status() = closed;

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 17:08:35 EDT (Tue, 29 Apr 2008)
@@ -254,6 +254,8 @@
       return keep_connection_;
     }
 
+ //int id() { return request_id_; }
+
   public:
     friend class fcgi_request_service;
     boost::uint16_t request_id_;

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 17:08:35 EDT (Tue, 29 Apr 2008)
@@ -122,18 +122,6 @@
         //{
           buffer_.resize(bufsz + size);
         //}
- /*
- cerr<< "Pre-read buffer (size: " << buffer_.size()
- << "|capacity: " << buffer_.capacity() << ") == {" << endl
- << std::string(buffer_.begin(), buffer_.end()) << endl
- // << "-----end buffer-----" << endl
- // << "-------buffer-------" << endl
- // << std::string(&buf_[0], &buf_[buf_.size()]) << endl
- << "}" << endl;
- ;
- */
- //return boost::asio::buffer(&(*(buf_.end())), size);
- // return boost::asio::buffer(&(*(buf_.begin())) + bufsz, size);
         return boost::asio::buffer(&buffer_[bufsz], size);
       }
 
@@ -160,11 +148,9 @@
 
     void construct(implementation_type& impl)
     {
- //std::cerr<< "request_service.hpp:83 Creating connection" << std::endl;
       impl.client_.set_connection(//new implementation_type::connection_type(this->io_service()));
         implementation_type::connection_type::create(this->io_service())
       );
- //std::cerr<< "conn.is_open() == " << impl.client_.is_open() << std::endl;
     }
 
     void destroy(implementation_type& impl)
@@ -189,6 +175,11 @@
       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)


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