changed client_body_limit (now in KB)

+ multiples little adjusts
This commit is contained in:
lperrey
2022-08-15 02:14:27 +02:00
parent 9ac84f706d
commit a284e400c1
12 changed files with 48 additions and 127 deletions

View File

@@ -1,25 +1,26 @@
#include "ConfigParser.hpp"
// Default
ConfigParser::ConfigParser()
ConfigParser::ConfigParser() {};
ConfigParser::~ConfigParser() {};
ConfigParser::ConfigParser(const std::string &config_file)
{
std::cout << "Default Constructor\n";
// don't use yet, you have no idea what the defaults are
read_config(config_file);
}
ConfigParser::ConfigParser(const char* path)
void ConfigParser::read_config(const std::string &config_file)
{
// std::cout << "Param Constructor\n";
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);
@@ -37,28 +38,9 @@ ConfigParser::ConfigParser(const char* path)
_content.append(tmp + '\n');
}
}
file.close();
}
else
throw std::invalid_argument("failed to open config");
}
ConfigParser::~ConfigParser()
{
// do i need to destroy anything, won't it handle itself?
}
/*
ConfigParser & ConfigParser::operator=(const ConfigParser& rhs)
{
if (this == rhs) // * & ?
return (*this); // * ?
// make some stuff equal
return (*this);
}
*/
// const?
std::vector<ServerConfig> * ConfigParser::parse()
{
@@ -190,7 +172,7 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
server->server_name.push_back(tmp_val[0]);
}
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)
{
@@ -231,6 +213,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")
{