diff options
-rw-r--r-- | project2/Jamfile.jam | 7 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 14 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.h | 4 | ||||
-rw-r--r-- | project2/sessionContainer.cpp | 2 | ||||
-rw-r--r-- | project2/sessionContainer.h | 6 | ||||
-rw-r--r-- | project2/sessionXml.cpp | 23 | ||||
-rw-r--r-- | project2/sessionXml.h | 3 | ||||
-rw-r--r-- | project2/uuid.cpp | 99 | ||||
-rw-r--r-- | project2/uuid.h | 38 |
9 files changed, 166 insertions, 30 deletions
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 6ae5713..7959ee4 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -1,4 +1,5 @@ import package ; +import feature : feature ; alias libxmlpp : : : : <cflags>"`pkg-config --cflags libxml++-2.6`" @@ -15,17 +16,21 @@ lib boost_filesystem : : <name>boost_filesystem ; lib cgicc : : <name>cgicc ; lib esmtp : : <name>esmtp ; lib curl : : <name>curl ; +lib osspuuid : : <name>ossp-uuid++ ; + +feature uuid : boost ossp : propagated ; lib p2common : appEngine.cpp dataSource.cpp environment.cpp fileStarGlibIoChannel.cpp iHaveParameters.cpp iterate.cpp paramChecker.cpp presenter.cpp rawView.cpp dumpTask.cpp sourceObject.cpp task.cpp variables.cpp view.cpp xmlObjectLoader.cpp exceptions.cpp sessionClearTask.cpp session.cpp sessionSetTask.cpp commonObjects.cpp xmlPresenter.cpp - rowView.cpp rowSet.cpp rowUser.cpp rowProcessor.cpp + rowView.cpp rowSet.cpp rowUser.cpp rowProcessor.cpp uuid.cpp : <library>../libmisc//misc <library>libxmlpp <library>boost_filesystem + <uuid>ossp:<library>osspuuid ; lib p2xml : diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index f4a4fb0..12a30d7 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -7,13 +7,10 @@ #include "../xmlObjectLoader.h" #include "../iterate.h" #include <boost/bind.hpp> -#include <boost/lexical_cast.hpp> -#include <boost/uuid/uuid_io.hpp> #include "../sessionXml.h" -#include <boost/uuid/uuid_generators.hpp> const std::string SESSIONID = "sessionID"; -typedef boost::uuids::uuid SIDKey; +typedef UUID SIDKey; typedef std::string SValue; SessionContainer * sessionsContainer = new SessionContainerXml(); @@ -21,12 +18,11 @@ SessionContainer * sessionsContainer = new SessionContainerXml(); CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e) : ApplicationEngine(), _env(e), - header(NULL), - sessionID(boost::uuids::nil_generator()()) + header(NULL) { BOOST_FOREACH(const cgicc::HTTPCookie c, e->getCookieList()) { if (c.getName() == SESSIONID) { - sessionID = boost::uuids::string_generator()(c.getValue()); + sessionID = c.getValue(); } } if (_env->getRequestMethod() == "POST") { @@ -57,7 +53,7 @@ CgiApplicationEngine::process() const delete prev; } if (!sessionID.is_nil()) { - header->setCookie(cgicc::HTTPCookie(SESSIONID, boost::lexical_cast<std::string>(sessionID), "Session ID", + header->setCookie(cgicc::HTTPCookie(SESSIONID, sessionID.str(), "Session ID", _env->getServerName().substr(_env->getServerName().find(".")), 3600, "/", false)); } } @@ -124,7 +120,7 @@ CgiApplicationEngine::addAppData(const Presenter * p) const // Sessions variables if (!sessionID.is_nil()) { p->pushSub("session", "project2"); - p->addField("id", boost::lexical_cast<Glib::ustring>(sessionID)); + p->addField("id", sessionID.str()); Session::Values session(sessionsContainer->GetSession(sessionID)->GetValuesCopy()); BOOST_FOREACH(Session::Values::value_type sv, session) { p->pushSub("var", "project2"); diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 7998648..abd4b9e 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -6,8 +6,8 @@ #include "../paramChecker.h" #include "../xmlPresenter.h" #include "../commonObjects.h" +#include "../uuid.h" #include <boost/intrusive_ptr.hpp> -#include <boost/uuid/uuid.hpp> #include <libxml++/document.h> #include <libxml++/parsers/domparser.h> @@ -63,7 +63,7 @@ class CgiApplicationEngine : public ApplicationEngine { virtual Stage * run(); }; mutable Stage * currentStage; - mutable boost::uuids::uuid sessionID; + mutable UUID sessionID; }; #endif diff --git a/project2/sessionContainer.cpp b/project2/sessionContainer.cpp index 5a73e3b..9028515 100644 --- a/project2/sessionContainer.cpp +++ b/project2/sessionContainer.cpp @@ -9,7 +9,7 @@ SessionContainer::~SessionContainer() } SessionPtr -SessionContainer::GetSession(boost::uuids::uuid & id) +SessionContainer::GetSession(UUID & id) { SessionPtr s = getSession(id); s->ExpiryTime(time(NULL) + 3600); diff --git a/project2/sessionContainer.h b/project2/sessionContainer.h index 08ad0e9..6163200 100644 --- a/project2/sessionContainer.h +++ b/project2/sessionContainer.h @@ -1,7 +1,7 @@ #ifndef SESSIONCONTAINER_H #define SESSIONCONTAINER_H -#include <boost/uuid/uuid.hpp> +#include "uuid.h" #include "session.h" class SessionContainer { @@ -9,11 +9,11 @@ class SessionContainer { SessionContainer(); virtual ~SessionContainer() = 0; - SessionPtr GetSession(boost::uuids::uuid & sid); + SessionPtr GetSession(UUID & sid); virtual void CleanUp() { } protected: - virtual SessionPtr getSession(boost::uuids::uuid & sid) = 0; + virtual SessionPtr getSession(UUID & sid) = 0; }; #endif diff --git a/project2/sessionXml.cpp b/project2/sessionXml.cpp index 3b42924..9e78aec 100644 --- a/project2/sessionXml.cpp +++ b/project2/sessionXml.cpp @@ -1,17 +1,16 @@ #include "sessionXml.h" +#include "uuid.h" #include <libxml++/nodes/element.h> #include <libxml++/parsers/domparser.h> #include <libxml++/nodes/textnode.h> #include <set> +#include <stdio.h> #include <boost/foreach.hpp> -#include <boost/uuid/uuid_generators.hpp> #include <boost/lexical_cast.hpp> -#include <boost/uuid/uuid_io.hpp> -using namespace boost::uuids; class SessionXml : public Session { public: - SessionXml(boost::uuids::uuid & sid); + SessionXml(UUID & sid); SessionXml(const xmlpp::Element *); virtual ~SessionXml(); @@ -22,7 +21,7 @@ class SessionXml : public Session { time_t ExpiryTime() const; void ExpiryTime(time_t); - const uuid sessionID; + const UUID sessionID; private: Values vars; @@ -56,7 +55,7 @@ SessionContainerXml::CleanUp() doc = parser.get_document(); char xpath[200]; snprintf(xpath, 200, "/sessions/session[@id='%s' or @expires < %lu]", - boost::lexical_cast<std::string>(currentSession->sessionID).c_str(), time(NULL)); + currentSession->sessionID.str().c_str(), time(NULL)); xmlpp::NodeSet sess = doc->get_root_node()->find(xpath); BOOST_FOREACH(xmlpp::Node * n, sess) { n->get_parent()->remove_child(n); @@ -67,7 +66,7 @@ SessionContainerXml::CleanUp() doc->create_root_node("sessions"); } xmlpp::Element * sess = doc->get_root_node()->add_child("session"); - sess->set_attribute("id", boost::lexical_cast<Glib::ustring>(currentSession->sessionID)); + sess->set_attribute("id", currentSession->sessionID.str()); sess->set_attribute("expires", boost::lexical_cast<Glib::ustring>(currentSession->expires)); BOOST_FOREACH(const SessionXml::Values::value_type & nvp, currentSession->vars) { xmlpp::Element * v = sess->add_child("var"); @@ -83,14 +82,14 @@ SessionContainerXml::CleanUp() } SessionPtr -SessionContainerXml::getSession(boost::uuids::uuid & sid) +SessionContainerXml::getSession(UUID & sid) { if (!currentSession || currentSession->sessionID != sid) { try { xmlpp::DomParser sessions(xmlFile); char xpath[200]; snprintf(xpath, 200, "/sessions/session[@id='%s' and @expires > %lu]", - boost::lexical_cast<std::string>(sid).c_str(), time(NULL)); + sid.str().c_str(), time(NULL)); xmlpp::NodeSet sess = sessions.get_document()->get_root_node()->find(xpath); if (sess.size() == 1) { currentSession = new SessionXml(dynamic_cast<const xmlpp::Element *>(sess[0])); @@ -106,13 +105,13 @@ SessionContainerXml::getSession(boost::uuids::uuid & sid) return currentSession; } -SessionXml::SessionXml(boost::uuids::uuid & sid) : - sessionID(sid.is_nil() ? sid = boost::uuids::random_generator()() : sid) +SessionXml::SessionXml(UUID & sid) : + sessionID(sid.is_nil() ? sid = UUID::generate_random() : sid) { } SessionXml::SessionXml(const xmlpp::Element * p) : - sessionID(boost::lexical_cast<uuid>(p->get_attribute_value("id"))), + sessionID(p->get_attribute_value("id")), expires(boost::lexical_cast<time_t>(p->get_attribute_value("expires"))) { xmlpp::NodeSet xvars = p->find("var"); diff --git a/project2/sessionXml.h b/project2/sessionXml.h index f9d0059..8086990 100644 --- a/project2/sessionXml.h +++ b/project2/sessionXml.h @@ -3,7 +3,6 @@ #include "sessionContainer.h" #include <map> -#include <boost/uuid/uuid.hpp> class SessionContainerXml : public SessionContainer { public: @@ -13,7 +12,7 @@ class SessionContainerXml : public SessionContainer { void CleanUp(); protected: - SessionPtr getSession(boost::uuids::uuid & sid); + SessionPtr getSession(UUID & sid); }; #endif diff --git a/project2/uuid.cpp b/project2/uuid.cpp new file mode 100644 index 0000000..03e851e --- /dev/null +++ b/project2/uuid.cpp @@ -0,0 +1,99 @@ +#include "uuid.h" + +#ifdef USINGBOOSTUUID +#include <boost/lexical_cast.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/uuid_generators.hpp> + +UUID::UUID() +{ + boost_uuid = boost::uuids::nil_generator()(); +} + +UUID::UUID(const std::string & str) +{ + boost_uuid = boost::lexical_cast<boost::uuids::uuid>(str); +} + +UUID +UUID::generate_random() +{ + UUID u; + u.boost_uuid = boost::uuids::random_generator()(); + return u; +} + +bool +UUID::is_nil() const +{ + return boost_uuid.is_nil(); +} + +std::string +UUID::str() const +{ + return boost::lexical_cast<std::string>(boost_uuid); +} + +void +UUID::operator=(const std::string & str) +{ + boost_uuid = boost::lexical_cast<boost::uuids::uuid>(str); +} + +bool +UUID::operator!=(const UUID & other) const +{ + return boost_uuid != other.boost_uuid; +} + +#endif + +#ifdef USINGOSSPUUID + +UUID::UUID() +{ +} + +UUID::UUID(const std::string & str) +{ + ossp_uuid.import(str.c_str()); +} + +UUID +UUID::generate_random() +{ + UUID u; + u.ossp_uuid.make(UUID_MAKE_V5); + return u; +} + +bool +UUID::is_nil() const +{ + return ossp_uuid.isnil(); +} + +std::string +UUID::str() const +{ + char * s = ossp_uuid.string(); + std::string r(s); + free(s); + return r; +} + +void +UUID::operator=(const std::string & str) +{ + ossp_uuid.import(str.c_str()); +} + +bool +UUID::operator!=(const UUID & other) const +{ + return ossp_uuid != other.ossp_uuid; +} + +#endif + diff --git a/project2/uuid.h b/project2/uuid.h new file mode 100644 index 0000000..8cb22f3 --- /dev/null +++ b/project2/uuid.h @@ -0,0 +1,38 @@ +#ifndef UUID_H +#define UUID_H + +#include <iostream> +#include <boost/version.hpp> + +#if BOOST_VERSION < 104200 +//#if 1 +# define USINGOSSPUUID +# include <ossp/uuid++.hh> +#else +# define USINGBOOSTUUID +# include <boost/uuid/uuid.hpp> +#endif + +class UUID { + public: + UUID(); + UUID(const std::string &); + + static UUID generate_random(); + + bool operator!=(const UUID & other) const; + bool is_nil() const; + + void operator=(const std::string &); + std::string str() const; + + private: +#ifdef USINGBOOSTUUID + boost::uuids::uuid boost_uuid; +#endif +#ifdef USINGOSSPUUID + mutable uuid ossp_uuid; +#endif +}; + +#endif |