mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
TOMLMap parser start
This commit is contained in:
@@ -21,7 +21,7 @@ void Server::readConfig(void)
|
||||
TOMLMap *root = parse();
|
||||
|
||||
|
||||
TOMLMap *map;
|
||||
// TOMLMap *map;
|
||||
TOMLMap::iterator it1;
|
||||
TOMLMapArray *arr;
|
||||
TOMLMapArray::iterator it;
|
||||
@@ -32,17 +32,8 @@ void Server::readConfig(void)
|
||||
|
||||
while (it != arr->end())
|
||||
{
|
||||
std::cout << BLUE << *it << std::endl;
|
||||
map = *it;
|
||||
|
||||
it1 = map->begin();
|
||||
while (it1 != map->end())
|
||||
{
|
||||
std::cout << TURGUOISE << it1->first << it1->second << ZERO_C << std::endl;
|
||||
++it1;
|
||||
}
|
||||
|
||||
|
||||
_configs.push_back(new ServerConfig(*it));
|
||||
std::cout << "biba\n";
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ private:
|
||||
struct epoll_event _events[MAX_CLIENT];
|
||||
struct sockaddr_in _addres;
|
||||
std::string _ip;
|
||||
std::vector<ServerConfig> _configs;
|
||||
std::vector<ServerConfig *> _configs;
|
||||
|
||||
private:
|
||||
void checkError(int fd, std::string str);
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
ServerConfig::ServerConfig()
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
// ServerConfig::ServerConfig(TOMLMap *map)
|
||||
// {
|
||||
// _root = map;
|
||||
// }
|
||||
ServerConfig::ServerConfig(TOMLMap *map)
|
||||
{
|
||||
ret = 0;
|
||||
server = map;
|
||||
fillFields();
|
||||
}
|
||||
|
||||
//--------------------------------------------------GET/SET---------------------------------------
|
||||
std::string ServerConfig::getServerName(void)
|
||||
@@ -40,10 +43,10 @@ std::map<int, std::string> ServerConfig::getErrorPages(void)
|
||||
return (_errorPages);
|
||||
}
|
||||
|
||||
// TOMLMap ServerConfig::*getRoot(void)
|
||||
// {
|
||||
// return (this->_root);
|
||||
// }
|
||||
TOMLMap *ServerConfig::getRoot(void)
|
||||
{
|
||||
return (server);
|
||||
}
|
||||
|
||||
void ServerConfig::setServerName(std::string name)
|
||||
{
|
||||
@@ -75,24 +78,75 @@ void ServerConfig::setLocations(std::vector<location> locations)
|
||||
_locations = locations;
|
||||
}
|
||||
|
||||
// void ServerConfig::setRoot(TOMLMap * data)
|
||||
// {
|
||||
// _root = data;
|
||||
// }
|
||||
void ServerConfig::setRoot(TOMLMap * data)
|
||||
{
|
||||
server = data;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------Parse-Config---------------------------------------
|
||||
|
||||
int ServerConfig::putBodySizeLimit(toml_node *node)
|
||||
{
|
||||
std::cout << TURGUOISE << node << ZERO_C << std::endl;
|
||||
return (0);
|
||||
}
|
||||
int ServerConfig::putErrorPage(toml_node *node)
|
||||
{
|
||||
std::cout << TURGUOISE << node << ZERO_C << std::endl;
|
||||
return (0);
|
||||
}
|
||||
int ServerConfig::putHost(toml_node *node)
|
||||
{
|
||||
std::cout << TURGUOISE << node << ZERO_C << std::endl;
|
||||
return (0);
|
||||
}
|
||||
int ServerConfig::putName(toml_node *node)
|
||||
{
|
||||
std::cout << TURGUOISE << node << ZERO_C << std::endl;
|
||||
return (0);
|
||||
}
|
||||
int ServerConfig::putPort(toml_node *node)
|
||||
{
|
||||
std::cout << TURGUOISE << node << ZERO_C << std::endl;
|
||||
return (0);
|
||||
}
|
||||
int ServerConfig::putLocation(toml_node *node)
|
||||
{
|
||||
std::cout << TURGUOISE << node << ZERO_C << std::endl;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ServerConfig::identify(TOMLMap::iterator it)
|
||||
{
|
||||
if (it->first == "body_size_limit")
|
||||
putBodySizeLimit(it->second);
|
||||
else if (it->first == "error_page")
|
||||
putErrorPage(it->second);
|
||||
else if (it->first == "host")
|
||||
putHost(it->second);
|
||||
else if (it->first == "loacation")
|
||||
putLocation(it->second);
|
||||
else if (it->first == "name")
|
||||
putName(it->second);
|
||||
else if (it->first == "port")
|
||||
putPort(it->second);
|
||||
else
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ServerConfig::fillFields(void)
|
||||
{
|
||||
// TOMLMap *tmp = _root;
|
||||
// TOMLMap::iterator it;
|
||||
|
||||
// it = tmp->begin();
|
||||
TOMLMap::iterator block;
|
||||
|
||||
// while (it != tmp->end())
|
||||
// {
|
||||
// std::cout << it->first << std::endl;
|
||||
// }
|
||||
|
||||
block = server->begin();
|
||||
while (block != server->end() && ret == 0)
|
||||
{
|
||||
ret = identify(block);
|
||||
++block;
|
||||
}
|
||||
}
|
||||
|
||||
ServerConfig::~ServerConfig()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SERVERCONFIG_HPP
|
||||
|
||||
#include "webserv.hpp"
|
||||
#include "parse.hpp"
|
||||
|
||||
struct location
|
||||
{
|
||||
@@ -17,8 +18,10 @@ struct location
|
||||
|
||||
class ServerConfig
|
||||
{
|
||||
public:
|
||||
int ret;
|
||||
private:
|
||||
// TOMLMap *_root;
|
||||
TOMLMap *server;
|
||||
std::string _serverName;
|
||||
std::string _host;
|
||||
int _port;
|
||||
@@ -34,7 +37,7 @@ public:
|
||||
void setClientBodySize(int);
|
||||
void setErrorPages(std::map<int, std::string>);
|
||||
void setLocations(std::vector<location>);
|
||||
// void setRoot(TOMLMap *);
|
||||
void setRoot(TOMLMap *);
|
||||
|
||||
std::string getServerName(void);
|
||||
std::string getHost(void);
|
||||
@@ -42,12 +45,21 @@ public:
|
||||
int getClientBodySize(void);
|
||||
std::vector<location> getLocations(void);
|
||||
std::map<int, std::string> getErrorPages(void);
|
||||
// TOMLMap *getRoot(void);
|
||||
TOMLMap *getRoot(void);
|
||||
|
||||
public:
|
||||
ServerConfig();
|
||||
// ServerConfig(TOMLMap *root);
|
||||
|
||||
ServerConfig(TOMLMap *root);
|
||||
private:
|
||||
int identify(TOMLMap::iterator it);
|
||||
int putBodySizeLimit(toml_node *);
|
||||
int putErrorPage(toml_node *);
|
||||
int putHost(toml_node *);
|
||||
int putName(toml_node *);
|
||||
int putPort(toml_node *);
|
||||
int putLocation(toml_node *);
|
||||
|
||||
public:
|
||||
void fillFields(void);
|
||||
|
||||
~ServerConfig();
|
||||
|
||||
Reference in New Issue
Block a user