summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.cpp20
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.h6
8 files changed, 112 insertions, 67 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;
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp
index 139a416..9b960fd 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.cpp
+++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp
@@ -132,7 +132,7 @@ void UserBackendMysql::configFinished() {
}
-boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserBackendMysql::getUserList() {
+boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserBackendMysql::getUserList() throw(Net::Exception) {
Net::ThreadManager::get()->detach();
mysql_ping(mysql);
@@ -140,8 +140,8 @@ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserBackendMysql::
mysql_real_query(mysql, queryListUsers.c_str(), queryListUsers.length());
MYSQL_RES *result = mysql_use_result(mysql);
- if(mysql_num_fields(result) < 4)
- return boost::shared_ptr<std::map<unsigned long, Common::UserInfo> >(); // TODO Error
+ if(!result || mysql_num_fields(result) < 4)
+ throw Net::Exception(Net::Exception::NOT_AVAILABLE);
boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > users(new std::map<unsigned long, Common::UserInfo>());
@@ -157,7 +157,7 @@ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserBackendMysql::
return users;
}
-boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long uid) {
+boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long uid) throw(Net::Exception) {
Net::ThreadManager::get()->detach();
mysql_ping(mysql);
@@ -174,8 +174,8 @@ boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long
mysql_real_query(mysql, query.c_str(), query.length());
MYSQL_RES *result = mysql_use_result(mysql);
- if(mysql_num_fields(result) < 4)
- return boost::shared_ptr<Common::UserInfo>(); // TODO Error
+ if(!result || mysql_num_fields(result) < 4)
+ throw Net::Exception(Net::Exception::NOT_AVAILABLE);
MYSQL_ROW row = mysql_fetch_row(result);
@@ -190,10 +190,10 @@ boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long
return user;
}
- return boost::shared_ptr<Common::UserInfo>();
+ throw Net::Exception(Net::Exception::NOT_AVAILABLE);
}
-boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserBackendMysql::getGroupList() {
+boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserBackendMysql::getGroupList() throw(Net::Exception) {
Net::ThreadManager::get()->detach();
mysql_ping(mysql);
@@ -201,8 +201,8 @@ boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserBackendMysql:
mysql_real_query(mysql, queryListGroups.c_str(), queryListGroups.length());
MYSQL_RES *result = mysql_use_result(mysql);
- if(mysql_num_fields(result) < 2)
- return boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> >(); // TODO Error
+ if(!result || mysql_num_fields(result) < 2)
+ throw Net::Exception(Net::Exception::NOT_AVAILABLE);
boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > groups(new std::map<unsigned long, Common::GroupInfo>());
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h
index 8a75a6b..1bf0f2b 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.h
+++ b/src/modules/UserBackendMysql/UserBackendMysql.h
@@ -50,10 +50,10 @@ class UserBackendMysql : public Server::UserBackend, private Common::Configurabl
virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool);
virtual void configFinished();
- virtual boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList();
- virtual boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid);
+ virtual boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList() throw(Net::Exception);
+ virtual boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid) throw(Net::Exception);
- virtual boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > getGroupList();
+ virtual boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > getGroupList() throw(Net::Exception);
public:
virtual ~UserBackendMysql() {