Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2007-08-22 22:44:44


Author: drrngrvy
Date: 2007-08-22 22:44:43 EDT (Wed, 22 Aug 2007)
New Revision: 38863
URL: http://svn.boost.org/trac/boost/changeset/38863

Log:
Altered/added to acgi example. Still quite minimal (but it works!)
Text files modified:
   sandbox/SOC/2007/cgi/libs/cgi/example/acgi/main.cpp | 125 +++++++++++++++++++++++----------------
   sandbox/SOC/2007/cgi/libs/cgi/example/cgi/Jamfile.v2 | 2
   sandbox/SOC/2007/cgi/libs/cgi/example/cgi/main.cpp | 9 +-
   sandbox/SOC/2007/cgi/libs/cgi/test/Jamfile.v2 | 3
   sandbox/SOC/2007/cgi/libs/cgi/test/compile/cgi_request.cpp | 2
   sandbox/SOC/2007/cgi/libs/cgi/util/system/Jamfile.v2 | 1
   6 files changed, 85 insertions(+), 57 deletions(-)

Modified: sandbox/SOC/2007/cgi/libs/cgi/example/acgi/main.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/example/acgi/main.cpp (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/example/acgi/main.cpp 2007-08-22 22:44:43 EDT (Wed, 22 Aug 2007)
@@ -1,70 +1,93 @@
 #include <boost/cgi/acgi.hpp>
+#include <boost/cgi/response.hpp>
 #include <iostream>
 
-class handlerer
-{
-public:
- handlerer(cgi::request_ostream& ros, cgi::acgi_request& req)
- : ros_(ros)
- , req_(req)
- {
- }
-
- void operator()(boost::system::error_code& ec)
- {
- if (!ec)
- {
- ros_<< "All ok";
- ros_.flush(req_);
- }
- }
-private:
- cgi::request_ostream& ros_;
- cgi::acgi_request& req_;
-};
+// class handler
+// {
+// public:
+// handler(cgi::request_ostream& ros, cgi::acgi::request& req)
+// : ros_(ros)
+// , req_(req)
+// {
+// }
+//
+// void operator()(boost::system::error_code& ec)
+// {
+// if (!ec)
+// {
+// ros_<< "All ok";
+// ros_.flush(req_);
+// }
+// }
+// private:
+// cgi::request_ostream& ros_;
+// cgi::acgi::request& req_;
+// };
 
 
 int main()
 {
- cgi::acgi_service service;
- cgi::acgi_request req(service);
- req.load(true);
-
- std::string buf("Content-type: text/html\r\n\r\nHello there, Universe.");
- cgi::write(req, cgi::buffer(buf.c_str(), buf.size()));
-
- cgi::reply rep;
+ using namespace cgi::acgi;
 
- rep<< "<br />What's your name?<br />";
- std::cerr<< std::endl << "name = " << req.meta_form("name") << std::endl;
- std::cerr.flush();
+ service srv;
+ request req(srv);
 
- rep<< "<form method='POST'>"
- "<input name='name' type='text' value='"
- << req.meta_form("name")
- << "'></input>"
- "<input type='submit'></input>"
- "</form>";
-
- rep.send(req);
+ // Load up the request data
+ req.load(true);
 
+ response resp;
 
+ if (req.get_("reset") == "true")
+ {
+ resp<< cookie("name")
+ << location(req.script_name())
+ << header();
+ resp.send(req);
+ return 0;
+ }
 
- /*
- for(cgi::streambuf::const_buffers_type::const_iterator
- i = rep.rdbuf()->data().begin()
- ; i != rep.rdbuf()->data().end(); ++i)
+ // First, see if they have a cookie set
+ std::string& name = req.cookie_()["name"];
+ if (!name.empty())
   {
- std::size_t buf_len = boost::asio::buffer_size(*i);
- std::string s(boost::asio::buffer_cast<const char*>(*i)
- , buf_len);
+ resp<< header("Content-type", "text/html")
+ << header() // terminate the headers
+ << "Hello again " << name << "<p />"
+ << "<a href='?reset=true'><input type='submit' value='Reset' /></a>";
+ resp.send(req);
+ return 0;
+ }
 
- rep<< "s = " << s;
- std::cerr<< "s = " << s;
+ // Now we'll check if they sent us a name
+ name = req.form_("name");
+ if (!name.empty())
+ {
+ resp<< header("Content-type", "text/html")
+ << cookie("name", name)
+ << header() // terminate the headers
+ << "Hello there, " << name;
+ resp.send(req);
+ return 0;
   }
- */
 
- //rep.flush(req);
+ //std::string buf("Content-type: text/html\r\n\r\nHello there, Universe.<br />");
+ //cgi::write(req, cgi::buffer(buf.c_str(), buf.size()));
+
+ resp<< header("Content-type", "text/html")
+ << header()
+ << "Hello there, Universe.<p />"
+ << "What's your name?<br />";
+
+ //std::cerr<< std::endl << "name = " << req.form_("name") << std::endl;
+ //std::cerr.flush();
+
+ resp<< "<form method='POST'>"
+ "<input name='name' type='text' value='" << req.form_("name") << "'>"
+ "</input>"
+ "<input type='submit'></input>"
+ "</form>";
+
+ resp.send(req);
 
   return 0;
 }

Modified: sandbox/SOC/2007/cgi/libs/cgi/example/cgi/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/example/cgi/Jamfile.v2 (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/example/cgi/Jamfile.v2 2007-08-22 22:44:43 EDT (Wed, 22 Aug 2007)
@@ -20,7 +20,9 @@
     <include>$(BOOST_ROOT)
     <include>"../../../../"
     <library>../../util/system//boost_system
+ #<library>l:/usr/local/lib/libboost_system.a
     <define>BOOST_ALL_NO_LIB=1
+ <define>_CRT_SECURE_NO_DEPRECIATE=1
     <toolset>gcc:<linkflags>-lpthread
   ;
 

Modified: sandbox/SOC/2007/cgi/libs/cgi/example/cgi/main.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/example/cgi/main.cpp (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/example/cgi/main.cpp 2007-08-22 22:44:43 EDT (Wed, 22 Aug 2007)
@@ -1,5 +1,6 @@
 #include <string>
 #include <boost/system/error_code.hpp>
+//#include "../../../../boost/cgi/basic_protocol_service_fwd.hpp"
 #include "../../../../boost/cgi/cgi.hpp"
 
 int main()
@@ -12,13 +13,13 @@
   std::string buf("Content-type: text/html\r\n\r\nHello there, universe!");
   boost::system::error_code ec;
 
- cgi::write(req, cgi::buffer(buf.c_str(), buf.size()));
+ cgi::write(req.client(), cgi::buffer(buf.c_str(), buf.size()));
 
- buf = req.meta_get("blah");
- cgi::write(req, cgi::buffer(buf.c_str(), buf.size()));
+ buf = req.get_("blah");
+ cgi::write(req.client(), cgi::buffer(buf.c_str(), buf.size()));
 
   } catch( boost::system::error_code& ec ) {
- std::cerr<< "error: " << ec.message() << std::endl;
+ //std::cerr<< "error: " << ec.message() << std::endl;
 }
   return 0;
 }

Modified: sandbox/SOC/2007/cgi/libs/cgi/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/test/Jamfile.v2 (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/test/Jamfile.v2 2007-08-22 22:44:43 EDT (Wed, 22 Aug 2007)
@@ -23,6 +23,7 @@
 # [ run run/cgi_request.cpp ]
   :
     <include>$(BOOST_ROOT)
- <include>$(BOOST_CGI_ROOT)
+# <include>$(BOOST_CGI_ROOT)
+ <include>/usr/local/src/cgi/svn.boost.org/
   ;
 

Modified: sandbox/SOC/2007/cgi/libs/cgi/test/compile/cgi_request.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/test/compile/cgi_request.cpp (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/test/compile/cgi_request.cpp 2007-08-22 22:44:43 EDT (Wed, 22 Aug 2007)
@@ -1,4 +1,4 @@
-#include <boost/cgi/cgi/cgi_request.hpp>
+#include <boost/cgi/cgi.hpp>
 
 int main()
 {

Modified: sandbox/SOC/2007/cgi/libs/cgi/util/system/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/cgi/libs/cgi/util/system/Jamfile.v2 (original)
+++ sandbox/SOC/2007/cgi/libs/cgi/util/system/Jamfile.v2 2007-08-22 22:44:43 EDT (Wed, 22 Aug 2007)
@@ -3,4 +3,5 @@
 lib boost_system
   :
   : <file>/usr/local/lib/libboost_system.a
+ #<toolset>gcc:<file>/usr/local/lib/libboost_system.a
   ;


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