summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-23 21:11:18 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-23 23:08:23 +0100
commit7967b82c19bfa5bd2249abcb807a7a55af031abe (patch)
tree751fdbd7c49466aa2f4a47e237ca489895078018 /src/utils
parent0391a2203100d1c6c45e8eb92f10ab625d66906b (diff)
downloadmanaserv-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/utils')
-rw-r--r--src/utils/xml.cpp53
-rw-r--r--src/utils/xml.h17
2 files changed, 17 insertions, 53 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index a4a5360..5d579dd 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)
diff --git a/src/utils/xml.h b/src/utils/xml.h
index eba88e5..2278ce4 100644
--- a/src/utils/xml.h
+++ b/src/utils/xml.h
@@ -40,19 +40,14 @@ namespace XML
{
public:
/**
- * Constructor that attempts to load the given file through the
- * resource manager. Logs errors.
- */
- Document(const std::string &filename, bool useResman = true);
-
- /**
- * Constructor that attempts to load an XML document from memory.
- * Does not log errors.
+ * Attempts to load an XML document from the given file. Logs an
+ * error when something went wrong.
*
- * @param data the string to parse as XML
- * @param size the length of the string in bytes
+ * @param fileName the file name of the XML document
+ * @param useResman whether to resolve the full path to the file
+ * using the resource manager (true by default).
*/
- Document(const char *data, int size);
+ Document(const std::string &fileName, bool useResman = true);
/**
* Destructor. Frees the loaded XML file.