From f892ec46086eee9c4bfb954469016829fb201532 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 10 Jul 2009 02:08:03 +0200 Subject: =?UTF-8?q?updateUser=20und=20deleteUser=20zum=20UserBackendMysql,?= =?UTF-8?q?=20NetworkUserBackend=20und=20Client=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/UserBackendMysql/UserBackendMysql.cpp | 51 +++++++++++++++++++++-- src/modules/UserBackendMysql/UserBackendMysql.h | 4 +- 2 files changed, 51 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp index 015c5a1..f169593 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.cpp +++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp @@ -116,6 +116,14 @@ bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool ha 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].empty()) return false; } @@ -463,9 +471,6 @@ void UserBackendMysql::addUser(const Common::UserInfo &userInfo) throw(Core::Exc boost::lock_guard lock(mutex); - if(!mysql || mysql_ping(mysql)) - throw Core::Exception(Core::Exception::NOT_AVAILABLE); - ArgumentMap args; args.insert(std::make_pair("UID", userInfo.getUid())); args.insert(std::make_pair("GID", userInfo.getGid())); @@ -484,6 +489,46 @@ void UserBackendMysql::addUser(const Common::UserInfo &userInfo) throw(Core::Exc lastUpdate = boost::posix_time::microsec_clock::universal_time(); } +void UserBackendMysql::updateUser(unsigned long uid, const Common::UserInfo &userInfo) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::lock_guard lock(mutex); + + ArgumentMap args; + args.insert(std::make_pair("ORIG_UID", uid)); + args.insert(std::make_pair("UID", userInfo.getUid())); + args.insert(std::make_pair("GID", userInfo.getGid())); + args.insert(std::make_pair("USER", userInfo.getUsername())); + args.insert(std::make_pair("FULL_NAME", userInfo.getFullName())); + + Result result = query(queryUpdateUser, args); + + if(result.getErrno()) { + if(result.getErrno() == ER_DUP_ENTRY) + throw Core::Exception(Core::Exception::DUPLICATE_ENTRY); + else + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + } + + lastUpdate = boost::posix_time::microsec_clock::universal_time(); +} + +void UserBackendMysql::deleteUser(unsigned long uid) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::lock_guard lock(mutex); + + ArgumentMap args; + args.insert(std::make_pair("UID", uid)); + + Result result = query(queryDeleteUser, args); + + if(result.getErrno()) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + lastUpdate = boost::posix_time::microsec_clock::universal_time(); +} + } } } diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h index 78926b9..a1c2bb1 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.h +++ b/src/modules/UserBackendMysql/UserBackendMysql.h @@ -94,7 +94,7 @@ class UserBackendMysql : public Common::UserBackend, private Core::Configurable, std::string queryUserById, queryUserByName; std::string queryGroupById, queryGroupByName; std::string queryUserGroupTable; - std::string queryAddUser; + std::string queryAddUser, queryUpdateUser, queryDeleteUser; MYSQL *mysql; @@ -119,6 +119,8 @@ class UserBackendMysql : public Common::UserBackend, private Core::Configurable, virtual boost::shared_ptr > getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual void addUser(const Common::UserInfo &userInfo) throw(Core::Exception); + virtual void updateUser(unsigned long uid, const Common::UserInfo &userInfo) throw(Core::Exception); + virtual void deleteUser(unsigned long uid) throw(Core::Exception); public: UserBackendMysql(Common::Application *application0) : application(application0), port(0), mysql(0), lastUpdate(boost::posix_time::microsec_clock::universal_time()) { -- cgit v1.2.3