Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58525 - in sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi: . cgi common connections detail fcgi impl utility
From: lists.drrngrvy_at_[hidden]
Date: 2009-12-24 05:41:23


Author: drrngrvy
Date: 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
New Revision: 58525
URL: http://svn.boost.org/trac/boost/changeset/58525

Log:
Bug fixes for linux.
Removed:
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi.hpp
Text files modified:
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_client.hpp | 6 +
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_request.hpp | 24 ++++-
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/cgi/request_service.hpp | 8 +
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/data_map_proxy.hpp | 1
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/header.hpp | 2
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/response.hpp | 102 ++++++++++++++++++-------
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/connections/async_stdio.hpp | 8 +
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/connections/stdio.hpp | 3
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/throw_error.hpp | 2
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/client.hpp | 24 +++--
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/request_service.hpp | 25 +++---
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/fcgi_request_service.ipp | 4
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/form_parser.ipp | 2
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/response.ipp | 110 +++++----------------------
   sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/utility/stencil.hpp | 154 +++++++++++++++++++++------------------
   15 files changed, 246 insertions(+), 229 deletions(-)

Deleted: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/acgi.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
+++ (empty file)
@@ -1,31 +0,0 @@
-// -- acgi.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_HPP_INCLUDED__
-#define CGI_ACGI_HPP_INCLUDED__
-
-#include "boost/cgi/acgi/service.hpp"
-#include "boost/cgi/acgi/request.hpp"
-#include "boost/cgi/detail/common_headers.hpp"
-
-BOOST_CGI_NAMESPACE_BEGIN
- namespace acgi {
-
- using namespace ::BOOST_CGI_NAMESPACE::common; // import common namespace elements.
-
- } // namespace acgi
-BOOST_CGI_NAMESPACE_END
-
-/// Dump acgi stuff into the boost namespace
-namespace boost {
- namespace acgi {
- using namespace ::BOOST_CGI_NAMESPACE::acgi;
- } // namespace acgi
-} // namespace boost
-
-#endif // CGI_ACGI_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_client.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/basic_client.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -12,11 +12,13 @@
 #include <boost/shared_ptr.hpp>
 ///////////////////////////////////////////////////////////
 #include "boost/cgi/common/map.hpp"
-#include "boost/cgi/http/status_code.hpp"
 #include "boost/cgi/common/role_type.hpp"
 #include "boost/cgi/common/request_status.hpp"
-#include "boost/cgi/detail/protocol_traits.hpp"
 #include "boost/cgi/connections/tcp_socket.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+#include "boost/cgi/detail/protocol_traits.hpp"
+#include "boost/cgi/error.hpp"
+#include "boost/cgi/http/status_code.hpp"
 
 
 BOOST_CGI_NAMESPACE_BEGIN

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-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -48,6 +48,10 @@
 # define BOOST_CGI_POST_MAX 6663322
 #endif // BOOST_CGI_POST_MAX
 
+#ifndef BOOST_CGI_DEFAULT_CHARSET
+# define BOOST_CGI_DEFAULT_CHARSET "UTF-8"
+#endif
+
 BOOST_CGI_NAMESPACE_BEGIN
  
  namespace common {
@@ -102,6 +106,14 @@
     common::data_map_proxy<cookie_map> cookies;
 
     basic_request(
+ int opts
+ , char** base_env = NULL)
+ : detail::basic_io_object<service_type>()
+ {
+ if ((parse_options)opts > parse_none) load((parse_options)opts, base_env);
+ }
+
+ basic_request(
         const parse_options opts = traits::parse_opts
       , char** base_env = NULL)
         : detail::basic_io_object<service_type>()
@@ -587,13 +599,11 @@
     /// Get the charset from the CONTENT_TYPE header
     string_type charset()
     {
- // Not sure if regex is needlessly heavy-weight here.
- boost::regex re(";[ ]?charset=([-\\w]+);");
- boost::smatch match;
- if (!boost::regex_match(this->content_type(), match, re))
- return ""; // A default could go here.
-
- return match[1];
+ string_type ctype(content_type());
+ std::size_t pos = ctype.find("charset=");
+ string_type val(ctype.substr(pos+8, ctype.find(";", pos)));
+ boost::algorithm::trim(val);
+ return val.empty() ? BOOST_CGI_DEFAULT_CHARSET : val;
     }
     
     /// The email of the user making the request.

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-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -36,6 +36,7 @@
 #include "boost/cgi/common/request_base.hpp"
 #include "boost/cgi/common/parse_options.hpp"
 #include "boost/cgi/common/request_status.hpp"
+#include "boost/cgi/connections/async_stdio.hpp"
 #include "boost/cgi/detail/extract_params.hpp"
 #include "boost/cgi/detail/save_environment.hpp"
 
@@ -94,11 +95,10 @@
     {
     }
 
- template<typename ImplType>
- void construct(ImplType& impl)
+ void construct(implementation_type& impl)
     {
       impl.client_.set_connection(
- typename ImplType::connection_type::create(this->get_io_service())
+ implementation_type::connection_type::create(this->get_io_service())
       );
     }
 
@@ -208,10 +208,12 @@
       
       // Return an error, except ignore EOF, as this is expected.
       if (ec)
+ {
         if (ec == boost::cgi::common::error::eof)
           ec = boost::system::error_code();
         else
           return ec;
+ }
 
       return base_type::parse_post_vars(
           impl,

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/data_map_proxy.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/data_map_proxy.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/data_map_proxy.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -3,6 +3,7 @@
 #define BOOST_CGI_DATA_MAP_PROXY_HPP_INCLUDED_20091206_
 
 #include <boost/assert.hpp>
+#include <boost/lexical_cast.hpp>
 ///////////////////////////////////////////////////////////
 #include "boost/cgi/config.hpp"
 

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/header.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/header.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/header.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -48,11 +48,13 @@
      {
      }
 
+ /*
      /// Construct an header from a cookie.
      basic_header(const basic_cookie<char_type>& ck)
        : content("Set-cookie: " + ck.to_string())
      {
      }
+ */
      
      operator string_type () {
         return content + "\r\n";

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/response.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/response.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/common/response.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -123,10 +123,10 @@
 
     /// Set the status code associated with the response.
     basic_response<char_type>&
- set_status(const http::status_code& num);
+ status(const http::status_code& num);
 
     /// Get the status code associated with the response.
- http::status_code& status();
+ http::status_code status() const;
 
     /// Allow more headers to be added (WARNING: avoid using this).
     void unterminate_headers();
@@ -136,6 +136,23 @@
 
     /// Add a header after appending the CRLF sequence.
     basic_response<char_type>&
+ set(basic_header<char_type> const& hdr)
+ {
+ if (hdr.content.empty())
+ end_headers();
+ else
+ set_header(hdr.content);
+ return *this;
+ }
+
+ basic_response<char_type>&
+ set(const basic_cookie<char_type>& ck)
+ {
+ set_header("Set-Cookie", ck.to_string());
+ return *this;
+ }
+
+ basic_response<char_type>&
       set_header(const string_type& value);
       
     /// Get the contents of the response as a string.
@@ -170,10 +187,54 @@
 
     /// Get the headers
     std::vector<string_type>& headers();
-
- template<typename T>
- friend self_type& operator<<(self_type& resp, T t);
 
+ template<typename T>
+ self_type& operator<<(T t)
+ {
+ ostream_<< t;
+ return *this;
+ }
+
+ self_type& operator<< (charset_header<char_type> const& hdr)
+ {
+ charset(hdr.content);
+ return *this;
+ }
+
+ self_type& operator<< (basic_header<char_type> const& hdr)
+ {
+ return set(hdr);
+ }
+
+ self_type& operator<< (basic_cookie<char_type> const& ck)
+ {
+ return set(ck);
+ }
+
+ self_type& operator<< (http::status_code stat)
+ {
+ status(stat);
+ return *this;
+ }
+
+ self_type& operator<< (self_type& other)
+ {
+ if (!headers_terminated())
+ {
+ typedef std::vector<std::string>::const_iterator iter_t;
+ for(iter_t iter (other.headers().begin()), end (other.headers().end());
+ iter != end;
+ ++iter
+ )
+ {
+ if (iter->substr(0,13) != "Content-type:") // Don't overwrite the content-type.
+ headers_.push_back(*iter);
+ }
+ }
+ ostream_<< other.ostream().rdbuf();
+ return *this;
+ }
+
   protected:
    // Vector of all the headers, each followed by a CRLF
     std::vector<string_type> headers_;
@@ -206,20 +267,11 @@
 
 
   /// Generic ostream template
+ /*
   template<typename CharT, typename T>
   BOOST_CGI_NAMESPACE::common::basic_response<CharT>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<CharT>& resp, T const& t);
-
- template<typename CharT>
- BOOST_CGI_NAMESPACE::common::basic_response<CharT>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<CharT>& resp
- , BOOST_CGI_NAMESPACE::common::basic_header<CharT> const& hdr);
-
- template<typename CharT>
- BOOST_CGI_NAMESPACE::common::basic_response<CharT>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<CharT>& resp
- , BOOST_CGI_NAMESPACE::common::charset_header<CharT> const& hdr);
-
+ operator<< (BOOST_CGI_NAMESPACE::common::basic_response<CharT>& resp, T t);
+ */
   /// You can stream a BOOST_CGI_NAMESPACE::cookie into a response.
   /**
    * This is just a shorthand way of setting a header that will set a
@@ -231,21 +283,13 @@
    * http://tinyurl.com/33znkj), but this is outside the scope of this
    * library.
    */
- template<typename charT>
+
+ /*
+ template<typename charT>
   BOOST_CGI_NAMESPACE::common::basic_response<charT>&
     operator<< (BOOST_CGI_NAMESPACE::common::basic_response<charT>&
                , BOOST_CGI_NAMESPACE::common::basic_cookie<charT>);
-
- template<typename charT, typename T>
- BOOST_CGI_NAMESPACE::common::basic_response<charT>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<charT>&
- , BOOST_CGI_NAMESPACE::common::http::status_code);
-
- template<typename charT, typename T>
- BOOST_CGI_NAMESPACE::common::basic_response<charT>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<charT>&
- , BOOST_CGI_NAMESPACE::common::basic_response<charT>&);
-
+ */
 #include "boost/cgi/detail/pop_options.hpp"
 
 #if !defined(BOOST_CGI_BUILD_LIB)

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/connections/async_stdio.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/connections/async_stdio.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/connections/async_stdio.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -21,7 +21,13 @@
 BOOST_CGI_NAMESPACE_BEGIN
  namespace common {
 
- // Asynchronous access to stdio
+ // Asynchronous access to stdio.
+ /**
+ * This class doesn't do real async I/O, but fakes it by posting
+ * a read / write to an io_service, which may be run in a background
+ * thread. On most systems this won't actually mean true async I/O,
+ * but this emulates it as an interim solution.
+ */
   template<>
   class basic_connection<tags::async_stdio>
     : public basic_connection<tags::stdio>

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/connections/stdio.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/connections/stdio.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/connections/stdio.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -11,9 +11,6 @@
 
 #include <cstdio>
 #include <string>
-# include <stdio.h> // for _setmode
-# include <io.h> // for _setmode
-# include <fcntl.h> // for _setmode
 #if BOOST_WINDOWS
 # include <stdio.h> // for _setmode
 # include <io.h> // for _setmode

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/throw_error.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/throw_error.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/detail/throw_error.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -12,6 +12,8 @@
 #include <boost/system/error_code.hpp>
 #include <boost/system/system_error.hpp>
 #include <boost/throw_exception.hpp>
+/////////////////////////////////////////////////
+#include "boost/cgi/config.hpp"
 
 BOOST_CGI_NAMESPACE_BEGIN
  namespace detail {

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/client.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/fcgi/client.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -15,23 +15,27 @@
 #include <boost/logic/tribool.hpp>
 #include <boost/asio/buffer.hpp>
 ///////////////////////////////////////////////////////////
-#include "boost/cgi/error.hpp"
+#include "boost/cgi/basic_client.hpp"
 #include "boost/cgi/common/map.hpp"
 #include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/connections/shareable_tcp_socket.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+#include "boost/cgi/detail/protocol_traits.hpp"
+#include "boost/cgi/fcgi/specification.hpp"
+#include "boost/cgi/fwd/basic_request_fwd.hpp"
+#include "boost/cgi/error.hpp"
 #include "boost/cgi/import/read.hpp"
-#include "boost/cgi/basic_client.hpp"
 #include "boost/cgi/import/buffer.hpp"
 #include "boost/cgi/import/io_service.hpp"
-#include "boost/cgi/fcgi/specification.hpp"
-#include "boost/cgi/detail/throw_error.hpp"
-#include "boost/cgi/fwd/basic_request_fwd.hpp"
-#include "boost/cgi/detail/protocol_traits.hpp"
-#include "boost/cgi/connections/shareable_tcp_socket.hpp"
 
 #undef min
 #undef max
 #include <algorithm>
 
+#ifndef NDEBUG
+# include <iostream>
+#endif
+
 BOOST_CGI_NAMESPACE_BEGIN
  namespace common {
 
@@ -44,11 +48,11 @@
>::basic_client()
     : request_id_(-1)
     , status_(none_)
- , keep_connection_(false)
     , total_sent_bytes_(0)
     , total_sent_packets_(0)
     , header_()
     , outbuf_()
+ , keep_connection_(false)
   {
   }
 
@@ -60,11 +64,11 @@
>::basic_client(io_service_type& ios)
     : request_id_(-1)
     , status_(none_)
- , keep_connection_(false)
     , total_sent_bytes_(0)
     , total_sent_packets_(0)
     , header_()
     , outbuf_()
+ , keep_connection_(false)
   {
   }
 
@@ -186,7 +190,7 @@
     // doesn't care about them.
     bytes_transferred -= fcgi::spec::header_length::value;
     // Check everything was written ok.
- if (!ec && bytes_transferred != total_buffer_size)
+ if (!ec && bytes_transferred != static_cast<std::size_t>(total_buffer_size))
       ec = ::BOOST_CGI_NAMESPACE::fcgi::error::couldnt_write_complete_packet;
 
     return bytes_transferred;

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-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -13,19 +13,20 @@
 #include <boost/system/error_code.hpp>
 #include <boost/fusion/include/vector.hpp>
 ////////////////////////////////////////////////////////////////
+#include "boost/cgi/common/form_parser.hpp"
 #include "boost/cgi/common/map.hpp"
+#include "boost/cgi/common/parse_options.hpp"
+#include "boost/cgi/common/request_base.hpp"
+#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/common/source_enums.hpp"
 #include "boost/cgi/common/tags.hpp"
+#include "boost/cgi/connections/shareable_tcp_socket.hpp"
+#include "boost/cgi/detail/service_base.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
 #include "boost/cgi/fcgi/client.hpp"
-#include "boost/cgi/import/read.hpp"
 #include "boost/cgi/http/status_code.hpp"
-#include "boost/cgi/common/role_type.hpp"
+#include "boost/cgi/import/read.hpp"
 #include "boost/cgi/import/io_service.hpp"
-#include "boost/cgi/detail/throw_error.hpp"
-#include "boost/cgi/common/form_parser.hpp"
-#include "boost/cgi/common/source_enums.hpp"
-#include "boost/cgi/common/request_base.hpp"
-#include "boost/cgi/detail/service_base.hpp"
-#include "boost/cgi/common/parse_options.hpp"
 
 BOOST_CGI_NAMESPACE_BEGIN
  namespace fcgi {
@@ -44,7 +45,8 @@
       typedef spec_detail::Header header_type;
 
       implementation_type()
- : id_(0)
+ : base_type::impl_base()
+ , id_(0)
         , request_role_(spec_detail::ANY)
       {
       }
@@ -84,11 +86,10 @@
     {
     }
 
- template<typename ImplType>
- void construct(ImplType& impl)
+ void construct(implementation_type& impl)
     {
       impl.client_.set_connection(
- typename ImplType::connection_type::create(this->get_io_service())
+ implementation_type::connection_type::create(this->get_io_service())
       );
     }
 

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-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -644,8 +644,8 @@
         //std::cerr<< "**FIXME** Role: "
         // << fcgi::spec::begin_request::get_role(impl.header_buf_) << std::endl;
 
- implementation_type::client_type::connection_type&
- conn = *impl.client_.connection();
+ //implementation_type::client_type::connection_type&
+ // conn = *impl.client_.connection();
       }
       return ec;
     }

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-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -191,7 +191,7 @@
               internal_filename.c_str()
             , std::ios::out | std::ios::binary);
           file<< content;
- file.flush();
+ //file.flush();
         }
       }
       // Load the data to the request's post map.

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/response.ipp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/response.ipp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/impl/response.ipp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -19,16 +19,18 @@
 #include <boost/bind.hpp>
 #include <boost/foreach.hpp>
 ///////////////////////////////////////////////////////////
-#include "boost/cgi/import/write.hpp"
-#include "boost/cgi/import/buffer.hpp"
+#include "boost/cgi/config.hpp"
+
 #include "boost/cgi/common/cookie.hpp"
 #include "boost/cgi/common/header.hpp"
+#include "boost/cgi/common/name.hpp"
 #include "boost/cgi/common/response.hpp"
-#include "boost/cgi/http/status_code.hpp"
-#include "boost/cgi/import/streambuf.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
 #include "boost/cgi/fwd/basic_request_fwd.hpp"
-#include "boost/cgi/config.hpp"
+#include "boost/cgi/http/status_code.hpp"
+#include "boost/cgi/import/buffer.hpp"
+#include "boost/cgi/import/streambuf.hpp"
+#include "boost/cgi/import/write.hpp"
 
 /// A macro to output an implicit Content-type.
 /**
@@ -299,7 +301,7 @@
   /// Set the status code associated with the response.
   template<typename T> BOOST_CGI_INLINE
   basic_response<T>&
- basic_response<T>::set_status(const http::status_code& num)
+ basic_response<T>::status(const http::status_code& num)
   {
     http_status_ = num;
     return *this;
@@ -307,8 +309,8 @@
 
   /// Get the status code associated with the response.
   template<typename T> BOOST_CGI_INLINE
- http::status_code&
- basic_response<T>::status()
+ http::status_code
+ basic_response<T>::status() const
   {
     return http_status_;
   }
@@ -335,7 +337,7 @@
     string_type body;
     if (include_header)
     {
- typedef std::vector<string_type>::const_iterator iter_t;
+ typedef typename std::vector<string_type>::const_iterator iter_t;
       for (
         iter_t iter(headers_.begin()), end(headers_.end());
         iter != end;
@@ -441,7 +443,7 @@
     if (!headers_terminated_)
       headers_.push_back("\r\n");
 
- typedef std::vector<string_type>::iterator iter_t;
+ typedef typename std::vector<string_type>::iterator iter_t;
     for (
       iter_t iter(headers_.begin()), end(headers_.end());
       iter != end;
@@ -460,19 +462,21 @@
     headers_terminated_ = true;
   }
 
+ template<typename T> BOOST_CGI_INLINE
+ BOOST_CGI_NAMESPACE::common::basic_response<T>&
+ operator<< (BOOST_CGI_NAMESPACE::common::basic_response<T>& resp
+ , BOOST_CGI_NAMESPACE::common::basic_cookie<T> const& ck)
+ {
+ BOOST_ASSERT(!resp.headers_terminated());
+ resp.set_header("Set-cookie", ck.to_string());
+ return resp;
+ }
+
  } // namespace common
 
 BOOST_CGI_NAMESPACE_END
 
   /// Generic ostream template
- template<typename T, typename U> BOOST_CGI_INLINE
- BOOST_CGI_NAMESPACE::common::basic_response<T>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<T>& resp, U const& u)
- {
- resp.ostream()<< u;
- return resp;
- }
-
   /// You can stream a BOOST_CGI_NAMESPACE::header into a response.
   /**
    * This is just a more convenient way of doing:
@@ -488,31 +492,6 @@
    * effects; for instance, it won't write any data to the client.
    * ]
    */
- template<typename CharT> BOOST_CGI_INLINE
- BOOST_CGI_NAMESPACE::common::basic_response<CharT>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<CharT>& resp
- , BOOST_CGI_NAMESPACE::common::basic_header<CharT> const& hdr)
- {
- if (hdr.content.empty()) {
- resp.end_headers();
- return resp;
- }else{
- // We shouldn't allow headers to be sent after they're explicitly ended.
- BOOST_ASSERT(!resp.headers_terminated());
- resp.set_header(hdr.content);
- return resp;
- }
- }
-
- template<typename CharT> BOOST_CGI_INLINE
- BOOST_CGI_NAMESPACE::common::basic_response<CharT>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<CharT>& resp
- , BOOST_CGI_NAMESPACE::common::charset_header<CharT> const& hdr)
- {
- resp.charset(hdr.content);
- return resp;
- }
-
   /// You can stream a BOOST_CGI_NAMESPACE::cookie into a response.
   /**
    * This is just a shorthand way of setting a header that will set a
@@ -524,51 +503,6 @@
    * or \url http://tinyurl.com/33znkj), but this is outside the scope of
    * this library.
    */
- template<typename T> BOOST_CGI_INLINE
- BOOST_CGI_NAMESPACE::common::basic_response<T>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<T>& resp
- , BOOST_CGI_NAMESPACE::common::basic_cookie<T> ck)
- {
- BOOST_ASSERT(!resp.headers_terminated());
- resp.set_header("Set-cookie", ck.to_string());
- return resp;
- }
-/*
- template<typename T> BOOST_CGI_INLINE
- BOOST_CGI_NAMESPACE::common::basic_response<T>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<T>& resp
- , BOOST_CGI_NAMESPACE::common::basic_cookie<T> const& ck)
- {
- BOOST_ASSERT(!resp.headers_terminated());
- resp.set_header("Set-cookie", ck.to_string());
- return resp;
- }
-*/
- template<typename T> BOOST_CGI_INLINE
- BOOST_CGI_NAMESPACE::common::basic_response<T>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<T>& resp
- , BOOST_CGI_NAMESPACE::common::http::status_code status)
- {
- BOOST_ASSERT(!resp.headers_terminated());
- return resp.set_status(status);
- }
-
- template<typename charT> BOOST_CGI_INLINE
- BOOST_CGI_NAMESPACE::common::basic_response<charT>&
- operator<< (BOOST_CGI_NAMESPACE::common::basic_response<charT>& resp
- , BOOST_CGI_NAMESPACE::common::basic_response<charT>& other_resp)
- {
- BOOST_ASSERT(!resp.headers_terminated());
- for(std::vector<std::string>::iterator iter = other_resp.headers().begin(), end = other_resp.headers().end();
- iter != end; ++iter)
- {
- if (iter->substr(0,13) != "Content-type:") // Don't overwrite the content-type.
- resp.headers().push_back(*iter);
- }
- resp.ostream()<< other_resp.ostream().rdbuf();
- return resp;
- }
-
 
 #undef BOOST_CGI_ADD_DEFAULT_HEADER
 

Modified: sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/utility/stencil.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/utility/stencil.hpp (original)
+++ sandbox/SOC/2007/cgi/branches/pickmeup/boost/cgi/utility/stencil.hpp 2009-12-24 05:41:20 EST (Thu, 24 Dec 2009)
@@ -38,10 +38,19 @@
 class section
 {
 public:
- typedef std::string string_type;
+ typedef char char_type;
+ typedef std::basic_string<char_type> string_type;
   
   section() {}
   section(
+ const char_type* name,
+ const char_type* filename = ""
+ )
+ : name(name)
+ , filename(filename)
+ {
+ }
+ section(
       string_type const& name,
       string_type const& filename = ""
     )
@@ -82,15 +91,7 @@
     return *this;
   }
 
- /// Set the varible `name` to `value` in the stencil.
- template<>
- self_type& set(string_type const& name, string_type const& value)
- {
- impl->SetValue(name, value);
- return *this;
- }
-
- /// Set a variable and show a section in one go.
+ /// Set a variable and show a section in one go.
   template<typename T>
   self_type& set(string_type const& name, T value, section const& sec)
   {
@@ -102,22 +103,15 @@
     return *this;
   }
   
- /// Set a variable and show a section in one go.
- template<>
- self_type& set(
- string_type const& name,
- string_type const& value,
- section const& sec
- )
- {
- impl->SetValueAndShowSection(name, value, sec.name);
- return *this;
- }
-
   /// Show a section.
- self_type& show(string_type const& section_name)
+ self_type& show(section const& sec)
   {
- impl->ShowSection(section_name);
+ if (sec.filename.empty())
+ impl->ShowSection(sec.name);
+ else {
+ dictionary d = include(sec);
+ impl->ShowSection(sec.name);
+ }
     return *this;
   }
 
@@ -170,21 +164,35 @@
     return d;
   }
 
- /// Add a section into the stencil.
- dictionary add(string_type const& section_name)
- {
- dictionary d;
- d.impl = impl->AddSectionDictionary(section_name);
- return d;
- }
-
   impl_type* impl;
 };
 
-}
+ /// Set the varible `name` to `value` in the stencil.
+ template<>
+ dictionary& dictionary::set(string_type const& name, string_type const& value)
+ {
+ impl->SetValue(name, value);
+ return *this;
+ }
+
+ /// Set a variable and show a section in one go.
+ template<>
+ dictionary& dictionary::set(
+ string_type const& name,
+ string_type const& value,
+ section const& sec
+ )
+ {
+ impl->SetValueAndShowSection(name, value, sec.name);
+ return *this;
+ }
+
+ }
 
 namespace boost { namespace cgi { namespace common {
 
+ using namespace stencils;
+
 class stencil
   : public boost::cgi::common::response
 {
@@ -204,19 +212,19 @@
   };
   
   stencil(impl_type* parent_dict)
- : dict(parent_dict->MakeCopy("response"))
+ : impl(parent_dict->MakeCopy("response"))
   {
   }
   
   stencil(string_type const& root_dir = "")
- : dict(new impl_type("response"))
+ : impl(new impl_type("response"))
   {
     if (!root_dir.empty())
       ctemplate::Template::SetTemplateRootDirectory(root_dir);
   }
   
   /// Get the implementation type of the template.
- impl_type& impl() { return *dict; }
+ impl_type& native() { return *impl; }
 
   bool expand(
       string_type const& template_name,
@@ -242,7 +250,7 @@
     
     // Expand the template and write it to the response.
     string_type body;
- tmpl->Expand(&body, dict.get());
+ tmpl->Expand(&body, impl.get());
     write(body);
 
     // All ok.
@@ -255,7 +263,7 @@
     )
   {
     dictionary d;
- d.impl = dict->AddIncludeDictionary(section_name);
+ d.impl = impl->AddIncludeDictionary(section_name);
     d.impl->SetFilename(filename);
     return d;
   }
@@ -263,7 +271,7 @@
   dictionary include(section const& sec)
   {
     dictionary d;
- d.impl = dict->AddIncludeDictionary(sec.name);
+ d.impl = impl->AddIncludeDictionary(sec.name);
     d.impl->SetFilename(sec.filename);
     return d;
   }
@@ -271,14 +279,7 @@
   dictionary add(section const& sec)
   {
     dictionary d;
- d.impl = dict->AddSectionDictionary(sec.name);
- return d;
- }
-
- dictionary add(string_type const& section_name)
- {
- dictionary d;
- d.impl = dict->AddSectionDictionary(section_name);
+ d.impl = impl->AddSectionDictionary(sec.name);
     return d;
   }
 
@@ -292,23 +293,15 @@
   template<typename T>
   self_type& set(string_type const& name, T value)
   {
- dict->SetValue(name, boost::lexical_cast<string_type>(value));
+ impl->SetValue(name, boost::lexical_cast<string_type>(value));
     return *this;
   }
 
- /// Set the varible `name` to `value` in the stencil.
- template<>
- self_type& set(string_type const& name, string_type const& value)
- {
- dict->SetValue(name, value);
- return *this;
- }
-
   /// Set a variable and show a section in one go.
   template<typename T>
   self_type& set(string_type const& name, T value, section const& sec)
   {
- dict->SetValueAndShowSection(
+ impl->SetValueAndShowSection(
         name,
         boost::lexical_cast<string_type>(value),
         sec.name
@@ -316,30 +309,49 @@
     return *this;
   }
   
+ /// Show a section.
+ self_type& show(section const& sec)
+ {
+ if (sec.filename.empty())
+ impl->ShowSection(sec.name);
+ else {
+ dictionary d = include(sec);
+ impl->ShowSection(sec.name);
+ }
+ return *this;
+ }
+
+ stencil_type* tmpl;
+ boost::scoped_ptr<impl_type> impl;
+ bool expanded;
+};
+
+ /// Set the varible `name` to `value` in the stencil.
+ template<>
+ stencil& stencil::set(string_type const& name, string_type const& value)
+ {
+ impl->SetValue(name, value);
+ return *this;
+ }
+
   /// Set a variable and show a section in one go.
   template<>
- self_type& set(
+ stencil& stencil::set(
       string_type const& name,
       string_type const& value,
       section const& sec
     )
   {
- dict->SetValueAndShowSection(name, value, sec.name);
- return *this;
- }
-
- /// Show a section.
- self_type& show(string_type const& section_name)
- {
- dict->ShowSection(section_name);
+ impl->SetValueAndShowSection(name, value, sec.name);
     return *this;
   }
 
- stencil_type* tmpl;
- boost::scoped_ptr<impl_type> dict;
- bool expanded;
-};
-
 } } } // namespace boost::cgi::common
 
+namespace boost { namespace cgi {
+
+ using common::stencil;
+
+} } // namespace boost::cgi
+
 #endif // BOOST_CGI_UTILITY_STENCIL_HPP_INCLUDED_20091222_


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