diff options
author | randomdan <randomdan@localhost> | 2011-11-28 15:24:58 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-11-28 15:24:58 +0000 |
commit | b5d014dbc5466b7899c24fae9bdb449d44e67d22 (patch) | |
tree | 8e40b893938b0c1fb0c3f95716fdc262d7c20d5b /project2/cgi | |
parent | Tweak the JS map function used to find expired sessions, even if I can't expl... (diff) | |
download | project2-b5d014dbc5466b7899c24fae9bdb449d44e67d22.tar.bz2 project2-b5d014dbc5466b7899c24fae9bdb449d44e67d22.tar.xz project2-b5d014dbc5466b7899c24fae9bdb449d44e67d22.zip |
Groundwork for common presenter layer
Diffstat (limited to 'project2/cgi')
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 31 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.h | 14 | ||||
-rw-r--r-- | project2/cgi/cgiStageFail.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStageRedirect.cpp | 2 |
4 files changed, 33 insertions, 16 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 45ccd95..f647b0e 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -117,20 +117,30 @@ CgiApplicationEngine::Stage::~Stage() } void -CgiApplicationEngine::addEnvData(const Presenter * p) const +CgiApplicationEngine::addEnvData(const MultiRowSetPresenter * p) const { - // These were for debug... but why not pass them on? - p->addNamedValue("servername", env()->xmlPrefix, env()->getServerName()); - p->addNamedValue("scriptname", env()->xmlPrefix, env()->getScriptName()); - + // Environment set up by web server + p->addNewRowSet("environment", env()->xmlPrefix); + // Server stuff + addEnvToPresenter(p, "servername", &cgicc::CgiEnvironment::getServerName); + addEnvToPresenter(p, "serversoftware", &cgicc::CgiEnvironment::getServerSoftware); + addEnvToPresenter(p, "serverprotocol", &cgicc::CgiEnvironment::getServerProtocol); + addEnvToPresenter(p, "serverport", &cgicc::CgiEnvironment::getServerPort); + addEnvToPresenter(p, "serverhttps", &cgicc::CgiEnvironment::usingHTTPS); + // Request stuff + addEnvToPresenter(p, "referrer", &cgicc::CgiEnvironment::getReferrer); + addEnvToPresenter(p, "querystring", &cgicc::CgiEnvironment::getQueryString); + p->finishRowSet(); + // URL elements p->addNewRowSet("uriElems", env()->xmlPrefix); + p->addAttribute("full", _env->getRedirectURL()); BOOST_FOREACH(std::string s, _env->elems) { p->addNewRow("uriElem"); p->addAttribute("text", s); p->finishRow(); } - p->finishRow(); + p->finishRowSet(); // Parameters p->addNewRowSet("params", env()->xmlPrefix); @@ -143,24 +153,23 @@ CgiApplicationEngine::addEnvData(const Presenter * p) const p->finishRowSet(); } -static void -addToPresenter(const Presenter * p, const Glib::ustring & name, const VariableType & value) +CgiApplicationEngine::addVarToPresenter(const MultiRowSetPresenter * p, const Glib::ustring & name, const VariableType & value) const { p->addNewRow("var"); - p->addAttribute("value", value); p->addAttribute("name", name); + p->addAttribute("value", value); p->finishRow(); } void -CgiApplicationEngine::addAppData(const Presenter * p) const +CgiApplicationEngine::addAppData(const MultiRowSetPresenter * p) const { addCoreAppData(p); // Sessions variables p->addNewRowSet("session", env()->xmlPrefix); p->addAttribute("id", cursession->ID.str()); - cursession->ForeachValue(boost::bind(addToPresenter, p, _1, _2)); + cursession->ForeachValue(boost::bind(&CgiApplicationEngine::addVarToPresenter, this, p, _1, _2)); p->finishRowSet(); // Timing info diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 6e202e4..88419fb 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -18,6 +18,7 @@ class CgiEnvironment; class Session; namespace cgicc { class HTTPHeader; + class CgiEnvironment; } namespace xmlpp { class Document; @@ -35,8 +36,8 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink const Environment * env() const; SessionPtr session() const; virtual Glib::ustring resolveCurrentConfig() const; - void addAppData(const Presenter * p) const; - void addEnvData(const Presenter * p) const; + void addAppData(const MultiRowSetPresenter * p) const; + void addEnvData(const MultiRowSetPresenter * p) const; const CgiEnvironment * _env; private: @@ -48,13 +49,20 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink bool checkDomain(const DomainPlatforms::value_type & i) const; void loadEngineSection(const xmlpp::Element *) const; SessionContainerPtr sessionsContainer; + // Helpers + void addVarToPresenter(const MultiRowSetPresenter * p, const Glib::ustring & name, const VariableType &) const; + typedef std::string (cgicc::CgiEnvironment::*StrEnvGetter)() const; + template <class X> + void addEnvToPresenter(const MultiRowSetPresenter * p, const char * name, X (cgicc::CgiEnvironment::*getter)() const) const { + addVarToPresenter(p, name, (_env->*getter)()); + } public: class Stage; class ResponseStage; typedef boost::intrusive_ptr<Stage> StagePtr; typedef boost::intrusive_ptr<ResponseStage> ResponseStagePtr; - typedef boost::tuple<StagePtr, ResponseStagePtr, TransformSourcePtr, PresenterPtr> NextStage; + typedef boost::tuple<StagePtr, ResponseStagePtr, TransformSourcePtr, MultiRowSetPresenterPtr> NextStage; /// Base class for a stage iteration that should eventually produce a response for the client class Stage : public virtual IntrusivePtrBase { public: diff --git a/project2/cgi/cgiStageFail.cpp b/project2/cgi/cgiStageFail.cpp index 6a60700..97ac22a 100644 --- a/project2/cgi/cgiStageFail.cpp +++ b/project2/cgi/cgiStageFail.cpp @@ -36,7 +36,7 @@ namespace CgiApplicationExtras { code(e, "code", false, 500), message(e, "message", false, "Application error") { } - void execute(const Presenter *) const { + void execute(const MultiRowSetPresenter *) const { throw CgiApplicationEngine::ResponseStagePtr( new FailStage(dynamic_cast<const CgiEnvironment *>(Environment::getCurrent()), code(), message())); } diff --git a/project2/cgi/cgiStageRedirect.cpp b/project2/cgi/cgiStageRedirect.cpp index c2e498f..f72e986 100644 --- a/project2/cgi/cgiStageRedirect.cpp +++ b/project2/cgi/cgiStageRedirect.cpp @@ -34,7 +34,7 @@ namespace CgiApplicationExtras { View(e), url(e, "url", true) { } - void execute(const Presenter *) const { + void execute(const MultiRowSetPresenter *) const { throw CgiApplicationEngine::ResponseStagePtr( new RedirectStage(dynamic_cast<const CgiEnvironment *>(Environment::getCurrent()), url())); } |