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/utils/xml.cpp | 53 +++++++++++------------------------------------------ 1 file changed, 11 insertions(+), 42 deletions(-) (limited to 'src/utils/xml.cpp') diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index a4a5360e..5d579ddc 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -30,62 +30,31 @@ namespace XML { - Document::Document(const std::string &filename, bool useResman): + Document::Document(const std::string &fileName, bool useResman): mDoc(0) { - int size; - char *data = NULL; + std::string resolvedFileName = fileName; if (useResman) { - data = ResourceManager::loadFile(filename, size); - } - else - { - std::ifstream file; - file.open(filename.c_str(), std::ios::in); + resolvedFileName = ResourceManager::resolve(fileName); - if (file.is_open()) + if (resolvedFileName.empty()) { - // Get length of file - file.seekg(0, std::ios::end); - size = file.tellg(); - file.seekg(0, std::ios::beg); - - data = (char*) malloc(size); - - file.read(data, size); - file.close(); - } - else - { - LOG_ERROR("(XML::Document) Error loading XML file: " - << filename); + LOG_ERROR("(XML::Document) File not found in search path: " + << fileName); + return; } } - if (data) - { - mDoc = xmlParseMemory(data, size); - free(data); + mDoc = xmlParseFile(resolvedFileName.c_str()); - if (!mDoc) - { - LOG_ERROR("(XML::Document) Error parsing XML file: " - << filename); - } - } - else + if (!mDoc) { - LOG_ERROR("(XML::Document) Error loading XML file: " - << filename); + LOG_ERROR("(XML::Document) Error parsing XML file: " + << resolvedFileName); } } - Document::Document(const char *data, int size) - { - mDoc = xmlParseMemory(data, size); - } - Document::~Document() { if (mDoc) -- cgit v1.2.3-60-g2f50