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/Common/AuthBackend.h | 8 +-- src/Common/AuthManager.cpp | 15 ++-- src/Common/AuthManager.h | 12 ++-- src/Common/AuthProvider.h | 6 +- src/Common/Backends/NetworkUserBackend.cpp | 50 ++++++------- src/Common/Backends/NetworkUserBackend.h | 34 ++++----- src/Common/GroupInfo.h | 10 +-- src/Common/Hash.h | 41 +++++++---- src/Common/HostInfo.h | 10 +-- src/Common/Request.cpp | 2 +- src/Common/RequestHandlerGroup.h | 6 +- .../RequestHandlers/FSInfoRequestHandler.cpp | 4 +- .../RequestHandlers/SimpleRequestHandler.cpp | 2 +- src/Common/RequestHandlers/SimpleRequestHandler.h | 4 +- .../RequestHandlers/SimpleRequestHandlerGroup.cpp | 6 +- .../RequestHandlers/SimpleRequestHandlerGroup.h | 14 ++-- src/Common/RequestManager.cpp | 2 +- src/Common/RequestManager.h | 34 ++++----- src/Common/Requests/DisconnectRequest.cpp | 2 +- src/Common/Requests/IdentifyRequest.cpp | 3 +- src/Common/Requests/IdentifyRequest.h | 4 +- src/Common/Requests/SimpleRequest.h | 6 +- src/Common/StorageBackend.h | 16 ++--- src/Common/StorageManager.cpp | 16 ++--- src/Common/StorageManager.h | 16 ++--- src/Common/UserCache.cpp | 12 ++-- src/Common/UserCache.h | 12 ++-- src/Common/UserConfigBackend.h | 2 +- src/Common/UserDBBackend.h | 9 ++- src/Common/UserInfo.h | 16 ++--- src/Common/UserLists/UserList.cpp | 24 +++---- src/Common/UserLists/UserList.h | 24 +++---- src/Common/UserLists/UserListEntry.h | 35 ++++----- src/Common/UserLists/Util.cpp | 12 ++-- src/Common/UserManager.cpp | 10 +-- src/Common/UserManager.h | 12 ++-- src/Common/XmlData.cpp | 42 +++++------ src/Common/XmlData.h | 83 +++++++++++----------- 38 files changed, 313 insertions(+), 303 deletions(-) (limited to 'src/Common') 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 getSubMethods(boost::shared_ptr provider) const = 0; + virtual const Core::String& getMethodName() const = 0; + virtual std::vector getSubMethods(boost::shared_ptr provider) const = 0; - virtual boost::shared_ptr authenticate(boost::shared_ptr provider, const std::string &subMethod, - const std::string &user, const std::vector &data, std::vector &response, + virtual boost::shared_ptr authenticate(boost::shared_ptr provider, const Core::String &subMethod, + const Core::String &user, const std::vector &data, std::vector &response, boost::shared_ptr 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 backend) { void AuthManager::unregisterBackend(boost::shared_ptr backend) { boost::lock_guard lock(mutex); - std::map >::iterator backendIt = backends.find(backend->getMethodName()); + std::map >::iterator backendIt = backends.find(backend->getMethodName()); if(backendIt == backends.end() || backendIt->second != backend) return; @@ -56,16 +56,16 @@ void AuthManager::unregisterBackend(boost::shared_ptr backend) { backends.erase(backendIt); } -std::set AuthManager::getMethods() { +const std::set& AuthManager::getMethods() { boost::shared_lock lock(mutex); return methods; } -std::vector AuthManager::getSubMethods(const std::string &method) throw(Core::Exception) { +std::vector AuthManager::getSubMethods(const Core::String &method) throw(Core::Exception) { boost::shared_lock lock(mutex); - std::map >::iterator backend = backends.find(method); + std::map >::iterator backend = backends.find(method); if(backend == backends.end()) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -75,9 +75,10 @@ std::vector AuthManager::getSubMethods(const std::string &method) t return backend->second->getSubMethods(provider); } -boost::shared_ptr AuthManager::authenticate(const std::string &method, const std::string &subMethod, const std::string &user, - const std::vector &data, std::vector &response, boost::shared_ptr context) throw(Core::Exception) { - std::map >::iterator backend; +boost::shared_ptr AuthManager::authenticate(const Core::String &method, const Core::String &subMethod, + const Core::String &user, const std::vector &data, std::vector &response, + boost::shared_ptr context) throw(Core::Exception) { + std::map >::iterator backend; { boost::lock_guard 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 provider; - std::set methods; - std::map > backends; + std::set methods; + std::map > backends; boost::shared_mutex mutex; @@ -62,11 +62,11 @@ class MAD_COMMON_EXPORT AuthManager : private boost::noncopyable { void registerBackend(boost::shared_ptr backend); void unregisterBackend(boost::shared_ptr backend); - std::set getMethods(); - std::vector getSubMethods(const std::string &method) throw(Core::Exception); + const std::set& getMethods(); + std::vector getSubMethods(const Core::String &method) throw(Core::Exception); - boost::shared_ptr authenticate(const std::string &method, const std::string &subMethod, - const std::string &user, const std::vector &data, std::vector &response, + boost::shared_ptr authenticate(const Core::String &method, const Core::String &subMethod, + const Core::String &user, const std::vector &data, std::vector &response, boost::shared_ptr context = boost::shared_ptr()) 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& getHashes() const = 0; + virtual const std::vector& getHashes() const = 0; - virtual bool checkPassword(const std::string &user, const std::vector &data, 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) { std::vector password = getPassword(user, hash); return (!password.empty() && data.size() == password.size() && std::equal(data.begin(), data.end(), password.begin())); } - virtual std::vector getPassword(const std::string& /*user*/, const std::string& /*hash*/) throw(Core::Exception) { + virtual std::vector 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 > NetworkUserBackend:: if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp").extract()); } catch(...) {} } @@ -148,9 +148,9 @@ boost::shared_ptr > NetworkUserBackend:: boost::shared_ptr > userList(new std::map); for(XmlData::List::const_iterator user = users->begin(); user != users->end(); ++user) { - UserInfo userInfo(user->get("uid"), user->get("username")); + UserInfo userInfo(user->get("uid"), user->get("username")); userInfo.setGid(user->get("gid")); - userInfo.setFullName(user->get("fullName")); + userInfo.setFullName(user->get("fullName")); userList->insert(std::make_pair(userInfo.getUid(), userInfo)); } @@ -174,7 +174,7 @@ boost::shared_ptr NetworkUserBackend::getUserInfo(unsigned long if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp").extract()); } catch(...) {} } @@ -182,10 +182,10 @@ boost::shared_ptr NetworkUserBackend::getUserInfo(unsigned long unsigned long uid2 = result.first->get("uid"); if(uid2) { - boost::shared_ptr userInfo(new UserInfo(uid2, result.first->get("username"))); + boost::shared_ptr userInfo(new UserInfo(uid2, result.first->get("username"))); userInfo->setGid(result.first->get("gid")); - userInfo->setFullName(result.first->get("fullName")); + userInfo->setFullName(result.first->get("fullName")); return userInfo; } @@ -193,7 +193,7 @@ boost::shared_ptr NetworkUserBackend::getUserInfo(unsigned long return boost::shared_ptr(); } -boost::shared_ptr NetworkUserBackend::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr NetworkUserBackend::getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::shared_ptr request(new NameUserRequest(application, "GetUserInfo", name, timestamp)); @@ -206,7 +206,7 @@ boost::shared_ptr NetworkUserBackend::getUserInfoByName(const st if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp").extract()); } catch(...) {} } @@ -214,10 +214,10 @@ boost::shared_ptr NetworkUserBackend::getUserInfoByName(const st unsigned long uid = result.first->get("uid"); if(uid) { - boost::shared_ptr userInfo(new UserInfo(uid, result.first->get("username"))); + boost::shared_ptr userInfo(new UserInfo(uid, result.first->get("username"))); userInfo->setGid(result.first->get("gid")); - userInfo->setFullName(result.first->get("fullName")); + userInfo->setFullName(result.first->get("fullName")); return userInfo; } @@ -238,7 +238,7 @@ boost::shared_ptr > NetworkUserBackend::getUserGro if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp").extract()); } catch(...) {} } @@ -270,7 +270,7 @@ boost::shared_ptr > NetworkUserBackend: if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp").extract()); } catch(...) {} } @@ -280,7 +280,7 @@ boost::shared_ptr > NetworkUserBackend: boost::shared_ptr > groupList(new std::map); for(XmlData::List::const_iterator group = groups->begin(); group != groups->end(); ++group) { - GroupInfo groupInfo(group->get("gid"), group->get("name")); + GroupInfo groupInfo(group->get("gid"), group->get("name")); groupList->insert(std::make_pair(groupInfo.getGid(), groupInfo)); } @@ -303,7 +303,7 @@ boost::shared_ptr NetworkUserBackend::getGroupInfo(unsigned lon if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp").extract()); } catch(...) {} } @@ -311,12 +311,12 @@ boost::shared_ptr NetworkUserBackend::getGroupInfo(unsigned lon unsigned long gid2 = result.first->get("gid"); if(gid2) - return boost::shared_ptr(new GroupInfo(gid2, result.first->get("name"))); + return boost::shared_ptr(new GroupInfo(gid2, result.first->get("name"))); return boost::shared_ptr(); } -boost::shared_ptr NetworkUserBackend::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr NetworkUserBackend::getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::shared_ptr request(new NameUserRequest(application, "GetGroupInfo", name, timestamp)); @@ -329,7 +329,7 @@ boost::shared_ptr NetworkUserBackend::getGroupInfoByName(const if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp").extract()); } catch(...) {} } @@ -337,7 +337,7 @@ boost::shared_ptr NetworkUserBackend::getGroupInfoByName(const unsigned long gid = result.first->get("gid"); if(gid) - return boost::shared_ptr(new GroupInfo(gid, result.first->get("name"))); + return boost::shared_ptr(new GroupInfo(gid, result.first->get("name"))); return boost::shared_ptr(); } @@ -355,7 +355,7 @@ boost::shared_ptr > NetworkUserBackend::getGroupUs if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp").extract()); } catch(...) {} } @@ -387,7 +387,7 @@ boost::shared_ptr > NetworkUse if(timestamp) { try { - *timestamp = boost::posix_time::from_iso_string(result.first->get("timestamp")); + *timestamp = boost::posix_time::from_iso_string(result.first->get("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 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 > getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr > getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr > getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr > getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr > 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 +#include 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 map; - std::vector list; + std::map map; + std::vector 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& getList() const { + const std::vector& getList() const { return list; } - const std::map& getMap() const { + const std::map& getMap() const { return map; } @@ -63,30 +66,38 @@ class MAD_COMMON_EXPORT Hash { static const Hashes hashes; public: - static const std::vector& getHashList() { + static const std::vector& 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 hash(const std::vector &in, unsigned int method) throw (Core::Exception); - static std::vector hash(const std::vector &in, const std::string &method) throw (Core::Exception) { - std::map::const_iterator methodIt = hashes.getMap().find(boost::algorithm::to_lower_copy(method)); + static std::vector hash(const std::vector &in, const Core::String &method) throw (Core::Exception) { + Core::String lowerMethod = method; + lowerMethod.toLower(); + + std::map::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 hash(const std::string &in, unsigned int method) throw (Core::Exception) { - return hash(std::vector(in.begin(), in.end()), method); + static std::vector hash(const Core::String &in, unsigned int method) throw (Core::Exception) { + std::string str = in.extractUTF8(); + return hash(std::vector(str.begin(), str.end()), method); } - static std::vector hash(const std::string &in, const std::string &method) throw (Core::Exception) { - return hash(std::vector(in.begin(), in.end()), method); + static std::vector hash(const Core::String &in, const Core::String &method) throw (Core::Exception) { + std::string str = in.extractUTF8(); + return hash(std::vector(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 +#include 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 packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get("Where"), static_cast(packet->get("ErrorCode")), + signalFinished(Core::Exception(packet->get("Where").extract(), static_cast(packet->get("ErrorCode")), packet->get("SubCode"), packet->get("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 #include -#include namespace Mad { namespace Common { @@ -35,9 +35,9 @@ class RequestHandlerGroup { RequestHandlerGroup() {} public: - virtual const std::set& getPacketTypes() = 0; + virtual const std::set& getPacketTypes() = 0; - virtual boost::shared_ptr createRequestHandler(Application *application, const std::string &type) = 0; + virtual boost::shared_ptr 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_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 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, XmlData*> handler; protected: virtual void handlePacket(boost::shared_ptr packet); - SimpleRequestHandler(Application *application, const std::string &type0, const boost::function2, XmlData*> &handler0) + SimpleRequestHandler(Application *application, const Core::String &type0, const boost::function2, 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 SimpleRequestHandlerGroup::createRequestHandler(Application *application, const std::string &type) { - std::map, XmlData*, Connection*> >::iterator handler = handlers.find(type); +boost::shared_ptr SimpleRequestHandlerGroup::createRequestHandler(Application *application, const Core::String &type) { + std::map, XmlData*, Connection*> >::iterator handler = handlers.find(type); if(handler == handlers.end()) return boost::shared_ptr(); 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, XmlData*, Connection*> handler; protected: virtual void handlePacket(boost::shared_ptr packet); public: - GroupRequestHandler(Application *application, const std::string &type0, const boost::function3, XmlData*, Connection*> &handler0) + GroupRequestHandler(Application *application, const Core::String &type0, const boost::function3, XmlData*, Connection*> &handler0) : RequestHandler(application), type(type0), handler(handler0) {} }; - std::set types; - std::map, XmlData*, Connection*> > handlers; + std::set types; + std::map, XmlData*, Connection*> > handlers; protected: - void registerHandler(const std::string &type, const boost::function3, XmlData*, Connection*> &handler) { + void registerHandler(const Core::String &type, const boost::function3, 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& getPacketTypes() { + virtual const std::set& getPacketTypes() { return types; } - virtual boost::shared_ptr createRequestHandler(Application *application, const std::string &type); + virtual boost::shared_ptr 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 >::iterator rgh = requestHandlerGroups.find(packet->getType()); + std::map >::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 class RequestHandlerFactory0 : public RequestHandlerGroup { private: - std::set types; + std::set types; public: - RequestHandlerFactory0(const std::string &type) { + RequestHandlerFactory0(const Core::String &type) { types.insert(type); } - virtual const std::set& getPacketTypes() { + virtual const std::set& getPacketTypes() { return types; } - virtual boost::shared_ptr createRequestHandler(Application *application, const std::string& /*type*/) { + virtual boost::shared_ptr createRequestHandler(Application *application, const Core::String& /*type*/) { return boost::shared_ptr(new T(application)); } }; template class RequestHandlerFactory1 : public RequestHandlerGroup { private: - std::set types; + std::set 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& getPacketTypes() { + virtual const std::set& getPacketTypes() { return types; } - virtual boost::shared_ptr createRequestHandler(Application *application, const std::string& /*type*/) { + virtual boost::shared_ptr createRequestHandler(Application *application, const Core::String& /*type*/) { return boost::shared_ptr(new T(application, arg1)); } }; @@ -115,7 +115,7 @@ class MAD_COMMON_EXPORT RequestManager : private boost::noncopyable { boost::uint16_t lastRequestId; - std::map > requestHandlerGroups; + std::map > 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) { boost::lock_guard lock(mutex); - const std::set &types = requestHandlerGroup->getPacketTypes(); - for(std::set::const_iterator type = types.begin(); type != types.end(); ++type) + const std::set &types = requestHandlerGroup->getPacketTypes(); + for(std::set::const_iterator type = types.begin(); type != types.end(); ++type) requestHandlerGroups.insert(std::make_pair(*type, requestHandlerGroup)); } void unregisterRequestHandlerGroup(boost::shared_ptr requestHandlerGroup) { boost::lock_guard lock(mutex); - const std::set &types = requestHandlerGroup->getPacketTypes(); - for(std::set::const_iterator type = types.begin(); type != types.end(); ++type) { - std::map >::iterator it = requestHandlerGroups.find(*type); + const std::set &types = requestHandlerGroup->getPacketTypes(); + for(std::set::const_iterator type = types.begin(); type != types.end(); ++type) { + std::map >::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 void registerPacketType(const std::string &type) { + template void registerPacketType(const Core::String &type) { registerRequestHandlerGroup(boost::shared_ptr >(new RequestHandlerFactory0(type))); } - template void registerPacketType(const std::string &type, T1 arg1) { + template void registerPacketType(const Core::String &type, T1 arg1) { registerRequestHandlerGroup(boost::shared_ptr >(new RequestHandlerFactory1(type, arg1))); } - void unregisterPacketType(const std::string &type) { + void unregisterPacketType(const Core::String &type) { boost::lock_guard 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 packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get("Where"), static_cast(packet->get("ErrorCode")), + signalFinished(Core::Exception(packet->get("Where").extract(), static_cast(packet->get("ErrorCode")), packet->get("SubCode"), packet->get("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 +#include 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 listTypes() throw (Core::Exception) = 0; - virtual std::set list(const std::string &type) throw (Core::Exception) = 0; + virtual std::set listTypes() throw (Core::Exception) = 0; + virtual std::set 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 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 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 oldBackend) backend.reset(); } -std::set StorageManager::listTypes() throw (Core::Exception) { +std::set StorageManager::listTypes() throw (Core::Exception) { boost::shared_lock lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -44,7 +44,7 @@ std::set StorageManager::listTypes() throw (Core::Exception) { return backend->listTypes(); } -std::set StorageManager::list(const std::string &type) throw (Core::Exception) { +std::set StorageManager::list(const Core::String &type) throw (Core::Exception) { boost::shared_lock lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -52,7 +52,7 @@ std::set 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 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 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 StorageManager::load(const std::string &type, const std::string &name) throw (Core::Exception) { +boost::shared_ptr StorageManager::load(const Core::String &type, const Core::String &name) throw (Core::Exception) { boost::shared_lock lock(mutex); if(!backend) throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); @@ -76,7 +76,7 @@ boost::shared_ptr 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 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 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 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 newBackend); void unsetBackend(boost::shared_ptr oldBackend); - std::set listTypes() throw (Core::Exception); - std::set list(const std::string &type) throw (Core::Exception); + std::set listTypes() throw (Core::Exception); + std::set 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 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 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 > UserCache::getUserLi userException = Core::Exception(); userTime = newTime; - userNames.reset(new std::map); + userNames.reset(new std::map); for(std::map::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 UserCache::getUserInfo(unsigned long uid, boos return boost::shared_ptr(new UserInfo(user->second)); } -boost::shared_ptr UserCache::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr UserCache::getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { boost::lock_guard lock(mutex); if(!getUserList(timestamp)) return boost::shared_ptr(); - std::map::const_iterator uid = userNames->find(name); + std::map::const_iterator uid = userNames->find(name); if(uid == userNames->end()) throw Core::Exception(Core::Exception::NOT_FOUND); @@ -127,7 +127,7 @@ boost::shared_ptr > UserCache::getGroup groupException = Core::Exception(); groupTime = newTime; - groupNames.reset(new std::map); + groupNames.reset(new std::map); for(std::map::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 UserCache::getGroupInfo(unsigned long gid, bo return boost::shared_ptr(new GroupInfo(group->second)); } -boost::shared_ptr UserCache::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr UserCache::getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { boost::lock_guard lock(mutex); if(!getGroupList(timestamp)) return boost::shared_ptr(); - std::map::const_iterator gid = groupNames->find(name); + std::map::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 > users; - boost::shared_ptr > userNames; + boost::shared_ptr > userNames; Core::Exception userException; boost::posix_time::ptime userTime; boost::shared_ptr > groups; - boost::shared_ptr > groupNames; + boost::shared_ptr > 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 > getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr > getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr > getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr > getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception); virtual boost::shared_ptr > 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 #include -#include #include #include @@ -56,7 +55,7 @@ class UserDBBackend { throw(Core::Exception(Core::Exception::NOT_IMPLEMENTED)); } - virtual boost::shared_ptr getUserInfoByName(const std::string& /*name*/, boost::posix_time::ptime* /*timestamp*/) throw(Core::Exception) { + virtual boost::shared_ptr 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 getGroupInfoByName(const std::string& /*name*/, boost::posix_time::ptime* /*timestamp*/) throw(Core::Exception) { + virtual boost::shared_ptr 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 +#include 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::iterator UserList::findEntry(const std::string &name) { +std::list::iterator UserList::findEntry(const Core::String &name) { for(std::list::iterator it = list.begin(); it != list.end(); ++it) { if(it->getName() == name) { return it; @@ -33,7 +33,7 @@ std::list::iterator UserList::findEntry(const std::string &name) return list.end(); } -std::list::const_iterator UserList::findEntry(const std::string &name) const { +std::list::const_iterator UserList::findEntry(const Core::String &name) const { for(std::list::const_iterator it = list.begin(); it != list.end(); ++it) { if(it->getName() == name) { return it; @@ -43,14 +43,14 @@ std::list::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 details = entry.getDetailList(); + std::set details = entry.getDetailList(); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { - std::map::iterator it = detailCounts.find(*detail); + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + std::map::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 details = entry.getDetailList(); + std::set details = entry.getDetailList(); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { - std::map::iterator it = detailCounts.find(*detail); + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + std::map::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 names; + std::set names; std::list list; - std::map detailCounts; + std::map detailCounts; void registerEntry(const UserListEntry &entry); void unregisterEntry(const UserListEntry &entry); - std::list::iterator findEntry(const std::string &name); - std::list::const_iterator findEntry(const std::string &name) const; + std::list::iterator findEntry(const Core::String &name); + std::list::const_iterator findEntry(const Core::String &name) const; public: typedef iterator_base::iterator> iterator; typedef iterator_base::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 getDetails() const { - std::set ret; + std::set getDetails() const { + std::set ret; - for(std::map::const_iterator it = detailCounts.begin(); it != detailCounts.end(); ++it) + for(std::map::const_iterator it = detailCounts.begin(); it != detailCounts.end(); ++it) ret.insert(it->first); return ret; } - unsigned getDetailUsage(const std::string &detail) const { - std::map::const_iterator it = detailCounts.find(detail); + unsigned getDetailUsage(const Core::String &detail) const { + std::map::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 + #include #include -#include 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 details; + std::map 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 getDetailList() const { - std::set ret; + std::set getDetailList() const { + std::set ret; - for(std::map::const_iterator it = details.begin(); it != details.end(); ++it) + for(std::map::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::const_iterator it = details.find(name); + Core::String getDetail(const Core::String &name) const { + std::map::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 details = user->getDetailList(); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) + std::set details = user->getDetailList(); + for(std::set::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("name"), entry->get("group")); + UserListEntry user(entry->get("name"), entry->get("group")); - std::set details = entry->getChildren(); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + std::set details = entry->getChildren(); + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { if(*detail == "name" || *detail == "group") continue; - user.setDetail(*detail, entry->get(*detail)); + user.setDetail(*detail, entry->get(*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 backend) { boost::lock_guard 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 backend) { void UserManager::registerBackendCached(boost::shared_ptr backend) { boost::lock_guard lock(mutex); - const std::string &name = backend->getName(); + const Core::String &name = backend->getName(); boost::shared_ptr cache(new UserCache(application, backend)); @@ -140,7 +140,7 @@ boost::shared_ptr UserManager::getUserInfo(unsigned long uid, bo return dbBackend->getUserInfo(uid, timestamp); } -boost::shared_ptr UserManager::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr UserManager::getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { boost::shared_lock lock(mutex); if(!dbBackend) @@ -176,7 +176,7 @@ boost::shared_ptr UserManager::getGroupInfo(unsigned long gid, return dbBackend->getGroupInfo(gid, timestamp); } -boost::shared_ptr UserManager::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { +boost::shared_ptr UserManager::getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { boost::shared_lock 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 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, std::pair, std::string> > BackendMap; + typedef std::map, std::pair, Core::String> > BackendMap; Application *application; std::set > configBackends; BackendMap dbBackends; - std::map > dbBackendNames; + std::map > dbBackendNames; boost::shared_ptr dbBackend; @@ -80,7 +80,7 @@ class MAD_COMMON_EXPORT UserManager : public Core::Configurable, private boost:: boost::shared_ptr oldBackend = it->second.first; - std::map >::iterator it2 = dbBackendNames.find(it->second.second); + std::map >::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 > getUserList(boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); - boost::shared_ptr getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); + boost::shared_ptr getUserInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr > getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr > getGroupList(boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); - boost::shared_ptr getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); + boost::shared_ptr getGroupInfoByName(const Core::String &name, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr > getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp = 0) throw(Core::Exception); boost::shared_ptr > 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 >(value)); + str = Base64Encoder::encode(boost::get >(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(const std::string &name) const { +Core::String XmlData::Entry::get(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 &name) const { - static std::string empty; +const Core::String& XmlData::Entry::get(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 &na } template <> -std::vector XmlData::Entry::get >(const std::string &name) const { +std::vector XmlData::Entry::get >(const Core::String &name) const { Element *element = getElement(name); if(!element) return std::vector(); @@ -225,8 +225,8 @@ std::vector XmlData::Entry::get >(con } template <> -const std::vector& XmlData::Entry::get&>(const std::string &name) const { - static std::vector empty; +const std::vector& XmlData::Entry::get&>(const Core::String &name) const { + static const std::vector 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 #include -#include #include #include @@ -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 elements; - std::map lists; + std::map elements; + std::map lists; - Element* getElement(const std::string &name) { - std::map::iterator element = elements.find(name); + Element* getElement(const Core::String &name) { + std::map::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::const_iterator element = elements.find(name); + Element* getElement(const Core::String &name) const { + std::map::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::iterator element = elements.begin(); element != elements.end(); ++element) + for(std::map::iterator element = elements.begin(); element != elements.end(); ++element) delete element->second; - for(std::map::iterator list = lists.begin(); list != lists.end(); ++list) + for(std::map::iterator list = lists.begin(); list != lists.end(); ++list) delete list->second; } public: template - 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 - 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::iterator list = lists.find(name); + List* createList(const Core::String &name, bool unique = false) { + std::map::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::iterator list = lists.find(name); + List* getList(const Core::String &name) { + std::map::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::const_iterator list = lists.find(name); + const List* getList(const Core::String &name) const { + std::map::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::iterator element = elements.find(name); + void unset(const Core::String &name) { + std::map::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::iterator list = lists.find(name); + std::map::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 getChildren() const { - std::set childNames; + std::set getChildren() const { + std::set childNames; - for(std::map::const_iterator it = elements.begin(); it != elements.end(); ++it) + for(std::map::const_iterator it = elements.begin(); it != elements.end(); ++it) childNames.insert(it->first); return childNames; } - std::set getLists() const { - std::set listNames; + std::set getLists() const { + std::set listNames; - for(std::map::const_iterator it = lists.begin(); it != lists.end(); ++it) + for(std::map::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 - bool set(const std::string &name, T val) { + bool set(const Core::String &name, T val) { return entry->set(name, val); } template - T get(const std::string &name) const { + T get(const Core::String &name) const { return entry->get(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(const std::string &name) const; -template <> MAD_COMMON_EXPORT const std::string& XmlData::Entry::get(const std::string &name) const; +template <> MAD_COMMON_EXPORT Core::String XmlData::Entry::get(const Core::String &name) const; +template <> MAD_COMMON_EXPORT const Core::String& XmlData::Entry::get(const Core::String &name) const; -template <> MAD_COMMON_EXPORT std::vector XmlData::Entry::get >(const std::string &name) const; -template <> MAD_COMMON_EXPORT const std::vector& XmlData::Entry::get&>(const std::string &name) const; +template <> MAD_COMMON_EXPORT std::vector XmlData::Entry::get >(const Core::String &name) const; +template <> MAD_COMMON_EXPORT const std::vector& XmlData::Entry::get&>(const Core::String &name) const; } } -- cgit v1.2.3