diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 19:58:24 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 19:58:24 +0200 |
commit | b40ba0cf91603b695f1f2380cbd39966a458f22f (patch) | |
tree | 1fec48ddc59eb1392fac38495b230e4b2cbf7528 /src/Common | |
parent | e1d8490f0654a3da0b900407d80d91d8d0da68c8 (diff) | |
download | mad-b40ba0cf91603b695f1f2380cbd39966a458f22f.tar mad-b40ba0cf91603b695f1f2380cbd39966a458f22f.zip |
Use Unicode-aware String class instead of std::string
Diffstat (limited to 'src/Common')
38 files changed, 313 insertions, 303 deletions
diff --git a/src/Common/AuthBackend.h b/src/Common/AuthBackend.h index 3fe3840..da40902 100644 --- a/src/Common/AuthBackend.h +++ b/src/Common/AuthBackend.h @@ -38,11 +38,11 @@ class AuthBackend { protected: friend class AuthManager; - virtual const std::string& getMethodName() const = 0; - virtual std::vector<std::string> getSubMethods(boost::shared_ptr<AuthProvider> provider) const = 0; + virtual const Core::String& getMethodName() const = 0; + virtual std::vector<Core::String> getSubMethods(boost::shared_ptr<AuthProvider> provider) const = 0; - virtual boost::shared_ptr<AuthContext> authenticate(boost::shared_ptr<AuthProvider> provider, const std::string &subMethod, - const std::string &user, const std::vector<boost::uint8_t> &data, std::vector<boost::uint8_t> &response, + virtual boost::shared_ptr<AuthContext> authenticate(boost::shared_ptr<AuthProvider> provider, const Core::String &subMethod, + const Core::String &user, const std::vector<boost::uint8_t> &data, std::vector<boost::uint8_t> &response, boost::shared_ptr<AuthContext> context) throw(Core::Exception) = 0; public: diff --git a/src/Common/AuthManager.cpp b/src/Common/AuthManager.cpp index 38ac9e3..5e97fb3 100644 --- a/src/Common/AuthManager.cpp +++ b/src/Common/AuthManager.cpp @@ -48,7 +48,7 @@ void AuthManager::registerBackend(boost::shared_ptr<AuthBackend> backend) { void AuthManager::unregisterBackend(boost::shared_ptr<AuthBackend> backend) { boost::lock_guard<boost::shared_mutex> lock(mutex); - std::map<std::string, boost::shared_ptr<AuthBackend> >::iterator backendIt = backends.find(backend->getMethodName()); + std::map<Core::String, boost::shared_ptr<AuthBackend> >::iterator backendIt = backends.find(backend->getMethodName()); if(backendIt == backends.end() || backendIt->second != backend) return; @@ -56,16 +56,16 @@ void AuthManager::unregisterBackend(boost::shared_ptr<AuthBackend> backend) { backends.erase(backendIt); } -std::set<std::string> AuthManager::getMethods() { +const std::set<Core::String>& AuthManager::getMethods() { boost::shared_lock<boost::shared_mutex> lock(mutex); return methods; } -std::vector<std::string> AuthManager::getSubMethods(const std::string &method) throw(Core::Exception) { +std::vector<Core::String> AuthManager::getSubMethods(const Core::String &method) throw(Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); - std::map<std::string, boost::shared_ptr<AuthBackend> >::iterator backend = backends.find(method); + std::map<Core::String, boost::shared_ptr<AuthBackend> >::iterator backend = backends.find(method); if(backend == backends.end()) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -75,9 +75,10 @@ std::vector<std::string> AuthManager::getSubMethods(const std::string &method) t return backend->second->getSubMethods(provider); } -boost::shared_ptr<AuthContext> AuthManager::authenticate(const std::string &method, const std::string &subMethod, const std::string &user, - const std::vector<boost::uint8_t> &data, std::vector<boost::uint8_t> &response, boost::shared_ptr<AuthContext> context) throw(Core::Exception) { - std::map<std::string, boost::shared_ptr<AuthBackend> >::iterator backend; +boost::shared_ptr<AuthContext> AuthManager::authenticate(const Core::String &method, const Core::String &subMethod, + const Core::String &user, const std::vector<boost::uint8_t> &data, std::vector<boost::uint8_t> &response, + boost::shared_ptr<AuthContext> context) throw(Core::Exception) { + std::map<Core::String, boost::shared_ptr<AuthBackend> >::iterator backend; { boost::lock_guard<boost::shared_mutex> lock(mutex); diff --git a/src/Common/AuthManager.h b/src/Common/AuthManager.h index e45762a..0c249ad 100644 --- a/src/Common/AuthManager.h +++ b/src/Common/AuthManager.h @@ -48,8 +48,8 @@ class MAD_COMMON_EXPORT AuthManager : private boost::noncopyable { boost::shared_ptr<AuthProvider> provider; - std::set<std::string> methods; - std::map<std::string, boost::shared_ptr<AuthBackend> > backends; + std::set<Core::String> methods; + std::map<Core::String, boost::shared_ptr<AuthBackend> > backends; boost::shared_mutex mutex; @@ -62,11 +62,11 @@ class MAD_COMMON_EXPORT AuthManager : private boost::noncopyable { void registerBackend(boost::shared_ptr<AuthBackend> backend); void unregisterBackend(boost::shared_ptr<AuthBackend> backend); - std::set<std::string> getMethods(); - std::vector<std::string> getSubMethods(const std::string &method) throw(Core::Exception); + const std::set<Core::String>& getMethods(); + std::vector<Core::String> getSubMethods(const Core::String &method) throw(Core::Exception); - boost::shared_ptr<AuthContext> authenticate(const std::string &method, const std::string &subMethod, - const std::string &user, const std::vector<boost::uint8_t> &data, std::vector<boost::uint8_t> &response, + boost::shared_ptr<AuthContext> authenticate(const Core::String &method, const Core::String &subMethod, + const Core::String &user, const std::vector<boost::uint8_t> &data, std::vector<boost::uint8_t> &response, boost::shared_ptr<AuthContext> context = boost::shared_ptr<AuthContext>()) throw(Core::Exception); }; diff --git a/src/Common/AuthProvider.h b/src/Common/AuthProvider.h index aaf8f10..5318e41 100644 --- a/src/Common/AuthProvider.h +++ b/src/Common/AuthProvider.h @@ -31,15 +31,15 @@ namespace Common { class AuthProvider { public: - virtual const std::vector<std::string>& getHashes() const = 0; + virtual const std::vector<Core::String>& getHashes() const = 0; - virtual bool checkPassword(const std::string &user, const std::vector<boost::uint8_t> &data, const std::string &hash) throw(Core::Exception) { + virtual bool checkPassword(const Core::String &user, const std::vector<boost::uint8_t> &data, const Core::String &hash) throw(Core::Exception) { std::vector<boost::uint8_t> password = getPassword(user, hash); return (!password.empty() && data.size() == password.size() && std::equal(data.begin(), data.end(), password.begin())); } - virtual std::vector<boost::uint8_t> getPassword(const std::string& /*user*/, const std::string& /*hash*/) throw(Core::Exception) { + virtual std::vector<boost::uint8_t> getPassword(const Core::String& /*user*/, const Core::String& /*hash*/) throw(Core::Exception) { throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); } diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp index 1b528ab..87d9b4f 100644 --- a/src/Common/Backends/NetworkUserBackend.cpp +++ b/src/Common/Backends/NetworkUserBackend.cpp @@ -26,14 +26,14 @@ namespace Mad { namespace Common { namespace Backends { -const std::string NetworkUserBackend::name("NetworkUserBackend"); +const Core::String NetworkUserBackend::name("NetworkUserBackend"); void NetworkUserBackend::SimpleUserRequest::sendRequest() { XmlData packet; packet.setType(type); if(!timestamp.is_not_a_date_time()) - packet.set("timestamp", boost::posix_time::to_iso_string(timestamp)); + packet.set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); sendPacket(packet); } @@ -44,7 +44,7 @@ void NetworkUserBackend::IdUserRequest::sendRequest() { packet.set(idType, id); if(!timestamp.is_not_a_date_time()) - packet.set("timestamp", boost::posix_time::to_iso_string(timestamp)); + packet.set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); sendPacket(packet); } @@ -55,7 +55,7 @@ void NetworkUserBackend::NameUserRequest::sendRequest() { packet.set("name", name); if(!timestamp.is_not_a_date_time()) - packet.set("timestamp", boost::posix_time::to_iso_string(timestamp)); + packet.set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); sendPacket(packet); } @@ -138,7 +138,7 @@ boost::shared_ptr<const std::map<unsigned long, UserInfo> > NetworkUserBackend:: if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); } catch(...) {} } @@ -148,9 +148,9 @@ boost::shared_ptr<const std::map<unsigned long, UserInfo> > NetworkUserBackend:: boost::shared_ptr<std::map<unsigned long, UserInfo> > userList(new std::map<unsigned long, UserInfo>); for(XmlData::List::const_iterator user = users->begin(); user != users->end(); ++user) { - UserInfo userInfo(user->get<unsigned long>("uid"), user->get<const std::string&>("username")); + UserInfo userInfo(user->get<unsigned long>("uid"), user->get<const Core::String&>("username")); userInfo.setGid(user->get<unsigned long>("gid")); - userInfo.setFullName(user->get<const std::string&>("fullName")); + userInfo.setFullName(user->get<const Core::String&>("fullName")); userList->insert(std::make_pair(userInfo.getUid(), userInfo)); } @@ -174,7 +174,7 @@ boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfo(unsigned long if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); } catch(...) {} } @@ -182,10 +182,10 @@ boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfo(unsigned long unsigned long uid2 = result.first->get<unsigned long>("uid"); if(uid2) { - boost::shared_ptr<UserInfo> userInfo(new UserInfo(uid2, result.first->get<const std::string&>("username"))); + boost::shared_ptr<UserInfo> userInfo(new UserInfo(uid2, result.first->get<const Core::String&>("username"))); userInfo->setGid(result.first->get<unsigned long>("gid")); - userInfo->setFullName(result.first->get<const std::string&>("fullName")); + userInfo->setFullName(result.first->get<const Core::String&>("fullName")); return userInfo; } @@ -193,7 +193,7 @@ boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfo(unsigned long return boost::shared_ptr<const UserInfo>(); } -boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::shared_ptr<NameUserRequest> request(new NameUserRequest(application, "GetUserInfo", name, timestamp)); @@ -206,7 +206,7 @@ boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfoByName(const st if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); } catch(...) {} } @@ -214,10 +214,10 @@ boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfoByName(const st unsigned long uid = result.first->get<unsigned long>("uid"); if(uid) { - boost::shared_ptr<UserInfo> userInfo(new UserInfo(uid, result.first->get<const std::string&>("username"))); + boost::shared_ptr<UserInfo> userInfo(new UserInfo(uid, result.first->get<const Core::String&>("username"))); userInfo->setGid(result.first->get<unsigned long>("gid")); - userInfo->setFullName(result.first->get<const std::string&>("fullName")); + userInfo->setFullName(result.first->get<const Core::String&>("fullName")); return userInfo; } @@ -238,7 +238,7 @@ boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getUserGro if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); } catch(...) {} } @@ -270,7 +270,7 @@ boost::shared_ptr<const std::map<unsigned long, GroupInfo> > NetworkUserBackend: if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); } catch(...) {} } @@ -280,7 +280,7 @@ boost::shared_ptr<const std::map<unsigned long, GroupInfo> > NetworkUserBackend: boost::shared_ptr<std::map<unsigned long, GroupInfo> > groupList(new std::map<unsigned long, GroupInfo>); for(XmlData::List::const_iterator group = groups->begin(); group != groups->end(); ++group) { - GroupInfo groupInfo(group->get<unsigned long>("gid"), group->get<const std::string&>("name")); + GroupInfo groupInfo(group->get<unsigned long>("gid"), group->get<const Core::String&>("name")); groupList->insert(std::make_pair(groupInfo.getGid(), groupInfo)); } @@ -303,7 +303,7 @@ boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfo(unsigned lon if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); } catch(...) {} } @@ -311,12 +311,12 @@ boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfo(unsigned lon unsigned long gid2 = result.first->get<unsigned long>("gid"); if(gid2) - return boost::shared_ptr<GroupInfo>(new GroupInfo(gid2, result.first->get<const std::string&>("name"))); + return boost::shared_ptr<GroupInfo>(new GroupInfo(gid2, result.first->get<const Core::String&>("name"))); return boost::shared_ptr<const GroupInfo>(); } -boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::shared_ptr<NameUserRequest> request(new NameUserRequest(application, "GetGroupInfo", name, timestamp)); @@ -329,7 +329,7 @@ boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfoByName(const if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); } catch(...) {} } @@ -337,7 +337,7 @@ boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfoByName(const unsigned long gid = result.first->get<unsigned long>("gid"); if(gid) - return boost::shared_ptr<GroupInfo>(new GroupInfo(gid, result.first->get<const std::string&>("name"))); + return boost::shared_ptr<GroupInfo>(new GroupInfo(gid, result.first->get<const Core::String&>("name"))); return boost::shared_ptr<const GroupInfo>(); } @@ -355,7 +355,7 @@ boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getGroupUs if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); } catch(...) {} } @@ -387,7 +387,7 @@ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > NetworkUse if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const std::string&>("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); } catch(...) {} } @@ -529,7 +529,7 @@ void NetworkUserBackend::deleteUserFromGroup(unsigned long uid, unsigned long gi } -void NetworkUserBackend::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { +void NetworkUserBackend::setPassword(unsigned long uid, const Core::String &password) throw(Core::Exception) { application->getThreadManager()->detach(); boost::shared_ptr<PasswordRequest> request(new PasswordRequest(application, uid, password)); diff --git a/src/Common/Backends/NetworkUserBackend.h b/src/Common/Backends/NetworkUserBackend.h index 6ae9747..9b52443 100644 --- a/src/Common/Backends/NetworkUserBackend.h +++ b/src/Common/Backends/NetworkUserBackend.h @@ -33,21 +33,21 @@ class MAD_COMMON_EXPORT NetworkUserBackend : public UserDBBackend { private: class MAD_COMMON_EXPORT SimpleUserRequest : public Request { private: - std::string type; + Core::String type; boost::posix_time::ptime timestamp; protected: virtual void sendRequest(); public: - SimpleUserRequest(Application *application, const std::string &type0, boost::posix_time::ptime *timestamp0) + SimpleUserRequest(Application *application, const Core::String &type0, boost::posix_time::ptime *timestamp0) : Request(application), type(type0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {} }; class MAD_COMMON_EXPORT IdUserRequest : public Request { private: - std::string type; - std::string idType; + Core::String type; + Core::String idType; unsigned long id; boost::posix_time::ptime timestamp; @@ -55,21 +55,21 @@ class MAD_COMMON_EXPORT NetworkUserBackend : public UserDBBackend { virtual void sendRequest(); public: - IdUserRequest(Application *application, const std::string &type0, const std::string &idType0, unsigned long id0, boost::posix_time::ptime *timestamp0 = 0) + IdUserRequest(Application *application, const Core::String &type0, const Core::String &idType0, unsigned long id0, boost::posix_time::ptime *timestamp0 = 0) : Request(application), type(type0), idType(idType0), id(id0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {} }; class MAD_COMMON_EXPORT NameUserRequest : public Request { private: - std::string type; - std::string name; + Core::String type; + Core::String name; boost::posix_time::ptime timestamp; protected: virtual void sendRequest(); public: - NameUserRequest(Application *application, const std::string &type0, const std::string &name0, boost::posix_time::ptime *timestamp0) + NameUserRequest(Application *application, const Core::String &type0, const Core::String &name0, boost::posix_time::ptime *timestamp0) : Request(application), type(type0), name(name0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {} }; @@ -127,7 +127,7 @@ class MAD_COMMON_EXPORT NetworkUserBackend : public UserDBBackend { class MAD_COMMON_EXPORT UserGroupRequest : public Request { private: - std::string type; + Core::String type; unsigned long uid; unsigned long gid; @@ -135,24 +135,24 @@ class MAD_COMMON_EXPORT NetworkUserBackend : public UserDBBackend { virtual void sendRequest(); public: - UserGroupRequest(Application *application, const std::string &type0, unsigned long uid0, unsigned long gid0) + UserGroupRequest(Application *application, const Core::String &type0, unsigned long uid0, unsigned long gid0) : Request(application), type(type0), uid(uid0), gid(gid0) {} }; class MAD_COMMON_EXPORT PasswordRequest : public Request { private: unsigned long uid; - std::string password; + Core::String password; protected: virtual void sendRequest(); public: - PasswordRequest(Application *application, unsigned long uid0, const std::string &password0) + PasswordRequest(Application *application, unsigned long uid0, const Core::String &password0) : Request(application), uid(uid0), password(password0) {} }; - static const std::string name; + static const Core::String name; Application *application; Connection *connection; @@ -160,12 +160,12 @@ class MAD_COMMON_EXPORT NetworkUserBackend : public UserDBBackend { protected: 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); @@ -183,12 +183,12 @@ class MAD_COMMON_EXPORT NetworkUserBackend : public UserDBBackend { virtual void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); virtual void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); - virtual void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); + virtual void setPassword(unsigned long uid, const Core::String &password) throw(Core::Exception); public: NetworkUserBackend(Application *application0, Connection *connection0) : application(application0), connection(connection0) {} - virtual const std::string& getName() { + virtual const Core::String& getName() { return name; } }; diff --git a/src/Common/GroupInfo.h b/src/Common/GroupInfo.h index c1a2274..cae12f0 100644 --- a/src/Common/GroupInfo.h +++ b/src/Common/GroupInfo.h @@ -22,7 +22,7 @@ #include "export.h" -#include <string> +#include <Core/String.h> namespace Mad { namespace Common { @@ -30,16 +30,16 @@ namespace Common { class GroupInfo { private: unsigned long gid; - std::string name; + Core::String name; public: - GroupInfo(unsigned long gid0 = 0, const std::string& name0 = std::string()) : gid(gid0), name(name0) {} + GroupInfo(unsigned long gid0 = 0, const Core::String& name0 = Core::String()) : gid(gid0), name(name0) {} void setGid(unsigned long newGid) {gid = newGid;} unsigned long getGid() const {return gid;} - void setName(const std::string& newName) {name = newName;} - const std::string& getName() const {return name;} + void setName(const Core::String& newName) {name = newName;} + const Core::String& getName() const {return name;} }; } diff --git a/src/Common/Hash.h b/src/Common/Hash.h index db581b7..f92779e 100644 --- a/src/Common/Hash.h +++ b/src/Common/Hash.h @@ -40,20 +40,23 @@ class MAD_COMMON_EXPORT Hash { class MAD_COMMON_EXPORT Hashes { private: - std::map<std::string, unsigned int> map; - std::vector<std::string> list; + std::map<Core::String, unsigned int> map; + std::vector<Core::String> list; - void addHash(const std::string &name, unsigned id) { - map.insert(std::make_pair(boost::algorithm::to_lower_copy(name), id)); + void addHash(const Core::String &name, unsigned id) { + Core::String lowerName = name; + lowerName.toLower(); + + map.insert(std::make_pair(lowerName, id)); list.push_back(name); } public: - const std::vector<std::string>& getList() const { + const std::vector<Core::String>& getList() const { return list; } - const std::map<std::string, unsigned int>& getMap() const { + const std::map<Core::String, unsigned int>& getMap() const { return map; } @@ -63,30 +66,38 @@ class MAD_COMMON_EXPORT Hash { static const Hashes hashes; public: - static const std::vector<std::string>& getHashList() { + static const std::vector<Core::String>& getHashList() { return hashes.getList(); } - static bool isHashSupported(const std::string &method) { - return (hashes.getMap().find(boost::algorithm::to_lower_copy(method)) != hashes.getMap().end()); + static bool isHashSupported(const Core::String &method) { + Core::String lowerMethod = method; + lowerMethod.toLower(); + + return (hashes.getMap().find(lowerMethod) != hashes.getMap().end()); } static std::vector<boost::uint8_t> hash(const std::vector<boost::uint8_t> &in, unsigned int method) throw (Core::Exception); - static std::vector<boost::uint8_t> hash(const std::vector<boost::uint8_t> &in, const std::string &method) throw (Core::Exception) { - std::map<std::string, unsigned int>::const_iterator methodIt = hashes.getMap().find(boost::algorithm::to_lower_copy(method)); + static std::vector<boost::uint8_t> hash(const std::vector<boost::uint8_t> &in, const Core::String &method) throw (Core::Exception) { + Core::String lowerMethod = method; + lowerMethod.toLower(); + + std::map<Core::String, unsigned int>::const_iterator methodIt = hashes.getMap().find(lowerMethod); if(methodIt == hashes.getMap().end()) throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); return hash(in, methodIt->second); } - static std::vector<boost::uint8_t> hash(const std::string &in, unsigned int method) throw (Core::Exception) { - return hash(std::vector<boost::uint8_t>(in.begin(), in.end()), method); + static std::vector<boost::uint8_t> hash(const Core::String &in, unsigned int method) throw (Core::Exception) { + std::string str = in.extractUTF8(); + return hash(std::vector<boost::uint8_t>(str.begin(), str.end()), method); } - static std::vector<boost::uint8_t> hash(const std::string &in, const std::string &method) throw (Core::Exception) { - return hash(std::vector<boost::uint8_t>(in.begin(), in.end()), method); + static std::vector<boost::uint8_t> hash(const Core::String &in, const Core::String &method) throw (Core::Exception) { + std::string str = in.extractUTF8(); + return hash(std::vector<boost::uint8_t>(str.begin(), str.end()), method); } }; diff --git a/src/Common/HostInfo.h b/src/Common/HostInfo.h index 4a6c3f3..bd4afba 100644 --- a/src/Common/HostInfo.h +++ b/src/Common/HostInfo.h @@ -22,7 +22,7 @@ #include "export.h" -#include <string> +#include <Core/String.h> namespace Mad { namespace Common { @@ -34,16 +34,16 @@ class HostInfo { }; private: - std::string name; + Core::String name; std::string ip; State state; public: - HostInfo(const std::string& name0 = std::string()) : name(name0), state(INACTIVE) {} + HostInfo(const Core::String& name0 = Core::String()) : name(name0), state(INACTIVE) {} - void setName(const std::string &newName) {name = newName;} - const std::string& getName() const {return name;} + void setName(const Core::String &newName) {name = newName;} + const Core::String& getName() const {return name;} void setIP(const std::string& newIp) {ip = newIp;} const std::string& getIP() const {return ip;} diff --git a/src/Common/Request.cpp b/src/Common/Request.cpp index 0edfcfd..f7ad600 100644 --- a/src/Common/Request.cpp +++ b/src/Common/Request.cpp @@ -24,7 +24,7 @@ namespace Common { void Request::handlePacket(boost::shared_ptr<const XmlData> packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get<const std::string&>("Where"), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), + signalFinished(Core::Exception(packet->get<const Core::String&>("Where").extract(), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); return; } diff --git a/src/Common/RequestHandlerGroup.h b/src/Common/RequestHandlerGroup.h index d1b7b25..ff21797 100644 --- a/src/Common/RequestHandlerGroup.h +++ b/src/Common/RequestHandlerGroup.h @@ -23,9 +23,9 @@ #include "export.h" #include "RequestHandler.h" +#include <Core/String.h> #include <set> -#include <string> namespace Mad { namespace Common { @@ -35,9 +35,9 @@ class RequestHandlerGroup { RequestHandlerGroup() {} public: - virtual const std::set<std::string>& getPacketTypes() = 0; + virtual const std::set<Core::String>& getPacketTypes() = 0; - virtual boost::shared_ptr<RequestHandler> createRequestHandler(Application *application, const std::string &type) = 0; + virtual boost::shared_ptr<RequestHandler> createRequestHandler(Application *application, const Core::String &type) = 0; virtual ~RequestHandlerGroup() {} }; diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp index af4bf50..36ae515 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp @@ -37,8 +37,8 @@ void FSInfoRequestHandler::handleRequest(boost::shared_ptr<const Common::XmlData for(std::vector<SystemManager::FSInfo>::const_iterator fs = fsInfo.begin(); fs != fsInfo.end(); ++fs) { XmlData::List::iterator entry = list->addEntry(); - entry->set("name", fs->fsName); - entry->set("mountedOn", fs->mountedOn); + entry->set("name", fs->fsName.c_str()); + entry->set("mountedOn", fs->mountedOn.c_str()); entry->set("totalSize", fs->total); entry->set("usedSize", fs->used); entry->set("availableSize", fs->available); diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.cpp b/src/Common/RequestHandlers/SimpleRequestHandler.cpp index 86edca6..71a8b3a 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandler.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandler.cpp @@ -49,7 +49,7 @@ void SimpleRequestHandler::handlePacket(boost::shared_ptr<const XmlData> packet) ret.set("ErrorCode", e.getErrorCode()); ret.set("SubCode", e.getSubCode()); ret.set("SubSubCode", e.getSubSubCode()); - ret.set("Where", e.getWhere()); + ret.set("Where", e.getWhere().c_str()); } sendPacket(ret); diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.h b/src/Common/RequestHandlers/SimpleRequestHandler.h index 85cbd4c..5ccb1f4 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandler.h +++ b/src/Common/RequestHandlers/SimpleRequestHandler.h @@ -30,13 +30,13 @@ namespace RequestHandlers { class MAD_COMMON_EXPORT SimpleRequestHandler : public RequestHandler { private: - std::string type; + Core::String type; boost::function2<void, boost::shared_ptr<const XmlData>, XmlData*> handler; protected: virtual void handlePacket(boost::shared_ptr<const XmlData> packet); - SimpleRequestHandler(Application *application, const std::string &type0, const boost::function2<void, boost::shared_ptr<const XmlData>, XmlData*> &handler0) + SimpleRequestHandler(Application *application, const Core::String &type0, const boost::function2<void, boost::shared_ptr<const XmlData>, XmlData*> &handler0) : RequestHandler(application), type(type0), handler(handler0) {} }; diff --git a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp index a7debc3..a3ed286 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp @@ -50,15 +50,15 @@ void SimpleRequestHandlerGroup::GroupRequestHandler::handlePacket(boost::shared_ ret.set("ErrorCode", e.getErrorCode()); ret.set("SubCode", e.getSubCode()); ret.set("SubSubCode", e.getSubSubCode()); - ret.set("Where", e.getWhere()); + ret.set("Where", e.getWhere().c_str()); } sendPacket(ret); signalFinished(); } -boost::shared_ptr<RequestHandler> SimpleRequestHandlerGroup::createRequestHandler(Application *application, const std::string &type) { - std::map<std::string, boost::function3<void, boost::shared_ptr<const XmlData>, XmlData*, Connection*> >::iterator handler = handlers.find(type); +boost::shared_ptr<RequestHandler> SimpleRequestHandlerGroup::createRequestHandler(Application *application, const Core::String &type) { + std::map<Core::String, boost::function3<void, boost::shared_ptr<const XmlData>, XmlData*, Connection*> >::iterator handler = handlers.find(type); if(handler == handlers.end()) return boost::shared_ptr<RequestHandler>(); diff --git a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h index 2022705..53f8516 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h +++ b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h @@ -32,22 +32,22 @@ class MAD_COMMON_EXPORT SimpleRequestHandlerGroup : public RequestHandlerGroup { private: class MAD_COMMON_EXPORT GroupRequestHandler : public RequestHandler { private: - std::string type; + Core::String type; boost::function3<void, boost::shared_ptr<const XmlData>, XmlData*, Connection*> handler; protected: virtual void handlePacket(boost::shared_ptr<const XmlData> packet); public: - GroupRequestHandler(Application *application, const std::string &type0, const boost::function3<void, boost::shared_ptr<const XmlData>, XmlData*, Connection*> &handler0) + GroupRequestHandler(Application *application, const Core::String &type0, const boost::function3<void, boost::shared_ptr<const XmlData>, XmlData*, Connection*> &handler0) : RequestHandler(application), type(type0), handler(handler0) {} }; - std::set<std::string> types; - std::map<std::string, boost::function3<void, boost::shared_ptr<const XmlData>, XmlData*, Connection*> > handlers; + std::set<Core::String> types; + std::map<Core::String, boost::function3<void, boost::shared_ptr<const XmlData>, XmlData*, Connection*> > handlers; protected: - void registerHandler(const std::string &type, const boost::function3<void, boost::shared_ptr<const XmlData>, XmlData*, Connection*> &handler) { + void registerHandler(const Core::String &type, const boost::function3<void, boost::shared_ptr<const XmlData>, XmlData*, Connection*> &handler) { types.insert(type); handlers.insert(std::make_pair(type, handler)); } @@ -55,11 +55,11 @@ class MAD_COMMON_EXPORT SimpleRequestHandlerGroup : public RequestHandlerGroup { SimpleRequestHandlerGroup() {} public: - virtual const std::set<std::string>& getPacketTypes() { + virtual const std::set<Core::String>& getPacketTypes() { return types; } - virtual boost::shared_ptr<RequestHandler> createRequestHandler(Application *application, const std::string &type); + virtual boost::shared_ptr<RequestHandler> createRequestHandler(Application *application, const Core::String &type); }; } diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index 12134e0..fa767c5 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -104,7 +104,7 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr<co return; } - std::map<std::string, boost::shared_ptr<RequestHandlerGroup> >::iterator rgh = requestHandlerGroups.find(packet->getType()); + std::map<Core::String, boost::shared_ptr<RequestHandlerGroup> >::iterator rgh = requestHandlerGroups.find(packet->getType()); if(rgh != requestHandlerGroups.end()) { request = rgh->second->createRequestHandler(application, packet->getType()); diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h index aef6b90..48472d5 100644 --- a/src/Common/RequestManager.h +++ b/src/Common/RequestManager.h @@ -72,37 +72,37 @@ class MAD_COMMON_EXPORT RequestManager : private boost::noncopyable { template<typename T> class RequestHandlerFactory0 : public RequestHandlerGroup { private: - std::set<std::string> types; + std::set<Core::String> types; public: - RequestHandlerFactory0(const std::string &type) { + RequestHandlerFactory0(const Core::String &type) { types.insert(type); } - virtual const std::set<std::string>& getPacketTypes() { + virtual const std::set<Core::String>& getPacketTypes() { return types; } - virtual boost::shared_ptr<RequestHandler> createRequestHandler(Application *application, const std::string& /*type*/) { + virtual boost::shared_ptr<RequestHandler> createRequestHandler(Application *application, const Core::String& /*type*/) { return boost::shared_ptr<RequestHandler>(new T(application)); } }; template<typename T, typename T1> class RequestHandlerFactory1 : public RequestHandlerGroup { private: - std::set<std::string> types; + std::set<Core::String> types; T1 arg1; public: - RequestHandlerFactory1(const std::string &type, T1 argT1) : arg1(argT1) { + RequestHandlerFactory1(const Core::String &type, T1 argT1) : arg1(argT1) { types.insert(type); } - virtual const std::set<std::string>& getPacketTypes() { + virtual const std::set<Core::String>& getPacketTypes() { return types; } - virtual boost::shared_ptr<RequestHandler> createRequestHandler(Application *application, const std::string& /*type*/) { + virtual boost::shared_ptr<RequestHandler> createRequestHandler(Application *application, const Core::String& /*type*/) { return boost::shared_ptr<RequestHandler>(new T(application, arg1)); } }; @@ -115,7 +115,7 @@ class MAD_COMMON_EXPORT RequestManager : private boost::noncopyable { boost::uint16_t lastRequestId; - std::map<std::string, boost::shared_ptr<RequestHandlerGroup> > requestHandlerGroups; + std::map<Core::String, boost::shared_ptr<RequestHandlerGroup> > requestHandlerGroups; boost::uint16_t _getRequestId() { return lastRequestId+=2; @@ -145,17 +145,17 @@ class MAD_COMMON_EXPORT RequestManager : private boost::noncopyable { void registerRequestHandlerGroup(boost::shared_ptr<RequestHandlerGroup> requestHandlerGroup) { boost::lock_guard<boost::shared_mutex> lock(mutex); - const std::set<std::string> &types = requestHandlerGroup->getPacketTypes(); - for(std::set<std::string>::const_iterator type = types.begin(); type != types.end(); ++type) + const std::set<Core::String> &types = requestHandlerGroup->getPacketTypes(); + for(std::set<Core::String>::const_iterator type = types.begin(); type != types.end(); ++type) requestHandlerGroups.insert(std::make_pair(*type, requestHandlerGroup)); } void unregisterRequestHandlerGroup(boost::shared_ptr<RequestHandlerGroup> requestHandlerGroup) { boost::lock_guard<boost::shared_mutex> lock(mutex); - const std::set<std::string> &types = requestHandlerGroup->getPacketTypes(); - for(std::set<std::string>::const_iterator type = types.begin(); type != types.end(); ++type) { - std::map<std::string, boost::shared_ptr<RequestHandlerGroup> >::iterator it = requestHandlerGroups.find(*type); + const std::set<Core::String> &types = requestHandlerGroup->getPacketTypes(); + for(std::set<Core::String>::const_iterator type = types.begin(); type != types.end(); ++type) { + std::map<Core::String, boost::shared_ptr<RequestHandlerGroup> >::iterator it = requestHandlerGroups.find(*type); if(it == requestHandlerGroups.end() || it->second != requestHandlerGroup) continue; @@ -164,15 +164,15 @@ class MAD_COMMON_EXPORT RequestManager : private boost::noncopyable { } } - template <class T> void registerPacketType(const std::string &type) { + template <class T> void registerPacketType(const Core::String &type) { registerRequestHandlerGroup(boost::shared_ptr<RequestHandlerFactory0<T> >(new RequestHandlerFactory0<T>(type))); } - template <class T, class T1> void registerPacketType(const std::string &type, T1 arg1) { + template <class T, class T1> void registerPacketType(const Core::String &type, T1 arg1) { registerRequestHandlerGroup(boost::shared_ptr<RequestHandlerFactory1<T, T1> >(new RequestHandlerFactory1<T, T1>(type, arg1))); } - void unregisterPacketType(const std::string &type) { + void unregisterPacketType(const Core::String &type) { boost::lock_guard<boost::shared_mutex> lock(mutex); requestHandlerGroups.erase(type); } diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp index c2b7b71..676c9e1 100644 --- a/src/Common/Requests/DisconnectRequest.cpp +++ b/src/Common/Requests/DisconnectRequest.cpp @@ -32,7 +32,7 @@ void DisconnectRequest::sendRequest() { void DisconnectRequest::handlePacket(boost::shared_ptr<const XmlData> packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get<const std::string&>("Where"), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), + signalFinished(Core::Exception(packet->get<const Core::String&>("Where").extract(), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); return; } diff --git a/src/Common/Requests/IdentifyRequest.cpp b/src/Common/Requests/IdentifyRequest.cpp index 98868ef..a9e566a 100644 --- a/src/Common/Requests/IdentifyRequest.cpp +++ b/src/Common/Requests/IdentifyRequest.cpp @@ -27,8 +27,7 @@ void IdentifyRequest::sendRequest() { Common::XmlData packet; packet.setType("Identify"); - if(!hostname.empty()) - packet.set("hostname", hostname); + packet.set("hostname", hostname); sendPacket(packet); } diff --git a/src/Common/Requests/IdentifyRequest.h b/src/Common/Requests/IdentifyRequest.h index 51b24dd..b0e9669 100644 --- a/src/Common/Requests/IdentifyRequest.h +++ b/src/Common/Requests/IdentifyRequest.h @@ -32,13 +32,13 @@ namespace Requests { class MAD_COMMON_EXPORT IdentifyRequest : public Common::Request { private: - std::string hostname; + Core::String hostname; protected: virtual void sendRequest(); public: - IdentifyRequest(Application *application, const std::string &hostname0) : Request(application), hostname(hostname0) {} + IdentifyRequest(Application *application, const Core::String &hostname0) : Request(application), hostname(hostname0) {} }; } diff --git a/src/Common/Requests/SimpleRequest.h b/src/Common/Requests/SimpleRequest.h index 4bff997..ff0c3c1 100644 --- a/src/Common/Requests/SimpleRequest.h +++ b/src/Common/Requests/SimpleRequest.h @@ -24,7 +24,7 @@ #include "../Request.h" -#include <string> +#include <Core/String.h> namespace Mad { namespace Common { @@ -32,11 +32,11 @@ namespace Requests { class MAD_COMMON_EXPORT SimpleRequest : public Request { protected: - const std::string type; + const Core::String type; virtual void sendRequest(); - SimpleRequest(Application *application, const std::string &type0) : Request(application), type(type0) {} + SimpleRequest(Application *application, const Core::String &type0) : Request(application), type(type0) {} }; } diff --git a/src/Common/StorageBackend.h b/src/Common/StorageBackend.h index 24bb437..13d9f5f 100644 --- a/src/Common/StorageBackend.h +++ b/src/Common/StorageBackend.h @@ -35,19 +35,19 @@ class StorageBackend { protected: friend class StorageManager; - virtual std::set<std::string> listTypes() throw (Core::Exception) = 0; - virtual std::set<std::string> list(const std::string &type) throw (Core::Exception) = 0; + virtual std::set<Core::String> listTypes() throw (Core::Exception) = 0; + virtual std::set<Core::String> list(const Core::String &type) throw (Core::Exception) = 0; - virtual bool exists(const std::string &type, const std::string &name) throw (Core::Exception) { + virtual bool exists(const Core::String &type, const Core::String &name) throw (Core::Exception) { return (list(type).count(name) > 0); } - virtual void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception) = 0; - virtual boost::shared_ptr<XmlData> load(const std::string &type, const std::string &name) throw (Core::Exception) = 0; + virtual void store(const Core::String &type, const Core::String &name, const XmlData *data) throw (Core::Exception) = 0; + virtual boost::shared_ptr<XmlData> load(const Core::String &type, const Core::String &name) throw (Core::Exception) = 0; - virtual void copy(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) = 0; - virtual void rename(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) = 0; - virtual void remove(const std::string &type, const std::string &name) throw (Core::Exception) = 0; + virtual void copy(const Core::String &type, const Core::String &name, const Core::String &newName) throw (Core::Exception) = 0; + virtual void rename(const Core::String &type, const Core::String &name, const Core::String &newName) throw (Core::Exception) = 0; + virtual void remove(const Core::String &type, const Core::String &name) throw (Core::Exception) = 0; public: virtual ~StorageBackend() {} diff --git a/src/Common/StorageManager.cpp b/src/Common/StorageManager.cpp index 5b5fc65..d15d110 100644 --- a/src/Common/StorageManager.cpp +++ b/src/Common/StorageManager.cpp @@ -36,7 +36,7 @@ void StorageManager::unsetBackend(boost::shared_ptr<StorageBackend> oldBackend) backend.reset(); } -std::set<std::string> StorageManager::listTypes() throw (Core::Exception) { +std::set<Core::String> StorageManager::listTypes() throw (Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -44,7 +44,7 @@ std::set<std::string> StorageManager::listTypes() throw (Core::Exception) { return backend->listTypes(); } -std::set<std::string> StorageManager::list(const std::string &type) throw (Core::Exception) { +std::set<Core::String> StorageManager::list(const Core::String &type) throw (Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -52,7 +52,7 @@ std::set<std::string> StorageManager::list(const std::string &type) throw (Core: return backend->list(type); } -bool StorageManager::exists(const std::string &type, const std::string &name) throw (Core::Exception) { +bool StorageManager::exists(const Core::String &type, const Core::String &name) throw (Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -60,7 +60,7 @@ bool StorageManager::exists(const std::string &type, const std::string &name) th return backend->exists(type, name); } -void StorageManager::store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception) { +void StorageManager::store(const Core::String &type, const Core::String &name, const XmlData *data) throw (Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -68,7 +68,7 @@ void StorageManager::store(const std::string &type, const std::string &name, con backend->store(type, name, data); } -boost::shared_ptr<XmlData> StorageManager::load(const std::string &type, const std::string &name) throw (Core::Exception) { +boost::shared_ptr<XmlData> StorageManager::load(const Core::String &type, const Core::String &name) throw (Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -76,7 +76,7 @@ boost::shared_ptr<XmlData> StorageManager::load(const std::string &type, const s return backend->load(type, name); } -void StorageManager::copy(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) { +void StorageManager::copy(const Core::String &type, const Core::String &name, const Core::String &newName) throw (Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -84,7 +84,7 @@ void StorageManager::copy(const std::string &type, const std::string &name, cons backend->copy(type, name, newName); } -void StorageManager::rename(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) { +void StorageManager::rename(const Core::String &type, const Core::String &name, const Core::String &newName) throw (Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -92,7 +92,7 @@ void StorageManager::rename(const std::string &type, const std::string &name, co backend->rename(type, name, newName); } -void StorageManager::remove(const std::string &type, const std::string &name) throw (Core::Exception) { +void StorageManager::remove(const Core::String &type, const Core::String &name) throw (Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); diff --git a/src/Common/StorageManager.h b/src/Common/StorageManager.h index d6cb5f5..a28f7a4 100644 --- a/src/Common/StorageManager.h +++ b/src/Common/StorageManager.h @@ -51,17 +51,17 @@ class MAD_COMMON_EXPORT StorageManager { void setBackend(boost::shared_ptr<StorageBackend> newBackend); void unsetBackend(boost::shared_ptr<StorageBackend> oldBackend); - std::set<std::string> listTypes() throw (Core::Exception); - std::set<std::string> list(const std::string &type) throw (Core::Exception); + std::set<Core::String> listTypes() throw (Core::Exception); + std::set<Core::String> list(const Core::String &type) throw (Core::Exception); - bool exists(const std::string &type, const std::string &name) throw (Core::Exception); + bool exists(const Core::String &type, const Core::String &name) throw (Core::Exception); - void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception); - boost::shared_ptr<XmlData> load(const std::string &type, const std::string &name) throw (Core::Exception); + void store(const Core::String &type, const Core::String &name, const XmlData *data) throw (Core::Exception); + boost::shared_ptr<XmlData> load(const Core::String &type, const Core::String &name) throw (Core::Exception); - void copy(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception); - void rename(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception); - void remove(const std::string &type, const std::string &name) throw (Core::Exception); + void copy(const Core::String &type, const Core::String &name, const Core::String &newName) throw (Core::Exception); + void rename(const Core::String &type, const Core::String &name, const Core::String &newName) throw (Core::Exception); + void remove(const Core::String &type, const Core::String &name) throw (Core::Exception); }; } diff --git a/src/Common/UserCache.cpp b/src/Common/UserCache.cpp index e2bb575..7682fb1 100644 --- a/src/Common/UserCache.cpp +++ b/src/Common/UserCache.cpp @@ -36,7 +36,7 @@ boost::shared_ptr<const std::map<unsigned long, UserInfo> > UserCache::getUserLi userException = Core::Exception(); userTime = newTime; - userNames.reset(new std::map<std::string, unsigned long>); + userNames.reset(new std::map<Core::String, unsigned long>); for(std::map<unsigned long, UserInfo>::const_iterator user = users->begin(); user != users->end(); ++user) userNames->insert(std::make_pair(user->second.getUsername(), user->first)); } @@ -82,13 +82,13 @@ boost::shared_ptr<const UserInfo> UserCache::getUserInfo(unsigned long uid, boos return boost::shared_ptr<UserInfo>(new UserInfo(user->second)); } -boost::shared_ptr<const UserInfo> UserCache::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr<const UserInfo> UserCache::getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { boost::lock_guard<boost::recursive_mutex> lock(mutex); if(!getUserList(timestamp)) return boost::shared_ptr<const UserInfo>(); - std::map<std::string, unsigned long>::const_iterator uid = userNames->find(name); + std::map<Core::String, unsigned long>::const_iterator uid = userNames->find(name); if(uid == userNames->end()) throw Core::Exception(Core::Exception::NOT_FOUND); @@ -127,7 +127,7 @@ boost::shared_ptr<const std::map<unsigned long, GroupInfo> > UserCache::getGroup groupException = Core::Exception(); groupTime = newTime; - groupNames.reset(new std::map<std::string, unsigned long>); + groupNames.reset(new std::map<Core::String, unsigned long>); for(std::map<unsigned long, GroupInfo>::const_iterator group = groups->begin(); group != groups->end(); ++group) groupNames->insert(std::make_pair(group->second.getName(), group->first)); } @@ -173,13 +173,13 @@ boost::shared_ptr<const GroupInfo> UserCache::getGroupInfo(unsigned long gid, bo return boost::shared_ptr<GroupInfo>(new GroupInfo(group->second)); } -boost::shared_ptr<const GroupInfo> UserCache::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr<const GroupInfo> UserCache::getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { boost::lock_guard<boost::recursive_mutex> lock(mutex); if(!getGroupList(timestamp)) return boost::shared_ptr<const GroupInfo>(); - std::map<std::string, unsigned long>::const_iterator gid = groupNames->find(name); + std::map<Core::String, unsigned long>::iterator gid = groupNames->find(name); if(gid == groupNames->end()) throw Core::Exception(Core::Exception::NOT_FOUND); diff --git a/src/Common/UserCache.h b/src/Common/UserCache.h index c579221..6981172 100644 --- a/src/Common/UserCache.h +++ b/src/Common/UserCache.h @@ -45,12 +45,12 @@ class MAD_COMMON_EXPORT UserCache : public UserDBBackend, private boost::noncopy boost::recursive_mutex mutex; boost::shared_ptr<const std::map<unsigned long, UserInfo> > users; - boost::shared_ptr<std::map<std::string, unsigned long> > userNames; + boost::shared_ptr<std::map<Core::String, unsigned long> > userNames; Core::Exception userException; boost::posix_time::ptime userTime; boost::shared_ptr<const std::map<unsigned long, GroupInfo> > groups; - boost::shared_ptr<std::map<std::string, unsigned long> > groupNames; + boost::shared_ptr<std::map<Core::String, unsigned long> > groupNames; Core::Exception groupException; boost::posix_time::ptime groupTime; @@ -62,12 +62,12 @@ class MAD_COMMON_EXPORT UserCache : public UserDBBackend, private boost::noncopy protected: virtual boost::shared_ptr<const std::map<unsigned long, UserInfo> > getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr<const UserInfo> getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr<const UserInfo> getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr<const 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, GroupInfo> > getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr<const GroupInfo> getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr<const GroupInfo> getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr<const 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); @@ -115,7 +115,7 @@ class MAD_COMMON_EXPORT UserCache : public UserDBBackend, private boost::noncopy } - virtual void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { + virtual void setPassword(unsigned long uid, const Core::String &password) throw(Core::Exception) { backend->setPassword(uid, password); } @@ -124,7 +124,7 @@ class MAD_COMMON_EXPORT UserCache : public UserDBBackend, private boost::noncopy userGroupTime(boost::posix_time::not_a_date_time) {} public: - virtual const std::string& getName() { + virtual const Core::String& getName() { return backend->getName(); } }; diff --git a/src/Common/UserConfigBackend.h b/src/Common/UserConfigBackend.h index e7c6245..26f3438 100644 --- a/src/Common/UserConfigBackend.h +++ b/src/Common/UserConfigBackend.h @@ -51,7 +51,7 @@ class UserConfigBackend { virtual void addUserToGroup(const UserInfo &/*userInfo*/, const GroupInfo &/*groupInfo*/) throw(Core::Exception) {} virtual void deleteUserFromGroup(const UserInfo &/*userInfo*/, const GroupInfo &/*groupInfo*/) throw(Core::Exception) {} - virtual void setPassword(const Common::UserInfo &/*userInfo*/, const std::string &/*password*/) throw(Core::Exception) { + virtual void setPassword(const Common::UserInfo &/*userInfo*/, const Core::String &/*password*/) throw(Core::Exception) { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } }; diff --git a/src/Common/UserDBBackend.h b/src/Common/UserDBBackend.h index 8d4c95a..7ac0ba3 100644 --- a/src/Common/UserDBBackend.h +++ b/src/Common/UserDBBackend.h @@ -29,7 +29,6 @@ #include <map> #include <set> -#include <string> #include <boost/date_time/posix_time/posix_time_types.hpp> #include <boost/smart_ptr.hpp> @@ -56,7 +55,7 @@ class UserDBBackend { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } - virtual boost::shared_ptr<const UserInfo> getUserInfoByName(const std::string& /*name*/, boost::posix_time::ptime* /*timestamp*/) throw(Core::Exception) { + virtual boost::shared_ptr<const UserInfo> getUserInfoByName(const Core::String& /*name*/, boost::posix_time::ptime* /*timestamp*/) throw(Core::Exception) { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } @@ -73,7 +72,7 @@ class UserDBBackend { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } - virtual boost::shared_ptr<const GroupInfo> getGroupInfoByName(const std::string& /*name*/, boost::posix_time::ptime* /*timestamp*/) throw(Core::Exception) { + virtual boost::shared_ptr<const GroupInfo> getGroupInfoByName(const Core::String& /*name*/, boost::posix_time::ptime* /*timestamp*/) throw(Core::Exception) { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } @@ -125,14 +124,14 @@ class UserDBBackend { } - virtual void setPassword(unsigned long /*uid*/, const std::string& /*password*/) throw(Core::Exception) { + virtual void setPassword(unsigned long /*uid*/, const Core::String& /*password*/) throw(Core::Exception) { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } public: virtual ~UserDBBackend() {} - virtual const std::string& getName() = 0; + virtual const Core::String& getName() = 0; }; } diff --git a/src/Common/UserInfo.h b/src/Common/UserInfo.h index 6859904..f85b9d8 100644 --- a/src/Common/UserInfo.h +++ b/src/Common/UserInfo.h @@ -22,7 +22,7 @@ #include "export.h" -#include <string> +#include <Core/String.h> namespace Mad { namespace Common { @@ -32,11 +32,11 @@ class UserInfo { unsigned long uid; unsigned long gid; - std::string username; - std::string fullName; + Core::String username; + Core::String fullName; public: - UserInfo(unsigned long uid0 = 0, const std::string& username0 = std::string()) : uid(uid0), gid(0), username(username0) {} + UserInfo(unsigned long uid0 = 0, const Core::String& username0 = Core::String()) : uid(uid0), gid(0), username(username0) {} void setUid(unsigned long newUid) {uid = newUid;} unsigned long getUid() const {return uid;} @@ -44,11 +44,11 @@ class UserInfo { void setGid(unsigned long newGid) {gid = newGid;} unsigned long getGid() const {return gid;} - void setUsername(const std::string& newUsername) {username = newUsername;} - const std::string& getUsername() const {return username;} + void setUsername(const Core::String& newUsername) {username = newUsername;} + const Core::String& getUsername() const {return username;} - void setFullName(const std::string& newFullName) {fullName = newFullName;} - const std::string& getFullName() const {return fullName;} + void setFullName(const Core::String& newFullName) {fullName = newFullName;} + const Core::String& getFullName() const {return fullName;} }; } diff --git a/src/Common/UserLists/UserList.cpp b/src/Common/UserLists/UserList.cpp index a14111d..2fb47cd 100644 --- a/src/Common/UserLists/UserList.cpp +++ b/src/Common/UserLists/UserList.cpp @@ -23,7 +23,7 @@ namespace Mad { namespace Common { namespace UserLists { -std::list<UserListEntry>::iterator UserList::findEntry(const std::string &name) { +std::list<UserListEntry>::iterator UserList::findEntry(const Core::String &name) { for(std::list<UserListEntry>::iterator it = list.begin(); it != list.end(); ++it) { if(it->getName() == name) { return it; @@ -33,7 +33,7 @@ std::list<UserListEntry>::iterator UserList::findEntry(const std::string &name) return list.end(); } -std::list<UserListEntry>::const_iterator UserList::findEntry(const std::string &name) const { +std::list<UserListEntry>::const_iterator UserList::findEntry(const Core::String &name) const { for(std::list<UserListEntry>::const_iterator it = list.begin(); it != list.end(); ++it) { if(it->getName() == name) { return it; @@ -43,14 +43,14 @@ std::list<UserListEntry>::const_iterator UserList::findEntry(const std::string & return list.end(); } -UserList::iterator UserList::find(const std::string &name) { +UserList::iterator UserList::find(const Core::String &name) { if(!names.count(name)) return end(); return iterator(findEntry(name)); } -UserList::const_iterator UserList::find(const std::string &name) const { +UserList::const_iterator UserList::find(const Core::String &name) const { if(!names.count(name)) return end(); @@ -58,22 +58,22 @@ UserList::const_iterator UserList::find(const std::string &name) const { } void UserList::registerEntry(const UserListEntry &entry) { - std::set<std::string> details = entry.getDetailList(); + std::set<Core::String> details = entry.getDetailList(); - for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) { - std::map<std::string, unsigned>::iterator it = detailCounts.find(*detail); + for(std::set<Core::String>::iterator detail = details.begin(); detail != details.end(); ++detail) { + std::map<Core::String, unsigned>::iterator it = detailCounts.find(*detail); if(it == detailCounts.end()) - detailCounts.insert(make_pair(*detail, 1)); + detailCounts.insert(std::make_pair(*detail, 1)); else ++it->second; } } void UserList::unregisterEntry(const UserListEntry &entry) { - std::set<std::string> details = entry.getDetailList(); + std::set<Core::String> details = entry.getDetailList(); - for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) { - std::map<std::string, unsigned>::iterator it = detailCounts.find(*detail); + for(std::set<Core::String>::iterator detail = details.begin(); detail != details.end(); ++detail) { + std::map<Core::String, unsigned>::iterator it = detailCounts.find(*detail); // TODO Assert if(it == detailCounts.end()) continue; @@ -99,7 +99,7 @@ bool UserList::insertUser(const UserListEntry &entry, iterator after) { return true; } -bool UserList::removeUser(const std::string &name) { +bool UserList::removeUser(const Core::String &name) { if(!names.erase(name)) return false; diff --git a/src/Common/UserLists/UserList.h b/src/Common/UserLists/UserList.h index 9c5985d..4e782bf 100644 --- a/src/Common/UserLists/UserList.h +++ b/src/Common/UserLists/UserList.h @@ -89,23 +89,23 @@ class MAD_COMMON_EXPORT UserList { } }; - std::set<std::string> names; + std::set<Core::String> names; std::list<UserListEntry> list; - std::map<std::string, unsigned> detailCounts; + std::map<Core::String, unsigned> detailCounts; void registerEntry(const UserListEntry &entry); void unregisterEntry(const UserListEntry &entry); - std::list<UserListEntry>::iterator findEntry(const std::string &name); - std::list<UserListEntry>::const_iterator findEntry(const std::string &name) const; + std::list<UserListEntry>::iterator findEntry(const Core::String &name); + std::list<UserListEntry>::const_iterator findEntry(const Core::String &name) const; public: typedef iterator_base<const UserListEntry, std::list<UserListEntry>::iterator> iterator; typedef iterator_base<const UserListEntry, std::list<UserListEntry>::const_iterator> const_iterator; - iterator find(const std::string &name); - const_iterator find(const std::string &name) const; + iterator find(const Core::String &name); + const_iterator find(const Core::String &name) const; iterator begin() { return iterator(list.begin()); @@ -131,17 +131,17 @@ class MAD_COMMON_EXPORT UserList { return list.size(); } - std::set<std::string> getDetails() const { - std::set<std::string> ret; + std::set<Core::String> getDetails() const { + std::set<Core::String> ret; - for(std::map<std::string, unsigned>::const_iterator it = detailCounts.begin(); it != detailCounts.end(); ++it) + for(std::map<Core::String, unsigned>::const_iterator it = detailCounts.begin(); it != detailCounts.end(); ++it) ret.insert(it->first); return ret; } - unsigned getDetailUsage(const std::string &detail) const { - std::map<std::string, unsigned>::const_iterator it = detailCounts.find(detail); + unsigned getDetailUsage(const Core::String &detail) const { + std::map<Core::String, unsigned>::const_iterator it = detailCounts.find(detail); if(it == detailCounts.end()) return 0; else @@ -150,7 +150,7 @@ class MAD_COMMON_EXPORT UserList { bool addUser(const UserListEntry &entry); bool insertUser(const UserListEntry &entry, iterator after); - bool removeUser(const std::string &name); + bool removeUser(const Core::String &name); bool updateUser(const UserListEntry &entry); UserList() {} diff --git a/src/Common/UserLists/UserListEntry.h b/src/Common/UserLists/UserListEntry.h index 8642275..acfe445 100644 --- a/src/Common/UserLists/UserListEntry.h +++ b/src/Common/UserLists/UserListEntry.h @@ -20,9 +20,10 @@ #ifndef MAD_COMMON_USERLISTS_USERLISTENTRY_H_ #define MAD_COMMON_USERLISTS_USERLISTENTRY_H_ +#include <Core/String.h> + #include <map> #include <set> -#include <string> namespace Mad { @@ -31,53 +32,53 @@ namespace UserLists { class UserListEntry { private: - std::string name; - std::string group; + Core::String name; + Core::String group; - std::map<std::string, std::string> details; + std::map<Core::String, Core::String> details; public: - UserListEntry(const std::string &name0 = std::string(), const std::string &group0 = std::string()) : name(name0), group(group0) {} + UserListEntry(const Core::String &name0 = Core::String(), const Core::String &group0 = Core::String()) : name(name0), group(group0) {} - const std::string& getName() const { + const Core::String& getName() const { return name; } - void setName(const std::string &newName) { + void setName(const Core::String &newName) { name = newName; } - const std::string& getGroup() const { + const Core::String& getGroup() const { return group; } - void setGroup(const std::string &newGroup) { + void setGroup(const Core::String &newGroup) { group = newGroup; } - std::set<std::string> getDetailList() const { - std::set<std::string> ret; + std::set<Core::String> getDetailList() const { + std::set<Core::String> ret; - for(std::map<std::string, std::string>::const_iterator it = details.begin(); it != details.end(); ++it) + for(std::map<Core::String, Core::String>::const_iterator it = details.begin(); it != details.end(); ++it) ret.insert(it->first); return ret; } - std::string getDetail(const std::string &name) const { - std::map<std::string, std::string>::const_iterator it = details.find(name); + Core::String getDetail(const Core::String &name) const { + std::map<Core::String, Core::String>::const_iterator it = details.find(name); if(it != details.end()) return it->second; else - return std::string(); + return Core::String(); } - void setDetail(const std::string &name, const std::string &value) { + void setDetail(const Core::String &name, const Core::String &value) { details.erase(name); details.insert(std::make_pair(name, value)); } - void unsetDetail(const std::string &name) { + void unsetDetail(const Core::String &name) { details.erase(name); } diff --git a/src/Common/UserLists/Util.cpp b/src/Common/UserLists/Util.cpp index 3c15956..cf04218 100644 --- a/src/Common/UserLists/Util.cpp +++ b/src/Common/UserLists/Util.cpp @@ -26,8 +26,8 @@ namespace Common { namespace UserLists { void Util::serializeUserListEntry(const UserListEntry *user, XmlData::List::iterator entry) { - std::set<std::string> details = user->getDetailList(); - for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) + std::set<Core::String> details = user->getDetailList(); + for(std::set<Core::String>::iterator detail = details.begin(); detail != details.end(); ++detail) entry->set(*detail, user->getDetail(*detail)); entry->set("name", user->getName()); @@ -35,14 +35,14 @@ void Util::serializeUserListEntry(const UserListEntry *user, XmlData::List::iter } UserListEntry Util::deserializeUserListEntry(XmlData::List::const_iterator entry) { - UserListEntry user(entry->get<const std::string&>("name"), entry->get<const std::string&>("group")); + UserListEntry user(entry->get<const Core::String&>("name"), entry->get<const Core::String&>("group")); - std::set<std::string> details = entry->getChildren(); - for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) { + std::set<Core::String> details = entry->getChildren(); + for(std::set<Core::String>::iterator detail = details.begin(); detail != details.end(); ++detail) { if(*detail == "name" || *detail == "group") continue; - user.setDetail(*detail, entry->get<const std::string&>(*detail)); + user.setDetail(*detail, entry->get<const Core::String&>(*detail)); } return user; diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp index f14dbcc..5fb5d15 100644 --- a/src/Common/UserManager.cpp +++ b/src/Common/UserManager.cpp @@ -98,7 +98,7 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl void UserManager::registerBackend(boost::shared_ptr<UserDBBackend> backend) { boost::lock_guard<boost::shared_mutex> lock(mutex); - const std::string &name = backend->getName(); + const Core::String &name = backend->getName(); dbBackends.insert(std::make_pair(backend, std::make_pair(backend, name))); dbBackendNames.insert(std::make_pair(name, backend)); @@ -110,7 +110,7 @@ void UserManager::registerBackend(boost::shared_ptr<UserDBBackend> backend) { void UserManager::registerBackendCached(boost::shared_ptr<UserDBBackend> backend) { boost::lock_guard<boost::shared_mutex> lock(mutex); - const std::string &name = backend->getName(); + const Core::String &name = backend->getName(); boost::shared_ptr<UserCache> cache(new UserCache(application, backend)); @@ -140,7 +140,7 @@ boost::shared_ptr<const UserInfo> UserManager::getUserInfo(unsigned long uid, bo return dbBackend->getUserInfo(uid, timestamp); } -boost::shared_ptr<const UserInfo> UserManager::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr<const UserInfo> UserManager::getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!dbBackend) @@ -176,7 +176,7 @@ boost::shared_ptr<const GroupInfo> UserManager::getGroupInfo(unsigned long gid, return dbBackend->getGroupInfo(gid, timestamp); } -boost::shared_ptr<const GroupInfo> UserManager::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr<const GroupInfo> UserManager::getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { boost::shared_lock<boost::shared_mutex> lock(mutex); if(!dbBackend) @@ -418,7 +418,7 @@ void UserManager::deleteUserFromGroup(unsigned long uid, unsigned long gid) thro } } -void UserManager::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { +void UserManager::setPassword(unsigned long uid, const Core::String &password) throw(Core::Exception) { boost::lock_guard<boost::shared_mutex> lock(mutex); if(!dbBackend) diff --git a/src/Common/UserManager.h b/src/Common/UserManager.h index 6da5af4..0cf7fca 100644 --- a/src/Common/UserManager.h +++ b/src/Common/UserManager.h @@ -46,14 +46,14 @@ class MAD_COMMON_EXPORT UserManager : public Core::Configurable, private boost:: private: friend class Application; - typedef std::map<boost::shared_ptr<UserDBBackend>, std::pair<boost::shared_ptr<UserDBBackend>, std::string> > BackendMap; + typedef std::map<boost::shared_ptr<UserDBBackend>, std::pair<boost::shared_ptr<UserDBBackend>, Core::String> > BackendMap; Application *application; std::set<boost::shared_ptr<UserConfigBackend> > configBackends; BackendMap dbBackends; - std::map<std::string, boost::shared_ptr<UserDBBackend> > dbBackendNames; + std::map<Core::String, boost::shared_ptr<UserDBBackend> > dbBackendNames; boost::shared_ptr<UserDBBackend> dbBackend; @@ -80,7 +80,7 @@ class MAD_COMMON_EXPORT UserManager : public Core::Configurable, private boost:: boost::shared_ptr<UserDBBackend> oldBackend = it->second.first; - std::map<std::string, boost::shared_ptr<UserDBBackend> >::iterator it2 = dbBackendNames.find(it->second.second); + std::map<Core::String, boost::shared_ptr<UserDBBackend> >::iterator it2 = dbBackendNames.find(it->second.second); if(it2->second == backend) dbBackendNames.erase(it2); @@ -107,12 +107,12 @@ class MAD_COMMON_EXPORT UserManager : public Core::Configurable, private boost:: boost::shared_ptr<const std::map<unsigned long, UserInfo> > getUserList(boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr<const UserInfo> getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); - boost::shared_ptr<const UserInfo> getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); + boost::shared_ptr<const UserInfo> getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr<const std::set<unsigned long> > getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr<const std::map<unsigned long, GroupInfo> > getGroupList(boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr<const GroupInfo> getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); - boost::shared_ptr<const GroupInfo> getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); + boost::shared_ptr<const GroupInfo> getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr<const std::set<unsigned long> > getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > getFullUserGroupList(boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); @@ -130,7 +130,7 @@ class MAD_COMMON_EXPORT UserManager : public Core::Configurable, private boost:: void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); - void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); + void setPassword(unsigned long uid, const Core::String &password) throw(Core::Exception); }; } diff --git a/src/Common/XmlData.cpp b/src/Common/XmlData.cpp index aa3fcdf..de9588a 100644 --- a/src/Common/XmlData.cpp +++ b/src/Common/XmlData.cpp @@ -29,13 +29,13 @@ namespace Mad { namespace Common { void XmlData::Element::updateStr() { - std::string typeStr; + Core::String typeStr; if(type == NONE) { str = ""; } else if(type == BINARY) { - str = Base64Encoder::encode(boost::get<std::vector<boost::uint8_t> >(value)); + str = Base64Encoder::encode(boost::get<std::vector<boost::uint8_t> >(value)).c_str(); typeStr = "binary"; } else if(type != STRING) { @@ -73,18 +73,18 @@ void XmlData::Element::updateStr() { break; } - str = buf.str(); + str = buf.str().c_str(); } else typeStr = "string"; - xmlNodePtr newNode = xmlNewText((xmlChar*)str.c_str()); + xmlNodePtr newNode = xmlNewText((xmlChar*)str.extractUTF8().c_str()); xmlNodePtr oldNode = elementNode->children; xmlReplaceNode(oldNode, newNode); xmlFreeNode(oldNode); - xmlSetProp(elementNode, (xmlChar*)"type", (xmlChar*)typeStr.c_str()); + xmlSetProp(elementNode, (xmlChar*)"type", (xmlChar*)typeStr.extractUTF8().c_str()); } XmlData::Element::Element(xmlNodePtr node) : elementNode(node), type(NONE) { @@ -101,13 +101,13 @@ XmlData::Element::Element(xmlNodePtr node) : elementNode(node), type(NONE) { return; } - str = (char*)content; - std::istringstream buf(str); + str = Core::String::fromUTF8((char*)content); + std::istringstream buf(str.extract()); if(!xmlStrcmp(typestr, (xmlChar*)"binary")) { type = BINARY; - value = Base64Encoder::decode(str); + value = Base64Encoder::decode(str.extract()); } else if(!xmlStrcmp(typestr, (xmlChar*)"int")) { type = INT; @@ -180,9 +180,9 @@ XmlData::Entry::Entry(xmlNodePtr node) : entryNode(node) { xmlChar *name = xmlGetProp(element, (xmlChar*)"name"); if(!xmlStrcmp(element->name, (xmlChar*)"list")) - lists.insert(std::make_pair(std::string((char*)name), new List(element))); + lists.insert(std::make_pair(Core::String::fromUTF8((char*)name), new List(element))); else if(!xmlStrcmp(element->name, (xmlChar*)"value")) - elements.insert(std::make_pair(std::string((char*)name), new Element(element))); + elements.insert(std::make_pair(Core::String::fromUTF8((char*)name), new Element(element))); xmlFree(name); } @@ -191,17 +191,17 @@ XmlData::Entry::Entry(xmlNodePtr node) : entryNode(node) { template <> -std::string XmlData::Entry::get<std::string>(const std::string &name) const { +Core::String XmlData::Entry::get<Core::String>(const Core::String &name) const { Element *element = getElement(name); if(!element) - return std::string(); + return Core::String(); return element->str; } template <> -const std::string& XmlData::Entry::get<const std::string&>(const std::string &name) const { - static std::string empty; +const Core::String& XmlData::Entry::get<const Core::String&>(const Core::String &name) const { + static const Core::String empty; Element *element = getElement(name); if(!element) @@ -211,7 +211,7 @@ const std::string& XmlData::Entry::get<const std::string&>(const std::string &na } template <> -std::vector<boost::uint8_t> XmlData::Entry::get<std::vector<unsigned char> >(const std::string &name) const { +std::vector<boost::uint8_t> XmlData::Entry::get<std::vector<unsigned char> >(const Core::String &name) const { Element *element = getElement(name); if(!element) return std::vector<boost::uint8_t>(); @@ -225,8 +225,8 @@ std::vector<boost::uint8_t> XmlData::Entry::get<std::vector<unsigned char> >(con } template <> -const std::vector<boost::uint8_t>& XmlData::Entry::get<const std::vector<unsigned char>&>(const std::string &name) const { - static std::vector<boost::uint8_t> empty; +const std::vector<boost::uint8_t>& XmlData::Entry::get<const std::vector<unsigned char>&>(const Core::String &name) const { + static const std::vector<boost::uint8_t> empty; Element *element = getElement(name); if(!element) @@ -290,18 +290,18 @@ XmlData& XmlData::operator=(const XmlData &o) { return *this; } -std::string XmlData::getType() const { +Core::String XmlData::getType() const { xmlChar *type = xmlGetProp(rootNode, (xmlChar*)"type"); - std::string ret(type ? (char*)type : ""); + Core::String ret(type ? Core::String::fromUTF8((char*)type) : ""); xmlFree(type); return ret; } -void XmlData::setType(const std::string &type) { - xmlSetProp(rootNode, (xmlChar*)"type", (xmlChar*)type.c_str()); +void XmlData::setType(const Core::String &type) { + xmlSetProp(rootNode, (xmlChar*)"type", (xmlChar*)type.extractUTF8().c_str()); } Net::Packet XmlData::toPacket(boost::uint16_t requestId) const { diff --git a/src/Common/XmlData.h b/src/Common/XmlData.h index b7e8ec1..1861b71 100644 --- a/src/Common/XmlData.h +++ b/src/Common/XmlData.h @@ -27,7 +27,6 @@ #include <map> #include <set> -#include <string> #include <sstream> #include <vector> @@ -69,7 +68,7 @@ class MAD_COMMON_EXPORT XmlData { Type type; Variant value; - std::string str; + Core::String str; void updateStr(); @@ -119,7 +118,7 @@ class MAD_COMMON_EXPORT XmlData { set(val, LONGDOUBLE); } - void set(const std::string &val) { + void set(const Core::String &val) { type = STRING; value = Element::Variant(); str = val; @@ -139,11 +138,11 @@ class MAD_COMMON_EXPORT XmlData { xmlNodePtr entryNode; - std::map<std::string, Element*> elements; - std::map<std::string, List*> lists; + std::map<Core::String, Element*> elements; + std::map<Core::String, List*> lists; - Element* getElement(const std::string &name) { - std::map<std::string, Element*>::iterator element = elements.find(name); + Element* getElement(const Core::String &name) { + std::map<Core::String, Element*>::iterator element = elements.find(name); if(element != elements.end()) return element->second; @@ -152,7 +151,7 @@ class MAD_COMMON_EXPORT XmlData { return 0; xmlNodePtr newNode = xmlNewTextChild(entryNode, 0, (xmlChar*)"value", (xmlChar*)""); - xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.c_str()); + xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.extractUTF8().c_str()); xmlSetProp(newNode, (xmlChar*)"type", (xmlChar*)""); Element* newElement = new Element(newNode); @@ -162,8 +161,8 @@ class MAD_COMMON_EXPORT XmlData { return newElement; } - Element* getElement(const std::string &name) const { - std::map<std::string, Element*>::const_iterator element = elements.find(name); + Element* getElement(const Core::String &name) const { + std::map<Core::String, Element*>::const_iterator element = elements.find(name); if(element != elements.end()) return element->second; @@ -173,16 +172,16 @@ class MAD_COMMON_EXPORT XmlData { Entry(xmlNodePtr node); ~Entry() { - for(std::map<std::string, Element*>::iterator element = elements.begin(); element != elements.end(); ++element) + for(std::map<Core::String, Element*>::iterator element = elements.begin(); element != elements.end(); ++element) delete element->second; - for(std::map<std::string, List*>::iterator list = lists.begin(); list != lists.end(); ++list) + for(std::map<Core::String, List*>::iterator list = lists.begin(); list != lists.end(); ++list) delete list->second; } public: template <typename T> - bool set(const std::string &name, T val) { + bool set(const Core::String &name, T val) { Element *element = getElement(name); if(!element) return false; @@ -193,7 +192,7 @@ class MAD_COMMON_EXPORT XmlData { } template <typename T> - T get(const std::string &name) const { + T get(const Core::String &name) const { Element *element = getElement(name); if(!element) return T(); @@ -218,8 +217,8 @@ class MAD_COMMON_EXPORT XmlData { } } - List* createList(const std::string &name, bool unique = false) { - std::map<std::string, List*>::iterator list = lists.find(name); + List* createList(const Core::String &name, bool unique = false) { + std::map<Core::String, List*>::iterator list = lists.find(name); if(list != lists.end()) return unique ? 0 : list->second; @@ -228,7 +227,7 @@ class MAD_COMMON_EXPORT XmlData { return 0; xmlNodePtr newNode = xmlNewChild(entryNode, 0, (xmlChar*)"list", 0); - xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.c_str()); + xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.extractUTF8().c_str()); List *newList = new List(newNode); @@ -237,8 +236,8 @@ class MAD_COMMON_EXPORT XmlData { return newList; } - List* getList(const std::string &name) { - std::map<std::string, List*>::iterator list = lists.find(name); + List* getList(const Core::String &name) { + std::map<Core::String, List*>::iterator list = lists.find(name); if(list == lists.end()) return 0; @@ -246,8 +245,8 @@ class MAD_COMMON_EXPORT XmlData { return list->second; } - const List* getList(const std::string &name) const { - std::map<std::string, List*>::const_iterator list = lists.find(name); + const List* getList(const Core::String &name) const { + std::map<Core::String, List*>::const_iterator list = lists.find(name); if(list == lists.end()) return 0; @@ -255,8 +254,8 @@ class MAD_COMMON_EXPORT XmlData { return list->second; } - void unset(const std::string &name) { - std::map<std::string, Element*>::iterator element = elements.find(name); + void unset(const Core::String &name) { + std::map<Core::String, Element*>::iterator element = elements.find(name); if(element != elements.end()) { xmlUnlinkNode(element->second->elementNode); @@ -269,7 +268,7 @@ class MAD_COMMON_EXPORT XmlData { return; } - std::map<std::string, List*>::iterator list = lists.find(name); + std::map<Core::String, List*>::iterator list = lists.find(name); if(list != lists.end()) { xmlUnlinkNode(list->second->elementNode); @@ -285,19 +284,19 @@ class MAD_COMMON_EXPORT XmlData { return; } - std::set<std::string> getChildren() const { - std::set<std::string> childNames; + std::set<Core::String> getChildren() const { + std::set<Core::String> childNames; - for(std::map<std::string, Element*>::const_iterator it = elements.begin(); it != elements.end(); ++it) + for(std::map<Core::String, Element*>::const_iterator it = elements.begin(); it != elements.end(); ++it) childNames.insert(it->first); return childNames; } - std::set<std::string> getLists() const { - std::set<std::string> listNames; + std::set<Core::String> getLists() const { + std::set<Core::String> listNames; - for(std::map<std::string, List*>::const_iterator it = lists.begin(); it != lists.end(); ++it) + for(std::map<Core::String, List*>::const_iterator it = lists.begin(); it != lists.end(); ++it) listNames.insert(it->first); return listNames; @@ -468,32 +467,32 @@ class MAD_COMMON_EXPORT XmlData { xmlFreeDoc(doc); } - std::string getType() const; - void setType(const std::string &type); + Core::String getType() const; + void setType(const Core::String &type); template <typename T> - bool set(const std::string &name, T val) { + bool set(const Core::String &name, T val) { return entry->set(name, val); } template <typename T> - T get(const std::string &name) const { + T get(const Core::String &name) const { return entry->get<T>(name); } - List* createList(const std::string &name, bool unique = false) { + List* createList(const Core::String &name, bool unique = false) { return entry->createList(name, unique); } - List* getList(const std::string &name) { + List* getList(const Core::String &name) { return entry->getList(name); } - const List* getList(const std::string &name) const { + const List* getList(const Core::String &name) const { return entry->getList(name); } - void unset(const std::string &name) { + void unset(const Core::String &name) { entry->unset(name); } @@ -502,11 +501,11 @@ class MAD_COMMON_EXPORT XmlData { void toFile(const std::string &filename) const throw (Core::Exception); }; -template <> MAD_COMMON_EXPORT std::string XmlData::Entry::get<std::string>(const std::string &name) const; -template <> MAD_COMMON_EXPORT const std::string& XmlData::Entry::get<const std::string&>(const std::string &name) const; +template <> MAD_COMMON_EXPORT Core::String XmlData::Entry::get<Core::String>(const Core::String &name) const; +template <> MAD_COMMON_EXPORT const Core::String& XmlData::Entry::get<const Core::String&>(const Core::String &name) const; -template <> MAD_COMMON_EXPORT std::vector<boost::uint8_t> XmlData::Entry::get<std::vector<unsigned char> >(const std::string &name) const; -template <> MAD_COMMON_EXPORT const std::vector<boost::uint8_t>& XmlData::Entry::get<const std::vector<unsigned char>&>(const std::string &name) const; +template <> MAD_COMMON_EXPORT std::vector<boost::uint8_t> XmlData::Entry::get<std::vector<unsigned char> >(const Core::String &name) const; +template <> MAD_COMMON_EXPORT const std::vector<boost::uint8_t>& XmlData::Entry::get<const std::vector<unsigned char>&>(const Core::String &name) const; } } |