summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-07-10 11:56:10 +0000
committerrandomdan <randomdan@localhost>2013-07-10 11:56:10 +0000
commita1ac4ac2533fc1273128c054fbf6a0099c82da93 (patch)
treef886f1d4a88c4beabb3bd9dc5eaf4820b8cd6437
parentBoost 1.53 compat fix (diff)
downloadproject2-a1ac4ac2533fc1273128c054fbf6a0099c82da93.tar.bz2
project2-a1ac4ac2533fc1273128c054fbf6a0099c82da93.tar.xz
project2-a1ac4ac2533fc1273128c054fbf6a0099c82da93.zip
Tidy up around hostname platform lookups
-rw-r--r--project2/cgi/cgiAppEngine.cpp39
-rw-r--r--project2/cgi/cgiAppEngine.h5
-rw-r--r--project2/cgi/cgiRequestContext.cpp39
-rw-r--r--project2/cgi/cgiRequestContext.h14
-rw-r--r--project2/cgi/p2webCgi.cpp2
-rw-r--r--project2/cgi/p2webFCgi.cpp2
-rw-r--r--project2/cgi/testCgi.cpp2
7 files changed, 44 insertions, 59 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp
index 2a82595..8adfb35 100644
--- a/project2/cgi/cgiAppEngine.cpp
+++ b/project2/cgi/cgiAppEngine.cpp
@@ -16,6 +16,7 @@
#include <boost/lexical_cast.hpp>
#include <glibmm/exception.h>
#include <cxxabi.h>
+#include <glibmm/regex.h>
typedef boost::uuids::uuid SIDKey;
typedef std::string SValue;
@@ -37,7 +38,29 @@ std::string CgiApplicationEngine::defaultPresenter;
SessionContainerPtr CgiApplicationEngine::sessionsContainer;
std::string CgiApplicationEngine::sessionCookie;
boost::shared_ptr<RouterLoader> CgiApplicationEngine::router;
-boost::intrusive_ptr<HostnamePlatformIdentifier> CgiApplicationEngine::hpi;
+CgiApplicationEngine::PlatformHostnameList CgiApplicationEngine::platHosts;
+
+class PlatformHostnameTarget : public Options::Target {
+ public:
+ void
+ reset() const
+ {
+ CgiApplicationEngine::platHosts.clear();
+ }
+
+ bool
+ paramRequired() const
+ {
+ return true;
+ }
+
+ void
+ consume(const Glib::ustring & p, const VariableType & m, const Options::CurrentPlatform &) const
+ {
+ CgiApplicationEngine::platHosts.push_back(
+ CgiApplicationEngine::PlatformHostname(p, Glib::Regex::create(m, Glib::REGEX_CASELESS | Glib::REGEX_DOTALL)));
+ }
+};
DECLARE_OPTIONS(CgiApplicationEngine, "Project2 CGI options")
("cgi.defaultPresenter", Options::value(&defaultPresenter, "xml"),
@@ -68,7 +91,7 @@ DECLARE_OPTIONS(CgiApplicationEngine, "Project2 CGI options")
"The module with which to implement session management")
("cgi.sessionCookie", Options::value(&sessionCookie, "sessionID"),
"The name of the cookie for storing session IDs")
-("cgi.hostRegex", (hpi = new HostnamePlatformIdentifier()),
+("cgi.hostRegex", new PlatformHostnameTarget(),
"Regular expression used to define a hostname -> platform association")
("cgi.router", Options::function([](const VariableType & r) { router = RouterLoader::getFor(r); }, "simple"),
"Implemenation of router model to map request paths to scripts")
@@ -309,3 +332,15 @@ CgiApplicationEngine::process(std::ostream & IO, CgiRequestContext * crc) const
}
}
+const Glib::ustring &
+CgiApplicationEngine::derivedPlatform(CgiRequestContext * crc)
+{
+ auto pi = std::find_if(platHosts.begin(), platHosts.end(), [crc](const PlatformHostname & r) -> bool {
+ return r.second->match(crc->getServerName());
+ });
+ if (pi == platHosts.end()) {
+ throw NoSuchPlatform(crc->getServerName());
+ }
+ return pi->first;
+}
+
diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h
index 6d3cd0c..476378a 100644
--- a/project2/cgi/cgiAppEngine.h
+++ b/project2/cgi/cgiAppEngine.h
@@ -26,11 +26,14 @@ namespace cgicc {
class CgiApplicationEngine {
public:
typedef boost::shared_ptr<Project2HttpHeader> HttpHeaderPtr;
+ typedef std::pair<Glib::ustring, Glib::RefPtr<Glib::Regex>> PlatformHostname;
+ typedef std::vector<PlatformHostname> PlatformHostnameList;
CgiApplicationEngine();
virtual ~CgiApplicationEngine();
void process(std::ostream & IO, CgiRequestContext *) const;
+ static const Glib::ustring & derivedPlatform(CgiRequestContext *);
private:
void processRun(std::ostream & IO, CgiRequestContext *) const;
@@ -156,7 +159,7 @@ class CgiApplicationEngine {
};
INITOPTIONS;
- static boost::intrusive_ptr<HostnamePlatformIdentifier> hpi;
+ static PlatformHostnameList platHosts;
static boost::shared_ptr<RouterLoader> router;
static SessionContainerPtr sessionsContainer;
static std::string sessionCookie;
diff --git a/project2/cgi/cgiRequestContext.cpp b/project2/cgi/cgiRequestContext.cpp
index 5a93243..d38a256 100644
--- a/project2/cgi/cgiRequestContext.cpp
+++ b/project2/cgi/cgiRequestContext.cpp
@@ -7,7 +7,6 @@
#include "exceptions.h"
#include <map>
#include <cgicc/Cgicc.h>
-#include <glibmm/regex.h>
#include <curl/curl.h>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid_generators.hpp>
@@ -121,41 +120,3 @@ CgiRequestContext::getParameter(const VariableType & p) const
return cgi(p);
}
-HostnamePlatformIdentifier::HostnamePlatformIdentifier()
-{
-}
-
-HostnamePlatformIdentifier::~HostnamePlatformIdentifier()
-{
-}
-
-const Glib::ustring &
-HostnamePlatformIdentifier::derivedPlatform(CgiRequestContext * crc) const
-{
- auto pi = std::find_if(platHosts.begin(), platHosts.end(), [crc](const PlatformHostname & r) -> bool {
- return r.second->match(crc->getServerName());
- });
- if (pi == platHosts.end()) {
- throw NoSuchPlatform(crc->getServerName());
- }
- return pi->first;
-}
-
-void
-HostnamePlatformIdentifier::reset() const
-{
- platHosts.clear();
-}
-
-bool
-HostnamePlatformIdentifier::paramRequired() const
-{
- return true;
-}
-
-void
-HostnamePlatformIdentifier::consume(const Glib::ustring & p, const VariableType & r, const Options::CurrentPlatform &) const
-{
- platHosts.push_back(PlatformHostname(p, Glib::Regex::create(r, Glib::REGEX_CASELESS | Glib::REGEX_DOTALL)));
-}
-
diff --git a/project2/cgi/cgiRequestContext.h b/project2/cgi/cgiRequestContext.h
index 1dbc613..57c233d 100644
--- a/project2/cgi/cgiRequestContext.h
+++ b/project2/cgi/cgiRequestContext.h
@@ -18,20 +18,6 @@ namespace Glib {
class Regex;
}
-class HostnamePlatformIdentifier : public Options::Target {
- public:
- HostnamePlatformIdentifier();
- virtual ~HostnamePlatformIdentifier();
- void reset() const;
- bool paramRequired() const;
- void consume(const Glib::ustring &, const VariableType &, const Options::CurrentPlatform &) const;
- const Glib::ustring & derivedPlatform(CgiRequestContext *) const;
- private:
- typedef std::pair<Glib::ustring, Glib::RefPtr<Glib::Regex>> PlatformHostname;
- typedef std::vector<PlatformHostname> PlatformHostnameList;
- mutable PlatformHostnameList platHosts;
-};
-
class CgiRequestContext : public ExecContext {
public:
typedef std::string ETag;
diff --git a/project2/cgi/p2webCgi.cpp b/project2/cgi/p2webCgi.cpp
index 4f806b2..a8b47e8 100644
--- a/project2/cgi/p2webCgi.cpp
+++ b/project2/cgi/p2webCgi.cpp
@@ -19,7 +19,7 @@ main(void)
CgiApplicationEngine app;
GetEnv ge;
CgiRequestContext crc(NULL, ge);
- OptionsSource::loadSources(boost::bind(&HostnamePlatformIdentifier::derivedPlatform, boost::cref(CgiApplicationEngine::hpi), &crc));
+ OptionsSource::loadSources(boost::bind(&CgiApplicationEngine::derivedPlatform, &crc));
Plugable::onAllComponents(boost::bind(&ComponentLoader::onBefore, _1));
app.process(std::cout, &crc);
Plugable::onAllComponents(boost::bind(&ComponentLoader::onIteration, _1));
diff --git a/project2/cgi/p2webFCgi.cpp b/project2/cgi/p2webFCgi.cpp
index 4320c48..4bc9b2d 100644
--- a/project2/cgi/p2webFCgi.cpp
+++ b/project2/cgi/p2webFCgi.cpp
@@ -46,7 +46,7 @@ main(void)
alarm(0);
cgicc::FCgiIO IO(request);
CgiRequestContext crc(&IO, IO);
- OptionsSource::loadSources(boost::bind(&HostnamePlatformIdentifier::derivedPlatform, boost::cref(CgiApplicationEngine::hpi), &crc));
+ OptionsSource::loadSources(boost::bind(&CgiApplicationEngine::derivedPlatform, &crc));
Plugable::onAllComponents(boost::bind(&ComponentLoader::onBefore, _1));
app.process(IO, &crc);
FCGX_Finish_r(&request);
diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp
index 2025594..6fa8d42 100644
--- a/project2/cgi/testCgi.cpp
+++ b/project2/cgi/testCgi.cpp
@@ -26,7 +26,7 @@ class TestInput : public cgicc::CgiInput, public CgiEnvInput {
TestInput(int argc, char ** argv) :
crc(NULL, *this)
{
- auto cp = boost::bind(&HostnamePlatformIdentifier::derivedPlatform, boost::cref(CgiApplicationEngine::hpi), &crc);
+ auto cp = boost::bind(&CgiApplicationEngine::derivedPlatform, &crc);
OptionsSource::loadSources(cp);
FileOptions fo(".testCgi.settings");
fo.loadInto(TestConfigConsumer(), cp);