diff options
Diffstat (limited to 'config.cpp')
-rw-r--r-- | config.cpp | 57 |
1 files changed, 45 insertions, 12 deletions
@@ -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; |