From cd60b3e44486712cecbdc983b178ef7e33e0d25d Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 31 May 2013 19:20:43 +0000 Subject: Remove the now pointless wrapper around UUIDs --- project2/Jamfile.jam | 1 - project2/cgi/cgiAppEngine.cpp | 13 ++-- project2/cgi/cgiAppEngine.h | 1 - project2/common/Jamfile.jam | 1 - project2/common/session.cpp | 7 +- project2/common/session.h | 8 +-- project2/common/sessionContainer.cpp | 2 +- project2/common/sessionContainer.h | 6 +- project2/console/consoleAppEngine.cpp | 3 +- project2/json/Jamfile.jam | 2 - project2/json/couchSession.cpp | 17 +++-- project2/uuid/Jamfile.jam | 12 ---- project2/uuid/uuid.cpp | 130 ---------------------------------- project2/uuid/uuid.h | 32 --------- project2/xml/Jamfile.jam | 2 - project2/xml/sessionXml.cpp | 9 +-- project2/xml/sessionXml.h | 2 +- 17 files changed, 38 insertions(+), 210 deletions(-) delete mode 100644 project2/uuid/Jamfile.jam delete mode 100644 project2/uuid/uuid.cpp delete mode 100644 project2/uuid/uuid.h diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 0930acc..b2bd49a 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -1,7 +1,6 @@ import package ; import feature : feature ; -feature uuid : boost ossp : propagated ; feature odbc : yes no : propagated ; feature pq : yes no : propagated ; feature mysql : yes no : propagated ; diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 799196d..9f72b31 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -10,9 +10,12 @@ #include "ostreamWrapper.h" #include "scopeObject.h" #include +#include +#include +#include const std::string SESSIONID = "sessionID"; -typedef UUID SIDKey; +typedef boost::uuids::uuid SIDKey; typedef std::string SValue; SimpleMessageException(UnknownDomain); @@ -24,10 +27,10 @@ CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e, std::ostrea outputCachingActive(false) { try { - cursession = sessionsContainer->GetSession(e->getCookieValue(SESSIONID)); + cursession = sessionsContainer->GetSession(boost::uuids::string_generator()(e->getCookieValue(SESSIONID))); } catch (const NoSuchCookie &) { - cursession = sessionsContainer->GetSession(UUID()); + cursession = sessionsContainer->GetSession(boost::uuids::uuid()); } } @@ -101,7 +104,7 @@ CgiApplicationEngine::process() const HttpHeaderPtr header = rs->getHeader(); if (!sessionEmpty || !cursession->Empty()) { sessionsContainer->SaveSession(cursession); - header->setCookie(cgicc::HTTPCookie(SESSIONID, cursession->ID().str(), "Session ID", + header->setCookie(cgicc::HTTPCookie(SESSIONID, boost::lexical_cast(cursession->ID()), "Session ID", _env->getServerName().substr(_env->getServerName().find(".")), env()->sessionTimeOut, "/", false)); } if (TransformSourcePtr ts = currentStage.get<2>()) { @@ -207,7 +210,7 @@ CgiApplicationEngine::addAppData(const MultiRowSetPresenter * p, OutputOptionsPt if (!outputCachingActive && (!cursession->Empty()) && (!o || o->Session())) { // Sessions variables p->addNewRowSet("session", env()->scriptNamespacePrefix); - p->addAttribute("id", cursession->ID().str()); + p->addAttribute("id", boost::lexical_cast(cursession->ID())); cursession->ForeachValue(boost::bind(&CgiApplicationEngine::addVarToPresenter, this, p, _1, _2)); p->finishRowSet(); } diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 69767be..f5f0e08 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -4,7 +4,6 @@ #include "appEngine.h" #include "task.h" #include "commonObjects.h" -#include "uuid.h" #include "taskHost.h" #include "viewHost.h" #include "transform.h" diff --git a/project2/common/Jamfile.jam b/project2/common/Jamfile.jam index bf61902..96f8137 100644 --- a/project2/common/Jamfile.jam +++ b/project2/common/Jamfile.jam @@ -21,7 +21,6 @@ lib p2common : boost_system boost_filesystem boost_date_time - ../uuid//p2uuid ../lib//p2lib : : . diff --git a/project2/common/session.cpp b/project2/common/session.cpp index f956d03..3fdd2af 100644 --- a/project2/common/session.cpp +++ b/project2/common/session.cpp @@ -2,12 +2,13 @@ #include "session.h" #include "safeMapFind.h" #include +#include Session::Session() { } -Session::Session(const UUID & sid) : +Session::Session(const boost::uuids::uuid & sid) : id(sid) { } @@ -60,11 +61,11 @@ Session::ForeachValue(const Session::SVH & svh) const } } -const UUID & +const boost::uuids::uuid & Session::ID() const { if (id.is_nil()) { - id = UUID::generate_random(); + id = boost::uuids::random_generator()(); } return id; } diff --git a/project2/common/session.h b/project2/common/session.h index e1f0b24..24b021e 100644 --- a/project2/common/session.h +++ b/project2/common/session.h @@ -1,7 +1,7 @@ #ifndef SESSION_H #define SESSION_H -#include +#include #include #include #include @@ -18,7 +18,7 @@ class Session : public virtual IntrusivePtrBase { typedef boost::function2 SVH; Session(); - Session(const UUID & id); + Session(const boost::uuids::uuid & id); virtual ~Session(); VariableType GetValue(const Glib::ustring & name) const; @@ -27,7 +27,7 @@ class Session : public virtual IntrusivePtrBase { void ClearValue(const Glib::ustring & name); bool Empty() const; time_t ExpiryTime() const; - const UUID & ID() const; + const boost::uuids::uuid & ID() const; protected: void ExpiryTime(time_t); @@ -37,7 +37,7 @@ class Session : public virtual IntrusivePtrBase { time_t expires; private: - mutable UUID id; + mutable boost::uuids::uuid id; }; typedef boost::intrusive_ptr SessionPtr; diff --git a/project2/common/sessionContainer.cpp b/project2/common/sessionContainer.cpp index 1366fc7..4347476 100644 --- a/project2/common/sessionContainer.cpp +++ b/project2/common/sessionContainer.cpp @@ -11,7 +11,7 @@ SessionContainer::~SessionContainer() } SessionPtr -SessionContainer::GetSession(const UUID & id) const +SessionContainer::GetSession(const boost::uuids::uuid & id) const { SessionPtr s; if (id.is_nil() || !(s = getSession(id))) { diff --git a/project2/common/sessionContainer.h b/project2/common/sessionContainer.h index 2a20085..75e5f02 100644 --- a/project2/common/sessionContainer.h +++ b/project2/common/sessionContainer.h @@ -1,7 +1,7 @@ #ifndef SESSIONCONTAINER_H #define SESSIONCONTAINER_H -#include "uuid.h" +#include #include "session.h" #include @@ -10,11 +10,11 @@ class SessionContainer : public IntrusivePtrBase { SessionContainer(); virtual ~SessionContainer() = 0; - SessionPtr GetSession(const UUID & sid) const; + SessionPtr GetSession(const boost::uuids::uuid & sid) const; virtual void SaveSession(SessionPtr sess) const = 0; protected: - virtual SessionPtr getSession(const UUID & sid) const = 0; + virtual SessionPtr getSession(const boost::uuids::uuid & sid) const = 0; }; typedef boost::intrusive_ptr SessionContainerPtr; typedef GenLoader SessionContainerLoader; diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp index 122de2e..114061d 100644 --- a/project2/console/consoleAppEngine.cpp +++ b/project2/console/consoleAppEngine.cpp @@ -10,6 +10,7 @@ #include "scriptLoader.h" #include #include +#include #include SimpleMessageException(UnknownPlatformAlias); @@ -21,7 +22,7 @@ ConsoleApplicationEngine::ConsoleApplicationEngine(const ConsoleEnvironment * en TaskHost(script->root()), ViewHost(script->root()), _env(env), - runtime(new Session(UUID::generate_random())), + runtime(new Session(boost::uuids::random_generator()())), presenter(new ConsolePresenter()) { } diff --git a/project2/json/Jamfile.jam b/project2/json/Jamfile.jam index 88bf92e..e9ae7b5 100644 --- a/project2/json/Jamfile.jam +++ b/project2/json/Jamfile.jam @@ -17,12 +17,10 @@ lib p2json : glibmm ../common//p2common ../lib//p2lib - ../uuid//p2uuid ../url//p2url boost_filesystem boost_date_time : : - ../uuid//p2uuid . ; diff --git a/project2/json/couchSession.cpp b/project2/json/couchSession.cpp index 2fe2ae6..ab7a7be 100644 --- a/project2/json/couchSession.cpp +++ b/project2/json/couchSession.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include "json.h" #include "safeMapFind.h" #include "conversion.h" @@ -19,7 +22,7 @@ class CouchSessionContainer : public SessionContainer { public: CouchSessionContainer() { } - virtual SessionPtr getSession(const UUID & uuid) const { + virtual SessionPtr getSession(const boost::uuids::uuid & uuid) const { try { json::Object obj = getSessionFromServer(uuid); if (boost::get(*safeMapLookup(obj, ExpiryKey)) > time(NULL)) { @@ -46,7 +49,7 @@ class CouchSessionContainer : public SessionContainer { c->setopt(CURLOPT_INFILESIZE_LARGE, (curl_off_t)out.size()); unsigned int off = 0; BOOST_FOREACH(const std::string & b, baseUrls) { - c->setopt(CURLOPT_URL, (b + s->ID().str()).c_str()); + c->setopt(CURLOPT_URL, (b + boost::lexical_cast(s->ID())).c_str()); try { c->performSend(boost::bind(send, &out, &off, _1, _2)); return; @@ -57,13 +60,13 @@ class CouchSessionContainer : public SessionContainer { throw CouchDBFailure(); } - json::Object getSessionFromServer(const UUID & uuid) const { + json::Object getSessionFromServer(const boost::uuids::uuid & uuid) const { CurlPtr c = new Curl(); c->setopt(CURLOPT_FAILONERROR, 1); Glib::ustring msg; BOOST_FOREACH(const std::string & b, baseUrls) { try { - c->setopt(CURLOPT_URL, (b + uuid.str()).c_str()); + c->setopt(CURLOPT_URL, (b + boost::lexical_cast(uuid)).c_str()); c->performRead(boost::bind(append, &msg, _1, _2)); json::Object o = json::parseObject(msg); return o; @@ -165,7 +168,7 @@ class CustomCouchSessionLoader : public SessionContainerLoader::For(*safeMapLookup(o, "rows"))) { json::Object rec = boost::get(*v); - UUID u = boost::get(*safeMapLookup(rec, "id")).raw(); + boost::uuids::uuid u = boost::uuids::string_generator()(boost::get(*safeMapLookup(rec, "id")).raw()); Glib::ustring & rev = boost::get(*safeMapLookup(rec, "value")); deleteSession(u, rev); } @@ -176,11 +179,11 @@ class CustomCouchSessionLoader : public SessionContainerLoader::Forsetopt(CURLOPT_CUSTOMREQUEST, "DELETE"); BOOST_FOREACH(const std::string & b, CouchSessionContainer::baseUrls) { - c->setopt(CURLOPT_URL, (b + sid.str() + "?rev=" + rev).c_str()); + c->setopt(CURLOPT_URL, (b + boost::lexical_cast(sid) + "?rev=" + rev).c_str()); c->performRead(boost::bind(discard, _2)); return; } diff --git a/project2/uuid/Jamfile.jam b/project2/uuid/Jamfile.jam deleted file mode 100644 index a0d160b..0000000 --- a/project2/uuid/Jamfile.jam +++ /dev/null @@ -1,12 +0,0 @@ -lib osspuuid : : ossp-uuid++ ; - -lib p2uuid : - uuid.cpp - : - ossp:OSSP_UUID - boost:BOOST_UUID - ossp:osspuuid - : : - . - ; - diff --git a/project2/uuid/uuid.cpp b/project2/uuid/uuid.cpp deleted file mode 100644 index 0d864b5..0000000 --- a/project2/uuid/uuid.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#ifdef BOOST_UUID -# include -# if BOOST_VERSION < 104200 -# error "Boost UUIDs required v1.42 or above" -# else -# include -# endif -#include -#include -#include -#define uuid_impl boost::uuids::uuid -#include "uuid.h" - -UUID::UUID() -{ - _uuid = new boost::uuids::uuid(boost::uuids::nil_generator()()); -} - -UUID::UUID(const UUID & other) -{ - _uuid = new boost::uuids::uuid(*other._uuid); -} - -UUID::UUID(const std::string & str) -{ - _uuid = new boost::uuids::uuid(boost::uuids::string_generator()(str)); -} - -UUID -UUID::generate_random() -{ - return UUID(new boost::uuids::uuid(boost::uuids::random_generator()())); -} - -bool -UUID::is_nil() const -{ - return _uuid->is_nil(); -} - -std::string -UUID::str() const -{ - return boost::lexical_cast(*_uuid); -} - -UUID & -UUID::operator=(const std::string & str) -{ - *_uuid = boost::uuids::string_generator()(str); - return *this; -} - -#endif - -#ifdef OSSP_UUID -# include -#define uuid_impl uuid -#include "uuid.h" - -UUID::UUID() -{ - _uuid = new uuid(); -} - -UUID::UUID(const UUID & other) -{ - _uuid = new uuid(*other._uuid); -} - -UUID::UUID(const std::string & str) -{ - _uuid = new uuid(); - _uuid->import(str.c_str()); -} - -UUID -UUID::generate_random() -{ - return UUID(_uuid->make(UUID_MAKE_V4)); -} - -bool -UUID::is_nil() const -{ - return _uuid->isnil(); -} - -std::string -UUID::str() const -{ - char * s = _uuid->string(); - std::string r(s); - free(s); - return r; -} - -UUID & -UUID::operator=(const std::string & str) -{ - _uuid->import(str.c_str()); - return *this; -} - -#endif - -// Shared implementation -UUID::~UUID() -{ - delete _uuid; -} - -UUID::UUID(uuid_impl * u) -{ - _uuid = u; -} - -bool -UUID::operator!=(const UUID & other) const -{ - return *_uuid != *other._uuid; -} - -UUID & -UUID::operator=(const UUID & other) -{ - *_uuid = *other._uuid; - return *this; -} - diff --git a/project2/uuid/uuid.h b/project2/uuid/uuid.h deleted file mode 100644 index 76d812d..0000000 --- a/project2/uuid/uuid.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef UUID_H -#define UUID_H - -#include - -#ifndef uuid_impl -class uuid_impl; -#endif - -class UUID { - public: - UUID(); - ~UUID(); - UUID(uuid_impl * _uuid); - UUID(const UUID &); - UUID(const std::string &); - - static UUID generate_random(); - - UUID & operator=(const UUID & other); - UUID & operator=(const std::string &); - - bool operator!=(const UUID & other) const; - bool is_nil() const; - - std::string str() const; - - private: - uuid_impl * _uuid; -}; - -#endif diff --git a/project2/xml/Jamfile.jam b/project2/xml/Jamfile.jam index 8addab8..2c21642 100644 --- a/project2/xml/Jamfile.jam +++ b/project2/xml/Jamfile.jam @@ -19,14 +19,12 @@ lib p2xml : ../libmisc libxmlpp ../common//p2common - ../uuid//p2uuid ../url//p2url ../lib//p2lib libxslt boost_filesystem boost_date_time : : - ../uuid//p2uuid . ; diff --git a/project2/xml/sessionXml.cpp b/project2/xml/sessionXml.cpp index 7e2644c..85ad6bd 100644 --- a/project2/xml/sessionXml.cpp +++ b/project2/xml/sessionXml.cpp @@ -1,6 +1,7 @@ #include "pch.hpp" #include "sessionXml.h" -#include "uuid.h" +#include +#include #include #include #include @@ -71,15 +72,15 @@ SessionContainerXml::SaveSession(SessionPtr currentSession) const xmlpp::Element * sess = d.create_root_node("session"); sess->set_attribute("expires", boost::lexical_cast(currentSession->ExpiryTime())); currentSession->ForeachValue(boost::bind(appendToXmlNode, sess, _1, _2)); - boost::filesystem::path p = xmlDir / currentSession->ID().str(); + boost::filesystem::path p = xmlDir / boost::lexical_cast(currentSession->ID()); d.write_to_file(p.string()); } SessionPtr -SessionContainerXml::getSession(const UUID & sid) const +SessionContainerXml::getSession(const boost::uuids::uuid & sid) const { try { - boost::filesystem::path p = xmlDir / sid.str(); + boost::filesystem::path p = xmlDir / boost::lexical_cast(sid); xmlpp::DomParser session(p.string()); xmlpp::Element * sess = session.get_document()->get_root_node(); time_t expires = boost::lexical_cast(sess->get_attribute_value("expires")); diff --git a/project2/xml/sessionXml.h b/project2/xml/sessionXml.h index 0ce502a..98123f6 100644 --- a/project2/xml/sessionXml.h +++ b/project2/xml/sessionXml.h @@ -11,7 +11,7 @@ class SessionContainerXml : public SessionContainer { void SaveSession(SessionPtr) const; protected: - SessionPtr getSession(const UUID & sid) const; + SessionPtr getSession(const boost::uuids::uuid & sid) const; private: // Configurables -- cgit v1.2.3