diff options
author | randomdan <randomdan@localhost> | 2010-07-14 18:04:41 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-07-14 18:04:41 +0000 |
commit | fc820bd352ef82d98f26487011ed79fb0e4dfdaa (patch) | |
tree | 4a5a5889c1025fb92f499b005b2faf8dc9a08222 | |
parent | Don't reference rows before they're put on the stack (diff) | |
download | project2-fc820bd352ef82d98f26487011ed79fb0e4dfdaa.tar.bz2 project2-fc820bd352ef82d98f26487011ed79fb0e4dfdaa.tar.xz project2-fc820bd352ef82d98f26487011ed79fb0e4dfdaa.zip |
Set the content-type header according to the existance of a stylesheet name
-rw-r--r-- | project2/cgiAppEngine.cpp | 13 | ||||
-rw-r--r-- | project2/cgiAppEngine.h | 5 | ||||
-rw-r--r-- | project2/p2webMain.cpp | 8 |
3 files changed, 15 insertions, 11 deletions
diff --git a/project2/cgiAppEngine.cpp b/project2/cgiAppEngine.cpp index e041d20..4f04b7e 100644 --- a/project2/cgiAppEngine.cpp +++ b/project2/cgiAppEngine.cpp @@ -19,10 +19,10 @@ typedef std::string SValue; SessionContainer * sessionsContainer = new SessionContainerShm(); -CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e, cgicc::HTTPContentHeader * h) : +CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e) : ApplicationEngine(e), _env(e), - header(h), + header(NULL), sessionID(boost::uuids::nil_generator()()) { BOOST_FOREACH(const cgicc::HTTPCookie c, e->getCookieList()) { @@ -40,6 +40,7 @@ CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e, cgicc::HTTP CgiApplicationEngine::~CgiApplicationEngine() { + delete header; } const Environment * @@ -121,12 +122,16 @@ CgiApplicationEngine::PresentStage::getDataDocument() const } // XSLT Style char * buf; - if (asprintf(&buf, "type=\"text/xsl\" href=\"%s\"", + if (responseStyle.length() && asprintf(&buf, "type=\"text/xsl\" href=\"%s\"", responseStyle.c_str()) > 0) { xmlAddPrevSibling(responseRoot->cobj(), xmlNewDocPI(responseDoc->cobj(), BAD_CAST "xml-stylesheet", BAD_CAST buf)); + free(buf); + appEngine->header = new cgicc::HTTPContentHeader("text/xml-xslt"); + } + else { + appEngine->header = new cgicc::HTTPContentHeader("text/xml"); } - free(buf); return responseDoc; } diff --git a/project2/cgiAppEngine.h b/project2/cgiAppEngine.h index d2a1f44..a42cedd 100644 --- a/project2/cgiAppEngine.h +++ b/project2/cgiAppEngine.h @@ -18,10 +18,11 @@ namespace cgicc { class CgiApplicationEngine : public ApplicationEngine { public: - CgiApplicationEngine(const CgiEnvironment *, cgicc::HTTPContentHeader *); + CgiApplicationEngine(const CgiEnvironment *); virtual ~CgiApplicationEngine(); void process() const; + const cgicc::HTTPContentHeader * getHeader() const { return header; } template <class Writer> void write(const Writer & w) const { @@ -32,7 +33,7 @@ class CgiApplicationEngine : public ApplicationEngine { PresenterPtr getPresenter(const std::string & group, const std::string & id) const; const CgiEnvironment * _env; protected: - cgicc::HTTPContentHeader * header; + mutable cgicc::HTTPContentHeader * header; private: mutable boost::shared_ptr<xmlpp::Document> doc; class Stage { diff --git a/project2/p2webMain.cpp b/project2/p2webMain.cpp index a526f8d..ef070f0 100644 --- a/project2/p2webMain.cpp +++ b/project2/p2webMain.cpp @@ -30,11 +30,10 @@ int main(void) try { cgicc::Cgicc cgi(&IO); CgiEnvironment env(&cgi); - cgicc::HTTPContentHeader header("text/xml-xslt"); - CgiApplicationEngine app(&env, &header); + CgiApplicationEngine app(&env); app.process(); IO << "Cache-control: no-cache" << std::endl; - header.render(IO); + app.getHeader()->render(IO); xmlOutputBufferPtr out = xmlOutputBufferCreateIO( xmlWrite, NULL, &IO, xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8)); app.write(boost::bind(xmlSaveFileTo, out, _1, "utf-8")); @@ -54,8 +53,7 @@ int main(void) else { cgicc::Cgicc cgi(NULL); CgiEnvironment env(&cgi); - cgicc::HTTPContentHeader header("text/xml-xslt"); - CgiApplicationEngine app(&env, &header); + CgiApplicationEngine app(&env); app.process(); app.write(boost::bind(xmlDocDump, realstdout, _1)); } |