From 7967b82c19bfa5bd2249abcb807a7a55af031abe Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 23 Mar 2011 21:11:18 +0100 Subject: 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 --- src/common/permissionmanager.cpp | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'src/common') 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")) -- cgit