summaryrefslogtreecommitdiff
path: root/project2/cgi
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-06-20 18:08:17 +0000
committerrandomdan <randomdan@localhost>2013-06-20 18:08:17 +0000
commit4d2de57f7ae974347767785dbb2062986d30df27 (patch)
treec6ccd43f1524adb06850795efa33d822691e30ca /project2/cgi
parentAdd back some basic help output (diff)
downloadproject2-4d2de57f7ae974347767785dbb2062986d30df27.tar.bz2
project2-4d2de57f7ae974347767785dbb2062986d30df27.tar.xz
project2-4d2de57f7ae974347767785dbb2062986d30df27.zip
Move options into the global scope
Diffstat (limited to 'project2/cgi')
-rw-r--r--project2/cgi/cgiContentNegotiate.cpp25
-rw-r--r--project2/cgi/cgiEnvironment.cpp92
-rw-r--r--project2/cgi/cgiEnvironment.h33
-rw-r--r--project2/cgi/cgiOutputOptions.cpp28
-rw-r--r--project2/cgi/cgiOutputOptions.h6
-rw-r--r--project2/cgi/cgiProgRouter.cpp26
-rw-r--r--project2/cgi/testCgi.cpp115
7 files changed, 156 insertions, 169 deletions
diff --git a/project2/cgi/cgiContentNegotiate.cpp b/project2/cgi/cgiContentNegotiate.cpp
index 2ed54c9..916dfc1 100644
--- a/project2/cgi/cgiContentNegotiate.cpp
+++ b/project2/cgi/cgiContentNegotiate.cpp
@@ -6,19 +6,6 @@
class ContentNegotiateLoader : public PresenterLoader {
public:
- ContentNegotiateLoader() :
- opts("Content negotiation options")
- {
- opts
- ("cgi.contentnegotiation.mappedtype", Options::functions(
- [this](const VariableType & v) { mappedTypes.push_back(new MappedType(v)); },
- boost::bind(&MappedTypes::clear, &mappedTypes)),
- "mimetype=presenter list of types to negotiate")
- ;
- }
-
- const Options * options() const { return &opts; }
-
MultiRowSetPresenter * create(const ScriptNodePtr & s, const ObjectSource & os) const
{
auto accept = static_cast<const CgiApplicationEngine *>(CgiApplicationEngine::getCurrent())->env()->getAccept();
@@ -35,7 +22,7 @@ class ContentNegotiateLoader : public PresenterLoader {
return PresenterLoader::getFor((*mappedTypes.begin())->present)->create(s, os);
}
- Options opts;
+ INITOPTIONS;
class MappedType : public IntrusivePtrBase {
public:
MappedType(const std::string & val) :
@@ -54,10 +41,18 @@ class ContentNegotiateLoader : public PresenterLoader {
};
typedef boost::intrusive_ptr<MappedType> MappedTypePtr;
typedef std::vector<MappedTypePtr> MappedTypes;
- MappedTypes mappedTypes;
+ static MappedTypes mappedTypes;
bool cacheable() const { return false; }
};
+ContentNegotiateLoader::MappedTypes ContentNegotiateLoader::mappedTypes;
DECLARE_CUSTOM_COMPONENT_LOADER("contentnegotiate", ContentNegotiateLoader, ContentNegotiateLoader, PresenterLoader);
+DECLARE_OPTIONS(ContentNegotiateLoader, "Content negotiation options")
+("cgi.contentnegotiation.mappedtype", Options::functions(
+ [](const VariableType & v) { mappedTypes.push_back(new MappedType(v)); },
+ boost::bind(&MappedTypes::clear, &mappedTypes)),
+ "mimetype=presenter list of types to negotiate")
+END_OPTIONS(ContentNegotiateLoader)
+
diff --git a/project2/cgi/cgiEnvironment.cpp b/project2/cgi/cgiEnvironment.cpp
index 618548c..7cd7cd5 100644
--- a/project2/cgi/cgiEnvironment.cpp
+++ b/project2/cgi/cgiEnvironment.cpp
@@ -10,49 +10,59 @@
#include <glibmm/regex.h>
#include <curl/curl.h>
+std::string CgiEnvironment::dumpdatadoc;
+Glib::ustring CgiEnvironment::errorContentType;
+Glib::ustring CgiEnvironment::errorTransformStyle;
+std::string CgiEnvironment::defaultPresent;
+std::string CgiEnvironment::transformContentType;
+std::string CgiEnvironment::transformTargetType;
+std::string CgiEnvironment::presentRoot;
+std::string CgiEnvironment::requestRoot;
+std::string CgiEnvironment::errorPresentRoot;
+std::string CgiEnvironment::notFoundPresent;
+std::string CgiEnvironment::onErrorPresent;
+std::string CgiEnvironment::defaultPresenter;
+std::string CgiEnvironment::sessionModule;
+std::string CgiEnvironment::routerType;
+boost::intrusive_ptr<HostnamePlatformIdentifier> CgiEnvironment::hpi;
+
+DECLARE_OPTIONS(CgiEnvironment, "Project2 CGI options")
+("cgi.defaultPresenter", Options::value(&defaultPresenter, "xml"),
+ "The default engine for formatting presentations")
+("cgi.transformContentType", Options::value(&transformContentType, "text/xml-xslt"),
+ "The content type specified to enable standard internal transformations")
+("cgi.transformTargetType", Options::value(&transformTargetType, "htmldocument"),
+ "The transform target type used in standard internal transformations")
+("cgi.defaultPresent", Options::value(&defaultPresent, "index"),
+ "The present script to use when no other is specified")
+("cgi.presentRoot", Options::value(&presentRoot, "present"),
+ "The folder in which to find presentation scripts")
+("cgi.requestRoot", Options::value(&requestRoot, "request"),
+ "The folder in which to find request scripts")
+("cgi.errorPresentRoot", Options::value(&errorPresentRoot, "error"),
+ "The folder in which to find presentation scripts for error handling")
+("cgi.errorContentType", Options::value(&errorContentType, "application/xml"),
+ "The Content-Type to use in HTTP headers in event of an error")
+("cgi.errorTransformStyle", Options::value(&errorTransformStyle),
+ "The xml-stylesheet to specify in the data document in event of an error")
+("cgi.notFoundPresent", Options::value(&notFoundPresent),
+ "The present script to use when the requested script does not exist")
+("cgi.onErrorPresent", Options::value(&onErrorPresent),
+ "The present script to use when the requested script (or child) fails")
+("cgi.dumpDataDoc", Options::value(&dumpdatadoc),
+ "Write a copy of the data document before sending it to the web server")
+("cgi.sessionModule", Options::value(&sessionModule, "xml"),
+ "The module with which to implement session management")
+("cgi.hostRegex", (hpi = new HostnamePlatformIdentifier()),
+ "Regular expression used to define a hostname -> platform association")
+("cgi.router", Options::value(&routerType, "simple"),
+ "Implemenation of router model to map request paths to scripts")
+END_OPTIONS(CgiEnvironment);
+
CgiEnvironment::CgiEnvironment() :
cgi(NULL),
- cgienv(NULL),
- cgiOptions("Project2 CGI options"),
- hpi(new HostnamePlatformIdentifier())
-{
- cgiOptions
- ("cgi.defaultPresenter", Options::value(&defaultPresenter, "xml"),
- "The default engine for formatting presentations")
- ("cgi.transformContentType", Options::value(&transformContentType, "text/xml-xslt"),
- "The content type specified to enable standard internal transformations")
- ("cgi.transformTargetType", Options::value(&transformTargetType, "htmldocument"),
- "The transform target type used in standard internal transformations")
- ("cgi.defaultPresent", Options::value(&defaultPresent, "index"),
- "The present script to use when no other is specified")
- ("cgi.presentRoot", Options::value(&presentRoot, "present"),
- "The folder in which to find presentation scripts")
- ("cgi.requestRoot", Options::value(&requestRoot, "request"),
- "The folder in which to find request scripts")
- ("cgi.errorPresentRoot", Options::value(&errorPresentRoot, "error"),
- "The folder in which to find presentation scripts for error handling")
- ("cgi.errorContentType", Options::value(&errorContentType, "application/xml"),
- "The Content-Type to use in HTTP headers in event of an error")
- ("cgi.errorTransformStyle", Options::value(&errorTransformStyle),
- "The xml-stylesheet to specify in the data document in event of an error")
- ("cgi.notFoundPresent", Options::value(&notFoundPresent),
- "The present script to use when the requested script does not exist")
- ("cgi.onErrorPresent", Options::value(&onErrorPresent),
- "The present script to use when the requested script (or child) fails")
- ("cgi.dumpDataDoc", Options::value(&dumpdatadoc),
- "Write a copy of the data document before sending it to the web server")
- ("cgi.sessionModule", Options::value(&sessionModule, "xml"),
- "The module with which to implement session management")
- ("cgi.hostRegex", hpi,
- "Regular expression used to define a hostname -> platform association")
- ("cgi.router", Options::value(&routerType, "simple"),
- "Implemenation of router model to map request paths to scripts")
- ;
-}
-
-const Options &
-CgiEnvironment::engineOptions() const {
- return cgiOptions;
+ cgienv(NULL)
+{
}
CgiEnvironment::~CgiEnvironment()
diff --git a/project2/cgi/cgiEnvironment.h b/project2/cgi/cgiEnvironment.h
index c09f5a9..d1d51c0 100644
--- a/project2/cgi/cgiEnvironment.h
+++ b/project2/cgi/cgiEnvironment.h
@@ -53,26 +53,25 @@ class CgiEnvironment : public Environment {
const CgiEnvInput * cgienv;
private:
- const Options & engineOptions() const;
const Glib::ustring & platform() const;
- Options cgiOptions;
- boost::intrusive_ptr<HostnamePlatformIdentifier> hpi;
public:
- std::string dumpdatadoc;
- Glib::ustring errorContentType;
- Glib::ustring errorTransformStyle;
- std::string defaultPresent;
- std::string transformContentType;
- std::string transformTargetType;
- std::string presentRoot;
- std::string requestRoot;
- std::string errorPresentRoot;
- std::string notFoundPresent;
- std::string onErrorPresent;
- std::string defaultPresenter;
- std::string sessionModule;
- std::string routerType;
+ INITOPTIONS;
+ static boost::intrusive_ptr<HostnamePlatformIdentifier> hpi;
+ static std::string dumpdatadoc;
+ static Glib::ustring errorContentType;
+ static Glib::ustring errorTransformStyle;
+ static std::string defaultPresent;
+ static std::string transformContentType;
+ static std::string transformTargetType;
+ static std::string presentRoot;
+ static std::string requestRoot;
+ static std::string errorPresentRoot;
+ static std::string notFoundPresent;
+ static std::string onErrorPresent;
+ static std::string defaultPresenter;
+ static std::string sessionModule;
+ static std::string routerType;
typedef LazyPointer<const Router> RouterPtr;
RouterPtr router;
};
diff --git a/project2/cgi/cgiOutputOptions.cpp b/project2/cgi/cgiOutputOptions.cpp
index 59b034d..55e1de4 100644
--- a/project2/cgi/cgiOutputOptions.cpp
+++ b/project2/cgi/cgiOutputOptions.cpp
@@ -20,30 +20,20 @@ OutputOptions::OutputOptions(ScriptNodePtr p) :
{
}
-OutputOptionsLoader::OutputOptionsLoader() :
- opts("CGI default output options")
-{
- opts
- ("cgi.output.encoding", Options::value(&OutputOptions::encoding, "utf-8"), "Default out encoding")
- ("cgi.output.core", Options::value(&OutputOptions::core, true), "Core messages")
- ("cgi.output.session", Options::value(&OutputOptions::session, true), "Session values")
- ("cgi.output.timing", Options::value(&OutputOptions::timing, true), "Timing")
- ("cgi.output.environment", Options::value(&OutputOptions::environment, true), "Environment")
- ("cgi.output.url", Options::value(&OutputOptions::url, true), "URL breakdown")
- ("cgi.output.parameters", Options::value(&OutputOptions::parameters, true), "Parameters")
- ;
-}
+DECLARE_OPTIONS(OutputOptionsLoader, "CGI default output options")
+("cgi.output.encoding", Options::value(&OutputOptions::encoding, "utf-8"), "Default out encoding")
+("cgi.output.core", Options::value(&OutputOptions::core, true), "Core messages")
+("cgi.output.session", Options::value(&OutputOptions::session, true), "Session values")
+("cgi.output.timing", Options::value(&OutputOptions::timing, true), "Timing")
+("cgi.output.environment", Options::value(&OutputOptions::environment, true), "Environment")
+("cgi.output.url", Options::value(&OutputOptions::url, true), "URL breakdown")
+("cgi.output.parameters", Options::value(&OutputOptions::parameters, true), "Parameters")
+END_OPTIONS(OutputOptionsLoader)
OutputOptionsPtr
OutputOptionsLoader::create(ScriptNodePtr e) const {
return new OutputOptions(e);
}
-const Options *
-OutputOptionsLoader::options() const
-{
- return &opts;
-}
-
DECLARE_CUSTOM_COMPONENT_LOADER("outputoptions", OutputOptions, OutputOptionsLoader, OutputOptionsLoader)
diff --git a/project2/cgi/cgiOutputOptions.h b/project2/cgi/cgiOutputOptions.h
index a975fa0..bb214ea 100644
--- a/project2/cgi/cgiOutputOptions.h
+++ b/project2/cgi/cgiOutputOptions.h
@@ -32,12 +32,8 @@ typedef boost::intrusive_ptr<OutputOptions> OutputOptionsPtr;
class OutputOptionsLoader : public ComponentLoader {
public:
- OutputOptionsLoader();
OutputOptionsPtr create(ScriptNodePtr e) const;
- const Options * options() const;
-
- private:
- Options opts;
+ INITOPTIONS;
};
#endif
diff --git a/project2/cgi/cgiProgRouter.cpp b/project2/cgi/cgiProgRouter.cpp
index 932242e..742924c 100644
--- a/project2/cgi/cgiProgRouter.cpp
+++ b/project2/cgi/cgiProgRouter.cpp
@@ -127,22 +127,6 @@ DECLARE_LOADER("route", Route);
class ProgRouter;
class ProgRouterLoader : public RouterLoader::For<ProgRouter> {
public:
- ProgRouterLoader() :
- opts("CGI Prog Router options")
- {
- opts
- ("cgi.progRouter.routes", Options::functions(
- boost::bind(&RoutingTable::loadRoutesFromFile, &routingTable, _1),
- boost::bind(&RoutingTable::clearRoutes, &routingTable)),
- "Script file defining web service routes")
- ;
- }
-
- const Options * options() const
- {
- return &opts;
- }
-
void onBefore()
{
routingTable.onBefore();
@@ -150,12 +134,18 @@ class ProgRouterLoader : public RouterLoader::For<ProgRouter> {
static RoutingTable routingTable;
- private:
- Options opts;
+ INITOPTIONS;
};
RoutingTable ProgRouterLoader::routingTable;
+DECLARE_OPTIONS(ProgRouterLoader, "CGI Programmable Router options")
+("cgi.progRouter.routes", Options::functions(
+ boost::bind(&RoutingTable::loadRoutesFromFile, &routingTable, _1),
+ boost::bind(&RoutingTable::clearRoutes, &routingTable)),
+ "Script file defining web service routes")
+END_OPTIONS(ProgRouterLoader);
+
SimpleMessageException(UriElementNotFound);
class ProgRouter : public Router {
diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp
index 6dc2193..cff947d 100644
--- a/project2/cgi/testCgi.cpp
+++ b/project2/cgi/testCgi.cpp
@@ -7,78 +7,47 @@
#include "../files/optionsSource.h"
#define TESTOPT(name, def, desc) \
- (name, Options::value(optStore.insert(OptStore::value_type(name, StrPtr(new std::string()))).first->second.get(), def), desc)
+ (name, Options::value(optStore().insert(OptStore::value_type(name, StrPtr(new std::string()))).first->second.get(), def), desc)
class TestInput : public cgicc::CgiInput, public CgiEnvInput {
public:
class TestConfigConsumer : public ConfigConsumer {
public:
- TestConfigConsumer(const Options * os) : o(os) {
- }
void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v) const {
- o->consume(n, p, v);
+ LoaderBase::onAll<Options>(boost::bind(&Options::consume, _1, n, p, v));
}
const Options::Option * get(const Glib::ustring &) const {
return NULL;
}
- private:
- const Options * o;
};
typedef boost::shared_ptr<std::string> StrPtr;
typedef std::map<std::string, StrPtr> OptStore;
- OptStore optStore;
- TestInput() :
- opts("Project2 CGI test options"),
- runCount(0)
+ TestInput(int argc, char ** argv)
{
- opts
- TESTOPT("SERVER_NAME", "localhost", "FQDN of web service")
- TESTOPT("SERVER_SOFTWARE", "Apache", "Web server version string")
- TESTOPT("GATEWAY_INTERFACE", "CGI/1.1", "Web server/script interface version")
- TESTOPT("SERVER_PROTOCOL", "HTTP/1.1", "Web server/client interface version")
- TESTOPT("SERVER_PORT", "80", "Server Port")
- TESTOPT("REQUEST_METHOD", "GET", "Request method")
- TESTOPT("PATH_INFO", "", "Path info")
- TESTOPT("PATH_TRANSLATED", "", "Path translated")
- TESTOPT("SCRIPT_NAME", "p2fcgi", "Script name")
- TESTOPT("QUERY_STRING", "", "Query string")
- TESTOPT("REMOTE_HOST", "", "Remote host")
- TESTOPT("REMOTE_ADDR", "", "Remote address")
- TESTOPT("AUTH_TYPE", "", "Authentication type")
- TESTOPT("REMOTE_USER", "", "Remote user")
- TESTOPT("REMOTE_IDENT", "", "Remote ident")
- TESTOPT("CONTENT_TYPE", "", "Content type")
- TESTOPT("CONTENT_LENGTH", "", "Content length")
- TESTOPT("HTTP_ACCEPT", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accepted MIME types")
- TESTOPT("HTTP_USER_AGENT", "Mozilla/5.0", "User agent")
- TESTOPT("REDIRECT_REQUEST", "", "Redirect request")
- TESTOPT("REDIRECT_URL", "", "Redirect URL")
- TESTOPT("REDIRECT_STATUS", "", "Redirect status")
- TESTOPT("HTTP_REFERER", "", "Referrer")
- TESTOPT("HTTP_COOKIE", "", "Cookie")
- TESTOPT("HTTPS", "No", "HTTPS?")
- TESTOPT("HTTP_IF_MODIFIED_SINCE", "", "Client cached copy timestamp")
- ("urlListFile", Options::value(&urlListFile, ""), "Load URL list from this file")
- ("runCount", Options::value(&runCount, 1), "Repeat run this many times")
- ;
+ env.init();
FileOptions fo(".testCgi.settings");
- opts.reset();
- fo.loadInto(TestConfigConsumer(&opts));
- }
-
- const Options * options() const {
- return &opts;
+ fo.loadInto(TestConfigConsumer());
+ if (argc > 1) {
+ const char * qm = strchr(argv[1], '?');
+ if (qm) {
+ optStore()["REDIRECT_URL"] = StrPtr(new std::string(argv[1], qm - argv[1]));
+ optStore()["QUERY_STRING"] = StrPtr(new std::string(qm + 1));
+ }
+ else {
+ optStore()["REDIRECT_URL"] = StrPtr(new std::string(argv[1]));
+ }
+ }
}
std::string getenv(const std::string & varName) const
{
StrPtr def(new std::string());
- return *defaultMapFind(optStore, varName, def);
+ return *defaultMapFind(optStore(), varName, def);
}
virtual std::string getenv(const char * varName)
{
StrPtr def(new std::string());
- return *defaultMapFind(optStore, varName, def);
+ return *defaultMapFind(optStore(), varName, def);
}
void run()
{
@@ -93,24 +62,62 @@ class TestInput : public cgicc::CgiInput, public CgiEnvInput {
while (!urls.eof()) {
std::string url;
urls >> url;
- optStore["REDIRECT_URL"] = StrPtr(new std::string(url));
+ optStore()["REDIRECT_URL"] = StrPtr(new std::string(url));
cgiServe(this, &env, std::cout, this);
}
}
}
}
+ INITOPTIONS;
private:
CgiEnvironment env;
- Options opts;
- int runCount;
- std::string urlListFile;
+ static int runCount;
+ static std::string urlListFile;
+ static OptStore & optStore()
+ {
+ static OptStore _optStore;
+ return _optStore;
+ }
};
+int TestInput::runCount;
+std::string TestInput::urlListFile;
+
+DECLARE_OPTIONS(TestInput, "Project2 CGI test options")
+TESTOPT("SERVER_NAME", "localhost", "FQDN of web service")
+TESTOPT("SERVER_SOFTWARE", "Apache", "Web server version string")
+TESTOPT("GATEWAY_INTERFACE", "CGI/1.1", "Web server/script interface version")
+TESTOPT("SERVER_PROTOCOL", "HTTP/1.1", "Web server/client interface version")
+TESTOPT("SERVER_PORT", "80", "Server Port")
+TESTOPT("REQUEST_METHOD", "GET", "Request method")
+TESTOPT("PATH_INFO", "", "Path info")
+TESTOPT("PATH_TRANSLATED", "", "Path translated")
+TESTOPT("SCRIPT_NAME", "p2fcgi", "Script name")
+TESTOPT("QUERY_STRING", "", "Query string")
+TESTOPT("REMOTE_HOST", "", "Remote host")
+TESTOPT("REMOTE_ADDR", "", "Remote address")
+TESTOPT("AUTH_TYPE", "", "Authentication type")
+TESTOPT("REMOTE_USER", "", "Remote user")
+TESTOPT("REMOTE_IDENT", "", "Remote ident")
+TESTOPT("CONTENT_TYPE", "", "Content type")
+TESTOPT("CONTENT_LENGTH", "", "Content length")
+TESTOPT("HTTP_ACCEPT", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accepted MIME types")
+TESTOPT("HTTP_USER_AGENT", "Mozilla/5.0", "User agent")
+TESTOPT("REDIRECT_REQUEST", "", "Redirect request")
+TESTOPT("REDIRECT_URL", "", "Redirect URL")
+TESTOPT("REDIRECT_STATUS", "", "Redirect status")
+TESTOPT("HTTP_REFERER", "", "Referrer")
+TESTOPT("HTTP_COOKIE", "", "Cookie")
+TESTOPT("HTTPS", "No", "HTTPS?")
+TESTOPT("HTTP_IF_MODIFIED_SINCE", "", "Client cached copy timestamp")
+("urlListFile", Options::value(&urlListFile, ""), "Load URL list from this file")
+("runCount", Options::value(&runCount, 1), "Repeat run this many times")
+END_OPTIONS(TestInput);
int
-main(int, char **)
+main(int argc, char ** argv)
{
- TestInput ti;
+ TestInput ti(argc, argv);
ti.run();
}