diff options
author | randomdan <randomdan@localhost> | 2013-05-31 19:20:43 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2013-05-31 19:20:43 +0000 |
commit | cd60b3e44486712cecbdc983b178ef7e33e0d25d (patch) | |
tree | f395b5fe2763e1daae60fff1ef62e833f312c74d | |
parent | Minor tidy up and localise (diff) | |
download | project2-cd60b3e44486712cecbdc983b178ef7e33e0d25d.tar.bz2 project2-cd60b3e44486712cecbdc983b178ef7e33e0d25d.tar.xz project2-cd60b3e44486712cecbdc983b178ef7e33e0d25d.zip |
Remove the now pointless wrapper around UUIDs
-rw-r--r-- | project2/Jamfile.jam | 1 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 13 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.h | 1 | ||||
-rw-r--r-- | project2/common/Jamfile.jam | 1 | ||||
-rw-r--r-- | project2/common/session.cpp | 7 | ||||
-rw-r--r-- | project2/common/session.h | 8 | ||||
-rw-r--r-- | project2/common/sessionContainer.cpp | 2 | ||||
-rw-r--r-- | project2/common/sessionContainer.h | 6 | ||||
-rw-r--r-- | project2/console/consoleAppEngine.cpp | 3 | ||||
-rw-r--r-- | project2/json/Jamfile.jam | 2 | ||||
-rw-r--r-- | project2/json/couchSession.cpp | 17 | ||||
-rw-r--r-- | project2/uuid/Jamfile.jam | 12 | ||||
-rw-r--r-- | project2/uuid/uuid.cpp | 130 | ||||
-rw-r--r-- | project2/uuid/uuid.h | 32 | ||||
-rw-r--r-- | project2/xml/Jamfile.jam | 2 | ||||
-rw-r--r-- | project2/xml/sessionXml.cpp | 9 | ||||
-rw-r--r-- | project2/xml/sessionXml.h | 2 |
17 files changed, 38 insertions, 210 deletions
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 <boost/date_time/microsec_time_clock.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/uuid_generators.hpp> +#include <boost/lexical_cast.hpp> 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<std::string>(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<Glib::ustring>(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 : <library>boost_system <library>boost_filesystem <library>boost_date_time - <library>../uuid//p2uuid <library>../lib//p2lib : : <include>. 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 <boost/foreach.hpp> +#include <boost/uuid/uuid_generators.hpp> 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 <uuid.h> +#include <boost/uuid/uuid.hpp> #include <map> #include <glibmm/ustring.h> #include <boost/intrusive_ptr.hpp> @@ -18,7 +18,7 @@ class Session : public virtual IntrusivePtrBase { typedef boost::function2<void, const Glib::ustring &, const VariableType &> 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<Session> 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 <boost/uuid/uuid.hpp> #include "session.h" #include <intrusivePtrBase.h> @@ -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<SessionContainer> SessionContainerPtr; typedef GenLoader<SessionContainer> 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 <boost/foreach.hpp> #include <boost/bind.hpp> +#include <boost/uuid/uuid_generators.hpp> #include <iostream> 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 : <library>glibmm <library>../common//p2common <library>../lib//p2lib - <library>../uuid//p2uuid <library>../url//p2url <library>boost_filesystem <library>boost_date_time : : - <library>../uuid//p2uuid <include>. ; 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 <sessionContainer.h> #include <boost/bind.hpp> #include <boost/foreach.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/uuid_generators.hpp> #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<json::Number>(*safeMapLookup<Session::VariableNotFound>(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<std::string>(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<std::string>(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<CouchSession json::Object o = json::parseObject(msg); BOOST_FOREACH(const json::Array::value_type & v, boost::get<json::Array>(*safeMapLookup<ParamNotFound>(o, "rows"))) { json::Object rec = boost::get<json::Object>(*v); - UUID u = boost::get<json::String>(*safeMapLookup<ParamNotFound>(rec, "id")).raw(); + boost::uuids::uuid u = boost::uuids::string_generator()(boost::get<json::String>(*safeMapLookup<ParamNotFound>(rec, "id")).raw()); Glib::ustring & rev = boost::get<json::String>(*safeMapLookup<ParamNotFound>(rec, "value")); deleteSession(u, rev); } @@ -176,11 +179,11 @@ class CustomCouchSessionLoader : public SessionContainerLoader::For<CouchSession } } - void deleteSession(const UUID & sid, const Glib::ustring & rev) const { + void deleteSession(const boost::uuids::uuid & sid, const Glib::ustring & rev) const { CurlPtr c = new Curl(); c->setopt(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<std::string>(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 : : <name>ossp-uuid++ ; - -lib p2uuid : - uuid.cpp - : - <uuid>ossp:<define>OSSP_UUID - <uuid>boost:<define>BOOST_UUID - <uuid>ossp:<library>osspuuid - : : - <include>. - ; - 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 <boost/version.hpp> -# if BOOST_VERSION < 104200 -# error "Boost UUIDs required v1.42 or above" -# else -# include <boost/uuid/uuid.hpp> -# endif -#include <boost/lexical_cast.hpp> -#include <boost/uuid/uuid_io.hpp> -#include <boost/uuid/uuid_generators.hpp> -#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<std::string>(*_uuid); -} - -UUID & -UUID::operator=(const std::string & str) -{ - *_uuid = boost::uuids::string_generator()(str); - return *this; -} - -#endif - -#ifdef OSSP_UUID -# include <ossp/uuid++.hh> -#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 <string> - -#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 : <include>../libmisc <library>libxmlpp <library>../common//p2common - <library>../uuid//p2uuid <library>../url//p2url <library>../lib//p2lib <library>libxslt <library>boost_filesystem <library>boost_date_time : : - <library>../uuid//p2uuid <include>. ; 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 <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> #include <libxml++/nodes/element.h> #include <libxml++/parsers/domparser.h> #include <boost/bind.hpp> @@ -71,15 +72,15 @@ SessionContainerXml::SaveSession(SessionPtr currentSession) const xmlpp::Element * sess = d.create_root_node("session"); sess->set_attribute("expires", boost::lexical_cast<Glib::ustring>(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<std::string>(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<std::string>(sid); xmlpp::DomParser session(p.string()); xmlpp::Element * sess = session.get_document()->get_root_node(); time_t expires = boost::lexical_cast<time_t>(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 |