summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Backends/NetworkUserBackend.cpp75
-rw-r--r--src/Common/Hash.h4
-rw-r--r--src/Common/ModuleManager.cpp8
-rw-r--r--src/Common/Request.cpp3
-rw-r--r--src/Common/RequestHandlers/SimpleRequestHandler.cpp2
-rw-r--r--src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp2
-rw-r--r--src/Common/Requests/DisconnectRequest.cpp9
-rw-r--r--src/Common/UserManager.cpp16
-rw-r--r--src/Common/XmlData.cpp43
-rw-r--r--src/Common/XmlData.h16
10 files changed, 102 insertions, 76 deletions
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;
+
}
}