summaryrefslogtreecommitdiffstats
path: root/src/Server
diff options
context:
space:
mode:
Diffstat (limited to 'src/Server')
-rw-r--r--src/Server/RequestHandlers/UserInfoRequestHandler.cpp30
-rw-r--r--src/Server/RequestHandlers/UserInfoRequestHandler.h6
-rw-r--r--src/Server/RequestHandlers/UserListRequestHandler.cpp39
-rw-r--r--src/Server/RequestHandlers/UserListRequestHandler.h6
-rw-r--r--src/Server/UserBackend.h15
-rw-r--r--src/Server/UserManager.cpp38
-rw-r--r--src/Server/UserManager.h23
7 files changed, 70 insertions, 87 deletions
diff --git a/src/Server/RequestHandlers/UserInfoRequestHandler.cpp b/src/Server/RequestHandlers/UserInfoRequestHandler.cpp
index 740c2a9..287d026 100644
--- a/src/Server/RequestHandlers/UserInfoRequestHandler.cpp
+++ b/src/Server/RequestHandlers/UserInfoRequestHandler.cpp
@@ -22,8 +22,6 @@
#include <Net/Exception.h>
#include <Common/Logger.h>
-#include <boost/bind.hpp>
-
namespace Mad {
namespace Server {
namespace RequestHandlers {
@@ -44,24 +42,22 @@ void UserInfoRequestHandler::handlePacket(const Common::XmlPacket &packet) {
// TODO Require authentication
- if(!UserManager::get()->getUserInfo(packet["uid"], boost::bind(&UserInfoRequestHandler::userInfoHandler, this, _1))) {
- Common::XmlPacket ret;
- ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED);
-
- sendPacket(ret);
- signalFinished()();
- }
-}
+ boost::shared_ptr<Common::UserInfo> info = UserManager::get()->getUserInfo(packet["uid"]);
-void UserInfoRequestHandler::userInfoHandler(const Common::UserInfo &info) {
Common::XmlPacket ret;
- ret.setType("OK");
- ret.add("uid", info.getUid());
- ret.add("gid", info.getGid());
- ret.add("username", info.getUsername());
- ret.add("fullName", info.getFullName());
+ if(info) {
+ ret.setType("OK");
+
+ ret.add("uid", info->getUid());
+ ret.add("gid", info->getGid());
+ ret.add("username", info->getUsername());
+ ret.add("fullName", info->getFullName());
+ }
+ else {
+ ret.setType("Error");
+ ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED);
+ }
sendPacket(ret);
signalFinished()();
diff --git a/src/Server/RequestHandlers/UserInfoRequestHandler.h b/src/Server/RequestHandlers/UserInfoRequestHandler.h
index 5b1d466..90032f0 100644
--- a/src/Server/RequestHandlers/UserInfoRequestHandler.h
+++ b/src/Server/RequestHandlers/UserInfoRequestHandler.h
@@ -21,18 +21,12 @@
#define MAD_SERVER_REQUESTHANDLERS_USERINFOREQUESTHANDLER_H_
#include <Common/RequestHandler.h>
-#include <Common/UserInfo.h>
-
-#include <map>
namespace Mad {
namespace Server {
namespace RequestHandlers {
class UserInfoRequestHandler : public Common::RequestHandler {
- private:
- void userInfoHandler(const Common::UserInfo &info);
-
protected:
virtual void handlePacket(const Common::XmlPacket &packet);
diff --git a/src/Server/RequestHandlers/UserListRequestHandler.cpp b/src/Server/RequestHandlers/UserListRequestHandler.cpp
index cd05c12..713753b 100644
--- a/src/Server/RequestHandlers/UserListRequestHandler.cpp
+++ b/src/Server/RequestHandlers/UserListRequestHandler.cpp
@@ -22,8 +22,6 @@
#include <Net/Exception.h>
#include <Common/Logger.h>
-#include <boost/bind.hpp>
-
namespace Mad {
namespace Server {
namespace RequestHandlers {
@@ -44,29 +42,28 @@ void UserListRequestHandler::handlePacket(const Common::XmlPacket &packet) {
// TODO Require authentication
- if(!UserManager::get()->getUserList(boost::bind(&UserListRequestHandler::userListHandler, this, _1))) {
- Common::XmlPacket ret;
- ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED);
-
- sendPacket(ret);
- signalFinished()();
- }
-}
+ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > info = UserManager::get()->getUserList();
-void UserListRequestHandler::userListHandler(const std::map<unsigned long, Common::UserInfo> &info) {
Common::XmlPacket ret;
- ret.setType("OK");
- ret.addList("users");
- for(std::map<unsigned long, Common::UserInfo>::const_iterator user = info.begin(); user != info.end(); ++user) {
- ret["users"].addEntry();
- Common::XmlPacket::Entry &entry = ret["users"].back();
+ if(info) {
+ ret.setType("OK");
+ ret.addList("users");
- entry.add("uid", user->second.getUid());
- entry.add("gid", user->second.getGid());
- entry.add("username", user->second.getUsername());
- entry.add("fullName", user->second.getFullName());
+ for(std::map<unsigned long, Common::UserInfo>::iterator user = info->begin(); user != info->end(); ++user) {
+ ret["users"].addEntry();
+ Common::XmlPacket::Entry &entry = ret["users"].back();
+
+ entry.add("uid", user->second.getUid());
+ entry.add("gid", user->second.getGid());
+ entry.add("username", user->second.getUsername());
+ entry.add("fullName", user->second.getFullName());
+ }
+ }
+
+ else {
+ ret.setType("Error");
+ ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED);
}
sendPacket(ret);
diff --git a/src/Server/RequestHandlers/UserListRequestHandler.h b/src/Server/RequestHandlers/UserListRequestHandler.h
index 7c85aa0..4b1a385 100644
--- a/src/Server/RequestHandlers/UserListRequestHandler.h
+++ b/src/Server/RequestHandlers/UserListRequestHandler.h
@@ -21,18 +21,12 @@
#define MAD_SERVER_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_
#include <Common/RequestHandler.h>
-#include <Common/UserInfo.h>
-
-#include <map>
namespace Mad {
namespace Server {
namespace RequestHandlers {
class UserListRequestHandler : public Common::RequestHandler {
- private:
- void userListHandler(const std::map<unsigned long, Common::UserInfo> &info);
-
protected:
virtual void handlePacket(const Common::XmlPacket &packet);
diff --git a/src/Server/UserBackend.h b/src/Server/UserBackend.h
index 6aac7bc..a673fa9 100644
--- a/src/Server/UserBackend.h
+++ b/src/Server/UserBackend.h
@@ -27,7 +27,7 @@
#include <map>
#include <string>
-#include <boost/signal.hpp>
+#include <boost/smart_ptr.hpp>
namespace Mad {
@@ -41,19 +41,20 @@ class UserBackend {
UserBackend() {}
- virtual bool getUserList(const boost::function1<void, const std::map<unsigned long, Common::UserInfo>& > &callback _UNUSED_PARAMETER_) {
- return false;
+ virtual boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList() {
+ return boost::shared_ptr<std::map<unsigned long, Common::UserInfo> >();
}
- virtual bool getUserInfo(unsigned long uid _UNUSED_PARAMETER_, const boost::function1<void, const Common::UserInfo&> &callback _UNUSED_PARAMETER_) {
- return false;
+ virtual boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid _UNUSED_PARAMETER_) {
+ return boost::shared_ptr<Common::UserInfo>();
}
- virtual bool setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string&, const boost::function1<void, bool> &callback _UNUSED_PARAMETER_) {
+ // TODO Better interface...
+ virtual bool setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_) {
return false;
}
- virtual bool addUser(const Common::UserInfo &userInfo _UNUSED_PARAMETER_, const boost::function1<void, bool> &callback _UNUSED_PARAMETER_) {
+ virtual bool addUser(const Common::UserInfo &userInfo _UNUSED_PARAMETER_) {
return false;
}
diff --git a/src/Server/UserManager.cpp b/src/Server/UserManager.cpp
index d763a8b..3b5887a 100644
--- a/src/Server/UserManager.cpp
+++ b/src/Server/UserManager.cpp
@@ -26,44 +26,46 @@ namespace Server {
UserManager UserManager::userManager;
-bool UserManager::Compare::operator() (const UserBackend *b1, const UserBackend *b2) {
+bool UserManager::Compare::operator() (boost::shared_ptr<UserBackend> b1, boost::shared_ptr<UserBackend> b2) {
if(b1->getPriority() == b2->getPriority())
- return (b1 > b2);
+ return (b1.get() > b2.get());
else
return (b1->getPriority() > b2->getPriority());
}
-bool UserManager::getUserList(const boost::function1<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
- for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->getUserList(callback))
- return true;
+boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserManager::getUserList() {
+ for(std::set<boost::shared_ptr<UserBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > ret = (*backend)->getUserList();
+ if(ret)
+ return ret;
}
- return false;
+ return boost::shared_ptr<std::map<unsigned long, Common::UserInfo> >();
}
-bool UserManager::getUserInfo(unsigned long uid, const boost::function1<void, const Common::UserInfo&> &callback) {
- for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->getUserInfo(uid, callback))
- return true;
+boost::shared_ptr<Common::UserInfo> UserManager::getUserInfo(unsigned long uid) {
+ for(std::set<boost::shared_ptr<UserBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ boost::shared_ptr<Common::UserInfo> ret = (*backend)->getUserInfo(uid);
+ if(ret)
+ return ret;
}
- return false;
+ return boost::shared_ptr<Common::UserInfo>();
}
-bool UserManager::setPassword(unsigned long uid, const std::string &password, const boost::function1<void, bool> &callback) {
- for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->setPassword(uid, password, callback))
+bool UserManager::setPassword(unsigned long uid, const std::string &password) {
+ for(std::set<boost::shared_ptr<UserBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ if((*backend)->setPassword(uid, password))
return true;
}
return false;
}
-bool UserManager::addUser(const Common::UserInfo &userInfo, const boost::function1<void, bool> &callback) {
- for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->addUser(userInfo, callback))
+bool UserManager::addUser(const Common::UserInfo &userInfo) {
+ for(std::set<boost::shared_ptr<UserBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ if((*backend)->addUser(userInfo))
return true;
}
diff --git a/src/Server/UserManager.h b/src/Server/UserManager.h
index d0e7074..c3d990d 100644
--- a/src/Server/UserManager.h
+++ b/src/Server/UserManager.h
@@ -25,42 +25,41 @@
#include <map>
#include <set>
-#include <boost/function.hpp>
+#include <boost/smart_ptr.hpp>
+#include <boost/noncopyable.hpp>
namespace Mad {
namespace Server {
class UserBackend;
-class UserManager {
+class UserManager : boost::noncopyable {
private:
struct Compare {
- bool operator() (const UserBackend *b1, const UserBackend *b2);
+ bool operator() (boost::shared_ptr<UserBackend> b1, boost::shared_ptr<UserBackend> b2);
};
static UserManager userManager;
- std::set<UserBackend*, Compare> backends;
+ std::set<boost::shared_ptr<UserBackend>, Compare> backends;
UserManager() {}
public:
- void registerBackend(UserBackend *backend) {
+ void registerBackend(boost::shared_ptr<UserBackend> backend) {
backends.insert(backend);
}
- void unregisterBackend(UserBackend *backend) {
+ void unregisterBackend(boost::shared_ptr<UserBackend> backend) {
backends.erase(backend);
}
+ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList();
+ boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid);
- bool getUserList(const boost::function1<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
- bool getUserInfo(unsigned long uid, const boost::function1<void, const Common::UserInfo&> &callback);
-
- bool setPassword(unsigned long uid, const std::string &password, const boost::function1<void, bool> &callback);
-
- bool addUser(const Common::UserInfo &userInfo, const boost::function1<void, bool> &callback);
+ bool setPassword(unsigned long uid, const std::string &password);
+ bool addUser(const Common::UserInfo &userInfo);
static UserManager *get() {
return &userManager;