summaryrefslogtreecommitdiffstats
path: root/src/modules/UserBackendMysql.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/UserBackendMysql.cpp')
-rw-r--r--src/modules/UserBackendMysql.cpp50
1 files changed, 43 insertions, 7 deletions
diff --git a/src/modules/UserBackendMysql.cpp b/src/modules/UserBackendMysql.cpp
index 0b028fb..db3c32b 100644
--- a/src/modules/UserBackendMysql.cpp
+++ b/src/modules/UserBackendMysql.cpp
@@ -17,14 +17,17 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
+
#include "UserBackendMysql.h"
#include <Common/ActionManager.h>
#include <Common/ConfigEntry.h>
#include <Common/Logger.h>
-#include <sigc++/bind.h>
+#include <sstream>
-#include <cstdlib>
+#include <sigc++/bind.h>
+#include <pcrecpp.h>
#define init UserBackendMysql_LTX_init
#define deinit UserBackendMysql_LTX_deinit
@@ -61,7 +64,7 @@ bool UserBackendMysql::handleConfigEntry(const Common::ConfigEntry &entry, bool
char *endptr;
long val;
- val = std::strtol(entry[1][0].c_str(), &endptr, 10);
+ val = strtol(entry[1][0].c_str(), &endptr, 10);
if(endptr != 0 || val < 0 || val > 65535)
Common::Logger::log(Common::Logger::WARNING, "UserBackendMysql: Invalid port");
@@ -143,9 +146,9 @@ bool UserBackendMysql::userList(const sigc::slot<void, const std::map<unsigned l
std::map<unsigned long, Common::UserInfo> users;
while(MYSQL_ROW row = mysql_fetch_row(result)) {
- Common::UserInfo user(std::strtoul(row[0], 0, 10), row[2]);
+ Common::UserInfo user(strtoul(row[0], 0, 10), row[2]);
- user.setGid(std::strtoul(row[1], 0, 10));
+ user.setGid(strtoul(row[1], 0, 10));
user.setFullName(row[3]);
users.insert(std::make_pair(user.getUid(), user));
@@ -157,10 +160,43 @@ bool UserBackendMysql::userList(const sigc::slot<void, const std::map<unsigned l
}
bool UserBackendMysql::userInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
- return false;
+ mysql_ping(mysql);
+
+ std::string query = queryUserById;
+
+ std::ostringstream tmp;
+ tmp << '"';
+ tmp << uid;
+ tmp << '"';
+
+ pcrecpp::RE("\\{ID\\}").GlobalReplace(tmp.str(), &query);
+
+ mysql_real_query(mysql, query.c_str(), query.length());
+ MYSQL_RES *result = mysql_use_result(mysql);
+
+ if(mysql_num_fields(result) < 4)
+ return true; // TODO Error
+
+ MYSQL_ROW row = mysql_fetch_row(result);
+
+ if(row) {
+ Common::UserInfo user(strtoul(row[0], 0, 10), row[2]);
+
+ user.setGid(strtoul(row[1], 0, 10));
+ user.setFullName(row[3]);
+
+ Common::ActionManager::get()->add(sigc::bind(callback, user));
+
+ while((row = mysql_fetch_row(result)) != 0) {}
+ }
+ else {
+ Common::ActionManager::get()->add(sigc::bind(callback, Common::UserInfo()));
+ }
+
+ return true;
}
-bool UserBackendMysql::password(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback) {
+bool UserBackendMysql::password(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_, const sigc::slot<void, bool> &callback _UNUSED_PARAMETER_) {
return false;
}