From 1eb9f4df776adc5dc5cf74a587288199bbf8b703 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 4 Sep 2009 00:24:42 +0200 Subject: Renamed: XmlPacket -> XmlData --- .../ChallengeResponseAuthenticator.cpp | 18 +- .../ChallengeResponseAuthenticator.h | 2 +- .../Authenticators/PasswordAuthenticator.cpp | 16 +- src/Client/Authenticators/PasswordAuthenticator.h | 2 +- src/Client/CommandParser.cpp | 2 +- src/Client/CommandParser.h | 2 +- src/Client/InformationManager.cpp | 8 +- src/Client/InformationManager.h | 4 +- src/Client/Requests/DaemonCommandRequest.cpp | 2 +- src/Client/Requests/DaemonFSInfoRequest.cpp | 2 +- src/Client/Requests/DaemonStatusRequest.cpp | 2 +- src/Client/SystemCommands.cpp | 16 +- src/Client/SystemCommands.h | 6 +- src/Common/Backends/NetworkUserBackend.cpp | 78 ++-- src/Common/CMakeLists.txt | 2 +- src/Common/Connection.cpp | 8 +- src/Common/Connection.h | 8 +- src/Common/Request.cpp | 2 +- src/Common/Request.h | 20 +- src/Common/RequestHandler.cpp | 2 +- src/Common/RequestHandler.h | 6 +- .../RequestHandlers/DisconnectRequestHandler.cpp | 6 +- .../RequestHandlers/DisconnectRequestHandler.h | 2 +- .../RequestHandlers/FSInfoRequestHandler.cpp | 6 +- src/Common/RequestHandlers/FSInfoRequestHandler.h | 2 +- .../RequestHandlers/SimpleRequestHandler.cpp | 6 +- src/Common/RequestHandlers/SimpleRequestHandler.h | 6 +- .../RequestHandlers/SimpleRequestHandlerGroup.cpp | 8 +- .../RequestHandlers/SimpleRequestHandlerGroup.h | 10 +- .../RequestHandlers/StatusRequestHandler.cpp | 2 +- src/Common/RequestHandlers/StatusRequestHandler.h | 2 +- src/Common/RequestManager.cpp | 4 +- src/Common/RequestManager.h | 2 +- src/Common/Requests/DisconnectRequest.cpp | 4 +- src/Common/Requests/DisconnectRequest.h | 2 +- src/Common/Requests/IdentifyRequest.cpp | 2 +- src/Common/Requests/SimpleRequest.cpp | 2 +- src/Common/XmlData.cpp | 311 +++++++++++++ src/Common/XmlData.h | 493 +++++++++++++++++++++ src/Common/XmlPacket.cpp | 311 ------------- src/Common/XmlPacket.h | 493 --------------------- .../RequestHandlers/CommandRequestHandler.cpp | 2 +- src/Daemon/RequestHandlers/CommandRequestHandler.h | 2 +- src/Daemon/Requests/LogRequest.cpp | 2 +- .../ConnectionRequestHandlerGroup.cpp | 22 +- .../ConnectionRequestHandlerGroup.h | 10 +- .../RequestHandlers/DaemonRequestHandlerGroup.cpp | 10 +- .../RequestHandlers/DaemonRequestHandlerGroup.h | 4 +- .../RequestHandlers/UserRequestHandlerGroup.cpp | 56 +-- .../RequestHandlers/UserRequestHandlerGroup.h | 36 +- src/Server/Requests/CommandRequest.cpp | 2 +- src/Server/Requests/DaemonStateUpdateRequest.cpp | 2 +- 52 files changed, 1015 insertions(+), 1015 deletions(-) create mode 100644 src/Common/XmlData.cpp create mode 100644 src/Common/XmlData.h delete mode 100644 src/Common/XmlPacket.cpp delete mode 100644 src/Common/XmlPacket.h diff --git a/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp b/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp index 33e5ccd..4aadb63 100644 --- a/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp +++ b/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp @@ -28,7 +28,7 @@ namespace Client { namespace Authenticators { void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::sendRequest() { - Common::XmlPacket packet; + Common::XmlData packet; packet.setType("Authenticate"); packet.set("method", "Challenge-Response"); packet.set("subMethod", hash); @@ -38,7 +38,7 @@ void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::sendRequest() sendPacket(packet); } -void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::handlePacket(boost::shared_ptr packet) { +void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::handlePacket(boost::shared_ptr packet) { if(packet->getType() == "Error") { signalFinished(Core::Exception(packet->get("Where"), static_cast(packet->get("ErrorCode")), packet->get("SubCode"), packet->get("SubSubCode"))); @@ -51,7 +51,7 @@ void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::handlePacket( return; // TODO Logging } - Common::XmlPacket ret; + Common::XmlData ret; ret.setType("Authenticate"); ret.set("method", "Challenge-Response"); ret.set("subMethod", hash); @@ -88,20 +88,20 @@ void ChallengeResponseAuthenticator::authenticate(Common::Application *applicati application->getRequestManager()->sendRequest(con, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; - const Common::XmlPacket::List *methods = result.first->getList("methods"); + const Common::XmlData::List *methods = result.first->getList("methods"); - for(Common::XmlPacket::List::const_iterator method = methods->begin(); method != methods->end(); ++method) { + for(Common::XmlData::List::const_iterator method = methods->begin(); method != methods->end(); ++method) { if(method->get("name") != "Challenge-Response") continue; - const Common::XmlPacket::List *subMethods = method->getList("subMethods"); + const Common::XmlData::List *subMethods = method->getList("subMethods"); - for(Common::XmlPacket::List::const_iterator subMethod = subMethods->begin(); subMethod != subMethods->end(); ++subMethod) { + for(Common::XmlData::List::const_iterator subMethod = subMethods->begin(); subMethod != subMethods->end(); ++subMethod) { if(Common::Hash::isHashSupported(subMethod->get("name"))) { hash = subMethod->get("name"); break; @@ -122,7 +122,7 @@ void ChallengeResponseAuthenticator::authenticate(Common::Application *applicati application->getRequestManager()->sendRequest(con, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; diff --git a/src/Client/Authenticators/ChallengeResponseAuthenticator.h b/src/Client/Authenticators/ChallengeResponseAuthenticator.h index 61c6f20..3906ba9 100644 --- a/src/Client/Authenticators/ChallengeResponseAuthenticator.h +++ b/src/Client/Authenticators/ChallengeResponseAuthenticator.h @@ -41,7 +41,7 @@ class MAD_CLIENT_EXPORT ChallengeResponseAuthenticator { protected: virtual void sendRequest(); - virtual void handlePacket(boost::shared_ptr packet); + virtual void handlePacket(boost::shared_ptr packet); public: ChallengeResponseAuthRequest(Common::Application *application, const std::string &username0, const std::string &password0, const std::string &hash0) diff --git a/src/Client/Authenticators/PasswordAuthenticator.cpp b/src/Client/Authenticators/PasswordAuthenticator.cpp index 8887d96..bf2a284 100644 --- a/src/Client/Authenticators/PasswordAuthenticator.cpp +++ b/src/Client/Authenticators/PasswordAuthenticator.cpp @@ -28,7 +28,7 @@ namespace Client { namespace Authenticators { void PasswordAuthenticator::PasswordAuthRequest::sendRequest() { - Common::XmlPacket packet; + Common::XmlData packet; packet.setType("Authenticate"); packet.set("method", "Password"); packet.set("subMethod", hash); @@ -43,7 +43,7 @@ void PasswordAuthenticator::PasswordAuthRequest::sendRequest() { sendPacket(packet); } -void PasswordAuthenticator::PasswordAuthRequest::handlePacket(boost::shared_ptr packet) { +void PasswordAuthenticator::PasswordAuthRequest::handlePacket(boost::shared_ptr packet) { if(packet->getType() == "Error") { signalFinished(Core::Exception(packet->get("Where"), static_cast(packet->get("ErrorCode")), packet->get("SubCode"), packet->get("SubSubCode"))); @@ -66,20 +66,20 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo application->getRequestManager()->sendRequest(con, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; - const Common::XmlPacket::List *methods = result.first->getList("methods"); + const Common::XmlData::List *methods = result.first->getList("methods"); - for(Common::XmlPacket::List::const_iterator method = methods->begin(); method != methods->end(); ++method) { + for(Common::XmlData::List::const_iterator method = methods->begin(); method != methods->end(); ++method) { if(method->get("name") != "Password") continue; - const Common::XmlPacket::List *subMethods = method->getList("subMethods"); + const Common::XmlData::List *subMethods = method->getList("subMethods"); - for(Common::XmlPacket::List::const_iterator subMethod = subMethods->begin(); subMethod != subMethods->end(); ++subMethod) { + for(Common::XmlData::List::const_iterator subMethod = subMethods->begin(); subMethod != subMethods->end(); ++subMethod) { if(Common::Hash::isHashSupported(subMethod->get("name"))) { hash = subMethod->get("name"); break; @@ -100,7 +100,7 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo application->getRequestManager()->sendRequest(con, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; diff --git a/src/Client/Authenticators/PasswordAuthenticator.h b/src/Client/Authenticators/PasswordAuthenticator.h index d7b2fbc..70ab3f2 100644 --- a/src/Client/Authenticators/PasswordAuthenticator.h +++ b/src/Client/Authenticators/PasswordAuthenticator.h @@ -39,7 +39,7 @@ class MAD_CLIENT_EXPORT PasswordAuthenticator { protected: virtual void sendRequest(); - virtual void handlePacket(boost::shared_ptr packet); + virtual void handlePacket(boost::shared_ptr packet); public: PasswordAuthRequest(Common::Application *application, const std::string &username0, const std::string &password0, const std::string &hash0) diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index ed0f47e..d93b432 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -202,7 +202,7 @@ void CommandParser::exitCommand(const std::vector &/*args*/) { application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(result.second) std::cerr << "An error occurred during your request: " << result.second.what() << "." << std::endl; diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h index ca168f3..8077a30 100644 --- a/src/Client/CommandParser.h +++ b/src/Client/CommandParser.h @@ -23,7 +23,7 @@ #include "export.h" #include -#include +#include #include #include diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index bcdb4a9..0021d49 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -27,7 +27,7 @@ namespace Mad { namespace Client { -void InformationManager::DaemonStateUpdateRequestHandler::handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret) { +void InformationManager::DaemonStateUpdateRequestHandler::handleRequest(boost::shared_ptr packet, Common::XmlData *ret) { if(!getConnection()->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -69,19 +69,19 @@ void InformationManager::updateDaemonList(Common::Connection *con) { updating = true; } -void InformationManager::daemonListRequestFinished(boost::shared_ptr packet, Core::Exception error) { +void InformationManager::daemonListRequestFinished(boost::shared_ptr packet, Core::Exception error) { boost::lock_guard lock(mutex); if(!packet || error) { application->logf(Core::Logger::LOG_CRITICAL, "Host list request failed: %s", error.what()); } else { - const Common::XmlPacket::List *list = packet->getList("hosts"); + const Common::XmlData::List *list = packet->getList("hosts"); daemons.clear(); if(list) { - for(Common::XmlPacket::List::const_iterator entry = list->begin(); entry != list->end(); ++entry) { + for(Common::XmlData::List::const_iterator entry = list->begin(); entry != list->end(); ++entry) { Common::HostInfo info; info.setName(entry->get("name")); info.setIP(entry->get("address")); diff --git a/src/Client/InformationManager.h b/src/Client/InformationManager.h index 5f68bc2..dcb0212 100644 --- a/src/Client/InformationManager.h +++ b/src/Client/InformationManager.h @@ -43,7 +43,7 @@ class MAD_CLIENT_EXPORT InformationManager : private boost::noncopyable { private: class MAD_CLIENT_EXPORT DaemonStateUpdateRequestHandler : public Common::RequestHandlers::SimpleRequestHandler { private: - void handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret); + void handleRequest(boost::shared_ptr packet, Common::XmlData *ret); public: DaemonStateUpdateRequestHandler(Common::Application *application) @@ -63,7 +63,7 @@ class MAD_CLIENT_EXPORT InformationManager : private boost::noncopyable { bool updating; - void daemonListRequestFinished(boost::shared_ptr packet, Core::Exception error); + void daemonListRequestFinished(boost::shared_ptr packet, Core::Exception error); InformationManager(Application *application0); ~InformationManager(); diff --git a/src/Client/Requests/DaemonCommandRequest.cpp b/src/Client/Requests/DaemonCommandRequest.cpp index e2066e2..12f91e0 100644 --- a/src/Client/Requests/DaemonCommandRequest.cpp +++ b/src/Client/Requests/DaemonCommandRequest.cpp @@ -24,7 +24,7 @@ namespace Client { namespace Requests { void DaemonCommandRequest::sendRequest() { - Common::XmlPacket packet; + Common::XmlData packet; packet.setType("DaemonCommand"); packet.set("command", reboot ? "reboot" : "shutdown"); packet.set("daemon", daemon); diff --git a/src/Client/Requests/DaemonFSInfoRequest.cpp b/src/Client/Requests/DaemonFSInfoRequest.cpp index b7ea81c..8e4c2d7 100644 --- a/src/Client/Requests/DaemonFSInfoRequest.cpp +++ b/src/Client/Requests/DaemonFSInfoRequest.cpp @@ -24,7 +24,7 @@ namespace Client { namespace Requests { void DaemonFSInfoRequest::sendRequest() { - Common::XmlPacket packet; + Common::XmlData packet; packet.setType("DaemonFSInfo"); packet.set("daemon", daemon); diff --git a/src/Client/Requests/DaemonStatusRequest.cpp b/src/Client/Requests/DaemonStatusRequest.cpp index 6de92cb..8986c7e 100644 --- a/src/Client/Requests/DaemonStatusRequest.cpp +++ b/src/Client/Requests/DaemonStatusRequest.cpp @@ -24,7 +24,7 @@ namespace Client { namespace Requests { void DaemonStatusRequest::sendRequest() { - Common::XmlPacket packet; + Common::XmlData packet; packet.setType("GetDaemonStatus"); packet.set("daemon", daemon); diff --git a/src/Client/SystemCommands.cpp b/src/Client/SystemCommands.cpp index f1bcbbd..ff14cc5 100644 --- a/src/Client/SystemCommands.cpp +++ b/src/Client/SystemCommands.cpp @@ -35,15 +35,15 @@ namespace Mad { namespace Client { -void SystemCommands::printFSInfo(boost::shared_ptr &packet) { +void SystemCommands::printFSInfo(boost::shared_ptr &packet) { const std::string units[] = { "kB", "MB", "GB", "TB", "" }; - const Common::XmlPacket::List *list = packet->getList("filesystems"); + const Common::XmlData::List *list = packet->getList("filesystems"); if(list) { - for(Common::XmlPacket::List::const_iterator fs = list->begin(); fs != list->end(); ++fs) { + for(Common::XmlData::List::const_iterator fs = list->begin(); fs != list->end(); ++fs) { unsigned usedUnit = 0, totalUnit = 0; float used = fs->get("usedSize"); @@ -86,7 +86,7 @@ void SystemCommands::printFSInfo(boost::shared_ptr &pac std::printf("\n"); } -void SystemCommands::printHostStatus(boost::shared_ptr &packet) { +void SystemCommands::printHostStatus(boost::shared_ptr &packet) { unsigned long uptime = packet->get("uptime"); if(uptime) { @@ -165,7 +165,7 @@ void SystemCommands::fsinfoCommand(CommandParser *commandParser, const std::vect commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) { std::cerr << "An error occurred during your request: " << result.second.what() << "." << std::endl; @@ -202,7 +202,7 @@ void SystemCommands::rebootCommand(CommandParser *commandParser, const std::vect (*request)->wait(); for(std::vector >::iterator request = requests.begin(); request != requests.end(); ++request) { - std::pair, Core::Exception> result = (*request)->getResult(); + std::pair, Core::Exception> result = (*request)->getResult(); if(result.second) std::cerr << "An error occurred during your request: " << result.second.what() << "." << std::endl; @@ -231,7 +231,7 @@ void SystemCommands::shutdownCommand(CommandParser *commandParser, const std::ve (*request)->wait(); for(std::vector >::iterator request = requests.begin(); request != requests.end(); ++request) { - std::pair, Core::Exception> result = (*request)->getResult(); + std::pair, Core::Exception> result = (*request)->getResult(); if(result.second) std::cerr << "An error occurred during your request: " << result.second.what() << "." << std::endl; @@ -254,7 +254,7 @@ void SystemCommands::statusCommand(CommandParser *commandParser, const std::vect commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) { std::cerr << "An error occurred during your request: " << result.second.what() << "." << std::endl; diff --git a/src/Client/SystemCommands.h b/src/Client/SystemCommands.h index 74b1a62..ba8c361 100644 --- a/src/Client/SystemCommands.h +++ b/src/Client/SystemCommands.h @@ -22,7 +22,7 @@ #include "export.h" -#include +#include #include @@ -37,8 +37,8 @@ class MAD_CLIENT_EXPORT SystemCommands { private: SystemCommands(); - static void printFSInfo(boost::shared_ptr &packet); - static void printHostStatus(boost::shared_ptr &packet); + static void printFSInfo(boost::shared_ptr &packet); + static void printHostStatus(boost::shared_ptr &packet); public: static void fsinfoCommand(CommandParser *commandParser, const std::vector &args); diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp index 00bd378..1b528ab 100644 --- a/src/Common/Backends/NetworkUserBackend.cpp +++ b/src/Common/Backends/NetworkUserBackend.cpp @@ -29,7 +29,7 @@ namespace Backends { const std::string NetworkUserBackend::name("NetworkUserBackend"); void NetworkUserBackend::SimpleUserRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType(type); if(!timestamp.is_not_a_date_time()) @@ -39,7 +39,7 @@ void NetworkUserBackend::SimpleUserRequest::sendRequest() { } void NetworkUserBackend::IdUserRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType(type); packet.set(idType, id); @@ -50,7 +50,7 @@ void NetworkUserBackend::IdUserRequest::sendRequest() { } void NetworkUserBackend::NameUserRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType(type); packet.set("name", name); @@ -61,7 +61,7 @@ void NetworkUserBackend::NameUserRequest::sendRequest() { } void NetworkUserBackend::UserAddRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType(check ? "CheckUserInfo" : "AddUser"); packet.set("uid", userInfo.getUid()); @@ -73,7 +73,7 @@ void NetworkUserBackend::UserAddRequest::sendRequest() { } void NetworkUserBackend::UserUpdateRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType("UpdateUser"); packet.set("origUid", uid); @@ -86,7 +86,7 @@ void NetworkUserBackend::UserUpdateRequest::sendRequest() { } void NetworkUserBackend::GroupAddRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType(check ? "CheckGroupInfo" : "AddGroup"); packet.set("gid", groupInfo.getGid()); @@ -96,7 +96,7 @@ void NetworkUserBackend::GroupAddRequest::sendRequest() { } void NetworkUserBackend::GroupUpdateRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType("UpdateGroup"); packet.set("origGid", gid); @@ -107,7 +107,7 @@ void NetworkUserBackend::GroupUpdateRequest::sendRequest() { } void NetworkUserBackend::UserGroupRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType(type); packet.set("uid", uid); packet.set("gid", gid); @@ -116,7 +116,7 @@ void NetworkUserBackend::UserGroupRequest::sendRequest() { } void NetworkUserBackend::PasswordRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType("SetPassword"); packet.set("uid", uid); packet.set("password", password); @@ -132,7 +132,7 @@ boost::shared_ptr > NetworkUserBackend:: request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; @@ -143,11 +143,11 @@ boost::shared_ptr > NetworkUserBackend:: catch(...) {} } - const XmlPacket::List *users = result.first->getList("users"); + const XmlData::List *users = result.first->getList("users"); if(users) { boost::shared_ptr > userList(new std::map); - for(XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user) { + for(XmlData::List::const_iterator user = users->begin(); user != users->end(); ++user) { UserInfo userInfo(user->get("uid"), user->get("username")); userInfo.setGid(user->get("gid")); userInfo.setFullName(user->get("fullName")); @@ -168,7 +168,7 @@ boost::shared_ptr NetworkUserBackend::getUserInfo(unsigned long application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; @@ -200,7 +200,7 @@ boost::shared_ptr NetworkUserBackend::getUserInfoByName(const st application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; @@ -232,7 +232,7 @@ boost::shared_ptr > NetworkUserBackend::getUserGro application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; @@ -243,12 +243,12 @@ boost::shared_ptr > NetworkUserBackend::getUserGro catch(...) {} } - const XmlPacket::List *groups = result.first->getList("groups"); + const XmlData::List *groups = result.first->getList("groups"); if(groups) { boost::shared_ptr > groupList(new std::set); - for(XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group) + for(XmlData::List::const_iterator group = groups->begin(); group != groups->end(); ++group) groupList->insert(group->get("gid")); return groupList; @@ -264,7 +264,7 @@ boost::shared_ptr > NetworkUserBackend: application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; @@ -275,11 +275,11 @@ boost::shared_ptr > NetworkUserBackend: catch(...) {} } - const XmlPacket::List *groups = result.first->getList("groups"); + const XmlData::List *groups = result.first->getList("groups"); if(groups) { boost::shared_ptr > groupList(new std::map); - for(XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group) { + for(XmlData::List::const_iterator group = groups->begin(); group != groups->end(); ++group) { GroupInfo groupInfo(group->get("gid"), group->get("name")); groupList->insert(std::make_pair(groupInfo.getGid(), groupInfo)); } @@ -297,7 +297,7 @@ boost::shared_ptr NetworkUserBackend::getGroupInfo(unsigned lon application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; @@ -323,7 +323,7 @@ boost::shared_ptr NetworkUserBackend::getGroupInfoByName(const application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; @@ -349,7 +349,7 @@ boost::shared_ptr > NetworkUserBackend::getGroupUs application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; @@ -360,11 +360,11 @@ boost::shared_ptr > NetworkUserBackend::getGroupUs catch(...) {} } - const XmlPacket::List *users = result.first->getList("users"); + const XmlData::List *users = result.first->getList("users"); if(users) { boost::shared_ptr > userList(new std::set); - for(XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user) { + for(XmlData::List::const_iterator user = users->begin(); user != users->end(); ++user) { userList->insert(user->get("uid")); } @@ -381,7 +381,7 @@ boost::shared_ptr > NetworkUse application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; @@ -392,11 +392,11 @@ boost::shared_ptr > NetworkUse catch(...) {} } - const XmlPacket::List *list = result.first->getList("userGroupList"); + const XmlData::List *list = result.first->getList("userGroupList"); if(list) { boost::shared_ptr > ret(new std::multimap); - for(XmlPacket::List::const_iterator entry = list->begin(); entry != list->end(); ++entry) + for(XmlData::List::const_iterator entry = list->begin(); entry != list->end(); ++entry) ret->insert(std::make_pair(entry->get("uid"), entry->get("gid"))); return ret; @@ -413,7 +413,7 @@ void NetworkUserBackend::checkUserInfo(const UserInfo &userInfo) throw(Core::Exc application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -425,7 +425,7 @@ void NetworkUserBackend::addUser(const UserInfo &userInfo) throw(Core::Exception application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -437,7 +437,7 @@ void NetworkUserBackend::updateUser(unsigned long uid, const Common::UserInfo &u application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -449,7 +449,7 @@ void NetworkUserBackend::deleteUser(unsigned long uid) throw(Core::Exception) { application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -462,7 +462,7 @@ void NetworkUserBackend::checkGroupInfo(const GroupInfo &groupInfo) throw(Core:: application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -474,7 +474,7 @@ void NetworkUserBackend::addGroup(const GroupInfo &groupInfo) throw(Core::Except application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -486,7 +486,7 @@ void NetworkUserBackend::updateGroup(unsigned long gid, const GroupInfo &groupIn application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -498,7 +498,7 @@ void NetworkUserBackend::deleteGroup(unsigned long gid) throw(Core::Exception) { application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -511,7 +511,7 @@ void NetworkUserBackend::addUserToGroup(unsigned long uid, unsigned long gid) th application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -523,7 +523,7 @@ void NetworkUserBackend::deleteUserFromGroup(unsigned long uid, unsigned long gi application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } @@ -536,7 +536,7 @@ void NetworkUserBackend::setPassword(unsigned long uid, const std::string &passw application->getRequestManager()->sendRequest(connection, request); request->wait(); - std::pair, Core::Exception> result = request->getResult(); + std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) throw result.second; } diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index a92648b..493081d 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -42,6 +42,6 @@ mad_library(Common UserCache.cpp UserCache.h UserInfo.h UserManager.cpp UserManager.h - XmlPacket.cpp XmlPacket.h + XmlData.cpp XmlData.h ) target_link_libraries(Common Net Core modules ${LIBXML2_LIBRARIES} ${MHASH_LIBRARY} ${DL_LIBRARY}) diff --git a/src/Common/Connection.cpp b/src/Common/Connection.cpp index b2bb835..c8b2bb1 100644 --- a/src/Common/Connection.cpp +++ b/src/Common/Connection.cpp @@ -18,17 +18,17 @@ */ #include "Connection.h" -#include "XmlPacket.h" +#include "XmlData.h" namespace Mad { namespace Common { void Connection::receive(boost::shared_ptr packet) { - signalReceive.emit(boost::shared_ptr(new XmlPacket(*packet)), packet->getRequestId()); + signalReceive.emit(boost::shared_ptr(new XmlData(*packet)), packet->getRequestId()); } -bool Connection::sendPacket(const XmlPacket &packet, boost::uint16_t requestId) { - return send(packet.encode(requestId)); +bool Connection::sendPacket(const XmlData &packet, boost::uint16_t requestId) { + return send(packet.toPacket(requestId)); } } diff --git a/src/Common/Connection.h b/src/Common/Connection.h index 2a04de0..b19e0b9 100644 --- a/src/Common/Connection.h +++ b/src/Common/Connection.h @@ -35,11 +35,11 @@ class Packet; namespace Common { -class XmlPacket; +class XmlData; class MAD_COMMON_EXPORT Connection : private boost::noncopyable { private: - Core::Signals::Signal2, boost::uint16_t> signalReceive; + Core::Signals::Signal2, boost::uint16_t> signalReceive; protected: Connection(Core::Application *application) : signalReceive(application) {} @@ -51,9 +51,9 @@ class MAD_COMMON_EXPORT Connection : private boost::noncopyable { public: virtual ~Connection() {} - bool sendPacket(const XmlPacket &packet, boost::uint16_t requestId); + bool sendPacket(const XmlData &packet, boost::uint16_t requestId); - Core::Signals::Connection connectSignalReceive(const Core::Signals::Signal2, boost::uint16_t>::slot_type &slot) { + Core::Signals::Connection connectSignalReceive(const Core::Signals::Signal2, boost::uint16_t>::slot_type &slot) { return signalReceive.connect(slot); } void disconnectSignalReceive(const Core::Signals::Connection &con) { diff --git a/src/Common/Request.cpp b/src/Common/Request.cpp index 9325d46..0edfcfd 100644 --- a/src/Common/Request.cpp +++ b/src/Common/Request.cpp @@ -22,7 +22,7 @@ namespace Mad { namespace Common { -void Request::handlePacket(boost::shared_ptr packet) { +void Request::handlePacket(boost::shared_ptr packet) { if(packet->getType() == "Error") { signalFinished(Core::Exception(packet->get("Where"), static_cast(packet->get("ErrorCode")), packet->get("SubCode"), packet->get("SubSubCode"))); diff --git a/src/Common/Request.h b/src/Common/Request.h index 268a196..d46e1b7 100644 --- a/src/Common/Request.h +++ b/src/Common/Request.h @@ -43,15 +43,15 @@ class MAD_COMMON_EXPORT Request : public RequestHandler { boost::condition_variable finishCond; bool isFinished; - boost::shared_ptr packet; + boost::shared_ptr packet; Core::Exception exception; - Core::Signals::Signal2, Core::Exception> finished; + Core::Signals::Signal2, Core::Exception> finished; protected: Request(Application *application) : RequestHandler(application), isFinished(false), finished(application) {} - void signalFinished(boost::shared_ptr pkt, Core::Exception exp) { + void signalFinished(boost::shared_ptr pkt, Core::Exception exp) { { boost::lock_guard lock(mutex); @@ -66,23 +66,23 @@ class MAD_COMMON_EXPORT Request : public RequestHandler { RequestHandler::signalFinished(); } - void signalFinished(boost::shared_ptr packet) { + void signalFinished(boost::shared_ptr packet) { signalFinished(packet, Core::Exception()); } void signalFinished(Core::Exception exp) { - signalFinished(boost::shared_ptr(), exp); + signalFinished(boost::shared_ptr(), exp); } void signalFinished() { - signalFinished(boost::shared_ptr(), Core::Exception()); + signalFinished(boost::shared_ptr(), Core::Exception()); } virtual void sendRequest() = 0; - virtual void handlePacket(boost::shared_ptr packet); + virtual void handlePacket(boost::shared_ptr packet); public: - Core::Signals::Connection connectSignalFinished(const Core::Signals::Signal2, Core::Exception>::slot_type &slot) { + Core::Signals::Connection connectSignalFinished(const Core::Signals::Signal2, Core::Exception>::slot_type &slot) { return finished.connect(slot); } void disconnectSignalFinished(const Core::Signals::Connection &con) { @@ -96,11 +96,11 @@ class MAD_COMMON_EXPORT Request : public RequestHandler { finishCond.wait(lock); } - std::pair, Core::Exception> getResult() { + std::pair, Core::Exception> getResult() { boost::lock_guard lock(mutex); if(!isFinished) - return std::make_pair(boost::shared_ptr(), Core::Exception(Core::Exception::NOT_FINISHED)); + return std::make_pair(boost::shared_ptr(), Core::Exception(Core::Exception::NOT_FINISHED)); else return std::make_pair(packet, exception); } diff --git a/src/Common/RequestHandler.cpp b/src/Common/RequestHandler.cpp index 3469448..50c8f11 100644 --- a/src/Common/RequestHandler.cpp +++ b/src/Common/RequestHandler.cpp @@ -29,7 +29,7 @@ Connection* RequestHandler::getConnection() const { return getRequestManager()->requestMap.getRequestInfo(this).first; } -void RequestHandler::sendPacket(const XmlPacket &packet) { +void RequestHandler::sendPacket(const XmlData &packet) { std::pair requestInfo = getRequestManager()->requestMap.getRequestInfo(this); if(!requestInfo.first) diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h index 6d15c09..6fcbd3a 100644 --- a/src/Common/RequestHandler.h +++ b/src/Common/RequestHandler.h @@ -24,7 +24,7 @@ #include "Application.h" #include "Connection.h" -#include "XmlPacket.h" +#include "XmlData.h" #include @@ -55,9 +55,9 @@ class MAD_COMMON_EXPORT RequestHandler : private boost::noncopyable { Connection* getConnection() const; - void sendPacket(const XmlPacket &packet); + void sendPacket(const XmlData &packet); - virtual void handlePacket(boost::shared_ptr packet) = 0; + virtual void handlePacket(boost::shared_ptr packet) = 0; public: virtual ~RequestHandler() {} diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp index d6b3449..90c976c 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp @@ -24,11 +24,11 @@ namespace Mad { namespace Common { namespace RequestHandlers { -void DisconnectRequestHandler::handlePacket(boost::shared_ptr packet) { +void DisconnectRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != "Disconnect") { getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); - XmlPacket ret; + XmlData ret; ret.setType("Error"); ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET); @@ -38,7 +38,7 @@ void DisconnectRequestHandler::handlePacket(boost::shared_ptr p return; } - XmlPacket ret; + XmlData ret; ret.setType("OK"); sendPacket(ret); diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.h b/src/Common/RequestHandlers/DisconnectRequestHandler.h index f4bc827..f3a1fce 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.h +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.h @@ -30,7 +30,7 @@ namespace RequestHandlers { class MAD_COMMON_EXPORT DisconnectRequestHandler : public RequestHandler { protected: - virtual void handlePacket(boost::shared_ptr packet); + virtual void handlePacket(boost::shared_ptr packet); public: DisconnectRequestHandler(Application *application) : RequestHandler(application) {} diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp index a416af4..af4bf50 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp @@ -24,7 +24,7 @@ namespace Mad { namespace Common { namespace RequestHandlers { -void FSInfoRequestHandler::handleRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret) { +void FSInfoRequestHandler::handleRequest(boost::shared_ptr /*packet*/, Common::XmlData *ret) { if(!getConnection()->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -32,10 +32,10 @@ void FSInfoRequestHandler::handleRequest(boost::shared_ptrgetSystemManager()->getFSInfo(&fsInfo); ret->setType("OK"); - XmlPacket::List *list = ret->createList("filesystems"); + XmlData::List *list = ret->createList("filesystems"); for(std::vector::const_iterator fs = fsInfo.begin(); fs != fsInfo.end(); ++fs) { - XmlPacket::List::iterator entry = list->addEntry(); + XmlData::List::iterator entry = list->addEntry(); entry->set("name", fs->fsName); entry->set("mountedOn", fs->mountedOn); diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h index 17c1d8e..745eaae 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.h +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h @@ -30,7 +30,7 @@ namespace RequestHandlers { class MAD_COMMON_EXPORT FSInfoRequestHandler : public SimpleRequestHandler { private: - void handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret); + void handleRequest(boost::shared_ptr packet, Common::XmlData *ret); public: FSInfoRequestHandler(Application *application) : SimpleRequestHandler(application, "FSInfo", boost::bind(&FSInfoRequestHandler::handleRequest, this, _1, _2)) {} diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.cpp b/src/Common/RequestHandlers/SimpleRequestHandler.cpp index 33dfd5a..86edca6 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandler.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandler.cpp @@ -25,11 +25,11 @@ namespace Mad { namespace Common { namespace RequestHandlers { -void SimpleRequestHandler::handlePacket(boost::shared_ptr packet) { +void SimpleRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != type) { getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); - XmlPacket ret; + XmlData ret; ret.setType("Error"); ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET); @@ -39,7 +39,7 @@ void SimpleRequestHandler::handlePacket(boost::shared_ptr packe return; } - XmlPacket ret; + XmlData ret; try { handler(packet, &ret); diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.h b/src/Common/RequestHandlers/SimpleRequestHandler.h index 3cf0f52..85cbd4c 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandler.h +++ b/src/Common/RequestHandlers/SimpleRequestHandler.h @@ -31,12 +31,12 @@ namespace RequestHandlers { class MAD_COMMON_EXPORT SimpleRequestHandler : public RequestHandler { private: std::string type; - boost::function2, XmlPacket*> handler; + boost::function2, XmlData*> handler; protected: - virtual void handlePacket(boost::shared_ptr packet); + virtual void handlePacket(boost::shared_ptr packet); - SimpleRequestHandler(Application *application, const std::string &type0, const boost::function2, XmlPacket*> &handler0) + SimpleRequestHandler(Application *application, const std::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 4d6a0e4..a7debc3 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp @@ -26,11 +26,11 @@ namespace Mad { namespace Common { namespace RequestHandlers { -void SimpleRequestHandlerGroup::GroupRequestHandler::handlePacket(boost::shared_ptr packet) { +void SimpleRequestHandlerGroup::GroupRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != type) { getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); - XmlPacket ret; + XmlData ret; ret.setType("Error"); ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET); @@ -40,7 +40,7 @@ void SimpleRequestHandlerGroup::GroupRequestHandler::handlePacket(boost::shared_ return; } - XmlPacket ret; + XmlData ret; try { handler(packet, &ret, getConnection()); @@ -58,7 +58,7 @@ void SimpleRequestHandlerGroup::GroupRequestHandler::handlePacket(boost::shared_ } boost::shared_ptr SimpleRequestHandlerGroup::createRequestHandler(Application *application, const std::string &type) { - std::map, XmlPacket*, Connection*> >::iterator handler = handlers.find(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 0a702f8..2022705 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h +++ b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h @@ -33,21 +33,21 @@ class MAD_COMMON_EXPORT SimpleRequestHandlerGroup : public RequestHandlerGroup { class MAD_COMMON_EXPORT GroupRequestHandler : public RequestHandler { private: std::string type; - boost::function3, XmlPacket*, Connection*> handler; + boost::function3, XmlData*, Connection*> handler; protected: - virtual void handlePacket(boost::shared_ptr packet); + virtual void handlePacket(boost::shared_ptr packet); public: - GroupRequestHandler(Application *application, const std::string &type0, const boost::function3, XmlPacket*, Connection*> &handler0) + GroupRequestHandler(Application *application, const std::string &type0, const boost::function3, XmlData*, Connection*> &handler0) : RequestHandler(application), type(type0), handler(handler0) {} }; std::set types; - std::map, XmlPacket*, Connection*> > handlers; + std::map, XmlData*, Connection*> > handlers; protected: - void registerHandler(const std::string &type, const boost::function3, XmlPacket*, Connection*> &handler) { + void registerHandler(const std::string &type, const boost::function3, XmlData*, Connection*> &handler) { types.insert(type); handlers.insert(std::make_pair(type, handler)); } diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp index e5d87da..20b49e0 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.cpp +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -24,7 +24,7 @@ namespace Mad { namespace Common { namespace RequestHandlers { -void StatusRequestHandler::handleRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret) { +void StatusRequestHandler::handleRequest(boost::shared_ptr /*packet*/, Common::XmlData *ret) { if(!getConnection()->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); diff --git a/src/Common/RequestHandlers/StatusRequestHandler.h b/src/Common/RequestHandlers/StatusRequestHandler.h index 4e79da8..e5301fa 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.h +++ b/src/Common/RequestHandlers/StatusRequestHandler.h @@ -30,7 +30,7 @@ namespace RequestHandlers { class MAD_COMMON_EXPORT StatusRequestHandler : public SimpleRequestHandler { private: - void handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret); + void handleRequest(boost::shared_ptr packet, Common::XmlData *ret); public: StatusRequestHandler(Application *application) : SimpleRequestHandler(application, "GetStatus", boost::bind(&StatusRequestHandler::handleRequest, this, _1, _2)) {} diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index 82ecd00..12134e0 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -86,7 +86,7 @@ std::pair RequestManager::RequestMap::getRequestIn } -void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr packet, boost::uint16_t requestId) { +void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr packet, boost::uint16_t requestId) { boost::upgrade_lock lock(mutex); boost::shared_ptr request = requestMap.findRequest(connection, requestId); @@ -126,7 +126,7 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr packet, boost::uint16_t requestId); + void receiveHandler(Connection *connection, boost::shared_ptr packet, boost::uint16_t requestId); void handleRequestFinished(Connection *con, boost::uint16_t requestId) { boost::lock_guard lock(mutex); diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp index 523ef2a..c2b7b71 100644 --- a/src/Common/Requests/DisconnectRequest.cpp +++ b/src/Common/Requests/DisconnectRequest.cpp @@ -24,13 +24,13 @@ namespace Common { namespace Requests { void DisconnectRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType("Disconnect"); sendPacket(packet); } -void DisconnectRequest::handlePacket(boost::shared_ptr packet) { +void DisconnectRequest::handlePacket(boost::shared_ptr packet) { if(packet->getType() == "Error") { signalFinished(Core::Exception(packet->get("Where"), static_cast(packet->get("ErrorCode")), packet->get("SubCode"), packet->get("SubSubCode"))); diff --git a/src/Common/Requests/DisconnectRequest.h b/src/Common/Requests/DisconnectRequest.h index a92c7e7..a905a56 100644 --- a/src/Common/Requests/DisconnectRequest.h +++ b/src/Common/Requests/DisconnectRequest.h @@ -31,7 +31,7 @@ namespace Requests { class MAD_COMMON_EXPORT DisconnectRequest : public Request { protected: virtual void sendRequest(); - virtual void handlePacket(boost::shared_ptr packet); + virtual void handlePacket(boost::shared_ptr packet); public: DisconnectRequest(Application *application) : Request(application) {} diff --git a/src/Common/Requests/IdentifyRequest.cpp b/src/Common/Requests/IdentifyRequest.cpp index fc31c3f..98868ef 100644 --- a/src/Common/Requests/IdentifyRequest.cpp +++ b/src/Common/Requests/IdentifyRequest.cpp @@ -24,7 +24,7 @@ namespace Common { namespace Requests { void IdentifyRequest::sendRequest() { - Common::XmlPacket packet; + Common::XmlData packet; packet.setType("Identify"); if(!hostname.empty()) diff --git a/src/Common/Requests/SimpleRequest.cpp b/src/Common/Requests/SimpleRequest.cpp index a16e1d4..452b6da 100644 --- a/src/Common/Requests/SimpleRequest.cpp +++ b/src/Common/Requests/SimpleRequest.cpp @@ -24,7 +24,7 @@ namespace Common { namespace Requests { void SimpleRequest::sendRequest() { - XmlPacket packet; + XmlData packet; packet.setType(type); sendPacket(packet); diff --git a/src/Common/XmlData.cpp b/src/Common/XmlData.cpp new file mode 100644 index 0000000..d3c948b --- /dev/null +++ b/src/Common/XmlData.cpp @@ -0,0 +1,311 @@ +/* + * XmlData.cpp + * + * Copyright (C) 2009 Matthias Schiffer + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program. If not, see . + */ + +#include "XmlData.h" +#include "Base64Encoder.h" +#include +#include + +#include + +namespace Mad { +namespace Common { + +void XmlData::Element::updateStr() { + std::string typeStr; + + if(type == NONE) { + str = ""; + } + else if(type == BINARY) { + str = Base64Encoder::encode(boost::get >(value)); + typeStr = "binary"; + } + else if(type != STRING) { + std::ostringstream buf; + + switch(type) { + case INT: + buf << boost::get(value); + typeStr = "int"; + break; + case UINT: + buf << boost::get(value); + typeStr = "uint"; + break; + case INT64: + buf << boost::get(value); + typeStr = "int64"; + break; + case UINT64: + buf << boost::get(value); + typeStr = "uint64"; + break; + case FLOAT: + buf << boost::get(value); + typeStr = "float"; + break; + case DOUBLE: + buf << boost::get(value); + typeStr = "double"; + break; + case LONGDOUBLE: + buf << boost::get(value); + typeStr = "longdouble"; + default: + break; + } + + str = buf.str(); + } + else + typeStr = "string"; + + xmlNodePtr newNode = xmlNewText((xmlChar*)str.c_str()); + xmlNodePtr oldNode = elementNode->children; + + xmlReplaceNode(oldNode, newNode); + xmlFreeNode(oldNode); + + xmlSetProp(elementNode, (xmlChar*)"type", (xmlChar*)typeStr.c_str()); +} + +XmlData::Element::Element(xmlNodePtr node) : elementNode(node), type(NONE) { + if(!node) + return; + + xmlChar *typestr = xmlGetProp(node, (xmlChar*)"type"); + if(!typestr) + return; + + xmlChar *content = xmlNodeGetContent(node->children); + if(!content) { + xmlFree(typestr); + return; + } + + str = (char*)content; + std::istringstream buf(str); + + if(!xmlStrcmp(typestr, (xmlChar*)"binary")) { + type = BINARY; + + value = Base64Encoder::decode(str); + } + else if(!xmlStrcmp(typestr, (xmlChar*)"int")) { + type = INT; + + long tmp; + buf >> tmp; + value = tmp; + } + else if(!xmlStrcmp(typestr, (xmlChar*)"uint")) { + type = UINT; + + unsigned long tmp; + buf >> tmp; + value = tmp; + } + else if(!xmlStrcmp(typestr, (xmlChar*)"int64")) { + type = INT64; + + long long tmp; + buf >> tmp; + value = tmp; + } + else if(!xmlStrcmp(typestr, (xmlChar*)"uint64")) { + type = UINT64; + + unsigned long long tmp; + buf >> tmp; + value = tmp; + } + else if(!xmlStrcmp(typestr, (xmlChar*)"float")) { + type = FLOAT; + + float tmp; + buf >> tmp; + value = tmp; + } + else if(!xmlStrcmp(typestr, (xmlChar*)"double")) { + type = DOUBLE; + + double tmp; + buf >> tmp; + value = tmp; + } + else if(!xmlStrcmp(typestr, (xmlChar*)"longdouble")) { + type = LONGDOUBLE; + + long double tmp; + buf >> tmp; + value = tmp; + } + else if(!xmlStrcmp(typestr, (xmlChar*)"string")) { + type = STRING; + } + + xmlFree(typestr); + xmlFree(content); + + if(type != NONE) + updateStr(); +} + +XmlData::Entry::Entry(xmlNodePtr node) : entryNode(node) { + if(!node) + return; + + for(xmlNodePtr element = node->children; element != 0; element = element->next) { + if(element->type != XML_ELEMENT_NODE) + continue; + + xmlChar *name = xmlGetProp(element, (xmlChar*)"name"); + + if(!xmlStrcmp(element->name, (xmlChar*)"list")) + lists.insert(std::make_pair(std::string((char*)name), new List(element))); + else if(!xmlStrcmp(element->name, (xmlChar*)"value")) + elements.insert(std::make_pair(std::string((char*)name), new Element(element))); + + xmlFree(name); + } +} + + + +template <> +std::string XmlData::Entry::get(const std::string &name) const { + Element *element = getElement(name); + if(!element) + return std::string(); + + return element->str; +} + +template <> +const std::string& XmlData::Entry::get(const std::string &name) const { + static std::string empty; + + Element *element = getElement(name); + if(!element) + return empty; + + return element->str; +} + +template <> +std::vector XmlData::Entry::get >(const std::string &name) const { + Element *element = getElement(name); + if(!element) + return std::vector(); + + switch(element->type) { + case Element::BINARY: + return boost::get >(element->value); + default: + return std::vector(); + } +} + +template <> +const std::vector& XmlData::Entry::get&>(const std::string &name) const { + static std::vector empty; + + Element *element = getElement(name); + if(!element) + return empty; + + switch(element->type) { + case Element::BINARY: + return boost::get >(element->value); + default: + return empty; + } +} + +XmlData::List::List(xmlNodePtr node) : elementNode(node) { + for(xmlNodePtr entry = node->children; entry != 0; entry = entry->next) { + if(entry->type != XML_ELEMENT_NODE || xmlStrcmp(entry->name, (xmlChar*)"entry")) + continue; + + entries.push_back(new Entry(entry)); + } +} + +XmlData::XmlData() { + doc = xmlNewDoc((xmlChar*)"1.0"); + + rootNode = xmlNewNode(0, (xmlChar*)"mad"); + xmlDocSetRootElement(doc, rootNode); + + entry = new Entry(rootNode); +} + +XmlData::XmlData(const XmlData &o) { + doc = xmlCopyDoc(o.doc, 1); + rootNode = xmlDocGetRootElement(doc); + entry = new Entry(rootNode); +} + +XmlData::XmlData(const Net::Packet &packet) { + doc = xmlParseMemory((const char*)packet.getData(), packet.getLength()); + rootNode = xmlDocGetRootElement(doc); + entry = new Entry(rootNode); +} + +XmlData& XmlData::operator=(const XmlData &o) { + delete entry; + xmlFreeDoc(doc); + + doc = xmlCopyDoc(o.doc, 1); + rootNode = xmlDocGetRootElement(doc); + entry = new Entry(rootNode); + + return *this; +} + +std::string XmlData::getType() const { + xmlChar *type = xmlGetProp(rootNode, (xmlChar*)"type"); + + std::string ret(type ? (char*)type : ""); + + xmlFree(type); + + return ret; +} + +void XmlData::setType(const std::string &type) { + xmlSetProp(rootNode, (xmlChar*)"type", (xmlChar*)type.c_str()); +} + +Net::Packet XmlData::toPacket(boost::uint16_t requestId) const { + xmlChar *buf; + int length; + + xmlDocDumpMemory(doc, &buf, &length); + + Net::Packet packet(requestId, buf, length); + + xmlFree(buf); + + return packet; +} + +} +} diff --git a/src/Common/XmlData.h b/src/Common/XmlData.h new file mode 100644 index 0000000..216b0f1 --- /dev/null +++ b/src/Common/XmlData.h @@ -0,0 +1,493 @@ +/* + * XmlData.h + * + * Copyright (C) 2009 Matthias Schiffer + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program. If not, see . + */ + +#ifndef MAD_COMMON_XMLDATA_H_ +#define MAD_COMMON_XMLDATA_H_ + +#include "export.h" + +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include + +namespace Mad { +namespace Common { + +class MAD_COMMON_EXPORT XmlData { + public: + class Entry; + class List; + + private: + xmlDocPtr doc; + xmlNodePtr rootNode; + Entry *entry; + + class MAD_COMMON_EXPORT Element : private boost::noncopyable { + private: + friend class Entry; + + enum Type { + NONE, BINARY, + INT, UINT, INT64, UINT64, + FLOAT, DOUBLE, LONGDOUBLE, STRING + }; + + typedef boost::variant > Variant; + + xmlNodePtr elementNode; + + Type type; + Variant value; + + std::string str; + + void updateStr(); + + Element(xmlNodePtr node); + + template + void set(T val, Type type0) { + type = type0; + value = val; + + updateStr(); + } + + void set(int val) { + set(val, INT); + } + + void set(unsigned int val) { + set(val, UINT); + } + + void set(long val) { + set(val, INT); + } + + void set(unsigned long val) { + set(val, UINT); + } + + void set(long long val) { + set(val, INT64); + } + + void set(unsigned long long val) { + set(val, UINT64); + } + + void set(float val) { + set(val, FLOAT); + } + + void set(double val) { + set(val, DOUBLE); + } + + void set(long double val) { + set(val, LONGDOUBLE); + } + + void set(const std::string &val) { + type = STRING; + value = Element::Variant(); + str = val; + updateStr(); + } + + void set(const std::vector &val) { + set(val, BINARY); + } + }; + + public: + class MAD_COMMON_EXPORT Entry : private boost::noncopyable { + private: + friend class List; + friend class XmlData; + + xmlNodePtr entryNode; + + std::map elements; + std::map lists; + + Element* getElement(const std::string &name) { + std::map::iterator element = elements.find(name); + + if(element != elements.end()) + return element->second; + + if(lists.find(name) != lists.end()) + return 0; + + xmlNodePtr newNode = xmlNewTextChild(entryNode, 0, (xmlChar*)"value", (xmlChar*)""); + xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.c_str()); + xmlSetProp(newNode, (xmlChar*)"type", (xmlChar*)""); + + Element* newElement = new Element(newNode); + + elements.insert(std::make_pair(name, newElement)); + + return newElement; + } + + Element* getElement(const std::string &name) const { + std::map::const_iterator element = elements.find(name); + + if(element != elements.end()) + return element->second; + else + return 0; + } + + Entry(xmlNodePtr node); + ~Entry() { + 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) + delete list->second; + } + + public: + template + bool set(const std::string &name, T val) { + Element *element = getElement(name); + if(!element) + return false; + + element->set(val); + + return true; + } + + template + T get(const std::string &name) const { + Element *element = getElement(name); + if(!element) + return T(); + + switch(element->type) { + case Element::INT: + return static_cast(boost::get(element->value)); + case Element::UINT: + return static_cast(boost::get(element->value)); + case Element::INT64: + return static_cast(boost::get(element->value)); + case Element::UINT64: + return static_cast(boost::get(element->value)); + case Element::FLOAT: + return static_cast(boost::get(element->value)); + case Element::DOUBLE: + return static_cast(boost::get(element->value)); + case Element::LONGDOUBLE: + return static_cast(boost::get(element->value)); + default: + return static_cast(0); + } + } + + List* createList(const std::string &name, bool unique = false) { + std::map::iterator list = lists.find(name); + + if(list != lists.end()) + return unique ? 0 : list->second; + + if(elements.find(name) != elements.end()) + return 0; + + xmlNodePtr newNode = xmlNewChild(entryNode, 0, (xmlChar*)"list", 0); + xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.c_str()); + + List *newList = new List(newNode); + + lists.insert(std::make_pair(name, newList)); + + return newList; + } + + List* getList(const std::string &name) { + std::map::iterator list = lists.find(name); + + if(list == lists.end()) + return 0; + + return list->second; + } + + const List* getList(const std::string &name) const { + std::map::const_iterator list = lists.find(name); + + if(list == lists.end()) + return 0; + + return list->second; + } + + void unset(const std::string &name) { + std::map::iterator element = elements.find(name); + + if(element != elements.end()) { + xmlUnlinkNode(element->second->elementNode); + xmlFreeNode(element->second->elementNode); + + delete element->second; + + elements.erase(element); + + return; + } + + std::map::iterator list = lists.find(name); + + if(list != lists.end()) { + xmlUnlinkNode(list->second->elementNode); + xmlFreeNode(list->second->elementNode); + + delete list->second; + + lists.erase(list); + + return; + } + + return; + } + }; + + class MAD_COMMON_EXPORT List : private boost::noncopyable { + private: + friend class Entry; + + xmlNodePtr elementNode; + + std::vector entries; + + template + class iterator_base { + public: + friend class List; + + typedef Type value_type; + + typedef value_type &reference; + typedef value_type *pointer; + + typedef long difference_type; + + private: + IteratorType it; + + iterator_base(IteratorType it0) : it(it0) {} + + public: + iterator_base() {} + + reference operator*() const { + return **it; + } + + iterator_base operator+(const difference_type &n) const { + return iterator(it+n); + } + + iterator_base operator++(int) { + return iterator(it++); + } + + iterator_base& operator++() { + ++it; + return *this; + } + + iterator_base& operator+=(const difference_type &n) { + it += n; + return *this; + } + + iterator_base operator-(const difference_type &n) const { + return iterator(it-n); + } + + iterator_base operator--(int) { + return iterator(it--); + } + + iterator_base& operator--() { + --it; + return *this; + } + + iterator_base& operator-=(const difference_type &n) { + it -= n; + return *this; + } + + bool operator==(const iterator_base &it2) { + return it2.it == it; + } + + bool operator!=(const iterator_base &it2) { + return it2.it != it; + } + + pointer operator->() const { + return *it; + } + + reference operator[](const difference_type &n) const { + return *it[n]; + } + }; + + List(xmlNodePtr node); + ~List() { + for(std::vector::iterator entry = entries.begin(); entry != entries.end(); ++entry) + delete *entry; + } + + public: + typedef iterator_base::iterator> iterator; + typedef iterator_base::const_iterator> const_iterator; + + size_t getSize() const { + return entries.size(); + } + + bool isEmpty() const { + return entries.empty(); + } + + Entry& operator[](size_t i) { + return *entries[i]; + } + + const Entry& operator[](size_t i) const { + return *entries[i]; + } + + iterator begin() { + return iterator(entries.begin()); + } + + const_iterator begin() const { + return const_iterator(entries.begin()); + } + + iterator end() { + return iterator(entries.end()); + } + + const_iterator end() const { + return const_iterator(entries.end()); + } + + iterator insertEntry(iterator it) { + xmlNodePtr newNode = xmlNewNode(0, (xmlChar*)"entry"); + + if(it == end()) + xmlAddChild(elementNode, newNode); + else + xmlAddPrevSibling(it->entryNode, newNode); + + return iterator(entries.insert(it.it, new Entry(newNode))); + } + + iterator addEntry() { + return insertEntry(end()); + } + + void removeEntry(iterator it) { + xmlUnlinkNode(it->entryNode); + xmlFreeNode(it->entryNode); + delete *it.it; + + entries.erase(it.it); + } + }; + + XmlData(); + XmlData(const XmlData &o); + XmlData(const Net::Packet &packet); + + XmlData& operator=(const XmlData &o); + + virtual ~XmlData() { + delete entry; + + xmlFreeDoc(doc); + } + + std::string getType() const; + void setType(const std::string &type); + + template + bool set(const std::string &name, T val) { + return entry->set(name, val); + } + + template + T get(const std::string &name) const { + return entry->get(name); + } + + List* createList(const std::string &name, bool unique = false) { + return entry->createList(name, unique); + } + + List* getList(const std::string &name) { + return entry->getList(name); + } + + const List* getList(const std::string &name) const { + return entry->getList(name); + } + + void unset(const std::string &name) { + entry->unset(name); + } + + Net::Packet toPacket(boost::uint16_t requestId) const; +}; + +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 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; + +} +} + +#endif /* MAD_COMMON_XMLDATA_H_ */ diff --git a/src/Common/XmlPacket.cpp b/src/Common/XmlPacket.cpp deleted file mode 100644 index ff8ca6a..0000000 --- a/src/Common/XmlPacket.cpp +++ /dev/null @@ -1,311 +0,0 @@ -/* - * XmlProcessor.cpp - * - * Copyright (C) 2009 Matthias Schiffer - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along - * with this program. If not, see . - */ - -#include "XmlPacket.h" -#include "Base64Encoder.h" -#include -#include - -#include - -namespace Mad { -namespace Common { - -void XmlPacket::Element::updateStr() { - std::string typeStr; - - if(type == NONE) { - str = ""; - } - else if(type == BINARY) { - str = Base64Encoder::encode(boost::get >(value)); - typeStr = "binary"; - } - else if(type != STRING) { - std::ostringstream buf; - - switch(type) { - case INT: - buf << boost::get(value); - typeStr = "int"; - break; - case UINT: - buf << boost::get(value); - typeStr = "uint"; - break; - case INT64: - buf << boost::get(value); - typeStr = "int64"; - break; - case UINT64: - buf << boost::get(value); - typeStr = "uint64"; - break; - case FLOAT: - buf << boost::get(value); - typeStr = "float"; - break; - case DOUBLE: - buf << boost::get(value); - typeStr = "double"; - break; - case LONGDOUBLE: - buf << boost::get(value); - typeStr = "longdouble"; - default: - break; - } - - str = buf.str(); - } - else - typeStr = "string"; - - xmlNodePtr newNode = xmlNewText((xmlChar*)str.c_str()); - xmlNodePtr oldNode = elementNode->children; - - xmlReplaceNode(oldNode, newNode); - xmlFreeNode(oldNode); - - xmlSetProp(elementNode, (xmlChar*)"type", (xmlChar*)typeStr.c_str()); -} - -XmlPacket::Element::Element(xmlNodePtr node) : elementNode(node), type(NONE) { - if(!node) - return; - - xmlChar *typestr = xmlGetProp(node, (xmlChar*)"type"); - if(!typestr) - return; - - xmlChar *content = xmlNodeGetContent(node->children); - if(!content) { - xmlFree(typestr); - return; - } - - str = (char*)content; - std::istringstream buf(str); - - if(!xmlStrcmp(typestr, (xmlChar*)"binary")) { - type = BINARY; - - value = Base64Encoder::decode(str); - } - else if(!xmlStrcmp(typestr, (xmlChar*)"int")) { - type = INT; - - long tmp; - buf >> tmp; - value = tmp; - } - else if(!xmlStrcmp(typestr, (xmlChar*)"uint")) { - type = UINT; - - unsigned long tmp; - buf >> tmp; - value = tmp; - } - else if(!xmlStrcmp(typestr, (xmlChar*)"int64")) { - type = INT64; - - long long tmp; - buf >> tmp; - value = tmp; - } - else if(!xmlStrcmp(typestr, (xmlChar*)"uint64")) { - type = UINT64; - - unsigned long long tmp; - buf >> tmp; - value = tmp; - } - else if(!xmlStrcmp(typestr, (xmlChar*)"float")) { - type = FLOAT; - - float tmp; - buf >> tmp; - value = tmp; - } - else if(!xmlStrcmp(typestr, (xmlChar*)"double")) { - type = DOUBLE; - - double tmp; - buf >> tmp; - value = tmp; - } - else if(!xmlStrcmp(typestr, (xmlChar*)"longdouble")) { - type = LONGDOUBLE; - - long double tmp; - buf >> tmp; - value = tmp; - } - else if(!xmlStrcmp(typestr, (xmlChar*)"string")) { - type = STRING; - } - - xmlFree(typestr); - xmlFree(content); - - if(type != NONE) - updateStr(); -} - -XmlPacket::Entry::Entry(xmlNodePtr node) : entryNode(node) { - if(!node) - return; - - for(xmlNodePtr element = node->children; element != 0; element = element->next) { - if(element->type != XML_ELEMENT_NODE) - continue; - - xmlChar *name = xmlGetProp(element, (xmlChar*)"name"); - - if(!xmlStrcmp(element->name, (xmlChar*)"list")) - lists.insert(std::make_pair(std::string((char*)name), new List(element))); - else if(!xmlStrcmp(element->name, (xmlChar*)"value")) - elements.insert(std::make_pair(std::string((char*)name), new Element(element))); - - xmlFree(name); - } -} - - - -template <> -std::string XmlPacket::Entry::get(const std::string &name) const { - Element *element = getElement(name); - if(!element) - return std::string(); - - return element->str; -} - -template <> -const std::string& XmlPacket::Entry::get(const std::string &name) const { - static std::string empty; - - Element *element = getElement(name); - if(!element) - return empty; - - return element->str; -} - -template <> -std::vector XmlPacket::Entry::get >(const std::string &name) const { - Element *element = getElement(name); - if(!element) - return std::vector(); - - switch(element->type) { - case Element::BINARY: - return boost::get >(element->value); - default: - return std::vector(); - } -} - -template <> -const std::vector& XmlPacket::Entry::get&>(const std::string &name) const { - static std::vector empty; - - Element *element = getElement(name); - if(!element) - return empty; - - switch(element->type) { - case Element::BINARY: - return boost::get >(element->value); - default: - return empty; - } -} - -XmlPacket::List::List(xmlNodePtr node) : elementNode(node) { - for(xmlNodePtr entry = node->children; entry != 0; entry = entry->next) { - if(entry->type != XML_ELEMENT_NODE || xmlStrcmp(entry->name, (xmlChar*)"entry")) - continue; - - entries.push_back(new Entry(entry)); - } -} - -XmlPacket::XmlPacket() { - doc = xmlNewDoc((xmlChar*)"1.0"); - - packetNode = xmlNewNode(0, (xmlChar*)"packet"); - xmlDocSetRootElement(doc, packetNode); - - entry = new Entry(packetNode); -} - -XmlPacket::XmlPacket(const XmlPacket &o) { - doc = xmlCopyDoc(o.doc, 1); - packetNode = xmlDocGetRootElement(doc); - entry = new Entry(packetNode); -} - -XmlPacket::XmlPacket(const Net::Packet &packet) { - doc = xmlParseMemory((const char*)packet.getData(), packet.getLength()); - packetNode = xmlDocGetRootElement(doc); - entry = new Entry(packetNode); -} - -XmlPacket& XmlPacket::operator=(const XmlPacket &o) { - delete entry; - xmlFreeDoc(doc); - - doc = xmlCopyDoc(o.doc, 1); - packetNode = xmlDocGetRootElement(doc); - entry = new Entry(packetNode); - - return *this; -} - -std::string XmlPacket::getType() const { - xmlChar *type = xmlGetProp(packetNode, (xmlChar*)"type"); - - std::string ret(type ? (char*)type : ""); - - xmlFree(type); - - return ret; -} - -void XmlPacket::setType(const std::string &type) { - xmlSetProp(packetNode, (xmlChar*)"type", (xmlChar*)type.c_str()); -} - -Net::Packet XmlPacket::encode(boost::uint16_t requestId) const { - xmlChar *buf; - int length; - - xmlDocDumpMemory(doc, &buf, &length); - - Net::Packet packet(requestId, buf, length); - - xmlFree(buf); - - return packet; -} - -} -} diff --git a/src/Common/XmlPacket.h b/src/Common/XmlPacket.h deleted file mode 100644 index 1902f82..0000000 --- a/src/Common/XmlPacket.h +++ /dev/null @@ -1,493 +0,0 @@ -/* - * XmlProcessor.h - * - * Copyright (C) 2009 Matthias Schiffer - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along - * with this program. If not, see . - */ - -#ifndef MAD_COMMON_XMLPACKET_H_ -#define MAD_COMMON_XMLPACKET_H_ - -#include "export.h" - -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include - -namespace Mad { -namespace Common { - -class MAD_COMMON_EXPORT XmlPacket { - public: - class Entry; - class List; - - private: - xmlDocPtr doc; - xmlNodePtr packetNode; - Entry *entry; - - class MAD_COMMON_EXPORT Element : private boost::noncopyable { - private: - friend class Entry; - - enum Type { - NONE, BINARY, - INT, UINT, INT64, UINT64, - FLOAT, DOUBLE, LONGDOUBLE, STRING - }; - - typedef boost::variant > Variant; - - xmlNodePtr elementNode; - - Type type; - Variant value; - - std::string str; - - void updateStr(); - - Element(xmlNodePtr node); - - template - void set(T val, Type type0) { - type = type0; - value = val; - - updateStr(); - } - - void set(int val) { - set(val, INT); - } - - void set(unsigned int val) { - set(val, UINT); - } - - void set(long val) { - set(val, INT); - } - - void set(unsigned long val) { - set(val, UINT); - } - - void set(long long val) { - set(val, INT64); - } - - void set(unsigned long long val) { - set(val, UINT64); - } - - void set(float val) { - set(val, FLOAT); - } - - void set(double val) { - set(val, DOUBLE); - } - - void set(long double val) { - set(val, LONGDOUBLE); - } - - void set(const std::string &val) { - type = STRING; - value = Element::Variant(); - str = val; - updateStr(); - } - - void set(const std::vector &val) { - set(val, BINARY); - } - }; - - public: - class MAD_COMMON_EXPORT Entry : private boost::noncopyable { - private: - friend class List; - friend class XmlPacket; - - xmlNodePtr entryNode; - - std::map elements; - std::map lists; - - Element* getElement(const std::string &name) { - std::map::iterator element = elements.find(name); - - if(element != elements.end()) - return element->second; - - if(lists.find(name) != lists.end()) - return 0; - - xmlNodePtr newNode = xmlNewTextChild(entryNode, 0, (xmlChar*)"value", (xmlChar*)""); - xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.c_str()); - xmlSetProp(newNode, (xmlChar*)"type", (xmlChar*)""); - - Element* newElement = new Element(newNode); - - elements.insert(std::make_pair(name, newElement)); - - return newElement; - } - - Element* getElement(const std::string &name) const { - std::map::const_iterator element = elements.find(name); - - if(element != elements.end()) - return element->second; - else - return 0; - } - - Entry(xmlNodePtr node); - ~Entry() { - 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) - delete list->second; - } - - public: - template - bool set(const std::string &name, T val) { - Element *element = getElement(name); - if(!element) - return false; - - element->set(val); - - return true; - } - - template - T get(const std::string &name) const { - Element *element = getElement(name); - if(!element) - return T(); - - switch(element->type) { - case Element::INT: - return static_cast(boost::get(element->value)); - case Element::UINT: - return static_cast(boost::get(element->value)); - case Element::INT64: - return static_cast(boost::get(element->value)); - case Element::UINT64: - return static_cast(boost::get(element->value)); - case Element::FLOAT: - return static_cast(boost::get(element->value)); - case Element::DOUBLE: - return static_cast(boost::get(element->value)); - case Element::LONGDOUBLE: - return static_cast(boost::get(element->value)); - default: - return static_cast(0); - } - } - - List* createList(const std::string &name, bool unique = false) { - std::map::iterator list = lists.find(name); - - if(list != lists.end()) - return unique ? 0 : list->second; - - if(elements.find(name) != elements.end()) - return 0; - - xmlNodePtr newNode = xmlNewChild(entryNode, 0, (xmlChar*)"list", 0); - xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.c_str()); - - List *newList = new List(newNode); - - lists.insert(std::make_pair(name, newList)); - - return newList; - } - - List* getList(const std::string &name) { - std::map::iterator list = lists.find(name); - - if(list == lists.end()) - return 0; - - return list->second; - } - - const List* getList(const std::string &name) const { - std::map::const_iterator list = lists.find(name); - - if(list == lists.end()) - return 0; - - return list->second; - } - - void unset(const std::string &name) { - std::map::iterator element = elements.find(name); - - if(element != elements.end()) { - xmlUnlinkNode(element->second->elementNode); - xmlFreeNode(element->second->elementNode); - - delete element->second; - - elements.erase(element); - - return; - } - - std::map::iterator list = lists.find(name); - - if(list != lists.end()) { - xmlUnlinkNode(list->second->elementNode); - xmlFreeNode(list->second->elementNode); - - delete list->second; - - lists.erase(list); - - return; - } - - return; - } - }; - - class MAD_COMMON_EXPORT List : private boost::noncopyable { - private: - friend class Entry; - - xmlNodePtr elementNode; - - std::vector entries; - - template - class iterator_base { - public: - friend class List; - - typedef Type value_type; - - typedef value_type &reference; - typedef value_type *pointer; - - typedef long difference_type; - - private: - IteratorType it; - - iterator_base(IteratorType it0) : it(it0) {} - - public: - iterator_base() {} - - reference operator*() const { - return **it; - } - - iterator_base operator+(const difference_type &n) const { - return iterator(it+n); - } - - iterator_base operator++(int) { - return iterator(it++); - } - - iterator_base& operator++() { - ++it; - return *this; - } - - iterator_base& operator+=(const difference_type &n) { - it += n; - return *this; - } - - iterator_base operator-(const difference_type &n) const { - return iterator(it-n); - } - - iterator_base operator--(int) { - return iterator(it--); - } - - iterator_base& operator--() { - --it; - return *this; - } - - iterator_base& operator-=(const difference_type &n) { - it -= n; - return *this; - } - - bool operator==(const iterator_base &it2) { - return it2.it == it; - } - - bool operator!=(const iterator_base &it2) { - return it2.it != it; - } - - pointer operator->() const { - return *it; - } - - reference operator[](const difference_type &n) const { - return *it[n]; - } - }; - - List(xmlNodePtr node); - ~List() { - for(std::vector::iterator entry = entries.begin(); entry != entries.end(); ++entry) - delete *entry; - } - - public: - typedef iterator_base::iterator> iterator; - typedef iterator_base::const_iterator> const_iterator; - - size_t getSize() const { - return entries.size(); - } - - bool isEmpty() const { - return entries.empty(); - } - - Entry& operator[](size_t i) { - return *entries[i]; - } - - const Entry& operator[](size_t i) const { - return *entries[i]; - } - - iterator begin() { - return iterator(entries.begin()); - } - - const_iterator begin() const { - return const_iterator(entries.begin()); - } - - iterator end() { - return iterator(entries.end()); - } - - const_iterator end() const { - return const_iterator(entries.end()); - } - - iterator insertEntry(iterator it) { - xmlNodePtr newNode = xmlNewNode(0, (xmlChar*)"entry"); - - if(it == end()) - xmlAddChild(elementNode, newNode); - else - xmlAddPrevSibling(it->entryNode, newNode); - - return iterator(entries.insert(it.it, new Entry(newNode))); - } - - iterator addEntry() { - return insertEntry(end()); - } - - void removeEntry(iterator it) { - xmlUnlinkNode(it->entryNode); - xmlFreeNode(it->entryNode); - delete *it.it; - - entries.erase(it.it); - } - }; - - XmlPacket(); - XmlPacket(const XmlPacket &o); - XmlPacket(const Net::Packet &packet); - - XmlPacket& operator=(const XmlPacket &o); - - virtual ~XmlPacket() { - delete entry; - - xmlFreeDoc(doc); - } - - std::string getType() const; - void setType(const std::string &type); - - template - bool set(const std::string &name, T val) { - return entry->set(name, val); - } - - template - T get(const std::string &name) const { - return entry->get(name); - } - - List* createList(const std::string &name, bool unique = false) { - return entry->createList(name, unique); - } - - List* getList(const std::string &name) { - return entry->getList(name); - } - - const List* getList(const std::string &name) const { - return entry->getList(name); - } - - void unset(const std::string &name) { - entry->unset(name); - } - - Net::Packet encode(boost::uint16_t requestId) const; -}; - -template <> MAD_COMMON_EXPORT std::string XmlPacket::Entry::get(const std::string &name) const; -template <> MAD_COMMON_EXPORT const std::string& XmlPacket::Entry::get(const std::string &name) const; - -template <> MAD_COMMON_EXPORT std::vector XmlPacket::Entry::get >(const std::string &name) const; -template <> MAD_COMMON_EXPORT const std::vector& XmlPacket::Entry::get&>(const std::string &name) const; - -} -} - -#endif /* MAD_COMMON_XMLPACKET_H_ */ diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp index 6c245f9..e3d34e5 100644 --- a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp @@ -24,7 +24,7 @@ namespace Mad { namespace Daemon { namespace RequestHandlers { -void CommandRequestHandler::handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret) { +void CommandRequestHandler::handleRequest(boost::shared_ptr packet, Common::XmlData *ret) { if(!getConnection()->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.h b/src/Daemon/RequestHandlers/CommandRequestHandler.h index 188b3d4..2e6addd 100644 --- a/src/Daemon/RequestHandlers/CommandRequestHandler.h +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.h @@ -30,7 +30,7 @@ namespace RequestHandlers { class MAD_DAEMON_EXPORT CommandRequestHandler : public Common::RequestHandlers::SimpleRequestHandler { private: - void handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret); + void handleRequest(boost::shared_ptr packet, Common::XmlData *ret); public: CommandRequestHandler(Common::Application *application) diff --git a/src/Daemon/Requests/LogRequest.cpp b/src/Daemon/Requests/LogRequest.cpp index 9266420..0282649 100644 --- a/src/Daemon/Requests/LogRequest.cpp +++ b/src/Daemon/Requests/LogRequest.cpp @@ -26,7 +26,7 @@ namespace Daemon { namespace Requests { void LogRequest::sendRequest() { - Common::XmlPacket packet; + Common::XmlData packet; packet.setType("Log"); diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp index af48d65..1348541 100644 --- a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp @@ -31,31 +31,31 @@ namespace Mad { namespace Server { namespace RequestHandlers { -void ConnectionRequestHandlerGroup::handleAuthMethodRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret, +void ConnectionRequestHandlerGroup::handleAuthMethodRequest(boost::shared_ptr /*packet*/, Common::XmlData *ret, Common::Connection* /*connection*/) { ret->setType("OK"); - Common::XmlPacket::List *list = ret->createList("methods"); + Common::XmlData::List *list = ret->createList("methods"); std::set methods = application->getAuthManager()->getMethods(); for(std::set::iterator method = methods.begin(); method != methods.end(); ++method) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + Common::XmlData::List::iterator entry = list->addEntry(); entry->set("name", *method); - Common::XmlPacket::List *subList = entry->createList("subMethods"); + Common::XmlData::List *subList = entry->createList("subMethods"); std::vector subMethods = application->getAuthManager()->getSubMethods(*method); for(std::vector::iterator subMethod = subMethods.begin(); subMethod != subMethods.end(); ++subMethod) { - Common::XmlPacket::List::iterator subEntry = subList->addEntry(); + Common::XmlData::List::iterator subEntry = subList->addEntry(); subEntry->set("name", *subMethod); } } } -void ConnectionRequestHandlerGroup::handleAuthRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { +void ConnectionRequestHandlerGroup::handleAuthRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { std::vector response; boost::shared_ptr authContext = application->getConnectionManager()->authenticateConnection(connection, @@ -72,18 +72,18 @@ void ConnectionRequestHandlerGroup::handleAuthRequest(boost::shared_ptrsetType("Continue"); } -void ConnectionRequestHandlerGroup::handleDaemonListRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret, +void ConnectionRequestHandlerGroup::handleDaemonListRequest(boost::shared_ptr /*packet*/, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); ret->setType("OK"); - Common::XmlPacket::List *list = ret->createList("hosts"); + Common::XmlData::List *list = ret->createList("hosts"); std::vector daemons = application->getConnectionManager()->getDaemonList(); for(std::vector::iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + Common::XmlData::List::iterator entry = list->addEntry(); entry->set("name", daemon->getName()); entry->set("address", daemon->getIP()); @@ -91,13 +91,13 @@ void ConnectionRequestHandlerGroup::handleDaemonListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { +void ConnectionRequestHandlerGroup::handleIdentifyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { application->getConnectionManager()->identifyDaemonConnection(connection, packet->get("hostname")); ret->setType("OK"); } -void ConnectionRequestHandlerGroup::handleLogRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection) { +void ConnectionRequestHandlerGroup::handleLogRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { // TODO Require authentication boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h index f3d2138..7b46f22 100644 --- a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h +++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h @@ -35,11 +35,11 @@ class MAD_SERVER_EXPORT ConnectionRequestHandlerGroup : public Common::RequestHa private: Application *application; - void handleAuthMethodRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleAuthRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleDaemonListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleIdentifyRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleLogRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleAuthMethodRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleAuthRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleDaemonListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleIdentifyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleLogRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); public: ConnectionRequestHandlerGroup(Application *application0); diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp index 499e7b6..e258b89 100644 --- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp @@ -30,11 +30,11 @@ namespace Mad { namespace Server { namespace RequestHandlers { -void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared_ptr packet) { +void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != type) { getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); - Common::XmlPacket ret; + Common::XmlData ret; ret.setType("Error"); ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET); @@ -64,7 +64,7 @@ void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared getRequestManager()->sendRequest(daemonCon.get(), request); } catch(Core::Exception &e) { - Common::XmlPacket ret; + Common::XmlData ret; ret.setType("Error"); ret.set("ErrorCode", e.getErrorCode()); ret.set("SubCode", e.getSubCode()); @@ -76,9 +76,9 @@ void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared } } -void DaemonRequestHandlerGroup::DaemonRequestHandler::requestFinished(boost::shared_ptr packet, Core::Exception error) { +void DaemonRequestHandlerGroup::DaemonRequestHandler::requestFinished(boost::shared_ptr packet, Core::Exception error) { if(error) { - Common::XmlPacket ret; + Common::XmlData ret; ret.setType("Error"); ret.set("ErrorCode", error.getErrorCode()); ret.set("SubCode", error.getSubCode()); diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h index 8312709..48d8e2c 100644 --- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h +++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h @@ -37,10 +37,10 @@ class MAD_SERVER_EXPORT DaemonRequestHandlerGroup : public Common::RequestHandle private: std::string type; - void requestFinished(boost::shared_ptr packet, Core::Exception error); + void requestFinished(boost::shared_ptr packet, Core::Exception error); protected: - virtual void handlePacket(boost::shared_ptr packet); + virtual void handlePacket(boost::shared_ptr packet); public: DaemonRequestHandler(Common::Application *application, const std::string &type0) diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp index d5f97a9..1d99c2e 100644 --- a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp @@ -29,7 +29,7 @@ namespace Mad { namespace Server { namespace RequestHandlers { -void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -52,10 +52,10 @@ void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptrset("timestamp", boost::posix_time::to_iso_string(timestamp)); if(users) { - Common::XmlPacket::List *list = ret->createList("users"); + Common::XmlData::List *list = ret->createList("users"); for(std::map::const_iterator user = users->begin(); user != users->end(); ++user) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + Common::XmlData::List::iterator entry = list->addEntry(); entry->set("uid", user->second.getUid()); entry->set("gid", user->second.getGid()); @@ -65,7 +65,7 @@ void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -101,7 +101,7 @@ void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -124,17 +124,17 @@ void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptrset("timestamp", boost::posix_time::to_iso_string(timestamp)); if(groups) { - Common::XmlPacket::List *list = ret->createList("groups"); + Common::XmlData::List *list = ret->createList("groups"); for(std::set::const_iterator group = groups->begin(); group != groups->end(); ++group) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + Common::XmlData::List::iterator entry = list->addEntry(); entry->set("gid", *group); } } } -void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -157,10 +157,10 @@ void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptrset("timestamp", boost::posix_time::to_iso_string(timestamp)); if(groups) { - Common::XmlPacket::List *list = ret->createList("groups"); + Common::XmlData::List *list = ret->createList("groups"); for(std::map::const_iterator group = groups->begin(); group != groups->end(); ++group) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + Common::XmlData::List::iterator entry = list->addEntry(); entry->set("gid", group->second.getGid()); entry->set("name", group->second.getName()); @@ -168,7 +168,7 @@ void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleGroupInfoRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -202,7 +202,7 @@ void UserRequestHandlerGroup::handleGroupInfoRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -224,16 +224,16 @@ void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptrset("timestamp", boost::posix_time::to_iso_string(timestamp)); - Common::XmlPacket::List *list = ret->createList("users"); + Common::XmlData::List *list = ret->createList("users"); for(std::set::const_iterator user = users->begin(); user != users->end(); ++user) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + Common::XmlData::List::iterator entry = list->addEntry(); entry->set("uid", *user); } } -void UserRequestHandlerGroup::handleFullUserGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleFullUserGroupListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -256,10 +256,10 @@ void UserRequestHandlerGroup::handleFullUserGroupListRequest(boost::shared_ptrset("timestamp", boost::posix_time::to_iso_string(timestamp)); if(userGroups) { - Common::XmlPacket::List *list = ret->createList("userGroupList"); + Common::XmlData::List *list = ret->createList("userGroupList"); for(std::multimap::const_iterator userGroup = userGroups->begin(); userGroup != userGroups->end(); ++userGroup) { - Common::XmlPacket::List::iterator entry = list->addEntry(); + Common::XmlData::List::iterator entry = list->addEntry(); entry->set("uid", userGroup->first); entry->set("gid", userGroup->second); @@ -268,7 +268,7 @@ void UserRequestHandlerGroup::handleFullUserGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleUserInfoCheckRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -282,7 +282,7 @@ void UserRequestHandlerGroup::handleUserInfoCheckRequest(boost::shared_ptrsetType("OK"); } -void UserRequestHandlerGroup::handleUserAddRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleUserAddRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -296,7 +296,7 @@ void UserRequestHandlerGroup::handleUserAddRequest(boost::shared_ptrsetType("OK"); } -void UserRequestHandlerGroup::handleUserUpdateRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleUserUpdateRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -310,7 +310,7 @@ void UserRequestHandlerGroup::handleUserUpdateRequest(boost::shared_ptrsetType("OK"); } -void UserRequestHandlerGroup::handleUserDeleteRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleUserDeleteRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -321,7 +321,7 @@ void UserRequestHandlerGroup::handleUserDeleteRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleGroupInfoCheckRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -331,7 +331,7 @@ void UserRequestHandlerGroup::handleGroupInfoCheckRequest(boost::shared_ptrsetType("OK"); } -void UserRequestHandlerGroup::handleGroupAddRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleGroupAddRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -341,7 +341,7 @@ void UserRequestHandlerGroup::handleGroupAddRequest(boost::shared_ptrsetType("OK"); } -void UserRequestHandlerGroup::handleGroupUpdateRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleGroupUpdateRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -352,7 +352,7 @@ void UserRequestHandlerGroup::handleGroupUpdateRequest(boost::shared_ptrsetType("OK"); } -void UserRequestHandlerGroup::handleGroupDeleteRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleGroupDeleteRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -363,7 +363,7 @@ void UserRequestHandlerGroup::handleGroupDeleteRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleAddUserToGroupRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -373,7 +373,7 @@ void UserRequestHandlerGroup::handleAddUserToGroupRequest(boost::shared_ptrsetType("OK"); } -void UserRequestHandlerGroup::handleDeleteUserFromGroupRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handleDeleteUserFromGroupRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); @@ -383,7 +383,7 @@ void UserRequestHandlerGroup::handleDeleteUserFromGroupRequest(boost::shared_ptr ret->setType("OK"); } -void UserRequestHandlerGroup::handlePasswordSetRequest(boost::shared_ptr packet, Common::XmlPacket *ret, +void UserRequestHandlerGroup::handlePasswordSetRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.h b/src/Server/RequestHandlers/UserRequestHandlerGroup.h index aed585f..d4326e1 100644 --- a/src/Server/RequestHandlers/UserRequestHandlerGroup.h +++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.h @@ -35,30 +35,30 @@ class MAD_SERVER_EXPORT UserRequestHandlerGroup : public Common::RequestHandlers private: Application *application; - void handleUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleUserInfoRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleUserGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleUserListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserInfoRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserGroupListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleGroupInfoRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleGroupUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleGroupListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleGroupInfoRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleGroupUserListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleFullUserGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleFullUserGroupListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleUserInfoCheckRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleUserAddRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleUserUpdateRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleUserDeleteRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleUserInfoCheckRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserAddRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserUpdateRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserDeleteRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleGroupInfoCheckRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleGroupAddRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleGroupUpdateRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleGroupDeleteRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleGroupInfoCheckRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleGroupAddRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleGroupUpdateRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleGroupDeleteRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleAddUserToGroupRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); - void handleDeleteUserFromGroupRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleAddUserToGroupRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleDeleteUserFromGroupRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handlePasswordSetRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection); + void handlePasswordSetRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); public: UserRequestHandlerGroup(Application *application0); diff --git a/src/Server/Requests/CommandRequest.cpp b/src/Server/Requests/CommandRequest.cpp index 2a84840..51e7b1d 100644 --- a/src/Server/Requests/CommandRequest.cpp +++ b/src/Server/Requests/CommandRequest.cpp @@ -24,7 +24,7 @@ namespace Server { namespace Requests { void CommandRequest::sendRequest() { - Common::XmlPacket packet; + Common::XmlData packet; packet.setType("Command"); packet.set("command", reboot ? "reboot" : "shutdown"); diff --git a/src/Server/Requests/DaemonStateUpdateRequest.cpp b/src/Server/Requests/DaemonStateUpdateRequest.cpp index 730b490..8ed1eed 100644 --- a/src/Server/Requests/DaemonStateUpdateRequest.cpp +++ b/src/Server/Requests/DaemonStateUpdateRequest.cpp @@ -24,7 +24,7 @@ namespace Server { namespace Requests { void DaemonStateUpdateRequest::sendRequest() { - Common::XmlPacket packet; + Common::XmlData packet; packet.setType("UpdateHostState"); packet.set("name", name); -- cgit v1.2.3