From 0d1a7cb65b7b0f5ecc8e3cd6fbabdebab7f47f7f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 6 Aug 2009 21:28:41 +0200 Subject: Revised server config format --- src/modules/UserBackendMysql/UserBackendMysql.cpp | 188 +++++++++++----------- 1 file changed, 95 insertions(+), 93 deletions(-) (limited to 'src/modules/UserBackendMysql') diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp index ebf86d5..3ef44d1 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.cpp +++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp @@ -36,111 +36,113 @@ namespace UserBackendMysql { const std::string UserBackendMysql::name("UserBackendMysql"); -bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) { - if(handled) +bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handled*/) { + if(!entry[0].getKey().matches("UserManager")) return false; - if(entry[0].getKey().matches("UserBackendMysql")) { - if(entry[1].getKey().matches("Host")) { - if(entry[2].empty()) - host = entry[1][0]; + if(entry[1].empty()) + return true; + + if(!entry[1].getKey().matches("Mysql")) + return false; + + if(entry[2].getKey().matches("Host")) { + if(entry[3].empty()) + host = entry[2][0]; + } + else if(entry[2].getKey().matches("Username")) { + if(entry[3].empty()) + username = entry[2][0]; + } + else if(entry[2].getKey().matches("Password")) { + if(entry[3].empty()) + passwd = entry[2][0]; + } + else if(entry[2].getKey().matches("Database")) { + if(entry[3].empty()) + db = entry[2][0]; + } + else if(entry[2].getKey().matches("Port")) { + if(entry[3].empty()) { + char *endptr; + long val; + + val = strtol(entry[2][0].c_str(), &endptr, 10); + + if(endptr != 0 || val < 0 || val > 65535) + application->log(Core::LoggerBase::WARNING, "UserBackendMysql: Invalid port"); + else + port = val; } - else if(entry[1].getKey().matches("Username")) { - if(entry[2].empty()) - username = entry[1][0]; + } + else if(entry[2].getKey().matches("UnixSocket")) { + if(entry[3].empty()) + unixSocket = entry[2][0]; + } + else if(entry[2].getKey().matches("Queries")) { + if(entry[3].getKey().matches("ListUsers")) { + if(entry[4].empty()) + queryListUsers = entry[3][0]; } - else if(entry[1].getKey().matches("Password")) { - if(entry[2].empty()) - passwd = entry[1][0]; + else if(entry[3].getKey().matches("ListGroups")) { + if(entry[4].empty()) + queryListGroups = entry[3][0]; } - else if(entry[1].getKey().matches("Database")) { - if(entry[2].empty()) - db = entry[1][0]; + else if(entry[3].getKey().matches("ListUserGroups")) { + if(entry[4].empty()) + queryListUserGroups = entry[3][0]; } - else if(entry[1].getKey().matches("Port")) { - if(entry[2].empty()) { - char *endptr; - long val; - - val = strtol(entry[1][0].c_str(), &endptr, 10); - - if(endptr != 0 || val < 0 || val > 65535) - application->log(Core::LoggerBase::WARNING, "UserBackendMysql: Invalid port"); - else - port = val; - } + else if(entry[3].getKey().matches("ListGroupUsers")) { + if(entry[4].empty()) + queryListGroupUsers = entry[3][0]; } - else if(entry[1].getKey().matches("UnixSocket")) { - if(entry[2].empty()) - unixSocket = entry[1][0]; + else if(entry[3].getKey().matches("UserById")) { + if(entry[4].empty()) + queryUserById = entry[3][0]; } - else if(entry[1].getKey().matches("Queries")) { - if(entry[2].getKey().matches("ListUsers")) { - if(entry[3].empty()) - queryListUsers = entry[2][0]; - } - else if(entry[2].getKey().matches("ListGroups")) { - if(entry[3].empty()) - queryListGroups = entry[2][0]; - } - else if(entry[2].getKey().matches("ListUserGroups")) { - if(entry[3].empty()) - queryListUserGroups = entry[2][0]; - } - else if(entry[2].getKey().matches("ListGroupUsers")) { - if(entry[3].empty()) - queryListGroupUsers = entry[2][0]; - } - else if(entry[2].getKey().matches("UserById")) { - if(entry[3].empty()) - queryUserById = entry[2][0]; - } - else if(entry[2].getKey().matches("UserByName")) { - if(entry[3].empty()) - queryUserByName = entry[2][0]; - } - else if(entry[2].getKey().matches("GroupById")) { - if(entry[3].empty()) - queryGroupById = entry[2][0]; - } - else if(entry[2].getKey().matches("GroupByName")) { - if(entry[3].empty()) - queryGroupByName = entry[2][0]; - } - else if(entry[2].getKey().matches("UserGroupTable")) { - if(entry[3].empty()) - queryUserGroupTable = entry[2][0]; - } - else if(entry[2].getKey().matches("AddUser")) { - if(entry[3].empty()) - queryAddUser = entry[2][0]; - } - else if(entry[2].getKey().matches("UpdateUser")) { - if(entry[3].empty()) - queryUpdateUser = entry[2][0]; - } - else if(entry[2].getKey().matches("DeleteUser")) { - if(entry[3].empty()) - queryDeleteUser = entry[2][0]; - } - else if(entry[2].getKey().matches("AddUserToGroup")) { - if(entry[3].empty()) - queryAddUserToGroup = entry[2][0]; - } - else if(entry[2].getKey().matches("DeleteUserFromGroup")) { - if(entry[3].empty()) - queryDeleteUserFromGroup = entry[2][0]; - } - else if(!entry[2].empty()) - return false; + else if(entry[3].getKey().matches("UserByName")) { + if(entry[4].empty()) + queryUserByName = entry[3][0]; + } + else if(entry[3].getKey().matches("GroupById")) { + if(entry[4].empty()) + queryGroupById = entry[3][0]; } - else if(!entry[1].empty()) + else if(entry[3].getKey().matches("GroupByName")) { + if(entry[4].empty()) + queryGroupByName = entry[3][0]; + } + else if(entry[3].getKey().matches("UserGroupTable")) { + if(entry[4].empty()) + queryUserGroupTable = entry[3][0]; + } + else if(entry[3].getKey().matches("AddUser")) { + if(entry[4].empty()) + queryAddUser = entry[3][0]; + } + else if(entry[3].getKey().matches("UpdateUser")) { + if(entry[4].empty()) + queryUpdateUser = entry[3][0]; + } + else if(entry[3].getKey().matches("DeleteUser")) { + if(entry[4].empty()) + queryDeleteUser = entry[3][0]; + } + else if(entry[3].getKey().matches("AddUserToGroup")) { + if(entry[4].empty()) + queryAddUserToGroup = entry[3][0]; + } + else if(entry[3].getKey().matches("DeleteUserFromGroup")) { + if(entry[4].empty()) + queryDeleteUserFromGroup = entry[3][0]; + } + else if(!entry[3].empty()) return false; - - return true; } + else if(!entry[2].empty()) + return false; - return false; + return true; } void UserBackendMysql::configFinished() { -- cgit v1.2.3