diff options
author | randomdan <randomdan@localhost> | 2011-12-14 21:42:31 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-12-14 21:42:31 +0000 |
commit | 8a7980bff41ccb8dc42b18eb1edd4b3938977fc3 (patch) | |
tree | 4b0a3414ba881a3118630c41ca24129d23f996df /project2/cgi | |
parent | Don't write JSON numbers in scientific notation, use native C++ boolalpha for... (diff) | |
download | project2-8a7980bff41ccb8dc42b18eb1edd4b3938977fc3.tar.bz2 project2-8a7980bff41ccb8dc42b18eb1edd4b3938977fc3.tar.xz project2-8a7980bff41ccb8dc42b18eb1edd4b3938977fc3.zip |
Pluggable script engines
XML script parser moved to XML module
Script parsing object multiple instantiation bug fix
Scripts changed to match new standardized format and layout
Diffstat (limited to 'project2/cgi')
-rw-r--r-- | project2/cgi/Jamfile.jam | 11 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 8 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.h | 12 | ||||
-rw-r--r-- | project2/cgi/cgiOutputOptions.cpp | 17 | ||||
-rw-r--r-- | project2/cgi/cgiOutputOptions.h | 4 | ||||
-rw-r--r-- | project2/cgi/cgiStageCustomError.cpp | 8 | ||||
-rw-r--r-- | project2/cgi/cgiStageCustomNotFound.cpp | 8 | ||||
-rw-r--r-- | project2/cgi/cgiStageDefaultNotFound.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStageFail.cpp | 6 | ||||
-rw-r--r-- | project2/cgi/cgiStageInitial.cpp | 6 | ||||
-rw-r--r-- | project2/cgi/cgiStagePresent.cpp | 10 | ||||
-rw-r--r-- | project2/cgi/cgiStageRedirect.cpp | 4 | ||||
-rw-r--r-- | project2/cgi/cgiStageRequest.cpp | 14 |
13 files changed, 55 insertions, 55 deletions
diff --git a/project2/cgi/Jamfile.jam b/project2/cgi/Jamfile.jam index 48225cb..017dd11 100644 --- a/project2/cgi/Jamfile.jam +++ b/project2/cgi/Jamfile.jam @@ -1,6 +1,7 @@ -alias libxmlpp : : : : - <cflags>"`pkg-config --cflags libxml++-2.6`" - <linkflags>"`pkg-config --libs libxml++-2.6`" ; +alias glibmm : : : : + <cflags>"`pkg-config --cflags glibmm-2.4`" + <linkflags>"`pkg-config --libs glibmm-2.4`" + ; lib boost_filesystem : : <name>boost_filesystem ; lib cgicc : : <name>cgicc ; lib fcgi : : <name>fcgi ; @@ -9,7 +10,7 @@ lib fcgi++ : : <name>fcgi++ ; cpp-pch pch : pch.hpp : <include>../../libmisc <library>cgicc - <library>libxmlpp + <library>glibmm <library>../common//p2common <library>boost_filesystem <library>../xml//p2xml @@ -20,7 +21,7 @@ lib p2web : : <include>../libmisc <library>cgicc - <library>libxmlpp + <library>glibmm <library>../common//p2common <library>boost_filesystem <library>../xml//p2xml diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 7fd7c33..4d91069 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -56,15 +56,15 @@ 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()))); + currentStage = NextStage(new PresentStage(_env, _env->resolveScript(_env->presentRoot, cf.failedCheck->present(), false))); } - catch (const XmlScriptParser::NotFound & nf) { + catch (const ScriptNotFound & nf) { if (_env->notFoundPresent.empty() || triedNotFound) { currentStage = NextStage(new DefaultNotFoundStage(_env, nf)); } else { triedNotFound = true; - currentStage = NextStage(new CustomNotFoundStage(_env, nf)); + currentStage = NextStage(new CustomNotFoundStage(_env, nf, _env->resolveScript(_env->errorPresentRoot, _env->notFoundPresent, false))); } } catch (const std::exception & ex) { @@ -73,7 +73,7 @@ CgiApplicationEngine::process() const } else { triedNotFound = true; - currentStage = NextStage(new CustomErrorStage(_env, ex)); + currentStage = NextStage(new CustomErrorStage(_env, ex, _env->resolveScript(_env->errorPresentRoot, _env->onErrorPresent, false))); } } } while (currentStage.get<0>()); diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 25d3b93..f4b3896 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -88,7 +88,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink /// Stage to process POST requests class RequestStage : public ResponseStage, TaskHost { public: - RequestStage(const CgiEnvironment *, const boost::filesystem::path & path); + RequestStage(const CgiEnvironment *, ScriptReaderPtr); virtual NextStage run(); virtual HttpHeaderPtr getHeader() const; @@ -99,7 +99,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, const boost::filesystem::path & path); + PresentStage(const CgiEnvironment * e, ScriptReaderPtr); virtual NextStage run(); virtual HttpHeaderPtr getHeader() const; @@ -108,19 +108,19 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink /// The built-in fail-safe not found stage class DefaultNotFoundStage : public virtual ResponseStage { public: - DefaultNotFoundStage(const CgiEnvironment *, const XmlScriptParser::NotFound &); + DefaultNotFoundStage(const CgiEnvironment *, const ScriptNotFound &); virtual NextStage run(); virtual HttpHeaderPtr getHeader() const; private: - const XmlScriptParser::NotFound nf; + const ScriptNotFound nf; XmlPresenterPtr pres; }; /// Custom not found handling stage class CustomNotFoundStage : public DefaultNotFoundStage, public PresentStage { public: - CustomNotFoundStage(const CgiEnvironment *, const ::XmlScriptParser::NotFound &); + CustomNotFoundStage(const CgiEnvironment *, const ScriptNotFound &, ScriptReaderPtr); virtual NextStage run(); virtual HttpHeaderPtr getHeader() const; }; @@ -142,7 +142,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 &); + CustomErrorStage(const CgiEnvironment *, const std::exception &, ScriptReaderPtr); virtual NextStage run(); virtual HttpHeaderPtr getHeader() const; }; diff --git a/project2/cgi/cgiOutputOptions.cpp b/project2/cgi/cgiOutputOptions.cpp index add1671..f9a6d86 100644 --- a/project2/cgi/cgiOutputOptions.cpp +++ b/project2/cgi/cgiOutputOptions.cpp @@ -1,4 +1,5 @@ #include "cgiOutputOptions.h" +#include "scripts.h" bool OutputOptions::core; bool OutputOptions::session; @@ -7,13 +8,13 @@ bool OutputOptions::environment; bool OutputOptions::url; bool OutputOptions::parameters; -OutputOptions::OutputOptions(const xmlpp::Element * p) : - Core(p, "core", false, core), - Session(p, "session", false, session), - Timing(p, "timing", false, timing), - Environment(p, "environment", false, environment), - URL(p, "url", false, url), - Parameters(p, "parameters", false, parameters) +OutputOptions::OutputOptions(ScriptNodePtr p) : + Core(p, "core", core), + Session(p, "session", session), + Timing(p, "timing", timing), + Environment(p, "environment", environment), + URL(p, "url", url), + Parameters(p, "parameters", parameters) { } @@ -31,7 +32,7 @@ OutputOptionsLoader::OutputOptionsLoader() : } OutputOptionsPtr -OutputOptionsLoader::createFrom(const xmlpp::Element * e) const { +OutputOptionsLoader::createFrom(ScriptNodePtr e) const { return new OutputOptions(e); } diff --git a/project2/cgi/cgiOutputOptions.h b/project2/cgi/cgiOutputOptions.h index a1ff62d..07b7598 100644 --- a/project2/cgi/cgiOutputOptions.h +++ b/project2/cgi/cgiOutputOptions.h @@ -11,7 +11,7 @@ namespace xmlpp { class OutputOptions : public IntrusivePtrBase { public: - OutputOptions(const xmlpp::Element *); + OutputOptions(ScriptNodePtr); const Variable Core; const Variable Session; @@ -35,7 +35,7 @@ typedef boost::intrusive_ptr<OutputOptions> OutputOptionsPtr; class OutputOptionsLoader : public ComponentLoader { public: OutputOptionsLoader(); - OutputOptionsPtr createFrom(const xmlpp::Element * e) const; + OutputOptionsPtr createFrom(ScriptNodePtr e) const; const Options * options() const; private: diff --git a/project2/cgi/cgiStageCustomError.cpp b/project2/cgi/cgiStageCustomError.cpp index 8b4b347..82fc6a1 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) : +CgiApplicationEngine::CustomErrorStage::CustomErrorStage(const CgiEnvironment * env, const std::exception & ex, ScriptReaderPtr s) : CgiApplicationEngine::ResponseStage(env), - ::XmlScriptParser(e->resolveScript(env->errorPresentRoot, env->onErrorPresent), false), - ::CheckHost(e->resolveScript(env->errorPresentRoot, env->onErrorPresent)), + ::CommonObjects(s), + ::CheckHost(s), CgiApplicationEngine::DefaultErrorStage(env, ex), - CgiApplicationEngine::PresentStage(env, e->resolveScript(env->errorPresentRoot, env->onErrorPresent)) + CgiApplicationEngine::PresentStage(env, s) { } diff --git a/project2/cgi/cgiStageCustomNotFound.cpp b/project2/cgi/cgiStageCustomNotFound.cpp index fc49804..8a224fa 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 ::XmlScriptParser::NotFound & notfound) : +CgiApplicationEngine::CustomNotFoundStage::CustomNotFoundStage(const CgiEnvironment * env, const ScriptNotFound & notfound, ScriptReaderPtr s) : CgiApplicationEngine::ResponseStage(env), - ::XmlScriptParser(e->resolveScript(env->errorPresentRoot, env->notFoundPresent), false), - ::CheckHost(e->resolveScript(env->errorPresentRoot, env->notFoundPresent)), + ::CommonObjects(s), + ::CheckHost(s), CgiApplicationEngine::DefaultNotFoundStage(env, notfound), - CgiApplicationEngine::PresentStage(env, e->resolveScript(env->errorPresentRoot, env->notFoundPresent)) + CgiApplicationEngine::PresentStage(env, s) { } diff --git a/project2/cgi/cgiStageDefaultNotFound.cpp b/project2/cgi/cgiStageDefaultNotFound.cpp index 38cc395..d05c92b 100644 --- a/project2/cgi/cgiStageDefaultNotFound.cpp +++ b/project2/cgi/cgiStageDefaultNotFound.cpp @@ -6,7 +6,7 @@ static const Glib::ustring DefaultNotFoundStageResp("notfound"); -CgiApplicationEngine::DefaultNotFoundStage::DefaultNotFoundStage(const CgiEnvironment * env, const XmlScriptParser::NotFound & notfound) : +CgiApplicationEngine::DefaultNotFoundStage::DefaultNotFoundStage(const CgiEnvironment * env, const ScriptNotFound & notfound) : CgiApplicationEngine::ResponseStage(env), nf(notfound), pres(new XmlPresenter(DefaultNotFoundStageResp, e->errorTransformStyle, e->errorContentType)) diff --git a/project2/cgi/cgiStageFail.cpp b/project2/cgi/cgiStageFail.cpp index 87aba66..62de295 100644 --- a/project2/cgi/cgiStageFail.cpp +++ b/project2/cgi/cgiStageFail.cpp @@ -31,11 +31,11 @@ namespace CgiApplicationExtras { class CgiFail : public View { public: - CgiFail(const xmlpp::Element * e) : + CgiFail(ScriptNodePtr e) : SourceObject(e), View(e), - code(e, "code", false, 500), - message(e, "message", false, "Application error") { + code(e, "code", 500), + message(e, "message", "Application error") { } void execute(const MultiRowSetPresenter *) const { throw CgiApplicationEngine::ResponseStagePtr( diff --git a/project2/cgi/cgiStageInitial.cpp b/project2/cgi/cgiStageInitial.cpp index b263110..0fe81d4 100644 --- a/project2/cgi/cgiStageInitial.cpp +++ b/project2/cgi/cgiStageInitial.cpp @@ -17,12 +17,10 @@ CgiApplicationEngine::InitialStage::run() if (e->elems.empty()) { throw EmptyRequestURL(); } - return NextStage(new RequestStage(e, e->resolveScript(e->requestRoot, - e->getRedirectURL()))); + return NextStage(new RequestStage(e, e->resolveScript(e->requestRoot, e->getRedirectURL(), false))); } else { - return NextStage(new PresentStage(e, e->resolveScript(e->presentRoot, - e->elems.empty() ? e->defaultPresent : e->getRedirectURL()))); + return NextStage(new PresentStage(e, 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 54b0e02..8eb0487 100644 --- a/project2/cgi/cgiStagePresent.cpp +++ b/project2/cgi/cgiStagePresent.cpp @@ -5,13 +5,13 @@ #include <boost/foreach.hpp> #include <boost/bind.hpp> -CgiApplicationEngine::PresentStage::PresentStage(const CgiEnvironment * e, const boost::filesystem::path & path) : +CgiApplicationEngine::PresentStage::PresentStage(const CgiEnvironment * e, ScriptReaderPtr s) : CgiApplicationEngine::ResponseStage(e), - XmlScriptParser(path, false), - CheckHost(path), - ViewHost(path) + CommonObjects(s), + CheckHost(s), + ViewHost(s) { - loader.supportedStorers.insert(Storer::into<OutputOptionsLoader>(&outputOptions)); + s->loader.addLoadTarget(s->root(), Storer::into<OutputOptionsLoader>(&outputOptions)); } CgiApplicationEngine::NextStage diff --git a/project2/cgi/cgiStageRedirect.cpp b/project2/cgi/cgiStageRedirect.cpp index f72e986..8c918f1 100644 --- a/project2/cgi/cgiStageRedirect.cpp +++ b/project2/cgi/cgiStageRedirect.cpp @@ -29,10 +29,10 @@ namespace CgiApplicationExtras { class CgiRedirect : public View { public: - CgiRedirect(const xmlpp::Element * e) : + CgiRedirect(ScriptNodePtr e) : SourceObject(e), View(e), - url(e, "url", true) { + url(e, "url") { } void execute(const MultiRowSetPresenter *) const { throw CgiApplicationEngine::ResponseStagePtr( diff --git a/project2/cgi/cgiStageRequest.cpp b/project2/cgi/cgiStageRequest.cpp index 4831a71..99ca956 100644 --- a/project2/cgi/cgiStageRequest.cpp +++ b/project2/cgi/cgiStageRequest.cpp @@ -5,13 +5,13 @@ #include "xmlObjectLoader.h" #include <boost/foreach.hpp> -CgiApplicationEngine::RequestStage::RequestStage(const CgiEnvironment * e, const boost::filesystem::path & path) : - XmlScriptParser(path, false), - SourceObject(get_document()->get_root_node()), - ::CheckHost(path), +CgiApplicationEngine::RequestStage::RequestStage(const CgiEnvironment * e, ScriptReaderPtr s) : + SourceObject(s->root()), + CommonObjects(s), + ::CheckHost(s), CgiApplicationEngine::ResponseStage(e), - ::TaskHost(path), - present(get_document()->get_root_node()->get_attribute_value("present")) + ::TaskHost(s), + 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)), this); + return NextStage(present.empty() ? NULL : new PresentStage(e, e->resolveScript(e->presentRoot, present, false)), this); } const std::string contentType = "text/plain"; |