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 *root = parse();
|
||||||
|
|
||||||
|
|
||||||
TOMLMap *map;
|
// TOMLMap *map;
|
||||||
TOMLMap::iterator it1;
|
TOMLMap::iterator it1;
|
||||||
TOMLMapArray *arr;
|
TOMLMapArray *arr;
|
||||||
TOMLMapArray::iterator it;
|
TOMLMapArray::iterator it;
|
||||||
@@ -32,17 +32,8 @@ void Server::readConfig(void)
|
|||||||
|
|
||||||
while (it != arr->end())
|
while (it != arr->end())
|
||||||
{
|
{
|
||||||
std::cout << BLUE << *it << std::endl;
|
_configs.push_back(new ServerConfig(*it));
|
||||||
map = *it;
|
std::cout << "biba\n";
|
||||||
|
|
||||||
it1 = map->begin();
|
|
||||||
while (it1 != map->end())
|
|
||||||
{
|
|
||||||
std::cout << TURGUOISE << it1->first << it1->second << ZERO_C << std::endl;
|
|
||||||
++it1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ private:
|
|||||||
struct epoll_event _events[MAX_CLIENT];
|
struct epoll_event _events[MAX_CLIENT];
|
||||||
struct sockaddr_in _addres;
|
struct sockaddr_in _addres;
|
||||||
std::string _ip;
|
std::string _ip;
|
||||||
std::vector<ServerConfig> _configs;
|
std::vector<ServerConfig *> _configs;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkError(int fd, std::string str);
|
void checkError(int fd, std::string str);
|
||||||
|
|||||||
@@ -2,12 +2,15 @@
|
|||||||
|
|
||||||
ServerConfig::ServerConfig()
|
ServerConfig::ServerConfig()
|
||||||
{
|
{
|
||||||
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerConfig::ServerConfig(TOMLMap *map)
|
ServerConfig::ServerConfig(TOMLMap *map)
|
||||||
// {
|
{
|
||||||
// _root = map;
|
ret = 0;
|
||||||
// }
|
server = map;
|
||||||
|
fillFields();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------GET/SET---------------------------------------
|
//--------------------------------------------------GET/SET---------------------------------------
|
||||||
std::string ServerConfig::getServerName(void)
|
std::string ServerConfig::getServerName(void)
|
||||||
@@ -40,10 +43,10 @@ std::map<int, std::string> ServerConfig::getErrorPages(void)
|
|||||||
return (_errorPages);
|
return (_errorPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOMLMap ServerConfig::*getRoot(void)
|
TOMLMap *ServerConfig::getRoot(void)
|
||||||
// {
|
{
|
||||||
// return (this->_root);
|
return (server);
|
||||||
// }
|
}
|
||||||
|
|
||||||
void ServerConfig::setServerName(std::string name)
|
void ServerConfig::setServerName(std::string name)
|
||||||
{
|
{
|
||||||
@@ -75,24 +78,75 @@ void ServerConfig::setLocations(std::vector<location> locations)
|
|||||||
_locations = locations;
|
_locations = locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void ServerConfig::setRoot(TOMLMap * data)
|
void ServerConfig::setRoot(TOMLMap * data)
|
||||||
// {
|
{
|
||||||
// _root = 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)
|
void ServerConfig::fillFields(void)
|
||||||
{
|
{
|
||||||
// TOMLMap *tmp = _root;
|
|
||||||
// TOMLMap::iterator it;
|
|
||||||
|
|
||||||
// it = tmp->begin();
|
TOMLMap::iterator block;
|
||||||
|
|
||||||
// while (it != tmp->end())
|
block = server->begin();
|
||||||
// {
|
while (block != server->end() && ret == 0)
|
||||||
// std::cout << it->first << std::endl;
|
{
|
||||||
// }
|
ret = identify(block);
|
||||||
|
++block;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerConfig::~ServerConfig()
|
ServerConfig::~ServerConfig()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define SERVERCONFIG_HPP
|
#define SERVERCONFIG_HPP
|
||||||
|
|
||||||
#include "webserv.hpp"
|
#include "webserv.hpp"
|
||||||
|
#include "parse.hpp"
|
||||||
|
|
||||||
struct location
|
struct location
|
||||||
{
|
{
|
||||||
@@ -17,8 +18,10 @@ struct location
|
|||||||
|
|
||||||
class ServerConfig
|
class ServerConfig
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
int ret;
|
||||||
private:
|
private:
|
||||||
// TOMLMap *_root;
|
TOMLMap *server;
|
||||||
std::string _serverName;
|
std::string _serverName;
|
||||||
std::string _host;
|
std::string _host;
|
||||||
int _port;
|
int _port;
|
||||||
@@ -34,7 +37,7 @@ public:
|
|||||||
void setClientBodySize(int);
|
void setClientBodySize(int);
|
||||||
void setErrorPages(std::map<int, std::string>);
|
void setErrorPages(std::map<int, std::string>);
|
||||||
void setLocations(std::vector<location>);
|
void setLocations(std::vector<location>);
|
||||||
// void setRoot(TOMLMap *);
|
void setRoot(TOMLMap *);
|
||||||
|
|
||||||
std::string getServerName(void);
|
std::string getServerName(void);
|
||||||
std::string getHost(void);
|
std::string getHost(void);
|
||||||
@@ -42,12 +45,21 @@ public:
|
|||||||
int getClientBodySize(void);
|
int getClientBodySize(void);
|
||||||
std::vector<location> getLocations(void);
|
std::vector<location> getLocations(void);
|
||||||
std::map<int, std::string> getErrorPages(void);
|
std::map<int, std::string> getErrorPages(void);
|
||||||
// TOMLMap *getRoot(void);
|
TOMLMap *getRoot(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ServerConfig();
|
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);
|
void fillFields(void);
|
||||||
|
|
||||||
~ServerConfig();
|
~ServerConfig();
|
||||||
|
|||||||
Reference in New Issue
Block a user