summaryrefslogtreecommitdiffstats
path: root/src/Common/Backends
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-07-03 17:23:37 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-07-03 17:23:37 +0200
commitf2f1d5b1da4f985bcbb0c075cf42efcacecae2a6 (patch)
tree8ffe90bf55fb9bb7d4408f56b78b8b5ab9153153 /src/Common/Backends
parentb014b0c0c29553ed9a7a38278f5433d28b0f8751 (diff)
downloadmad-f2f1d5b1da4f985bcbb0c075cf42efcacecae2a6.tar
mad-f2f1d5b1da4f985bcbb0c075cf42efcacecae2a6.zip
Timestamps für Benutzercache
Diffstat (limited to 'src/Common/Backends')
-rw-r--r--src/Common/Backends/NetworkUserBackend.cpp193
-rw-r--r--src/Common/Backends/NetworkUserBackend.h44
2 files changed, 179 insertions, 58 deletions
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 <boost/date_time/posix_time/posix_time.hpp>
+
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<const std::map<unsigned long, UserInfo> > NetworkUserBackend::getUserList() throw(Core::Exception) {
- boost::shared_ptr<SimpleUserRequest> request(new SimpleUserRequest(application, "ListUsers"));
+boost::shared_ptr<const std::map<unsigned long, UserInfo> > NetworkUserBackend::getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+ boost::shared_ptr<SimpleUserRequest> request(new SimpleUserRequest(application, "ListUsers", timestamp));
application->getRequestManager()->sendRequest(connection, request);
+
request->wait();
std::pair<boost::shared_ptr<const XmlPacket>, Core::Exception> result = request->getResult();
if(!result.first || result.second)
throw result.second;
- boost::shared_ptr<std::map<unsigned long, UserInfo> > userList(new std::map<unsigned long, UserInfo>);
+ if(timestamp) {
+ try {
+ *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp"));
+ }
+ catch(...) {}
+ }
const XmlPacket::List *users = result.first->getList("users");
if(users) {
+ boost::shared_ptr<std::map<unsigned long, UserInfo> > userList(new std::map<unsigned long, UserInfo>);
+
for(XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user) {
UserInfo userInfo(user->get<unsigned long>("uid"), user->get<const std::string&>("username"));
userInfo.setGid(user->get<unsigned long>("gid"));
@@ -60,13 +86,15 @@ boost::shared_ptr<const std::map<unsigned long, UserInfo> > NetworkUserBackend::
userList->insert(std::make_pair(userInfo.getUid(), userInfo));
}
+
+ return userList;
}
- return userList;
+ return boost::shared_ptr<const std::map<unsigned long, UserInfo> >();
}
-boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfo(unsigned long uid) throw(Core::Exception) {
- boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "GetUserInfo", "uid", uid));
+boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+ boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "GetUserInfo", "uid", uid, timestamp));
application->getRequestManager()->sendRequest(connection, request);
request->wait();
@@ -74,15 +102,29 @@ boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfo(unsigned long
if(!result.first || result.second)
throw result.second;
- boost::shared_ptr<UserInfo> userInfo(new UserInfo(result.first->get<unsigned long>("uid"), result.first->get<const std::string&>("username")));
- userInfo->setGid(result.first->get<unsigned long>("gid"));
- userInfo->setFullName(result.first->get<const std::string&>("fullName"));
+ if(timestamp) {
+ try {
+ *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp"));
+ }
+ catch(...) {}
+ }
+
+ unsigned long uid2 = result.first->get<unsigned long>("uid");
- return userInfo;
+ if(uid2) {
+ boost::shared_ptr<UserInfo> userInfo(new UserInfo(uid2, result.first->get<const std::string&>("username")));
+
+ userInfo->setGid(result.first->get<unsigned long>("gid"));
+ userInfo->setFullName(result.first->get<const std::string&>("fullName"));
+
+ return userInfo;
+ }
+
+ return boost::shared_ptr<const UserInfo>();
}
-boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfoByName(const std::string &name) throw(Core::Exception) {
- boost::shared_ptr<NameUserRequest> request(new NameUserRequest(application, "GetUserInfo", name));
+boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+ boost::shared_ptr<NameUserRequest> request(new NameUserRequest(application, "GetUserInfo", name, timestamp));
application->getRequestManager()->sendRequest(connection, request);
request->wait();
@@ -90,15 +132,29 @@ boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfoByName(const st
if(!result.first || result.second)
throw result.second;
- boost::shared_ptr<UserInfo> userInfo(new UserInfo(result.first->get<unsigned long>("uid"), result.first->get<const std::string&>("username")));
- userInfo->setGid(result.first->get<unsigned long>("gid"));
- userInfo->setFullName(result.first->get<const std::string&>("fullName"));
+ if(timestamp) {
+ try {
+ *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp"));
+ }
+ catch(...) {}
+ }
+
+ unsigned long uid = result.first->get<unsigned long>("uid");
+
+ if(uid) {
+ boost::shared_ptr<UserInfo> userInfo(new UserInfo(uid, result.first->get<const std::string&>("username")));
+
+ userInfo->setGid(result.first->get<unsigned long>("gid"));
+ userInfo->setFullName(result.first->get<const std::string&>("fullName"));
- return userInfo;
+ return userInfo;
+ }
+
+ return boost::shared_ptr<const UserInfo>();
}
-boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getUserGroupList(unsigned long uid) throw(Core::Exception) {
- boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "ListUserGroups", "uid", uid));
+boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+ boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "ListUserGroups", "uid", uid, timestamp));
application->getRequestManager()->sendRequest(connection, request);
request->wait();
@@ -106,19 +162,29 @@ boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getUserGro
if(!result.first || result.second)
throw result.second;
- boost::shared_ptr<std::set<unsigned long> > groupList(new std::set<unsigned long>);
+ if(timestamp) {
+ try {
+ *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp"));
+ }
+ catch(...) {}
+ }
const XmlPacket::List *groups = result.first->getList("groups");
+
if(groups) {
+ boost::shared_ptr<std::set<unsigned long> > groupList(new std::set<unsigned long>);
+
for(XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group)
groupList->insert(group->get<unsigned long>("gid"));
+
+ return groupList;
}
- return groupList;
+ return boost::shared_ptr<const std::set<unsigned long> >();
}
-boost::shared_ptr<const std::map<unsigned long, GroupInfo> > NetworkUserBackend::getGroupList() throw(Core::Exception) {
- boost::shared_ptr<SimpleUserRequest> request(new SimpleUserRequest(application, "ListGroups"));
+boost::shared_ptr<const std::map<unsigned long, GroupInfo> > NetworkUserBackend::getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+ boost::shared_ptr<SimpleUserRequest> request(new SimpleUserRequest(application, "ListGroups", timestamp));
application->getRequestManager()->sendRequest(connection, request);
request->wait();
@@ -126,21 +192,30 @@ boost::shared_ptr<const std::map<unsigned long, GroupInfo> > NetworkUserBackend:
if(!result.first || result.second)
throw result.second;
- boost::shared_ptr<std::map<unsigned long, GroupInfo> > groupList(new std::map<unsigned long, GroupInfo>);
+ if(timestamp) {
+ try {
+ *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp"));
+ }
+ catch(...) {}
+ }
const XmlPacket::List *groups = result.first->getList("groups");
if(groups) {
+ boost::shared_ptr<std::map<unsigned long, GroupInfo> > groupList(new std::map<unsigned long, GroupInfo>);
+
for(XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group) {
GroupInfo groupInfo(group->get<unsigned long>("gid"), group->get<const std::string&>("name"));
groupList->insert(std::make_pair(groupInfo.getGid(), groupInfo));
}
+
+ return groupList;
}
- return groupList;
+ return boost::shared_ptr<const std::map<unsigned long, GroupInfo> >();
}
-boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfo(unsigned long gid) throw(Core::Exception) {
- boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "GetGroupInfo", "gid", gid));
+boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+ boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "GetGroupInfo", "gid", gid, timestamp));
application->getRequestManager()->sendRequest(connection, request);
request->wait();
@@ -148,13 +223,23 @@ boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfo(unsigned lon
if(!result.first || result.second)
throw result.second;
- boost::shared_ptr<GroupInfo> groupInfo(new GroupInfo(result.first->get<unsigned long>("gid"), result.first->get<const std::string&>("name")));
+ if(timestamp) {
+ try {
+ *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp"));
+ }
+ catch(...) {}
+ }
+
+ unsigned long gid2 = result.first->get<unsigned long>("gid");
- return groupInfo;
+ if(gid2)
+ return boost::shared_ptr<GroupInfo>(new GroupInfo(gid2, result.first->get<const std::string&>("name")));
+
+ return boost::shared_ptr<const GroupInfo>();
}
-boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfoByName(const std::string &name) throw(Core::Exception) {
- boost::shared_ptr<NameUserRequest> request(new NameUserRequest(application, "GetGroupInfo", name));
+boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+ boost::shared_ptr<NameUserRequest> request(new NameUserRequest(application, "GetGroupInfo", name, timestamp));
application->getRequestManager()->sendRequest(connection, request);
request->wait();
@@ -162,13 +247,23 @@ boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfoByName(const
if(!result.first || result.second)
throw result.second;
- boost::shared_ptr<GroupInfo> groupInfo(new GroupInfo(result.first->get<unsigned long>("gid"), result.first->get<const std::string&>("name")));
+ if(timestamp) {
+ try {
+ *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp"));
+ }
+ catch(...) {}
+ }
+
+ unsigned long gid = result.first->get<unsigned long>("gid");
- return groupInfo;
+ if(gid)
+ return boost::shared_ptr<GroupInfo>(new GroupInfo(gid, result.first->get<const std::string&>("name")));
+
+ return boost::shared_ptr<const GroupInfo>();
}
-boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getGroupUserList(unsigned long gid) throw(Core::Exception) {
- boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "ListGroupUsers", "gid", gid));
+boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+ boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "ListGroupUsers", "gid", gid, timestamp));
application->getRequestManager()->sendRequest(connection, request);
request->wait();
@@ -176,20 +271,29 @@ boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getGroupUs
if(!result.first || result.second)
throw result.second;
- boost::shared_ptr<std::set<unsigned long> > userList(new std::set<unsigned long>);
+ if(timestamp) {
+ try {
+ *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp"));
+ }
+ catch(...) {}
+ }
const XmlPacket::List *users = result.first->getList("users");
if(users) {
+ boost::shared_ptr<std::set<unsigned long> > userList(new std::set<unsigned long>);
+
for(XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user) {
userList->insert(user->get<unsigned long>("uid"));
}
+
+ return userList;
}
- return userList;
+ return boost::shared_ptr<const std::set<unsigned long> >();
}
-boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > NetworkUserBackend::getFullUserGroupList() throw(Core::Exception) {
- boost::shared_ptr<SimpleUserRequest> request(new SimpleUserRequest(application, "GetFullUserGroupList"));
+boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > NetworkUserBackend::getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+ boost::shared_ptr<SimpleUserRequest> request(new SimpleUserRequest(application, "GetFullUserGroupList", timestamp));
application->getRequestManager()->sendRequest(connection, request);
request->wait();
@@ -197,15 +301,24 @@ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > NetworkUse
if(!result.first || result.second)
throw result.second;
- boost::shared_ptr<std::multimap<unsigned long, unsigned long> > ret(new std::multimap<unsigned long, unsigned long>);
+ if(timestamp) {
+ try {
+ *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp"));
+ }
+ catch(...) {}
+ }
const XmlPacket::List *list = result.first->getList("userGroupList");
if(list) {
+ boost::shared_ptr<std::multimap<unsigned long, unsigned long> > ret(new std::multimap<unsigned long, unsigned long>);
+
for(XmlPacket::List::const_iterator entry = list->begin(); entry != list->end(); ++entry)
ret->insert(std::make_pair(entry->get<unsigned long>("uid"), entry->get<unsigned long>("gid")));
+
+ return ret;
}
- return ret;
+ return boost::shared_ptr<const std::multimap<unsigned long, unsigned long> >();
}
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<const std::map<unsigned long, UserInfo> > getUserList() throw(Core::Exception);
- virtual boost::shared_ptr<const UserInfo> getUserInfo(unsigned long uid) throw(Core::Exception);
- virtual boost::shared_ptr<const UserInfo> getUserInfoByName(const std::string &name) throw(Core::Exception);
- virtual boost::shared_ptr<const std::set<unsigned long> > getUserGroupList(unsigned long uid) throw(Core::Exception);
+ virtual boost::shared_ptr<const std::map<unsigned long, Common::UserInfo> > getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception);
+ virtual boost::shared_ptr<const Common::UserInfo> getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception);
+ virtual boost::shared_ptr<const Common::UserInfo> getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception);
+ virtual boost::shared_ptr<const std::set<unsigned long> > getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception);
- virtual boost::shared_ptr<const std::map<unsigned long, GroupInfo> > getGroupList() throw(Core::Exception);
- virtual boost::shared_ptr<const GroupInfo> getGroupInfo(unsigned long gid) throw(Core::Exception);
- virtual boost::shared_ptr<const GroupInfo> getGroupInfoByName(const std::string &name) throw(Core::Exception);
- virtual boost::shared_ptr<const std::set<unsigned long> > getGroupUserList(unsigned long gid) throw(Core::Exception);
+ virtual boost::shared_ptr<const std::map<unsigned long, Common::GroupInfo> > getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception);
+ virtual boost::shared_ptr<const Common::GroupInfo> getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception);
+ virtual boost::shared_ptr<const Common::GroupInfo> getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception);
+ virtual boost::shared_ptr<const std::set<unsigned long> > getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception);
- virtual boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > getFullUserGroupList() throw(Core::Exception);
+ virtual boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > 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);