From cbfc28a946ded64e9402e1e6d32511150339ec72 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 4 Apr 2020 20:09:04 +0200 Subject: Prepare DocRoot(), WIP --- config.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'config.cpp') diff --git a/config.cpp b/config.cpp index c478265..4e33dfc 100644 --- a/config.cpp +++ b/config.cpp @@ -1,5 +1,6 @@ #include "config.h" +#include #include #include @@ -181,3 +182,30 @@ void Config::dump() const std::cout << "=============================================" << std::endl; } +std::string Config::DocRoot(const Socket& socket, const std::string& requested_host, const std::string& requested_path) +{ + // TODO: speed this up + std::string host{requested_host}; + + auto pos {host.find(':')}; + if (pos != host.npos) { + host = host.substr(0, pos); + } + + for (const auto& site: m_sites) { + if (std::find(socket.serve_sites.begin(), socket.serve_sites.end(), site.name) != socket.serve_sites.end()) { + for (const auto& m_host: site.hosts) { + if (m_host == host) { + for (const auto& path: site.paths) { + if (boost::starts_with(requested_path, path.requested)) { + return path.params.at("target"); + } + } + } + } + } + } + + return ""; +} + -- cgit v1.2.3