From f116c9146e53d885840ed957204d60d81fd858bd Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 26 Nov 2022 09:12:23 +0100 Subject: Read and use config file --- config.cpp | 25 +++++++++++++++++++++++-- debian/whiteboard.conf | 3 +++ debian/whiteboard.install | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 debian/whiteboard.conf create mode 100644 debian/whiteboard.install diff --git a/config.cpp b/config.cpp index a3fcf3c..6e2e2b6 100644 --- a/config.cpp +++ b/config.cpp @@ -1,8 +1,29 @@ #include "config.h" -Config::Config(): m_dataPath{"/var/lib/whiteboard"} +#include +#include + +#include + +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("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() diff --git a/debian/whiteboard.conf b/debian/whiteboard.conf new file mode 100644 index 0000000..91a868a --- /dev/null +++ b/debian/whiteboard.conf @@ -0,0 +1,3 @@ + + /var/lib/whiteboard + diff --git a/debian/whiteboard.install b/debian/whiteboard.install new file mode 100644 index 0000000..fa446b2 --- /dev/null +++ b/debian/whiteboard.install @@ -0,0 +1 @@ +debian/whiteboard.conf etc -- cgit v1.2.3