merge, the whole thing is cleaner
This commit is contained in:
@@ -1,23 +1,26 @@
|
||||
|
||||
#include "ConfigParser.hpp"
|
||||
|
||||
// Default
|
||||
// possibly remove...
|
||||
ConfigParser::ConfigParser()
|
||||
ConfigParser::ConfigParser() {};
|
||||
ConfigParser::~ConfigParser() {};
|
||||
|
||||
ConfigParser::ConfigParser(const std::string &config_file)
|
||||
{
|
||||
std::cout << "Default Constructor\n";
|
||||
read_config(config_file);
|
||||
}
|
||||
|
||||
ConfigParser::ConfigParser(const char* path)
|
||||
void ConfigParser::read_config(const std::string &config_file)
|
||||
{
|
||||
std::ifstream file;
|
||||
std::string buf;
|
||||
size_t comment;
|
||||
|
||||
_content.clear();
|
||||
file.open(path);
|
||||
if (file.is_open())
|
||||
file.open(config_file.c_str());
|
||||
if (!file)
|
||||
throw std::invalid_argument("failed to open config");
|
||||
else
|
||||
{
|
||||
_content.clear();
|
||||
while (!file.eof())
|
||||
{
|
||||
getline(file, buf);
|
||||
@@ -35,19 +38,9 @@ ConfigParser::ConfigParser(const char* path)
|
||||
_content.append(tmp + '\n');
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
throw std::invalid_argument("failed to open config");
|
||||
}
|
||||
|
||||
// might not need this...
|
||||
ConfigParser::~ConfigParser()
|
||||
{
|
||||
// do i need to destroy anything, won't it handle itself?
|
||||
}
|
||||
|
||||
|
||||
// const?
|
||||
std::vector<ServerConfig> * ConfigParser::parse()
|
||||
{
|
||||
@@ -156,7 +149,7 @@ LocationConfig ConfigParser::_parse_location(size_t *start)
|
||||
|
||||
|
||||
// should i be sending pointers or references?
|
||||
void ConfigParser::_set_server_values(ServerConfig *server, \
|
||||
void ConfigParser::_set_server_values(ServerConfig *server,
|
||||
const std::string key, std::string value)
|
||||
{
|
||||
// should i be sending pointers or references?
|
||||
@@ -181,7 +174,7 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
|
||||
}
|
||||
}
|
||||
else if (key == "listen" && size == 1 && server->host == ""
|
||||
&& server->port == "")
|
||||
&& server->port == "") // QUESTION LUKE : C'est quoi cette condition ? Si listen est vide ? Je comprends pas trop.
|
||||
{
|
||||
if (tmp_val[0].find_first_of(":") == NPOS)
|
||||
{
|
||||
@@ -222,6 +215,9 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
|
||||
if (!::isNumeric(tmp_val[0]))
|
||||
throw std::invalid_argument("client_body_limit not a number");
|
||||
server->client_body_limit = std::strtoul(tmp_val[0].c_str(), NULL, 10);
|
||||
if (errno == ERANGE || server->client_body_limit > (ULONG_MAX / KB) )
|
||||
throw std::invalid_argument("client_body_limit too big");
|
||||
server->client_body_limit = server->client_body_limit * KB;
|
||||
}
|
||||
else if (key == "index")
|
||||
{
|
||||
@@ -231,7 +227,7 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
|
||||
else if (key == "error_page")
|
||||
{
|
||||
std::string path = tmp_val[size - 1];
|
||||
for (size_t i = 0; i < size() - 1; i++)
|
||||
for (size_t i = 0; i < size - 1; i++)
|
||||
{
|
||||
if (!(isNumeric_btw(400, 599, tmp_val[i])))
|
||||
throw std::invalid_argument("invalid error code");
|
||||
@@ -247,7 +243,7 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
|
||||
|
||||
|
||||
// should i be sending pointers or references?
|
||||
void ConfigParser::_set_location_values(LocationConfig *location, \
|
||||
void ConfigParser::_set_location_values(LocationConfig *location,
|
||||
const std::string key, std::string value)
|
||||
{
|
||||
// should i be sending pointers or references?
|
||||
|
||||
Reference in New Issue
Block a user