#pragma once #include #include #include #include #include namespace fs = std::filesystem; enum PathType { Files, // serve files Plugin // delegate to plugin }; struct Path { std::string requested; // the requested path PathType type; std::unordered_map params; // what to serve, e.g. which filesystem path, or which plugin }; struct Site { std::string name; std::unordered_set hosts; std::vector paths; fs::path cert_path; fs::path key_path; }; enum class SocketProtocol { HTTP, HTTPS }; struct Socket { std::string address; std::string port; SocketProtocol protocol; std::vector serve_sites; // if empty, automatically expand to all configured sites }; class Config { const std::string default_filename{"/etc/webserver.conf"}; void readConfigfile(std::string filename); std::string m_user; std::string m_group; int m_threads; std::vector m_plugin_directories; std::vector m_sites; std::vector m_sockets; public: Config(const std::string& filename); // Data getters std::string User() const; std::string Group() const; int Threads() const; const std::vector& PluginDirectories() const; const std::vector& Sites() const; const std::vector& Sockets() const; // // secondary calculation functions // /// param[in] requested_host e.g. www.domain.com:8080 or www.domain.com std::string DocRoot(const Socket& socket, const std::string& requested_host, const std::string& requested_path) const; std::string GetPlugin(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; };