diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2011-03-23 21:11:18 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2011-03-23 23:08:23 +0100 |
commit | 7967b82c19bfa5bd2249abcb807a7a55af031abe (patch) | |
tree | 751fdbd7c49466aa2f4a47e237ca489895078018 /src/common | |
parent | 0391a2203100d1c6c45e8eb92f10ab625d66906b (diff) | |
download | manaserv-7967b82c19bfa5bd2249abcb807a7a55af031abe.tar.gz manaserv-7967b82c19bfa5bd2249abcb807a7a55af031abe.tar.xz manaserv-7967b82c19bfa5bd2249abcb807a7a55af031abe.zip |
Fixed problems with loading XML files containing Windows newlines
By using xmlParseFile instead of xmlParseMemory, the system-dependent
newlines should be handled automatically.
The .tmx.gz files should still be supported, but instead of manually
decompressing them the xmlParseFile function should take care of that.
It also fixes the leaking of XML documents in both the SkillManager as
well as the PermissionManager, since they now rely on XML::Document,
which cleans up automatically.
Reviewed-by: Stefan Dombrowski
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/permissionmanager.cpp | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/src/common/permissionmanager.cpp b/src/common/permissionmanager.cpp index a2c67cd..573e1d2 100644 --- a/src/common/permissionmanager.cpp +++ b/src/common/permissionmanager.cpp @@ -20,7 +20,6 @@ #include "common/permissionmanager.h" -#include "common/resourcemanager.h" #include "game-server/character.h" #include "utils/logger.h" #include "utils/xml.h" @@ -52,37 +51,18 @@ void PermissionManager::initialize(const std::string & file) void PermissionManager::reload() { - int size; - char *data = ResourceManager::loadFile(permissionFile, size); + XML::Document doc(permissionFile); + xmlNodePtr rootNode = doc.rootNode(); - if (!data) { - LOG_ERROR("Permission Manager: Could not find " - << permissionFile << "!"); - free(data); - return; - } - - xmlDocPtr doc = xmlParseMemory(data, size); - free(data); - - if (!doc) - { - LOG_ERROR("Permission Manager: Error while parsing permission database (" - << permissionFile << ")!"); - return; - } - - xmlNodePtr node = xmlDocGetRootElement(doc); - if (!node || !xmlStrEqual(node->name, BAD_CAST "permissions")) + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "permissions")) { LOG_ERROR("Permission Manager: " << permissionFile << " is not a valid database file!"); - xmlFreeDoc(doc); return; } LOG_INFO("Loading permission reference..."); - for (node = node->xmlChildrenNode; node != NULL; node = node->next) + for_each_xml_child_node(node, rootNode) { unsigned char classmask = 0x01; if (!xmlStrEqual(node->name, BAD_CAST "class")) |