diff options
Diffstat (limited to 'src/Common/Backends/NetworkUserBackend.cpp')
-rw-r--r-- | src/Common/Backends/NetworkUserBackend.cpp | 193 |
1 files changed, 153 insertions, 40 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> >(); } |