From f2f3b1957aa71c60e2af61e4e7547a8181eb2712 Mon Sep 17 00:00:00 2001 From: Talyx Date: Sun, 23 Jan 2022 14:20:08 +0300 Subject: [PATCH] ServerConfig class --- includes/ServerConfig.hpp | 59 ++++++++++++++++++++++ includes/Socket.hpp | 4 +- includes/webserv.hpp | 1 + src/ServerConfig.cpp | 100 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 includes/ServerConfig.hpp create mode 100644 src/ServerConfig.cpp diff --git a/includes/ServerConfig.hpp b/includes/ServerConfig.hpp new file mode 100644 index 0000000..bf5eedb --- /dev/null +++ b/includes/ServerConfig.hpp @@ -0,0 +1,59 @@ +#ifndef SERVERCONFIG_HPP +#define SERVERCONFIG_HPP + +#include "webserv.hpp" + +struct location +{ + std::string location; + std::string root; + std::string directoryFile; + std::string uploadDir; + bool autoindex; + bool uploadAccept; + std::vector methods; + std::map redirect; +}; + +class ServerConfig +{ +private: + // TOMLMap *_root; + std::string _serverName; + std::string _host; + int _port; + int _clientBodySize; + + std::map _errorPages; + std::vector _locations; + +public: + void setServerName(std::string); + void setHost(std::string); + void setPort(int); + void setClientBodySize(int); + void setErrorPages(std::map); + void setLocations(std::vector); + // void setRoot(TOMLMap *); + + std::string getServerName(void); + std::string getHost(void); + int getPort(void); + int getClientBodySize(void); + std::vector getLocations(void); + std::map getErrorPages(void); + // TOMLMap *getRoot(void); + +public: + ServerConfig(); + // ServerConfig(TOMLMap *root); + + void fillFields(void); + + ~ServerConfig(); +}; + + + + +#endif \ No newline at end of file diff --git a/includes/Socket.hpp b/includes/Socket.hpp index 7fd4187..421abf7 100644 --- a/includes/Socket.hpp +++ b/includes/Socket.hpp @@ -1,5 +1,5 @@ -#ifndef SOCKET -#define SOCKET +#ifndef SOCKET_HPP +#define SOCKET_HPP #include "webserv.hpp" class Socket diff --git a/includes/webserv.hpp b/includes/webserv.hpp index 47b9403..f2b0f2e 100644 --- a/includes/webserv.hpp +++ b/includes/webserv.hpp @@ -37,6 +37,7 @@ #include "Socket.hpp" #include "HeaderHandl.hpp" +#include "ServerConfig.hpp" #include "Autoindex.hpp" #include "Server.hpp" #include "Header.hpp" diff --git a/src/ServerConfig.cpp b/src/ServerConfig.cpp new file mode 100644 index 0000000..9661161 --- /dev/null +++ b/src/ServerConfig.cpp @@ -0,0 +1,100 @@ +#include "ServerConfig.hpp" + +ServerConfig::ServerConfig() +{ +} + +// ServerConfig::ServerConfig(TOMLMap *map) +// { +// _root = map; +// } + +//--------------------------------------------------GET/SET--------------------------------------- +std::string ServerConfig::getServerName(void) +{ + return (_serverName); +} + +std::string ServerConfig::getHost(void) +{ + return (_host); +} + +int ServerConfig::getPort(void) +{ + return (_port); +} + +int ServerConfig::getClientBodySize(void) +{ + return (_clientBodySize); +} + +std::vector ServerConfig::getLocations(void) +{ + return (_locations); +} + +std::map ServerConfig::getErrorPages(void) +{ + return (_errorPages); +} + +// TOMLMap ServerConfig::*getRoot(void) +// { +// return (this->_root); +// } + +void ServerConfig::setServerName(std::string name) +{ + _serverName = name; +} + +void ServerConfig::setHost(std::string host) +{ + _host = host; +} + +void ServerConfig::setPort(int port) +{ + _port = port; +} + +void ServerConfig::setClientBodySize(int body) +{ + _clientBodySize = body; +} + +void ServerConfig::setErrorPages(std::map pages) +{ + _errorPages = pages; +} + +void ServerConfig::setLocations(std::vector locations) +{ + _locations = locations; +} + +// void ServerConfig::setRoot(TOMLMap * data) +// { +// _root = data; +// } + + +void ServerConfig::fillFields(void) +{ + // TOMLMap *tmp = _root; + // TOMLMap::iterator it; + + // it = tmp->begin(); + + // while (it != tmp->end()) + // { + // std::cout << it->first << std::endl; + // } + +} + +ServerConfig::~ServerConfig() +{ +} \ No newline at end of file