diff options
author | randomdan <randomdan@localhost> | 2011-09-02 15:17:00 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-09-02 15:17:00 +0000 |
commit | 3ac624988d3198e4bb3d039db46072d9689d3a57 (patch) | |
tree | f0d633245ae54d013a9efbc39d775ffe27d94633 | |
parent | Allow low preference caches to refill higher ones (diff) | |
download | project2-3ac624988d3198e4bb3d039db46072d9689d3a57.tar.bz2 project2-3ac624988d3198e4bb3d039db46072d9689d3a57.tar.xz project2-3ac624988d3198e4bb3d039db46072d9689d3a57.zip |
Minor shuffle
Add referer support in cURL things
Add support for redirects in cgi views
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 9 | ||||
-rw-r--r-- | project2/cgi/cgiHttpHeader.cpp | 6 | ||||
-rw-r--r-- | project2/cgi/cgiHttpHeader.h | 1 | ||||
-rw-r--r-- | project2/cgi/cgiStagePresent.cpp | 12 | ||||
-rw-r--r-- | project2/cgi/cgiStageRedirect.cpp | 49 | ||||
-rw-r--r-- | project2/url/curlHelper.cpp | 2 | ||||
-rw-r--r-- | project2/url/curlHelper.h | 1 | ||||
-rw-r--r-- | project2/xml/Jamfile.jam | 2 | ||||
-rw-r--r-- | project2/xml/transformXml.cpp | 14 |
9 files changed, 84 insertions, 12 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 4978c0c..2c4feb0 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -41,15 +41,6 @@ CgiApplicationEngine::env() const return _env; } -class TransformXmlToHttpStream : public TransformImpl<xmlpp::Document, ostreamWrapper> { - public: - void transform(const xmlpp::Document * doc, ostreamWrapper * o) const - { - const_cast<xmlpp::Document *>(doc)->write_to_stream_formatted(o->strm, "UTF-8"); - } -}; -DECLARE_TRANSFORM(TransformXmlToHttpStream); - void CgiApplicationEngine::process() const { diff --git a/project2/cgi/cgiHttpHeader.cpp b/project2/cgi/cgiHttpHeader.cpp index e82a882..20b20ea 100644 --- a/project2/cgi/cgiHttpHeader.cpp +++ b/project2/cgi/cgiHttpHeader.cpp @@ -2,6 +2,12 @@ #include "cgiHttpHeader.h" #include <boost/foreach.hpp> +Project2HttpHeader::Project2HttpHeader(const std::string & s) : + cgicc::HTTPHeader("") +{ + addHeader("Status", s); +} + Project2HttpHeader::Project2HttpHeader(const std::string & s, const std::string & t) : cgicc::HTTPHeader("") { diff --git a/project2/cgi/cgiHttpHeader.h b/project2/cgi/cgiHttpHeader.h index f84c707..87edde5 100644 --- a/project2/cgi/cgiHttpHeader.h +++ b/project2/cgi/cgiHttpHeader.h @@ -9,6 +9,7 @@ class Project2HttpHeader : public cgicc::HTTPHeader { public: typedef std::map<std::string, const Glib::ustring> Headers; + Project2HttpHeader(const std::string & s); Project2HttpHeader(const std::string & s, const std::string & t); void addHeader(const std::string & name, const Glib::ustring & value); void render(std::ostream & out) const; diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp index fffcaa7..df05465 100644 --- a/project2/cgi/cgiStagePresent.cpp +++ b/project2/cgi/cgiStagePresent.cpp @@ -17,8 +17,16 @@ CgiApplicationEngine::NextStage CgiApplicationEngine::PresentStage::run() { runChecks(); - executeViews(boost::bind(&PresenterLoader::createFrom, LoaderBase::getLoader<PresenterLoader, NotSupported>(e->defaultPresenter), _1)); - return NextStage(NULL, this, boost::dynamic_pointer_cast<TransformSource>(headPresenter()), headPresenter()); + try { + executeViews(boost::bind(&PresenterLoader::createFrom, LoaderBase::getLoader<PresenterLoader, NotSupported>(e->defaultPresenter), _1)); + return NextStage(NULL, this, boost::dynamic_pointer_cast<TransformSource>(headPresenter()), headPresenter()); + } + catch (ResponseStagePtr p) { + return NextStage(NULL, p, boost::dynamic_pointer_cast<TransformSource>(p), boost::dynamic_pointer_cast<Presenter>(p)); + } + catch (StagePtr p) { + return NextStage(p, NULL, boost::dynamic_pointer_cast<TransformSource>(p), boost::dynamic_pointer_cast<Presenter>(p)); + } } CgiApplicationEngine::ResponseStage::ResponseStage(const CgiEnvironment * e) : diff --git a/project2/cgi/cgiStageRedirect.cpp b/project2/cgi/cgiStageRedirect.cpp new file mode 100644 index 0000000..af938c0 --- /dev/null +++ b/project2/cgi/cgiStageRedirect.cpp @@ -0,0 +1,49 @@ +#include <pch.hpp> +#include "cgiAppEngine.h" +#include "cgiEnvironment.h" +#include "cgiHttpHeader.h" +#include "logger.h" + +namespace CgiApplicationExtras { + class RedirectStage : public CgiApplicationEngine::ResponseStage { + public: + RedirectStage(const CgiEnvironment * env, const std::string & u) : + ResponseStage(env), + url(u) { + } + + CgiApplicationEngine::HttpHeaderPtr getHeader() const + { + Project2HttpHeader * header = new Project2HttpHeader("301 Moved Permanently"); + header->addHeader("Location", url); + return CgiApplicationEngine::HttpHeaderPtr(header); + } + + CgiApplicationEngine::NextStage run() + { + return CgiApplicationEngine::NextStage(NULL, this, NULL, NULL); + } + private: + const std::string url; + }; + + class CgiRedirect : public View { + public: + CgiRedirect(const xmlpp::Element * e) : + SourceObject(e), + View(e), + url(e, "url", true) { + } + void loadComplete(const CommonObjects *) { + } + void execute(const Presenter *) const { + throw CgiApplicationEngine::ResponseStagePtr( + new RedirectStage(dynamic_cast<const CgiEnvironment *>(Environment::getCurrent()), url())); + } + private: + Variable url; + }; +} + +typedef CgiApplicationExtras::CgiRedirect cgird; +DECLARE_LOADER("cgiredirect", cgird); diff --git a/project2/url/curlHelper.cpp b/project2/url/curlHelper.cpp index 7c204aa..bec779e 100644 --- a/project2/url/curlHelper.cpp +++ b/project2/url/curlHelper.cpp @@ -5,6 +5,7 @@ CurlHelper::CurlHelper(const xmlpp::Element * p) : userAgent(p, "useragent", false, "project2/0.3"), cookieJar(p, "cookiejar", false), proxy(p, "proxy", false), + referer(p, "referer", false), method(p, "method", false), userName(p, "username", false), password(p, "password", false), @@ -25,6 +26,7 @@ CurlHelper::newCurl() const setopt_s(c, CURLOPT_URL, url()); setopt_s(c, CURLOPT_USERAGENT, userAgent()); setopt_s(c, CURLOPT_PROXY, proxy()); + setopt_s(c, CURLOPT_REFERER, referer()); setopt_s(c, CURLOPT_COOKIEFILE, cookieJar()); setopt_s(c, CURLOPT_COOKIEJAR, cookieJar()); setopt_l(c, CURLOPT_TIMEOUT_MS, timeout()); diff --git a/project2/url/curlHelper.h b/project2/url/curlHelper.h index afebcdc..111823f 100644 --- a/project2/url/curlHelper.h +++ b/project2/url/curlHelper.h @@ -23,6 +23,7 @@ class CurlHelper { const Variable userAgent; const Variable cookieJar; const Variable proxy; + const Variable referer; const Variable method; const Variable userName; const Variable password; diff --git a/project2/xml/Jamfile.jam b/project2/xml/Jamfile.jam index b6e29ef..be45dc6 100644 --- a/project2/xml/Jamfile.jam +++ b/project2/xml/Jamfile.jam @@ -13,7 +13,7 @@ cpp-pch pch : pch.hpp : ; lib p2xml : pch - rawView.cpp xmlPresenter.cpp transformHtml.cpp transformText.cpp xmlRows.cpp + rawView.cpp xmlPresenter.cpp transformXml.cpp transformHtml.cpp transformText.cpp xmlRows.cpp xmlRawRows.cpp xslRows.cpp xslRowsCache.cpp xslPreFetch.cpp xmlMemCache.cpp xmlCache.cpp sessionXml.cpp : <include>../libmisc diff --git a/project2/xml/transformXml.cpp b/project2/xml/transformXml.cpp new file mode 100644 index 0000000..d1e58b5 --- /dev/null +++ b/project2/xml/transformXml.cpp @@ -0,0 +1,14 @@ +#include <pch.hpp> +#include "transform.h" +#include <libxml++/document.h> +#include "ostreamWrapper.h" + +class TransformXmlToHttpStream : public TransformImpl<xmlpp::Document, ostreamWrapper> { + public: + void transform(const xmlpp::Document * doc, ostreamWrapper * o) const + { + const_cast<xmlpp::Document *>(doc)->write_to_stream_formatted(o->strm, "UTF-8"); + } +}; +DECLARE_TRANSFORM(TransformXmlToHttpStream); + |