summaryrefslogtreecommitdiffstats
path: root/src/modules/UserDBBackendMysql
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/UserDBBackendMysql')
-rw-r--r--src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp146
-rw-r--r--src/modules/UserDBBackendMysql/UserDBBackendMysql.h5
2 files changed, 27 insertions, 124 deletions
diff --git a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
index 1d213a8..be5426d 100644
--- a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
+++ b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
@@ -37,128 +37,32 @@ namespace UserDBBackendMysql {
const Core::String UserDBBackendMysql::name("UserDBBackendMysql");
-bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handled*/) {
- if(!entry[0].getKey().matches("UserManager"))
- return false;
+void UserDBBackendMysql::configure() {
+ host = application->getConfigManager()->get("UserManager.Mysql.Host");
+ username = application->getConfigManager()->get("UserManager.Mysql.Username");
+ passwd = application->getConfigManager()->get("UserManager.Mysql.Password");
+ db = application->getConfigManager()->get("UserManager.Mysql.Database");
+ port = std::strtol(application->getConfigManager()->get("UserManager.Mysql.Port").toString().c_str(), 0, 10);
+ unixSocket = application->getConfigManager()->get("UserManager.Mysql.UnixSocket");
+
+ queryListUsers = application->getConfigManager()->get("UserManager.Mysql.Queries.ListUsers");
+ queryListGroups = application->getConfigManager()->get("UserManager.Mysql.Queries.ListGroups");
+ queryListUserGroups = application->getConfigManager()->get("UserManager.Mysql.Queries.ListUserGroups");
+ queryListGroupUsers = application->getConfigManager()->get("UserManager.Mysql.Queries.ListGroupUsers");
+ queryUserById = application->getConfigManager()->get("UserManager.Mysql.Queries.UserById");
+ queryUserByName = application->getConfigManager()->get("UserManager.Mysql.Queries.UserByName");
+ queryGroupById = application->getConfigManager()->get("UserManager.Mysql.Queries.GroupById");
+ queryGroupByName = application->getConfigManager()->get("UserManager.Mysql.Queries.GroupByName");
+ queryUserGroupTable = application->getConfigManager()->get("UserManager.Mysql.Queries.UserGroupTable");
+ queryAddUser = application->getConfigManager()->get("UserManager.Mysql.Queries.AddUser");
+ queryUpdateUser = application->getConfigManager()->get("UserManager.Mysql.Queries.UpdateUser");
+ queryDeleteUser = application->getConfigManager()->get("UserManager.Mysql.Queries.DeleteUser");
+ queryAddGroup = application->getConfigManager()->get("UserManager.Mysql.Queries.AddGroup");
+ queryUpdateGroup = application->getConfigManager()->get("UserManager.Mysql.Queries.UpdateGroup");
+ queryDeleteGroup = application->getConfigManager()->get("UserManager.Mysql.Queries.DeleteGroup");
+ queryAddUserToGroup = application->getConfigManager()->get("UserManager.Mysql.Queries.AddUserToGroup");
+ queryDeleteUserFromGroup = application->getConfigManager()->get("UserManager.Mysql.Queries.DeleteUserFromGroup");
- if(entry[1].isEmpty())
- return true;
-
- if(!entry[1].getKey().matches("Mysql"))
- return false;
-
- if(entry[2].getKey().matches("Host")) {
- if(entry[3].isEmpty())
- host = entry[2][0];
- }
- else if(entry[2].getKey().matches("Username")) {
- if(entry[3].isEmpty())
- username = entry[2][0];
- }
- else if(entry[2].getKey().matches("Password")) {
- if(entry[3].isEmpty())
- passwd = entry[2][0];
- }
- else if(entry[2].getKey().matches("Database")) {
- if(entry[3].isEmpty())
- db = entry[2][0];
- }
- else if(entry[2].getKey().matches("Port")) {
- if(entry[3].isEmpty()) {
- char *endptr;
- long val;
-
- val = strtol(entry[2][0].toString().c_str(), &endptr, 10);
-
- if(endptr != 0 || val < 0 || val > 65535)
- application->log(Core::Logger::LOG_WARNING, "UserDBBackendMysql: Invalid port");
- else
- port = val;
- }
- }
- else if(entry[2].getKey().matches("UnixSocket")) {
- if(entry[3].isEmpty())
- unixSocket = entry[2][0];
- }
- else if(entry[2].getKey().matches("Queries")) {
- if(entry[3].getKey().matches("ListUsers")) {
- if(entry[4].isEmpty())
- queryListUsers = entry[3][0];
- }
- else if(entry[3].getKey().matches("ListGroups")) {
- if(entry[4].isEmpty())
- queryListGroups = entry[3][0];
- }
- else if(entry[3].getKey().matches("ListUserGroups")) {
- if(entry[4].isEmpty())
- queryListUserGroups = entry[3][0];
- }
- else if(entry[3].getKey().matches("ListGroupUsers")) {
- if(entry[4].isEmpty())
- queryListGroupUsers = entry[3][0];
- }
- else if(entry[3].getKey().matches("UserById")) {
- if(entry[4].isEmpty())
- queryUserById = entry[3][0];
- }
- else if(entry[3].getKey().matches("UserByName")) {
- if(entry[4].isEmpty())
- queryUserByName = entry[3][0];
- }
- else if(entry[3].getKey().matches("GroupById")) {
- if(entry[4].isEmpty())
- queryGroupById = entry[3][0];
- }
- else if(entry[3].getKey().matches("GroupByName")) {
- if(entry[4].isEmpty())
- queryGroupByName = entry[3][0];
- }
- else if(entry[3].getKey().matches("UserGroupTable")) {
- if(entry[4].isEmpty())
- queryUserGroupTable = entry[3][0];
- }
- else if(entry[3].getKey().matches("AddUser")) {
- if(entry[4].isEmpty())
- queryAddUser = entry[3][0];
- }
- else if(entry[3].getKey().matches("UpdateUser")) {
- if(entry[4].isEmpty())
- queryUpdateUser = entry[3][0];
- }
- else if(entry[3].getKey().matches("DeleteUser")) {
- if(entry[4].isEmpty())
- queryDeleteUser = entry[3][0];
- }
- else if(entry[3].getKey().matches("AddGroup")) {
- if(entry[4].isEmpty())
- queryAddGroup = entry[3][0];
- }
- else if(entry[3].getKey().matches("UpdateGroup")) {
- if(entry[4].isEmpty())
- queryUpdateGroup = entry[3][0];
- }
- else if(entry[3].getKey().matches("DeleteGroup")) {
- if(entry[4].isEmpty())
- queryDeleteGroup = entry[3][0];
- }
- else if(entry[3].getKey().matches("AddUserToGroup")) {
- if(entry[4].isEmpty())
- queryAddUserToGroup = entry[3][0];
- }
- else if(entry[3].getKey().matches("DeleteUserFromGroup")) {
- if(entry[4].isEmpty())
- queryDeleteUserFromGroup = entry[3][0];
- }
- else if(!entry[3].isEmpty())
- return false;
- }
- else if(!entry[2].isEmpty())
- return false;
-
- return true;
-}
-
-void UserDBBackendMysql::configFinished() {
if(db.isEmpty()) {
application->log(Core::Logger::LOG_ERROR, "UserDBBackendMysql: No database name given");
return;
diff --git a/src/modules/UserDBBackendMysql/UserDBBackendMysql.h b/src/modules/UserDBBackendMysql/UserDBBackendMysql.h
index 9351ca1..10c069c 100644
--- a/src/modules/UserDBBackendMysql/UserDBBackendMysql.h
+++ b/src/modules/UserDBBackendMysql/UserDBBackendMysql.h
@@ -107,8 +107,7 @@ class UserDBBackendMysql : public Common::UserDBBackend, private Core::Configura
boost::mutex mutex;
protected:
- virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled);
- virtual void configFinished();
+ virtual void configure();
virtual boost::shared_ptr<const std::map<unsigned long, Common::UserInfo> > getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception);
virtual boost::shared_ptr<const Common::UserInfo> getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception);
@@ -134,7 +133,7 @@ class UserDBBackendMysql : public Common::UserDBBackend, private Core::Configura
virtual void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception);
public:
- UserDBBackendMysql(Common::Application *application0) : application(application0), port(0), mysql(0), lastUpdate(boost::posix_time::microsec_clock::universal_time()) {
+ UserDBBackendMysql(Common::Application *application0) : application(application0), mysql(0), lastUpdate(boost::posix_time::microsec_clock::universal_time()) {
application->getConfigManager()->registerConfigurable(this);
}