summaryrefslogtreecommitdiff
path: root/project2/cgi
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-12-14 00:20:38 +0000
committerrandomdan <randomdan@localhost>2010-12-14 00:20:38 +0000
commit3d7de00dfbd5d8127d2a41f23c39568852a68062 (patch)
treea4ecc86baff05083ee7149a06c735c28eb79c8b5 /project2/cgi
parentSupport binding null to an SQL command parameter (diff)
downloadproject2-3d7de00dfbd5d8127d2a41f23c39568852a68062.tar.bz2
project2-3d7de00dfbd5d8127d2a41f23c39568852a68062.tar.xz
project2-3d7de00dfbd5d8127d2a41f23c39568852a68062.zip
All new fangled iterators, views, row engines, exceptions, the list goes on
Includes site and console updates to match
Diffstat (limited to 'project2/cgi')
-rw-r--r--project2/cgi/cgiAppEngine.cpp82
-rw-r--r--project2/cgi/cgiAppEngine.h9
-rw-r--r--project2/cgi/cgiEnvironment.cpp5
-rw-r--r--project2/cgi/p2webMain.cpp10
4 files changed, 52 insertions, 54 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp
index 94de818..f4a4fb0 100644
--- a/project2/cgi/cgiAppEngine.cpp
+++ b/project2/cgi/cgiAppEngine.cpp
@@ -72,17 +72,20 @@ CgiApplicationEngine::Stage::~Stage()
CgiApplicationEngine::PresentStage::PresentStage(const CgiApplicationEngine * e, const std::string & id) :
CgiApplicationEngine::Stage(e),
- Presenter("present", id)
+ XmlPresenter("present", id)
{
}
+
CgiApplicationEngine::PresentStage::PresentStage(const CgiApplicationEngine * e, const std::string & group, const std::string & id) :
CgiApplicationEngine::Stage(e),
- Presenter(group, id)
+ XmlPresenter(group, id)
{
}
+
CgiApplicationEngine::PresentStage::~PresentStage()
{
}
+
CgiApplicationEngine::Stage *
CgiApplicationEngine::PresentStage::run()
{
@@ -91,52 +94,46 @@ CgiApplicationEngine::PresentStage::run()
return new PresentStage(appEngine, pc.second->present);
}
}
+ execute();
appEngine->doc = getDataDocument();
+ appEngine->header = new cgicc::HTTPContentHeader(contentType);
sessionsContainer->CleanUp();
return NULL;
}
-Presenter::XmlDocumentPtr
-CgiApplicationEngine::PresentStage::getDataDocument() const
+void
+CgiApplicationEngine::addAppData(const Presenter * p) const
{
- XmlDocumentPtr responseDoc = Presenter::getDataDocument();
- xmlpp::Element * responseRoot = responseDoc->get_root_node();
// URL elements
- xmlpp::Element * uriElems = responseRoot->add_child("uriElems", "project2");
- BOOST_FOREACH(std::string s, appEngine->_env->elems) {
- uriElems->add_child("uriElem", "project2")->set_child_text(s);
+ p->pushSub("uriElems", "project2");
+ BOOST_FOREACH(std::string s, _env->elems) {
+ p->addField("uriElem", "project2", s);
}
+ p->popSub();
+
// Parameters
- xmlpp::Element * paramsXml = responseRoot->add_child("params", "project2");
- BOOST_FOREACH(cgicc::FormEntry fe, appEngine->_env->cgi->getElements()) {
- xmlpp::Element * param = paramsXml->add_child("param", "project2");
- param->add_child_text(fe.getValue());
- param->set_attribute("name", fe.getName());
+ p->pushSub("params", "project2");
+ BOOST_FOREACH(cgicc::FormEntry fe, _env->cgi->getElements()) {
+ p->pushSub("param", "project2");
+ p->addAttr("name", fe.getName());
+ p->addAttr("value", fe.getValue());
+ p->popSub();
}
+ p->popSub();
+
// Sessions variables
- if (!appEngine->sessionID.is_nil()) {
- xmlpp::Element * sessionXml = responseRoot->add_child("session", "project2");
- sessionXml->set_attribute("id", boost::lexical_cast<Glib::ustring>(appEngine->sessionID));
- Session::Values session(sessionsContainer->GetSession(appEngine->sessionID)->GetValuesCopy());
+ if (!sessionID.is_nil()) {
+ p->pushSub("session", "project2");
+ p->addField("id", boost::lexical_cast<Glib::ustring>(sessionID));
+ Session::Values session(sessionsContainer->GetSession(sessionID)->GetValuesCopy());
BOOST_FOREACH(Session::Values::value_type sv, session) {
- xmlpp::Element * param = sessionXml->add_child("var", "project2");
- param->add_child_text(sv.second);
- param->set_attribute("name", sv.first);
+ p->pushSub("var", "project2");
+ p->addAttr("value", sv.second);
+ p->addAttr("name", sv.first);
+ p->popSub();
}
+ p->popSub();
}
- // XSLT Style
- char * buf;
- 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");
- }
- return responseDoc;
}
CgiApplicationEngine::RequestStage::RequestStage(const CgiApplicationEngine * e, const std::string & id) :
@@ -148,10 +145,11 @@ CgiApplicationEngine::RequestStage::RequestStage(const CgiApplicationEngine * e,
present = requestRoot->get_attribute_value("present");
LoaderBase loader("http://project2.randomdan.homeip.net", true);
- loader.supportedStorers.insert(Storer::into(&appEngine->datasources));
+ loader.supportedStorers.insert(Storer::into(&datasources));
loader.supportedStorers.insert(Storer::into(&parameterChecks));
+ loader.supportedStorers.insert(Storer::into(&rowSets));
loader.supportedStorers.insert(Storer::into(&tasks));
- loader.collectAll(requestRoot, true);
+ loader.collectAll(this, requestRoot, true);
}
CgiApplicationEngine::RequestStage::~RequestStage()
{
@@ -169,18 +167,18 @@ CgiApplicationEngine::RequestStage::run()
t.second->execute();
}
// Commit data source transactions (without invoking a connection)
- BOOST_FOREACH(DataSources::value_type ds, appEngine->datasources) {
+ BOOST_FOREACH(DataSources::value_type ds, datasources) {
ds.second->commit();
}
+ return new PresentStage(appEngine, present);
}
catch (...) {
// Do something about the error
- BOOST_FOREACH(DataSources::value_type ds, appEngine->datasources) {
+ BOOST_FOREACH(DataSources::value_type ds, datasources) {
ds.second->rollback();
}
throw;
}
- return new PresentStage(appEngine, present);
}
SessionPtr
@@ -189,9 +187,3 @@ CgiApplicationEngine::session() const
return sessionsContainer->GetSession(sessionID);
}
-PresenterPtr
-CgiApplicationEngine::getPresenter(const std::string & group, const std::string & id) const
-{
- return PresenterPtr(new PresentStage(this, group, id));
-}
-
diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h
index cebb294..db4d696 100644
--- a/project2/cgi/cgiAppEngine.h
+++ b/project2/cgi/cgiAppEngine.h
@@ -5,6 +5,7 @@
#include "../task.h"
#include "../paramChecker.h"
#include "../presenter.h"
+#include "../commonObjects.h"
#include <boost/intrusive_ptr.hpp>
#include <boost/uuid/uuid.hpp>
#include <libxml++/document.h>
@@ -30,13 +31,13 @@ class CgiApplicationEngine : public ApplicationEngine {
}
const Environment * env() const;
SessionPtr session() const;
- PresenterPtr getPresenter(const std::string & group, const std::string & id) const;
+ void addAppData(const Presenter * p) const;
const CgiEnvironment * _env;
protected:
mutable cgicc::HTTPContentHeader * header;
private:
mutable boost::shared_ptr<xmlpp::Document> doc;
- class Stage {
+ class Stage : public CommonObjects {
public:
Stage(const CgiApplicationEngine *);
virtual ~Stage() = 0;
@@ -54,14 +55,12 @@ class CgiApplicationEngine : public ApplicationEngine {
OrderedParamCheckers parameterChecks;
NoOutputExecutes tasks;
};
- class PresentStage : public Stage, public Presenter {
+ class PresentStage : public Stage, public XmlPresenter {
public:
PresentStage(const CgiApplicationEngine *, const std::string & id);
PresentStage(const CgiApplicationEngine *, const std::string & group, const std::string & id);
virtual ~PresentStage();
virtual Stage * run();
- protected:
- XmlDocumentPtr getDataDocument() const;
};
mutable Stage * currentStage;
mutable boost::uuids::uuid sessionID;
diff --git a/project2/cgi/cgiEnvironment.cpp b/project2/cgi/cgiEnvironment.cpp
index 630629a..3461973 100644
--- a/project2/cgi/cgiEnvironment.cpp
+++ b/project2/cgi/cgiEnvironment.cpp
@@ -1,5 +1,6 @@
#include "cgiEnvironment.h"
#include "../appEngine.h"
+#include "../exceptions.h"
#include <map>
#include <cgicc/Cgicc.h>
#include <boost/tokenizer.hpp>
@@ -25,7 +26,7 @@ Glib::ustring
CgiEnvironment::getParamUri(unsigned int p) const
{
if (p >= elems.size()) {
- throw ApplicationEngine::UriElementOutOfRange();
+ throw UriElementOutOfRange();
}
return elems[p];
}
@@ -35,7 +36,7 @@ CgiEnvironment::getParamQuery(const std::string & p) const
{
cgicc::const_form_iterator i = cgi->getElement(p);
if (i == cgi->getElements().end()) {
- throw ApplicationEngine::ParamNotFound();
+ throw ParamNotFound();
}
return (*cgi)(p);
}
diff --git a/project2/cgi/p2webMain.cpp b/project2/cgi/p2webMain.cpp
index c36335a..59e8d7b 100644
--- a/project2/cgi/p2webMain.cpp
+++ b/project2/cgi/p2webMain.cpp
@@ -40,6 +40,7 @@ p2webGoingIdle(int)
int main(void)
{
if (!FCGX_IsCGI()) {
+ syslog(LOG_NOTICE, "FCGID Startup ($Id$)");
FCGX_Request request;
FCGX_Init();
@@ -69,12 +70,17 @@ int main(void)
catch (const std::exception & e) {
cgicc::HTTPContentHeader header("text/plain");
header.render(IO);
- IO << "Kaboom!" << std::endl << std::endl << e.what();
+ IO << "Kaboom!" << std::endl
+ << std::endl
+ << typeid(e).name() << std::endl
+ << e.what() << std::endl;
}
catch (...) {
cgicc::HTTPContentHeader header("text/plain");
header.render(IO);
- IO << "Kaboom!" << std::endl << std::endl << "Unknown exception.";
+ IO << "Kaboom!" << std::endl
+ << std::endl
+ << "Unknown exception." << std::endl;
}
alarm(60);
LoaderBase::onIteration();