summaryrefslogtreecommitdiffstats
path: root/src/Server
diff options
context:
space:
mode:
Diffstat (limited to 'src/Server')
-rw-r--r--src/Server/RequestHandlers/GroupListRequestHandler.cpp14
-rw-r--r--src/Server/RequestHandlers/UserInfoRequestHandler.cpp13
-rw-r--r--src/Server/RequestHandlers/UserListRequestHandler.cpp14
-rw-r--r--src/Server/UserBackend.h22
-rw-r--r--src/Server/UserManager.cpp78
-rw-r--r--src/Server/UserManager.h12
6 files changed, 99 insertions, 54 deletions
diff --git a/src/Server/RequestHandlers/GroupListRequestHandler.cpp b/src/Server/RequestHandlers/GroupListRequestHandler.cpp
index 1ca2b92..356e105 100644
--- a/src/Server/RequestHandlers/GroupListRequestHandler.cpp
+++ b/src/Server/RequestHandlers/GroupListRequestHandler.cpp
@@ -42,11 +42,13 @@ void GroupListRequestHandler::handlePacket(const Common::XmlPacket &packet) {
// TODO Require authentication
- boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > info = UserManager::get()->getGroupList();
+
Common::XmlPacket ret;
- if(info) {
+ try {
+ boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > info = UserManager::get()->getGroupList();
+
ret.setType("OK");
ret.addList("groups");
@@ -58,10 +60,12 @@ void GroupListRequestHandler::handlePacket(const Common::XmlPacket &packet) {
entry.add("name", group->second.getName());
}
}
-
- else {
+ catch(Net::Exception e) {
ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED);
+ ret.add("ErrorCode", e.getErrorCode());
+ ret.add("SubCode", e.getSubCode());
+ ret.add("SubSubCode", e.getSubSubCode());
+ ret.add("Where", e.getWhere());
}
sendPacket(ret);
diff --git a/src/Server/RequestHandlers/UserInfoRequestHandler.cpp b/src/Server/RequestHandlers/UserInfoRequestHandler.cpp
index 287d026..e4ef447 100644
--- a/src/Server/RequestHandlers/UserInfoRequestHandler.cpp
+++ b/src/Server/RequestHandlers/UserInfoRequestHandler.cpp
@@ -42,11 +42,11 @@ void UserInfoRequestHandler::handlePacket(const Common::XmlPacket &packet) {
// TODO Require authentication
- boost::shared_ptr<Common::UserInfo> info = UserManager::get()->getUserInfo(packet["uid"]);
-
Common::XmlPacket ret;
- if(info) {
+ try {
+ boost::shared_ptr<Common::UserInfo> info = UserManager::get()->getUserInfo(packet["uid"]);
+
ret.setType("OK");
ret.add("uid", info->getUid());
@@ -54,9 +54,12 @@ void UserInfoRequestHandler::handlePacket(const Common::XmlPacket &packet) {
ret.add("username", info->getUsername());
ret.add("fullName", info->getFullName());
}
- else {
+ catch(Net::Exception e) {
ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED);
+ ret.add("ErrorCode", e.getErrorCode());
+ ret.add("SubCode", e.getSubCode());
+ ret.add("SubSubCode", e.getSubSubCode());
+ ret.add("Where", e.getWhere());
}
sendPacket(ret);
diff --git a/src/Server/RequestHandlers/UserListRequestHandler.cpp b/src/Server/RequestHandlers/UserListRequestHandler.cpp
index 713753b..37db6d5 100644
--- a/src/Server/RequestHandlers/UserListRequestHandler.cpp
+++ b/src/Server/RequestHandlers/UserListRequestHandler.cpp
@@ -42,11 +42,11 @@ void UserListRequestHandler::handlePacket(const Common::XmlPacket &packet) {
// TODO Require authentication
- boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > info = UserManager::get()->getUserList();
-
Common::XmlPacket ret;
- if(info) {
+ try {
+ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > info = UserManager::get()->getUserList();
+
ret.setType("OK");
ret.addList("users");
@@ -60,10 +60,12 @@ void UserListRequestHandler::handlePacket(const Common::XmlPacket &packet) {
entry.add("fullName", user->second.getFullName());
}
}
-
- else {
+ catch(Net::Exception e) {
ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED);
+ ret.add("ErrorCode", e.getErrorCode());
+ ret.add("SubCode", e.getSubCode());
+ ret.add("SubSubCode", e.getSubSubCode());
+ ret.add("Where", e.getWhere());
}
sendPacket(ret);
diff --git a/src/Server/UserBackend.h b/src/Server/UserBackend.h
index 6d59615..2a51d1b 100644
--- a/src/Server/UserBackend.h
+++ b/src/Server/UserBackend.h
@@ -25,6 +25,8 @@
#include <Common/UserInfo.h>
#include <Common/GroupInfo.h>
+#include <Net/Exception.h>
+
#include <map>
#include <string>
@@ -42,25 +44,25 @@ class UserBackend {
UserBackend() {}
- virtual boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList() {
- return boost::shared_ptr<std::map<unsigned long, Common::UserInfo> >();
+ virtual boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList() throw(Net::Exception) {
+ throw(Net::Exception(Net::Exception::NOT_IMPLEMENTED));
}
- virtual boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid _UNUSED_PARAMETER_) {
- return boost::shared_ptr<Common::UserInfo>();
+ virtual boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid _UNUSED_PARAMETER_) throw(Net::Exception) {
+ throw(Net::Exception(Net::Exception::NOT_IMPLEMENTED));
}
- virtual boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > getGroupList() {
- return boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> >();
+ virtual boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > getGroupList() throw(Net::Exception) {
+ throw(Net::Exception(Net::Exception::NOT_IMPLEMENTED));
}
// TODO Better interface...
- virtual bool setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_) {
- return false;
+ virtual void setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_) throw(Net::Exception) {
+ throw(Net::Exception(Net::Exception::NOT_IMPLEMENTED));
}
- virtual bool addUser(const Common::UserInfo &userInfo _UNUSED_PARAMETER_) {
- return false;
+ virtual void addUser(const Common::UserInfo &userInfo _UNUSED_PARAMETER_) throw(Net::Exception) {
+ throw(Net::Exception(Net::Exception::NOT_IMPLEMENTED));
}
virtual int getPriority() const {
diff --git a/src/Server/UserManager.cpp b/src/Server/UserManager.cpp
index e32cb57..7101b2c 100644
--- a/src/Server/UserManager.cpp
+++ b/src/Server/UserManager.cpp
@@ -34,52 +34,84 @@ bool UserManager::Compare::operator() (boost::shared_ptr<UserBackend> b1, boost:
}
-boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserManager::getUserList() {
+boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserManager::getUserList() throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
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;
+ try {
+ return (*backend)->getUserList();
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return boost::shared_ptr<std::map<unsigned long, Common::UserInfo> >();
+ throw e;
}
-boost::shared_ptr<Common::UserInfo> UserManager::getUserInfo(unsigned long uid) {
+boost::shared_ptr<Common::UserInfo> UserManager::getUserInfo(unsigned long uid) throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
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;
+ try {
+ return (*backend)->getUserInfo(uid);
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return boost::shared_ptr<Common::UserInfo>();
+ throw e;
}
-boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserManager::getGroupList() {
+boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserManager::getGroupList() throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
for(std::set<boost::shared_ptr<UserBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > ret = (*backend)->getGroupList();
- if(ret)
- return ret;
+ try {
+ return (*backend)->getGroupList();
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> >();
+ throw e;
}
-bool UserManager::setPassword(unsigned long uid, const std::string &password) {
+void UserManager::setPassword(unsigned long uid, const std::string &password) throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
for(std::set<boost::shared_ptr<UserBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->setPassword(uid, password))
- return true;
+ try {
+ return (*backend)->setPassword(uid, password);
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return false;
+ throw e;
}
-bool UserManager::addUser(const Common::UserInfo &userInfo) {
+void UserManager::addUser(const Common::UserInfo &userInfo) throw(Net::Exception) {
+ Net::Exception e(Net::Exception::NOT_IMPLEMENTED);
+
for(std::set<boost::shared_ptr<UserBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->addUser(userInfo))
- return true;
+ try {
+ return (*backend)->addUser(userInfo);
+ }
+ catch(Net::Exception e2) {
+ if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED)
+ e = e2;
+ }
}
- return false;
+ throw e;
}
}
diff --git a/src/Server/UserManager.h b/src/Server/UserManager.h
index e33b678..3377727 100644
--- a/src/Server/UserManager.h
+++ b/src/Server/UserManager.h
@@ -23,6 +23,8 @@
#include <Common/UserInfo.h>
#include <Common/GroupInfo.h>
+#include <Net/Exception.h>
+
#include <map>
#include <set>
@@ -55,14 +57,14 @@ class UserManager : boost::noncopyable {
backends.erase(backend);
}
- boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList();
- boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid);
+ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList() throw(Net::Exception);
+ boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid) throw(Net::Exception);
- boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > getGroupList();
+ boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > getGroupList() throw(Net::Exception);
- bool setPassword(unsigned long uid, const std::string &password);
+ void setPassword(unsigned long uid, const std::string &password) throw(Net::Exception);
- bool addUser(const Common::UserInfo &userInfo);
+ void addUser(const Common::UserInfo &userInfo) throw(Net::Exception);
static UserManager *get() {
return &userManager;