summaryrefslogtreecommitdiffstats
path: root/src/Common/UserLists
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-09-23 09:44:02 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-09-23 09:44:02 +0200
commit0eddc28a331437ef95a60418ed1fc6de4e9b63c1 (patch)
tree17dcb71adbca54b47e12b32fb313597f971709f5 /src/Common/UserLists
parentd6844595c9b47dab1db4b970ff6cc7fb3f64f107 (diff)
downloadmad-0eddc28a331437ef95a60418ed1fc6de4e9b63c1.tar
mad-0eddc28a331437ef95a60418ed1fc6de4e9b63c1.zip
UserListManager: Moved module into libCommon and libServer
Diffstat (limited to 'src/Common/UserLists')
-rw-r--r--src/Common/UserLists/UserList.h40
-rw-r--r--src/Common/UserLists/UserListDiff.cpp46
-rw-r--r--src/Common/UserLists/UserListDiff.h88
-rw-r--r--src/Common/UserLists/UserListEntry.h93
-rw-r--r--src/Common/UserLists/Util.cpp111
-rw-r--r--src/Common/UserLists/Util.h55
6 files changed, 433 insertions, 0 deletions
diff --git a/src/Common/UserLists/UserList.h b/src/Common/UserLists/UserList.h
new file mode 100644
index 0000000..e80abaf
--- /dev/null
+++ b/src/Common/UserLists/UserList.h
@@ -0,0 +1,40 @@
+/*
+ * UserList.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_COMMON_USERLISTS_USERLIST_H_
+#define MAD_COMMON_USERLISTS_USERLIST_H_
+
+#include "UserListEntry.h"
+
+#include <list>
+
+namespace Mad {
+namespace Common {
+namespace UserLists {
+
+class UserList : public std::list<UserListEntry> {
+ public:
+ UserList() {}
+};
+
+}
+}
+}
+
+#endif /* MAD_COMMON_USERLISTS_USERLIST_H_ */
diff --git a/src/Common/UserLists/UserListDiff.cpp b/src/Common/UserLists/UserListDiff.cpp
new file mode 100644
index 0000000..e763afe
--- /dev/null
+++ b/src/Common/UserLists/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 Common {
+namespace UserLists {
+
+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/Common/UserLists/UserListDiff.h b/src/Common/UserLists/UserListDiff.h
new file mode 100644
index 0000000..41b8e81
--- /dev/null
+++ b/src/Common/UserLists/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_COMMON_USERLISTS_USERLISTDIFF_H_
+#define MAD_COMMON_USERLISTS_USERLISTDIFF_H_
+
+#include "../export.h"
+
+#include "UserListEntry.h"
+#include <Core/Exception.h>
+
+#include <set>
+
+namespace Mad {
+namespace Common {
+namespace UserLists {
+
+class UserList;
+
+class MAD_COMMON_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_COMMON_USERLISTS_USERLISTDIFF_H_ */
diff --git a/src/Common/UserLists/UserListEntry.h b/src/Common/UserLists/UserListEntry.h
new file mode 100644
index 0000000..8642275
--- /dev/null
+++ b/src/Common/UserLists/UserListEntry.h
@@ -0,0 +1,93 @@
+/*
+ * UserListEntry.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_COMMON_USERLISTS_USERLISTENTRY_H_
+#define MAD_COMMON_USERLISTS_USERLISTENTRY_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+
+namespace Mad {
+namespace Common {
+namespace UserLists {
+
+class UserListEntry {
+ private:
+ std::string name;
+ std::string group;
+
+ std::map<std::string, std::string> details;
+
+ public:
+ UserListEntry(const std::string &name0 = std::string(), const std::string &group0 = std::string()) : name(name0), group(group0) {}
+
+ const std::string& getName() const {
+ return name;
+ }
+
+ void setName(const std::string &newName) {
+ name = newName;
+ }
+
+ const std::string& getGroup() const {
+ return group;
+ }
+
+ void setGroup(const std::string &newGroup) {
+ group = newGroup;
+ }
+
+ std::set<std::string> getDetailList() const {
+ std::set<std::string> ret;
+
+ for(std::map<std::string, std::string>::const_iterator it = details.begin(); it != details.end(); ++it)
+ ret.insert(it->first);
+
+ return ret;
+ }
+
+ std::string getDetail(const std::string &name) const {
+ std::map<std::string, std::string>::const_iterator it = details.find(name);
+ if(it != details.end())
+ return it->second;
+ else
+ return std::string();
+ }
+
+ void setDetail(const std::string &name, const std::string &value) {
+ details.erase(name);
+ details.insert(std::make_pair(name, value));
+ }
+
+ void unsetDetail(const std::string &name) {
+ details.erase(name);
+ }
+
+ bool operator<(const UserListEntry o) const {
+ return (name < o.name);
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_COMMON_USERLISTS_USERLISTENTRY_H_ */
diff --git a/src/Common/UserLists/Util.cpp b/src/Common/UserLists/Util.cpp
new file mode 100644
index 0000000..812c2c7
--- /dev/null
+++ b/src/Common/UserLists/Util.cpp
@@ -0,0 +1,111 @@
+/*
+ * Util.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 "Util.h"
+#include "UserList.h"
+#include "UserListDiff.h"
+
+namespace Mad {
+namespace Common {
+namespace UserLists {
+
+void Util::serializeUserListEntry(const UserListEntry *user, 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());
+}
+
+UserListEntry Util::deserializeUserListEntry(XmlData::List::const_iterator entry) {
+ UserListEntry user(entry->get<const std::string&>("name"), entry->get<const std::string&>("group"));
+
+ 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;
+
+ user.setDetail(*detail, entry->get<const std::string&>(*detail));
+ }
+
+ return user;
+}
+
+void Util::serializeUserList(const UserList *list, XmlData *data) {
+ 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 XmlData *data) {
+ boost::shared_ptr<UserList> users(new UserList);
+
+ const XmlData::List *userList = data->getList("users");
+
+ if(userList) {
+ for(XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ users->push_back(deserializeUserListEntry(user));
+ }
+
+ return users;
+}
+
+void Util::serializeUserListDiff(const UserListDiff *diff, XmlData *data) {
+ 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());
+
+ 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 XmlData *data) {
+ boost::shared_ptr<UserListDiff> diff(new UserListDiff);
+
+ const XmlData::List *userList = data->getList("addedUsers");
+ if(userList) {
+ for(XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ diff->insertAddedUser(deserializeUserListEntry(user));
+ }
+
+ userList = data->getList("deletedUsers");
+ if(userList) {
+ for(XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ diff->insertDeletedUser(deserializeUserListEntry(user));
+ }
+
+ userList = data->getList("unchangedUsers");
+ if(userList) {
+ for(XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ diff->insertUnchangedUser(deserializeUserListEntry(user));
+ }
+
+ return diff;
+}
+
+}
+}
+}
diff --git a/src/Common/UserLists/Util.h b/src/Common/UserLists/Util.h
new file mode 100644
index 0000000..df7f203
--- /dev/null
+++ b/src/Common/UserLists/Util.h
@@ -0,0 +1,55 @@
+/*
+ * Util.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_COMMON_USERLISTS_UTIL_H_
+#define MAD_COMMON_USERLISTS_UTIL_H_
+
+#include "../export.h"
+
+#include "../XmlData.h"
+#include <boost/shared_ptr.hpp>
+
+namespace Mad {
+namespace Common {
+namespace UserLists {
+
+class UserList;
+class UserListDiff;
+class UserListEntry;
+
+class MAD_COMMON_EXPORT Util {
+ private:
+ static void serializeUserListEntry(const UserListEntry *user, XmlData::List::iterator entry);
+ static UserListEntry deserializeUserListEntry(XmlData::List::const_iterator entry);
+
+ Util();
+
+ public:
+ static void serializeUserList(const UserList *list, XmlData *data);
+ static boost::shared_ptr<UserList> deserializeUserList(const XmlData *data);
+
+ static void serializeUserListDiff(const UserListDiff *diff, XmlData *data);
+ static boost::shared_ptr<UserListDiff> deserializeUserListDiff(const XmlData *data);
+};
+
+}
+}
+}
+
+#endif /* MAD_COMMON_USERLISTS_UTIL_H_ */