summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-07-11 01:11:21 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-07-11 01:11:21 +0200
commitbf4c6ec2b7694f1a844eef5989b77e83a8cab362 (patch)
treea407ccab48195d61d4e04ccf8581b1328fd08e72 /src/Common
parentb8aa377d883c316f544274dd24db9f079fb8f02a (diff)
downloadmad-bf4c6ec2b7694f1a844eef5989b77e83a8cab362.tar
mad-bf4c6ec2b7694f1a844eef5989b77e83a8cab362.zip
Befehle add_user_to_group und delete_user_from_group implementiert
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Backends/NetworkUserBackend.cpp33
-rw-r--r--src/Common/Backends/NetworkUserBackend.h17
-rw-r--r--src/Common/UserBackend.h8
-rw-r--r--src/Common/UserCache.h8
-rw-r--r--src/Common/UserManager.cpp34
-rw-r--r--src/Common/UserManager.h3
6 files changed, 103 insertions, 0 deletions
diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp
index 1e06a78..6296581 100644
--- a/src/Common/Backends/NetworkUserBackend.cpp
+++ b/src/Common/Backends/NetworkUserBackend.cpp
@@ -83,6 +83,15 @@ void NetworkUserBackend::UserUpdateRequest::sendRequest() {
sendPacket(packet);
}
+void NetworkUserBackend::UserGroupRequest::sendRequest() {
+ XmlPacket packet;
+ packet.setType(type);
+ packet.set("uid", uid);
+ packet.set("gid", gid);
+
+ sendPacket(packet);
+}
+
boost::shared_ptr<const std::map<unsigned long, UserInfo> > NetworkUserBackend::getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
application->getThreadManager()->detach();
@@ -406,6 +415,30 @@ void NetworkUserBackend::deleteUser(unsigned long uid) throw(Core::Exception) {
throw result.second;
}
+void NetworkUserBackend::addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::shared_ptr<UserGroupRequest> request(new UserGroupRequest(application, "AddUserToGroup", uid, 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;
+}
+
+void NetworkUserBackend::deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::shared_ptr<UserGroupRequest> request(new UserGroupRequest(application, "DeleteUserFromGroup", uid, 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;
+}
+
}
}
}
diff --git a/src/Common/Backends/NetworkUserBackend.h b/src/Common/Backends/NetworkUserBackend.h
index b932e87..0567514 100644
--- a/src/Common/Backends/NetworkUserBackend.h
+++ b/src/Common/Backends/NetworkUserBackend.h
@@ -96,6 +96,20 @@ class NetworkUserBackend : public UserBackend {
: Request(application), uid(uid0), userInfo(userInfo0) {}
};
+ class UserGroupRequest : public Request {
+ private:
+ std::string type;
+ unsigned long uid;
+ unsigned long gid;
+
+ protected:
+ virtual void sendRequest();
+
+ public:
+ UserGroupRequest(Application *application, const std::string &type0, unsigned long uid0, unsigned long gid0)
+ : Request(application), type(type0), uid(uid0), gid(gid0) {}
+ };
+
Application *application;
Connection *connection;
@@ -118,6 +132,9 @@ class NetworkUserBackend : public UserBackend {
virtual void updateUser(unsigned long uid, const Common::UserInfo &userInfo) throw(Core::Exception);
virtual void deleteUser(unsigned long uid) throw(Core::Exception);
+ virtual void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception);
+ virtual void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception);
+
public:
NetworkUserBackend(Application *application0, Connection *connection0) : application(application0), connection(connection0) {}
};
diff --git a/src/Common/UserBackend.h b/src/Common/UserBackend.h
index 2e42e12..9eb59d3 100644
--- a/src/Common/UserBackend.h
+++ b/src/Common/UserBackend.h
@@ -113,6 +113,14 @@ class UserBackend {
throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED));
}
+ virtual void addUserToGroup(unsigned long uid _UNUSED_PARAMETER_, unsigned long gid _UNUSED_PARAMETER_) throw(Core::Exception) {
+ throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED));
+ }
+
+ virtual void deleteUserFromGroup(unsigned long uid _UNUSED_PARAMETER_, unsigned long gid _UNUSED_PARAMETER_) throw(Core::Exception) {
+ throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED));
+ }
+
public:
virtual ~UserBackend() {}
diff --git a/src/Common/UserCache.h b/src/Common/UserCache.h
index e778e24..1425908 100644
--- a/src/Common/UserCache.h
+++ b/src/Common/UserCache.h
@@ -98,6 +98,14 @@ class UserCache : public UserBackend, private boost::noncopyable {
backend->deleteGroup(gid);
}
+ virtual void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) {
+ backend->addUserToGroup(uid, gid);
+ }
+
+ virtual void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) {
+ backend->deleteUserFromGroup(uid, gid);
+ }
+
UserCache(Application *application0, boost::shared_ptr<UserBackend> backend0) : application(application0), backend(backend0),
userTime(boost::posix_time::not_a_date_time), groupTime(boost::posix_time::not_a_date_time),
userGroupTime(boost::posix_time::not_a_date_time) {}
diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp
index 14451aa..928289b 100644
--- a/src/Common/UserManager.cpp
+++ b/src/Common/UserManager.cpp
@@ -326,5 +326,39 @@ void UserManager::deleteGroup(unsigned long gid) throw(Core::Exception) {
throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
}
+void UserManager::addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) {
+ boost::lock_guard<boost::shared_mutex> lock(mutex);
+
+ for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ try {
+ backend->second->addUserToGroup(uid, gid);
+ return;
+ }
+ catch(Core::Exception e) {
+ if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
+ throw e;
+ }
+ }
+
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+}
+
+void UserManager::deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) {
+ boost::lock_guard<boost::shared_mutex> lock(mutex);
+
+ for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ try {
+ backend->second->deleteUserFromGroup(uid, gid);
+ return;
+ }
+ catch(Core::Exception e) {
+ if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
+ throw e;
+ }
+ }
+
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+}
+
}
}
diff --git a/src/Common/UserManager.h b/src/Common/UserManager.h
index 466b9a9..d2529e7 100644
--- a/src/Common/UserManager.h
+++ b/src/Common/UserManager.h
@@ -90,6 +90,9 @@ class UserManager : private boost::noncopyable {
void addGroup(const GroupInfo &groupInfo) throw(Core::Exception);
void updateGroup(unsigned long gid, const GroupInfo &groupInfo) throw(Core::Exception);
void deleteGroup(unsigned long gid) throw(Core::Exception);
+
+ void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception);
+ void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception);
};
}