From b40ba0cf91603b695f1f2380cbd39966a458f22f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 27 Sep 2009 19:58:24 +0200 Subject: Use Unicode-aware String class instead of std::string --- .../ChallengeResponseAuthenticator.cpp | 18 +-- .../ChallengeResponseAuthenticator.h | 10 +- .../Authenticators/PasswordAuthenticator.cpp | 29 ++-- src/Client/Authenticators/PasswordAuthenticator.h | 10 +- src/Client/CommandParser.cpp | 44 ++--- src/Client/CommandParser.h | 19 ++- src/Client/InformationManager.cpp | 6 +- src/Client/InformationManager.h | 4 +- src/Client/PasswordReader.cpp | 8 +- src/Client/PasswordReader.h | 6 +- src/Client/Requests/DaemonCommandRequest.h | 5 +- src/Client/Requests/DaemonFSInfoRequest.h | 5 +- src/Client/Requests/DaemonStatusRequest.h | 6 +- .../Requests/UserLists/UserListDownloadRequest.h | 4 +- src/Client/SystemCommands.cpp | 48 +++--- src/Client/SystemCommands.h | 8 +- src/Client/UserCommands.cpp | 180 ++++++++++----------- src/Client/UserCommands.h | 32 ++-- src/Client/UserListCommands.cpp | 72 ++++----- src/Client/UserListCommands.h | 18 +-- src/Client/XLSReader.cpp | 4 +- src/Client/XLSReader.h | 2 +- src/Client/XLSSheet.cpp | 16 +- src/Client/XLSSheet.h | 16 +- 24 files changed, 286 insertions(+), 284 deletions(-) (limited to 'src/Client') diff --git a/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp b/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp index 4aadb63..7ccaa63 100644 --- a/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp +++ b/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp @@ -40,7 +40,7 @@ void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::sendRequest() void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::handlePacket(boost::shared_ptr packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get("Where"), static_cast(packet->get("ErrorCode")), + signalFinished(Core::Exception(packet->get("Where").extract(), static_cast(packet->get("ErrorCode")), packet->get("SubCode"), packet->get("SubSubCode"))); return; } @@ -58,7 +58,7 @@ void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::handlePacket( ret.set("user", username); - std::vector hashedPassword = Common::Hash::hash(std::vector(password.begin(), password.end()), hash); + std::vector hashedPassword = Common::Hash::hash(password, hash); const std::vector &challenge = packet->get&>("data"); hashedPassword.insert(hashedPassword.end(), challenge.begin(), challenge.end()); @@ -79,8 +79,8 @@ void ChallengeResponseAuthenticator::ChallengeResponseAuthRequest::handlePacket( } } -void ChallengeResponseAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const std::string &username, const std::string &password) throw (Core::Exception) { - std::string hash; +void ChallengeResponseAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const Core::String &username, const Core::String &password) throw (Core::Exception) { + Core::String hash; { boost::shared_ptr request(new Common::Requests::AuthMethodRequest(application)); @@ -96,14 +96,14 @@ void ChallengeResponseAuthenticator::authenticate(Common::Application *applicati const Common::XmlData::List *methods = result.first->getList("methods"); for(Common::XmlData::List::const_iterator method = methods->begin(); method != methods->end(); ++method) { - if(method->get("name") != "Challenge-Response") + if(method->get("name") != "Challenge-Response") continue; const Common::XmlData::List *subMethods = method->getList("subMethods"); for(Common::XmlData::List::const_iterator subMethod = subMethods->begin(); subMethod != subMethods->end(); ++subMethod) { - if(Common::Hash::isHashSupported(subMethod->get("name"))) { - hash = subMethod->get("name"); + if(Common::Hash::isHashSupported(subMethod->get("name"))) { + hash = subMethod->get("name"); break; } } @@ -111,11 +111,11 @@ void ChallengeResponseAuthenticator::authenticate(Common::Application *applicati break; } - if(hash.empty()) + if(hash.isEmpty()) throw Core::Exception(Core::Exception::NOT_AVAILABLE); } - application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Challenge-Response' using hash '%s'...", hash.c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Challenge-Response' using hash '%s'...", hash.extract().c_str()); boost::shared_ptr request(new ChallengeResponseAuthRequest(application, username, password, hash)); diff --git a/src/Client/Authenticators/ChallengeResponseAuthenticator.h b/src/Client/Authenticators/ChallengeResponseAuthenticator.h index 3906ba9..5787b1b 100644 --- a/src/Client/Authenticators/ChallengeResponseAuthenticator.h +++ b/src/Client/Authenticators/ChallengeResponseAuthenticator.h @@ -32,10 +32,10 @@ class MAD_CLIENT_EXPORT ChallengeResponseAuthenticator { private: class MAD_CLIENT_EXPORT ChallengeResponseAuthRequest : public Common::Request { private: - std::string username; - std::string password; + Core::String username; + Core::String password; - std::string hash; + Core::String hash; bool hasResponded; @@ -44,14 +44,14 @@ class MAD_CLIENT_EXPORT ChallengeResponseAuthenticator { virtual void handlePacket(boost::shared_ptr packet); public: - ChallengeResponseAuthRequest(Common::Application *application, const std::string &username0, const std::string &password0, const std::string &hash0) + ChallengeResponseAuthRequest(Common::Application *application, const Core::String &username0, const Core::String &password0, const Core::String &hash0) : Common::Request(application), username(username0), password(password0), hash(hash0), hasResponded(false) {} }; ChallengeResponseAuthenticator(); public: - static void authenticate(Common::Application *application, Common::Connection *con, const std::string &username, const std::string &password) throw (Core::Exception); + static void authenticate(Common::Application *application, Common::Connection *con, const Core::String &username, const Core::String &password) throw (Core::Exception); }; } diff --git a/src/Client/Authenticators/PasswordAuthenticator.cpp b/src/Client/Authenticators/PasswordAuthenticator.cpp index bf2a284..2ac9d68 100644 --- a/src/Client/Authenticators/PasswordAuthenticator.cpp +++ b/src/Client/Authenticators/PasswordAuthenticator.cpp @@ -35,17 +35,22 @@ void PasswordAuthenticator::PasswordAuthRequest::sendRequest() { packet.set("user", username); - if(hash == "Clear") - packet.set("data", std::vector(password.begin(), password.end())); - else - packet.set("data", Common::Hash::hash(std::vector(password.begin(), password.end()), hash)); + + + if(hash == "Clear") { + std::string passwordStr = password.extractUTF8(); + packet.set("data", std::vector(passwordStr.begin(), passwordStr.end())); + } + else { + packet.set("data", Common::Hash::hash(password, hash)); + } sendPacket(packet); } void PasswordAuthenticator::PasswordAuthRequest::handlePacket(boost::shared_ptr packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get("Where"), static_cast(packet->get("ErrorCode")), + signalFinished(Core::Exception(packet->get("Where").extract(), static_cast(packet->get("ErrorCode")), packet->get("SubCode"), packet->get("SubSubCode"))); return; } @@ -57,8 +62,8 @@ void PasswordAuthenticator::PasswordAuthRequest::handlePacket(boost::shared_ptr< signalFinished(packet); } -void PasswordAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const std::string &username, const std::string &password) throw (Core::Exception) { - std::string hash; +void PasswordAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const Core::String &username, const Core::String &password) throw (Core::Exception) { + Core::String hash; { boost::shared_ptr request(new Common::Requests::AuthMethodRequest(application)); @@ -74,14 +79,14 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo const Common::XmlData::List *methods = result.first->getList("methods"); for(Common::XmlData::List::const_iterator method = methods->begin(); method != methods->end(); ++method) { - if(method->get("name") != "Password") + if(method->get("name") != "Password") continue; const Common::XmlData::List *subMethods = method->getList("subMethods"); for(Common::XmlData::List::const_iterator subMethod = subMethods->begin(); subMethod != subMethods->end(); ++subMethod) { - if(Common::Hash::isHashSupported(subMethod->get("name"))) { - hash = subMethod->get("name"); + if(Common::Hash::isHashSupported(subMethod->get("name"))) { + hash = subMethod->get("name"); break; } } @@ -89,11 +94,11 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo break; } - if(hash.empty()) + if(hash.isEmpty()) throw Core::Exception(Core::Exception::NOT_AVAILABLE); } - application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.extract().c_str()); boost::shared_ptr request(new PasswordAuthRequest(application, username, password, hash)); diff --git a/src/Client/Authenticators/PasswordAuthenticator.h b/src/Client/Authenticators/PasswordAuthenticator.h index 70ab3f2..e0ae8ef 100644 --- a/src/Client/Authenticators/PasswordAuthenticator.h +++ b/src/Client/Authenticators/PasswordAuthenticator.h @@ -32,24 +32,24 @@ class MAD_CLIENT_EXPORT PasswordAuthenticator { private: class MAD_CLIENT_EXPORT PasswordAuthRequest : public Common::Request { private: - std::string username; - std::string password; + Core::String username; + Core::String password; - std::string hash; + Core::String hash; protected: virtual void sendRequest(); virtual void handlePacket(boost::shared_ptr packet); public: - PasswordAuthRequest(Common::Application *application, const std::string &username0, const std::string &password0, const std::string &hash0) + PasswordAuthRequest(Common::Application *application, const Core::String &username0, const Core::String &password0, const Core::String &hash0) : Common::Request(application), username(username0), password(password0), hash(hash0) {} }; PasswordAuthenticator(); public: - static void authenticate(Common::Application *application, Common::Connection *con, const std::string &username, const std::string &password) throw (Core::Exception); + static void authenticate(Common::Application *application, Common::Connection *con, const Core::String &username, const Core::String &password) throw (Core::Exception); }; } diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index a271860..9b5c6bf 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -63,7 +63,7 @@ const CommandParser::Command CommandParser::commands[] = { }; -const CommandParser::Command* CommandParser::findCommand(const std::string& command) { +const CommandParser::Command* CommandParser::findCommand(const Core::String& command) { for(int i = 0; commands[i].commands[0] != 0; ++i) { for(int j = 0; commands[i].commands[j] != 0; ++j) { if(command == commands[i].commands[j]) { @@ -75,7 +75,7 @@ const CommandParser::Command* CommandParser::findCommand(const std::string& comm return 0; } -void CommandParser::printUsage(const std::string& command) { +void CommandParser::printUsage(const Core::String& command) { const CommandParser::Command *cmd = findCommand(command); if(cmd) @@ -83,14 +83,14 @@ void CommandParser::printUsage(const std::string& command) { } -std::map CommandParser::parseHostList(const std::vector &args, bool mustBeActive) { - const std::map& hosts = application->getInformationManager()->getDaemons(); - std::map ret; +std::map CommandParser::parseHostList(const std::vector &args, bool mustBeActive) { + const std::map& hosts = application->getInformationManager()->getDaemons(); + std::map ret; - for(std::vector::const_iterator arg = args.begin(); arg != args.end(); ++arg) { + for(std::vector::const_iterator arg = args.begin(); arg != args.end(); ++arg) { if(*arg == "*") { if(mustBeActive) { - for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { + for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { if(host->second.getState() != Common::HostInfo::INACTIVE) ret.insert(*host); } @@ -103,7 +103,7 @@ std::map CommandParser::parseHostList(const std:: } } else { - std::map::const_iterator host = hosts.find(*arg); + std::map::const_iterator host = hosts.find(*arg); if(host == hosts.end()) std::cerr << "Host '" << *arg << "' doesn't exist." << std::endl; @@ -117,7 +117,7 @@ std::map CommandParser::parseHostList(const std:: return ret; } -void CommandParser::helpCommand(const std::vector &args) { +void CommandParser::helpCommand(const std::vector &args) { if(args.size() == 1) { std::cout << "Available commands:" << std::endl << std::endl; @@ -146,8 +146,8 @@ void CommandParser::helpCommand(const std::vector &args) { } } -void CommandParser::listHostsCommand(const std::vector &args) { - const std::map& hosts = application->getInformationManager()->getDaemons(); +void CommandParser::listHostsCommand(const std::vector &args) { + const std::map& hosts = application->getInformationManager()->getDaemons(); if(args.size() == 1) { if(hosts.empty()) { @@ -157,7 +157,7 @@ void CommandParser::listHostsCommand(const std::vector &args) { bool output = false; - for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { + for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { if(host->second.getState() == Common::HostInfo::INACTIVE) continue; @@ -186,7 +186,7 @@ void CommandParser::listHostsCommand(const std::vector &args) { std::cout << "Host list:" << std::endl; - for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { + for(std::map::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { std::cout << " " << host->first << " (" << (host->second.getState() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")" << std::endl; } @@ -198,7 +198,7 @@ void CommandParser::listHostsCommand(const std::vector &args) { } } -void CommandParser::exitCommand(const std::vector &/*args*/) { +void CommandParser::exitCommand(const std::vector &/*args*/) { boost::shared_ptr request(new Common::Requests::DisconnectRequest(application)); application->getRequestManager()->sendRequest(connection, request); @@ -212,26 +212,26 @@ void CommandParser::exitCommand(const std::vector &/*args*/) { disconnect = true; } -bool CommandParser::parse(const std::string &cmd) { - std::vector splitCmd; +bool CommandParser::parse(const Core::String &cmd) { + std::vector splitCmd; - Core::Tokenizer::tokenize(cmd.c_str(), splitCmd); + Core::Tokenizer::tokenize(cmd, splitCmd); if(splitCmd.empty()) return true; - const Command* command = findCommand(splitCmd[0].extract()); + const Command* command = findCommand(splitCmd[0]); if(command) { - std::vector strings; + std::vector strings; - for(std::vector::iterator it = splitCmd.begin(); it != splitCmd.end(); ++it) - strings.push_back(it->extract()); + for(std::vector::iterator it = splitCmd.begin(); it != splitCmd.end(); ++it) + strings.push_back(*it); command->function(this, strings); } else { - std::cerr << "Unknown command '" << splitCmd[0].extract() << "'." << std::endl; + std::cerr << "Unknown command '" << splitCmd[0] << "'." << std::endl; } return true; diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h index c4a0f79..87262d7 100644 --- a/src/Client/CommandParser.h +++ b/src/Client/CommandParser.h @@ -29,7 +29,6 @@ #include #include -#include #include namespace Mad { @@ -57,7 +56,7 @@ class MAD_CLIENT_EXPORT CommandParser { const char* desc; const char* longdesc; - boost::function2 > function; + boost::function2 > function; }; static const Command commands[]; @@ -68,14 +67,14 @@ class MAD_CLIENT_EXPORT CommandParser { bool disconnect; - static const Command* findCommand(const std::string& command); + static const Command* findCommand(const Core::String& command); - static void printUsage(const std::string& command); - std::map parseHostList(const std::vector &args, bool mustBeActive = false); + static void printUsage(const Core::String& command); + std::map parseHostList(const std::vector &args, bool mustBeActive = false); - void helpCommand(const std::vector &args); - void listHostsCommand(const std::vector &args); - void exitCommand(const std::vector &args); + void helpCommand(const std::vector &args); + void listHostsCommand(const std::vector &args); + void exitCommand(const std::vector &args); public: CommandParser(Application *application0, Common::Connection *connection0); @@ -84,10 +83,10 @@ class MAD_CLIENT_EXPORT CommandParser { return connection; } - bool parse(const std::string &cmd); + bool parse(const Core::String &cmd); void requestDisconnect() { - exitCommand(std::vector()); + exitCommand(std::vector()); } bool willDisconnect() const { diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index 0021d49..e66f43d 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -36,7 +36,7 @@ void InformationManager::DaemonStateUpdateRequestHandler::handleRequest(boost::s { boost::lock_guard lock(informationManager->mutex); - std::map::iterator host = informationManager->daemons.find(packet->get("name")); + std::map::iterator host = informationManager->daemons.find(packet->get("name")); if(host != informationManager->daemons.end()) host->second.setState(static_cast(packet->get("state"))); else @@ -83,8 +83,8 @@ void InformationManager::daemonListRequestFinished(boost::shared_ptrbegin(); entry != list->end(); ++entry) { Common::HostInfo info; - info.setName(entry->get("name")); - info.setIP(entry->get("address")); + info.setName(entry->get("name")); + info.setIP(entry->get("address").extract()); info.setState(static_cast(entry->get("state"))); daemons.insert(std::make_pair(info.getName(), info)); diff --git a/src/Client/InformationManager.h b/src/Client/InformationManager.h index dcb0212..65672ef 100644 --- a/src/Client/InformationManager.h +++ b/src/Client/InformationManager.h @@ -59,7 +59,7 @@ class MAD_CLIENT_EXPORT InformationManager : private boost::noncopyable { boost::shared_ptr updateRequest; - std::map daemons; + std::map daemons; bool updating; @@ -86,7 +86,7 @@ class MAD_CLIENT_EXPORT InformationManager : private boost::noncopyable { } - std::map getDaemons() { + std::map getDaemons() { boost::lock_guard lock(mutex); return daemons; } diff --git a/src/Client/PasswordReader.cpp b/src/Client/PasswordReader.cpp index d5c4fe8..8d549f5 100644 --- a/src/Client/PasswordReader.cpp +++ b/src/Client/PasswordReader.cpp @@ -32,7 +32,7 @@ namespace Mad { namespace Client { -std::string PasswordReader::readPassword(const std::string &prompt) { +Core::String PasswordReader::readPassword(const Core::String &prompt) { std::string password; #ifdef _WIN32 @@ -41,7 +41,7 @@ std::string PasswordReader::readPassword(const std::string &prompt) { GetConsoleMode(handle, &mode); SetConsoleMode(handle, mode & ~(ENABLE_ECHO_INPUT)); - std::cout << prompt << std::flush; + std::cout << prompt.extract() << std::flush; std::getline(std::cin, password); std::cout << std::endl; @@ -56,14 +56,14 @@ std::string PasswordReader::readPassword(const std::string &prompt) { termnew.c_lflag &= ~ECHO; tcsetattr(STDIN_FILENO, TCSAFLUSH, &termnew); - std::cout << prompt << std::flush; + std::cout << prompt.extract() << std::flush; std::getline(std::cin, password); std::cout << std::endl; tcsetattr(STDIN_FILENO, TCSAFLUSH, &termold); #endif - return password; + return password.c_str(); } } diff --git a/src/Client/PasswordReader.h b/src/Client/PasswordReader.h index 35487c4..d96c9c1 100644 --- a/src/Client/PasswordReader.h +++ b/src/Client/PasswordReader.h @@ -22,7 +22,7 @@ #include "export.h" -#include +#include namespace Mad { namespace Client { @@ -32,10 +32,10 @@ class MAD_CLIENT_EXPORT PasswordReader { PasswordReader(); public: - static std::string readPassword(const std::string &prompt); + static Core::String readPassword(const Core::String &prompt); }; } } -#endif /* MAD_CLIENT_PASSWORDREADER_H_ */ \ No newline at end of file +#endif /* MAD_CLIENT_PASSWORDREADER_H_ */ diff --git a/src/Client/Requests/DaemonCommandRequest.h b/src/Client/Requests/DaemonCommandRequest.h index 04e0304..e4efa99 100644 --- a/src/Client/Requests/DaemonCommandRequest.h +++ b/src/Client/Requests/DaemonCommandRequest.h @@ -23,7 +23,6 @@ #include "../export.h" #include -#include namespace Mad { namespace Client { @@ -31,14 +30,14 @@ namespace Requests { class MAD_CLIENT_EXPORT DaemonCommandRequest : public Common::Request { private: - std::string daemon; + Core::String daemon; bool reboot; protected: virtual void sendRequest(); public: - DaemonCommandRequest(Common::Application *application, const std::string &daemon0, bool reboot0) + DaemonCommandRequest(Common::Application *application, const Core::String &daemon0, bool reboot0) : Common::Request(application), daemon(daemon0), reboot(reboot0) {} }; diff --git a/src/Client/Requests/DaemonFSInfoRequest.h b/src/Client/Requests/DaemonFSInfoRequest.h index 50c0783..7d20645 100644 --- a/src/Client/Requests/DaemonFSInfoRequest.h +++ b/src/Client/Requests/DaemonFSInfoRequest.h @@ -24,7 +24,6 @@ #include -#include namespace Mad { namespace Client { @@ -32,13 +31,13 @@ namespace Requests { class MAD_CLIENT_EXPORT DaemonFSInfoRequest : public Common::Request { private: - std::string daemon; + Core::String daemon; protected: virtual void sendRequest(); public: - DaemonFSInfoRequest(Common::Application *application, const std::string &daemon0) : Common::Request(application), daemon(daemon0) {} + DaemonFSInfoRequest(Common::Application *application, const Core::String &daemon0) : Common::Request(application), daemon(daemon0) {} }; } diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h index 1cdc82e..23e9e29 100644 --- a/src/Client/Requests/DaemonStatusRequest.h +++ b/src/Client/Requests/DaemonStatusRequest.h @@ -24,21 +24,19 @@ #include -#include - namespace Mad { namespace Client { namespace Requests { class MAD_CLIENT_EXPORT DaemonStatusRequest : public Common::Request { private: - std::string daemon; + Core::String daemon; protected: virtual void sendRequest(); public: - DaemonStatusRequest(Common::Application *application, const std::string &daemon0) : Common::Request(application), daemon(daemon0) {} + DaemonStatusRequest(Common::Application *application, const Core::String &daemon0) : Common::Request(application), daemon(daemon0) {} }; } diff --git a/src/Client/Requests/UserLists/UserListDownloadRequest.h b/src/Client/Requests/UserLists/UserListDownloadRequest.h index 570899f..13536f8 100644 --- a/src/Client/Requests/UserLists/UserListDownloadRequest.h +++ b/src/Client/Requests/UserLists/UserListDownloadRequest.h @@ -29,13 +29,13 @@ namespace UserLists { class UserListDownloadRequest : public Common::Request { private: - std::string name; + Core::String name; protected: virtual void sendRequest(); public: - UserListDownloadRequest(Common::Application *application, const std::string &name0) + UserListDownloadRequest(Common::Application *application, const Core::String &name0) : Common::Request(application), name(name0) {} }; diff --git a/src/Client/SystemCommands.cpp b/src/Client/SystemCommands.cpp index ff14cc5..d33441f 100644 --- a/src/Client/SystemCommands.cpp +++ b/src/Client/SystemCommands.cpp @@ -36,7 +36,7 @@ namespace Mad { namespace Client { void SystemCommands::printFSInfo(boost::shared_ptr &packet) { - const std::string units[] = { + const Core::String units[] = { "kB", "MB", "GB", "TB", "" }; @@ -50,36 +50,38 @@ void SystemCommands::printFSInfo(boost::shared_ptr &packe float total = fs->get("totalSize"); float available = fs->get("availableSize"); - while(used >= 1024 && !units[usedUnit+1].empty()) { + while(used >= 1024 && !units[usedUnit+1].isEmpty()) { ++usedUnit; used /= 1024; available /= 1024; } - while(total >= 1024 && !units[totalUnit+1].empty()) { + while(total >= 1024 && !units[totalUnit+1].isEmpty()) { ++totalUnit; total /= 1024; } - std::string name = fs->get("name"); - std::string mountedOn = fs->get("mountedOn"); + Core::String name = fs->get("name"); + Core::String mountedOn = fs->get("mountedOn"); - std::string nameString = mountedOn + " (" + name + ")"; + Core::String nameString = mountedOn + " (" + name + ")"; if(nameString.length() < 32) { - nameString.resize(32, ' '); + while(nameString.length() < 32) + nameString.append(' '); } else { nameString += "\n\t"; - nameString.resize(nameString.length() + 32, ' '); + for(int i = 0; i < 32; ++i) + nameString.append(' '); } float percent = 100*used/(used+available); if(percent > 100) percent = 100; - std::printf("\t%s%.*f%s", nameString.c_str(), (used < 10) ? 2 : 1, used, (usedUnit == totalUnit) ? "" : (" " + units[usedUnit]).c_str()); - std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].c_str(), percent); + std::printf("\t%s%.*f%s", nameString.extract().c_str(), (used < 10) ? 2 : 1, used, (usedUnit == totalUnit) ? "" : Core::String(" " + units[usedUnit]).extract().c_str()); + std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].extract().c_str(), percent); } } @@ -111,20 +113,20 @@ void SystemCommands::printHostStatus(boost::shared_ptr &p float freeMem = packet->get("freeMem"); if(totalMem && freeMem) { - const std::string units[] = { + const Core::String units[] = { "kB", "MB", "GB", "TB", "" }; unsigned unit = 0; float usedMem = totalMem-freeMem; - while(totalMem >= 1024 && !units[unit+1].empty()) { + while(totalMem >= 1024 && !units[unit+1].isEmpty()) { ++unit; totalMem /= 1024; usedMem /= 1024; } - std::printf("\tMemory usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].c_str()); + std::printf("\tMemory usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].extract().c_str()); std::printf(" (%.1f%%)\n", usedMem*100.0f/totalMem); totalMem = packet->get("totalSwap"); @@ -134,13 +136,13 @@ void SystemCommands::printHostStatus(boost::shared_ptr &p unit = 0; usedMem = totalMem-freeMem; - while(totalMem >= 1024 && !units[unit+1].empty()) { + while(totalMem >= 1024 && !units[unit+1].isEmpty()) { ++unit; totalMem /= 1024; usedMem /= 1024; } - std::printf("\tSwap usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].c_str()); + std::printf("\tSwap usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].extract().c_str()); std::printf(" (%.1f%%)\n", usedMem*100.0f/totalMem); } @@ -149,7 +151,7 @@ void SystemCommands::printHostStatus(boost::shared_ptr &p } -void SystemCommands::fsinfoCommand(CommandParser *commandParser, const std::vector &args) { +void SystemCommands::fsinfoCommand(CommandParser *commandParser, const std::vector &args) { boost::shared_ptr request; if(args.size() == 1) @@ -180,18 +182,18 @@ void SystemCommands::fsinfoCommand(CommandParser *commandParser, const std::vect } } -void SystemCommands::rebootCommand(CommandParser *commandParser, const std::vector &args) { +void SystemCommands::rebootCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 2) { std::cerr << args[0] << ": No host given." << std::endl; commandParser->printUsage("reboot"); return; } - std::map hosts = commandParser->parseHostList(std::vector(args.begin()+1, args.end()), true); + std::map hosts = commandParser->parseHostList(std::vector(args.begin()+1, args.end()), true); std::vector > requests; - for(std::map::iterator host = hosts.begin(); host != hosts.end(); ++host) { + for(std::map::iterator host = hosts.begin(); host != hosts.end(); ++host) { boost::shared_ptr request(new Requests::DaemonCommandRequest(commandParser->application, host->first, true)); commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request); @@ -209,18 +211,18 @@ void SystemCommands::rebootCommand(CommandParser *commandParser, const std::vect } } -void SystemCommands::shutdownCommand(CommandParser *commandParser, const std::vector &args) { +void SystemCommands::shutdownCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 2) { std::cerr << args[0] << ": No host given." << std::endl; commandParser->printUsage("shutdown"); return; } - std::map hosts = commandParser->parseHostList(std::vector(args.begin()+1, args.end()), true); + std::map hosts = commandParser->parseHostList(std::vector(args.begin()+1, args.end()), true); std::vector > requests; - for(std::map::iterator host = hosts.begin(); host != hosts.end(); ++host) { + for(std::map::iterator host = hosts.begin(); host != hosts.end(); ++host) { boost::shared_ptr request(new Requests::DaemonCommandRequest(commandParser->application, host->first, false)); commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request); @@ -238,7 +240,7 @@ void SystemCommands::shutdownCommand(CommandParser *commandParser, const std::ve } } -void SystemCommands::statusCommand(CommandParser *commandParser, const std::vector &args) { +void SystemCommands::statusCommand(CommandParser *commandParser, const std::vector &args) { boost::shared_ptr request; if(args.size() == 1) diff --git a/src/Client/SystemCommands.h b/src/Client/SystemCommands.h index ba8c361..fa2b63a 100644 --- a/src/Client/SystemCommands.h +++ b/src/Client/SystemCommands.h @@ -41,10 +41,10 @@ class MAD_CLIENT_EXPORT SystemCommands { static void printHostStatus(boost::shared_ptr &packet); public: - static void fsinfoCommand(CommandParser *commandParser, const std::vector &args); - static void rebootCommand(CommandParser *commandParser, const std::vector &args); - static void shutdownCommand(CommandParser *commandParser, const std::vector &args); - static void statusCommand(CommandParser *commandParser, const std::vector &args); + static void fsinfoCommand(CommandParser *commandParser, const std::vector &args); + static void rebootCommand(CommandParser *commandParser, const std::vector &args); + static void shutdownCommand(CommandParser *commandParser, const std::vector &args); + static void statusCommand(CommandParser *commandParser, const std::vector &args); }; } diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp index a1d190a..5e55534 100644 --- a/src/Client/UserCommands.cpp +++ b/src/Client/UserCommands.cpp @@ -31,7 +31,7 @@ namespace Mad { namespace Client { -std::string UserCommands::getUserName(CommandParser *commandParser, unsigned long uid, bool withId) { +Core::String UserCommands::getUserName(CommandParser *commandParser, unsigned long uid, bool withId) { std::ostringstream stream; try { @@ -47,10 +47,10 @@ std::string UserCommands::getUserName(CommandParser *commandParser, unsigned lon stream << ")"; } - return stream.str(); + return stream.str().c_str(); } -std::string UserCommands::getGroupName(CommandParser *commandParser, unsigned long gid, bool withId) { +Core::String UserCommands::getGroupName(CommandParser *commandParser, unsigned long gid, bool withId) { std::ostringstream stream; try { @@ -66,10 +66,10 @@ std::string UserCommands::getGroupName(CommandParser *commandParser, unsigned lo stream << ")"; } - return stream.str(); + return stream.str().c_str(); } -void UserCommands::listUsersCommand(CommandParser *commandParser, const std::vector &/*args*/) { +void UserCommands::listUsersCommand(CommandParser *commandParser, const std::vector &/*args*/) { try { boost::shared_ptr > users = commandParser->application->getUserManager()->getUserList(); @@ -93,7 +93,7 @@ void UserCommands::listUsersCommand(CommandParser *commandParser, const std::vec } } -void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() == 1) { std::cerr << args[0] << ": No user id given." << std::endl; commandParser->printUsage("user_info"); @@ -107,11 +107,11 @@ void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vect try { char *endptr; - unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); + unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); boost::shared_ptr userInfo; - if(args[1].empty() || *endptr != '\0') { + if(args[1].isEmpty() || *endptr != '\0') { userInfo = commandParser->application->getUserManager()->getUserInfoByName(args[1]); } else @@ -136,7 +136,7 @@ void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vect } } -void UserCommands::listGroupsCommand(CommandParser *commandParser, const std::vector &/*args*/) { +void UserCommands::listGroupsCommand(CommandParser *commandParser, const std::vector &/*args*/) { try { boost::shared_ptr > groups = commandParser->application->getUserManager()->getGroupList(); @@ -158,31 +158,31 @@ void UserCommands::listGroupsCommand(CommandParser *commandParser, const std::ve } } -void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() == 1) { - std::cerr << args[0] << ": No group id given." << std::endl; + std::cerr << args[0].extract() << ": No group id given." << std::endl; commandParser->printUsage("group_info"); return; } if(args.size() > 2) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("group_info"); return; } try { char *endptr; - unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); + unsigned long gid = std::strtoul(args[1].extract().c_str(), &endptr, 10); boost::shared_ptr groupInfo; - if(args[1].empty() || *endptr != '\0') { + if(args[1].isEmpty() || *endptr != '\0') { groupInfo = commandParser->application->getUserManager()->getGroupInfoByName(args[1]); } else groupInfo = commandParser->application->getUserManager()->getGroupInfo(gid); - std::cout << " Group name: " << groupInfo->getName() << " (" << groupInfo->getGid() << ")" << std::endl << std::endl; + std::cout << " Group name: " << groupInfo->getName().extract() << " (" << groupInfo->getGid() << ")" << std::endl << std::endl; boost::shared_ptr > users = commandParser->application->getUserManager()->getGroupUserList(groupInfo->getGid()); @@ -191,7 +191,7 @@ void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vec for(std::set::const_iterator user = users->begin(); user != users->end(); ++user) - std::cout << " " << getUserName(commandParser, *user, true) << std::endl; + std::cout << " " << getUserName(commandParser, *user, true).extract() << std::endl; std::cout << std::endl; } @@ -201,29 +201,29 @@ void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vec } } -void UserCommands::addUserCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::addUserCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 5) { - std::cerr << args[0] << ": Too few arguments." << std::endl; + std::cerr << args[0].extract() << ": Too few arguments." << std::endl; commandParser->printUsage("add_user"); return; } if(args.size() > 5) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("add_user"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); - if(args[1].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse user id." << std::endl; + unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + if(args[1].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; commandParser->printUsage("add_user"); return; } - unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10); - if(args[2].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse group id." << std::endl; + unsigned long gid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + if(args[2].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; commandParser->printUsage("add_user"); return; } @@ -242,36 +242,36 @@ void UserCommands::addUserCommand(CommandParser *commandParser, const std::vecto } } -void UserCommands::updateUserCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::updateUserCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 6) { - std::cerr << args[0] << ": Too few arguments." << std::endl; + std::cerr << args[0].extract() << ": Too few arguments." << std::endl; commandParser->printUsage("update_user"); return; } if(args.size() > 6) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("update_user"); return; } char *endptr; - unsigned long origUid = std::strtoul(args[1].c_str(), &endptr, 10); - if(args[1].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse the old user id." << std::endl; + unsigned long origUid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + if(args[1].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse the old user id." << std::endl; commandParser->printUsage("update_user"); return; } - unsigned long uid = std::strtoul(args[2].c_str(), &endptr, 10); - if(args[2].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse the new user id." << std::endl; + unsigned long uid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + if(args[2].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse the new user id." << std::endl; commandParser->printUsage("update_user"); return; } - unsigned long gid = std::strtoul(args[3].c_str(), &endptr, 10); - if(args[3].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse group id." << std::endl; + unsigned long gid = std::strtoul(args[3].extract().c_str(), &endptr, 10); + if(args[3].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; commandParser->printUsage("update_user"); return; } @@ -290,22 +290,22 @@ void UserCommands::updateUserCommand(CommandParser *commandParser, const std::ve } } -void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 2) { - std::cerr << args[0] << ": No user id given." << std::endl; + std::cerr << args[0].extract() << ": No user id given." << std::endl; commandParser->printUsage("delete_user"); return; } if(args.size() > 2) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("delete_user"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); - if(args[1].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse user id." << std::endl; + unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + if(args[1].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; commandParser->printUsage("delete_user"); return; } @@ -320,22 +320,22 @@ void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::ve } } -void UserCommands::addGroupCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::addGroupCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 3) { - std::cerr << args[0] << ": Too few arguments." << std::endl; + std::cerr << args[0].extract() << ": Too few arguments." << std::endl; commandParser->printUsage("add_group"); return; } if(args.size() > 3) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("add_group"); return; } char *endptr; - unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); - if(args[2].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse group id." << std::endl; + unsigned long gid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + if(args[2].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; commandParser->printUsage("add_group"); return; } @@ -350,29 +350,29 @@ void UserCommands::addGroupCommand(CommandParser *commandParser, const std::vect } } -void UserCommands::updateGroupCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::updateGroupCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 4) { - std::cerr << args[0] << ": Too few arguments." << std::endl; + std::cerr << args[0].extract() << ": Too few arguments." << std::endl; commandParser->printUsage("update_group"); return; } if(args.size() > 4) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("update_group"); return; } char *endptr; - unsigned long origGid = std::strtoul(args[1].c_str(), &endptr, 10); - if(args[1].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse the old group id." << std::endl; + unsigned long origGid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + if(args[1].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse the old group id." << std::endl; commandParser->printUsage("update_group"); return; } - unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10); - if(args[2].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse the new group id." << std::endl; + unsigned long gid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + if(args[2].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse the new group id." << std::endl; commandParser->printUsage("update_group"); return; } @@ -387,22 +387,22 @@ void UserCommands::updateGroupCommand(CommandParser *commandParser, const std::v } } -void UserCommands::deleteGroupCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::deleteGroupCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 2) { - std::cerr << args[0] << ": No group id given." << std::endl; + std::cerr << args[0].extract() << ": No group id given." << std::endl; commandParser->printUsage("delete_group"); return; } if(args.size() > 2) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("delete_group"); return; } char *endptr; - unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); - if(args[1].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse group id." << std::endl; + unsigned long gid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + if(args[1].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; commandParser->printUsage("delete_group"); return; } @@ -417,29 +417,29 @@ void UserCommands::deleteGroupCommand(CommandParser *commandParser, const std::v } } -void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 3) { - std::cerr << args[0] << ": Too few arguments." << std::endl; + std::cerr << args[0].extract() << ": Too few arguments." << std::endl; commandParser->printUsage("add_user_to_group"); return; } if(args.size() > 3) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("add_user_to_group"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); - if(args[1].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse user id." << std::endl; + unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + if(args[1].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; commandParser->printUsage("add_user_to_group"); return; } - unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10); - if(args[2].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse group id." << std::endl; + unsigned long gid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + if(args[2].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; commandParser->printUsage("add_user_to_group"); return; } @@ -454,29 +454,29 @@ void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std } } -void UserCommands::deleteUserFromGroupCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::deleteUserFromGroupCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 3) { - std::cerr << args[0] << ": Too few arguments." << std::endl; + std::cerr << args[0].extract() << ": Too few arguments." << std::endl; commandParser->printUsage("delete_user_from_group"); return; } if(args.size() > 3) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("delete_user_from_group"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); - if(args[1].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse user id." << std::endl; + unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + if(args[1].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; commandParser->printUsage("delete_user_from_group"); return; } - unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10); - if(args[2].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse group id." << std::endl; + unsigned long gid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + if(args[2].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; commandParser->printUsage("delete_user_from_group"); return; } @@ -491,28 +491,28 @@ void UserCommands::deleteUserFromGroupCommand(CommandParser *commandParser, cons } } -void UserCommands::setPasswordCommand(CommandParser *commandParser, const std::vector &args) { +void UserCommands::setPasswordCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 2) { - std::cerr << args[0] << ": Too few arguments." << std::endl; + std::cerr << args[0].extract() << ": Too few arguments." << std::endl; commandParser->printUsage("set_password"); return; } if(args.size() > 2) { - std::cerr << args[0] << ": Too many arguments." << std::endl; + std::cerr << args[0].extract() << ": Too many arguments." << std::endl; commandParser->printUsage("set_password"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); - if(args[1].empty() || *endptr != '\0') { - std::cerr << args[0] << ": Unable to parse user id." << std::endl; + unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + if(args[1].isEmpty() || *endptr != '\0') { + std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; commandParser->printUsage("set_password"); return; } - std::string password = PasswordReader::readPassword("Password: "); - std::string password2 = PasswordReader::readPassword("Verify password: "); + Core::String password = PasswordReader::readPassword("Password: "); + Core::String password2 = PasswordReader::readPassword("Verify password: "); if(password != password2) { std::cerr << "Passwords do not match." << std::endl; diff --git a/src/Client/UserCommands.h b/src/Client/UserCommands.h index 640b5b4..34eb84b 100644 --- a/src/Client/UserCommands.h +++ b/src/Client/UserCommands.h @@ -22,7 +22,7 @@ #include "export.h" -#include +#include #include namespace Mad { @@ -34,28 +34,28 @@ class MAD_CLIENT_EXPORT UserCommands { private: UserCommands(); - static std::string getUserName(CommandParser *commandParser, unsigned long uid, bool withId); - static std::string getGroupName(CommandParser *commandParser, unsigned long gid, bool withId); + static Core::String getUserName(CommandParser *commandParser, unsigned long uid, bool withId); + static Core::String getGroupName(CommandParser *commandParser, unsigned long gid, bool withId); public: - static void listUsersCommand(CommandParser *commandParser, const std::vector &args); - static void userInfoCommand(CommandParser *commandParser, const std::vector &args); + static void listUsersCommand(CommandParser *commandParser, const std::vector &args); + static void userInfoCommand(CommandParser *commandParser, const std::vector &args); - static void listGroupsCommand(CommandParser *commandParser, const std::vector &args); - static void groupInfoCommand(CommandParser *commandParser, const std::vector &args); + static void listGroupsCommand(CommandParser *commandParser, const std::vector &args); + static void groupInfoCommand(CommandParser *commandParser, const std::vector &args); - static void addUserCommand(CommandParser *commandParser, const std::vector &args); - static void updateUserCommand(CommandParser *commandParser, const std::vector &args); - static void deleteUserCommand(CommandParser *commandParser, const std::vector &args); + static void addUserCommand(CommandParser *commandParser, const std::vector &args); + static void updateUserCommand(CommandParser *commandParser, const std::vector &args); + static void deleteUserCommand(CommandParser *commandParser, const std::vector &args); - static void addGroupCommand(CommandParser *commandParser, const std::vector &args); - static void updateGroupCommand(CommandParser *commandParser, const std::vector &args); - static void deleteGroupCommand(CommandParser *commandParser, const std::vector &args); + static void addGroupCommand(CommandParser *commandParser, const std::vector &args); + static void updateGroupCommand(CommandParser *commandParser, const std::vector &args); + static void deleteGroupCommand(CommandParser *commandParser, const std::vector &args); - static void addUserToGroupCommand(CommandParser *commandParser, const std::vector &args); - static void deleteUserFromGroupCommand(CommandParser *commandParser, const std::vector &args); + static void addUserToGroupCommand(CommandParser *commandParser, const std::vector &args); + static void deleteUserFromGroupCommand(CommandParser *commandParser, const std::vector &args); - static void setPasswordCommand(CommandParser *commandParser, const std::vector &args); + static void setPasswordCommand(CommandParser *commandParser, const std::vector &args); }; } diff --git a/src/Client/UserListCommands.cpp b/src/Client/UserListCommands.cpp index 7774240..947cbc1 100644 --- a/src/Client/UserListCommands.cpp +++ b/src/Client/UserListCommands.cpp @@ -42,7 +42,7 @@ const UserListCommands::Command UserListCommands::commands[] = { {{0}, 0, 0, 0, 0} }; -const UserListCommands::Command* UserListCommands::findCommand(const std::string& command) { +const UserListCommands::Command* UserListCommands::findCommand(const Core::String& command) { for(int i = 0; commands[i].commands[0] != 0; ++i) { for(int j = 0; commands[i].commands[j] != 0; ++j) { if(command == commands[i].commands[j]) { @@ -54,7 +54,7 @@ const UserListCommands::Command* UserListCommands::findCommand(const std::string return 0; } -void UserListCommands::printUsage(const std::string& command) { +void UserListCommands::printUsage(const Core::String& command) { const UserListCommands::Command *cmd = findCommand(command); if(cmd) @@ -62,7 +62,7 @@ void UserListCommands::printUsage(const std::string& command) { } -void UserListCommands::helpCommand(CommandParser* /*commandParser*/, const std::vector &args) { +void UserListCommands::helpCommand(CommandParser* /*commandParser*/, const std::vector &args) { if(args.size() <= 2) { std::cout << "Available commands:" << std::endl << std::endl; @@ -91,7 +91,7 @@ void UserListCommands::helpCommand(CommandParser* /*commandParser*/, const std:: } } -void UserListCommands::listCommand(CommandParser *commandParser, const std::vector& /*args*/) { +void UserListCommands::listCommand(CommandParser *commandParser, const std::vector& /*args*/) { boost::shared_ptr userListRequest(new Requests::UserLists::UserListListRequest(commandParser->application)); boost::shared_ptr userListDiffRequest(new Requests::UserLists::UserListDiffListRequest(commandParser->application)); @@ -126,7 +126,7 @@ void UserListCommands::listCommand(CommandParser *commandParser, const std::vect std::cout << "There are " << userLists->getSize() << " user lists stored on the server:" << std::endl; for(Common::XmlData::List::const_iterator userList = userLists->begin(); userList != userLists->end(); ++userList) { - std::cout << " " << userList->get("name") << std::endl; + std::cout << " " << userList->get("name") << std::endl; } } @@ -139,12 +139,12 @@ void UserListCommands::listCommand(CommandParser *commandParser, const std::vect std::cout << "There are " << userListDiffs->getSize() << " user list difference records stored on the server:" << std::endl; for(Common::XmlData::List::const_iterator diff = userListDiffs->begin(); diff != userListDiffs->end(); ++diff) { - std::cout << " " << diff->get("name") << std::endl; + std::cout << " " << diff->get("name") << std::endl; } } } -void UserListCommands::showListCommand(CommandParser *commandParser, const std::vector &args) { +void UserListCommands::showListCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 3) { std::cerr << args[0] << " " << args[1] << ": No list name given." << std::endl; printUsage("show_list"); @@ -188,7 +188,7 @@ void UserListCommands::showListCommand(CommandParser *commandParser, const std:: } } -void UserListCommands::importCommand(CommandParser* /*commandParser*/, const std::vector &args) { +void UserListCommands::importCommand(CommandParser* /*commandParser*/, const std::vector &args) { if(args.size() < 3) { std::cerr << args[0] << " " << args[1] << ": No filename given." << std::endl; printUsage("import"); @@ -196,7 +196,7 @@ void UserListCommands::importCommand(CommandParser* /*commandParser*/, const std } else if(args.size() == 3) { try { - XLSReader reader(args[2]); + XLSReader reader(args[2].extract()); const std::list > &sheets = reader.getSheets(); if(sheets.empty()) { @@ -253,12 +253,12 @@ void UserListCommands::importCommand(CommandParser* /*commandParser*/, const std unsigned id = 1; for(std::vector::const_iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt, ++id) { - const std::vector &row = **rowIt; + const std::vector &row = **rowIt; Common::UserLists::UserListEntry entry; std::ostringstream stream; stream << id; - entry.setName(stream.str()); + entry.setName(stream.str().c_str()); for(unsigned col = 0; col < (*sheet)->getColumnCount(); ++col) { entry.setDetail((*sheet)->getColumnName(col), row[col]); @@ -283,21 +283,21 @@ void UserListCommands::importCommand(CommandParser* /*commandParser*/, const std void UserListCommands::printUserList(const Common::UserLists::UserList &list) { - std::map lengths; + std::map lengths; - static const std::string USER_NAME = "User name"; - static const std::string GROUP_NAME = "Group name"; + static const Core::String USER_NAME = "User name"; + static const Core::String GROUP_NAME = "Group name"; lengths.insert(std::make_pair(USER_NAME, USER_NAME.length())); lengths.insert(std::make_pair(GROUP_NAME, GROUP_NAME.length())); - std::set details = list.getDetails(); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + std::set details = list.getDetails(); + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { lengths.insert(std::make_pair(*detail, detail->length())); } for(Common::UserLists::UserList::const_iterator user = list.begin(); user != list.end(); ++user) { - std::map::iterator it = lengths.find(USER_NAME); + std::map::iterator it = lengths.find(USER_NAME); if(user->getName().length() > it->second) it->second = user->getName().length(); @@ -305,9 +305,9 @@ void UserListCommands::printUserList(const Common::UserLists::UserList &list) { if(user->getGroup().length() > it->second) it->second = user->getGroup().length(); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { it = lengths.find(*detail); - std::string detailStr = user->getDetail(*detail); + Core::String detailStr = user->getDetail(*detail); if(detailStr.length() > it->second) it->second = detailStr.length(); } @@ -317,7 +317,7 @@ void UserListCommands::printUserList(const Common::UserLists::UserList &list) { printPadded(USER_NAME, lengths.find(USER_NAME)->second); std::cout << " "; printPadded(GROUP_NAME, lengths.find(GROUP_NAME)->second); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { std::cout << " "; printPadded(*detail, lengths.find(*detail)->second); } @@ -327,30 +327,30 @@ void UserListCommands::printUserList(const Common::UserLists::UserList &list) { printDelimiter(lengths.find(USER_NAME)->second); std::cout << "- -"; printDelimiter(lengths.find(GROUP_NAME)->second); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { std::cout << "- -"; printDelimiter(lengths.find(*detail)->second); } std::cout << "-" << std::endl; for(Common::UserLists::UserList::const_iterator user = list.begin(); user != list.end(); ++user) { - static const std::string UNSET(""); + static const Core::String UNSET(""); std::cout << " "; - if(!user->getName().empty()) + if(!user->getName().isEmpty()) printPadded(user->getName(), lengths.find(USER_NAME)->second); else printPadded(UNSET, lengths.find(USER_NAME)->second); std::cout << " "; - if(!user->getGroup().empty()) + if(!user->getGroup().isEmpty()) printPadded(user->getGroup(), lengths.find(GROUP_NAME)->second); else printPadded(UNSET, lengths.find(GROUP_NAME)->second); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { std::cout << " "; printPadded(user->getDetail(*detail), lengths.find(*detail)->second); } @@ -361,18 +361,18 @@ void UserListCommands::printUserList(const Common::UserLists::UserList &list) { void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) { const std::vector &rows = sheet.getRows(); - std::vector lengths(sheet.getColumnCount()); + std::vector lengths(sheet.getColumnCount()); for(unsigned col = 0; col < sheet.getColumnCount(); ++col) { - lengths[col] = sheet.getColumnName(col).size(); + lengths[col] = sheet.getColumnName(col).length(); } for(std::vector::const_iterator rowIt = rows.begin(); rowIt != rows.end() && (rowCount == 0 || rowIt != rows.begin()+rowCount); ++rowIt) { - const std::vector &row = **rowIt; + const std::vector &row = **rowIt; for(unsigned col = 0; col < sheet.getColumnCount(); ++col) { - if(row[col].size() > lengths[col]) - lengths[col] = row[col].size(); + if(row[col].length() > lengths[col]) + lengths[col] = row[col].length(); } } @@ -391,7 +391,7 @@ void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) { std::cout << std::endl; for(std::vector::const_iterator rowIt = rows.begin(); rowIt != rows.end() && (rowCount == 0 || rowIt != rows.begin()+rowCount); ++rowIt) { - const std::vector &row = **rowIt; + const std::vector &row = **rowIt; for(unsigned col = 0; col < sheet.getColumnCount(); ++col) { std::cout << " "; @@ -409,19 +409,19 @@ void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) { } } -void UserListCommands::printPadded(const std::string &str, unsigned length) { +void UserListCommands::printPadded(const Core::String &str, boost::int32_t length) { std::cout << str; if(str.length() < length) std::cout << std::string(length-str.length(), ' '); } -void UserListCommands::printDelimiter(unsigned length) { - printPadded(std::string(length, '-'), length); +void UserListCommands::printDelimiter(boost::int32_t length) { + printPadded(Core::String(std::string(length, '-').c_str()), length); } -void UserListCommands::userListCommand(CommandParser *commandParser, const std::vector &args) { - std::string cmd; +void UserListCommands::userListCommand(CommandParser *commandParser, const std::vector &args) { + Core::String cmd; if(args.size() < 2) cmd = "help"; diff --git a/src/Client/UserListCommands.h b/src/Client/UserListCommands.h index 8c77e7f..ab20974 100644 --- a/src/Client/UserListCommands.h +++ b/src/Client/UserListCommands.h @@ -44,21 +44,21 @@ class MAD_CLIENT_EXPORT UserListCommands { UserListCommands(); - static const Command* findCommand(const std::string& command); - static void printUsage(const std::string& command); + static const Command* findCommand(const Core::String& command); + static void printUsage(const Core::String& command); - static void helpCommand(CommandParser *commandParser, const std::vector &args); - static void listCommand(CommandParser *commandParser, const std::vector &args); - static void showListCommand(CommandParser *commandParser, const std::vector &args); - static void importCommand(CommandParser *commandParser, const std::vector &args); + static void helpCommand(CommandParser *commandParser, const std::vector &args); + static void listCommand(CommandParser *commandParser, const std::vector &args); + static void showListCommand(CommandParser *commandParser, const std::vector &args); + static void importCommand(CommandParser *commandParser, const std::vector &args); static void printUserList(const Common::UserLists::UserList &list); static void printSheet(const XLSSheet &sheet, unsigned rowCount = 0); - static void printPadded(const std::string &str, unsigned length); - static void printDelimiter(unsigned length); + static void printPadded(const Core::String &str, boost::int32_t length); + static void printDelimiter(boost::int32_t length); public: - static void userListCommand(CommandParser *commandParser, const std::vector &args); + static void userListCommand(CommandParser *commandParser, const std::vector &args); }; } diff --git a/src/Client/XLSReader.cpp b/src/Client/XLSReader.cpp index 9bd9dda..27ff2f5 100644 --- a/src/Client/XLSReader.cpp +++ b/src/Client/XLSReader.cpp @@ -27,12 +27,12 @@ namespace Mad { namespace Client { -xmlNodePtr XLSReader::findNode(xmlNodePtr parent, const std::string &name) { +xmlNodePtr XLSReader::findNode(xmlNodePtr parent, const Core::String &name) { if(!parent) return 0; for(xmlNodePtr entry = parent->children; entry != 0; entry = entry->next) { - if(entry->type == XML_ELEMENT_NODE && !xmlStrcmp(entry->name, (xmlChar*)name.c_str())) { + if(entry->type == XML_ELEMENT_NODE && !xmlStrcmp(entry->name, (xmlChar*)name.extractUTF8().c_str())) { return entry; } } diff --git a/src/Client/XLSReader.h b/src/Client/XLSReader.h index 8c7b11a..b5364d9 100644 --- a/src/Client/XLSReader.h +++ b/src/Client/XLSReader.h @@ -41,7 +41,7 @@ class MAD_CLIENT_EXPORT XLSReader : private boost::noncopyable { boost::shared_ptr doc; std::list > sheets; - static xmlNodePtr findNode(xmlNodePtr parent, const std::string &name); + static xmlNodePtr findNode(xmlNodePtr parent, const Core::String &name); public: XLSReader(const std::string &filename) throw (Core::Exception); diff --git a/src/Client/XLSSheet.cpp b/src/Client/XLSSheet.cpp index 915234f..9c4b5a9 100644 --- a/src/Client/XLSSheet.cpp +++ b/src/Client/XLSSheet.cpp @@ -26,12 +26,12 @@ namespace Mad { namespace Client { -std::string XLSSheet::getSheetLevelField(const std::string &name) const { +Core::String XLSSheet::getSheetLevelField(const Core::String &name) const { xmlNodePtr entry = XLSReader::findNode(node, name); if(entry) - return std::string((char*)xmlNodeGetContent(entry)); + return Core::String::fromUTF8((char*)xmlNodeGetContent(entry)); else - return std::string(); + return Core::String(); } void XLSSheet::readRows() { @@ -58,7 +58,7 @@ void XLSSheet::readRows() { if(col >= colCount) continue; - colNames[col] = (char*)xmlNodeGetContent(cellEntry); + colNames[col] = Core::String::fromUTF8((char*)xmlNodeGetContent(cellEntry)); } // Skip the first row @@ -71,7 +71,7 @@ void XLSSheet::readRows() { if(rowEntry->type != XML_ELEMENT_NODE || xmlStrcmp(rowEntry->name, (xmlChar*)"row")) continue; - boost::shared_ptr > rowVector(new std::vector(colCount)); + boost::shared_ptr > rowVector(new std::vector(colCount)); rows.push_back(rowVector); for(xmlNodePtr cellEntry = rowEntry->children; cellEntry != 0; cellEntry = cellEntry->next) { @@ -86,20 +86,20 @@ void XLSSheet::readRows() { if(col >= colCount) continue; - (*rowVector)[col] = (char*)xmlNodeGetContent(cellEntry); + (*rowVector)[col] = Core::String::fromUTF8((char*)xmlNodeGetContent(cellEntry)); } } } XLSSheet::XLSSheet(boost::shared_ptr doc0, xmlNodePtr node0) : doc(doc0), node(node0), firstRowColNames(false) { title = getSheetLevelField("pagetitle"); - colCount = std::strtoul(getSheetLevelField("lastcol").c_str(), 0, 10)+1-std::strtoul(getSheetLevelField("firstcol").c_str(), 0, 10); + colCount = std::strtoul(getSheetLevelField("lastcol").extract().c_str(), 0, 10)+1-std::strtoul(getSheetLevelField("firstcol").extract().c_str(), 0, 10); for(unsigned col = 0; col < colCount; ++col) { std::ostringstream stream; stream << col; - colNames.push_back(stream.str()); + colNames.push_back(stream.str().c_str()); } readRows(); diff --git a/src/Client/XLSSheet.h b/src/Client/XLSSheet.h index 3038fdc..0960fc0 100644 --- a/src/Client/XLSSheet.h +++ b/src/Client/XLSSheet.h @@ -22,9 +22,9 @@ #include "export.h" -#include -#include +#include +#include #include #include #include @@ -37,7 +37,7 @@ class XLSReader; class MAD_CLIENT_EXPORT XLSSheet : private boost::noncopyable { public: - typedef boost::shared_ptr > RowType; + typedef boost::shared_ptr > RowType; private: friend class XLSReader; @@ -45,17 +45,17 @@ class MAD_CLIENT_EXPORT XLSSheet : private boost::noncopyable { boost::shared_ptr doc; xmlNodePtr node; - std::string title; + Core::String title; size_t colCount; std::vector rows; - std::vector colNames; + std::vector colNames; bool firstRowColNames; XLSSheet(boost::shared_ptr doc0, xmlNodePtr node0); - std::string getSheetLevelField(const std::string &name) const; + Core::String getSheetLevelField(const Core::String &name) const; void readRows(); @@ -68,7 +68,7 @@ class MAD_CLIENT_EXPORT XLSSheet : private boost::noncopyable { readRows(); } - const std::string& getTitle() const { + const Core::String& getTitle() const { return title; } @@ -76,7 +76,7 @@ class MAD_CLIENT_EXPORT XLSSheet : private boost::noncopyable { return colCount; } - const std::string& getColumnName(unsigned col) const { + const Core::String& getColumnName(unsigned col) const { return colNames[col]; } -- cgit v1.2.3