summaryrefslogtreecommitdiffstats
path: root/src/modules/UserDBBackendMysql
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/UserDBBackendMysql')
-rw-r--r--src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp68
-rw-r--r--src/modules/UserDBBackendMysql/UserDBBackendMysql.h34
2 files changed, 52 insertions, 50 deletions
diff --git a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
index 7e7711a..46f9d12 100644
--- a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
+++ b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
@@ -27,6 +27,7 @@
#include <boost/bind.hpp>
#include <boost/regex.hpp>
#include <boost/thread/locks.hpp>
+#include <boost/variant/get.hpp>
#include <mysql/mysqld_error.h>
@@ -34,7 +35,7 @@ namespace Mad {
namespace Modules {
namespace UserDBBackendMysql {
-const std::string UserDBBackendMysql::name("UserDBBackendMysql");
+const Core::String UserDBBackendMysql::name("UserDBBackendMysql");
bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handled*/) {
if(!entry[0].getKey().matches("UserManager"))
@@ -48,19 +49,19 @@ bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool
if(entry[2].getKey().matches("Host")) {
if(entry[3].isEmpty())
- host = entry[2][0].extract();
+ host = entry[2][0];
}
else if(entry[2].getKey().matches("Username")) {
if(entry[3].isEmpty())
- username = entry[2][0].extract();
+ username = entry[2][0];
}
else if(entry[2].getKey().matches("Password")) {
if(entry[3].isEmpty())
- passwd = entry[2][0].extract();
+ passwd = entry[2][0];
}
else if(entry[2].getKey().matches("Database")) {
if(entry[3].isEmpty())
- db = entry[2][0].extract();
+ db = entry[2][0];
}
else if(entry[2].getKey().matches("Port")) {
if(entry[3].isEmpty()) {
@@ -77,76 +78,76 @@ bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool
}
else if(entry[2].getKey().matches("UnixSocket")) {
if(entry[3].isEmpty())
- unixSocket = entry[2][0].extract();
+ 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].extract();
+ queryListUsers = entry[3][0];
}
else if(entry[3].getKey().matches("ListGroups")) {
if(entry[4].isEmpty())
- queryListGroups = entry[3][0].extract();
+ queryListGroups = entry[3][0];
}
else if(entry[3].getKey().matches("ListUserGroups")) {
if(entry[4].isEmpty())
- queryListUserGroups = entry[3][0].extract();
+ queryListUserGroups = entry[3][0];
}
else if(entry[3].getKey().matches("ListGroupUsers")) {
if(entry[4].isEmpty())
- queryListGroupUsers = entry[3][0].extract();
+ queryListGroupUsers = entry[3][0];
}
else if(entry[3].getKey().matches("UserById")) {
if(entry[4].isEmpty())
- queryUserById = entry[3][0].extract();
+ queryUserById = entry[3][0];
}
else if(entry[3].getKey().matches("UserByName")) {
if(entry[4].isEmpty())
- queryUserByName = entry[3][0].extract();
+ queryUserByName = entry[3][0];
}
else if(entry[3].getKey().matches("GroupById")) {
if(entry[4].isEmpty())
- queryGroupById = entry[3][0].extract();
+ queryGroupById = entry[3][0];
}
else if(entry[3].getKey().matches("GroupByName")) {
if(entry[4].isEmpty())
- queryGroupByName = entry[3][0].extract();
+ queryGroupByName = entry[3][0];
}
else if(entry[3].getKey().matches("UserGroupTable")) {
if(entry[4].isEmpty())
- queryUserGroupTable = entry[3][0].extract();
+ queryUserGroupTable = entry[3][0];
}
else if(entry[3].getKey().matches("AddUser")) {
if(entry[4].isEmpty())
- queryAddUser = entry[3][0].extract();
+ queryAddUser = entry[3][0];
}
else if(entry[3].getKey().matches("UpdateUser")) {
if(entry[4].isEmpty())
- queryUpdateUser = entry[3][0].extract();
+ queryUpdateUser = entry[3][0];
}
else if(entry[3].getKey().matches("DeleteUser")) {
if(entry[4].isEmpty())
- queryDeleteUser = entry[3][0].extract();
+ queryDeleteUser = entry[3][0];
}
else if(entry[3].getKey().matches("AddGroup")) {
if(entry[4].isEmpty())
- queryAddGroup = entry[3][0].extract();
+ queryAddGroup = entry[3][0];
}
else if(entry[3].getKey().matches("UpdateGroup")) {
if(entry[4].isEmpty())
- queryUpdateGroup = entry[3][0].extract();
+ queryUpdateGroup = entry[3][0];
}
else if(entry[3].getKey().matches("DeleteGroup")) {
if(entry[4].isEmpty())
- queryDeleteGroup = entry[3][0].extract();
+ queryDeleteGroup = entry[3][0];
}
else if(entry[3].getKey().matches("AddUserToGroup")) {
if(entry[4].isEmpty())
- queryAddUserToGroup = entry[3][0].extract();
+ queryAddUserToGroup = entry[3][0];
}
else if(entry[3].getKey().matches("DeleteUserFromGroup")) {
if(entry[4].isEmpty())
- queryDeleteUserFromGroup = entry[3][0].extract();
+ queryDeleteUserFromGroup = entry[3][0];
}
else if(!entry[3].isEmpty())
return false;
@@ -158,32 +159,33 @@ bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool
}
void UserDBBackendMysql::configFinished() {
- if(db.empty()) {
+ if(db.isEmpty()) {
application->log(Core::Logger::LOG_ERROR, "UserDBBackendMysql: No database name given");
return;
}
boost::lock_guard<boost::mutex> lock(mutex);
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);
+ mysql_real_connect(mysql, host.extract().c_str(), username.extract().c_str(), passwd.extract().c_str(),
+ db.extract().c_str(), port, unixSocket.isEmpty() ? 0 : unixSocket.extract().c_str(), 0);
}
-UserDBBackendMysql::Result UserDBBackendMysql::query(const std::string &query, const ArgumentMap &args) throw(Core::Exception) {
+UserDBBackendMysql::Result UserDBBackendMysql::query(const Core::String &query, const ArgumentMap &args) throw(Core::Exception) {
if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+ std::string queryStr = query.extract();
+
if(args.empty()) {
- mysql_real_query(mysql, query.c_str(), query.length());
+ mysql_real_query(mysql, queryStr.c_str(), queryStr.length());
}
else {
- std::string queryStr = query;
-
for(ArgumentMap::const_iterator arg = args.begin(); arg != args.end(); ++arg) {
std::string argStr;
try {
- argStr = boost::get<std::string>(arg->second);
+ argStr = boost::get<Core::String>(arg->second).extract();
}
catch(...) {
std::ostringstream stream;
@@ -194,7 +196,7 @@ UserDBBackendMysql::Result UserDBBackendMysql::query(const std::string &query, c
boost::scoped_array<char> escaped(new char[argStr.length()*2+1]);
mysql_real_escape_string(mysql, escaped.get(), argStr.c_str(), argStr.length());
- queryStr = boost::regex_replace(queryStr, boost::regex("\\{" + arg->first + "\\}"), "\"" + std::string(escaped.get()) + "\"", boost::match_default);
+ queryStr = boost::regex_replace(queryStr, boost::regex("\\{" + arg->first.extract() + "\\}"), "\"" + std::string(escaped.get()) + "\"", boost::match_default);
}
mysql_real_query(mysql, queryStr.c_str(), queryStr.length());
@@ -273,7 +275,7 @@ boost::shared_ptr<const Common::UserInfo> UserDBBackendMysql::getUserInfo(unsign
throw Core::Exception(Core::Exception::NOT_FOUND);
}
-boost::shared_ptr<const Common::UserInfo> UserDBBackendMysql::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+boost::shared_ptr<const Common::UserInfo> UserDBBackendMysql::getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
application->getThreadManager()->detach();
boost::unique_lock<boost::mutex> lock(mutex);
@@ -400,7 +402,7 @@ boost::shared_ptr<const Common::GroupInfo> UserDBBackendMysql::getGroupInfo(unsi
throw Core::Exception(Core::Exception::NOT_FOUND);
}
-boost::shared_ptr<const Common::GroupInfo> UserDBBackendMysql::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
+boost::shared_ptr<const Common::GroupInfo> UserDBBackendMysql::getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) {
application->getThreadManager()->detach();
boost::unique_lock<boost::mutex> lock(mutex);
diff --git a/src/modules/UserDBBackendMysql/UserDBBackendMysql.h b/src/modules/UserDBBackendMysql/UserDBBackendMysql.h
index 959e133..9351ca1 100644
--- a/src/modules/UserDBBackendMysql/UserDBBackendMysql.h
+++ b/src/modules/UserDBBackendMysql/UserDBBackendMysql.h
@@ -29,7 +29,7 @@
#include <mysql/mysql.h>
#include <boost/thread/mutex.hpp>
-#include <boost/variant.hpp>
+#include <boost/variant/variant.hpp>
namespace Mad {
namespace Modules {
@@ -37,14 +37,14 @@ namespace UserDBBackendMysql {
class UserDBBackendMysql : public Common::UserDBBackend, private Core::Configurable, private boost::noncopyable {
private:
- typedef std::map<std::string, boost::variant<std::string, unsigned long> > ArgumentMap;
+ typedef std::map<Core::String, boost::variant<Core::String, unsigned long> > ArgumentMap;
class Result;
- Result query(const std::string &query, const ArgumentMap &args = ArgumentMap()) throw(Core::Exception);
+ Result query(const Core::String &query, const ArgumentMap &args = ArgumentMap()) throw(Core::Exception);
class Result {
private:
- friend Result UserDBBackendMysql::query(const std::string &query, const ArgumentMap &args) throw(Core::Exception);
+ friend Result UserDBBackendMysql::query(const Core::String &query, const ArgumentMap &args) throw(Core::Exception);
boost::shared_ptr<MYSQL_RES> result;
@@ -84,21 +84,21 @@ class UserDBBackendMysql : public Common::UserDBBackend, private Core::Configura
}
};
- static const std::string name;
+ static const Core::String name;
Common::Application *application;
- std::string host, username, passwd, db, unixSocket;
+ Core::String host, username, passwd, db, unixSocket;
uint16_t port;
- std::string queryListUsers, queryListGroups;
- std::string queryListUserGroups, queryListGroupUsers;
- std::string queryUserById, queryUserByName;
- std::string queryGroupById, queryGroupByName;
- std::string queryUserGroupTable;
- std::string queryAddUser, queryUpdateUser, queryDeleteUser;
- std::string queryAddGroup, queryUpdateGroup, queryDeleteGroup;
- std::string queryAddUserToGroup, queryDeleteUserFromGroup;
+ Core::String queryListUsers, queryListGroups;
+ Core::String queryListUserGroups, queryListGroupUsers;
+ Core::String queryUserById, queryUserByName;
+ Core::String queryGroupById, queryGroupByName;
+ Core::String queryUserGroupTable;
+ Core::String queryAddUser, queryUpdateUser, queryDeleteUser;
+ Core::String queryAddGroup, queryUpdateGroup, queryDeleteGroup;
+ Core::String queryAddUserToGroup, queryDeleteUserFromGroup;
MYSQL *mysql;
@@ -112,12 +112,12 @@ class UserDBBackendMysql : public Common::UserDBBackend, private Core::Configura
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);
- virtual boost::shared_ptr<const Common::UserInfo> getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception);
+ virtual boost::shared_ptr<const Common::UserInfo> getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception);
virtual boost::shared_ptr<const std::set<unsigned long> > getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception);
virtual boost::shared_ptr<const std::map<unsigned long, Common::GroupInfo> > getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception);
virtual boost::shared_ptr<const Common::GroupInfo> getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception);
- virtual boost::shared_ptr<const Common::GroupInfo> getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception);
+ virtual boost::shared_ptr<const Common::GroupInfo> getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception);
virtual boost::shared_ptr<const std::set<unsigned long> > getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception);
virtual boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception);
@@ -147,7 +147,7 @@ class UserDBBackendMysql : public Common::UserDBBackend, private Core::Configura
}
}
- virtual const std::string& getName() {
+ virtual const Core::String& getName() {
return name;
}
};