From 0d157fb407a35f8afe6d6f0f4c2cc5cd5d5a1933 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Thu, 9 Apr 2020 18:30:32 +0200 Subject: Prepared generate_page for static-files plugin --- config.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'config.cpp') diff --git a/config.cpp b/config.cpp index 0d1eb34..9468e39 100644 --- a/config.cpp +++ b/config.cpp @@ -215,6 +215,36 @@ std::string Config::DocRoot(const Socket& socket, const std::string& requested_h return result; } +std::string Config::GetPlugin(const Socket& socket, const std::string& requested_host, const std::string& requested_path) const +{ + // TODO: speed this up + std::string host{requested_host}; + std::string result; + + 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)) { + const auto& root { path.params.at("plugin")}; + if (root.size() > result.size()) + result = root; + } + } + } + } + } + } + + return result; +} + bool Config::PluginIsConfigured(const std::string& name) const { for (const auto& site: m_sites) { -- cgit v1.2.3