summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-07-29 23:56:27 +0000
committerrandomdan <randomdan@localhost>2011-07-29 23:56:27 +0000
commit510c77d0eaa1cda885541463bdce249b65f95bbf (patch)
tree80d9a3643102b77f972e1fd1d15713274c441df0
parentWork around old compiler bug by fully qualifying function call to not get mix... (diff)
downloadproject2-510c77d0eaa1cda885541463bdce249b65f95bbf.tar.bz2
project2-510c77d0eaa1cda885541463bdce249b65f95bbf.tar.xz
project2-510c77d0eaa1cda885541463bdce249b65f95bbf.zip
Strip out some useless wrappers
Add support for plugable session containers
-rw-r--r--project2/appEngine.cpp2
-rw-r--r--project2/cgi/cgiAppEngine.cpp23
-rw-r--r--project2/cgi/cgiAppEngine.h2
-rw-r--r--project2/cgi/cgiEnvironment.cpp2
-rw-r--r--project2/cgi/cgiEnvironment.h1
-rw-r--r--project2/cgi/cgiStageDefaultError.cpp4
-rw-r--r--project2/cgi/cgiStageDefaultNotFound.cpp2
-rw-r--r--project2/commonObjects.cpp2
-rw-r--r--project2/environment.cpp20
-rw-r--r--project2/environment.h6
-rw-r--r--project2/sessionContainer.cpp3
-rw-r--r--project2/sessionContainer.h21
-rw-r--r--project2/sessionXml.cpp10
-rw-r--r--project2/sessionXml.h5
-rw-r--r--project2/xmlObjectLoader.cpp2
-rw-r--r--project2/xmlPresenter.cpp4
16 files changed, 52 insertions, 57 deletions
diff --git a/project2/appEngine.cpp b/project2/appEngine.cpp
index 9abe834..d8c097b 100644
--- a/project2/appEngine.cpp
+++ b/project2/appEngine.cpp
@@ -32,7 +32,7 @@ void
ApplicationEngine::addCoreAppData(const Presenter * p) const
{
// Message log
- p->pushSub("messages", env()->getXmlPrefix());
+ p->pushSub("messages", env()->xmlPrefix);
BOOST_FOREACH(const Messages::value_type & m, appMessages) {
p->pushSub("message");
p->addAttr("group", m->group);
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp
index ee19331..d601670 100644
--- a/project2/cgi/cgiAppEngine.cpp
+++ b/project2/cgi/cgiAppEngine.cpp
@@ -6,7 +6,6 @@
#include "../logger.h"
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
-#include "../sessionXml.h"
#include "../ostreamWrapper.h"
#include <boost/date_time/microsec_time_clock.hpp>
#include <glibmm/regex.h>
@@ -15,13 +14,12 @@ const std::string SESSIONID = "sessionID";
typedef UUID SIDKey;
typedef std::string SValue;
-SessionContainer * sessionsContainer = new SessionContainerXml();
-
SimpleMessageException(UnknownDomain);
CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e, std::ostream & io) :
ApplicationEngine("web/host"),
_env(e),
+ sessionsContainer(LoaderBase::getLoader<SessionContainerLoader, NotSupported>(e->sessionModule)->open()),
IO(io)
{
BOOST_FOREACH(const cgicc::HTTPCookie c, e->getCookieList()) {
@@ -34,7 +32,6 @@ CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e, std::ostrea
CgiApplicationEngine::~CgiApplicationEngine()
{
- sessionsContainer->CleanUp();
}
const Environment *
@@ -124,20 +121,20 @@ void
CgiApplicationEngine::addEnvData(const Presenter * p) const
{
// These were for debug... but why not pass them on?
- p->addField("servername", env()->getXmlPrefix(), env()->getServerName());
- p->addField("scriptname", env()->getXmlPrefix(), env()->getScriptName());
+ p->addField("servername", env()->xmlPrefix, env()->getServerName());
+ p->addField("scriptname", env()->xmlPrefix, env()->getScriptName());
// URL elements
- p->pushSub("uriElems", env()->getXmlPrefix());
+ p->pushSub("uriElems", env()->xmlPrefix);
BOOST_FOREACH(std::string s, _env->elems) {
- p->addField("uriElem", env()->getXmlPrefix(), s);
+ p->addField("uriElem", env()->xmlPrefix, s);
}
p->popSub();
// Parameters
- p->pushSub("params", env()->getXmlPrefix());
+ p->pushSub("params", env()->xmlPrefix);
BOOST_FOREACH(cgicc::FormEntry fe, _env->cgi->getElements()) {
- p->pushSub("param", env()->getXmlPrefix());
+ p->pushSub("param", env()->xmlPrefix);
p->addAttr("name", fe.getName());
p->addAttr("value", fe.getValue());
p->popSub();
@@ -151,11 +148,11 @@ CgiApplicationEngine::addAppData(const Presenter * p) const
addCoreAppData(p);
// Sessions variables
if (!sessionID.is_nil()) {
- p->pushSub("session", env()->getXmlPrefix());
+ p->pushSub("session", env()->xmlPrefix);
p->addField("id", sessionID.str());
Session::Values session(sessionsContainer->GetSession(sessionID)->GetValuesCopy());
BOOST_FOREACH(Session::Values::value_type sv, session) {
- p->pushSub("var", env()->getXmlPrefix());
+ p->pushSub("var", env()->xmlPrefix);
p->addAttr("value", sv.second);
p->addAttr("name", sv.first);
p->popSub();
@@ -164,7 +161,7 @@ CgiApplicationEngine::addAppData(const Presenter * p) const
}
// Timing info
- p->pushSub("timing", env()->getXmlPrefix());
+ p->pushSub("timing", env()->xmlPrefix);
p->addAttr("start", startTime);
if (!endTime.is_not_a_date_time()) {
p->addAttr("end", endTime);
diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h
index 8482181..2109a31 100644
--- a/project2/cgi/cgiAppEngine.h
+++ b/project2/cgi/cgiAppEngine.h
@@ -10,6 +10,7 @@
#include "../viewHost.h"
#include "../transform.h"
#include "../xmlPresenter.h"
+#include "../sessionContainer.h"
#include <boost/intrusive_ptr.hpp>
#include <boost/tuple/tuple.hpp>
@@ -46,6 +47,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
mutable DomainPlatforms domplat;
bool checkDomain(const DomainPlatforms::value_type & i) const;
void loadEngineSection(const xmlpp::Element *) const;
+ SessionContainerPtr sessionsContainer;
public:
class Stage;
diff --git a/project2/cgi/cgiEnvironment.cpp b/project2/cgi/cgiEnvironment.cpp
index e88dbc1..1382709 100644
--- a/project2/cgi/cgiEnvironment.cpp
+++ b/project2/cgi/cgiEnvironment.cpp
@@ -57,6 +57,8 @@ CgiEnvironment::addOptions(boost::program_options::positional_options_descriptio
"The present script to use when the requested script (or child) fails")
("dumpdatadoc", boost::program_options::value(&dumpdatadoc),
"Write a copy of the data document before sending it to the web server")
+ ("sessionModule", boost::program_options::value(&sessionModule)->default_value("xml"),
+ "The module with which to implement session management")
;
return cgi;
}
diff --git a/project2/cgi/cgiEnvironment.h b/project2/cgi/cgiEnvironment.h
index abfe78e..db39da8 100644
--- a/project2/cgi/cgiEnvironment.h
+++ b/project2/cgi/cgiEnvironment.h
@@ -37,6 +37,7 @@ class CgiEnvironment : public Environment, public cgicc::CgiEnvironment {
std::string notFoundPresent;
std::string onErrorPresent;
std::string defaultPresenter;
+ std::string sessionModule;
};
#endif
diff --git a/project2/cgi/cgiStageDefaultError.cpp b/project2/cgi/cgiStageDefaultError.cpp
index 767a634..1843905 100644
--- a/project2/cgi/cgiStageDefaultError.cpp
+++ b/project2/cgi/cgiStageDefaultError.cpp
@@ -28,8 +28,8 @@ CgiApplicationEngine::DefaultErrorStage::getHeader() const
CgiApplicationEngine::NextStage
CgiApplicationEngine::DefaultErrorStage::run()
{
- pres->addField("error-type", e->getXmlPrefix(), buf);
- pres->addField("error-what", e->getXmlPrefix(), what.c_str());
+ pres->addField("error-type", e->xmlPrefix, buf);
+ pres->addField("error-what", e->xmlPrefix, what.c_str());
return NextStage(NULL, this, pres.get(), pres.get());
}
diff --git a/project2/cgi/cgiStageDefaultNotFound.cpp b/project2/cgi/cgiStageDefaultNotFound.cpp
index 2e7acb1..8359aa7 100644
--- a/project2/cgi/cgiStageDefaultNotFound.cpp
+++ b/project2/cgi/cgiStageDefaultNotFound.cpp
@@ -22,7 +22,7 @@ CgiApplicationEngine::DefaultNotFoundStage::getHeader() const
CgiApplicationEngine::NextStage
CgiApplicationEngine::DefaultNotFoundStage::run()
{
- pres->addField("missing-resource", e->getXmlPrefix(), nf.what());
+ pres->addField("missing-resource", e->xmlPrefix, nf.what());
return NextStage(NULL, this, pres.get(), pres.get());
}
diff --git a/project2/commonObjects.cpp b/project2/commonObjects.cpp
index 63d4d1d..e811fe7 100644
--- a/project2/commonObjects.cpp
+++ b/project2/commonObjects.cpp
@@ -21,7 +21,7 @@ CommonObjects::DataSources::const_iterator
CommonObjects::loadDataSource(const std::string & name) const
{
XmlScriptParser xml(Environment::getCurrent()->resolveScript(
- Environment::getCurrent()->getDatasourceRoot(), name), true);
+ Environment::getCurrent()->datasourceRoot, name), true);
LoaderBase loader(true);
loader.supportedStorers.insert(Storer::into(&datasources));
diff --git a/project2/environment.cpp b/project2/environment.cpp
index 8a03af9..bdbc8f5 100644
--- a/project2/environment.cpp
+++ b/project2/environment.cpp
@@ -37,6 +37,8 @@ Environment::init()
"The XML namespace to use for Project2 components and responses")
("xmlprefix", boost::program_options::value(&xmlPrefix)->default_value("project2"),
"The XML namespace prefix to use for the Project2 XML namespace")
+ ("sessionTimeOut", boost::program_options::value(&sessionTimeOut)->default_value(3600),
+ "The time after which idle sessions are forgetten")
;
allOptions.add(common).add(addOptions(posOptions));
optionsBuilt = true;
@@ -68,24 +70,6 @@ Environment::~Environment()
Logger()->clear();
}
-const std::string &
-Environment::getDatasourceRoot() const
-{
- return datasourceRoot;
-}
-
-const Glib::ustring &
-Environment::getXmlNamespace() const
-{
- return xmlNamespace;
-}
-
-const Glib::ustring &
-Environment::getXmlPrefix() const
-{
- return xmlPrefix;
-}
-
const Environment *
Environment::getCurrent()
{
diff --git a/project2/environment.h b/project2/environment.h
index 6a822c7..681a80c 100644
--- a/project2/environment.h
+++ b/project2/environment.h
@@ -16,10 +16,6 @@ class Environment {
static const Environment * getCurrent();
- const std::string & getDatasourceRoot() const;
- const Glib::ustring & getXmlNamespace() const;
- const Glib::ustring & getXmlPrefix() const;
-
virtual Glib::ustring getParamUri(unsigned int idx) const = 0;
virtual Glib::ustring getParamQuery(const std::string & idx) const = 0;
@@ -44,9 +40,11 @@ class Environment {
static int clLevel;
static int slLevel;
+ public:
std::string datasourceRoot;
Glib::ustring xmlNamespace;
Glib::ustring xmlPrefix;
+ time_t sessionTimeOut;
};
#endif
diff --git a/project2/sessionContainer.cpp b/project2/sessionContainer.cpp
index 9028515..635889b 100644
--- a/project2/sessionContainer.cpp
+++ b/project2/sessionContainer.cpp
@@ -1,4 +1,5 @@
#include "sessionContainer.h"
+#include "environment.h"
SessionContainer::SessionContainer()
{
@@ -12,7 +13,7 @@ SessionPtr
SessionContainer::GetSession(UUID & id)
{
SessionPtr s = getSession(id);
- s->ExpiryTime(time(NULL) + 3600);
+ s->ExpiryTime(time(NULL) + Environment::getCurrent()->sessionTimeOut);
return s;
}
diff --git a/project2/sessionContainer.h b/project2/sessionContainer.h
index 6163200..fcad4b9 100644
--- a/project2/sessionContainer.h
+++ b/project2/sessionContainer.h
@@ -3,18 +3,35 @@
#include "uuid.h"
#include "session.h"
+#include <intrusivePtrBase.h>
-class SessionContainer {
+class SessionContainer : public IntrusivePtrBase {
public:
SessionContainer();
virtual ~SessionContainer() = 0;
SessionPtr GetSession(UUID & sid);
- virtual void CleanUp() { }
protected:
virtual SessionPtr getSession(UUID & sid) = 0;
};
+typedef boost::intrusive_ptr<SessionContainer> SessionContainerPtr;
+
+/// Base class to implement session container imlpementations
+class SessionContainerLoader : public ComponentLoader {
+ public:
+ virtual SessionContainerPtr open() const = 0;
+};
+
+/// Helper implemention for specific container types
+template <class SCType>
+class SessionContainerLoaderImpl : public SessionContainerLoader {
+ public:
+ virtual SessionContainerPtr open() const
+ {
+ return new SCType();
+ }
+};
#endif
diff --git a/project2/sessionXml.cpp b/project2/sessionXml.cpp
index 03b48bc..fc552a9 100644
--- a/project2/sessionXml.cpp
+++ b/project2/sessionXml.cpp
@@ -30,11 +30,9 @@ class SessionXml : public Session {
friend class SessionContainerXml;
};
-typedef boost::intrusive_ptr<SessionXml> SessionXmlPtr;
-
const char * xmlFile = "/tmp/project2sessions.xml";
-SessionXmlPtr currentSession;
+DECLARE_COMPONENT_LOADER("xml", SessionContainerXml, SessionContainerLoader);
SessionContainerXml::SessionContainerXml()
{
@@ -42,12 +40,6 @@ SessionContainerXml::SessionContainerXml()
SessionContainerXml::~SessionContainerXml()
{
- CleanUp();
-}
-
-void
-SessionContainerXml::CleanUp()
-{
if (currentSession) {
xmlpp::DomParser parser;
xmlpp::Document * doc;
diff --git a/project2/sessionXml.h b/project2/sessionXml.h
index 8086990..d8bc8aa 100644
--- a/project2/sessionXml.h
+++ b/project2/sessionXml.h
@@ -4,15 +4,16 @@
#include "sessionContainer.h"
#include <map>
+class SessionXml;
class SessionContainerXml : public SessionContainer {
public:
SessionContainerXml();
~SessionContainerXml();
- void CleanUp();
-
protected:
SessionPtr getSession(UUID & sid);
+ typedef boost::intrusive_ptr<SessionXml> SessionXmlPtr;
+ SessionXmlPtr currentSession;
};
#endif
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index c41b0c0..faa5b2a 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -27,7 +27,7 @@ typedef std::set<boost::shared_ptr<ComponentLoader> > ComponentLoaderSet;
LoaderBase::LoaderBase(bool r) :
recursive(r),
- ns(Environment::getCurrent()->getXmlNamespace())
+ ns(Environment::getCurrent()->xmlNamespace)
{
supportedStorers.insert(Storer::into(&libraries));
}
diff --git a/project2/xmlPresenter.cpp b/project2/xmlPresenter.cpp
index c6bb04d..b9e433c 100644
--- a/project2/xmlPresenter.cpp
+++ b/project2/xmlPresenter.cpp
@@ -28,8 +28,8 @@ void
XmlPresenter::createDoc(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle) const
{
nodeStack.push_back(responseDoc->create_root_node(responseRootNodeName));
- declareNamespace(Environment::getCurrent()->getXmlPrefix(),
- Environment::getCurrent()->getXmlNamespace());
+ declareNamespace(Environment::getCurrent()->xmlPrefix,
+ Environment::getCurrent()->xmlNamespace);
// XSLT Style
char * buf;
if (!responseStyle.empty() && asprintf(&buf, "type=\"text/xsl\" href=\"%s\"",