diff options
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 12 | ||||
-rw-r--r-- | project2/cgi/cgiProgRouter.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStageDefaultError.cpp | 4 | ||||
-rw-r--r-- | project2/cgi/cgiStageDefaultNotFound.cpp | 2 | ||||
-rw-r--r-- | project2/common/appEngine.cpp | 2 | ||||
-rw-r--r-- | project2/common/commonObjects.cpp | 9 | ||||
-rw-r--r-- | project2/common/commonObjects.h | 4 | ||||
-rw-r--r-- | project2/common/environment.cpp | 16 | ||||
-rw-r--r-- | project2/common/environment.h | 8 | ||||
-rw-r--r-- | project2/common/scripts.cpp | 10 | ||||
-rw-r--r-- | project2/common/scripts.h | 8 | ||||
-rw-r--r-- | project2/common/sessionContainer.cpp | 9 | ||||
-rw-r--r-- | project2/common/sessionContainer.h | 6 | ||||
-rw-r--r-- | project2/xml/xmlCache.cpp | 2 | ||||
-rw-r--r-- | project2/xml/xmlPresenter.cpp | 5 | ||||
-rw-r--r-- | project2/xml/xmlRawRows.cpp | 2 | ||||
-rw-r--r-- | project2/xml/xmlScriptParser.cpp | 2 |
17 files changed, 59 insertions, 44 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 654c2ce..75bc004 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -105,7 +105,7 @@ CgiApplicationEngine::process() const if (!sessionEmpty || !cursession->Empty()) { sessionsContainer->SaveSession(cursession); header->setCookie(cgicc::HTTPCookie(SESSIONID, boost::lexical_cast<std::string>(cursession->ID()), "Session ID", - _env->getServerName().substr(_env->getServerName().find(".")), env()->sessionTimeOut, "/", false)); + _env->getServerName().substr(_env->getServerName().find(".")), SessionContainer::sessionTimeOut, "/", false)); } if (TransformSourcePtr ts = currentStage.get<2>()) { TransformSourcePtr final = finalTransformSource(ts); @@ -162,7 +162,7 @@ CgiApplicationEngine::addEnvData(const MultiRowSetPresenter * p, OutputOptionsPt { if (!o || o->Environment()) { // Environment set up by web server - p->addNewRowSet("environment", env()->scriptNamespacePrefix); + p->addNewRowSet("environment", Scripts::scriptNamespacePrefix); // Server stuff addEnvToPresenter(p, "servername", &cgicc::CgiEnvironment::getServerName); addEnvToPresenter(p, "serversoftware", &cgicc::CgiEnvironment::getServerSoftware); @@ -179,7 +179,7 @@ CgiApplicationEngine::addEnvData(const MultiRowSetPresenter * p, OutputOptionsPt if (!o || o->URL()) { // URL elements - p->addNewRowSet("uriElems", env()->scriptNamespacePrefix); + p->addNewRowSet("uriElems", Scripts::scriptNamespacePrefix); p->addAttribute("full", _env->getRedirectURL()); _env->router->present(p); p->finishRowSet(); @@ -187,7 +187,7 @@ CgiApplicationEngine::addEnvData(const MultiRowSetPresenter * p, OutputOptionsPt if (!o || o->Parameters()) { // Parameters - p->addNewRowSet("params", env()->scriptNamespacePrefix); + p->addNewRowSet("params", Scripts::scriptNamespacePrefix); BOOST_FOREACH(cgicc::FormEntry fe, _env->cgi->getElements()) { p->addNamedValue(fe.getName(), fe.getValue()); } @@ -209,7 +209,7 @@ CgiApplicationEngine::addAppData(const MultiRowSetPresenter * p, OutputOptionsPt } if (!outputCachingActive && (!cursession->Empty()) && (!o || o->Session())) { // Sessions variables - p->addNewRowSet("session", env()->scriptNamespacePrefix); + p->addNewRowSet("session", Scripts::scriptNamespacePrefix); p->addAttribute("id", boost::lexical_cast<Glib::ustring>(cursession->ID())); cursession->ForeachValue(boost::bind(&CgiApplicationEngine::addVarToPresenter, this, p, _1, _2)); p->finishRowSet(); @@ -217,7 +217,7 @@ CgiApplicationEngine::addAppData(const MultiRowSetPresenter * p, OutputOptionsPt if (!outputCachingActive && (!o || o->Timing())) { // Timing info - p->addNewRowSet("timing", env()->scriptNamespacePrefix); + p->addNewRowSet("timing", Scripts::scriptNamespacePrefix); p->addAttribute("start", startTime); if (!endTime.is_not_a_date_time()) { p->addAttribute("end", endTime); diff --git a/project2/cgi/cgiProgRouter.cpp b/project2/cgi/cgiProgRouter.cpp index d187de2..e8ae15d 100644 --- a/project2/cgi/cgiProgRouter.cpp +++ b/project2/cgi/cgiProgRouter.cpp @@ -35,7 +35,7 @@ class RoutingTable { } void setRouteScript() { - routeScript = ScriptReader::resolveScript(Environment::getCurrent()->datasourceRoot, routeScriptPath, true); + routeScript = ScriptReader::resolveScript(CommonObjects::datasourceRoot, routeScriptPath, true); routeScript->loader.addLoadTarget(routeScript->root(), Storer::into<ElementLoader>(&routes)); routes.clear(); routeScript->load(NULL, true); diff --git a/project2/cgi/cgiStageDefaultError.cpp b/project2/cgi/cgiStageDefaultError.cpp index b8f0b4b..4c3eefe 100644 --- a/project2/cgi/cgiStageDefaultError.cpp +++ b/project2/cgi/cgiStageDefaultError.cpp @@ -36,8 +36,8 @@ CgiApplicationEngine::NextStage CgiApplicationEngine::DefaultErrorStage::run() { pres->init(); - pres->addNamedValue("error-type", env()->scriptNamespacePrefix, buf); - pres->addNamedValue("error-what", env()->scriptNamespacePrefix, what.c_str()); + pres->addNamedValue("error-type", Scripts::scriptNamespacePrefix, buf); + pres->addNamedValue("error-what", Scripts::scriptNamespacePrefix, what.c_str()); return NextStage(NULL, this, pres.get(), pres.get()); } diff --git a/project2/cgi/cgiStageDefaultNotFound.cpp b/project2/cgi/cgiStageDefaultNotFound.cpp index 5b68bc6..e497058 100644 --- a/project2/cgi/cgiStageDefaultNotFound.cpp +++ b/project2/cgi/cgiStageDefaultNotFound.cpp @@ -24,7 +24,7 @@ CgiApplicationEngine::NextStage CgiApplicationEngine::DefaultNotFoundStage::run() { pres->init(); - pres->addNamedValue("missing-resource", env()->scriptNamespacePrefix, nf.what()); + pres->addNamedValue("missing-resource", Scripts::scriptNamespacePrefix, nf.what()); return NextStage(NULL, this, pres.get(), pres.get()); } diff --git a/project2/common/appEngine.cpp b/project2/common/appEngine.cpp index c6d3e92..ce71153 100644 --- a/project2/common/appEngine.cpp +++ b/project2/common/appEngine.cpp @@ -33,7 +33,7 @@ void ApplicationEngine::addCoreAppData(const MultiRowSetPresenter * p) const { // Message log - p->addNewRowSet("messages", env()->scriptNamespacePrefix); + p->addNewRowSet("messages", Scripts::scriptNamespacePrefix); p->addNewArray("message", true); BOOST_FOREACH(const Messages::value_type & m, appMessages) { p->addNewRow("message"); diff --git a/project2/common/commonObjects.cpp b/project2/common/commonObjects.cpp index c18db3c..23f2edb 100644 --- a/project2/common/commonObjects.cpp +++ b/project2/common/commonObjects.cpp @@ -9,6 +9,13 @@ CommonObjects::CommonObjects() : { } +DECLARE_OPTIONS(CommonObjects, "Project2 Data Source options") +("common.datasourceRoot", Options::value(&datasourceRoot, "datasources"), + "The folder in which to find datasource definitions") +END_OPTIONS(CommonObjects); + +std::string CommonObjects::datasourceRoot; + CommonObjects::CommonObjects(ScriptNodePtr s) : script(s->script), scriptLoaded(false) @@ -29,7 +36,7 @@ CommonObjects::getSource(const std::string & name) const CommonObjects::DataSources::const_iterator CommonObjects::loadDataSource(const std::string & name) const { - ScriptReaderPtr dbs = ScriptReader::resolveScript(Environment::getCurrent()->datasourceRoot, name, true); + ScriptReaderPtr dbs = ScriptReader::resolveScript(datasourceRoot, name, true); dbs->loader.addLoadTarget(dbs->root(), Storer::into<ElementLoader>(&datasources)); dbs->load(NULL, false); return safeMapFind<DataSourceNotFound>(datasources, name); diff --git a/project2/common/commonObjects.h b/project2/common/commonObjects.h index b70185c..788e3bd 100644 --- a/project2/common/commonObjects.h +++ b/project2/common/commonObjects.h @@ -4,6 +4,7 @@ #include "dataSource.h" #include "rowSet.h" #include "scriptStorage.h" +#include "options.h" class CommonObjects : public virtual IntrusivePtrBase { public: @@ -33,6 +34,9 @@ class CommonObjects : public virtual IntrusivePtrBase { } void loadScriptComponents() const; + INITOPTIONS; + static std::string datasourceRoot; + protected: RowSets rowSets; mutable DataSources datasources; diff --git a/project2/common/environment.cpp b/project2/common/environment.cpp index a996408..69f853c 100644 --- a/project2/common/environment.cpp +++ b/project2/common/environment.cpp @@ -4,22 +4,6 @@ const Environment * Environment::currentEnv(NULL); -DECLARE_OPTIONS(Environment, "Project2 Common options") -("common.datasourceRoot", Options::value(&datasourceRoot, "datasources"), - "The folder in which to find datasource definitions") -("common.namespace", Options::value(&scriptNamespace, "http://project2.randomdan.homeip.net"), - "The namespace to use for Project2 components and responses") -("common.namespacePrefix", Options::value(&scriptNamespacePrefix, "project2"), - "The namespace prefix to use for the Project2 namespace") -("common.sessionTimeOut", Options::value(&sessionTimeOut, 3600), - "The time after which idle sessions are forgotten") -END_OPTIONS(Environment); - -time_t Environment::sessionTimeOut; -std::string Environment::scriptNamespacePrefix; -std::string Environment::scriptNamespace; -std::string Environment::datasourceRoot; - Environment::Environment() { currentEnv = this; diff --git a/project2/common/environment.h b/project2/common/environment.h index 7289bb0..a97255f 100644 --- a/project2/common/environment.h +++ b/project2/common/environment.h @@ -3,7 +3,6 @@ #include <string> #include <glibmm/ustring.h> -#include "options.h" #include "exceptions.h" #include "scripts.h" @@ -21,15 +20,8 @@ class Environment { virtual std::string getServerName() const = 0; virtual const Glib::ustring & platform() const = 0; - INITOPTIONS; private: static const Environment * currentEnv; - - public: - static std::string datasourceRoot; - static std::string scriptNamespace; - static std::string scriptNamespacePrefix; - static time_t sessionTimeOut; }; #endif diff --git a/project2/common/scripts.cpp b/project2/common/scripts.cpp index cb5d035..767ff0d 100644 --- a/project2/common/scripts.cpp +++ b/project2/common/scripts.cpp @@ -5,6 +5,16 @@ ScriptReader::ScriptCache ScriptReader::scriptCache; +DECLARE_OPTIONS(Scripts, "Project2 Script options") +("common.namespace", Options::value(&scriptNamespace, "http://project2.randomdan.homeip.net"), + "The namespace to use for Project2 components and responses") +("common.namespacePrefix", Options::value(&scriptNamespacePrefix, "project2"), + "The namespace prefix to use for the Project2 namespace") +END_OPTIONS(Scripts); + +std::string Scripts::scriptNamespacePrefix; +std::string Scripts::scriptNamespace; + ScriptNode::ScriptNode(ScriptReaderPtr s) : script(s) { diff --git a/project2/common/scripts.h b/project2/common/scripts.h index ed4d9fd..0cb478c 100644 --- a/project2/common/scripts.h +++ b/project2/common/scripts.h @@ -10,6 +10,7 @@ #include "scripts_fwd.h" #include "exceptions.h" #include "variableType.h" +#include "options.h" #include <vector> SimpleMessageException(ValueNotFound); @@ -18,6 +19,13 @@ SimpleMessage2Exception(DependencyNotFound); class VariableImpl; +class Scripts { + public: + INITOPTIONS; + static std::string scriptNamespace; + static std::string scriptNamespacePrefix; +}; + class ScriptNode : public IntrusivePtrBase { public: ScriptNode(ScriptReaderPtr); diff --git a/project2/common/sessionContainer.cpp b/project2/common/sessionContainer.cpp index 8caa351..e9c76c9 100644 --- a/project2/common/sessionContainer.cpp +++ b/project2/common/sessionContainer.cpp @@ -6,6 +6,13 @@ SessionContainer::SessionContainer() { } +DECLARE_OPTIONS(SessionContainer, "Project2 Session options") +("common.sessionTimeOut", Options::value(&sessionTimeOut, 3600), + "The time after which idle sessions are forgotten") +END_OPTIONS(SessionContainer); + +time_t SessionContainer::sessionTimeOut; + SessionContainer::~SessionContainer() { } @@ -17,7 +24,7 @@ SessionContainer::GetSession(const boost::uuids::uuid & id) const if (id.is_nil() || !(s = getSession(id))) { s = new Session(); } - s->ExpiryTime(time(NULL) + Environment::getCurrent()->sessionTimeOut); + s->ExpiryTime(time(NULL) + sessionTimeOut); return s; } diff --git a/project2/common/sessionContainer.h b/project2/common/sessionContainer.h index 75e5f02..4ce2a33 100644 --- a/project2/common/sessionContainer.h +++ b/project2/common/sessionContainer.h @@ -2,8 +2,9 @@ #define SESSIONCONTAINER_H #include <boost/uuid/uuid.hpp> -#include "session.h" #include <intrusivePtrBase.h> +#include "session.h" +#include "options.h" class SessionContainer : public IntrusivePtrBase { public: @@ -13,6 +14,9 @@ class SessionContainer : public IntrusivePtrBase { SessionPtr GetSession(const boost::uuids::uuid & sid) const; virtual void SaveSession(SessionPtr sess) const = 0; + INITOPTIONS; + static time_t sessionTimeOut; + protected: virtual SessionPtr getSession(const boost::uuids::uuid & sid) const = 0; }; diff --git a/project2/xml/xmlCache.cpp b/project2/xml/xmlCache.cpp index 8b09dde..3481b1e 100644 --- a/project2/xml/xmlCache.cpp +++ b/project2/xml/xmlCache.cpp @@ -36,7 +36,7 @@ class XmlCache : public Cache { RowSetPresenterPtr openFor(const Glib::ustring & n, const Glib::ustring &, const IHaveParameters *) { - writeTo = new XmlPresenter(n, Environment::getCurrent()->scriptNamespace, Environment::getCurrent()->scriptNamespacePrefix); + writeTo = new XmlPresenter(n, Scripts::scriptNamespace, Scripts::scriptNamespacePrefix); return writeTo; } diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp index 671b48b..08978ce 100644 --- a/project2/xml/xmlPresenter.cpp +++ b/project2/xml/xmlPresenter.cpp @@ -77,8 +77,7 @@ XmlPresenter::init() responseDoc = XmlDocumentPtr(new xmlpp::Document("1.0")); nodeStack.clear(); nodeStack.push_back(responseDoc->create_root_node(root())); - declareNamespace(Environment::getCurrent()->scriptNamespacePrefix, - Environment::getCurrent()->scriptNamespace); + declareNamespace(Scripts::scriptNamespacePrefix, Scripts::scriptNamespace); // XSLT Style char * buf; if (!style().isNull() && asprintf(&buf, "type=\"text/xsl\" href=\"%s\"", @@ -200,7 +199,7 @@ class XmlNodeWriter : public boost::static_visitor<bool> { protected: void addType(bool condition, const char * type) const { if (condition) { - node->set_attribute("type", type, Environment::getCurrent()->scriptNamespacePrefix); + node->set_attribute("type", type, Scripts::scriptNamespacePrefix); } } private: diff --git a/project2/xml/xmlRawRows.cpp b/project2/xml/xmlRawRows.cpp index 0da516f..3511981 100644 --- a/project2/xml/xmlRawRows.cpp +++ b/project2/xml/xmlRawRows.cpp @@ -73,7 +73,7 @@ void XmlRawRowsBase::execute(const xmlpp::Document * doc, const RowProcessor * r const xmlpp::TextNode * t = ie->get_child_text(); if (t) { rs.fields[col] = VariableType::make(t->get_content(), - VariableType::getTypeFromName(ie->get_attribute_value("type", Environment::getCurrent()->scriptNamespacePrefix))); + VariableType::getTypeFromName(ie->get_attribute_value("type", Scripts::scriptNamespacePrefix))); } col++; } diff --git a/project2/xml/xmlScriptParser.cpp b/project2/xml/xmlScriptParser.cpp index cf873a3..1040667 100644 --- a/project2/xml/xmlScriptParser.cpp +++ b/project2/xml/xmlScriptParser.cpp @@ -119,7 +119,7 @@ XmlScriptNode::xmlElement() const bool XmlScriptNode::componentNamespace() const { - return element->get_namespace_uri().raw() == Environment::getCurrent()->scriptNamespace; + return element->get_namespace_uri().raw() == Scripts::scriptNamespace; } std::string |