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 --- .../RequestHandlers/UserRequestHandlerGroup.cpp | 191 ++++++++++++++++----- 1 file changed, 152 insertions(+), 39 deletions(-) (limited to 'src/Server/RequestHandlers/UserRequestHandlerGroup.cpp') diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp index d579480..292e887 100644 --- a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp @@ -17,99 +17,196 @@ * with this program. If not, see . */ +#include + #include "UserRequestHandlerGroup.h" #include "../Application.h" + #include +#include + namespace Mad { namespace Server { namespace RequestHandlers { -void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr packet _UNUSED_PARAMETER_, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { - boost::shared_ptr > info = application->getUserManager()->getUserList(); + boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); + + const std::string ×tr = packet->get("timestamp"); + if(!timestr.empty()) { + try { + timestamp = boost::posix_time::from_iso_string(timestr); + } + catch(...) {} + } + + boost::shared_ptr > users = application->getUserManager()->getUserList(×tamp); ret->setType("OK"); - Common::XmlPacket::List *list = ret->createList("users"); - for(std::map::const_iterator user = info->begin(); user != info->end(); ++user) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + if(!timestamp.is_not_a_date_time()) + ret->set("timestamp", boost::posix_time::to_iso_string(timestamp)); + + if(users) { + Common::XmlPacket::List *list = ret->createList("users"); + + for(std::map::const_iterator user = users->begin(); user != users->end(); ++user) { + Common::XmlPacket::List::iterator entry = list->addEntry(); - entry->set("uid", user->second.getUid()); - entry->set("gid", user->second.getGid()); - entry->set("username", user->second.getUsername()); - entry->set("fullName", user->second.getFullName()); + entry->set("uid", user->second.getUid()); + entry->set("gid", user->second.getGid()); + entry->set("username", user->second.getUsername()); + entry->set("fullName", user->second.getFullName()); + } } } void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { + boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); + + const std::string ×tr = packet->get("timestamp"); + if(!timestr.empty()) { + try { + timestamp = boost::posix_time::from_iso_string(timestr); + } + catch(...) {} + } + boost::shared_ptr info; unsigned long uid = packet->get("uid"); if(uid) - info = application->getUserManager()->getUserInfo(uid); + info = application->getUserManager()->getUserInfo(uid, ×tamp); else - info = application->getUserManager()->getUserInfoByName(packet->get("name")); + info = application->getUserManager()->getUserInfoByName(packet->get("name"), ×tamp); ret->setType("OK"); - ret->set("uid", info->getUid()); - ret->set("gid", info->getGid()); - ret->set("username", info->getUsername()); - ret->set("fullName", info->getFullName()); + if(!timestamp.is_not_a_date_time()) + ret->set("timestamp", boost::posix_time::to_iso_string(timestamp)); + + if(info) { + ret->set("uid", info->getUid()); + ret->set("gid", info->getGid()); + ret->set("username", info->getUsername()); + ret->set("fullName", info->getFullName()); + } } void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { - boost::shared_ptr > groups = application->getUserManager()->getUserGroupList(packet->get("uid")); + boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); + + const std::string ×tr = packet->get("timestamp"); + if(!timestr.empty()) { + try { + timestamp = boost::posix_time::from_iso_string(timestr); + } + catch(...) {} + } + + boost::shared_ptr > groups = application->getUserManager()->getUserGroupList(packet->get("uid"), ×tamp); ret->setType("OK"); - Common::XmlPacket::List *list = ret->createList("groups"); - for(std::set::const_iterator group = groups->begin(); group != groups->end(); ++group) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + if(!timestamp.is_not_a_date_time()) + ret->set("timestamp", boost::posix_time::to_iso_string(timestamp)); + + if(groups) { + Common::XmlPacket::List *list = ret->createList("groups"); + + for(std::set::const_iterator group = groups->begin(); group != groups->end(); ++group) { + Common::XmlPacket::List::iterator entry = list->addEntry(); - entry->set("gid", *group); + entry->set("gid", *group); + } } } -void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr packet _UNUSED_PARAMETER_, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { - boost::shared_ptr > info = application->getUserManager()->getGroupList(); + boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); + + const std::string ×tr = packet->get("timestamp"); + if(!timestr.empty()) { + try { + timestamp = boost::posix_time::from_iso_string(timestr); + } + catch(...) {} + } + + boost::shared_ptr > groups = application->getUserManager()->getGroupList(×tamp); ret->setType("OK"); - Common::XmlPacket::List *list = ret->createList("groups"); - for(std::map::const_iterator group = info->begin(); group != info->end(); ++group) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + if(!timestamp.is_not_a_date_time()) + ret->set("timestamp", boost::posix_time::to_iso_string(timestamp)); + + if(groups) { + Common::XmlPacket::List *list = ret->createList("groups"); + + for(std::map::const_iterator group = groups->begin(); group != groups->end(); ++group) { + Common::XmlPacket::List::iterator entry = list->addEntry(); - entry->set("gid", group->second.getGid()); - entry->set("name", group->second.getName()); + entry->set("gid", group->second.getGid()); + entry->set("name", group->second.getName()); + } } } void UserRequestHandlerGroup::handleGroupInfoRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { + boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); + + const std::string ×tr = packet->get("timestamp"); + if(!timestr.empty()) { + try { + timestamp = boost::posix_time::from_iso_string(timestr); + } + catch(...) {} + } + boost::shared_ptr info; unsigned long gid = packet->get("gid"); if(gid) - info = application->getUserManager()->getGroupInfo(gid); + info = application->getUserManager()->getGroupInfo(gid, ×tamp); else - info = application->getUserManager()->getGroupInfoByName(packet->get("name")); + info = application->getUserManager()->getGroupInfoByName(packet->get("name"), ×tamp); ret->setType("OK"); - ret->set("gid", info->getGid()); - ret->set("name", info->getName()); + if(!timestamp.is_not_a_date_time()) + ret->set("timestamp", boost::posix_time::to_iso_string(timestamp)); + + if(info) { + ret->set("gid", info->getGid()); + ret->set("name", info->getName()); + } } void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { - boost::shared_ptr > users = application->getUserManager()->getGroupUserList(packet->get("gid")); + boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); + + const std::string ×tr = packet->get("timestamp"); + if(!timestr.empty()) { + try { + timestamp = boost::posix_time::from_iso_string(timestr); + } + catch(...) {} + } + + boost::shared_ptr > users = application->getUserManager()->getGroupUserList(packet->get("gid"), ×tamp); ret->setType("OK"); + + if(!timestamp.is_not_a_date_time()) + ret->set("timestamp", boost::posix_time::to_iso_string(timestamp)); + Common::XmlPacket::List *list = ret->createList("users"); for(std::set::const_iterator user = users->begin(); user != users->end(); ++user) { @@ -119,18 +216,34 @@ void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr packet _UNUSED_PARAMETER_, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleFullUserGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { - boost::shared_ptr > userGroups = application->getUserManager()->getFullUserGroupList(); + boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); + + const std::string ×tr = packet->get("timestamp"); + if(!timestr.empty()) { + try { + timestamp = boost::posix_time::from_iso_string(timestr); + } + catch(...) {} + } + + boost::shared_ptr > userGroups = application->getUserManager()->getFullUserGroupList(×tamp); ret->setType("OK"); - Common::XmlPacket::List *list = ret->createList("userGroupList"); - for(std::map::const_iterator userGroup = userGroups->begin(); userGroup != userGroups->end(); ++userGroup) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + if(!timestamp.is_not_a_date_time()) + ret->set("timestamp", boost::posix_time::to_iso_string(timestamp)); + + if(userGroups) { + Common::XmlPacket::List *list = ret->createList("userGroupList"); + + for(std::map::const_iterator userGroup = userGroups->begin(); userGroup != userGroups->end(); ++userGroup) { + Common::XmlPacket::List::iterator entry = list->addEntry(); - entry->set("uid", userGroup->first); - entry->set("gid", userGroup->second); + entry->set("uid", userGroup->first); + entry->set("gid", userGroup->second); + } } } -- cgit v1.2.3