diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-05-01 13:08:38 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-05-01 13:08:38 +0200 |
commit | c3612be4c3c51ccbe0e4ab27a9d7cf02e0ff3819 (patch) | |
tree | b22058e2031ea3851af4b645993d33577a93f6af | |
parent | b77bb246e366d346b55cc8cfb4f1d0ac83211ae7 (diff) |
Check for double values in config
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | config.cpp | 57 |
2 files changed, 45 insertions, 13 deletions
@@ -5,7 +5,6 @@ Integrate into Debian: WNPP read: The socket was closed due to a timeout webbox: Info if not selected: all webbox: Copy function -config consistency: check double keys new plugin: redirect-plugin new plugin: fcgi support alternative SSL libs: mbedtls, gnutls, wolfssl, botan, (matrixssl, libressl, cryptlib: not in debian) @@ -48,7 +48,10 @@ void Config::readConfigfile(std::string filename) if (elements) { for (const auto& element: *elements) { if (element.first == "plugin-directory"s) { - m_plugin_directories.push_back(element.second.data()); + if (std::find(m_plugin_directories.begin(), m_plugin_directories.end(), element.second.data()) == m_plugin_directories.end()) + m_plugin_directories.push_back(element.second.data()); + else + throw std::runtime_error("Found double plugin-directory element: "s + element.second.data()); } else if (element.first == "sites"s) { for (const auto& site: element.second) { if (site.first != "site"s) @@ -56,9 +59,15 @@ void Config::readConfigfile(std::string filename) Site site_struct; for (const auto& x: site.second) { if (x.first == "name"s) { - site_struct.name = x.second.data(); + if (site_struct.name == "") + site_struct.name = x.second.data(); + else + throw std::runtime_error("Found double site name: "s + x.second.data()); } else if (x.first == "host"s) { - site_struct.hosts.insert(x.second.data()); + if (std::find(site_struct.hosts.begin(), site_struct.hosts.end(), x.second.data()) == site_struct.hosts.end()) + site_struct.hosts.insert(x.second.data()); + else + throw std::runtime_error("Found double site host element: "s + x.second.data()); } else if (x.first == "path"s) { Path path; auto attrs = x.second.get_child("<xmlattr>"); @@ -68,25 +77,43 @@ void Config::readConfigfile(std::string filename) if (param.first == "auth") { try { std::string login{param.second.get<std::string>("<xmlattr>.login")}; - std::string password{param.second.get<std::string>("<xmlattr>.password")}; - path.auth[login] = password; + if (path.auth.find(login) == path.auth.end()) { + std::string password{param.second.get<std::string>("<xmlattr>.password")}; + path.auth[login] = password; + } else + throw std::runtime_error("Found double auth (login): "s + login); } catch (const std::exception& ex) { std::cerr << "Warning: Can't read auth data from config: " << ex.what() << std::endl; } } else { - path.params[param.first] = param.second.data(); + if (path.params.find(param.first) == path.params.end()) + path.params[param.first] = param.second.data(); + else + throw std::runtime_error("Found double path param: "s + param.first + ": " + param.second.data()); } } } - site_struct.paths.push_back(path); + if (std::find_if(site_struct.paths.begin(), site_struct.paths.end(), [&](const Path& p){ return p.requested == path.requested;}) == site_struct.paths.end()) + site_struct.paths.push_back(path); + else + throw std::runtime_error("Found double path spec: "s + path.requested); } else if (x.first == "certpath"s) { - site_struct.cert_path = x.second.data(); + if (site_struct.cert_path == "") + site_struct.cert_path = x.second.data(); + else + throw std::runtime_error("Found double certpath: "s + x.second.data()); } else if (x.first == "keypath"s) { - site_struct.key_path = x.second.data(); + if (site_struct.key_path == "") + site_struct.key_path = x.second.data(); + else + throw std::runtime_error("Found double keypath: "s + x.second.data()); } else throw std::runtime_error("Unknown element: "s + x.first); } - m_sites.push_back(site_struct); + if (std::find_if(m_sites.begin(), m_sites.end(), [&](const Site& site){return site.name == site_struct.name;}) == m_sites.end()) + m_sites.push_back(site_struct); + else + throw std::runtime_error("Found double site spec: "s + site_struct.name); } } else if (element.first == "sockets"s) { for (const auto& socket: element.second) { @@ -95,9 +122,15 @@ void Config::readConfigfile(std::string filename) Socket socket_struct; for (const auto& x: socket.second) { if (x.first == "address"s) { - socket_struct.address = x.second.data(); + if (socket_struct.address == "") + socket_struct.address = x.second.data(); + else + throw std::runtime_error("Found double address spec: "s + x.second.data()); } else if (x.first == "port"s) { - socket_struct.port = x.second.data(); + if (socket_struct.port == "") + socket_struct.port = x.second.data(); + else + throw std::runtime_error("Found double port spec: "s + x.second.data()); } else if (x.first == "protocol"s) { if (x.second.data() == "http"s) socket_struct.protocol = SocketProtocol::HTTP; |