diff options
Diffstat (limited to 'src/modules/UserBackendMysql/UserBackendMysql.cpp')
-rw-r--r-- | src/modules/UserBackendMysql/UserBackendMysql.cpp | 71 |
1 files changed, 19 insertions, 52 deletions
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp index f0e9b2e..904c9a6 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.cpp +++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp @@ -22,7 +22,6 @@ #include "UserBackendMysql.h" #include <Core/ConfigEntry.h> #include <Core/ConfigManager.h> -#include <Core/Logger.h> #include <Core/ThreadManager.h> #include <sstream> @@ -33,8 +32,8 @@ namespace Mad { namespace Modules { +namespace UserBackendMysql { -boost::shared_ptr<UserBackendMysql> UserBackendMysql::backend; bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) { if(handled) @@ -65,7 +64,7 @@ bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool ha val = strtol(entry[1][0].c_str(), &endptr, 10); if(endptr != 0 || val < 0 || val > 65535) - Core::Logger::log(Core::Logger::WARNING, "UserBackendMysql: Invalid port"); + application->log(Core::LoggerBase::WARNING, "UserBackendMysql: Invalid port"); else port = val; } @@ -121,21 +120,19 @@ bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool ha void UserBackendMysql::configFinished() { if(db.empty()) { - Core::Logger::log(Core::Logger::ERROR, "UserBackendMysql: No database name given"); + application->log(Core::LoggerBase::ERROR, "UserBackendMysql: No database name given"); return; } mysql = mysql_init(0); mysql_real_connect(mysql, host.c_str(), username.c_str(), passwd.c_str(), db.c_str(), port, unixSocket.empty() ? 0 : unixSocket.c_str(), 0); - - Server::UserManager::get()->registerBackend(backend); } boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserBackendMysql::getUserList() throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); - if(mysql_ping(mysql)) + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); mysql_real_query(mysql, queryListUsers.c_str(), queryListUsers.length()); @@ -159,9 +156,9 @@ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserBackendMysql:: } boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long uid) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); - if(mysql_ping(mysql)) + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); std::string query = queryUserById; @@ -196,9 +193,9 @@ boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long } boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfoByName(const std::string &name) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); - if(mysql_ping(mysql)) + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); boost::scoped_array<char> escapedName(new char[name.length()*2+1]); @@ -230,9 +227,9 @@ boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfoByName(const st } boost::shared_ptr<std::set<unsigned long> > UserBackendMysql::getUserGroupList(unsigned long uid) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); - if(mysql_ping(mysql)) + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); std::ostringstream tmp; @@ -258,9 +255,9 @@ boost::shared_ptr<std::set<unsigned long> > UserBackendMysql::getUserGroupList(u boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserBackendMysql::getGroupList() throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); - if(mysql_ping(mysql)) + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); mysql_real_query(mysql, queryListGroups.c_str(), queryListGroups.length()); @@ -281,9 +278,9 @@ boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserBackendMysql: } std::string UserBackendMysql::getGroupName(unsigned long gid) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); - if(mysql_ping(mysql)) + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); std::string query = queryGroupById; @@ -310,9 +307,9 @@ std::string UserBackendMysql::getGroupName(unsigned long gid) throw(Core::Except } unsigned long UserBackendMysql::getGroupId(const std::string &name) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); - if(mysql_ping(mysql)) + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); boost::scoped_array<char> escapedName(new char[name.length()*2+1]); @@ -336,9 +333,9 @@ unsigned long UserBackendMysql::getGroupId(const std::string &name) throw(Core:: } boost::shared_ptr<std::set<unsigned long> > UserBackendMysql::getGroupUserList(unsigned long gid) throw(Core::Exception) { - Core::ThreadManager::get()->detach(); + application->getThreadManager()->detach(); - if(mysql_ping(mysql)) + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); std::ostringstream tmp; @@ -362,36 +359,6 @@ boost::shared_ptr<std::set<unsigned long> > UserBackendMysql::getGroupUserList(u return users; } - -void UserBackendMysql::registerBackend() { - if(backend) - return; - - backend.reset(new UserBackendMysql()); - Core::ConfigManager::get()->registerConfigurable(backend.get()); } - -void UserBackendMysql::unregisterBackend() { - if(!backend) - return; - - Core::ConfigManager::get()->unregisterConfigurable(backend.get()); - Server::UserManager::get()->unregisterBackend(backend); - - backend.reset(); } - -} -} - -extern "C" { - -void UserBackendMysql_init() { - Mad::Modules::UserBackendMysql::registerBackend(); -} - -void UserBackendMysql_deinit() { - Mad::Modules::UserBackendMysql::unregisterBackend(); -} - } |