#pragma once #include #include #include #include #include // URL path, not FS struct Path { std::string requested; // the requested path // mandatory entries: "plugin", "target", others are optional std::unordered_map params; // what to serve, e.g. which filesystem path (target), and which plugin std::unordered_map auth; // optional }; struct Site { // std::string name; is the index in the m_sites map std::unordered_set hosts; std::vector paths; std::filesystem::path cert_path; std::filesystem::path key_path; }; enum class SocketProtocol { HTTP, HTTPS }; struct Socket { std::string address; std::string port; SocketProtocol protocol; std::unordered_set serve_sites; // if empty, automatically expand to all configured sites std::unordered_map host_lut; // look up table for fast server decision in GetPath() }; class Config { const std::filesystem::path default_filename{"/etc/webserver.conf"}; void readConfigfile(const std::filesystem::path& filename); void expand_socket_sites(); void validate(); void create_look_up_table(); std::string m_user; std::string m_group; int m_threads; std::filesystem::path m_statistics_path; std::vector m_plugin_directories; std::unordered_map m_sites; std::vector m_sockets; public: Config(const std::filesystem::path& filename); // Data getters std::string User() const; std::string Group() const; int Threads() const; std::filesystem::path statistics_path() const; const std::vector& PluginDirectories() const; const std::unordered_map& Sites() const; const std::vector& Sockets() const; // // secondary calculation functions // const Path& GetPath(const Socket& socket, const std::string& requested_host, const std::string& requested_path) const; // return true iff plugin "name" is mentioned in config bool PluginIsConfigured(const std::string& name) const; void dump() const; };