$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r60795 - in sandbox/SOC/2007/cgi/trunk: boost/cgi boost/cgi/common boost/cgi/detail boost/cgi/fwd boost/cgi/impl boost/cgi/utility libs/cgi/build/msvc/9.0/Boost.CGI libs/cgi/build/msvc/9.0/Boost.CGI/cgi_ctemplate_cookie_game libs/cgi/build/msvc/9.0/Boost.CGI/cgi_sessions libs/cgi/example/cgi/custom_sessions libs/cgi/example/cgi/sessions
From: lists.drrngrvy_at_[hidden]
Date: 2010-03-23 21:06:52
Author: drrngrvy
Date: 2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
New Revision: 60795
URL: http://svn.boost.org/trac/boost/changeset/60795
Log:
* Changes to the way sessions work (should be in a working state now).
* Changed the default session implementation to std::map<string,string>, when BOOST_CGI_ENABLE_SESSIONS is defined.
* Add put(char) to data_map_proxy.
* Cleanup sessions example.
* Add custom_sessions example.
* Other cleanups
Added:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fwd/data_map_proxy_fwd.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fwd/sessions_fwd.hpp   (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/custom_sessions/
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/custom_sessions/main.cpp
      - copied, changed from r60226, /sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/sessions/main.cpp
Removed:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/return.hpp
Text files modified: 
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request.hpp                                                                  |    16 +++--                                   
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/commit.hpp                                                                  |    19 +++++-                                  
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/cookie.hpp                                                                  |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/data_map_proxy.hpp                                                          |     4 +                                       
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/protocol_traits.hpp                                                         |    52 +++++++++++------                       
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp                                                                |     3 +                                       
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/role_type.hpp                                                               |     9 +++                                     
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/tags.hpp                                                                    |     2                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/config.hpp                                                                         |    18 +++++                                   
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/common_headers.hpp                                                          |     1                                         
   sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/response.ipp                                                                  |     8 ++                                      
   sandbox/SOC/2007/cgi/trunk/boost/cgi/utility/sessions.hpp                                                               |   118 ++++++++++++++++++++++++++++++--------- 
   sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/Boost.CGI.sln                                              |     6 ++                                      
   sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/cgi_ctemplate_cookie_game/cgi_ctemplate_cookie_game.vcproj |     2                                         
   sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/cgi_sessions/cgi_sessions.vcproj                           |     4 -                                       
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/custom_sessions/main.cpp                                                |    79 +++++---------------------              
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/sessions/main.cpp                                                       |    79 +++++---------------------              
   17 files changed, 229 insertions(+), 193 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	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -195,19 +195,21 @@
     /// Start a session, or load the session from a cookie.
     void start_session()
     {
-      if (!session.loaded() && session.id().empty())
+      if (!session.loaded())
       {
         // Assume cookies have been loaded. This will throw at runtime (in
         // a debug build) if `request.load(parse_cookie)` hasn't been called
         // by now.
-        string_type ssid (cookies.pick(BOOST_CGI_SESSION_COOKIE_NAME, ""));
-        if (!ssid.empty()) {
-          session.id(ssid);
-          this->service.session_manager().load(session);
-        } else
-          session.id(this->service.make_session_id());
+        this->service.session_manager().start(
+            session, cookies.pick(BOOST_CGI_SESSION_COOKIE_NAME, ""));
       }
     }
+
+    /// Stop the session and delete the stored session data.
+    void stop_session()
+    {
+      this->service.session_manager().stop(session);
+    }
 #endif // BOOST_CGI_ENABLE_SESSIONS
 
     protocol_service_type& get_protocol_service()
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/commit.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/commit.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/commit.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -5,7 +5,6 @@
 #include <map>
 #include <boost/system/error_code.hpp>
 ///////////////////////////////////////////////////////////
-#include "boost/cgi/common/return.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
 #include "boost/cgi/config.hpp"
 
@@ -24,13 +23,27 @@
     }
 
     /// Send a response to a reqest and close off the request.
+    /**
+     * This sends the response and commits the session data.
+     */
     template<typename Request, typename Response>
     int commit(Request& req, Response& resp, int program_status
               , boost::system::error_code& ec)
     {
+      typedef typename Request::string_type string_type;
 #ifdef BOOST_CGI_ENABLE_SESSIONS
-      if (!program_status && !req.session.id().empty())
-        resp<< cookie(BOOST_CGI_SESSION_COOKIE_NAME, req.session.id());
+      if (!program_status)
+      {
+        string_type path(
+            Request::traits::session_options == path_session
+              ? req.script_name()
+              : "/"
+          );
+        if (req.session.id().empty())
+          resp<< cookie(BOOST_CGI_SESSION_COOKIE_NAME, "", path, BOOST_CGI_DATE_IN_THE_PAST);
+        else
+          resp<< cookie(BOOST_CGI_SESSION_COOKIE_NAME, req.session.id(), path);
+      }
 #endif // BOOST_CGI_ENABLE_SESSIONS
       resp.send(req.client(), ec);
       return ec ? -1 : req.close(resp.status(), program_status, ec);
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/cookie.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/cookie.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/cookie.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -71,8 +71,8 @@
 
     /// Create a cookie.
     basic_cookie(const string_type& _name, const string_type& _val
-                , const string_type& _expires = ""
                 , const string_type& _path = "/"
+                , const string_type& _expires = ""
                 , const string_type& _domain = ""
                 , bool _secure = false
                 , bool HttpOnly = false)
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/data_map_proxy.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/data_map_proxy.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/data_map_proxy.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -2,6 +2,7 @@
 #ifndef BOOST_CGI_DATA_MAP_PROXY_HPP_INCLUDED_20091206_
 #define BOOST_CGI_DATA_MAP_PROXY_HPP_INCLUDED_20091206_
 
+#include <exception>
 #include <boost/assert.hpp>
 #include <boost/lexical_cast.hpp>
 ///////////////////////////////////////////////////////////
@@ -41,8 +42,9 @@
    * into a type the user specifies.
    */
   template<typename MapType>
-  struct data_map_proxy
+  class data_map_proxy
   {
+  public:
     typedef MapType                                   map_type;
     typedef data_map_proxy<map_type>                  self_type;
     typedef typename map_type::key_type               key_type;
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/protocol_traits.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/protocol_traits.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/protocol_traits.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -21,9 +21,10 @@
 #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/data_map_proxy_fwd.hpp"
 #include "boost/cgi/fwd/form_parser_fwd.hpp"
 #ifdef BOOST_CGI_ENABLE_SESSIONS
-#  include "boost/cgi/utility/sessions.hpp"
+#  include "boost/cgi/fwd/sessions_fwd.hpp"
 #  include <boost/uuid/uuid_generators.hpp>
 #endif // BOOST_CGI_ENABLE_SESSIONS
 
@@ -56,8 +57,14 @@
   class fcgi_request_service;
 
  namespace common {
+ 
+    enum session_opts
+    {
+      path_session,
+      domain_session
+    };
 
-   template<typename Protocol>
+    template<typename Protocol>
     struct protocol_traits
     {
     };
@@ -67,22 +74,23 @@
     struct protocol_traits<tags::cgi>
     {
       typedef protocol_traits<tags::cgi>             type;
+      typedef tags::cgi                              protocol_type;
       typedef cgi_request_service                    request_service_impl;
       typedef cgi_request_service                    service_type;
       typedef common::basic_protocol_service<
                   tags::cgi
               >                                      protocol_service_type;
-      typedef common::basic_request<
+      typedef basic_request<
                   tags::cgi
               >                                      request_type; 
       typedef cgi_service_impl                       service_impl_type;
-      typedef common::basic_connection<
+      typedef basic_connection<
                   tags::async_stdio
               >                                      connection_type;
-      typedef common::basic_client<
+      typedef basic_client<
                   tags::cgi
               >                                      client_type;
-      typedef common::form_parser                    form_parser_type;
+      typedef form_parser                            form_parser_type;
       typedef boost::none_t                          header_type;
       typedef char                                   char_type;
       typedef std::basic_string<char_type>           string_type;
@@ -90,16 +98,19 @@
       typedef boost::array<unsigned char, 8>         header_buffer_type;
       typedef boost::asio::const_buffers_1           const_buffers_type;
       typedef boost::asio::mutable_buffers_1         mutable_buffers_type;
-      typedef common::role_type                      role_type;
+      typedef role_type                              role_type;
       typedef boost::shared_ptr<request_type>        pointer;
 #ifdef BOOST_CGI_ENABLE_SESSIONS
       typedef basic_session<
-                std::map<string_type, string_type> 
+                std::map<string_type, string_type>
               >                                      session_type;
-      typedef session_manager                        session_manager_type;
+      typedef boost::uuids::random_generator         uuid_generator_type;
+      typedef basic_session_manager<
+                protocol_type
+              >                                      session_manager_type;
       static const bool auto_start_session = true;
+      static const int session_options = path_session;
 
-      typedef boost::uuids::random_generator          uuid_generator_type;
 #endif // BOOST_CGI_ENABLE_SESSIONS
       static const common::parse_options parse_opts = common::parse_all;
     };
@@ -109,18 +120,19 @@
     struct protocol_traits<tags::fcgi>
     {
       typedef protocol_traits<tags::fcgi>            type;
+      typedef tags::fcgi                             protocol_type;
       typedef fcgi::fcgi_request_service             request_service_impl;
       typedef fcgi::fcgi_request_service             service_type;
-      typedef common::basic_protocol_service<
+      typedef basic_protocol_service<
                   tags::fcgi
               >                                      protocol_service_type;
-      typedef common::basic_request<
+      typedef basic_request<
                   tags::fcgi
               >                                      request_type; 
       typedef boost::shared_ptr<request_type>        request_ptr;
       typedef fcgi::fcgi_service_impl                service_impl_type;
       typedef fcgi::fcgi_acceptor_service            acceptor_service_impl;
-      typedef common::basic_connection<
+      typedef basic_connection<
                   tags::shareable_tcp_socket
               >                                      connection_type;
       typedef boost::asio::ip::tcp                   native_protocol_type;
@@ -132,8 +144,8 @@
       typedef acceptor_service_type::native_type     native_type;
       typedef unsigned short                         port_number_type;
       typedef boost::asio::ip::tcp::endpoint         endpoint_type;
-      typedef common::basic_client<tags::fcgi>       client_type;
-      typedef common::form_parser                    form_parser_type;
+      typedef basic_client<tags::fcgi>               client_type;
+      typedef form_parser                            form_parser_type;
       typedef fcgi::spec::header                     header_type;
       typedef fcgi::spec_detail::role_types          role_type;
 
@@ -146,13 +158,17 @@
       typedef boost::shared_ptr<request_type>        pointer;
 #ifdef BOOST_CGI_ENABLE_SESSIONS
       typedef basic_session<
-                std::map<string_type, string_type> 
+                std::map<string_type, string_type>
               >                                      session_type;
-      typedef session_manager                        session_manager_type;
+      typedef boost::uuids::random_generator         uuid_generator_type;
+      typedef basic_session_manager<
+                protocol_type
+              >                                      session_manager_type;
       static const bool auto_start_session = true;
+      static const int session_options = path_session;
 #endif // BOOST_CGI_ENABLE_SESSIONS
 
-      static const common::parse_options parse_opts = common::parse_none;
+      static const parse_options parse_opts = common::parse_none;
     };
 
  } // namespace common
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -72,6 +72,9 @@
      */
     template<typename SyncWriteStream>
     void flush(SyncWriteStream& sws);
+    
+    /// Put a character into the stream.
+    self_type& put (char_type c);
 
     /// Synchronously flush the data via the supplied request
     /**
Deleted: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/return.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/return.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
+++ (empty file)
@@ -1,64 +0,0 @@
-//                     -- return.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)
-//
-////////////////////////////////////////////////////////////////
-//
-// A macro to make finishing up a request easier.
-// eg.
-//    return_(resp, req, status);
-// is equivalent to
-//    resp.send(req.client());
-//    req.close(resp.status(), status);
-//    return status;
-//
-#ifndef CGI_RETURN_HPP_INCLUDED__
-#define CGI_RETURN_HPP_INCLUDED__
-
-#include "boost/cgi/common/response.hpp"
-#include "boost/cgi/basic_request.hpp"
-#include "boost/cgi/config.hpp"
-
-BOOST_CGI_NAMESPACE_BEGIN
- namespace common {
-
-   template<typename Response, typename Request>
-   boost::system::error_code
-     return_helper(Response& response, Request& request, int program_status)
-   {
-     boost::system::error_code ec;
-     response.send(request.client(), ec);
-     if (ec) return ec;
-
-     request.close(response.status(), program_status);
-
-     return ec;
-   }
-
- } // namespace common
-BOOST_CGI_NAMESPACE_END
-
-/// If an error occurs during the sending or closing then `status` will be
-// incremented by the value of this macro.
-#ifndef BOOST_CGI_RETURN_ERROR_INCREMENT
-#  define BOOST_CGI_RETURN_ERROR_INCREMENT 100
-#endif
-
-#define BOOST_CGI_RETURN(response, request, status)                     \
-          if ( ::BOOST_CGI_NAMESPACE::common::return_helper(response, request, status)) \
-            /** error **/                                               \
-            return status + BOOST_CGI_RETURN_ERROR_INCREMENT;           \
-          return status;
-
-BOOST_CGI_NAMESPACE_BEGIN
- namespace common {
-
-#define return_(response, request, status) BOOST_CGI_RETURN(response, request, status)
-
- } // namespace common
-BOOST_CGI_NAMESPACE_END
-
-#endif // CGI_RETURN_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/role_type.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/role_type.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/role_type.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -1,5 +1,14 @@
+//                   -- role_type.hpp --
+//
+//          Copyright (c) Darren Garvey 2007-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_ROLE_TYPE_HPP_INCLUDED__
 #define CGI_ROLE_TYPE_HPP_INCLUDED__
+
 #include "boost/cgi/config.hpp"
 
 BOOST_CGI_NAMESPACE_BEGIN
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/tags.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/tags.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/tags.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -1,6 +1,6 @@
 //                   -- common/tags.hpp --
 //
-//            Copyright (c) Darren Garvey 2007.
+//            Copyright (c) Darren Garvey 2007-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)
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/config.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/config.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/config.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -1,6 +1,6 @@
-//                   -- form_parser.hpp --
+//                    -- config.hpp --
 //
-//            Copyright (c) Darren Garvey 2007.
+//          Copyright (c) Darren Garvey 2007-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)
@@ -65,4 +65,18 @@
 # endif // NDEBUG
 #endif // BOOST_CGI_ASSERT
 
+#ifndef BOOST_CGI_OVERRIDE_PROTOCOL
+# define BOOST_CGI_OVERRIDE_PROTOCOL(p, tag, brace_enclosed_traits) \
+    namespace boost { namespace cgi { namespace common {\
+    \
+      template<>\
+      struct protocol_traits<tag>\
+        : protocol_traits<tags::cgi>\
+        brace_enclosed_traits\
+     ; } } } \
+    typedef boost::cgi::common::basic_request_acceptor<tag> acceptor;\
+    typedef boost::cgi::common::basic_request<tag>          request;\
+    typedef boost::cgi::common::basic_protocol_service<tag> service;
+#endif // BOOST_CGI_OVERRIDE_PROTOCOL
+
 #endif // BOOST_CGI_CONFIG_HPP_INCLUDED__
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/common_headers.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/common_headers.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/common_headers.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -15,6 +15,7 @@
 //#include "boost/cgi/logger.hpp"
 #include "boost/cgi/config.hpp"
 #include "boost/cgi/basic_request.hpp"
+#include "boost/cgi/basic_request_acceptor.hpp"
 #include "boost/cgi/common/header.hpp"
 #include "boost/cgi/common/map.hpp"
 #include "boost/cgi/common/commit.hpp"
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/fwd/data_map_proxy_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fwd/data_map_proxy_fwd.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -0,0 +1,23 @@
+
+#ifndef BOOST_CGI_DATA_MAP_PROXY_HPP_INCLUDED_20091206_
+#define BOOST_CGI_DATA_MAP_PROXY_HPP_INCLUDED_20091206_
+
+BOOST_CGI_NAMESPACE_BEGIN
+ namespace common {
+ 
+  /// A proxy class to provide access to the data maps as member variables.
+  /**
+   * This wraps the underlying data map and exposes a std::map-like 
+   * interface for the different data maps.
+   *
+   * It also includes an as<> member function which casts the found data
+   * into a type the user specifies.
+   */
+  template<typename MapType>
+  class data_map_proxy;
+
+ } // namespace common
+BOOST_CGI_NAMESPACE_END
+
+#endif // BOOST_CGI_DATA_MAP_PROXY_HPP_INCLUDED_20091206_
+
Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/fwd/sessions_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fwd/sessions_fwd.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -0,0 +1,14 @@
+
+#ifndef BOOST_CGI_FWD_SESSIONS_HPP_INCLUDED_
+#define BOOST_CGI_FWD_SESSIONS_HPP_INCLUDED_
+
+#include "boost/cgi/config.hpp"
+
+BOOST_CGI_NAMESPACE_BEGIN
+  namespace common {
+    template<typename T> class basic_session;
+    template<typename Protocol> class basic_session_manager;
+  }
+BOOST_CGI_NAMESPACE_END
+
+#endif // BOOST_CGI_FWD_SESSIONS_HPP_INCLUDED_
\ No newline at end of file
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/response.ipp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/response.ipp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/response.ipp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -156,6 +156,14 @@
     return ostream_.write(buf.begin(), buf.end());
   }
 
+  template<typename T>
+  BOOST_CGI_INLINE
+  basic_response<T>& basic_response<T>::put(char_type ch)
+  {
+    ostream_.put(ch);
+    return *this;
+  }
+
   /// Synchronously flush the data to the supplied SyncWriteStream
   /**
    * This call uses throwing semantics. ie. an exception will be thrown on
Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/utility/sessions.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/utility/sessions.hpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/utility/sessions.hpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -1,6 +1,6 @@
 
-#ifndef BOOST_CGI_SESSIONS_HPP_INCLUDED_
-#define BOOST_CGI_SESSIONS_HPP_INCLUDED_
+#ifndef BOOST_CGI_UTILITY_SESSIONS_HPP_INCLUDED_
+#define BOOST_CGI_UTILITY_SESSIONS_HPP_INCLUDED_
 
 #include "boost/cgi/detail/push_options.hpp"
 
@@ -17,14 +17,14 @@
 ///////////////////////////////////////////////////////////
 #include "boost/cgi/import/write.hpp"
 #include "boost/cgi/common/header.hpp"
+#include "boost/cgi/common/protocol_traits.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
 ///////////////////////////////////////////////////////////
 
 /// The directory to store sessions in.
 /**
  * Your web server will need read and write permissions to this directory.
- * You are responsible for ensuring that no other users are able to access
- * files in this directory!
+ * You are responsible for ensuring that files in this folder are protected!
  * 
  * Session support is currently experimental and relatively dumb.
  *
@@ -32,6 +32,14 @@
  * The session data itself defaults to a std::map<string,string>, which
  * is derived from the ProtocolTraits of the request.
  *
+ * At the moment you are also responsible for maintaining this directory:
+ * the library does nothing to clean up stale sessions. Session files are
+ * only removed when the session is explicitly closed by a library user.
+ *
+ * In general you will need to write a script which deletes session files
+ * that have not been modified in the last N days... Need clearer docs on
+ * this.
+ *
  * Look at the `sessions` example to see how to use your own types
  * for sessions. In general, the idea is that any type that is both
  * DefaultConstructable and also Serializable (as defined by
@@ -39,69 +47,81 @@
  * overhead.
  */
 #ifndef BOOST_CGI_SESSIONS_DIRECTORY
-#  define BOOST_CGI_SESSIONS_DIRECTORY "../sessions/"
+#  define BOOST_CGI_SESSIONS_DIRECTORY "../sessions"
 #endif // BOOST_CGI_SESSIONS_DIRECTORY
 
 #ifndef BOOST_CGI_SESSION_COOKIE_NAME
-#  define BOOST_CGI_SESSION_COOKIE_NAME ".ssid"
+#  define BOOST_CGI_SESSION_COOKIE_NAME "_ssid"
 #endif // BOOST_CGI_SESSION_COOKIE_NAME
 
 BOOST_CGI_NAMESPACE_BEGIN
  namespace common {
 
-using namespace std;
-//using namespace boost::serialization;
-
-///////////////////////////////////////////////////////////
-
 template<typename T>
 class basic_session : public T, private boost::noncopyable
 {
 public:
-  typedef T value_type;
+  typedef T           value_type;
+  typedef std::string string_type;
 
-  basic_session(string const& id = "")
+  basic_session(string_type const& id = "")
     : id_(id)
     , loaded_(false)
   {}
   
-  basic_session(T& t, string const& id = "")
+  basic_session(T& t, string_type const& id = "")
     : T(t)
     , id_(id)
     , loaded_(false)
   {}
   
-  basic_session(T const& t, string const& id = "")
+  basic_session(T const& t, string_type const& id = "")
     : T(t)
     , id_(id)
     , loaded_(false)
   {}
 
-  string const& id () const { return id_; }
-  void id (string const& new_id) { id_ = new_id; }
-  
+  /// Get the id for the session.
+  string_type const& id () const { return id_; }
+  /// Set the id for the session.
+  void id (string_type const& new_id) { id_ = new_id; }
+
+  /// A basic_session is implicitly convertible to it's value_type.
   operator T& () { return static_cast<T&>(*this); }
+  /// A basic_session is implicitly convertible to it's value_type.
   operator T const& () const { return static_cast<T const&>(*this); }
 
+  /// Check if the session has been loaded.
   bool const& loaded() const { return loaded_; }
+  /// Set whether the session is loaded.
   void loaded(bool status) { loaded_ = status; }
 
 private:
-  string id_;
+  string_type id_;
   bool loaded_;
 };
 
-class session_manager
+///////////////////////////////////////////////////////////
+
+template<typename Protocol>
+class basic_session_manager
 {
 public:
-  session_manager()
+  typedef Protocol                             protocol_type;
+  typedef protocol_traits<protocol_type>       traits;
+  typedef typename traits::string_type         string_type;
+  typedef typename traits::uuid_generator_type uuid_generator_type;
+  
+  basic_session_manager(
+    string_type const& save_dir = BOOST_CGI_SESSIONS_DIRECTORY)
+    : save_dir(save_dir)
   {}
 
   template<typename T>
   void save(basic_session<T>& sesh)
   {
-    ofstream ofs(
-        (std::string(BOOST_CGI_SESSIONS_DIRECTORY) + sesh.id() + ".arc").c_str());
+    std::ofstream ofs(
+        (save_dir + "/" + sesh.id() + ".arc").c_str());
     if (ofs) {
       boost::archive::text_oarchive archive(ofs);
       archive<< static_cast<typename basic_session<T>::value_type&>(sesh);
@@ -111,18 +131,62 @@
   template<typename T>
   void load(basic_session<T>& sesh)
   {
-    ifstream ifs(
-        (std::string(BOOST_CGI_SESSIONS_DIRECTORY) + sesh.id() + ".arc").c_str());
+    std::ifstream ifs(
+        (save_dir + "/" + sesh.id() + ".arc").c_str());
     if (ifs) {
       boost::archive::text_iarchive archive(ifs);
       archive>> static_cast<typename basic_session<T>::value_type&>(sesh);
       sesh.loaded(true);
     }
   }
+  
+  template<typename T>
+  void stop(basic_session<T>& sesh)
+  {
+    namespace fs = boost::filesystem;
+    if (sesh.loaded()) {
+      fs::path file (save_dir + sesh.id() + ".arc");
+      if (fs::exists(file))
+        fs::remove(file);
+      sesh.id("");
+    }
+  }
+  
+  template<typename T>
+  void start(basic_session<T>& sesh, string_type const& ssid = "")
+  {
+    if (!sesh.loaded() && sesh.id().empty())
+    {
+      if (!ssid.empty()) {
+        sesh.id(ssid);
+        load(sesh);
+      } else {
+        sesh.id(make_session_id());
+        sesh.loaded(true);
+      }
+    }  
+  }
+  
+  /// Get a new UUID as a string, suitable as a session id.
+  string_type make_session_id()
+  {
+    try {
+        return boost::lexical_cast<string_type>(make_uuid());
+    } catch (...) {
+        // pass
+    }
+    return "";
+  }
+
+  /// Generate a new UUID.
+  boost::uuids::uuid make_uuid() { return generator_(); }
+
+private:
+  string_type save_dir;
+  uuid_generator_type generator_;
 };
 
  } // namespace common
 BOOST_CGI_NAMESPACE_END
 
-#endif // BOOST_CGI_SESSIONS_HPP_INCLUDED_
-
+#endif // BOOST_CGI_UTILITY_SESSIONS_HPP_INCLUDED_
Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/Boost.CGI.sln
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/Boost.CGI.sln	(original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/Boost.CGI.sln	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -43,6 +43,8 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cgi_sessions", "cgi_sessions\cgi_sessions.vcproj", "{5C01290A-DD11-4DD9-971A-9C25CCA7FB96}"
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cgi_custom_sessions", "cgi_custom_sessions\cgi_custom_sessions.vcproj", "{FF4B6C26-B292-47FF-89B6-F2930AAA020B}"
+EndProject
 Global
         GlobalSection(SolutionConfigurationPlatforms) = preSolution
                 Debug|Win32 = Debug|Win32
@@ -133,6 +135,10 @@
                 {5C01290A-DD11-4DD9-971A-9C25CCA7FB96}.Debug|Win32.Build.0 = Debug|Win32
                 {5C01290A-DD11-4DD9-971A-9C25CCA7FB96}.Release|Win32.ActiveCfg = Release|Win32
                 {5C01290A-DD11-4DD9-971A-9C25CCA7FB96}.Release|Win32.Build.0 = Release|Win32
+		{FF4B6C26-B292-47FF-89B6-F2930AAA020B}.Debug|Win32.ActiveCfg = Debug|Win32
+		{FF4B6C26-B292-47FF-89B6-F2930AAA020B}.Debug|Win32.Build.0 = Debug|Win32
+		{FF4B6C26-B292-47FF-89B6-F2930AAA020B}.Release|Win32.ActiveCfg = Release|Win32
+		{FF4B6C26-B292-47FF-89B6-F2930AAA020B}.Release|Win32.Build.0 = Release|Win32
         EndGlobalSection
         GlobalSection(SolutionProperties) = preSolution
                 HideSolutionNode = FALSE
Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/cgi_ctemplate_cookie_game/cgi_ctemplate_cookie_game.vcproj
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/cgi_ctemplate_cookie_game/cgi_ctemplate_cookie_game.vcproj	(original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/cgi_ctemplate_cookie_game/cgi_ctemplate_cookie_game.vcproj	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -60,7 +60,7 @@
                         />
                         <Tool
                                 Name="VCLinkerTool"
-				AdditionalOptions="libboost_system-vc90-mt-gd-1_38.lib
libctemplate-debug.lib"
+				AdditionalOptions="libctemplate-debug.lib"
                                 LinkIncremental="2"
                                 GenerateDebugInformation="true"
                                 SubSystem="1"
Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/cgi_sessions/cgi_sessions.vcproj
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/cgi_sessions/cgi_sessions.vcproj	(original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/build/msvc/9.0/Boost.CGI/cgi_sessions/cgi_sessions.vcproj	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -182,10 +182,6 @@
                         Filter="h;hpp;hxx;hm;inl;inc;xsd"
                         UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
 			>
-			<File
-				RelativePath="..\..\..\..\..\example\cgi\sessions\sessions.hpp"
-				>
-			</File>
                 </Filter>
                 <Filter
                         Name="Resource Files"
Copied: sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/custom_sessions/main.cpp (from r60226, /sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/sessions/main.cpp)
==============================================================================
--- /sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/sessions/main.cpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/custom_sessions/main.cpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -3,83 +3,34 @@
 #include <iostream>
 
 using namespace std;
-
-class context
-{
-public:
-
-  context() {}
-  
-  map<string,int> data;
-
-  template<typename Archive>
-  void serialize(Archive& ar, const unsigned int version)
-  {
-    ar & data;
-  }
-  
-};
-
-/*<
- * Now we can override the default session type to use the `context` class.
- *
- * To do this we need to create a `Tag`. A `Tag` is a plain struct used as
- * an identifier. If we specialise the `protocol_traits<>` template for this
- * tag we can change the behaviour of the library at compile-time.
- *
- * In this example we are just going to override the actual `session_type`
- * and otherwise inherit the properties for CGI.
->*/
-
-/// The `Tag`
-struct session_enabled_cgi {};
-
-/// Specialise the `protocol_traits` template in the `boost::cgi::common`
-/// namespace.
-namespace boost { namespace cgi { namespace common {
-
-template<>
-struct protocol_traits<session_enabled_cgi>
-  : protocol_traits<boost::cgi::tags::cgi>
-{
-  typedef basic_session<context> session_type; /*<
-The session_type for the request holds all session-related data, which in this
-example is everything stored in the `context` class defined above.
->*/
-  static const bool auto_start_session = false; /*<
-`auto_start_session` is `true` by default. Here we override it to be `false`,
-which means we must explicitly call `basic_request<>::start_session()` for
-any sessions to be created / loaded.
->*/
-};
-
-} } } // namespace boost::cgi::common
-
 using namespace boost::cgi;
 
-/// Define a request type which uses the traits for our
-/// `session_enabled_cgi` Tag.
-typedef basic_request<session_enabled_cgi> my_request;
-
 int main(int, char**)
 {
   try
   {
-    my_request req;
+    request req;
     response resp;
+    
+    if (req.get.pick("clear", "") == "1") {
+      req.stop_session();
+      resp<< "Cleared session";
+      return commit(req, resp);
+    }
 
     // Start the session. It is safe to call `start_session()` if a session
     // is already open, but you shouldn't have to do that...
     req.start_session();
 
-    resp<< "one = " << req.session.data["one"]
-        << ", two = " << req.session.data["two"]
-        << ", ten = " << req.session.data["ten"];
-    
+    resp<< content_type("text/plain")
+        << "one = " << req.session["one"]
+        << ", two = " << req.session["two"]
+        << ", ten = " << req.session["ten"];
+
     // Modify the request session.
-    req.session.data["one"] = 1;
-    req.session.data["two"] = 2;
-    req.session.data["ten"] = 10;
+    req.session["one"] = "1";
+    req.session["two"] = "2";
+    req.session["ten"] = "10";
 
     // The session is saved by `commit()`.
     return commit(req, resp);
Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/sessions/main.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/sessions/main.cpp	(original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/sessions/main.cpp	2010-03-23 21:06:49 EDT (Tue, 23 Mar 2010)
@@ -3,83 +3,34 @@
 #include <iostream>
 
 using namespace std;
-
-class context
-{
-public:
-
-  context() {}
-  
-  map<string,int> data;
-
-  template<typename Archive>
-  void serialize(Archive& ar, const unsigned int version)
-  {
-    ar & data;
-  }
-  
-};
-
-/*<
- * Now we can override the default session type to use the `context` class.
- *
- * To do this we need to create a `Tag`. A `Tag` is a plain struct used as
- * an identifier. If we specialise the `protocol_traits<>` template for this
- * tag we can change the behaviour of the library at compile-time.
- *
- * In this example we are just going to override the actual `session_type`
- * and otherwise inherit the properties for CGI.
->*/
-
-/// The `Tag`
-struct session_enabled_cgi {};
-
-/// Specialise the `protocol_traits` template in the `boost::cgi::common`
-/// namespace.
-namespace boost { namespace cgi { namespace common {
-
-template<>
-struct protocol_traits<session_enabled_cgi>
-  : protocol_traits<boost::cgi::tags::cgi>
-{
-  typedef basic_session<context> session_type; /*<
-The session_type for the request holds all session-related data, which in this
-example is everything stored in the `context` class defined above.
->*/
-  static const bool auto_start_session = false; /*<
-`auto_start_session` is `true` by default. Here we override it to be `false`,
-which means we must explicitly call `basic_request<>::start_session()` for
-any sessions to be created / loaded.
->*/
-};
-
-} } } // namespace boost::cgi::common
-
 using namespace boost::cgi;
 
-/// Define a request type which uses the traits for our
-/// `session_enabled_cgi` Tag.
-typedef basic_request<session_enabled_cgi> my_request;
-
 int main(int, char**)
 {
   try
   {
-    my_request req;
+    request req;
     response resp;
+    
+    if (req.get.pick("clear", "") == "1") {
+      req.stop_session();
+      resp<< "Cleared session";
+      return commit(req, resp);
+    }
 
     // Start the session. It is safe to call `start_session()` if a session
     // is already open, but you shouldn't have to do that...
     req.start_session();
 
-    resp<< "one = " << req.session.data["one"]
-        << ", two = " << req.session.data["two"]
-        << ", ten = " << req.session.data["ten"];
-    
+    resp<< content_type("text/plain")
+        << "one = " << req.session["one"]
+        << ", two = " << req.session["two"]
+        << ", ten = " << req.session["ten"];
+
     // Modify the request session.
-    req.session.data["one"] = 1;
-    req.session.data["two"] = 2;
-    req.session.data["ten"] = 10;
+    req.session["one"] = "1";
+    req.session["two"] = "2";
+    req.session["ten"] = "10";
 
     // The session is saved by `commit()`.
     return commit(req, resp);