From b40ba0cf91603b695f1f2380cbd39966a458f22f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 27 Sep 2009 19:58:24 +0200 Subject: Use Unicode-aware String class instead of std::string --- src/modules/AuthProviderFile/AuthProviderFile.cpp | 42 ++++++++++++----------- src/modules/AuthProviderFile/AuthProviderFile.h | 14 ++++---- 2 files changed, 29 insertions(+), 27 deletions(-) (limited to 'src/modules/AuthProviderFile') diff --git a/src/modules/AuthProviderFile/AuthProviderFile.cpp b/src/modules/AuthProviderFile/AuthProviderFile.cpp index b1e1e52..b006cdc 100644 --- a/src/modules/AuthProviderFile/AuthProviderFile.cpp +++ b/src/modules/AuthProviderFile/AuthProviderFile.cpp @@ -54,17 +54,19 @@ void AuthProviderFile::readFile(const std::string &name) { continue; } - std::string password = match[2].str(); + Core::String password = match[2].str().c_str(); + + if(filehash.isEmpty()) { + std::string utf8pass = password.extractUTF8(); - if(filehash.empty()) { boost::lock_guard lock(mutex); - userMap.insert(std::make_pair(match[1].str(), std::vector(password.begin(), password.end()))); + userMap.insert(std::make_pair(match[1].str().c_str(), std::vector(utf8pass.begin(), utf8pass.end()))); } else { std::vector data; - data.reserve(password.size()/2); + data.reserve(password.length()/2); - for(size_t c = 0; c < password.size()-1; c += 2) { + for(boost::int32_t c = 0; c < password.length()-1; c += 2) { char buffer[3] = {password[c], password[c+1], 0}; unsigned char byte; @@ -79,7 +81,7 @@ void AuthProviderFile::readFile(const std::string &name) { if(!data.empty()) { boost::lock_guard lock(mutex); - userMap.insert(std::make_pair(match[1].str(), data)); + userMap.insert(std::make_pair(match[1].str().c_str(), data)); } } } @@ -94,15 +96,15 @@ bool AuthProviderFile::handleConfigEntry(const Core::ConfigEntry &entry, bool /* if(entry[1].getKey().matches("Hash")) { if(entry[2].isEmpty()) { - filehash = entry[1][0].extract(); + filehash = entry[1][0]; if(!Common::Hash::isHashSupported(filehash)) - application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.c_str()); + application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.extract().c_str()); } } else if(entry[1].getKey().matches("File")) { if(entry[2].isEmpty()) { - files.push_back(entry[1][0].extract()); + files.push_back(entry[1][0]); } } else if(!entry[2].isEmpty()) @@ -112,9 +114,9 @@ bool AuthProviderFile::handleConfigEntry(const Core::ConfigEntry &entry, bool /* } void AuthProviderFile::configFinished() { - if(filehash.empty() || boost::algorithm::to_lower_copy(filehash) == "clear") { + if(filehash.isEmpty() || filehash.matches("clear")) { hashes = Common::Hash::getHashList(); - filehash.clear(); + filehash.remove(); } else { hashes.clear(); @@ -123,12 +125,12 @@ void AuthProviderFile::configFinished() { hashes.push_back("Clear"); - for(std::vector::iterator file = files.begin(); file != files.end(); ++file) - readFile(*file); + for(std::vector::iterator file = files.begin(); file != files.end(); ++file) + readFile(file->extract()); } -bool AuthProviderFile::checkPassword(const std::string &user, const std::vector &data, const std::string &hash) throw(Core::Exception) { - if((hash.empty() || boost::algorithm::to_lower_copy(hash) == "clear") && !filehash.empty()) { +bool AuthProviderFile::checkPassword(const Core::String &user, const std::vector &data, const Core::String &hash) throw(Core::Exception) { + if((hash.isEmpty() || hash.matches("clear")) && !filehash.isEmpty()) { std::vector password = getPassword(user, filehash); std::vector hashdata = Common::Hash::hash(data, filehash); @@ -140,20 +142,20 @@ bool AuthProviderFile::checkPassword(const std::string &user, const std::vector< } } -std::vector AuthProviderFile::getPassword(const std::string &user, const std::string &hash) throw(Core::Exception) { +std::vector AuthProviderFile::getPassword(const Core::String &user, const Core::String &hash) throw(Core::Exception) { boost::lock_guard lock(mutex); - std::map >::iterator userIt = userMap.find(user); + std::map >::iterator userIt = userMap.find(user); if(userIt == userMap.end()) return std::vector(); - if(filehash.empty()) { - if(boost::algorithm::to_lower_copy(hash) == "clear") + if(filehash.isEmpty()) { + if(hash.matches("clear")) return userIt->second; else return Common::Hash::hash(userIt->second, hash); } - else if(boost::algorithm::to_lower_copy(filehash) == boost::algorithm::to_lower_copy(hash)) { + else if(filehash.matches(hash)) { return userIt->second; } else diff --git a/src/modules/AuthProviderFile/AuthProviderFile.h b/src/modules/AuthProviderFile/AuthProviderFile.h index 63f3d28..6ca907f 100644 --- a/src/modules/AuthProviderFile/AuthProviderFile.h +++ b/src/modules/AuthProviderFile/AuthProviderFile.h @@ -42,23 +42,23 @@ class MAD_MODULE_EXPORT AuthProviderFile : public Common::AuthProvider, private boost::mutex mutex; - std::map > userMap; + std::map > userMap; - std::vector files; - std::string filehash; + std::vector files; + Core::String filehash; - std::vector hashes; + std::vector hashes; protected: virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool /*handled*/); virtual void configFinished(); - virtual const std::vector& getHashes() const { + virtual const std::vector& getHashes() const { return hashes; } - virtual bool checkPassword(const std::string &user, const std::vector &data, const std::string &hash) throw(Core::Exception); - virtual std::vector getPassword(const std::string &user, const std::string &hash) throw(Core::Exception); + virtual bool checkPassword(const Core::String &user, const std::vector &data, const Core::String &hash) throw(Core::Exception); + virtual std::vector getPassword(const Core::String &user, const Core::String &hash) throw(Core::Exception); public: AuthProviderFile(Common::Application *application0) : application(application0) { -- cgit v1.2.3