Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2008-05-19 15:21:22


Author: drrngrvy
Date: 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
New Revision: 45557
URL: http://svn.boost.org/trac/boost/changeset/45557

Log:
Updating tests and examples.
Added:
   sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/troubleshooting.qbk (contents, props changed)
Text files modified:
   sandbox/SOC/2007/cgi/trunk/libs/cgi/build/Jamfile.v2 | 6 ++++
   sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/cgi.qbk | 2 +
   sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/reference.qbk | 53 ++++++++++++++++++++++++++++++++++++++-
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/echo/Jamfile.v2 | 4 +-
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/echo/main.cpp | 50 ++++++++++++++++++++++++-------------
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/CheckCookie.cpp | 6 ++--
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/Login.cpp | 20 ++++++++------
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/Logout.cpp | 2
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/echo/Jamfile.v2 | 7 +++--
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/acgi_simple_request.cpp | 2
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp | 1
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cookie.cpp | 3 ++
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/request_test_template.hpp | 16 ++++++++++++
   13 files changed, 132 insertions(+), 40 deletions(-)

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/build/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/build/Jamfile.v2 (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/build/Jamfile.v2 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -3,13 +3,19 @@
 # user-supplied variables (ie. using modules.peek, I think)
 
 project boost/cgi
+ : build-dir
+ $(top)/bin.v2
   : usage-requirements
       <include>$(top)
       <include>$(boost-root)
       <library>/boost/thread/
       <library>/boost/system/
+ <library>/boost/regex/
       <define>_CRT_SECURE_NO_WARNINGS
       <define>_SCL_SECURE_NO_WARNINGS
   ;
 
 
+alias boost_cgi ;
+
+#lib boost_cgi : $(top)/boost/cgi/common/form_parser.cpp ;

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/cgi.qbk
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/cgi.qbk (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/cgi.qbk 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -117,4 +117,6 @@
 
 [include:server_support user_guide/server_support.qbk]
 
+[include troubleshooting.qbk]
+
 [include acknowledgements.qbk]

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/reference.qbk
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/reference.qbk (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/reference.qbk 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -7,8 +7,57 @@
 
 [section:ref Reference]
 
+[xinclude:doxygen cgi_dox.xml]
+
+[section:quick Quick Reference]
+
 Reference coming...
 
-[/include request_objects.qbk]
+Requests
+ - Request Data
+ - environment
+ - operator[""]
+ - operator[env][""]
+ - member functions
+ - script_name()
+ - request_method()
+ - content_length()
+ - content_encoding()
+ - etc...
+ - GET
+ - POST
+ - form (transparent GET/POST)
+ - cookie
+ - constructors
+ - load()
+ - async_load()
+ - close()
+ - clear()
+ - id()
+ - client()
+
+Acceptor
+ - constructors
+ - accept()
+ - async_accept()
+ - cancel()
+
+
+Service
+ - run()
+ - stop()
+ - reset()
+ - get_io_service()
+
+Responses
+ - operator<<
+ - send()
+ - clear()
+ - data()
+ - content_length()
+
+
+[endsect] [/ quick]
+
+[endsect] [/ ref]
 
-[endsect]

Added: sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/troubleshooting.qbk
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/doc/src/troubleshooting.qbk 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -0,0 +1,53 @@
+
+[section Troubleshooting]
+
+[section Internal Server Errors]
+
+Every CGI programmer knows of the dreaded "500: Internal Server Error". It is such a generic error that it is usually completely useless. There are however some techniques that can be used to diagnose problems: they are not ideal, but can usually help in some way.
+
+[section:exceptions_and_asserts Uncaught Exceptions and Failed Asserts]
+
+An uncaught exception or a failed assert can cause your program to terminate unexpectedly, before you manage to output anything. One way to see if this is happening is to put your entire `main()` function in a `try {} catch(...) {}` block. Then - either in the body of `catch(...)` or at the very start of `main()` - you should try writing something to `std::cerr` (any protocol) or `std::cout` (CGI/aCGI only). The following is a template:
+
+``
+main()
+try
+{
+ // In almost all cases std::cerr is available (check your server's error logs).
+ std::cerr<< "Program started ok..." << std::endl << std::flush;
+
+ std::cout<< "Content-type: text/plain\r\n\r\n" // the required content-type header
+ << "TESTING"
+ << std::flush; // make sure you flush the buffer as soon as possible!
+
+ // ...
+
+}catch(...){
+ std::cerr<< "Caught exception in main()" << std::endl << std::flush;
+ std::cout<< "Content-type: text/plain\r\n\r\n"
+ << "Caught exception!" << std::flush;
+}
+``
+
+[endsect] [/ exceptions_and_asserts]
+
+[section Static Linking]
+
+Because this library depends on compiled libraries, you may find that your application crashes before it even starts running. If you find you can't even write to std::cerr at the very start of your program then you may have a runtime linking problem.
+
+The easiest way around this is to statically link your program. If you're using `bjam` you can use the command:
+
+``
+bjam link=static runtime-link=static
+``
+
+[tip
+ To check what directories are searched for libraries, try one of the echo examples on your server and look for a variable like `LIB_DIR` or `LIB`.
+]
+
+[endsect] [/ static_linking]
+
+[endsect] [/ internal_server_error]
+
+[endsect] [/ troubleshooting]
+

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/echo/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/echo/Jamfile.v2 (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/echo/Jamfile.v2 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -9,8 +9,8 @@
 exe acgi_echo
   :
     main.cpp
- /boost/regex/
- /boost/thread/
+ :
+ <library>/boost/cgi/
   ;
 
 # Our install rule (builds binaries and copies them to <location>)

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/echo/main.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/echo/main.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/echo/main.cpp 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -17,6 +17,7 @@
 
 #include <boost/cgi/acgi.hpp>
 #include <fstream>
+#include <cstdio>
 
 using namespace std;
 using namespace boost::acgi;
@@ -27,13 +28,25 @@
 void show_map_contents(OStreamT& os, MapT& m, const std::string& title)
 {
   os<< "<h3>" << title << "</h3>";
- if (m.empty()) os<< "NONE<br />";
- for (typename MapT::const_iterator i = m.begin(); i != m.end(); ++i)
- {
- os<< "<b>" << i->first << "</b> = <i>" << i->second << "</i><br />";
- }
+ if (m.empty())
+ os<< "NONE<br />";
+ else
+ for (typename MapT::const_iterator i = m.begin(); i != m.end(); ++i)
+ {
+ os<< "<b>" << i->first << "</b> = <i>" << i->second << "</i><br />";
+ }
 }
 
+std::size_t process_id()
+{
+#if defined(BOOST_WINDOWS)
+ return _getpid();
+#else
+ return getpid();
+#endif
+}
+
+
 int main()
 {
   try{
@@ -52,20 +65,21 @@
       if (ec)
       {
         response resp;
- resp
- << content_type("text/html")
- << "Error " << ec.value() << ": " << ec.message() << "<p />"
- "--Original message follows--"
- "<p />";
+ resp<< content_type("text/html")
+ << "Error " << ec.value() << ": " << ec.message() << "<p />"
+ "--Original message follows--"
+ "<p />";
         resp.send(req.client());
       }
 
       response resp;
       resp<< content_type("text/html")
+ << "Request ID = " << req.id() << "<br />"
+ << "Process ID = " << process_id() << "<br />"
           << "<form method=POST enctype='multipart/form-data'>"
- "<input type=text name=name value='" << req.POST("name") << "' />"
+ "<input type=text name=name value='" << req[post]["name"] << "' />"
               "<br />"
- "<input type=text name=hello value='" << req.POST("hello") << "' />"
+ "<input type=text name=hello value='" << req[post]["hello"] << "' />"
               "<br />"
               "<input type=file name=user_file />"
               "<input type=hidden name=cmd value=multipart_test />"
@@ -73,10 +87,10 @@
               "<input type=submit value=submit />"
              "</form><p />";
 
- show_map_contents(resp, req[get_data], "GET Variables");
- show_map_contents(resp, req[post_data], "POST Variables");
- show_map_contents(resp, req[cookie_data], "Cookie Variables");
- show_map_contents(resp, req[env_data], "Environment Variables");
+ show_map_contents(resp, req[env], "Environment Variables");
+ show_map_contents(resp, req[get], "GET Variables");
+ show_map_contents(resp, req[post], "POST Variables");
+ show_map_contents(resp, req[cookies], "Cookie Variables");
 
       return_(resp, req, 0); // All ok.
 
@@ -101,12 +115,12 @@
     // are reached.
 
   }catch(std::exception* e){
- std::cerr
+ std::cout
     << content_type("text/plain").content
     << "Exception: " << e->what();
     return 3;
   }catch(...){
- std::cerr<< content_type("text/plain").content
+ std::cout<< content_type("text/plain").content
              << "Unknown error.";
     return 4;
   }

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/CheckCookie.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/CheckCookie.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/CheckCookie.cpp 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -12,10 +12,10 @@
 
   response resp;
 
- if (!req.cookie("uuid").empty())
+ if (!req[cookie_data]["uuid"].empty())
   { // The cookie has been set correctly!
     boost::system::error_code ec;
- std::string fwd(req.form("fwd", ec));
+ std::string fwd (req[form_data]["fwd"]);
     resp<< location(fwd);
   // resp<< location(req.form("fwd"));
   }else
@@ -31,7 +31,7 @@
          "<p>You have cookies disabled. They are required for logging in.</p>"
                                  "<a href='http://www.google.com/search?q=enabling cookies'>Google it</a>"
                                  " if you're stuck, or return to "
- "<a href='" << req.env("referrer") << "'>where you came from</a>"
+ "<a href='" << req[env_data]["referrer"] << "'>where you came from</a>"
        "</center>"
        "</body>"
        "</html>";

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/Login.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/Login.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/Login.cpp 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -13,8 +13,8 @@
            "You provided the following data:"
            "<p>"
            "<h3>Form data:</h3>";
- for (boost::acgi::map::iterator i = req.form().begin();
- i != req.form().end();
+ for (boost::acgi::map::iterator i = req[form_data].begin();
+ i != req[form_data].end();
        ++i)
   {
     resp<< "<b>" << i->first << "</b> = <i>" << i->second << "</i>";
@@ -54,12 +54,13 @@
   << content_type("text/html")
   << "<html>"
      "<head><title>Redirecting...</title>"
- "<meta http-equiv='refresh' content='5;url="<< req.POST("fwd") <<"' />"
+ "<meta http-equiv='refresh' content='5;url="
+ << req[post_data]["fwd"] <<"' />"
      "</head>"
      "<body>"
      "<center>"
      "You are already logged in. You should be redirected "
- "<a href='"<< req.POST("fwd") <<"'>here</a>"
+ "<a href='"<< req[post_data]["fwd"] <<"'>here</a>"
      " in five seconds."
      "</center>";
      show_passed_variables(req, resp);
@@ -85,7 +86,8 @@
           "<span class='red'>Your user name must only use letters, numbers or "
           "the underscore character."
           "</span>"
- "<input type='text' name='name' value='"<< req.POST("name") <<"' />"
+ "<input type='text' name='name' value='"
+ << req[post_data]["name"] <<"' />"
           "<input type='button' name='cmd' value='login' />"
          "</form>"
        "</center>";
@@ -133,18 +135,18 @@
 
   // If there's already a session id set, warn them and then redirect
   // them to where they would be going anyway.
- if (!req.cookie("uuid").empty()) {
+ if (!req[cookie_data]["uuid"].empty()) {
     return show_already_logged_in_page(req, resp);
   }
 
   // If they haven't asked explicitly to log in, show the default page.
- string cmd(req.POST("cmd"));
+ string cmd (req[post_data]["cmd"]);
   if (cmd.empty() || cmd != "login") {
     return show_default_page(req, resp);
   }
 
   // If they're name is invalid, inform them.
- string name(req.POST("name"));
+ string name (req[post_data]["name"]);
   if (!verify_name(name)) {
     return show_name_error_page(req, resp);
   }
@@ -153,7 +155,7 @@
   // Here we give them a 'universally unique id' and forward them to a
   // cookie checking page.
   resp<< cookie("uuid", make_uuid())
- << location("CheckCookie?fwd=" + req.POST("fwd"));
+ << location("CheckCookie?fwd=" + req[post_data]["fwd"]);
   resp.send(req.client());
 
   return req.close(http::ok);

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/Logout.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/Logout.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/example/acgi/login/Logout.cpp 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -14,7 +14,7 @@
 
   resp<< cookie("uuid");
   boost::system::error_code ec;
- std::string fwd(req.form("fwd", ec));
+ std::string fwd (req[form_data]["fwd"]);
   resp<< location(fwd);
 
   resp.send(req.client());

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/echo/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/echo/Jamfile.v2 (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/example/cgi/echo/Jamfile.v2 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -7,9 +7,10 @@
 project boost/cgi/example/cgi/echo ;
 
 exe cgi_echo
- : main.cpp
- /boost/thread/
- /boost/regex/
+ :
+ main.cpp
+ :
+ <library>/boost/cgi/
   ;
 
 

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/acgi_simple_request.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/acgi_simple_request.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/acgi_simple_request.cpp 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -16,9 +16,9 @@
 
 #include "request_test_template.hpp"
 
+
 void init_env()
 {
- using namespace std;
   setenv("HTTP_HOST", "localhost", 1);
   setenv("SCRIPT_NAME", "some/test/script", 1);
   setenv("EMPTY_VAR", "", 1);

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -18,7 +18,6 @@
 
 void init_env()
 {
- using namespace std;
   setenv("HTTP_HOST", "localhost", 1);
   setenv("SCRIPT_NAME", "some/test/script", 1);
   setenv("EMPTY_VAR", "", 1);

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cookie.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cookie.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cookie.cpp 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -18,6 +18,7 @@
   // delete the cookie. ie. set its value to NULL and give it a date
   // in the past
   using namespace cgi;
+ using cgi::common::cookie;
   using namespace std;
 
   string ex("Fri, 05-Jun-1989 15:30:00 GMT");
@@ -38,6 +39,7 @@
 {
   // Check the full version of the constructor works (simple test)
   using namespace cgi;
+ using cgi::common::cookie;
   using namespace std;
 
   string ex("Wed, 03-Oct-2007 16:26:06 GMT");
@@ -62,6 +64,7 @@
   // delete the cookie. ie. set its value to NULL and give it a date
   // in the past
   using namespace cgi;
+ using cgi::common::cookie;
   using namespace std;
 
   string cookie_content(

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/request_test_template.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/request_test_template.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/request_test_template.hpp 2008-05-19 15:21:20 EDT (Mon, 19 May 2008)
@@ -49,3 +49,19 @@
     BOOST_CHECK_EQUAL( req[cookie_data]["foo"], "bar" ); \
     BOOST_CHECK_EQUAL( req[cookie_data]["encoded"], "\"£$%^$*^hh%%thd@:" );
 
+
+#include <string>
+#include <cstdlib>
+#include <boost/config.hpp>
+
+#ifdef BOOST_MSVC
+ // MSVC doesn't support setenv, but it does support putenv
+ void setenv(std::string const& name, std::string const& val, int reset = 0)
+ {
+ if (putenv((name + val).c_str()) != 0)
+ {
+ std::cerr<< "Error adding environment variable." << std::endl;
+ }
+ }
+#endif
+


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