/*********************************/ /* */ /* o.riabenkyi@gmail.com */ /* */ /*********************************/ #ifndef SERVERCONFIG_HPP #define SERVERCONFIG_HPP #include #include #include #include #include #include "LocationConfig.hpp" // One "server { ... }" block: everything needed to run a single virtual server. class ServerConfig { public: struct Listen { std::string host; int port; }; ServerConfig(); void addListen(const std::string &host, int port); void addServerName(const std::string &name); void setRoot(const std::string &root); void setClientMaxBodySize(size_t size); void addErrorPage(int code, const std::string &path); void addLocation(const LocationConfig &location); const std::vector &getListens() const; const std::vector &getServerNames() const; const std::optional &getRoot() const; size_t getClientMaxBodySize() const; const std::map &getErrorPages() const; const std::vector &getLocations() const; // Returns the location's own root if set, otherwise this server's root. // Only meaningful once validate() has confirmed one of the two exists. const std::string &resolveRoot(const LocationConfig &location) const; // Throws std::runtime_error with a descriptive message when invalid. void validate() const; private: std::vector _listens; std::vector _serverNames; std::optional _root; size_t _clientMaxBodySize; std::map _errorPages; std::vector _locations; }; #endif