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/utils/xml.cpp | |
parent | 0391a2203100d1c6c45e8eb92f10ab625d66906b (diff) | |
download | manaserv-7967b82c19bfa5bd2249abcb807a7a55af031abe.tar.gz manaserv-7967b82c19bfa5bd2249abcb807a7a55af031abe.tar.bz2 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/utils/xml.cpp')
-rw-r--r-- | src/utils/xml.cpp | 53 |
1 files changed, 11 insertions, 42 deletions
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) |