From f2f1d5b1da4f985bcbb0c075cf42efcacecae2a6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 3 Jul 2009 17:23:37 +0200 Subject: =?UTF-8?q?Timestamps=20f=C3=BCr=20Benutzercache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Backends/NetworkUserBackend.cpp | 193 +++++++++++++++++++++++------ src/Common/Backends/NetworkUserBackend.h | 44 ++++--- 2 files changed, 179 insertions(+), 58 deletions(-) (limited to 'src/Common/Backends') diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp index f75783c..27f65f5 100644 --- a/src/Common/Backends/NetworkUserBackend.cpp +++ b/src/Common/Backends/NetworkUserBackend.cpp @@ -20,15 +20,30 @@ #include "NetworkUserBackend.h" #include "../RequestManager.h" +#include + namespace Mad { namespace Common { namespace Backends { +void NetworkUserBackend::SimpleUserRequest::sendRequest() { + Common::XmlPacket packet; + packet.setType(type); + + if(!timestamp.is_not_a_date_time()) + packet.set("timestamp", boost::posix_time::to_iso_string(timestamp)); + + sendPacket(packet); +} + void NetworkUserBackend::IdUserRequest::sendRequest() { Common::XmlPacket packet; packet.setType(type); packet.set(idType, id); + if(!timestamp.is_not_a_date_time()) + packet.set("timestamp", boost::posix_time::to_iso_string(timestamp)); + sendPacket(packet); } @@ -37,22 +52,33 @@ void NetworkUserBackend::NameUserRequest::sendRequest() { packet.setType(type); packet.set("name", name); + if(!timestamp.is_not_a_date_time()) + packet.set("timestamp", boost::posix_time::to_iso_string(timestamp)); + sendPacket(packet); } -boost::shared_ptr > NetworkUserBackend::getUserList() throw(Core::Exception) { - boost::shared_ptr request(new SimpleUserRequest(application, "ListUsers")); +boost::shared_ptr > NetworkUserBackend::getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception) { + boost::shared_ptr request(new SimpleUserRequest(application, "ListUsers", timestamp)); application->getRequestManager()->sendRequest(connection, request); + request->wait(); std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; - boost::shared_ptr > userList(new std::map); + if(timestamp) { + try { + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + } + catch(...) {} + } const XmlPacket::List *users = result.first->getList("users"); if(users) { + boost::shared_ptr > userList(new std::map); + for(XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user) { UserInfo userInfo(user->get("uid"), user->get("username")); userInfo.setGid(user->get("gid")); @@ -60,13 +86,15 @@ boost::shared_ptr > NetworkUserBackend:: userList->insert(std::make_pair(userInfo.getUid(), userInfo)); } + + return userList; } - return userList; + return boost::shared_ptr >(); } -boost::shared_ptr NetworkUserBackend::getUserInfo(unsigned long uid) throw(Core::Exception) { - boost::shared_ptr request(new IdUserRequest(application, "GetUserInfo", "uid", uid)); +boost::shared_ptr NetworkUserBackend::getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception) { + boost::shared_ptr request(new IdUserRequest(application, "GetUserInfo", "uid", uid, timestamp)); application->getRequestManager()->sendRequest(connection, request); request->wait(); @@ -74,15 +102,29 @@ boost::shared_ptr NetworkUserBackend::getUserInfo(unsigned long if(!result.first || result.second) throw result.second; - boost::shared_ptr userInfo(new UserInfo(result.first->get("uid"), result.first->get("username"))); - userInfo->setGid(result.first->get("gid")); - userInfo->setFullName(result.first->get("fullName")); + if(timestamp) { + try { + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + } + catch(...) {} + } + + unsigned long uid2 = result.first->get("uid"); - return userInfo; + if(uid2) { + boost::shared_ptr userInfo(new UserInfo(uid2, result.first->get("username"))); + + userInfo->setGid(result.first->get("gid")); + userInfo->setFullName(result.first->get("fullName")); + + return userInfo; + } + + return boost::shared_ptr(); } -boost::shared_ptr NetworkUserBackend::getUserInfoByName(const std::string &name) throw(Core::Exception) { - boost::shared_ptr request(new NameUserRequest(application, "GetUserInfo", name)); +boost::shared_ptr NetworkUserBackend::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { + boost::shared_ptr request(new NameUserRequest(application, "GetUserInfo", name, timestamp)); application->getRequestManager()->sendRequest(connection, request); request->wait(); @@ -90,15 +132,29 @@ boost::shared_ptr NetworkUserBackend::getUserInfoByName(const st if(!result.first || result.second) throw result.second; - boost::shared_ptr userInfo(new UserInfo(result.first->get("uid"), result.first->get("username"))); - userInfo->setGid(result.first->get("gid")); - userInfo->setFullName(result.first->get("fullName")); + if(timestamp) { + try { + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + } + catch(...) {} + } + + unsigned long uid = result.first->get("uid"); + + if(uid) { + boost::shared_ptr userInfo(new UserInfo(uid, result.first->get("username"))); + + userInfo->setGid(result.first->get("gid")); + userInfo->setFullName(result.first->get("fullName")); - return userInfo; + return userInfo; + } + + return boost::shared_ptr(); } -boost::shared_ptr > NetworkUserBackend::getUserGroupList(unsigned long uid) throw(Core::Exception) { - boost::shared_ptr request(new IdUserRequest(application, "ListUserGroups", "uid", uid)); +boost::shared_ptr > NetworkUserBackend::getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception) { + boost::shared_ptr request(new IdUserRequest(application, "ListUserGroups", "uid", uid, timestamp)); application->getRequestManager()->sendRequest(connection, request); request->wait(); @@ -106,19 +162,29 @@ boost::shared_ptr > NetworkUserBackend::getUserGro if(!result.first || result.second) throw result.second; - boost::shared_ptr > groupList(new std::set); + if(timestamp) { + try { + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + } + catch(...) {} + } const XmlPacket::List *groups = result.first->getList("groups"); + if(groups) { + boost::shared_ptr > groupList(new std::set); + for(XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group) groupList->insert(group->get("gid")); + + return groupList; } - return groupList; + return boost::shared_ptr >(); } -boost::shared_ptr > NetworkUserBackend::getGroupList() throw(Core::Exception) { - boost::shared_ptr request(new SimpleUserRequest(application, "ListGroups")); +boost::shared_ptr > NetworkUserBackend::getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) { + boost::shared_ptr request(new SimpleUserRequest(application, "ListGroups", timestamp)); application->getRequestManager()->sendRequest(connection, request); request->wait(); @@ -126,21 +192,30 @@ boost::shared_ptr > NetworkUserBackend: if(!result.first || result.second) throw result.second; - boost::shared_ptr > groupList(new std::map); + if(timestamp) { + try { + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + } + catch(...) {} + } const XmlPacket::List *groups = result.first->getList("groups"); if(groups) { + boost::shared_ptr > groupList(new std::map); + for(XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group) { GroupInfo groupInfo(group->get("gid"), group->get("name")); groupList->insert(std::make_pair(groupInfo.getGid(), groupInfo)); } + + return groupList; } - return groupList; + return boost::shared_ptr >(); } -boost::shared_ptr NetworkUserBackend::getGroupInfo(unsigned long gid) throw(Core::Exception) { - boost::shared_ptr request(new IdUserRequest(application, "GetGroupInfo", "gid", gid)); +boost::shared_ptr NetworkUserBackend::getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception) { + boost::shared_ptr request(new IdUserRequest(application, "GetGroupInfo", "gid", gid, timestamp)); application->getRequestManager()->sendRequest(connection, request); request->wait(); @@ -148,13 +223,23 @@ boost::shared_ptr NetworkUserBackend::getGroupInfo(unsigned lon if(!result.first || result.second) throw result.second; - boost::shared_ptr groupInfo(new GroupInfo(result.first->get("gid"), result.first->get("name"))); + if(timestamp) { + try { + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + } + catch(...) {} + } + + unsigned long gid2 = result.first->get("gid"); - return groupInfo; + if(gid2) + return boost::shared_ptr(new GroupInfo(gid2, result.first->get("name"))); + + return boost::shared_ptr(); } -boost::shared_ptr NetworkUserBackend::getGroupInfoByName(const std::string &name) throw(Core::Exception) { - boost::shared_ptr request(new NameUserRequest(application, "GetGroupInfo", name)); +boost::shared_ptr NetworkUserBackend::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { + boost::shared_ptr request(new NameUserRequest(application, "GetGroupInfo", name, timestamp)); application->getRequestManager()->sendRequest(connection, request); request->wait(); @@ -162,13 +247,23 @@ boost::shared_ptr NetworkUserBackend::getGroupInfoByName(const if(!result.first || result.second) throw result.second; - boost::shared_ptr groupInfo(new GroupInfo(result.first->get("gid"), result.first->get("name"))); + if(timestamp) { + try { + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + } + catch(...) {} + } + + unsigned long gid = result.first->get("gid"); - return groupInfo; + if(gid) + return boost::shared_ptr(new GroupInfo(gid, result.first->get("name"))); + + return boost::shared_ptr(); } -boost::shared_ptr > NetworkUserBackend::getGroupUserList(unsigned long gid) throw(Core::Exception) { - boost::shared_ptr request(new IdUserRequest(application, "ListGroupUsers", "gid", gid)); +boost::shared_ptr > NetworkUserBackend::getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception) { + boost::shared_ptr request(new IdUserRequest(application, "ListGroupUsers", "gid", gid, timestamp)); application->getRequestManager()->sendRequest(connection, request); request->wait(); @@ -176,20 +271,29 @@ boost::shared_ptr > NetworkUserBackend::getGroupUs if(!result.first || result.second) throw result.second; - boost::shared_ptr > userList(new std::set); + if(timestamp) { + try { + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + } + catch(...) {} + } const XmlPacket::List *users = result.first->getList("users"); if(users) { + boost::shared_ptr > userList(new std::set); + for(XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user) { userList->insert(user->get("uid")); } + + return userList; } - return userList; + return boost::shared_ptr >(); } -boost::shared_ptr > NetworkUserBackend::getFullUserGroupList() throw(Core::Exception) { - boost::shared_ptr request(new SimpleUserRequest(application, "GetFullUserGroupList")); +boost::shared_ptr > NetworkUserBackend::getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) { + boost::shared_ptr request(new SimpleUserRequest(application, "GetFullUserGroupList", timestamp)); application->getRequestManager()->sendRequest(connection, request); request->wait(); @@ -197,15 +301,24 @@ boost::shared_ptr > NetworkUse if(!result.first || result.second) throw result.second; - boost::shared_ptr > ret(new std::multimap); + if(timestamp) { + try { + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + } + catch(...) {} + } const XmlPacket::List *list = result.first->getList("userGroupList"); if(list) { + boost::shared_ptr > ret(new std::multimap); + for(XmlPacket::List::const_iterator entry = list->begin(); entry != list->end(); ++entry) ret->insert(std::make_pair(entry->get("uid"), entry->get("gid"))); + + return ret; } - return ret; + return boost::shared_ptr >(); } diff --git a/src/Common/Backends/NetworkUserBackend.h b/src/Common/Backends/NetworkUserBackend.h index 66be909..8faa8e3 100644 --- a/src/Common/Backends/NetworkUserBackend.h +++ b/src/Common/Backends/NetworkUserBackend.h @@ -21,7 +21,7 @@ #define MAD_COMMON_BACKENDS_NETWORKUSERBACKEND_H_ #include "../UserBackend.h" -#include "../Requests/SimpleRequest.h" +#include "../Request.h" namespace Mad { namespace Common { @@ -29,9 +29,17 @@ namespace Backends { class NetworkUserBackend : public UserBackend { private: - class SimpleUserRequest : public Requests::SimpleRequest { + class SimpleUserRequest : public Request { + private: + std::string type; + boost::posix_time::ptime timestamp; + + protected: + virtual void sendRequest(); + public: - SimpleUserRequest(Application *application, const std::string &type) : SimpleRequest(application, type) {} + SimpleUserRequest(Application *application, const std::string &type0, boost::posix_time::ptime *timestamp0) + : Request(application), type(type0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {} }; class IdUserRequest : public Request { @@ -39,45 +47,45 @@ class NetworkUserBackend : public UserBackend { std::string type; std::string idType; unsigned long id; - + boost::posix_time::ptime timestamp; protected: virtual void sendRequest(); public: - IdUserRequest(Application *application, const std::string &type0, const std::string &idType0, unsigned long id0) - : Request(application), type(type0), idType(idType0), id(id0) {} + IdUserRequest(Application *application, const std::string &type0, const std::string &idType0, unsigned long id0, boost::posix_time::ptime *timestamp0) + : Request(application), type(type0), idType(idType0), id(id0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {} }; class NameUserRequest : public Request { private: std::string type; std::string name; - + boost::posix_time::ptime timestamp; protected: virtual void sendRequest(); public: - NameUserRequest(Application *application, const std::string &type0, const std::string &name0) - : Request(application), type(type0), name(name0) {} + NameUserRequest(Application *application, const std::string &type0, const std::string &name0, boost::posix_time::ptime *timestamp0) + : Request(application), type(type0), name(name0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {} }; Application *application; Connection *connection; protected: - virtual boost::shared_ptr > getUserList() throw(Core::Exception); - virtual boost::shared_ptr getUserInfo(unsigned long uid) throw(Core::Exception); - virtual boost::shared_ptr getUserInfoByName(const std::string &name) throw(Core::Exception); - virtual boost::shared_ptr > getUserGroupList(unsigned long uid) throw(Core::Exception); + virtual boost::shared_ptr > getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr > getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr > getGroupList() throw(Core::Exception); - virtual boost::shared_ptr getGroupInfo(unsigned long gid) throw(Core::Exception); - virtual boost::shared_ptr getGroupInfoByName(const std::string &name) throw(Core::Exception); - virtual boost::shared_ptr > getGroupUserList(unsigned long gid) throw(Core::Exception); + virtual boost::shared_ptr > getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr > getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr > getFullUserGroupList() throw(Core::Exception); + virtual boost::shared_ptr > getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); //virtual void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); //virtual void addUser(const UserInfo &userInfo) throw(Core::Exception); -- cgit v1.2.3