diff options
author | Roland Reichwein <mail@reichwein.it> | 2022-11-26 09:12:23 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2022-11-26 09:12:23 +0100 |
commit | f116c9146e53d885840ed957204d60d81fd858bd (patch) | |
tree | 8947c94a4e08360b210c2f4ca707ed902db14c14 /config.cpp | |
parent | 32d1a989683f9a64e70f972d4a3e185a85a2c309 (diff) |
Read and use config file
Diffstat (limited to 'config.cpp')
-rw-r--r-- | config.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -1,8 +1,29 @@ #include "config.h" -Config::Config(): m_dataPath{"/var/lib/whiteboard"} +#include <boost/property_tree/ptree.hpp> +#include <boost/property_tree/xml_parser.hpp> + +#include <iostream> + +namespace pt = boost::property_tree; + +namespace { + const std::string default_datapath {"/var/lib/whiteboard"}; + const std::string config_filename{"/etc/webserver.conf"}; +} + +Config::Config(): m_dataPath{default_datapath} { - // TODO: read /etc/whiteboard.conf xml + + try { + pt::ptree tree; + + pt::read_xml(config_filename, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + + m_dataPath = tree.get<std::string>("whiteboard.datapath", default_datapath); + } catch (const std::exception& ex) { + std::cerr << "Error reading config file " << config_filename << ". Using " << default_datapath << "." << std::endl; + } } std::string Config::getDataPath() |