summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-07-07 18:51:35 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-07-07 18:51:35 +0200
commitc4cbe4a94fd63e0da6e291a481b9a9ccc71e7843 (patch)
tree54fc3c43aec1b08f6918add662574b35a355e363 /src/Common
parentf2f1d5b1da4f985bcbb0c075cf42efcacecae2a6 (diff)
downloadmad-c4cbe4a94fd63e0da6e291a481b9a9ccc71e7843.tar
mad-c4cbe4a94fd63e0da6e291a481b9a9ccc71e7843.zip
Added add_user command to client & UserBackendMysql
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Backends/NetworkUserBackend.cpp28
-rw-r--r--src/Common/Backends/NetworkUserBackend.h15
-rw-r--r--src/Common/UserManager.cpp22
3 files changed, 47 insertions, 18 deletions
diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp
index 27f65f5..a1cf415 100644
--- a/src/Common/Backends/NetworkUserBackend.cpp
+++ b/src/Common/Backends/NetworkUserBackend.cpp
@@ -27,7 +27,7 @@ namespace Common {
namespace Backends {
void NetworkUserBackend::SimpleUserRequest::sendRequest() {
- Common::XmlPacket packet;
+ XmlPacket packet;
packet.setType(type);
if(!timestamp.is_not_a_date_time())
@@ -37,7 +37,7 @@ void NetworkUserBackend::SimpleUserRequest::sendRequest() {
}
void NetworkUserBackend::IdUserRequest::sendRequest() {
- Common::XmlPacket packet;
+ XmlPacket packet;
packet.setType(type);
packet.set(idType, id);
@@ -48,7 +48,7 @@ void NetworkUserBackend::IdUserRequest::sendRequest() {
}
void NetworkUserBackend::NameUserRequest::sendRequest() {
- Common::XmlPacket packet;
+ XmlPacket packet;
packet.setType(type);
packet.set("name", name);
@@ -58,6 +58,18 @@ void NetworkUserBackend::NameUserRequest::sendRequest() {
sendPacket(packet);
}
+void NetworkUserBackend::UserAddRequest::sendRequest() {
+ XmlPacket packet;
+ packet.setType("AddUser");
+
+ packet.set("uid", userInfo.getUid());
+ packet.set("gid", userInfo.getGid());
+ packet.set("username", userInfo.getUsername());
+ packet.set("fullName", userInfo.getFullName());
+
+ sendPacket(packet);
+}
+
boost::shared_ptr<const std::map<unsigned long, UserInfo> > NetworkUserBackend::getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
boost::shared_ptr<SimpleUserRequest> request(new SimpleUserRequest(application, "ListUsers", timestamp));
application->getRequestManager()->sendRequest(connection, request);
@@ -327,9 +339,15 @@ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > NetworkUse
}*/
-/*void NetworkUserBackend::addUser(const UserInfo &userInfo) throw(Core::Exception) {
+void NetworkUserBackend::addUser(const UserInfo &userInfo) throw(Core::Exception) {
+ boost::shared_ptr<UserAddRequest> request(new UserAddRequest(application, userInfo));
+ 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 8faa8e3..9518790 100644
--- a/src/Common/Backends/NetworkUserBackend.h
+++ b/src/Common/Backends/NetworkUserBackend.h
@@ -71,6 +71,18 @@ class NetworkUserBackend : public UserBackend {
: Request(application), type(type0), name(name0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {}
};
+ class UserAddRequest : public Request {
+ private:
+ UserInfo userInfo;
+
+ protected:
+ virtual void sendRequest();
+
+ public:
+ UserAddRequest(Application *application, const UserInfo &userInfo0)
+ : Request(application), userInfo(userInfo0) {}
+ };
+
Application *application;
Connection *connection;
@@ -88,7 +100,8 @@ class NetworkUserBackend : public UserBackend {
virtual boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > getFullUserGroupList(boost::posix_time::ptime *timestamp) 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);
+
+ virtual void addUser(const UserInfo &userInfo) throw(Core::Exception);
public:
NetworkUserBackend(Application *application0, Connection *connection0) : application(application0), connection(connection0) {}
diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp
index 4031140..0ccf314 100644
--- a/src/Common/UserManager.cpp
+++ b/src/Common/UserManager.cpp
@@ -208,39 +208,37 @@ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > UserManage
}
void UserManager::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
-
boost::lock_guard<boost::shared_mutex> lock(mutex);
for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
try {
backend->second->setPassword(uid, password);
+ return;
}
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
+ catch(Core::Exception e) {
+ if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
+ throw e;
}
}
- throw e;
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
}
void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) {
- Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
-
boost::lock_guard<boost::shared_mutex> lock(mutex);
for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
try {
backend->second->addUser(userInfo);
+ return;
}
- catch(Core::Exception e2) {
- if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- e = e2;
+ catch(Core::Exception e) {
+ if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
+ throw e;
}
}
- throw e;
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
}
}