summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-09-19 18:12:26 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-09-19 18:12:26 +0200
commit78db15a780cc5389fc6e01d500d5c91bdd8bc422 (patch)
treee0b935a883fecb5aa1c7a650a3f2d5d141fbabfd
parentfa14f97b9ad2260ca0918eae13431974e7fcfb26 (diff)
downloadmad-78db15a780cc5389fc6e01d500d5c91bdd8bc422.tar
mad-78db15a780cc5389fc6e01d500d5c91bdd8bc422.zip
UserListManager: Added user list diff support.
-rw-r--r--src/modules/UserListManager/CMakeLists.txt2
-rw-r--r--src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp82
-rw-r--r--src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.h51
-rw-r--r--src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp44
-rw-r--r--src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.h4
-rw-r--r--src/modules/UserListManager/UserListDiff.cpp46
-rw-r--r--src/modules/UserListManager/UserListDiff.h88
-rw-r--r--src/modules/UserListManager/UserListEntry.h4
-rw-r--r--src/modules/UserListManager/UserListManager.cpp35
-rw-r--r--src/modules/UserListManager/UserListManager.h15
-rw-r--r--src/modules/UserListManager/Util.cpp83
-rw-r--r--src/modules/UserListManager/Util.h14
12 files changed, 436 insertions, 32 deletions
diff --git a/src/modules/UserListManager/CMakeLists.txt b/src/modules/UserListManager/CMakeLists.txt
index 0ab429f..f8e72ce 100644
--- a/src/modules/UserListManager/CMakeLists.txt
+++ b/src/modules/UserListManager/CMakeLists.txt
@@ -1,11 +1,13 @@
include_directories(${INCLUDES})
mad_module(UserListManager
+ RequestHandlers/UserListDiffUploadRequestHandler.cpp RequestHandlers/UserListDiffUploadRequestHandler.h
RequestHandlers/UserListRequestHandlerGroup.cpp RequestHandlers/UserListRequestHandlerGroup.h
RequestHandlers/UserListUploadRequestHandler.cpp RequestHandlers/UserListUploadRequestHandler.h
Module.cpp Module.h
UserList.h
+ UserListDiff.cpp UserListDiff.h
UserListEntry.h
UserListManager.cpp UserListManager.h
Util.cpp Util.h
diff --git a/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp b/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp
new file mode 100644
index 0000000..4660850
--- /dev/null
+++ b/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp
@@ -0,0 +1,82 @@
+/*
+ * UserListDiffUploadRequestHandler.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "UserListDiffUploadRequestHandler.h"
+#include "../UserListManager.h"
+#include "../Util.h"
+
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+namespace Mad {
+namespace Modules {
+namespace UserListManager {
+namespace RequestHandlers {
+
+void UserListDiffUploadRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlData> packet) {
+ if(packet->getType() == "Cancel") {
+ Common::XmlData ret;
+ ret.setType("OK");
+ sendPacket(ret);
+
+ signalFinished();
+ return;
+ }
+ else if(packet->getType() != "UploadUserListDiff") {
+ getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet.");
+
+ Common::XmlData ret;
+ ret.setType("Error");
+ ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET);
+
+ sendPacket(ret);
+
+ signalFinished();
+ return;
+ }
+
+ if(!getConnection()->isAuthenticated())
+ throw(Core::Exception(Core::Exception::PERMISSION));
+
+ if(name.empty()) { // Request
+ name = packet->get<const std::string&>("name");
+
+ if(name.empty())
+ name = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time());
+
+ Common::XmlData ret;
+ ret.setType("Continue");
+ ret.set("exists", userListManager->existsUserListDiff(name));
+ sendPacket(ret);
+ }
+ else { // Upload
+ boost::shared_ptr<UserListDiff> diff = Util::deserializeUserListDiff(packet.get());
+ userListManager->storeUserListDiff(name, diff.get());
+
+ Common::XmlData ret;
+ ret.setType("OK");
+ sendPacket(ret);
+
+ signalFinished();
+ }
+}
+
+}
+}
+}
+}
diff --git a/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.h b/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.h
new file mode 100644
index 0000000..205a87f
--- /dev/null
+++ b/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.h
@@ -0,0 +1,51 @@
+/*
+ * UserListDiffUploadRequestHandler.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTDIFFUPLOADREQUESTHANDLER_H_
+#define MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTDIFFUPLOADREQUESTHANDLER_H_
+
+#include <Common/RequestHandler.h>
+
+namespace Mad {
+namespace Modules {
+namespace UserListManager {
+
+class UserListManager;
+
+namespace RequestHandlers {
+
+class UserListDiffUploadRequestHandler : public Common::RequestHandler {
+ private:
+ std::string name;
+
+ UserListManager *userListManager;
+
+ protected:
+ virtual void handlePacket(boost::shared_ptr<const Common::XmlData> packet);
+
+ public:
+ UserListDiffUploadRequestHandler(Common::Application *application, UserListManager *userListManager0) : Common::RequestHandler(application), userListManager(userListManager0) {}
+};
+
+}
+}
+}
+}
+
+#endif /* MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTDIFFUPLOADREQUESTHANDLER_H_ */
diff --git a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp b/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp
index 98d2815..99d2818 100644
--- a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp
+++ b/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp
@@ -64,11 +64,55 @@ void UserListRequestHandlerGroup::handleUserListRemoveRequest(boost::shared_ptr<
ret->setType("OK");
}
+
+void UserListRequestHandlerGroup::handleUserListDiffListRequest(boost::shared_ptr<const Common::XmlData> /*packet*/, Common::XmlData *ret, Common::Connection *connection) {
+ if(!connection->isAuthenticated())
+ throw(Core::Exception(Core::Exception::PERMISSION));
+
+ const std::set<std::string> &userListDiffs = userListManager->getUserListDiffs();
+
+ ret->setType("OK");
+ Common::XmlData::List *list = ret->createList("userListDiffs");
+
+ for(std::set<std::string>::const_iterator diff = userListDiffs.begin(); diff != userListDiffs.end(); ++diff) {
+ Common::XmlData::List::iterator entry = list->addEntry();
+
+ entry->set("name", *diff);
+ }
+
+}
+
+void UserListRequestHandlerGroup::handleUserListDiffDownloadRequest(boost::shared_ptr<const Common::XmlData> packet, Common::XmlData *ret, Common::Connection *connection) {
+ if(!connection->isAuthenticated())
+ throw(Core::Exception(Core::Exception::PERMISSION));
+
+ boost::shared_ptr<UserListDiff> diff = userListManager->loadUserListDiff(packet->get<const std::string&>("name"));
+ if(!diff)
+ throw(Core::Exception(Core::Exception::NOT_FOUND));
+
+ ret->setType("OK");
+ Util::serializeUserListDiff(diff.get(), ret);
+}
+
+void UserListRequestHandlerGroup::handleUserListDiffRemoveRequest(boost::shared_ptr<const Common::XmlData> packet, Common::XmlData *ret, Common::Connection *connection) {
+ if(!connection->isAuthenticated())
+ throw(Core::Exception(Core::Exception::PERMISSION));
+
+ userListManager->removeUserListDiff(packet->get<const std::string&>("name"));
+
+ ret->setType("OK");
+}
+
+
UserListRequestHandlerGroup::UserListRequestHandlerGroup(Server::Application *application0, UserListManager *userListManager0)
: application(application0), userListManager(userListManager0) {
registerHandler("ListUserLists", boost::bind(&UserListRequestHandlerGroup::handleUserListListRequest, this, _1, _2, _3));
registerHandler("DownloadUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListDownloadRequest, this, _1, _2, _3));
registerHandler("RemoveUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListRemoveRequest, this, _1, _2, _3));
+
+ registerHandler("ListUserListDiffs", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffListRequest, this, _1, _2, _3));
+ registerHandler("DownloadUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffDownloadRequest, this, _1, _2, _3));
+ registerHandler("RemoveUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffRemoveRequest, this, _1, _2, _3));
}
}
diff --git a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.h b/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.h
index 2aeda6b..105621b 100644
--- a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.h
+++ b/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.h
@@ -46,6 +46,10 @@ class MAD_MODULE_EXPORT UserListRequestHandlerGroup : public Common::RequestHan
void handleUserListDownloadRequest(boost::shared_ptr<const Common::XmlData> packet, Common::XmlData *ret, Common::Connection *connection);
void handleUserListRemoveRequest(boost::shared_ptr<const Common::XmlData> packet, Common::XmlData *ret, Common::Connection *connection);
+ void handleUserListDiffListRequest(boost::shared_ptr<const Common::XmlData> packet, Common::XmlData *ret, Common::Connection *connection);
+ void handleUserListDiffDownloadRequest(boost::shared_ptr<const Common::XmlData> packet, Common::XmlData *ret, Common::Connection *connection);
+ void handleUserListDiffRemoveRequest(boost::shared_ptr<const Common::XmlData> packet, Common::XmlData *ret, Common::Connection *connection);
+
public:
UserListRequestHandlerGroup(Server::Application *application0, UserListManager *userListManager0);
};
diff --git a/src/modules/UserListManager/UserListDiff.cpp b/src/modules/UserListManager/UserListDiff.cpp
new file mode 100644
index 0000000..a7b5f2f
--- /dev/null
+++ b/src/modules/UserListManager/UserListDiff.cpp
@@ -0,0 +1,46 @@
+/*
+ * UserListDiff.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "UserListDiff.h"
+#include "UserList.h"
+
+namespace Mad {
+namespace Modules {
+namespace UserListManager {
+
+UserListDiff::UserListDiff(const UserList *oldList, const UserList *newList) {
+ for(UserList::const_iterator user = oldList->begin(); user != oldList->end(); ++user)
+ deletedUsers.insert(*user);
+
+ for(UserList::const_iterator user = newList->begin(); user != newList->end(); ++user) {
+ std::set<UserListEntry>::const_iterator it = deletedUsers.find(*user);
+
+ if(it != deletedUsers.end()) {
+ deletedUsers.erase(it);
+ unchangedUsers.insert(*user);
+ }
+ else {
+ addedUsers.insert(*user);
+ }
+ }
+}
+
+}
+}
+}
diff --git a/src/modules/UserListManager/UserListDiff.h b/src/modules/UserListManager/UserListDiff.h
new file mode 100644
index 0000000..de881bd
--- /dev/null
+++ b/src/modules/UserListManager/UserListDiff.h
@@ -0,0 +1,88 @@
+/*
+ * UserListDiff.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_MODULES_USERLISTMANAGER_USERLISTDIFF_H_
+#define MAD_MODULES_USERLISTMANAGER_USERLISTDIFF_H_
+
+#include "../export.h"
+
+#include "UserListEntry.h"
+#include <Core/Exception.h>
+
+#include <set>
+
+namespace Mad {
+namespace Modules {
+namespace UserListManager {
+
+class UserList;
+
+class MAD_MODULE_EXPORT UserListDiff {
+ private:
+ std::set<UserListEntry> addedUsers;
+ std::set<UserListEntry> deletedUsers;
+ std::set<UserListEntry> unchangedUsers;
+
+ public:
+ UserListDiff() {}
+ UserListDiff(const UserList *oldList, const UserList *newList);
+
+ void invert() {
+ addedUsers.swap(deletedUsers);
+ }
+
+ const std::set<UserListEntry>& getAddedUsers() const {
+ return addedUsers;
+ }
+
+ const std::set<UserListEntry>& getDeletedUsers() const {
+ return deletedUsers;
+ }
+
+ const std::set<UserListEntry>& getUnchangedUsers() const {
+ return unchangedUsers;
+ }
+
+ bool insertAddedUser(UserListEntry user) {
+ if(deletedUsers.count(user) || unchangedUsers.count(user))
+ return false;
+
+ return addedUsers.insert(user).second;
+ }
+
+ bool insertDeletedUser(UserListEntry user) {
+ if(addedUsers.count(user) || unchangedUsers.count(user))
+ return false;
+
+ return deletedUsers.insert(user).second;
+ }
+
+ bool insertUnchangedUser(UserListEntry user) {
+ if(addedUsers.count(user) || deletedUsers.count(user))
+ return false;
+
+ return unchangedUsers.insert(user).second;
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_MODULES_USERLISTMANAGER_USERLISTDIFF_H_ */
diff --git a/src/modules/UserListManager/UserListEntry.h b/src/modules/UserListManager/UserListEntry.h
index 719787f..59776d6 100644
--- a/src/modules/UserListManager/UserListEntry.h
+++ b/src/modules/UserListManager/UserListEntry.h
@@ -80,6 +80,10 @@ class UserListEntry {
void unsetDetail(const std::string &name) {
details.erase(name);
}
+
+ bool operator<(const UserListEntry o) const {
+ return (name < o.name);
+ }
};
}
diff --git a/src/modules/UserListManager/UserListManager.cpp b/src/modules/UserListManager/UserListManager.cpp
index 18ed83c..e947e24 100644
--- a/src/modules/UserListManager/UserListManager.cpp
+++ b/src/modules/UserListManager/UserListManager.cpp
@@ -22,6 +22,7 @@
#include "Util.h"
#include "RequestHandlers/UserListRequestHandlerGroup.h"
#include "RequestHandlers/UserListUploadRequestHandler.h"
+#include "RequestHandlers/UserListDiffUploadRequestHandler.h"
#include <Server/Application.h>
#include <Common/RequestManager.h>
@@ -39,6 +40,7 @@ UserListManager::UserListManager(Server::Application *application0) : applicatio
UserListManager::~UserListManager() {
application->getRequestManager()->unregisterPacketType("UploadUserList");
+ application->getRequestManager()->unregisterPacketType("UploadUserListDiff");
application->getRequestManager()->unregisterRequestHandlerGroup(requestHandlerGroup);
application->getConfigManager()->unregisterConfigurable(this);
}
@@ -46,17 +48,13 @@ UserListManager::~UserListManager() {
void UserListManager::configFinished() {
userLists = application->getStorageManager()->list("UserList");
+ userListDiffs = application->getStorageManager()->list("UserListDiff");
application->getRequestManager()->registerRequestHandlerGroup(requestHandlerGroup);
application->getRequestManager()->registerPacketType<RequestHandlers::UserListUploadRequestHandler>("UploadUserList", this);
+ application->getRequestManager()->registerPacketType<RequestHandlers::UserListDiffUploadRequestHandler>("UploadUserListDiff", this);
}
-
-const std::set<std::string>& UserListManager::getUserLists() const {
- return userLists;
-}
-
-
bool UserListManager::existsUserList(const std::string &name) {
return application->getStorageManager()->exists("UserList", name);
}
@@ -81,6 +79,31 @@ void UserListManager::removeUserList(const std::string &name) {
application->getStorageManager()->remove("UserList", name);
}
+
+bool UserListManager::existsUserListDiff(const std::string &name) {
+ return application->getStorageManager()->exists("UserListDiff", name);
+}
+
+boost::shared_ptr<UserListDiff> UserListManager::loadUserListDiff(const std::string &name) {
+ boost::shared_ptr<Common::XmlData> data = application->getStorageManager()->load("UserListDiff", name);
+
+ if(!data)
+ return boost::shared_ptr<UserListDiff>();
+
+ return Util::deserializeUserListDiff(data.get());
+}
+
+void UserListManager::storeUserListDiff(const std::string &name, const UserListDiff *list) {
+ Common::XmlData data;
+
+ Util::serializeUserListDiff(list, &data);
+ application->getStorageManager()->store("UserListDiff", name, &data);
+}
+
+void UserListManager::removeUserListDiff(const std::string &name) {
+ application->getStorageManager()->remove("UserListDiff", name);
+}
+
boost::shared_ptr<UserList> UserListManager::getCurrentUserList() {
boost::shared_ptr<UserList> list(new UserList);
diff --git a/src/modules/UserListManager/UserListManager.h b/src/modules/UserListManager/UserListManager.h
index 3f806e9..6d2599b 100644
--- a/src/modules/UserListManager/UserListManager.h
+++ b/src/modules/UserListManager/UserListManager.h
@@ -43,6 +43,7 @@ class UserListRequestHandlerGroup;
}
class UserList;
+class UserListDiff;
class MAD_MODULE_EXPORT UserListManager : private Core::Configurable, private boost::noncopyable {
private:
@@ -51,6 +52,7 @@ class MAD_MODULE_EXPORT UserListManager : private Core::Configurable, private bo
boost::shared_ptr<RequestHandlers::UserListRequestHandlerGroup> requestHandlerGroup;
std::set<std::string> userLists;
+ std::set<std::string> userListDiffs;
protected:
virtual void configFinished();
@@ -61,13 +63,24 @@ class MAD_MODULE_EXPORT UserListManager : private Core::Configurable, private bo
UserListManager(Server::Application *application0);
virtual ~UserListManager();
- const std::set<std::string>& getUserLists() const;
+ const std::set<std::string>& getUserLists() const {
+ return userLists;
+ }
bool existsUserList(const std::string &name);
boost::shared_ptr<UserList> loadUserList(const std::string &name);
void storeUserList(const std::string &name, const UserList *list);
void removeUserList(const std::string &name);
+ const std::set<std::string>& getUserListDiffs() const {
+ return userListDiffs;
+ }
+
+ bool existsUserListDiff(const std::string &name);
+ boost::shared_ptr<UserListDiff> loadUserListDiff(const std::string &name);
+ void storeUserListDiff(const std::string &name, const UserListDiff *list);
+ void removeUserListDiff(const std::string &name);
+
boost::shared_ptr<UserList> getCurrentUserList();
};
diff --git a/src/modules/UserListManager/Util.cpp b/src/modules/UserListManager/Util.cpp
index f9b6a55..9b986d8 100644
--- a/src/modules/UserListManager/Util.cpp
+++ b/src/modules/UserListManager/Util.cpp
@@ -19,6 +19,7 @@
#include "Util.h"
#include "UserList.h"
+#include "UserListDiff.h"
#include <Common/XmlData.h>
@@ -26,19 +27,34 @@ namespace Mad {
namespace Modules {
namespace UserListManager {
-void Util::serializeUserList(const UserList *list, Common::XmlData *data) {
- Common::XmlData::List *userList = data->createList("users");
+void Util::serializeUserListEntry(const UserListEntry *user, Common::XmlData::List::iterator entry) {
+ std::set<std::string> details = user->getDetailList();
+ for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail)
+ entry->set(*detail, user->getDetail(*detail));
+
+ entry->set("name", user->getName());
+ entry->set("group", user->getGroup());
+}
- for(UserList::const_iterator user = list->begin(); user != list->end(); ++user) {
- Common::XmlData::List::iterator entry = userList->addEntry();
+UserListEntry Util::deserializeUserListEntry(Common::XmlData::List::const_iterator entry) {
+ UserListEntry user(entry->get<const std::string&>("name"), entry->get<const std::string&>("group"));
- std::set<std::string> details = user->getDetailList();
- for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail)
- entry->set(*detail, user->getDetail(*detail));
+ std::set<std::string> details = entry->getChildren();
+ for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) {
+ if(*detail == "user" || *detail == "group")
+ continue;
- entry->set("name", user->getName());
- entry->set("group", user->getGroup());
+ user.setDetail(*detail, entry->get<const std::string&>(*detail));
}
+
+ return user;
+}
+
+void Util::serializeUserList(const UserList *list, Common::XmlData *data) {
+ Common::XmlData::List *userList = data->createList("users");
+
+ for(UserList::const_iterator user = list->begin(); user != list->end(); ++user)
+ serializeUserListEntry(&*user, userList->addEntry());
}
boost::shared_ptr<UserList> Util::deserializeUserList(const Common::XmlData *data) {
@@ -47,22 +63,49 @@ boost::shared_ptr<UserList> Util::deserializeUserList(const Common::XmlData *dat
const Common::XmlData::List *userList = data->getList("users");
if(userList) {
- for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) {
- UserListEntry entry(user->get<const std::string&>("name"), user->get<const std::string&>("group"));
+ for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ users->push_back(deserializeUserListEntry(user));
+ }
- std::set<std::string> details = user->getChildren();
- for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) {
- if(*detail == "user" || *detail == "group")
- continue;
+ return users;
+}
- entry.setDetail(*detail, user->get<const std::string&>(*detail));
- }
+void Util::serializeUserListDiff(const UserListDiff *diff, Common::XmlData *data) {
+ Common::XmlData::List *userList = data->createList("addedUsers");
+ for(std::set<UserListEntry>::const_iterator user = diff->getAddedUsers().begin(); user != diff->getAddedUsers().end(); ++user)
+ serializeUserListEntry(&*user, userList->addEntry());
- users->push_back(entry);
- }
+ userList = data->createList("deletedUsers");
+ for(std::set<UserListEntry>::const_iterator user = diff->getDeletedUsers().begin(); user != diff->getDeletedUsers().end(); ++user)
+ serializeUserListEntry(&*user, userList->addEntry());
+
+ userList = data->createList("unchangedUsers");
+ for(std::set<UserListEntry>::const_iterator user = diff->getUnchangedUsers().begin(); user != diff->getUnchangedUsers().end(); ++user)
+ serializeUserListEntry(&*user, userList->addEntry());
+}
+
+boost::shared_ptr<UserListDiff> Util::deserializeUserListDiff(const Common::XmlData *data) {
+ boost::shared_ptr<UserListDiff> diff(new UserListDiff);
+
+ const Common::XmlData::List *userList = data->getList("addedUsers");
+ if(userList) {
+ for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ diff->insertAddedUser(deserializeUserListEntry(user));
}
- return users;
+ userList = data->getList("deletedUsers");
+ if(userList) {
+ for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ diff->insertDeletedUser(deserializeUserListEntry(user));
+ }
+
+ userList = data->getList("unchangedUsers");
+ if(userList) {
+ for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ diff->insertUnchangedUser(deserializeUserListEntry(user));
+ }
+
+ return diff;
}
}
diff --git a/src/modules/UserListManager/Util.h b/src/modules/UserListManager/Util.h
index 6af35cc..c9b9a2c 100644
--- a/src/modules/UserListManager/Util.h
+++ b/src/modules/UserListManager/Util.h
@@ -22,26 +22,30 @@
#include "../export.h"
+#include <Common/XmlData.h>
#include <boost/shared_ptr.hpp>
namespace Mad {
-
-namespace Common {
-class XmlData;
-}
-
namespace Modules {
namespace UserListManager {
class UserList;
+class UserListDiff;
+class UserListEntry;
class MAD_MODULE_EXPORT Util {
private:
+ static void serializeUserListEntry(const UserListEntry *user, Common::XmlData::List::iterator entry);
+ static UserListEntry deserializeUserListEntry(Common::XmlData::List::const_iterator entry);
+
Util();
public:
static void serializeUserList(const UserList *list, Common::XmlData *data);
static boost::shared_ptr<UserList> deserializeUserList(const Common::XmlData *data);
+
+ static void serializeUserListDiff(const UserListDiff *diff, Common::XmlData *data);
+ static boost::shared_ptr<UserListDiff> deserializeUserListDiff(const Common::XmlData *data);
};
}