diff options
author | randomdan <randomdan@localhost> | 2012-01-03 23:10:47 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2012-01-03 23:10:47 +0000 |
commit | 6d81a82a76208cc31a74c248921d23348fb8be40 (patch) | |
tree | cb83752e3d01f3432c47c65d4a42c0f1e5b34878 /project2/cgi | |
parent | Regeneralise some code (diff) | |
download | project2-6d81a82a76208cc31a74c248921d23348fb8be40.tar.bz2 project2-6d81a82a76208cc31a74c248921d23348fb8be40.tar.xz project2-6d81a82a76208cc31a74c248921d23348fb8be40.zip |
Allowing specification of output encoding
Diffstat (limited to 'project2/cgi')
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 22 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.h | 3 | ||||
-rw-r--r-- | project2/cgi/cgiEnvironment.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiEnvironment.h | 1 | ||||
-rw-r--r-- | project2/cgi/cgiStageCustomError.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStageCustomNotFound.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStageDefaultError.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStageDefaultNotFound.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStageFail.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStagePresent.cpp | 7 | ||||
-rw-r--r-- | project2/cgi/cgiStageRedirect.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStageRequest.cpp | 2 |
12 files changed, 28 insertions, 21 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 8093ef3..b92095c 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -45,20 +45,22 @@ CgiApplicationEngine::env() const class CgiResult : public TransformChainLink { public: - CgiResult(CgiApplicationEngine::HttpHeaderPtr & h, std::ostream & s) : + CgiResult(CgiApplicationEngine::HttpHeaderPtr & h, std::ostream & s, const std::string & e) : header(h), - stream(s) { + stream(s), + encoding(e) { } CgiApplicationEngine::HttpHeaderPtr header; std::ostream & stream; + const std::string encoding; }; class WriteToCgiResult : public TransformImpl<WritableContent, CgiResult> { public: void transform(const WritableContent * wc, CgiResult * cr) const { - cr->header->addHeader("Content-Type", wc->getContentType()); + cr->header->addHeader("Content-Type", Glib::ustring::compose("%1; charset=%2", wc->getContentType(), cr->encoding)); cr->header->render(cr->stream); - wc->writeTo(cr->stream); + wc->writeTo(cr->stream, cr->encoding); } }; DECLARE_TRANSFORM(WriteToCgiResult); @@ -115,9 +117,9 @@ CgiApplicationEngine::process() const } while (currentStage.get<0>()); endTime = boost::date_time::microsec_clock<boost::posix_time::ptime>::universal_time(); ResponseStagePtr rs = currentStage.get<1>(); - if (currentStage.get<3>()) { - addAppData(currentStage.get<3>().get(), rs->outputOptions); - addEnvData(currentStage.get<3>().get(), rs->outputOptions); + if (const MultiRowSetPresenter * p = currentStage.get<3>().get()) { + addAppData(p, rs->outputOptions); + addEnvData(p, rs->outputOptions); } HttpHeaderPtr header = rs->getHeader(); if (!sessionEmpty || !cursession->Empty()) { @@ -125,9 +127,9 @@ CgiApplicationEngine::process() const header->setCookie(cgicc::HTTPCookie(SESSIONID, cursession->ID.str(), "Session ID", _env->getServerName().substr(_env->getServerName().find(".")), env()->sessionTimeOut, "/", false)); } - if (currentStage.get<2>()) { - TransformSourcePtr ts = currentStage.get<2>(); - addFinalTransformTarget(ts, new CgiResult(header, IO)); + if (TransformSourcePtr ts = currentStage.get<2>()) { + addFinalTransformTarget(ts, new CgiResult(header, IO, + rs && rs->root ? rs->root->value("encoding", _env->outputEncoding) : VariableType(_env->outputEncoding))); std::fstream * ddd = NULL; if (!_env->dumpdatadoc.empty()) { ddd = new std::fstream(_env->dumpdatadoc.c_str(), std::fstream::trunc | std::fstream::out); diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 80dad6e..a7648d1 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -67,10 +67,11 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink /// Base class for a stage that can be a response to the client class ResponseStage : public Stage { public: - ResponseStage(const CgiEnvironment * e); + ResponseStage(const CgiEnvironment * e, ScriptNodePtr root); virtual HttpHeaderPtr getHeader() const = 0; OutputOptionsPtr outputOptions; + ScriptNodePtr root; }; /// Stage implementation used to bootstrap the iteration process based on the CGI environment diff --git a/project2/cgi/cgiEnvironment.cpp b/project2/cgi/cgiEnvironment.cpp index 7b2b254..b1565ad 100644 --- a/project2/cgi/cgiEnvironment.cpp +++ b/project2/cgi/cgiEnvironment.cpp @@ -55,6 +55,8 @@ CgiEnvironment::CgiEnvironment(cgicc::Cgicc * c) : "The module with which to implement session management") ("cgi.hostRegex", hpi, "Regular expression used to define a hostname -> platform association") + ("cgi.outputEncoding", Options::value(&outputEncoding, "utf-8"), + "The encoding to use when outputing to the web server") ; } diff --git a/project2/cgi/cgiEnvironment.h b/project2/cgi/cgiEnvironment.h index 28e47d3..25ea90f 100644 --- a/project2/cgi/cgiEnvironment.h +++ b/project2/cgi/cgiEnvironment.h @@ -53,6 +53,7 @@ class CgiEnvironment : public Environment, public cgicc::CgiEnvironment { std::string onErrorPresent; std::string defaultPresenter; std::string sessionModule; + std::string outputEncoding; }; #endif diff --git a/project2/cgi/cgiStageCustomError.cpp b/project2/cgi/cgiStageCustomError.cpp index eb66ff0..957b572 100644 --- a/project2/cgi/cgiStageCustomError.cpp +++ b/project2/cgi/cgiStageCustomError.cpp @@ -5,7 +5,7 @@ #include "logger.h" CgiApplicationEngine::CustomErrorStage::CustomErrorStage(const CgiEnvironment * env, const std::exception & ex, ScriptReaderPtr s) : - CgiApplicationEngine::ResponseStage(env), + CgiApplicationEngine::ResponseStage(env, s->root()), ::CommonObjects(s->root()), ::CheckHost(s->root()), CgiApplicationEngine::DefaultErrorStage(env, ex), diff --git a/project2/cgi/cgiStageCustomNotFound.cpp b/project2/cgi/cgiStageCustomNotFound.cpp index e6520dd..3ce8012 100644 --- a/project2/cgi/cgiStageCustomNotFound.cpp +++ b/project2/cgi/cgiStageCustomNotFound.cpp @@ -5,7 +5,7 @@ #include "logger.h" CgiApplicationEngine::CustomNotFoundStage::CustomNotFoundStage(const CgiEnvironment * env, const ScriptNotFound & notfound, ScriptReaderPtr s) : - CgiApplicationEngine::ResponseStage(env), + CgiApplicationEngine::ResponseStage(env, s->root()), ::CommonObjects(s->root()), ::CheckHost(s->root()), CgiApplicationEngine::DefaultNotFoundStage(env, notfound), diff --git a/project2/cgi/cgiStageDefaultError.cpp b/project2/cgi/cgiStageDefaultError.cpp index e464981..d2abeef 100644 --- a/project2/cgi/cgiStageDefaultError.cpp +++ b/project2/cgi/cgiStageDefaultError.cpp @@ -8,7 +8,7 @@ static const Glib::ustring DefaultErrorStageResp("error"); CgiApplicationEngine::DefaultErrorStage::DefaultErrorStage(const CgiEnvironment * env, const std::exception & ex) : - CgiApplicationEngine::ResponseStage(env), + CgiApplicationEngine::ResponseStage(env, NULL), buf(__cxxabiv1::__cxa_demangle(typeid(ex).name(), NULL, NULL, NULL)), what(ex.what()), pres(new XmlPresenter(DefaultErrorStageResp, e->errorTransformStyle, e->errorContentType)) diff --git a/project2/cgi/cgiStageDefaultNotFound.cpp b/project2/cgi/cgiStageDefaultNotFound.cpp index 2cf0475..b971dc3 100644 --- a/project2/cgi/cgiStageDefaultNotFound.cpp +++ b/project2/cgi/cgiStageDefaultNotFound.cpp @@ -7,7 +7,7 @@ static const Glib::ustring DefaultNotFoundStageResp("notfound"); CgiApplicationEngine::DefaultNotFoundStage::DefaultNotFoundStage(const CgiEnvironment * env, const ScriptNotFound & notfound) : - CgiApplicationEngine::ResponseStage(env), + CgiApplicationEngine::ResponseStage(env, NULL), nf(notfound), pres(new XmlPresenter(DefaultNotFoundStageResp, e->errorTransformStyle, e->errorContentType)) { diff --git a/project2/cgi/cgiStageFail.cpp b/project2/cgi/cgiStageFail.cpp index 62de295..64bc15a 100644 --- a/project2/cgi/cgiStageFail.cpp +++ b/project2/cgi/cgiStageFail.cpp @@ -9,7 +9,7 @@ namespace CgiApplicationExtras { class FailStage : public CgiApplicationEngine::ResponseStage { public: FailStage(const CgiEnvironment * env, int c, const std::string & m) : - ResponseStage(env), + ResponseStage(env, NULL), code(c), message(m) { } diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp index 1330cdc..2ca6147 100644 --- a/project2/cgi/cgiStagePresent.cpp +++ b/project2/cgi/cgiStagePresent.cpp @@ -6,7 +6,7 @@ #include <boost/bind.hpp> CgiApplicationEngine::PresentStage::PresentStage(const CgiEnvironment * e, ScriptReaderPtr s) : - CgiApplicationEngine::ResponseStage(e), + CgiApplicationEngine::ResponseStage(e, s->root()), CommonObjects(s->root()), CheckHost(s->root()), ViewHost(s->root()), @@ -41,8 +41,9 @@ CgiApplicationEngine::PresentStage::getPresenter() const return presenter; } -CgiApplicationEngine::ResponseStage::ResponseStage(const CgiEnvironment * e) : - CgiApplicationEngine::Stage(e) +CgiApplicationEngine::ResponseStage::ResponseStage(const CgiEnvironment * e, ScriptNodePtr r) : + CgiApplicationEngine::Stage(e), + root(r) { } diff --git a/project2/cgi/cgiStageRedirect.cpp b/project2/cgi/cgiStageRedirect.cpp index 8c918f1..5459e08 100644 --- a/project2/cgi/cgiStageRedirect.cpp +++ b/project2/cgi/cgiStageRedirect.cpp @@ -8,7 +8,7 @@ namespace CgiApplicationExtras { class RedirectStage : public CgiApplicationEngine::ResponseStage { public: RedirectStage(const CgiEnvironment * env, const std::string & u) : - ResponseStage(env), + ResponseStage(env, NULL), url(u) { } diff --git a/project2/cgi/cgiStageRequest.cpp b/project2/cgi/cgiStageRequest.cpp index d505f3c..136627f 100644 --- a/project2/cgi/cgiStageRequest.cpp +++ b/project2/cgi/cgiStageRequest.cpp @@ -9,7 +9,7 @@ CgiApplicationEngine::RequestStage::RequestStage(const CgiEnvironment * e, Scrip SourceObject(s->root()), CommonObjects(s->root()), ::CheckHost(s->root()), - CgiApplicationEngine::ResponseStage(e), + CgiApplicationEngine::ResponseStage(e, s->root()), ::TaskHost(s->root()), present(s->root()->value("present","").as<std::string>()) { |