From 3fc84507bf1da84a6cee2f73054bdfb19b2ea4f0 Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 15 Feb 2011 01:25:15 +0000 Subject: Add debug option for dumping the data document before sending it to the web server --- project2/cgi/cgiAppEngine.cpp | 5 +++++ project2/cgi/cgiEnvironment.cpp | 6 ++++++ project2/cgi/cgiEnvironment.h | 4 ++++ project2/environment.cpp | 11 ++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 364d393..1d00c18 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -62,6 +62,11 @@ CgiApplicationEngine::process() const header->setCookie(cgicc::HTTPCookie(SESSIONID, sessionID.str(), "Session ID", _env->getServerName().substr(_env->getServerName().find(".")), 3600, "/", false)); } +#ifndef NDEBUG + if (!_env->dumpdatadoc.empty()) { + doc->write_to_file_formatted(_env->dumpdatadoc); + } +#endif } CgiApplicationEngine::Stage::Stage(const CgiApplicationEngine * e) : appEngine(e) diff --git a/project2/cgi/cgiEnvironment.cpp b/project2/cgi/cgiEnvironment.cpp index ae65183..aa9e57f 100644 --- a/project2/cgi/cgiEnvironment.cpp +++ b/project2/cgi/cgiEnvironment.cpp @@ -27,6 +27,12 @@ boost::program_options::options_description CgiEnvironment::addOptions(boost::program_options::positional_options_description &) { boost::program_options::options_description cgi("Project2 CGI options"); +#ifndef NDEBUG + cgi.add_options() + ("dumpdatadoc", boost::program_options::value(&dumpdatadoc), + "Write a copy of the data document before sending it to the web server") + ; +#endif return cgi; } diff --git a/project2/cgi/cgiEnvironment.h b/project2/cgi/cgiEnvironment.h index 005a49b..1774417 100644 --- a/project2/cgi/cgiEnvironment.h +++ b/project2/cgi/cgiEnvironment.h @@ -26,6 +26,10 @@ class CgiEnvironment : public Environment, public cgicc::CgiEnvironment { private: boost::program_options::options_description addOptions(boost::program_options::positional_options_description &); void postinit(const boost::program_options::options_description &, const boost::program_options::variables_map &); +#ifndef NDEBUG + public: + std::string dumpdatadoc; +#endif }; #endif diff --git a/project2/environment.cpp b/project2/environment.cpp index 5c50517..5510b1a 100644 --- a/project2/environment.cpp +++ b/project2/environment.cpp @@ -36,7 +36,16 @@ Environment::init() po::store(po::parse_environment(all, "P2_"), settings); if (boost::filesystem::exists(".p2config")) { std::ifstream f(".p2config"); - po::store(po::parse_config_file(f, all), settings); + // Allow anything in release, but valid the config file in debug + // Some options only work in debug and you wouldn't want extra + // config entries to break an install + po::store(po::parse_config_file(f, all, +#if NDEBUG + true +#else + false +#endif + ), settings); } po::notify(settings); -- cgit v1.2.3