diff options
Diffstat (limited to 'src/configuration.cpp')
-rw-r--r-- | src/configuration.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp index 53f6785e..d33df386 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -30,6 +30,7 @@ #include "log.h" #include "utils/tostring.h" +#include "utils/xml.h" void Configuration::init(const std::string &filename) { @@ -48,14 +49,14 @@ void Configuration::init(const std::string &filename) if (!doc) return; - xmlNodePtr node = xmlDocGetRootElement(doc); + xmlNodePtr rootNode = xmlDocGetRootElement(doc); - if (!node || !xmlStrEqual(node->name, BAD_CAST "configuration")) { + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "configuration")) { logger->log("Warning: No configuration file (%s)", filename.c_str()); return; } - for (node = node->xmlChildrenNode; node != NULL; node = node->next) + for_each_xml_child_node(node, rootNode) { if (!xmlStrEqual(node->name, BAD_CAST "option")) continue; @@ -79,6 +80,8 @@ void Configuration::write() // Do not attempt to write to file that cannot be opened for writing FILE *testFile = fopen(mConfigPath.c_str(), "w"); if (!testFile) { + logger->log("Configuration::write() couldn't open %s for writing", + mConfigPath.c_str()); return; } else { @@ -87,8 +90,12 @@ void Configuration::write() xmlTextWriterPtr writer = xmlNewTextWriterFilename(mConfigPath.c_str(), 0); - if (!writer) + if (!writer) { + logger->log("Configuration::write() error while creating writer"); return; + } + + logger->log("Configuration::write() writing configuration..."); xmlTextWriterSetIndent(writer, 1); xmlTextWriterStartDocument(writer, NULL, NULL, NULL); @@ -96,9 +103,6 @@ void Configuration::write() for (OptionIterator i = mOptions.begin(); i != mOptions.end(); i++) { - logger->log("Configuration::write(%s, \"%s\")", - i->first.c_str(), i->second.c_str()); - xmlTextWriterStartElement(writer, BAD_CAST "option"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST i->first.c_str()); |