diff options
author | randomdan <randomdan@localhost> | 2011-02-04 14:39:54 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-02-04 14:39:54 +0000 |
commit | b9d463547a055a251710b1e046a473209a292c18 (patch) | |
tree | 52fe3919b6d4e4cc71c98f30e2e0640abaaee63b /project2/cgi | |
parent | Don't construct the dir end iterator every iteration (diff) | |
download | project2-b9d463547a055a251710b1e046a473209a292c18.tar.bz2 project2-b9d463547a055a251710b1e046a473209a292c18.tar.xz project2-b9d463547a055a251710b1e046a473209a292c18.zip |
Add concept of runtime configuration, set by HTTP hostname or environment variable depending on engine
Use it in ArtfulSeller, although there is currently only one platform
Diffstat (limited to 'project2/cgi')
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 28 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.h | 13 |
2 files changed, 40 insertions, 1 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index d1c1579..3a9e362 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -7,6 +7,7 @@ #include "../xmlObjectLoader.h" #include "../iterate.h" #include <boost/bind.hpp> +#include <boost/regex.hpp> #include "../sessionXml.h" const std::string SESSIONID = "sessionID"; @@ -15,8 +16,10 @@ typedef std::string SValue; SessionContainer * sessionsContainer = new SessionContainerXml(); +class UnknownDomain : public std::exception { }; + CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e) : - ApplicationEngine(), + ApplicationEngine("web/host"), _env(e), header(NULL) { @@ -181,3 +184,26 @@ CgiApplicationEngine::session() const return sessionsContainer->GetSession(sessionID); } +bool +CgiApplicationEngine::checkDomain(const CgiApplicationEngine::DomainPlatforms::value_type & i) const +{ + const std::string & h = _env->getServerName(); + return boost::regex_match(h.begin(), h.end(), boost::regex(i.first.raw())); +} + +Glib::ustring +CgiApplicationEngine::resolveCurrentConfig() const +{ + DomainPlatforms::const_iterator i = std::find_if(domplat.begin(), domplat.end(), boost::bind(&CgiApplicationEngine::checkDomain, this, _1)); + if (i != domplat.end()) { + return i->second; + } + throw UnknownDomain(); +} + +void +CgiApplicationEngine::loadEngineSection(const xmlpp::Element * e) const +{ + domplat.push_back(DomainPlatforms::value_type(e->get_attribute_value("name"), e->get_attribute_value("platform"))); +} + diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 532b74d..5a21e98 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -31,12 +31,22 @@ class CgiApplicationEngine : public ApplicationEngine { } const Environment * env() const; SessionPtr session() const; + virtual Glib::ustring resolveCurrentConfig() const; void addAppData(const Presenter * p) const; const CgiEnvironment * _env; + protected: mutable cgicc::HTTPContentHeader * header; + private: + typedef std::pair<Glib::ustring, Glib::ustring> DomainPlatform; + typedef std::list<DomainPlatform> DomainPlatforms; + mutable DomainPlatforms domplat; + bool checkDomain(const DomainPlatforms::value_type & i) const; + void loadEngineSection(const xmlpp::Element *) const; + mutable boost::shared_ptr<xmlpp::Document> doc; + class Stage; typedef boost::intrusive_ptr<Stage> StagePtr; class Stage : public virtual CommonObjects { @@ -47,6 +57,7 @@ class CgiApplicationEngine : public ApplicationEngine { protected: const CgiApplicationEngine * appEngine; }; + class RequestStage : public Stage { public: RequestStage(const CgiApplicationEngine *, const std::string & id); @@ -57,12 +68,14 @@ class CgiApplicationEngine : public ApplicationEngine { OrderedParamCheckers parameterChecks; NoOutputExecutes tasks; }; + class PresentStage : public Stage, public XmlPresenter { public: PresentStage(const CgiApplicationEngine *, const std::string & id); PresentStage(const CgiApplicationEngine *, const std::string & group, const std::string & id); virtual ~PresentStage(); virtual StagePtr run(); + }; mutable StagePtr currentStage; mutable UUID sessionID; |