summaryrefslogtreecommitdiffstats
path: root/src/Common/Backends
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-24 00:04:28 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-24 00:04:28 +0200
commitdff7c00a0c2c3fcb64efd611d70398d711ad861b (patch)
tree93c1556c15987b37e8d2ba3421cb246006a02eac /src/Common/Backends
parent02b9e16833acbdaa820bd3b8b64d652a41a8ff58 (diff)
downloadmad-dff7c00a0c2c3fcb64efd611d70398d711ad861b.tar
mad-dff7c00a0c2c3fcb64efd611d70398d711ad861b.zip
NetworkUserBackend implementiert
Diffstat (limited to 'src/Common/Backends')
-rw-r--r--src/Common/Backends/CMakeLists.txt6
-rw-r--r--src/Common/Backends/NetworkUserBackend.cpp203
-rw-r--r--src/Common/Backends/NetworkUserBackend.h91
3 files changed, 300 insertions, 0 deletions
diff --git a/src/Common/Backends/CMakeLists.txt b/src/Common/Backends/CMakeLists.txt
new file mode 100644
index 0000000..4d9d30e
--- /dev/null
+++ b/src/Common/Backends/CMakeLists.txt
@@ -0,0 +1,6 @@
+include_directories(${INCLUDES})
+
+add_library(Backends STATIC
+ NetworkUserBackend.cpp NetworkUserBackend.h
+)
+target_link_libraries(Backends Common)
diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp
new file mode 100644
index 0000000..81fc94a
--- /dev/null
+++ b/src/Common/Backends/NetworkUserBackend.cpp
@@ -0,0 +1,203 @@
+/*
+ * NetworkUserBackend.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 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "NetworkUserBackend.h"
+#include "../RequestManager.h"
+
+namespace Mad {
+namespace Common {
+namespace Backends {
+
+void NetworkUserBackend::IdUserRequest::sendRequest() {
+ Common::XmlPacket packet;
+ packet.setType(type);
+ packet.set(idType, id);
+
+ sendPacket(packet);
+}
+
+void NetworkUserBackend::NameUserRequest::sendRequest() {
+ Common::XmlPacket packet;
+ packet.setType(type);
+ packet.set("name", name);
+
+ 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"));
+ 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>);
+
+ const XmlPacket::List *users = result.first->getList("users");
+ if(users) {
+ 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"));
+ userInfo.setFullName(user->get<const std::string&>("fullName"));
+
+ userList->insert(std::make_pair(userInfo.getUid(), userInfo));
+ }
+ }
+
+ return userList;
+}
+
+boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfo(unsigned long uid) throw(Core::Exception) {
+ boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "GetUserInfo", "uid", uid));
+ 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<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"));
+
+ return 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));
+ 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<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"));
+
+ return 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));
+ 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::set<unsigned long> > groupList(new std::set<unsigned long>);
+
+ const XmlPacket::List *groups = result.first->getList("groups");
+ if(groups) {
+ for(XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group)
+ groupList->insert(group->get<unsigned long>("gid"));
+ }
+
+ return groupList;
+}
+
+boost::shared_ptr<const std::map<unsigned long, GroupInfo> > NetworkUserBackend::getGroupList() throw(Core::Exception) {
+ boost::shared_ptr<SimpleUserRequest> request(new SimpleUserRequest(application, "ListGroups"));
+ 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, GroupInfo> > groupList(new std::map<unsigned long, GroupInfo>);
+
+ const XmlPacket::List *groups = result.first->getList("groups");
+ if(groups) {
+ 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;
+}
+
+boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfo(unsigned long gid) throw(Core::Exception) {
+ boost::shared_ptr<IdUserRequest> request(new IdUserRequest(application, "GetGroupInfo", "gid", gid));
+ 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<GroupInfo> groupInfo(new GroupInfo(result.first->get<unsigned long>("gid"), result.first->get<const std::string&>("name")));
+
+ return 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));
+ 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<GroupInfo> groupInfo(new GroupInfo(result.first->get<unsigned long>("gid"), result.first->get<const std::string&>("name")));
+
+ return 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));
+ 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::set<unsigned long> > userList(new std::set<unsigned long>);
+
+ const XmlPacket::List *users = result.first->getList("users");
+ if(users) {
+ for(XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user) {
+ userList->insert(user->get<unsigned long>("uid"));
+ }
+ }
+
+ return userList;
+}
+
+
+/*void NetworkUserBackend::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) {
+
+}*/
+
+
+/*void NetworkUserBackend::addUser(const UserInfo &userInfo) throw(Core::Exception) {
+
+}*/
+
+}
+}
+}
diff --git a/src/Common/Backends/NetworkUserBackend.h b/src/Common/Backends/NetworkUserBackend.h
new file mode 100644
index 0000000..c569ab6
--- /dev/null
+++ b/src/Common/Backends/NetworkUserBackend.h
@@ -0,0 +1,91 @@
+/*
+ * NetworkUserBackend.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 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_COMMON_BACKENDS_NETWORKUSERBACKEND_H_
+#define MAD_COMMON_BACKENDS_NETWORKUSERBACKEND_H_
+
+#include "../UserBackend.h"
+#include "../Requests/SimpleRequest.h"
+
+namespace Mad {
+namespace Common {
+namespace Backends {
+
+class NetworkUserBackend : public UserBackend {
+ private:
+ class SimpleUserRequest : public Requests::SimpleRequest {
+ public:
+ SimpleUserRequest(Application *application, const std::string &type) : SimpleRequest(application, type) {}
+ };
+
+ class IdUserRequest : public Request {
+ private:
+ std::string type;
+ std::string idType;
+ unsigned long id;
+
+
+ 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) {}
+ };
+
+ class NameUserRequest : public Request {
+ private:
+ std::string type;
+ std::string name;
+
+
+ protected:
+ virtual void sendRequest();
+
+ public:
+ NameUserRequest(Application *application, const std::string &type0, const std::string &name0)
+ : Request(application), type(type0), name(name0) {}
+ };
+
+ 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, 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 void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception);
+ //virtual void addUser(const UserInfo &userInfo) throw(Core::Exception);
+
+ public:
+ NetworkUserBackend(Application *application0, Connection *connection0) : application(application0), connection(connection0) {}
+};
+
+}
+}
+}
+
+#endif /* MAD_COMMON_BACKENDS_NETWORKUSERBACKEND_H_ */