diff --git a/daemon/src/config/yamlparser.cpp b/daemon/src/config/yamlparser.cpp index 10a34bb0b59ce8586735a64f68850c349a4162b2..b83e5a4f402466c40ab44999dfe6b48c17f187b6 100644 --- a/daemon/src/config/yamlparser.cpp +++ b/daemon/src/config/yamlparser.cpp @@ -40,8 +40,7 @@ namespace Conf { -YamlParser::YamlParser(const char *file) : filename_(file) - , fd_(0) +YamlParser::YamlParser(FILE *fd) : fd_(fd) , parser_() , events_() , eventNumber_(0) @@ -58,7 +57,6 @@ YamlParser::YamlParser(const char *file) : filename_(file) , voiplinkNode_(NULL) , shortcutNode_(NULL) { - fd_ = fopen(filename_.c_str(), "rb"); if (!fd_) throw YamlParserException("Could not open file descriptor"); @@ -129,10 +127,8 @@ YamlParser::getShortcutNode() YamlParser::~YamlParser() { - if (fd_) { - fclose(fd_); + if (fd_) yaml_parser_delete(&parser_); - } for (int i = 0; i < eventNumber_; ++i) yaml_event_delete(&events_[i]); diff --git a/daemon/src/config/yamlparser.h b/daemon/src/config/yamlparser.h index 09d2959f8d620bfa1b5e9ae486d6e2a4142877f8..a94bcf601e2c5f5d1716574e1edd4579d5b9d7c5 100644 --- a/daemon/src/config/yamlparser.h +++ b/daemon/src/config/yamlparser.h @@ -51,8 +51,7 @@ typedef std::vector<yaml_event_t> YamlEventVector; class YamlParserException : public std::runtime_error { public: - YamlParserException(const std::string& str="") : - std::runtime_error("YamlParserException occured: " + str) {} + YamlParserException(const char *err) : std::runtime_error(err) {} }; @@ -60,7 +59,7 @@ class YamlParser { public: - YamlParser(const char *file); + YamlParser(FILE *fd); ~YamlParser(); @@ -107,11 +106,6 @@ class YamlParser { void mainNativeDataMapping(MappingNode *map); - /** - * Configuration file name - */ - std::string filename_; - /** * Configuration file descriptor */ diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 41d68417d3973ee4ce2ac461c051d1c288f51916..dd7c970978fefbb70a7ad0510ef138cd4741bd3b 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -103,26 +103,20 @@ void ManagerImpl::init(const std::string &config_file) DEBUG("Configuration file path: %s", path_.c_str()); try { - std::fstream testFileExistence(path_.c_str(), std::fstream::in); - bool fileExist = testFileExistence.good(); - testFileExistence.close(); + FILE *file = fopen(path_.c_str(), "rb"); - if(fileExist) { - Conf::YamlParser parser(path_.c_str()); + if (file) { + Conf::YamlParser parser(file); parser.serializeEvents(); parser.composeEvents(); parser.constructNativeData(); loadAccountMap(parser); - } - else { + fclose(file); + } else { WARN("Config file not found: creating default account map"); loadDefaultAccountMap(); } - } - catch (const Conf::YamlParserException &e) { - ERROR("%s", e.what()); - } - catch(std::fstream::failure &e) { + } catch (const Conf::YamlParserException &e) { ERROR("%s", e.what()); } diff --git a/daemon/test/configurationtest.cpp b/daemon/test/configurationtest.cpp index 59136e9117bc47c0b370e64790313e543f4bafed..fc05dcd4b13aa41ea633ebafcbec2c924b3ef85f 100644 --- a/daemon/test/configurationtest.cpp +++ b/daemon/test/configurationtest.cpp @@ -91,10 +91,13 @@ void ConfigurationTest::testInitAudioDriver() void ConfigurationTest::testYamlParser() { try { - Conf::YamlParser parser("ymlParser.yml"); + FILE *file = fopen("ymlParser.yml", "rb"); + Conf::YamlParser parser(file); parser.serializeEvents(); parser.composeEvents(); parser.constructNativeData(); + if (file) + fclose(file); } catch (const Conf::YamlParserException &e) { ERROR("ConfigTree: %s", e.what()); }