summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2012-03-15 00:51:18 +0000
committerrandomdan <randomdan@localhost>2012-03-15 00:51:18 +0000
commit4532a493ba828558626d508c87bef8b833bb56be (patch)
treedb9755631690fa620b5d07ffc588660fb20e57b9
parentPort to C++0x (minor tweaks) (diff)
downloadproject2-4532a493ba828558626d508c87bef8b833bb56be.tar.bz2
project2-4532a493ba828558626d508c87bef8b833bb56be.tar.xz
project2-4532a493ba828558626d508c87bef8b833bb56be.zip
Strip clutter from CGI stages
-rw-r--r--project2/cgi/cgiAppEngine.cpp21
-rw-r--r--project2/cgi/cgiAppEngine.h24
-rw-r--r--project2/cgi/cgiStageCacheHit.cpp4
-rw-r--r--project2/cgi/cgiStageCustomError.cpp8
-rw-r--r--project2/cgi/cgiStageCustomNotFound.cpp8
-rw-r--r--project2/cgi/cgiStageDefaultError.cpp10
-rw-r--r--project2/cgi/cgiStageDefaultNotFound.cpp8
-rw-r--r--project2/cgi/cgiStageFail.cpp6
-rw-r--r--project2/cgi/cgiStageInitial.cpp10
-rw-r--r--project2/cgi/cgiStagePresent.cpp11
-rw-r--r--project2/cgi/cgiStageRedirect.cpp7
-rw-r--r--project2/cgi/cgiStageRequest.cpp6
12 files changed, 58 insertions, 65 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp
index be42af9..a503f3d 100644
--- a/project2/cgi/cgiAppEngine.cpp
+++ b/project2/cgi/cgiAppEngine.cpp
@@ -28,14 +28,14 @@ CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e, std::ostrea
catch (const NoSuchCookie &) {
cursession = sessionsContainer->GetSession(UUID());
}
- currentStage = NextStage(new InitialStage(e));
+ currentStage = NextStage(new InitialStage());
}
CgiApplicationEngine::~CgiApplicationEngine()
{
}
-const Environment *
+const CgiEnvironment *
CgiApplicationEngine::env() const
{
return _env;
@@ -101,24 +101,24 @@ CgiApplicationEngine::process() const
currentStage = currentStage.get<0>()->run();
}
catch (const CheckHost::CheckFailure & cf) {
- currentStage = NextStage(new PresentStage(_env, _env->resolveScript(_env->presentRoot, cf.failedCheck->present(), false)));
+ currentStage = NextStage(new PresentStage(_env->resolveScript(_env->presentRoot, cf.failedCheck->present(), false)));
}
catch (const ScriptNotFound & nf) {
if (_env->notFoundPresent.empty() || triedNotFound) {
- currentStage = NextStage(new DefaultNotFoundStage(_env, nf));
+ currentStage = NextStage(new DefaultNotFoundStage(nf));
}
else {
triedNotFound = true;
- currentStage = NextStage(new CustomNotFoundStage(_env, nf, _env->resolveScript(_env->errorPresentRoot, _env->notFoundPresent, false)));
+ currentStage = NextStage(new CustomNotFoundStage(nf, _env->resolveScript(_env->errorPresentRoot, _env->notFoundPresent, false)));
}
}
catch (const std::exception & ex) {
if (_env->onErrorPresent.empty() || triedOnError) {
- currentStage = NextStage(new DefaultErrorStage(_env, ex));
+ currentStage = NextStage(new DefaultErrorStage(ex));
}
else {
triedNotFound = true;
- currentStage = NextStage(new CustomErrorStage(_env, ex, _env->resolveScript(_env->errorPresentRoot, _env->onErrorPresent, false)));
+ currentStage = NextStage(new CustomErrorStage(ex, _env->resolveScript(_env->errorPresentRoot, _env->onErrorPresent, false)));
}
}
} while (currentStage.get<0>());
@@ -163,13 +163,14 @@ CgiApplicationEngine::process() const
}
}
-CgiApplicationEngine::Stage::Stage(const CgiEnvironment * env) :
- e(env)
+CgiApplicationEngine::Stage::~Stage()
{
}
-CgiApplicationEngine::Stage::~Stage()
+const CgiEnvironment *
+CgiApplicationEngine::Stage::env() const
{
+ return dynamic_cast<const CgiEnvironment *>(Environment::getCurrent());
}
void
diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h
index 154ca09..7e081e6 100644
--- a/project2/cgi/cgiAppEngine.h
+++ b/project2/cgi/cgiAppEngine.h
@@ -32,13 +32,13 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
virtual ~CgiApplicationEngine();
void process() const;
- const Environment * env() const;
+ const CgiEnvironment * env() const;
SessionPtr session() const;
void addAppData(const MultiRowSetPresenter * p, OutputOptionsPtr) const;
void addEnvData(const MultiRowSetPresenter * p, OutputOptionsPtr) const;
- const CgiEnvironment * _env;
private:
+ const CgiEnvironment * _env;
mutable boost::posix_time::ptime startTime;
mutable boost::posix_time::ptime endTime;
SessionContainerPtr sessionsContainer;
@@ -58,11 +58,10 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
/// Base class for a stage iteration that should eventually produce a response for the client
class Stage : public virtual IntrusivePtrBase {
public:
- Stage(const CgiEnvironment * e);
virtual ~Stage() = 0;
virtual NextStage run() = 0;
protected:
- const CgiEnvironment * e;
+ const CgiEnvironment * env() const;
};
/// Base class for a stage that can be a response to the client
@@ -70,7 +69,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
public:
typedef ANONORDEREDSTORAGEOF(PresenterCache) PresenterCaches;
- ResponseStage(const CgiEnvironment * e, ScriptNodePtr root);
+ ResponseStage(ScriptNodePtr root);
virtual HttpHeaderPtr getHeader() const = 0;
OutputOptionsPtr outputOptions;
@@ -81,14 +80,13 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
/// Stage implementation used to bootstrap the iteration process based on the CGI environment
class InitialStage : public Stage {
public:
- InitialStage(const CgiEnvironment * e);
virtual NextStage run();
};
/// Stage to process POST requests
class RequestStage : public ResponseStage, TaskHost {
public:
- RequestStage(const CgiEnvironment *, ScriptReaderPtr);
+ RequestStage(ScriptReaderPtr);
virtual NextStage run();
virtual HttpHeaderPtr getHeader() const;
@@ -99,7 +97,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
/// Stage to process GET requests and follow up RequestStages
class PresentStage : public virtual ResponseStage, ViewHost {
public:
- PresentStage(const CgiEnvironment * e, ScriptReaderPtr);
+ PresentStage(ScriptReaderPtr);
MultiRowSetPresenterPtr getPresenter() const;
virtual NextStage run();
@@ -111,7 +109,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
/// Stage to return previous cached output
class CacheHitStage : public virtual ResponseStage {
public:
- CacheHitStage(const CgiEnvironment * e, ScriptNodePtr, PresenterCachePtr);
+ CacheHitStage(ScriptNodePtr, PresenterCachePtr);
virtual NextStage run();
virtual HttpHeaderPtr getHeader() const;
@@ -122,7 +120,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
/// The built-in fail-safe not found stage
class DefaultNotFoundStage : public virtual ResponseStage {
public:
- DefaultNotFoundStage(const CgiEnvironment *, const ScriptNotFound &);
+ DefaultNotFoundStage(const ScriptNotFound &);
virtual NextStage run();
virtual HttpHeaderPtr getHeader() const;
@@ -134,7 +132,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
/// Custom not found handling stage
class CustomNotFoundStage : public DefaultNotFoundStage, public PresentStage {
public:
- CustomNotFoundStage(const CgiEnvironment *, const ScriptNotFound &, ScriptReaderPtr);
+ CustomNotFoundStage(const ScriptNotFound &, ScriptReaderPtr);
virtual NextStage run();
virtual HttpHeaderPtr getHeader() const;
};
@@ -142,7 +140,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
/// The built-in fail-safe unhandled error stage
class DefaultErrorStage : public virtual ResponseStage {
public:
- DefaultErrorStage(const CgiEnvironment *, const std::exception &);
+ DefaultErrorStage(const std::exception &);
~DefaultErrorStage();
virtual NextStage run();
@@ -156,7 +154,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
/// Custom unhandled error handling stage
class CustomErrorStage : public DefaultErrorStage, public PresentStage {
public:
- CustomErrorStage(const CgiEnvironment *, const std::exception &, ScriptReaderPtr);
+ CustomErrorStage(const std::exception &, ScriptReaderPtr);
virtual NextStage run();
virtual HttpHeaderPtr getHeader() const;
};
diff --git a/project2/cgi/cgiStageCacheHit.cpp b/project2/cgi/cgiStageCacheHit.cpp
index 728cc56..8d854b6 100644
--- a/project2/cgi/cgiStageCacheHit.cpp
+++ b/project2/cgi/cgiStageCacheHit.cpp
@@ -5,8 +5,8 @@
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
-CgiApplicationEngine::CacheHitStage::CacheHitStage(const CgiEnvironment * e, ScriptNodePtr s, PresenterCachePtr pcp) :
- CgiApplicationEngine::ResponseStage(e, s),
+CgiApplicationEngine::CacheHitStage::CacheHitStage(ScriptNodePtr s, PresenterCachePtr pcp) :
+ CgiApplicationEngine::ResponseStage(s),
pc(pcp)
{
}
diff --git a/project2/cgi/cgiStageCustomError.cpp b/project2/cgi/cgiStageCustomError.cpp
index 957b572..56739fd 100644
--- a/project2/cgi/cgiStageCustomError.cpp
+++ b/project2/cgi/cgiStageCustomError.cpp
@@ -4,12 +4,12 @@
#include "cgiHttpHeader.h"
#include "logger.h"
-CgiApplicationEngine::CustomErrorStage::CustomErrorStage(const CgiEnvironment * env, const std::exception & ex, ScriptReaderPtr s) :
- CgiApplicationEngine::ResponseStage(env, s->root()),
+CgiApplicationEngine::CustomErrorStage::CustomErrorStage(const std::exception & ex, ScriptReaderPtr s) :
+ CgiApplicationEngine::ResponseStage(s->root()),
::CommonObjects(s->root()),
::CheckHost(s->root()),
- CgiApplicationEngine::DefaultErrorStage(env, ex),
- CgiApplicationEngine::PresentStage(env, s)
+ CgiApplicationEngine::DefaultErrorStage(ex),
+ CgiApplicationEngine::PresentStage(s)
{
}
diff --git a/project2/cgi/cgiStageCustomNotFound.cpp b/project2/cgi/cgiStageCustomNotFound.cpp
index 3ce8012..872da77 100644
--- a/project2/cgi/cgiStageCustomNotFound.cpp
+++ b/project2/cgi/cgiStageCustomNotFound.cpp
@@ -4,12 +4,12 @@
#include "cgiHttpHeader.h"
#include "logger.h"
-CgiApplicationEngine::CustomNotFoundStage::CustomNotFoundStage(const CgiEnvironment * env, const ScriptNotFound & notfound, ScriptReaderPtr s) :
- CgiApplicationEngine::ResponseStage(env, s->root()),
+CgiApplicationEngine::CustomNotFoundStage::CustomNotFoundStage(const ScriptNotFound & notfound, ScriptReaderPtr s) :
+ CgiApplicationEngine::ResponseStage(s->root()),
::CommonObjects(s->root()),
::CheckHost(s->root()),
- CgiApplicationEngine::DefaultNotFoundStage(env, notfound),
- CgiApplicationEngine::PresentStage(env, s)
+ CgiApplicationEngine::DefaultNotFoundStage(notfound),
+ CgiApplicationEngine::PresentStage(s)
{
}
diff --git a/project2/cgi/cgiStageDefaultError.cpp b/project2/cgi/cgiStageDefaultError.cpp
index d2abeef..70efafc 100644
--- a/project2/cgi/cgiStageDefaultError.cpp
+++ b/project2/cgi/cgiStageDefaultError.cpp
@@ -7,11 +7,11 @@
static const Glib::ustring DefaultErrorStageResp("error");
-CgiApplicationEngine::DefaultErrorStage::DefaultErrorStage(const CgiEnvironment * env, const std::exception & ex) :
- CgiApplicationEngine::ResponseStage(env, NULL),
+CgiApplicationEngine::DefaultErrorStage::DefaultErrorStage(const std::exception & ex) :
+ CgiApplicationEngine::ResponseStage(NULL),
buf(__cxxabiv1::__cxa_demangle(typeid(ex).name(), NULL, NULL, NULL)),
what(ex.what()),
- pres(new XmlPresenter(DefaultErrorStageResp, e->errorTransformStyle, e->errorContentType))
+ pres(new XmlPresenter(DefaultErrorStageResp, env()->errorTransformStyle, env()->errorContentType))
{
}
@@ -29,8 +29,8 @@ CgiApplicationEngine::DefaultErrorStage::getHeader() const
CgiApplicationEngine::NextStage
CgiApplicationEngine::DefaultErrorStage::run()
{
- pres->addNamedValue("error-type", e->scriptNamespacePrefix, buf);
- pres->addNamedValue("error-what", e->scriptNamespacePrefix, what.c_str());
+ pres->addNamedValue("error-type", env()->scriptNamespacePrefix, buf);
+ pres->addNamedValue("error-what", env()->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 b971dc3..8b3d6cc 100644
--- a/project2/cgi/cgiStageDefaultNotFound.cpp
+++ b/project2/cgi/cgiStageDefaultNotFound.cpp
@@ -6,10 +6,10 @@
static const Glib::ustring DefaultNotFoundStageResp("notfound");
-CgiApplicationEngine::DefaultNotFoundStage::DefaultNotFoundStage(const CgiEnvironment * env, const ScriptNotFound & notfound) :
- CgiApplicationEngine::ResponseStage(env, NULL),
+CgiApplicationEngine::DefaultNotFoundStage::DefaultNotFoundStage(const ScriptNotFound & notfound) :
+ CgiApplicationEngine::ResponseStage(NULL),
nf(notfound),
- pres(new XmlPresenter(DefaultNotFoundStageResp, e->errorTransformStyle, e->errorContentType))
+ pres(new XmlPresenter(DefaultNotFoundStageResp, env()->errorTransformStyle, env()->errorContentType))
{
Logger()->messagef(LOG_ERR, "%s: Resource not found: %s", __FUNCTION__, nf.what());
}
@@ -23,7 +23,7 @@ CgiApplicationEngine::DefaultNotFoundStage::getHeader() const
CgiApplicationEngine::NextStage
CgiApplicationEngine::DefaultNotFoundStage::run()
{
- pres->addNamedValue("missing-resource", e->scriptNamespacePrefix, nf.what());
+ pres->addNamedValue("missing-resource", env()->scriptNamespacePrefix, nf.what());
return NextStage(NULL, this, pres.get(), pres.get());
}
diff --git a/project2/cgi/cgiStageFail.cpp b/project2/cgi/cgiStageFail.cpp
index 64bc15a..019ab8e 100644
--- a/project2/cgi/cgiStageFail.cpp
+++ b/project2/cgi/cgiStageFail.cpp
@@ -8,8 +8,8 @@
namespace CgiApplicationExtras {
class FailStage : public CgiApplicationEngine::ResponseStage {
public:
- FailStage(const CgiEnvironment * env, int c, const std::string & m) :
- ResponseStage(env, NULL),
+ FailStage(int c, const std::string & m) :
+ ResponseStage(NULL),
code(c),
message(m) {
}
@@ -39,7 +39,7 @@ namespace CgiApplicationExtras {
}
void execute(const MultiRowSetPresenter *) const {
throw CgiApplicationEngine::ResponseStagePtr(
- new FailStage(dynamic_cast<const CgiEnvironment *>(Environment::getCurrent()), code(), message()));
+ new FailStage(code(), message()));
}
private:
Variable code, message;
diff --git a/project2/cgi/cgiStageInitial.cpp b/project2/cgi/cgiStageInitial.cpp
index 0fe81d4..5abbbfb 100644
--- a/project2/cgi/cgiStageInitial.cpp
+++ b/project2/cgi/cgiStageInitial.cpp
@@ -5,22 +5,18 @@
StaticMessageException(EmptyRequestURL, "Request URL cannot be empty");
-CgiApplicationEngine::InitialStage::InitialStage(const CgiEnvironment * env) :
- CgiApplicationEngine::Stage(env)
-{
-}
-
CgiApplicationEngine::NextStage
CgiApplicationEngine::InitialStage::run()
{
+ const CgiEnvironment * e = env();
if (e->getRequestMethod() == "POST") {
if (e->elems.empty()) {
throw EmptyRequestURL();
}
- return NextStage(new RequestStage(e, e->resolveScript(e->requestRoot, e->getRedirectURL(), false)));
+ return NextStage(new RequestStage(e->resolveScript(e->requestRoot, e->getRedirectURL(), false)));
}
else {
- return NextStage(new PresentStage(e, e->resolveScript(e->presentRoot, e->elems.empty() ? e->defaultPresent : e->getRedirectURL(), false)));
+ return NextStage(new PresentStage(e->resolveScript(e->presentRoot, e->elems.empty() ? e->defaultPresent : e->getRedirectURL(), false)));
}
}
diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp
index b5e73b5..8ff1013 100644
--- a/project2/cgi/cgiStagePresent.cpp
+++ b/project2/cgi/cgiStagePresent.cpp
@@ -5,8 +5,8 @@
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
-CgiApplicationEngine::PresentStage::PresentStage(const CgiEnvironment * e, ScriptReaderPtr s) :
- CgiApplicationEngine::ResponseStage(e, s->root()),
+CgiApplicationEngine::PresentStage::PresentStage(ScriptReaderPtr s) :
+ CgiApplicationEngine::ResponseStage(s->root()),
CommonObjects(s->root()),
CheckHost(s->root()),
ViewHost(s->root())
@@ -23,7 +23,7 @@ CgiApplicationEngine::PresentStage::run()
PresenterCaches backFill;
BOOST_FOREACH(const PresenterCachePtr & pc, caches) {
if (pc->check()) {
- CacheHitStage * chs = new CacheHitStage(e, root, pc);
+ CacheHitStage * chs = new CacheHitStage(root, pc);
chs->caches = backFill;
return NextStage(NULL, chs, pc, NULL);
}
@@ -47,13 +47,12 @@ MultiRowSetPresenterPtr
CgiApplicationEngine::PresentStage::getPresenter() const
{
if (!presenter) {
- presenter = LoaderBase::getLoader<PresenterLoader, NotSupported>(e->defaultPresenter)->createFrom(root);
+ presenter = LoaderBase::getLoader<PresenterLoader, NotSupported>(env()->defaultPresenter)->createFrom(root);
}
return presenter;
}
-CgiApplicationEngine::ResponseStage::ResponseStage(const CgiEnvironment * e, ScriptNodePtr r) :
- CgiApplicationEngine::Stage(e),
+CgiApplicationEngine::ResponseStage::ResponseStage(ScriptNodePtr r) :
root(r)
{
}
diff --git a/project2/cgi/cgiStageRedirect.cpp b/project2/cgi/cgiStageRedirect.cpp
index 5459e08..4a4cd02 100644
--- a/project2/cgi/cgiStageRedirect.cpp
+++ b/project2/cgi/cgiStageRedirect.cpp
@@ -7,8 +7,8 @@
namespace CgiApplicationExtras {
class RedirectStage : public CgiApplicationEngine::ResponseStage {
public:
- RedirectStage(const CgiEnvironment * env, const std::string & u) :
- ResponseStage(env, NULL),
+ RedirectStage(const std::string & u) :
+ ResponseStage(NULL),
url(u) {
}
@@ -35,8 +35,7 @@ namespace CgiApplicationExtras {
url(e, "url") {
}
void execute(const MultiRowSetPresenter *) const {
- throw CgiApplicationEngine::ResponseStagePtr(
- new RedirectStage(dynamic_cast<const CgiEnvironment *>(Environment::getCurrent()), url()));
+ throw CgiApplicationEngine::ResponseStagePtr(new RedirectStage(url()));
}
private:
Variable url;
diff --git a/project2/cgi/cgiStageRequest.cpp b/project2/cgi/cgiStageRequest.cpp
index 136627f..967365a 100644
--- a/project2/cgi/cgiStageRequest.cpp
+++ b/project2/cgi/cgiStageRequest.cpp
@@ -5,11 +5,11 @@
#include "scriptLoader.h"
#include <boost/foreach.hpp>
-CgiApplicationEngine::RequestStage::RequestStage(const CgiEnvironment * e, ScriptReaderPtr s) :
+CgiApplicationEngine::RequestStage::RequestStage(ScriptReaderPtr s) :
SourceObject(s->root()),
CommonObjects(s->root()),
::CheckHost(s->root()),
- CgiApplicationEngine::ResponseStage(e, s->root()),
+ CgiApplicationEngine::ResponseStage(s->root()),
::TaskHost(s->root()),
present(s->root()->value("present","").as<std::string>())
{
@@ -20,7 +20,7 @@ CgiApplicationEngine::RequestStage::run()
{
runChecks();
execute();
- return NextStage(present.empty() ? NULL : new PresentStage(e, e->resolveScript(e->presentRoot, present, false)), this);
+ return NextStage(present.empty() ? NULL : new PresentStage(env()->resolveScript(env()->presentRoot, present, false)), this);
}
CgiApplicationEngine::HttpHeaderPtr