diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 23:51:34 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 23:51:34 +0200 |
commit | a7a285eb61dd83afc892bc1d64ffe14b9f1426a3 (patch) | |
tree | 08d2efcaec46e5f5702d9e336a0e8ba7e636aff9 | |
parent | b40ba0cf91603b695f1f2380cbd39966a458f22f (diff) | |
download | mad-a7a285eb61dd83afc892bc1d64ffe14b9f1426a3.tar mad-a7a285eb61dd83afc892bc1d64ffe14b9f1426a3.zip |
Completely migrate to Unicode String class
48 files changed, 406 insertions, 425 deletions
diff --git a/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp b/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp index 7ccaa63..92ced08 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<const Common::XmlData> packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get<const Core::String&>("Where").extract(), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), + signalFinished(Core::Exception(packet->get<const Core::String&>("Where"), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); return; } @@ -115,7 +115,7 @@ void ChallengeResponseAuthenticator::authenticate(Common::Application *applicati throw Core::Exception(Core::Exception::NOT_AVAILABLE); } - application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Challenge-Response' using hash '%s'...", hash.extract().c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Challenge-Response' using hash '%s'...", hash.toLocale().c_str()); boost::shared_ptr<ChallengeResponseAuthRequest> request(new ChallengeResponseAuthRequest(application, username, password, hash)); diff --git a/src/Client/Authenticators/PasswordAuthenticator.cpp b/src/Client/Authenticators/PasswordAuthenticator.cpp index 2ac9d68..ac01d44 100644 --- a/src/Client/Authenticators/PasswordAuthenticator.cpp +++ b/src/Client/Authenticators/PasswordAuthenticator.cpp @@ -38,7 +38,7 @@ void PasswordAuthenticator::PasswordAuthRequest::sendRequest() { if(hash == "Clear") { - std::string passwordStr = password.extractUTF8(); + std::string passwordStr = password.toUTF8(); packet.set("data", std::vector<boost::uint8_t>(passwordStr.begin(), passwordStr.end())); } else { @@ -50,7 +50,7 @@ void PasswordAuthenticator::PasswordAuthRequest::sendRequest() { void PasswordAuthenticator::PasswordAuthRequest::handlePacket(boost::shared_ptr<const Common::XmlData> packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get<const Core::String&>("Where").extract(), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), + signalFinished(Core::Exception(packet->get<const Core::String&>("Where"), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); return; } @@ -98,7 +98,7 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo throw Core::Exception(Core::Exception::NOT_AVAILABLE); } - application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.extract().c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.toLocale().c_str()); boost::shared_ptr<PasswordAuthRequest> request(new PasswordAuthRequest(application, username, password, hash)); diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index e66f43d..8872834 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -84,7 +84,7 @@ void InformationManager::daemonListRequestFinished(boost::shared_ptr<const Commo for(Common::XmlData::List::const_iterator entry = list->begin(); entry != list->end(); ++entry) { Common::HostInfo info; info.setName(entry->get<const Core::String&>("name")); - info.setIP(entry->get<const Core::String&>("address").extract()); + info.setIP(entry->get<const Core::String&>("address").toString()); info.setState(static_cast<Common::HostInfo::State>(entry->get<long>("state"))); daemons.insert(std::make_pair(info.getName(), info)); diff --git a/src/Client/PasswordReader.cpp b/src/Client/PasswordReader.cpp index 8d549f5..cb77ad5 100644 --- a/src/Client/PasswordReader.cpp +++ b/src/Client/PasswordReader.cpp @@ -33,20 +33,11 @@ namespace Mad { namespace Client { Core::String PasswordReader::readPassword(const Core::String &prompt) { - std::string password; - #ifdef _WIN32 DWORD mode; HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); GetConsoleMode(handle, &mode); SetConsoleMode(handle, mode & ~(ENABLE_ECHO_INPUT)); - - std::cout << prompt.extract() << std::flush; - std::getline(std::cin, password); - std::cout << std::endl; - - SetConsoleMode(handle, mode); - #else struct termios termold, termnew; @@ -55,15 +46,19 @@ Core::String PasswordReader::readPassword(const Core::String &prompt) { termnew = termold; termnew.c_lflag &= ~ECHO; tcsetattr(STDIN_FILENO, TCSAFLUSH, &termnew); +#endif - std::cout << prompt.extract() << std::flush; - std::getline(std::cin, password); + std::cout << prompt << std::flush; + Core::String password = Core::String::getline(std::cin); std::cout << std::endl; +#ifdef _WIN32 + SetConsoleMode(handle, mode); +#else tcsetattr(STDIN_FILENO, TCSAFLUSH, &termold); #endif - return password.c_str(); + return password; } } diff --git a/src/Client/SystemCommands.cpp b/src/Client/SystemCommands.cpp index d33441f..2151071 100644 --- a/src/Client/SystemCommands.cpp +++ b/src/Client/SystemCommands.cpp @@ -80,8 +80,8 @@ void SystemCommands::printFSInfo(boost::shared_ptr<const Common::XmlData> &packe float percent = 100*used/(used+available); if(percent > 100) percent = 100; - 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); + std::printf("\t%s%.*f%s", nameString.toLocale().c_str(), (used < 10) ? 2 : 1, used, (usedUnit == totalUnit) ? "" : Core::String(" " + units[usedUnit]).toLocale().c_str()); + std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].toLocale().c_str(), percent); } } @@ -126,7 +126,7 @@ void SystemCommands::printHostStatus(boost::shared_ptr<const Common::XmlData> &p usedMem /= 1024; } - 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("\tMemory usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].toLocale().c_str()); std::printf(" (%.1f%%)\n", usedMem*100.0f/totalMem); totalMem = packet->get<unsigned long>("totalSwap"); @@ -142,7 +142,7 @@ void SystemCommands::printHostStatus(boost::shared_ptr<const Common::XmlData> &p usedMem /= 1024; } - 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("\tSwap usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].toLocale().c_str()); std::printf(" (%.1f%%)\n", usedMem*100.0f/totalMem); } diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp index 5e55534..fe5343c 100644 --- a/src/Client/UserCommands.cpp +++ b/src/Client/UserCommands.cpp @@ -107,7 +107,7 @@ void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vect try { char *endptr; - unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long uid = std::strtoul(args[1].toString().c_str(), &endptr, 10); boost::shared_ptr<const Common::UserInfo> userInfo; @@ -160,19 +160,19 @@ void UserCommands::listGroupsCommand(CommandParser *commandParser, const std::ve void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() == 1) { - std::cerr << args[0].extract() << ": No group id given." << std::endl; + std::cerr << args[0] << ": No group id given." << std::endl; commandParser->printUsage("group_info"); return; } if(args.size() > 2) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("group_info"); return; } try { char *endptr; - unsigned long gid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long gid = std::strtoul(args[1].toString().c_str(), &endptr, 10); boost::shared_ptr<const Common::GroupInfo> groupInfo; @@ -182,7 +182,7 @@ void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vec else groupInfo = commandParser->application->getUserManager()->getGroupInfo(gid); - std::cout << " Group name: " << groupInfo->getName().extract() << " (" << groupInfo->getGid() << ")" << std::endl << std::endl; + std::cout << " Group name: " << groupInfo->getName() << " (" << groupInfo->getGid() << ")" << std::endl << std::endl; boost::shared_ptr<const std::set<unsigned long> > users = commandParser->application->getUserManager()->getGroupUserList(groupInfo->getGid()); @@ -191,7 +191,7 @@ void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vec for(std::set<unsigned long>::const_iterator user = users->begin(); user != users->end(); ++user) - std::cout << " " << getUserName(commandParser, *user, true).extract() << std::endl; + std::cout << " " << getUserName(commandParser, *user, true) << std::endl; std::cout << std::endl; } @@ -203,27 +203,27 @@ void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vec void UserCommands::addUserCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() < 5) { - std::cerr << args[0].extract() << ": Too few arguments." << std::endl; + std::cerr << args[0] << ": Too few arguments." << std::endl; commandParser->printUsage("add_user"); return; } if(args.size() > 5) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("add_user"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long uid = std::strtoul(args[1].toString().c_str(), &endptr, 10); if(args[1].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; + std::cerr << args[0] << ": Unable to parse user id." << std::endl; commandParser->printUsage("add_user"); return; } - unsigned long gid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + unsigned long gid = std::strtoul(args[2].toString().c_str(), &endptr, 10); if(args[2].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; + std::cerr << args[0] << ": Unable to parse group id." << std::endl; commandParser->printUsage("add_user"); return; } @@ -244,34 +244,34 @@ void UserCommands::addUserCommand(CommandParser *commandParser, const std::vecto void UserCommands::updateUserCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() < 6) { - std::cerr << args[0].extract() << ": Too few arguments." << std::endl; + std::cerr << args[0] << ": Too few arguments." << std::endl; commandParser->printUsage("update_user"); return; } if(args.size() > 6) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("update_user"); return; } char *endptr; - unsigned long origUid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long origUid = std::strtoul(args[1].toString().c_str(), &endptr, 10); if(args[1].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse the old user id." << std::endl; + std::cerr << args[0] << ": Unable to parse the old user id." << std::endl; commandParser->printUsage("update_user"); return; } - unsigned long uid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + unsigned long uid = std::strtoul(args[2].toString().c_str(), &endptr, 10); if(args[2].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse the new user id." << std::endl; + std::cerr << args[0] << ": Unable to parse the new user id." << std::endl; commandParser->printUsage("update_user"); return; } - unsigned long gid = std::strtoul(args[3].extract().c_str(), &endptr, 10); + unsigned long gid = std::strtoul(args[3].toString().c_str(), &endptr, 10); if(args[3].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; + std::cerr << args[0] << ": Unable to parse group id." << std::endl; commandParser->printUsage("update_user"); return; } @@ -292,20 +292,20 @@ void UserCommands::updateUserCommand(CommandParser *commandParser, const std::ve void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() < 2) { - std::cerr << args[0].extract() << ": No user id given." << std::endl; + std::cerr << args[0] << ": No user id given." << std::endl; commandParser->printUsage("delete_user"); return; } if(args.size() > 2) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("delete_user"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long uid = std::strtoul(args[1].toString().c_str(), &endptr, 10); if(args[1].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; + std::cerr << args[0] << ": Unable to parse user id." << std::endl; commandParser->printUsage("delete_user"); return; } @@ -322,20 +322,20 @@ void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::ve void UserCommands::addGroupCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() < 3) { - std::cerr << args[0].extract() << ": Too few arguments." << std::endl; + std::cerr << args[0] << ": Too few arguments." << std::endl; commandParser->printUsage("add_group"); return; } if(args.size() > 3) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("add_group"); return; } char *endptr; - unsigned long gid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long gid = std::strtoul(args[1].toString().c_str(), &endptr, 10); if(args[2].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; + std::cerr << args[0] << ": Unable to parse group id." << std::endl; commandParser->printUsage("add_group"); return; } @@ -352,27 +352,27 @@ void UserCommands::addGroupCommand(CommandParser *commandParser, const std::vect void UserCommands::updateGroupCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() < 4) { - std::cerr << args[0].extract() << ": Too few arguments." << std::endl; + std::cerr << args[0] << ": Too few arguments." << std::endl; commandParser->printUsage("update_group"); return; } if(args.size() > 4) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("update_group"); return; } char *endptr; - unsigned long origGid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long origGid = std::strtoul(args[1].toString().c_str(), &endptr, 10); if(args[1].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse the old group id." << std::endl; + std::cerr << args[0] << ": Unable to parse the old group id." << std::endl; commandParser->printUsage("update_group"); return; } - unsigned long gid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + unsigned long gid = std::strtoul(args[2].toString().c_str(), &endptr, 10); if(args[2].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse the new group id." << std::endl; + std::cerr << args[0] << ": Unable to parse the new group id." << std::endl; commandParser->printUsage("update_group"); return; } @@ -389,20 +389,20 @@ void UserCommands::updateGroupCommand(CommandParser *commandParser, const std::v void UserCommands::deleteGroupCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() < 2) { - std::cerr << args[0].extract() << ": No group id given." << std::endl; + std::cerr << args[0] << ": No group id given." << std::endl; commandParser->printUsage("delete_group"); return; } if(args.size() > 2) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("delete_group"); return; } char *endptr; - unsigned long gid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long gid = std::strtoul(args[1].toString().c_str(), &endptr, 10); if(args[1].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; + std::cerr << args[0] << ": Unable to parse group id." << std::endl; commandParser->printUsage("delete_group"); return; } @@ -419,27 +419,27 @@ void UserCommands::deleteGroupCommand(CommandParser *commandParser, const std::v void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() < 3) { - std::cerr << args[0].extract() << ": Too few arguments." << std::endl; + std::cerr << args[0] << ": Too few arguments." << std::endl; commandParser->printUsage("add_user_to_group"); return; } if(args.size() > 3) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("add_user_to_group"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long uid = std::strtoul(args[1].toString().c_str(), &endptr, 10); if(args[1].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; + std::cerr << args[0] << ": Unable to parse user id." << std::endl; commandParser->printUsage("add_user_to_group"); return; } - unsigned long gid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + unsigned long gid = std::strtoul(args[2].toString().c_str(), &endptr, 10); if(args[2].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; + std::cerr << args[0] << ": Unable to parse group id." << std::endl; commandParser->printUsage("add_user_to_group"); return; } @@ -456,27 +456,27 @@ void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std void UserCommands::deleteUserFromGroupCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() < 3) { - std::cerr << args[0].extract() << ": Too few arguments." << std::endl; + std::cerr << args[0] << ": Too few arguments." << std::endl; commandParser->printUsage("delete_user_from_group"); return; } if(args.size() > 3) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("delete_user_from_group"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long uid = std::strtoul(args[1].toString().c_str(), &endptr, 10); if(args[1].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; + std::cerr << args[0] << ": Unable to parse user id." << std::endl; commandParser->printUsage("delete_user_from_group"); return; } - unsigned long gid = std::strtoul(args[2].extract().c_str(), &endptr, 10); + unsigned long gid = std::strtoul(args[2].toString().c_str(), &endptr, 10); if(args[2].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse group id." << std::endl; + std::cerr << args[0] << ": Unable to parse group id." << std::endl; commandParser->printUsage("delete_user_from_group"); return; } @@ -493,20 +493,20 @@ void UserCommands::deleteUserFromGroupCommand(CommandParser *commandParser, cons void UserCommands::setPasswordCommand(CommandParser *commandParser, const std::vector<Core::String> &args) { if(args.size() < 2) { - std::cerr << args[0].extract() << ": Too few arguments." << std::endl; + std::cerr << args[0] << ": Too few arguments." << std::endl; commandParser->printUsage("set_password"); return; } if(args.size() > 2) { - std::cerr << args[0].extract() << ": Too many arguments." << std::endl; + std::cerr << args[0] << ": Too many arguments." << std::endl; commandParser->printUsage("set_password"); return; } char *endptr; - unsigned long uid = std::strtoul(args[1].extract().c_str(), &endptr, 10); + unsigned long uid = std::strtoul(args[1].toString().c_str(), &endptr, 10); if(args[1].isEmpty() || *endptr != '\0') { - std::cerr << args[0].extract() << ": Unable to parse user id." << std::endl; + std::cerr << args[0] << ": Unable to parse user id." << std::endl; commandParser->printUsage("set_password"); return; } diff --git a/src/Client/UserListCommands.cpp b/src/Client/UserListCommands.cpp index 947cbc1..d602579 100644 --- a/src/Client/UserListCommands.cpp +++ b/src/Client/UserListCommands.cpp @@ -196,7 +196,7 @@ void UserListCommands::importCommand(CommandParser* /*commandParser*/, const std } else if(args.size() == 3) { try { - XLSReader reader(args[2].extract()); + XLSReader reader(args[2].toLocale()); const std::list<boost::shared_ptr<XLSSheet> > &sheets = reader.getSheets(); if(sheets.empty()) { diff --git a/src/Client/XLSReader.cpp b/src/Client/XLSReader.cpp index 27ff2f5..68065b6 100644 --- a/src/Client/XLSReader.cpp +++ b/src/Client/XLSReader.cpp @@ -32,7 +32,7 @@ xmlNodePtr XLSReader::findNode(xmlNodePtr parent, const Core::String &name) { return 0; for(xmlNodePtr entry = parent->children; entry != 0; entry = entry->next) { - if(entry->type == XML_ELEMENT_NODE && !xmlStrcmp(entry->name, (xmlChar*)name.extractUTF8().c_str())) { + if(entry->type == XML_ELEMENT_NODE && !xmlStrcmp(entry->name, (xmlChar*)name.toUTF8().c_str())) { return entry; } } @@ -49,7 +49,7 @@ XLSReader::XLSReader(const std::string &filename) throw (Core::Exception) { std::string escapedFilename = boost::regex_replace(filename, r, "\\\\'", boost::match_default); - std::FILE *stream = popen((XLHTML_EXEC + " '" + escapedFilename + "' 2>&1").c_str(), "r"); + std::FILE *stream = popen((XLHTML_EXEC + " '" + escapedFilename + "' 2>/dev/null").c_str(), "r"); std::string data; diff --git a/src/Client/XLSSheet.cpp b/src/Client/XLSSheet.cpp index 9c4b5a9..96bf16c 100644 --- a/src/Client/XLSSheet.cpp +++ b/src/Client/XLSSheet.cpp @@ -93,7 +93,7 @@ void XLSSheet::readRows() { XLSSheet::XLSSheet(boost::shared_ptr<xmlDoc> doc0, xmlNodePtr node0) : doc(doc0), node(node0), firstRowColNames(false) { title = getSheetLevelField("pagetitle"); - colCount = std::strtoul(getSheetLevelField("lastcol").extract().c_str(), 0, 10)+1-std::strtoul(getSheetLevelField("firstcol").extract().c_str(), 0, 10); + colCount = std::strtoul(getSheetLevelField("lastcol").toString().c_str(), 0, 10)+1-std::strtoul(getSheetLevelField("firstcol").toString().c_str(), 0, 10); for(unsigned col = 0; col < colCount; ++col) { std::ostringstream stream; diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp index 87d9b4f..f46f588 100644 --- a/src/Common/Backends/NetworkUserBackend.cpp +++ b/src/Common/Backends/NetworkUserBackend.cpp @@ -31,9 +31,7 @@ const Core::String NetworkUserBackend::name("NetworkUserBackend"); void NetworkUserBackend::SimpleUserRequest::sendRequest() { XmlData packet; packet.setType(type); - - if(!timestamp.is_not_a_date_time()) - packet.set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + packet.set("timestamp", timestamp); sendPacket(packet); } @@ -42,9 +40,7 @@ void NetworkUserBackend::IdUserRequest::sendRequest() { XmlData packet; packet.setType(type); packet.set(idType, id); - - if(!timestamp.is_not_a_date_time()) - packet.set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + packet.set("timestamp", timestamp); sendPacket(packet); } @@ -53,9 +49,7 @@ void NetworkUserBackend::NameUserRequest::sendRequest() { XmlData packet; packet.setType(type); packet.set("name", name); - - if(!timestamp.is_not_a_date_time()) - packet.set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + packet.set("timestamp", timestamp); sendPacket(packet); } @@ -137,10 +131,9 @@ boost::shared_ptr<const std::map<unsigned long, UserInfo> > NetworkUserBackend:: throw result.second; if(timestamp) { - try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); - } - catch(...) {} + boost::posix_time::ptime t = result.first->get<boost::posix_time::ptime>("timestamp"); + if(!t.is_not_a_date_time()) + *timestamp = t; } const XmlData::List *users = result.first->getList("users"); @@ -173,10 +166,9 @@ boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfo(unsigned long throw result.second; if(timestamp) { - try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); - } - catch(...) {} + boost::posix_time::ptime t = result.first->get<boost::posix_time::ptime>("timestamp"); + if(!t.is_not_a_date_time()) + *timestamp = t; } unsigned long uid2 = result.first->get<unsigned long>("uid"); @@ -205,10 +197,9 @@ boost::shared_ptr<const UserInfo> NetworkUserBackend::getUserInfoByName(const Co throw result.second; if(timestamp) { - try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); - } - catch(...) {} + boost::posix_time::ptime t = result.first->get<boost::posix_time::ptime>("timestamp"); + if(!t.is_not_a_date_time()) + *timestamp = t; } unsigned long uid = result.first->get<unsigned long>("uid"); @@ -237,10 +228,9 @@ boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getUserGro throw result.second; if(timestamp) { - try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); - } - catch(...) {} + boost::posix_time::ptime t = result.first->get<boost::posix_time::ptime>("timestamp"); + if(!t.is_not_a_date_time()) + *timestamp = t; } const XmlData::List *groups = result.first->getList("groups"); @@ -269,10 +259,9 @@ boost::shared_ptr<const std::map<unsigned long, GroupInfo> > NetworkUserBackend: throw result.second; if(timestamp) { - try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); - } - catch(...) {} + boost::posix_time::ptime t = result.first->get<boost::posix_time::ptime>("timestamp"); + if(!t.is_not_a_date_time()) + *timestamp = t; } const XmlData::List *groups = result.first->getList("groups"); @@ -302,10 +291,9 @@ boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfo(unsigned lon throw result.second; if(timestamp) { - try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); - } - catch(...) {} + boost::posix_time::ptime t = result.first->get<boost::posix_time::ptime>("timestamp"); + if(!t.is_not_a_date_time()) + *timestamp = t; } unsigned long gid2 = result.first->get<unsigned long>("gid"); @@ -328,10 +316,9 @@ boost::shared_ptr<const GroupInfo> NetworkUserBackend::getGroupInfoByName(const throw result.second; if(timestamp) { - try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); - } - catch(...) {} + boost::posix_time::ptime t = result.first->get<boost::posix_time::ptime>("timestamp"); + if(!t.is_not_a_date_time()) + *timestamp = t; } unsigned long gid = result.first->get<unsigned long>("gid"); @@ -354,10 +341,9 @@ boost::shared_ptr<const std::set<unsigned long> > NetworkUserBackend::getGroupUs throw result.second; if(timestamp) { - try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); - } - catch(...) {} + boost::posix_time::ptime t = result.first->get<boost::posix_time::ptime>("timestamp"); + if(!t.is_not_a_date_time()) + *timestamp = t; } const XmlData::List *users = result.first->getList("users"); @@ -386,10 +372,9 @@ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > NetworkUse throw result.second; if(timestamp) { - try { - *timestamp = boost::posix_time::from_iso_string(result.first->get<const Core::String&>("timestamp").extract()); - } - catch(...) {} + boost::posix_time::ptime t = result.first->get<boost::posix_time::ptime>("timestamp"); + if(!t.is_not_a_date_time()) + *timestamp = t; } const XmlData::List *list = result.first->getList("userGroupList"); diff --git a/src/Common/Hash.h b/src/Common/Hash.h index f92779e..b89eb67 100644 --- a/src/Common/Hash.h +++ b/src/Common/Hash.h @@ -91,12 +91,12 @@ class MAD_COMMON_EXPORT Hash { } static std::vector<boost::uint8_t> hash(const Core::String &in, unsigned int method) throw (Core::Exception) { - std::string str = in.extractUTF8(); + std::string str = in.toUTF8(); return hash(std::vector<boost::uint8_t>(str.begin(), str.end()), method); } static std::vector<boost::uint8_t> hash(const Core::String &in, const Core::String &method) throw (Core::Exception) { - std::string str = in.extractUTF8(); + std::string str = in.toUTF8(); return hash(std::vector<boost::uint8_t>(str.begin(), str.end()), method); } }; diff --git a/src/Common/ModuleManager.cpp b/src/Common/ModuleManager.cpp index 053d395..be25f9e 100644 --- a/src/Common/ModuleManager.cpp +++ b/src/Common/ModuleManager.cpp @@ -63,8 +63,8 @@ bool ModuleManager::handleConfigEntry(const Core::ConfigEntry &entry, bool handl return false; if(entry[0].getKey().matches("LoadModule") && entry[1].isEmpty()) { - if(!loadModule(entry[0][0].extract())) - application->logf(Core::Logger::LOG_ERROR, "Can't load module '%s'.", entry[0][0].extract().c_str()); + if(!loadModule(entry[0][0].toLocale())) + application->logf(Core::Logger::LOG_ERROR, "Can't load module '%s'.", entry[0][0].toLocale().c_str()); return true; } @@ -94,9 +94,9 @@ bool ModuleManager::loadModule(const std::string &name) { if(!handle) { #ifdef WIN32 - application->logf(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Error %u", GetLastError()); + application->logf(Core::Logger::LOG_VERBOSE, "loadModule: Can't open module: Error %u", GetLastError()); #else - application->log(Core::Logger::LOG_VERBOSE, std::string("loadModule: Can't open module: ") + std::string(dlerror())); + application->logf(Core::Logger::LOG_VERBOSE, "loadModule: Can't open module: %s", dlerror()); #endif return false; } diff --git a/src/Common/Request.cpp b/src/Common/Request.cpp index f7ad600..c7169bf 100644 --- a/src/Common/Request.cpp +++ b/src/Common/Request.cpp @@ -24,7 +24,8 @@ namespace Common { void Request::handlePacket(boost::shared_ptr<const XmlData> packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get<const Core::String&>("Where").extract(), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), + signalFinished(Core::Exception(packet->get<const Core::String&>("Where"), + static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); return; } diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.cpp b/src/Common/RequestHandlers/SimpleRequestHandler.cpp index 71a8b3a..86edca6 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandler.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandler.cpp @@ -49,7 +49,7 @@ void SimpleRequestHandler::handlePacket(boost::shared_ptr<const XmlData> packet) ret.set("ErrorCode", e.getErrorCode()); ret.set("SubCode", e.getSubCode()); ret.set("SubSubCode", e.getSubSubCode()); - ret.set("Where", e.getWhere().c_str()); + ret.set("Where", e.getWhere()); } sendPacket(ret); diff --git a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp index a3ed286..c5f8fe3 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp @@ -50,7 +50,7 @@ void SimpleRequestHandlerGroup::GroupRequestHandler::handlePacket(boost::shared_ ret.set("ErrorCode", e.getErrorCode()); ret.set("SubCode", e.getSubCode()); ret.set("SubSubCode", e.getSubSubCode()); - ret.set("Where", e.getWhere().c_str()); + ret.set("Where", e.getWhere()); } sendPacket(ret); diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp index 676c9e1..e348047 100644 --- a/src/Common/Requests/DisconnectRequest.cpp +++ b/src/Common/Requests/DisconnectRequest.cpp @@ -32,10 +32,11 @@ void DisconnectRequest::sendRequest() { void DisconnectRequest::handlePacket(boost::shared_ptr<const XmlData> packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get<const Core::String&>("Where").extract(), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), - packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); - return; - } + signalFinished(Core::Exception(packet->get<const Core::String&>("Where"), + static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), + packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); + return; + } else if(packet->getType() != "OK") { signalFinished(Core::Exception(Core::Exception::UNEXPECTED_PACKET)); return; // TODO Logging diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp index 5fb5d15..90a0435 100644 --- a/src/Common/UserManager.cpp +++ b/src/Common/UserManager.cpp @@ -41,9 +41,9 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl if(entry[1].getKey().matches("MinUid")) { if(entry[2].isEmpty()) { char *endptr; - unsigned long val = std::strtoul(entry[1][0].extract().c_str(), &endptr, 10); + unsigned long val = std::strtoul(entry[1][0].toString().c_str(), &endptr, 10); if(entry[1][0].isEmpty() || *endptr) { - application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MinUid '%s'", entry[1][0].extract().c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MinUid '%s'", entry[1][0].toLocale().c_str()); } else { minUid = val; @@ -53,9 +53,9 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl else if(entry[1].getKey().matches("MaxUid")) { if(entry[2].isEmpty()) { char *endptr; - unsigned long val = std::strtoul(entry[1][0].extract().c_str(), &endptr, 10); + unsigned long val = std::strtoul(entry[1][0].toString().c_str(), &endptr, 10); if(entry[1][0].isEmpty() || *endptr) { - application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxUid '%s'", entry[1][0].extract().c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxUid '%s'", entry[1][0].toLocale().c_str()); } else { maxUid = val; @@ -65,9 +65,9 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl else if(entry[1].getKey().matches("MinGid")) { if(entry[2].isEmpty()) { char *endptr; - unsigned long val = std::strtoul(entry[1][0].extract().c_str(), &endptr, 10); + unsigned long val = std::strtoul(entry[1][0].toString().c_str(), &endptr, 10); if(entry[1][0].isEmpty() || *endptr) { - application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MinGid '%s'", entry[1][0].extract().c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MinGid '%s'", entry[1][0].toLocale().c_str()); } else { minGid = val; @@ -77,9 +77,9 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl else if(entry[1].getKey().matches("MaxGid")) { if(entry[2].isEmpty()) { char *endptr; - unsigned long val = std::strtoul(entry[1][0].extract().c_str(), &endptr, 10); + unsigned long val = std::strtoul(entry[1][0].toString().c_str(), &endptr, 10); if(entry[1][0].isEmpty() || *endptr) { - application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxGid '%s'", entry[1][0].extract().c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxGid '%s'", entry[1][0].toLocale().c_str()); } else { maxGid = val; diff --git a/src/Common/XmlData.cpp b/src/Common/XmlData.cpp index de9588a..956117f 100644 --- a/src/Common/XmlData.cpp +++ b/src/Common/XmlData.cpp @@ -38,6 +38,10 @@ void XmlData::Element::updateStr() { str = Base64Encoder::encode(boost::get<std::vector<boost::uint8_t> >(value)).c_str(); typeStr = "binary"; } + else if(type == TIME) { + str = Core::String::fromString(boost::posix_time::to_iso_string(boost::get<boost::posix_time::ptime>(value))); + typeStr = "time"; + } else if(type != STRING) { std::ostringstream buf; @@ -69,7 +73,10 @@ void XmlData::Element::updateStr() { case LONGDOUBLE: buf << boost::get<long double>(value); typeStr = "longdouble"; - default: + case BINARY: + case STRING: + case TIME: + case NONE: break; } @@ -78,13 +85,13 @@ void XmlData::Element::updateStr() { else typeStr = "string"; - xmlNodePtr newNode = xmlNewText((xmlChar*)str.extractUTF8().c_str()); + xmlNodePtr newNode = xmlNewText((xmlChar*)str.toUTF8().c_str()); xmlNodePtr oldNode = elementNode->children; xmlReplaceNode(oldNode, newNode); xmlFreeNode(oldNode); - xmlSetProp(elementNode, (xmlChar*)"type", (xmlChar*)typeStr.extractUTF8().c_str()); + xmlSetProp(elementNode, (xmlChar*)"type", (xmlChar*)typeStr.toUTF8().c_str()); } XmlData::Element::Element(xmlNodePtr node) : elementNode(node), type(NONE) { @@ -102,12 +109,22 @@ XmlData::Element::Element(xmlNodePtr node) : elementNode(node), type(NONE) { } str = Core::String::fromUTF8((char*)content); - std::istringstream buf(str.extract()); + std::istringstream buf(str.toString()); if(!xmlStrcmp(typestr, (xmlChar*)"binary")) { type = BINARY; - value = Base64Encoder::decode(str.extract()); + value = Base64Encoder::decode(str.toString()); + } + else if(!xmlStrcmp(typestr, (xmlChar*)"time")) { + type = TIME; + + try { + value = boost::posix_time::from_iso_string(str.toString()); + } + catch(...) { + value = boost::posix_time::ptime(boost::posix_time::not_a_date_time); + } } else if(!xmlStrcmp(typestr, (xmlChar*)"int")) { type = INT; @@ -240,6 +257,20 @@ const std::vector<boost::uint8_t>& XmlData::Entry::get<const std::vector<unsigne } } +template <> +boost::posix_time::ptime XmlData::Entry::get<boost::posix_time::ptime>(const Core::String &name) const { + Element *element = getElement(name); + if(!element) + return boost::posix_time::ptime(boost::posix_time::not_a_date_time); + + switch(element->type) { + case Element::TIME: + return boost::get<boost::posix_time::ptime>(element->value); + default: + return boost::posix_time::ptime(boost::posix_time::not_a_date_time); + } +} + 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")) @@ -301,7 +332,7 @@ Core::String XmlData::getType() const { } void XmlData::setType(const Core::String &type) { - xmlSetProp(rootNode, (xmlChar*)"type", (xmlChar*)type.extractUTF8().c_str()); + xmlSetProp(rootNode, (xmlChar*)"type", (xmlChar*)type.toUTF8().c_str()); } Net::Packet XmlData::toPacket(boost::uint16_t requestId) const { diff --git a/src/Common/XmlData.h b/src/Common/XmlData.h index 1861b71..4f566fa 100644 --- a/src/Common/XmlData.h +++ b/src/Common/XmlData.h @@ -33,6 +33,7 @@ #include <libxml/parser.h> #include <boost/cstdint.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/noncopyable.hpp> #include <boost/variant/get.hpp> #include <boost/variant/variant.hpp> @@ -56,12 +57,13 @@ class MAD_COMMON_EXPORT XmlData { friend class Entry; enum Type { - NONE, BINARY, + NONE, BINARY, TIME, INT, UINT, INT64, UINT64, FLOAT, DOUBLE, LONGDOUBLE, STRING }; - typedef boost::variant<long, unsigned long, long long, unsigned long long, float, double, long double, std::vector<boost::uint8_t> > Variant; + typedef boost::variant<long, unsigned long, long long, unsigned long long, + float, double, long double, std::vector<boost::uint8_t>, boost::posix_time::ptime> Variant; xmlNodePtr elementNode; @@ -128,6 +130,10 @@ class MAD_COMMON_EXPORT XmlData { void set(const std::vector<boost::uint8_t> &val) { set(val, BINARY); } + + void set(const boost::posix_time::ptime &val) { + set(val, TIME); + } }; public: @@ -151,7 +157,7 @@ class MAD_COMMON_EXPORT XmlData { return 0; xmlNodePtr newNode = xmlNewTextChild(entryNode, 0, (xmlChar*)"value", (xmlChar*)""); - xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.extractUTF8().c_str()); + xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.toUTF8().c_str()); xmlSetProp(newNode, (xmlChar*)"type", (xmlChar*)""); Element* newElement = new Element(newNode); @@ -227,7 +233,7 @@ class MAD_COMMON_EXPORT XmlData { return 0; xmlNodePtr newNode = xmlNewChild(entryNode, 0, (xmlChar*)"list", 0); - xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.extractUTF8().c_str()); + xmlSetProp(newNode, (xmlChar*)"name", (xmlChar*)name.toUTF8().c_str()); List *newList = new List(newNode); @@ -507,6 +513,8 @@ template <> MAD_COMMON_EXPORT const Core::String& XmlData::Entry::get<const Core template <> MAD_COMMON_EXPORT std::vector<boost::uint8_t> XmlData::Entry::get<std::vector<unsigned char> >(const Core::String &name) const; template <> MAD_COMMON_EXPORT const std::vector<boost::uint8_t>& XmlData::Entry::get<const std::vector<unsigned char>&>(const Core::String &name) const; +template <> MAD_COMMON_EXPORT boost::posix_time::ptime XmlData::Entry::get<boost::posix_time::ptime>(const Core::String &name) const; + } } diff --git a/src/Core/Application.cpp b/src/Core/Application.cpp index 666f2cb..86b5b7b 100644 --- a/src/Core/Application.cpp +++ b/src/Core/Application.cpp @@ -33,7 +33,7 @@ namespace Mad { namespace Core { Application::Application() { - std::setlocale(LC_ALL, ""); + std::setlocale(LC_ALL, "en_US.UTF-8"); configManager = new ConfigManager(this); logManager = new LogManager(this); @@ -47,7 +47,7 @@ Application::~Application() { } -void Application::logfv(Logger::MessageCategory category, Logger::MessageLevel level, const char *format, va_list ap) { +void Application::logfv(Logger::MessageCategory category, Logger::MessageLevel level, const Core::String &format, va_list ap) { int size = 100; char *buf = (char*)std::malloc(size); @@ -56,11 +56,11 @@ void Application::logfv(Logger::MessageCategory category, Logger::MessageLevel l va_list ap2; va_copy(ap2, ap); - int n = vsnprintf(buf, size, format, ap2); + int n = vsnprintf(buf, size, format.toLocale().c_str(), ap2); va_end(ap2); if(n > -1 && n < size) { - logManager->log(category, level, boost::posix_time::microsec_clock::universal_time(), buf); + logManager->log(category, level, boost::posix_time::microsec_clock::universal_time(), Core::String::fromLocale(buf)); std::free(buf); return; } @@ -75,32 +75,32 @@ void Application::logfv(Logger::MessageCategory category, Logger::MessageLevel l } -void Application::log(Logger::MessageCategory category, Logger::MessageLevel level, const std::string &message) { +void Application::log(Logger::MessageCategory category, Logger::MessageLevel level, const Core::String &message) { logManager->log(category, level, boost::posix_time::microsec_clock::universal_time(), message); } -void Application::logf(Logger::MessageCategory category, Logger::MessageLevel level, const char *format, ...) { +void Application::logf(Logger::MessageCategory category, Logger::MessageLevel level, const Core::String &format, ...) { va_list ap; va_start(ap, format); logfv(category, level, format, ap); va_end(ap); } -void Application::logf(Logger::MessageCategory category, const char *format, ...) { +void Application::logf(Logger::MessageCategory category, const Core::String &format, ...) { va_list ap; va_start(ap, format); logfv(category, Logger::LOG_DEFAULT, format, ap); va_end(ap); } -void Application::logf(Logger::MessageLevel level, const char *format, ...) { +void Application::logf(Logger::MessageLevel level, const Core::String &format, ...) { va_list ap; va_start(ap, format); logfv(Logger::LOG_GENERAL, level, format, ap); va_end(ap); } -void Application::logf(const char *format, ...) { +void Application::logf(const Core::String &format, ...) { va_list ap; va_start(ap, format); logfv(Logger::LOG_GENERAL, Logger::LOG_DEFAULT, format, ap); diff --git a/src/Core/Application.h b/src/Core/Application.h index 18521d5..ffab639 100644 --- a/src/Core/Application.h +++ b/src/Core/Application.h @@ -45,7 +45,7 @@ class MAD_CORE_EXPORT Application : private boost::noncopyable { LogManager *logManager; ThreadManager *threadManager; - void logfv(Logger::MessageCategory category, Logger::MessageLevel level, const char *format, va_list ap); + void logfv(Logger::MessageCategory category, Logger::MessageLevel level, const Core::String &format, va_list ap); protected: Application(); @@ -69,25 +69,25 @@ class MAD_CORE_EXPORT Application : private boost::noncopyable { } - void log(Logger::MessageCategory category, Logger::MessageLevel level, const std::string &message); + void log(Logger::MessageCategory category, Logger::MessageLevel level, const Core::String &message); - void log(Logger::MessageCategory category, const std::string &message) { + void log(Logger::MessageCategory category, const Core::String &message) { log(category, Logger::LOG_DEFAULT, message); } - void log(Logger::MessageLevel level, const std::string &message) { + void log(Logger::MessageLevel level, const Core::String &message) { log(Logger::LOG_GENERAL, level, message); } - void log(const std::string &message) { + void log(const Core::String &message) { log(Logger::LOG_GENERAL, Logger::LOG_DEFAULT, message); } - void logf(Logger::MessageCategory category, Logger::MessageLevel level, const char *format, ...); - void logf(Logger::MessageCategory category, const char *format, ...); - void logf(Logger::MessageLevel level, const char *format, ...); - void logf(const char *format, ...); + void logf(Logger::MessageCategory category, Logger::MessageLevel level, const Core::String &format, ...); + void logf(Logger::MessageCategory category, const Core::String &format, ...); + void logf(Logger::MessageLevel level, const Core::String &format, ...); + void logf(const Core::String &format, ...); }; } diff --git a/src/Core/ConfigManager.cpp b/src/Core/ConfigManager.cpp index d79ce32..fdbc93f 100644 --- a/src/Core/ConfigManager.cpp +++ b/src/Core/ConfigManager.cpp @@ -48,7 +48,7 @@ void ConfigManager::handleConfigEntry(const ConfigEntry &entry) { } if(!handled) - application->logf(Logger::LOG_WARNING, "Invalid config option '%s'.", entry[entry.getSize()-1].getKey().extract().c_str()); + application->logf(Logger::LOG_WARNING, "Invalid config option '%s'.", entry[entry.getSize()-1].getKey().toLocale().c_str()); } bool ConfigManager::loadFile(const std::string &filename) { @@ -66,9 +66,7 @@ bool ConfigManager::loadFile(const std::string &filename) { while(!(file.eof() && line.isEmpty() && input.isEmpty())) { while(input.isEmpty() && !file.eof()) { - std::string tmp; - std::getline(file, tmp); - input = tmp.c_str(); + input = String::getline(file); } if(input.isEmpty()) diff --git a/src/Core/Exception.cpp b/src/Core/Exception.cpp index 220e6fd..338bd7c 100644 --- a/src/Core/Exception.cpp +++ b/src/Core/Exception.cpp @@ -25,60 +25,62 @@ namespace Mad { namespace Core { void Exception::updateWhatStr() { - if(where.empty()) - whatStr.clear(); + if(where.isEmpty()) + errorStr.remove(); else - whatStr = where + ": "; + errorStr = where + ": "; switch(errorCode) { case SUCCESS: - whatStr += "Success"; + errorStr += "Success"; break; case UNEXPECTED_PACKET: - whatStr += "An unexpected packet was received"; + errorStr += "An unexpected packet was received"; break; case INVALID_ACTION: - whatStr += "The action is invalid"; + errorStr += "The action is invalid"; break; case NOT_AVAILABLE: - whatStr += "Not available"; + errorStr += "Not available"; break; case NOT_FINISHED: - whatStr += "Not finished"; + errorStr += "Not finished"; break; case NOT_IMPLEMENTED: - whatStr += "Not implemented"; + errorStr += "Not implemented"; break; case NOT_FOUND: - whatStr += "Not found"; + errorStr += "Not found"; break; case INVALID_INPUT: - whatStr += "Invalid input"; + errorStr += "Invalid input"; break; case PERMISSION: - whatStr += "Permission denied"; + errorStr += "Permission denied"; break; case INTERNAL_ERRNO: - whatStr += std::strerror(subCode); + errorStr += std::strerror(subCode); break; case INVALID_ADDRESS: - whatStr += "Invalid address"; + errorStr += "Invalid address"; break; case ALREADY_IDENTIFIED: - whatStr += "The host is already identified"; + errorStr += "The host is already identified"; break; case UNKNOWN_DAEMON: whatStr += "The daemon is unknown"; break; case DUPLICATE_ENTRY: - whatStr += "Duplicate entry"; + errorStr += "Duplicate entry"; break; case AUTHENTICATION: - whatStr += "Authentication failure"; + errorStr += "Authentication failure"; break; default: - whatStr += "Unknown error"; + errorStr += "Unknown error"; } + + whatStr = errorStr.toLocale(); } } diff --git a/src/Core/Exception.h b/src/Core/Exception.h index 8e0342d..48688a4 100644 --- a/src/Core/Exception.h +++ b/src/Core/Exception.h @@ -43,18 +43,19 @@ class MAD_CORE_EXPORT Exception : public std::exception { }; private: - std::string where; + Core::String where; ErrorCode errorCode; long subCode; long subSubCode; + Core::String errorStr; std::string whatStr; void updateWhatStr(); public: - Exception(const std::string &where0, ErrorCode errorCode0 = SUCCESS, long subCode0 = 0, long subSubCode0 = 0) + Exception(const Core::String &where0, ErrorCode errorCode0 = SUCCESS, long subCode0 = 0, long subSubCode0 = 0) : where(where0), errorCode(errorCode0), subCode(subCode0), subSubCode(subSubCode0) { updateWhatStr(); } @@ -63,7 +64,7 @@ class MAD_CORE_EXPORT Exception : public std::exception { } virtual ~Exception() throw () {} - const std::string& getWhere() const {return where;} + const Core::String& getWhere() const {return where;} ErrorCode getErrorCode() const {return errorCode;} long getSubCode() const {return subCode;} long getSubSubCode() const {return subSubCode;} @@ -72,7 +73,11 @@ class MAD_CORE_EXPORT Exception : public std::exception { return whatStr.c_str(); } - operator bool() const { + const Core::String& toString() const throw () { + return errorStr; + } + + operator bool() const throw () { return (errorCode != SUCCESS); } }; diff --git a/src/Core/LogManager.cpp b/src/Core/LogManager.cpp index c2a90de..7282009 100644 --- a/src/Core/LogManager.cpp +++ b/src/Core/LogManager.cpp @@ -27,15 +27,15 @@ namespace Mad { namespace Core { -void LogManager::ConsoleLogger::logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) { - if(!(level == LOG_CRITICAL && source.empty())) {// Critical messages are printed to cerr directly, so don't print them a second time +void LogManager::ConsoleLogger::logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const Core::String &message, const Core::String &source) { + if(!(level == LOG_CRITICAL && source.isEmpty())) {// Critical messages are printed to cerr directly, so don't print them a second time boost::lock_guard<boost::mutex> lock(cerrMutex); logMessageDirect(category, level, timestamp, message, source); } } -void LogManager::ConsoleLogger::logMessageDirect(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &source) { - if(source.empty()) +void LogManager::ConsoleLogger::logMessageDirect(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const Core::String &message, const Core::String &source) { + if(source.isEmpty()) std::cerr << message << std::endl; else std::cerr << message << " from " << source << std::endl; @@ -95,7 +95,7 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) { consoleLogger->setLevel(parseLevel(entry[1][0])); } catch(Core::Exception e) { - application->logf(Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].extract().c_str()); + application->logf(Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].toLocale().c_str()); } return true; @@ -104,7 +104,7 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) { } else if(entry[1].isEmpty()) { if(!handled) { - application->logf(Logger::LOG_WARNING, "Unknown logger '%s'.", entry[0][0].extract().c_str()); + application->logf(Logger::LOG_WARNING, "Unknown logger '%s'.", entry[0][0].toLocale().c_str()); return true; } } @@ -123,8 +123,8 @@ void LogManager::configFinished() { queueCond.notify_one(); } -void LogManager::log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) { - if(level == Logger::LOG_CRITICAL && source.empty()) +void LogManager::log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const Core::String &message, const Core::String &source) { + if(level == Logger::LOG_CRITICAL && source.isEmpty()) consoleLogger->logMessageDirect(category, level, timestamp, message, source); boost::lock_guard<boost::mutex> lock(queueMutex); diff --git a/src/Core/LogManager.h b/src/Core/LogManager.h index 4f7c500..a1f3d7d 100644 --- a/src/Core/LogManager.h +++ b/src/Core/LogManager.h @@ -51,8 +51,8 @@ class MAD_CORE_EXPORT LogManager : public Configurable { MessageCategory category; MessageLevel level; boost::posix_time::ptime timestamp; - std::string message; - std::string source; + Core::String message; + Core::String source; }; class ConsoleLogger : public Logger { @@ -62,12 +62,12 @@ class MAD_CORE_EXPORT LogManager : public Configurable { boost::mutex cerrMutex; protected: - virtual void logMessage(MessageCategory category, MessageLevel, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source); + virtual void logMessage(MessageCategory category, MessageLevel, boost::posix_time::ptime timestamp, const Core::String &message, const Core::String &source); public: ConsoleLogger() {} - void logMessageDirect(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source); + void logMessageDirect(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const Core::String &message, const Core::String &source); }; @@ -102,7 +102,7 @@ class MAD_CORE_EXPORT LogManager : public Configurable { public: static MessageLevel parseLevel(const String &str) throw (Exception); - void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source = std::string()); + void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const Core::String &message, const Core::String &source = Core::String()); void registerLogger(boost::shared_ptr<Logger> logger) { boost::lock_guard<boost::mutex> lock(loggerMutex); diff --git a/src/Core/Logger.h b/src/Core/Logger.h index a43b340..89fdc8d 100644 --- a/src/Core/Logger.h +++ b/src/Core/Logger.h @@ -20,8 +20,9 @@ #ifndef MAD_CORE_LOGGER_H_ #define MAD_CORE_LOGGER_H_ +#include "String.h" + #include <bitset> -#include <string> #include <boost/date_time/posix_time/ptime.hpp> namespace Mad { @@ -54,13 +55,13 @@ class Logger { Logger() : level(LOG_DEFAULT), remoteLevel(LOG_DEFAULT) {setAllCategories(); setAllRemoteCategories(); remote = false;} virtual ~Logger() {} - void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) { - if((source.empty() && getLevel() >= level && isCategorySet(category)) - || (!source.empty() && remote && getRemoteLevel() >= level && isRemoteCategorySet(category))) + void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const Core::String &message, const Core::String &source) { + if((source.isEmpty() && getLevel() >= level && isCategorySet(category)) + || (!source.isEmpty() && remote && getRemoteLevel() >= level && isRemoteCategorySet(category))) logMessage(category, level, timestamp, message, source); } - virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) = 0; + virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const Core::String &message, const Core::String &source) = 0; public: void setCategory(MessageCategory newCategory) { diff --git a/src/Core/String.cpp b/src/Core/String.cpp index d9d357e..e66e456 100644 --- a/src/Core/String.cpp +++ b/src/Core/String.cpp @@ -22,6 +22,15 @@ namespace Mad { namespace Core { +std::string String::toCodepage(const char *codepage) const { + boost::uint32_t len = static_cast<boost::uint32_t>(extract(0, length(), 0, codepage)); + + boost::scoped_array<char> buf(new char[len]); + extract(0, length(), buf.get(), len, codepage); + + return std::string(buf.get(), len); +} + boost::int32_t String::findFirstOf(const String &chars, boost::int32_t start) const { for(boost::int32_t i = start; i < length(); ++i) { if(chars.indexOf(charAt(i)) >= 0) diff --git a/src/Core/String.h b/src/Core/String.h index 1c93902..4694812 100644 --- a/src/Core/String.h +++ b/src/Core/String.h @@ -22,7 +22,7 @@ #include "export.h" -#include <ostream> +#include <iostream> #include <string> #include <boost/cstdint.hpp> #include <boost/scoped_array.hpp> @@ -35,25 +35,18 @@ namespace Core { class MAD_CORE_EXPORT String : public icu::UnicodeString { private: - std::string extractCodepage(const char *codepage) const { - boost::uint32_t len = static_cast<boost::uint32_t>(icu::UnicodeString::extract(0, length(), 0, codepage)); - - boost::scoped_array<char> buf(new char[len]); - icu::UnicodeString::extract(0, length(), buf.get(), len, codepage); - - return std::string(buf.get(), len); - } + std::string toCodepage(const char *codepage) const; public: String() {} - String(const icu::UnicodeString &str) : icu::UnicodeString(str) {} - String(const char *str) : icu::UnicodeString(str, -1, US_INV) {} + String(const icu::UnicodeString &str) : UnicodeString(str) {} + String(const char *str) : UnicodeString(str, "") {} String substr(boost::int32_t start, boost::int32_t length = -1) const { if(length < 0) - return icu::UnicodeString(*this, start); + return UnicodeString(*this, start); else - return icu::UnicodeString(*this, start, length); + return UnicodeString(*this, start, length); } bool matches(const String &str) const { @@ -63,22 +56,53 @@ class MAD_CORE_EXPORT String : public icu::UnicodeString { boost::int32_t findFirstOf(const String &chars, boost::int32_t start = 0) const; boost::int32_t findFirstNotOf(const String &chars, boost::int32_t start = 0) const; - std::string extract() const { - return extractCodepage(0); + std::string toString() const { + return toCodepage(""); + } + + std::string toLocale() const { + return toCodepage(0); + } + + std::string toUTF8() const { + return toCodepage("UTF-8"); + } + + static String fromString(const char *str) { + return UnicodeString(str, ""); } - std::string extractUTF8() const { - return extractCodepage("UTF-8"); + static String fromString(const std::string &str) { + return fromString(str.c_str()); + } + + static String fromLocale(const char *str) { + return UnicodeString(str, static_cast<char*>(0)); + } + + static String fromLocale(const std::string &str) { + return fromLocale(str.c_str()); } static String fromUTF8(const char *str) { - return icu::UnicodeString(str, "UTF-8"); + return UnicodeString(str, "UTF-8"); + } + + static String fromUTF8(const std::string &str) { + return fromUTF8(str.c_str()); + } + + template<typename ElemType, typename Traits> + static String getline(std::basic_istream<ElemType, Traits> &stream) { + std::string input; + std::getline(stream, input); + return fromLocale(input); } }; template<typename ElemType, typename Traits> std::basic_ostream<ElemType, Traits>& operator<<(std::basic_ostream<ElemType, Traits> &stream, const String &string) { - stream << string.extract(); + stream << string.toLocale(); return stream; } diff --git a/src/Daemon/Backends/NetworkLogger.h b/src/Daemon/Backends/NetworkLogger.h index 2ee9fcf..dc285a3 100644 --- a/src/Daemon/Backends/NetworkLogger.h +++ b/src/Daemon/Backends/NetworkLogger.h @@ -35,8 +35,8 @@ class NetworkLogger : public Core::Logger { Common::Connection *connection; protected: - virtual void logMessage(Core::Logger::MessageCategory category, Core::Logger::MessageLevel level, boost::posix_time::ptime messageTimestamp, const std::string &message, const std::string &source) { - boost::shared_ptr<Requests::LogRequest> request(new Requests::LogRequest(application, category, level, messageTimestamp, message.c_str(), source.c_str())); + virtual void logMessage(Core::Logger::MessageCategory category, Core::Logger::MessageLevel level, boost::posix_time::ptime messageTimestamp, const Core::String &message, const Core::String &source) { + boost::shared_ptr<Requests::LogRequest> request(new Requests::LogRequest(application, category, level, messageTimestamp, message, source)); application->getRequestManager()->sendRequest(connection, request); } diff --git a/src/Daemon/Requests/LogRequest.cpp b/src/Daemon/Requests/LogRequest.cpp index 1f1fdc8..8a24d26 100644 --- a/src/Daemon/Requests/LogRequest.cpp +++ b/src/Daemon/Requests/LogRequest.cpp @@ -32,7 +32,7 @@ void LogRequest::sendRequest() { packet.set("category", category); packet.set("level", level); - packet.set("timestamp", boost::posix_time::to_iso_string(messageTimestamp).c_str()); + packet.set("timestamp", timestamp); packet.set("message", message); packet.set("source", source); diff --git a/src/Daemon/Requests/LogRequest.h b/src/Daemon/Requests/LogRequest.h index 8630b45..68f8cc0 100644 --- a/src/Daemon/Requests/LogRequest.h +++ b/src/Daemon/Requests/LogRequest.h @@ -33,16 +33,16 @@ class MAD_DAEMON_EXPORT LogRequest : public Common::Request { private: Core::Logger::MessageCategory category; Core::Logger::MessageLevel level; - boost::posix_time::ptime messageTimestamp; + boost::posix_time::ptime timestamp; Core::String message, source; protected: virtual void sendRequest(); public: - LogRequest(Common::Application *application, Core::Logger::MessageCategory category0, Core::Logger::MessageLevel level0, boost::posix_time::ptime messageTimestamp0, const Core::String &message0, + LogRequest(Common::Application *application, Core::Logger::MessageCategory category0, Core::Logger::MessageLevel level0, boost::posix_time::ptime timestamp0, const Core::String &message0, const Core::String &source0) - : Common::Request(application), category(category0), level(level0), messageTimestamp(messageTimestamp0), message(message0), source(source0) {} + : Common::Request(application), category(category0), level(level0), timestamp(timestamp0), message(message0), source(source0) {} }; } diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp index a67e608..3d7088f 100644 --- a/src/Net/Listener.cpp +++ b/src/Net/Listener.cpp @@ -80,7 +80,7 @@ void Listener::handleDisconnect(boost::shared_ptr<Connection> con) { } -Listener::Listener(Core::Application *application0, const std::string &x905CertFile0, const std::string &x905KeyFile0, +Listener::Listener(Core::Application *application0, const Core::String &x905CertFile0, const Core::String &x905KeyFile0, const boost::asio::ip::tcp::endpoint &address0) throw(Core::Exception) : application(application0), x905CertFile(x905CertFile0), x905KeyFile(x905KeyFile0), address(address0), context(new boost::asio::ssl::context(application->getIOService(), boost::asio::ssl::context::sslv23)), @@ -89,8 +89,8 @@ acceptor(application->getIOService(), address), signal(application) context->set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::single_dh_use); - context->use_certificate_chain_file(x905CertFile); - context->use_private_key_file(x905KeyFile, boost::asio::ssl::context::pem); + context->use_certificate_chain_file(x905CertFile.toLocale()); + context->use_private_key_file(x905KeyFile.toLocale(), boost::asio::ssl::context::pem); accept(); } diff --git a/src/Net/Listener.h b/src/Net/Listener.h index 598ea2f..46ad4f2 100644 --- a/src/Net/Listener.h +++ b/src/Net/Listener.h @@ -23,7 +23,6 @@ #include "export.h" #include <map> -#include <string> #include "Connection.h" #include <Core/Exception.h> @@ -37,7 +36,7 @@ class MAD_NET_EXPORT Listener : private boost::noncopyable { boost::mutex mutex; - std::string x905CertFile, x905KeyFile; + Core::String x905CertFile, x905KeyFile; boost::asio::ip::tcp::endpoint address; boost::shared_ptr<boost::asio::ssl::context> context; boost::asio::ip::tcp::acceptor acceptor; @@ -53,7 +52,7 @@ class MAD_NET_EXPORT Listener : private boost::noncopyable { void handleDisconnect(boost::shared_ptr<Connection> con); public: - Listener(Core::Application *application0, const std::string &x905CertFile0, const std::string &x905KeyFile0, + Listener(Core::Application *application0, const Core::String &x905CertFile0, const Core::String &x905KeyFile0, const boost::asio::ip::tcp::endpoint &address0) throw(Core::Exception); virtual ~Listener(); diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index f09f9e3..25e088a 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -120,31 +120,31 @@ bool ConnectionManager::handleConfigEntry(const Core::ConfigEntry &entry, bool h if(entry[0].getKey().matches("Listen") && entry[1].isEmpty()) { try { - listenerAddresses.push_back(parseAddress(entry[0][0].extract())); + listenerAddresses.push_back(parseAddress(entry[0][0].toString())); } catch(Core::Exception &e) { - application->logf(Core::Logger::LOG_WARNING, "ConnectionManager: Invalid listen address '%s'", entry[0][0].extract().c_str()); + application->logf(Core::Logger::LOG_WARNING, "ConnectionManager: Invalid listen address '%s'", entry[0][0].toLocale().c_str()); } return true; } else if(entry[0].getKey().matches("X509TrustFile") && entry[1].isEmpty()) { - x509TrustFile = entry[0][0].extract(); + x509TrustFile = entry[0][0]; return true; } else if(entry[0].getKey().matches("X509CrlFile") && entry[1].isEmpty()) { - x509CrlFile = entry[0][0].extract(); + x509CrlFile = entry[0][0]; return true; } else if(entry[0].getKey().matches("X509CertFile") && entry[1].isEmpty()) { - x509CertFile = entry[0][0].extract(); + x509CertFile = entry[0][0]; return true; } else if(entry[0].getKey().matches("X509KeyFile") && entry[1].isEmpty()) { - x509KeyFile = entry[0][0].extract(); + x509KeyFile = entry[0][0]; return true; } @@ -156,7 +156,7 @@ bool ConnectionManager::handleConfigEntry(const Core::ConfigEntry &entry, bool h return true; } else if(entry[1].getKey().matches("IpAddress") && entry[2].isEmpty()) { - daemonInfo[entry[0][0]].setIP(entry[1][0].extract()); + daemonInfo[entry[0][0]].setIP(entry[1][0].toString()); return true; } diff --git a/src/Server/ConnectionManager.h b/src/Server/ConnectionManager.h index dab1892..7e9dab0 100644 --- a/src/Server/ConnectionManager.h +++ b/src/Server/ConnectionManager.h @@ -107,7 +107,7 @@ class MAD_SERVER_EXPORT ConnectionManager : public Core::Configurable, private b Application *application; - std::string x509TrustFile, x509CrlFile, x509CertFile, x509KeyFile; + Core::String x509TrustFile, x509CrlFile, x509CertFile, x509KeyFile; std::vector<boost::asio::ip::tcp::endpoint> listenerAddresses; std::list<boost::shared_ptr<Net::Listener> > listeners; diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp index d446485..a1c492b 100644 --- a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp @@ -100,23 +100,13 @@ void ConnectionRequestHandlerGroup::handleIdentifyRequest(boost::shared_ptr<cons void ConnectionRequestHandlerGroup::handleLogRequest(boost::shared_ptr<const Common::XmlData> packet, Common::XmlData *ret, Common::Connection *connection) { // TODO Require authentication - boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); - - const Core::String ×tr = packet->get<const Core::String&>("timestamp"); - if(!timestr.isEmpty()) { - try { - timestamp = boost::posix_time::from_iso_string(timestr.extract()); - } - catch(...) {} - } - try { application->getLogManager()->log( static_cast<Core::Logger::MessageCategory>(packet->get<long>("category")), static_cast<Core::Logger::MessageLevel>(packet->get<long>("level")), - timestamp, - packet->get<const Core::String&>("message").extract(), - application->getConnectionManager()->getDaemonName(connection).extract()); + packet->get<boost::posix_time::ptime>("timestamp"), + packet->get<const Core::String&>("message"), + application->getConnectionManager()->getDaemonName(connection)); } catch(Core::Exception &e) { application->logf(Core::Logger::LOG_ERROR, "Can't determine daemon name: %s", e.what()); diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp index 8f6909e..c80f493 100644 --- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp @@ -69,7 +69,7 @@ void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared ret.set("ErrorCode", e.getErrorCode()); ret.set("SubCode", e.getSubCode()); ret.set("SubSubCode", e.getSubSubCode()); - ret.set("Where", e.getWhere().c_str()); + ret.set("Where", e.getWhere()); sendPacket(ret); signalFinished(); @@ -83,7 +83,7 @@ void DaemonRequestHandlerGroup::DaemonRequestHandler::requestFinished(boost::sha ret.set("ErrorCode", error.getErrorCode()); ret.set("SubCode", error.getSubCode()); ret.set("SubSubCode", error.getSubSubCode()); - ret.set("Where", error.getWhere().c_str()); + ret.set("Where", error.getWhere()); sendPacket(ret); } diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp index f43ec86..5a7e3f9 100644 --- a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp @@ -34,22 +34,12 @@ void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr<const Comm if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); - boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); - - const Core::String ×tr = packet->get<const Core::String&>("timestamp"); - if(!timestr.isEmpty()) { - try { - timestamp = boost::posix_time::from_iso_string(timestr.extract()); - } - catch(...) {} - } + boost::posix_time::ptime timestamp = packet->get<boost::posix_time::ptime>("timestamp"); boost::shared_ptr<const std::map<unsigned long, Common::UserInfo> > users = application->getUserManager()->getUserList(×tamp); ret->setType("OK"); - - if(!timestamp.is_not_a_date_time()) - ret->set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + ret->set("timestamp", timestamp); if(users) { Common::XmlData::List *list = ret->createList("users"); @@ -70,15 +60,7 @@ void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr<const Comm if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); - boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); - - const Core::String ×tr = packet->get<const Core::String&>("timestamp"); - if(!timestr.isEmpty()) { - try { - timestamp = boost::posix_time::from_iso_string(timestr.extract()); - } - catch(...) {} - } + boost::posix_time::ptime timestamp = packet->get<boost::posix_time::ptime>("timestamp"); boost::shared_ptr<const Common::UserInfo> info; @@ -89,9 +71,7 @@ void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr<const Comm info = application->getUserManager()->getUserInfoByName(packet->get<const Core::String&>("name"), ×tamp); ret->setType("OK"); - - if(!timestamp.is_not_a_date_time()) - ret->set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + ret->set("timestamp", timestamp); if(info) { ret->set("uid", info->getUid()); @@ -106,22 +86,12 @@ void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr<const if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); - boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); - - const Core::String ×tr = packet->get<const Core::String&>("timestamp"); - if(!timestr.isEmpty()) { - try { - timestamp = boost::posix_time::from_iso_string(timestr.extract()); - } - catch(...) {} - } + boost::posix_time::ptime timestamp = packet->get<boost::posix_time::ptime>("timestamp"); boost::shared_ptr<const std::set<unsigned long> > groups = application->getUserManager()->getUserGroupList(packet->get<unsigned long>("uid"), ×tamp); ret->setType("OK"); - - if(!timestamp.is_not_a_date_time()) - ret->set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + ret->set("timestamp", timestamp); if(groups) { Common::XmlData::List *list = ret->createList("groups"); @@ -139,22 +109,12 @@ void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr<const Com if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); - boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); - - const Core::String ×tr = packet->get<const Core::String&>("timestamp"); - if(!timestr.isEmpty()) { - try { - timestamp = boost::posix_time::from_iso_string(timestr.extract()); - } - catch(...) {} - } + boost::posix_time::ptime timestamp = packet->get<boost::posix_time::ptime>("timestamp"); boost::shared_ptr<const std::map<unsigned long, Common::GroupInfo> > groups = application->getUserManager()->getGroupList(×tamp); ret->setType("OK"); - - if(!timestamp.is_not_a_date_time()) - ret->set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + ret->set("timestamp", timestamp); if(groups) { Common::XmlData::List *list = ret->createList("groups"); @@ -173,15 +133,7 @@ void UserRequestHandlerGroup::handleGroupInfoRequest(boost::shared_ptr<const Com if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); - boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); - - const Core::String ×tr = packet->get<const Core::String&>("timestamp"); - if(!timestr.isEmpty()) { - try { - timestamp = boost::posix_time::from_iso_string(timestr.extract()); - } - catch(...) {} - } + boost::posix_time::ptime timestamp = packet->get<boost::posix_time::ptime>("timestamp"); boost::shared_ptr<const Common::GroupInfo> info; @@ -192,9 +144,7 @@ void UserRequestHandlerGroup::handleGroupInfoRequest(boost::shared_ptr<const Com info = application->getUserManager()->getGroupInfoByName(packet->get<const Core::String&>("name"), ×tamp); ret->setType("OK"); - - if(!timestamp.is_not_a_date_time()) - ret->set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + ret->set("timestamp", timestamp); if(info) { ret->set("gid", info->getGid()); @@ -207,22 +157,12 @@ void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr<const if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); - boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); - - const Core::String ×tr = packet->get<const Core::String&>("timestamp"); - if(!timestr.isEmpty()) { - try { - timestamp = boost::posix_time::from_iso_string(timestr.extract()); - } - catch(...) {} - } + boost::posix_time::ptime timestamp = packet->get<boost::posix_time::ptime>("timestamp"); boost::shared_ptr<const std::set<unsigned long> > users = application->getUserManager()->getGroupUserList(packet->get<unsigned long>("gid"), ×tamp); ret->setType("OK"); - - if(!timestamp.is_not_a_date_time()) - ret->set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + ret->set("timestamp", timestamp); Common::XmlData::List *list = ret->createList("users"); @@ -238,22 +178,12 @@ void UserRequestHandlerGroup::handleFullUserGroupListRequest(boost::shared_ptr<c if(!connection->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); - boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time); - - const Core::String ×tr = packet->get<const Core::String&>("timestamp"); - if(!timestr.isEmpty()) { - try { - timestamp = boost::posix_time::from_iso_string(timestr.extract()); - } - catch(...) {} - } + boost::posix_time::ptime timestamp = packet->get<boost::posix_time::ptime>("timestamp"); boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > userGroups = application->getUserManager()->getFullUserGroupList(×tamp); ret->setType("OK"); - - if(!timestamp.is_not_a_date_time()) - ret->set("timestamp", boost::posix_time::to_iso_string(timestamp).c_str()); + ret->set("timestamp", timestamp); if(userGroups) { Common::XmlData::List *list = ret->createList("userGroupList"); diff --git a/src/madc.cpp b/src/madc.cpp index 88060e9..7d8cb81 100644 --- a/src/madc.cpp +++ b/src/madc.cpp @@ -95,21 +95,18 @@ int main(int argc, char *argv[]) { std::cerr << " connected." << std::endl << std::endl; { - std::string username; - Core::String password; - std::cerr << "Login: " << std::flush; - std::getline(std::cin, username); - password = Client::PasswordReader::readPassword("Password: "); + Core::String username = Core::String::getline(std::cin); + Core::String password = Client::PasswordReader::readPassword("Password: "); try { - Client::Authenticators::ChallengeResponseAuthenticator::authenticate(&application, connection, username.c_str(), password); + Client::Authenticators::ChallengeResponseAuthenticator::authenticate(&application, connection, username, password); } catch(Core::Exception e) { if(e.getErrorCode() != Core::Exception::NOT_AVAILABLE) throw e; - Client::Authenticators::PasswordAuthenticator::authenticate(&application, connection, username.c_str(), password); + Client::Authenticators::PasswordAuthenticator::authenticate(&application, connection, username, password); } } @@ -144,8 +141,7 @@ int main(int argc, char *argv[]) { commandParser.requestDisconnect(); } else if(*cmd) { - // TODO Use locale - commandParser.parse(Core::String::fromUTF8(cmd)); + commandParser.parse(Core::String::fromLocale(cmd)); history(hist, &histEv, H_ENTER, cmd); } else continue; diff --git a/src/modules/AuthProviderFile/AuthProviderFile.cpp b/src/modules/AuthProviderFile/AuthProviderFile.cpp index b006cdc..177d633 100644 --- a/src/modules/AuthProviderFile/AuthProviderFile.cpp +++ b/src/modules/AuthProviderFile/AuthProviderFile.cpp @@ -54,13 +54,14 @@ void AuthProviderFile::readFile(const std::string &name) { continue; } - Core::String password = match[2].str().c_str(); + Core::String username = Core::String::fromLocale(match[1].str()); + Core::String password = Core::String::fromLocale(match[2].str()); if(filehash.isEmpty()) { - std::string utf8pass = password.extractUTF8(); + std::string utf8pass = password.toUTF8(); boost::lock_guard<boost::mutex> lock(mutex); - userMap.insert(std::make_pair(match[1].str().c_str(), std::vector<boost::uint8_t>(utf8pass.begin(), utf8pass.end()))); + userMap.insert(std::make_pair(username, std::vector<boost::uint8_t>(utf8pass.begin(), utf8pass.end()))); } else { std::vector<boost::uint8_t> data; @@ -81,7 +82,7 @@ void AuthProviderFile::readFile(const std::string &name) { if(!data.empty()) { boost::lock_guard<boost::mutex> lock(mutex); - userMap.insert(std::make_pair(match[1].str().c_str(), data)); + userMap.insert(std::make_pair(username, data)); } } } @@ -99,7 +100,7 @@ bool AuthProviderFile::handleConfigEntry(const Core::ConfigEntry &entry, bool /* filehash = entry[1][0]; if(!Common::Hash::isHashSupported(filehash)) - application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.extract().c_str()); + application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.toLocale().c_str()); } } else if(entry[1].getKey().matches("File")) { @@ -126,7 +127,7 @@ void AuthProviderFile::configFinished() { hashes.push_back("Clear"); for(std::vector<Core::String>::iterator file = files.begin(); file != files.end(); ++file) - readFile(file->extract()); + readFile(file->toLocale()); } bool AuthProviderFile::checkPassword(const Core::String &user, const std::vector<boost::uint8_t> &data, const Core::String &hash) throw(Core::Exception) { diff --git a/src/modules/FileLogger/FileLogger.h b/src/modules/FileLogger/FileLogger.h index edd74a8..9fccc64 100644 --- a/src/modules/FileLogger/FileLogger.h +++ b/src/modules/FileLogger/FileLogger.h @@ -33,8 +33,8 @@ class FileLogger : public Core::Logger { std::ofstream file; protected: - virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &source) { - if(source.empty()) + virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const Core::String &message, const Core::String &source) { + if(source.isEmpty()) file << message << std::endl; else file << message << " from " << source << std::endl; diff --git a/src/modules/FileLogger/Module.cpp b/src/modules/FileLogger/Module.cpp index 663389f..d8a302c 100644 --- a/src/modules/FileLogger/Module.cpp +++ b/src/modules/FileLogger/Module.cpp @@ -34,7 +34,7 @@ bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) { if(entry[0][0].matches("File")) { if(entry[1].isEmpty()) { if(!entry[0][1].isEmpty()) { - lastLogger.reset(new FileLogger(entry[0][1].extract())); + lastLogger.reset(new FileLogger(entry[0][1].toLocale())); loggers.insert(lastLogger); application->getLogManager()->registerLogger(lastLogger); @@ -55,7 +55,7 @@ bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) { lastLogger->setLevel(Core::LogManager::parseLevel(entry[1][0])); } catch(Core::Exception e) { - application->logf(Core::Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].extract().c_str()); + application->logf(Core::Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].toLocale().c_str()); } return true; diff --git a/src/modules/StorageBackendFile/StorageBackendFile.cpp b/src/modules/StorageBackendFile/StorageBackendFile.cpp index 0affc2c..e5da4e0 100644 --- a/src/modules/StorageBackendFile/StorageBackendFile.cpp +++ b/src/modules/StorageBackendFile/StorageBackendFile.cpp @@ -38,7 +38,7 @@ bool StorageBackendFile::handleConfigEntry(const Core::ConfigEntry &entry, bool if(!entry[2].isEmpty()) return false; - storageRoot = entry[1][0].extract(); + storageRoot = entry[1][0].toLocale(); } else if(!entry[1].isEmpty()) { return false; @@ -65,8 +65,8 @@ void StorageBackendFile::configFinished() { boost::filesystem::path StorageBackendFile::getFileName(const Core::String &type, const Core::String &name) { boost::filesystem::path path(storageRoot); - path /= type.extract(); - path /= Core::String(name + ".xml").extract(); + path /= type.toLocale(); + path /= Core::String(name + ".xml").toLocale(); return path; } @@ -101,7 +101,7 @@ std::set<Core::String> StorageBackendFile::list(const Core::String &type) throw std::set<Core::String> ret; boost::filesystem::path path(storageRoot); - path /= type.extract(); + path /= type.toLocale(); try { for(boost::filesystem::directory_iterator it(path); it != boost::filesystem::directory_iterator(); ++it) { diff --git a/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp b/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp index e1db3b9..4dca729 100644 --- a/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp +++ b/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp @@ -48,9 +48,9 @@ bool UserConfigBackendHome::handleConfigEntry(const Core::ConfigEntry &entry, bo } else { char *endptr; - unsigned long val = std::strtoul(entry[1][0].extract().c_str(), &endptr, 8); + unsigned long val = std::strtoul(entry[1][0].toString().c_str(), &endptr, 8); if(*endptr || val > 07777) { - application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: DirMode '%s'", entry[1][0].extract().c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: DirMode '%s'", entry[1][0].toLocale().c_str()); } else { dirMode = val; @@ -104,8 +104,8 @@ void UserConfigBackendHome::migrateOwner(const std::string &path, const Common:: } void UserConfigBackendHome::addUser(const Common::UserInfo &userInfo) throw(Core::Exception) { - boost::filesystem::path path(homeDir.extract()); - path /= userInfo.getUsername().extract(); + boost::filesystem::path path(homeDir.toLocale()); + path /= userInfo.getUsername().toLocale(); boost::filesystem::create_directories(path); @@ -118,7 +118,7 @@ void UserConfigBackendHome::addUser(const Common::UserInfo &userInfo) throw(Core // TODO Error } - boost::filesystem::path skeletonPath(skeleton.extract()); + boost::filesystem::path skeletonPath(skeleton.toLocale()); if(!boost::filesystem::is_directory(skeletonPath)) return; @@ -161,11 +161,11 @@ void UserConfigBackendHome::addUser(const Common::UserInfo &userInfo) throw(Core } void UserConfigBackendHome::updateUser(const Common::UserInfo &oldUserInfo, const Common::UserInfo &userInfo) throw(Core::Exception) { - boost::filesystem::path oldPath(homeDir.extract()); - oldPath /= oldUserInfo.getUsername().extract(); + boost::filesystem::path oldPath(homeDir.toLocale()); + oldPath /= oldUserInfo.getUsername().toLocale(); - boost::filesystem::path path(homeDir.extract()); - path /= userInfo.getUsername().extract(); + boost::filesystem::path path(homeDir.toLocale()); + path /= userInfo.getUsername().toLocale(); if(oldPath != path) { try { @@ -202,8 +202,8 @@ void UserConfigBackendHome::updateUser(const Common::UserInfo &oldUserInfo, cons } void UserConfigBackendHome::deleteUser(const Common::UserInfo &userInfo) throw(Core::Exception) { - boost::filesystem::path path(homeDir.extract()); - path /= userInfo.getUsername().extract(); + boost::filesystem::path path(homeDir.toLocale()); + path /= userInfo.getUsername().toLocale(); boost::filesystem::remove_all(path); } diff --git a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp index 7d53e55..f0c65b1 100644 --- a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp +++ b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp @@ -30,12 +30,12 @@ namespace Modules { namespace UserConfigBackendKrb5 { void UserConfigBackendKrb5::_connect() { - if(principal.empty()) { + if(principal.isEmpty()) { application->log(Core::Logger::LOG_USER, Core::Logger::LOG_ERROR, "UserConfigBackendKrb5: no principal given"); return; } - if(realm.empty()) { + if(realm.isEmpty()) { application->log(Core::Logger::LOG_USER, Core::Logger::LOG_ERROR, "UserConfigBackendKrb5: no realm given and no default realm available"); return; } @@ -49,20 +49,22 @@ void UserConfigBackendKrb5::_connect() { } kadm5_config_params params; - params.realm = const_cast<char*>(realm.c_str()); + std::string realmStr = realm.toLocale(); + params.realm = const_cast<char*>(realmStr.c_str()); params.mask = KADM5_CONFIG_REALM; - if(!server.empty()) { - params.admin_server = const_cast<char*>(server.c_str()); + std::string serverStr = server.toLocale(); + if(!serverStr.empty()) { + params.admin_server = const_cast<char*>(serverStr.c_str()); params.mask |= KADM5_CONFIG_ADMIN_SERVER; } - std::string princ = principal; - if(princ.find('@') == std::string::npos) + Core::String princ = principal; + if(princ.indexOf('@') < 0) princ += "@" + realm; - if(!password.empty() && keytab.empty()) { - krb5_error_code err = kadm5_init_with_password(const_cast<char*>(princ.c_str()), const_cast<char*>(password.c_str()), + if(!password.isEmpty() && keytab.isEmpty()) { + krb5_error_code err = kadm5_init_with_password(const_cast<char*>(princ.toLocale().c_str()), const_cast<char*>(password.toLocale().c_str()), const_cast<char*>(KADM5_ADMIN_SERVICE), ¶ms, KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, 0, &handle); if(err) { @@ -72,10 +74,13 @@ void UserConfigBackendKrb5::_connect() { } else { char *keytabName = 0; - if(!keytab.empty()) - keytabName = const_cast<char*>(keytab.c_str()); - krb5_error_code err = kadm5_init_with_skey(const_cast<char*>(princ.c_str()), keytabName, + std::string keytabStr = keytab.toLocale(); + if(!keytabStr.empty()) { + keytabName = const_cast<char*>(keytabStr.c_str()); + } + + krb5_error_code err = kadm5_init_with_skey(const_cast<char*>(princ.toLocale().c_str()), keytabName, const_cast<char*>(KADM5_ADMIN_SERVICE), ¶ms, KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, 0, &handle); if(err) { @@ -102,23 +107,23 @@ bool UserConfigBackendKrb5::handleConfigEntry(const Core::ConfigEntry &entry, bo if(entry[2].getKey().matches("Realm")) { if(entry[3].isEmpty()) - realm = entry[2][0].extract(); + realm = entry[2][0]; } else if(entry[2].getKey().matches("Principal")) { if(entry[3].isEmpty()) - principal = entry[2][0].extract(); + principal = entry[2][0]; } else if(entry[2].getKey().matches("Server")) { if(entry[3].isEmpty()) - server = entry[2][0].extract(); + server = entry[2][0]; } else if(entry[2].getKey().matches("Password")) { if(entry[3].isEmpty()) - password = entry[2][0].extract(); + password = entry[2][0]; } else if(entry[2].getKey().matches("Keytab")) { if(entry[3].isEmpty()) - keytab = entry[2][0].extract(); + keytab = entry[2][0]; } else if(!entry[2].isEmpty()) return false; @@ -133,7 +138,7 @@ void UserConfigBackendKrb5::configFinished() { void UserConfigBackendKrb5::checkUserInfo(const Common::UserInfo &userInfo) throw(Core::Exception) { - std::string username = userInfo.getUsername().extract(); + std::string username = userInfo.getUsername().toLocale(); if(std::strcspn(username.c_str(), "/@") != username.length()) throw Core::Exception(Core::Exception::INVALID_INPUT); @@ -147,11 +152,11 @@ void UserConfigBackendKrb5::addUser(const Common::UserInfo &userInfo) throw(Core if(!context || !handle) throw Core::Exception(Core::Exception::NOT_AVAILABLE); - std::string princStr = userInfo.getUsername().extract() + "@" + realm; + Core::String princStr = userInfo.getUsername() + "@" + realm; kadm5_principal_ent_rec princ; - krb5_error_code err = krb5_parse_name(context, princStr.c_str(), &princ.principal); + krb5_error_code err = krb5_parse_name(context, princStr.toLocale().c_str(), &princ.principal); if(err) throw Core::Exception("krb5_parse_name", Core::Exception::INTERNAL_ERRNO, err); @@ -230,10 +235,10 @@ void UserConfigBackendKrb5::deleteUser(const Common::UserInfo &userInfo) throw(C if(!context || !handle) throw Core::Exception(Core::Exception::NOT_AVAILABLE); - std::string princStr = userInfo.getUsername().extract() + "@" + realm; + Core::String princStr = userInfo.getUsername() + "@" + realm; krb5_principal princ; - krb5_error_code err = krb5_parse_name(context, princStr.c_str(), &princ); + krb5_error_code err = krb5_parse_name(context, princStr.toLocale().c_str(), &princ); if(err) throw Core::Exception("krb5_parse_name", Core::Exception::INTERNAL_ERRNO, err); @@ -255,7 +260,7 @@ void UserConfigBackendKrb5::deleteUser(const Common::UserInfo &userInfo) throw(C application->logf(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, "kadm5_delete_principal: %s", krb5_get_error_message(context, err)); } -void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const std::string &password) throw(Core::Exception) { +void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const Core::String &password) throw(Core::Exception) { application->getThreadManager()->detach(); boost::lock_guard<boost::mutex> lock(mutex); @@ -263,17 +268,17 @@ void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const if(!context || !handle) throw Core::Exception(Core::Exception::NOT_AVAILABLE); - std::string princStr = userInfo.getUsername().extract() + "@" + realm; + Core::String princStr = userInfo.getUsername() + "@" + realm; krb5_principal princ; - krb5_error_code err = krb5_parse_name(context, princStr.c_str(), &princ); + krb5_error_code err = krb5_parse_name(context, princStr.toLocale().c_str(), &princ); if(err) throw Core::Exception("krb5_parse_name", Core::Exception::INTERNAL_ERRNO, err); int retryCount = 3; do { - err = kadm5_chpass_principal(handle, princ, const_cast<char*>(password.c_str())); + err = kadm5_chpass_principal(handle, princ, const_cast<char*>(password.toLocale().c_str())); if(err == KADM5_RPC_ERROR && retryCount > 0) { application->log(Core::Logger::LOG_USER, Core::Logger::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); _connect(); diff --git a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.h b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.h index c2b35fe..eab8be4 100644 --- a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.h +++ b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.h @@ -41,8 +41,8 @@ class UserConfigBackendKrb5 : public Common::UserConfigBackend, private Core::Co boost::mutex mutex; - std::string realm, principal, server; - std::string password, keytab; + Core::String realm, principal, server; + Core::String password, keytab; krb5_context context; void *handle; @@ -59,7 +59,7 @@ class UserConfigBackendKrb5 : public Common::UserConfigBackend, private Core::Co virtual void updateUser(const Common::UserInfo &oldUserInfo, const Common::UserInfo &userInfo) throw(Core::Exception); virtual void deleteUser(const Common::UserInfo &userInfo) throw(Core::Exception); - virtual void setPassword(const Common::UserInfo &userInfo, const std::string &password) throw(Core::Exception); + virtual void setPassword(const Common::UserInfo &userInfo, const Core::String &password) throw(Core::Exception); public: UserConfigBackendKrb5(Common::Application *application0) : application(application0), handle(0) { diff --git a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp index 46f9d12..1d213a8 100644 --- a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp +++ b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp @@ -68,7 +68,7 @@ bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool char *endptr; long val; - val = strtol(entry[2][0].extract().c_str(), &endptr, 10); + val = strtol(entry[2][0].toString().c_str(), &endptr, 10); if(endptr != 0 || val < 0 || val > 65535) application->log(Core::Logger::LOG_WARNING, "UserDBBackendMysql: Invalid port"); @@ -166,8 +166,8 @@ void UserDBBackendMysql::configFinished() { boost::lock_guard<boost::mutex> lock(mutex); mysql = mysql_init(0); - mysql_real_connect(mysql, host.extract().c_str(), username.extract().c_str(), passwd.extract().c_str(), - db.extract().c_str(), port, unixSocket.isEmpty() ? 0 : unixSocket.extract().c_str(), 0); + mysql_real_connect(mysql, host.toLocale().c_str(), username.toLocale().c_str(), passwd.toLocale().c_str(), + db.toLocale().c_str(), port, unixSocket.isEmpty() ? 0 : unixSocket.toLocale().c_str(), 0); } @@ -175,7 +175,7 @@ UserDBBackendMysql::Result UserDBBackendMysql::query(const Core::String &query, if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); - std::string queryStr = query.extract(); + std::string queryStr = query.toLocale(); if(args.empty()) { mysql_real_query(mysql, queryStr.c_str(), queryStr.length()); @@ -185,7 +185,7 @@ UserDBBackendMysql::Result UserDBBackendMysql::query(const Core::String &query, std::string argStr; try { - argStr = boost::get<Core::String>(arg->second).extract(); + argStr = boost::get<Core::String>(arg->second).toLocale(); } catch(...) { std::ostringstream stream; @@ -196,7 +196,7 @@ UserDBBackendMysql::Result UserDBBackendMysql::query(const Core::String &query, boost::scoped_array<char> escaped(new char[argStr.length()*2+1]); mysql_real_escape_string(mysql, escaped.get(), argStr.c_str(), argStr.length()); - queryStr = boost::regex_replace(queryStr, boost::regex("\\{" + arg->first.extract() + "\\}"), "\"" + std::string(escaped.get()) + "\"", boost::match_default); + queryStr = boost::regex_replace(queryStr, boost::regex("\\{" + arg->first.toLocale() + "\\}"), "\"" + std::string(escaped.get()) + "\"", boost::match_default); } mysql_real_query(mysql, queryStr.c_str(), queryStr.length()); |