summaryrefslogtreecommitdiffhomepage
path: root/config.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-21 19:05:43 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-21 19:05:43 +0100
commitc464265f60ddd367786b08f5d49cd7a6d650b7d6 (patch)
treed2c747cc041a92d38ac1d25eb47fc7e398d5af7b /config.cpp
parent3d0592e9238a59df54b3e3b757a38fa2e7f0ccfb (diff)
First websocket connection
Diffstat (limited to 'config.cpp')
-rw-r--r--config.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/config.cpp b/config.cpp
index 4488e84..d59156f 100644
--- a/config.cpp
+++ b/config.cpp
@@ -4,15 +4,24 @@
#include <boost/property_tree/xml_parser.hpp>
#include <iostream>
+#include <string>
namespace pt = boost::property_tree;
+using namespace std::string_literals;
namespace {
const std::string default_datapath {"/var/lib/whiteboard"};
const uint64_t default_maxage{0}; // timeout in seconds; 0 = no timeout
+ const std::string default_listen {"::1:9000"};
+ const int default_threads{1};
}
-Config::Config(const std::string& config_filename): m_dataPath{default_datapath}, m_maxage{default_maxage}
+Config::Config(const std::string& config_filename):
+ m_dataPath{default_datapath},
+ m_maxage{default_maxage},
+ m_listenAddress{"::1"},
+ m_listenPort{9000},
+ m_threads{default_threads}
{
try {
@@ -22,6 +31,17 @@ Config::Config(const std::string& config_filename): m_dataPath{default_datapath}
m_dataPath = tree.get<std::string>("config.datapath", default_datapath);
m_maxage = tree.get<uint64_t>("config.maxage", default_maxage);
+ std::string listen {tree.get<std::string>("config.port", default_listen)};
+ auto pos{listen.find_last_of(':')};
+ if (pos == std::string::npos)
+ throw std::runtime_error("Bad port address: "s + listen);
+
+ m_listenAddress = listen.substr(0, pos);
+ m_listenPort = std::stoi(listen.substr(pos + 1));
+ if (m_listenPort < 0 || m_listenPort > 65535)
+ throw std::runtime_error("Bad listen port: "s + std::to_string(m_listenPort));
+
+ m_threads = tree.get<int>("config.threads", default_threads);
} catch (const std::exception& ex) {
std::cerr << "Error reading config file " << config_filename << ". Using defaults." << std::endl;
}
@@ -36,3 +56,18 @@ uint64_t Config::getMaxage() const
{
return m_maxage;
}
+
+std::string Config::getListenAddress() const
+{
+ return m_listenAddress;
+}
+
+int Config::getListenPort() const
+{
+ return m_listenPort;
+}
+
+int Config::getThreads() const
+{
+ return m_threads;
+}