clean comment and stuff
This commit is contained in:
@@ -41,8 +41,7 @@ void ConfigParser::read_config(const std::string &config_file)
|
||||
}
|
||||
}
|
||||
|
||||
// const?
|
||||
std::vector<ServerConfig> * ConfigParser::parse()
|
||||
std::vector<ServerConfig> * ConfigParser::parse() const
|
||||
{
|
||||
std::vector<ServerConfig> * ret = new std::vector<ServerConfig>();
|
||||
|
||||
@@ -67,7 +66,7 @@ std::vector<ServerConfig> * ConfigParser::parse()
|
||||
return (ret);
|
||||
}
|
||||
|
||||
ServerConfig ConfigParser::_parse_server(size_t *start)
|
||||
ServerConfig ConfigParser::_parse_server(size_t *start) const
|
||||
{
|
||||
ServerConfig ret;
|
||||
size_t curr = _content.find_first_not_of(" \t\n", *start);
|
||||
@@ -78,7 +77,6 @@ ServerConfig ConfigParser::_parse_server(size_t *start)
|
||||
|
||||
if ((curr = _content.find_first_of(" \t\n", curr + 1)) == NPOS)
|
||||
throw std::invalid_argument("bad config file syntax");
|
||||
// are there other things to check for?
|
||||
while (curr != NPOS) // here curr == { + 1
|
||||
{
|
||||
// so this moves curr to past the word...
|
||||
@@ -104,7 +102,7 @@ ServerConfig ConfigParser::_parse_server(size_t *start)
|
||||
|
||||
|
||||
|
||||
LocationConfig ConfigParser::_parse_location(size_t *start)
|
||||
LocationConfig ConfigParser::_parse_location(size_t *start) const
|
||||
{
|
||||
LocationConfig ret;
|
||||
size_t curr = *start;
|
||||
@@ -148,11 +146,9 @@ LocationConfig ConfigParser::_parse_location(size_t *start)
|
||||
|
||||
|
||||
|
||||
// should i be sending pointers or references?
|
||||
void ConfigParser::_set_server_values(ServerConfig *server,
|
||||
const std::string key, std::string value)
|
||||
const std::string &key, std::string value) const
|
||||
{
|
||||
// should i be sending pointers or references?
|
||||
value = _pre_set_val_check(key, value);
|
||||
|
||||
std::vector<std::string> tmp_val = ::split(value, ' ');
|
||||
@@ -174,11 +170,11 @@ void ConfigParser::_set_server_values(ServerConfig *server,
|
||||
}
|
||||
}
|
||||
else if (key == "listen" && size == 1 && server->host == ""
|
||||
&& server->port == "") // QUESTION LUKE : C'est quoi cette condition ? Si listen est vide ? Je comprends pas trop.
|
||||
&& server->port == "")
|
||||
{
|
||||
if (tmp_val[0].find_first_of(":") == NPOS)
|
||||
{
|
||||
if (!::isNumeric_btw(0, 65535, tmp_val[0]))
|
||||
if (!::is_numeric_btw(0, 65535, tmp_val[0]))
|
||||
throw std::invalid_argument("bad port number");
|
||||
server->host = "0.0.0.0";
|
||||
server->port = tmp_val[0];
|
||||
@@ -192,10 +188,10 @@ void ConfigParser::_set_server_values(ServerConfig *server,
|
||||
throw std::invalid_argument("bad host ip");
|
||||
for (size_t i = 0; i < ip.size(); i++)
|
||||
{
|
||||
if (!::isNumeric_btw(0, 255, ip[i]))
|
||||
if (!::is_numeric_btw(0, 255, ip[i]))
|
||||
throw std::invalid_argument("bad host ip");
|
||||
}
|
||||
if (!::isNumeric_btw(0, 65535, tmp2[1]))
|
||||
if (!::is_numeric_btw(0, 65535, tmp2[1]))
|
||||
throw std::invalid_argument("bad port number");
|
||||
server->host = tmp2[0];
|
||||
server->port = tmp2[1];
|
||||
@@ -206,13 +202,12 @@ void ConfigParser::_set_server_values(ServerConfig *server,
|
||||
// remove trailing /
|
||||
if (tmp_val[0][tmp_val[0].size() - 1] == '/')
|
||||
tmp_val[0].erase(tmp_val[0].size() - 1, 1);
|
||||
// tmp_val[0].push_back('/');
|
||||
server->root = tmp_val[0];
|
||||
}
|
||||
else if (key == "client_body_limit" && size == 1
|
||||
&& server->client_body_limit == 0)
|
||||
{
|
||||
if (!::isNumeric(tmp_val[0]))
|
||||
if (!::is_numeric(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) )
|
||||
@@ -229,7 +224,7 @@ void ConfigParser::_set_server_values(ServerConfig *server,
|
||||
std::string path = tmp_val[size - 1];
|
||||
for (size_t i = 0; i < size - 1; i++)
|
||||
{
|
||||
if (!(isNumeric_btw(400, 599, tmp_val[i])))
|
||||
if (!(is_numeric_btw(400, 599, tmp_val[i])))
|
||||
throw std::invalid_argument("invalid error code");
|
||||
int status_code = std::strtoul(tmp_val[i].c_str(), NULL, 10);
|
||||
if (server->error_pages.find(status_code) != server->error_pages.end())
|
||||
@@ -242,11 +237,9 @@ void ConfigParser::_set_server_values(ServerConfig *server,
|
||||
}
|
||||
|
||||
|
||||
// should i be sending pointers or references?
|
||||
void ConfigParser::_set_location_values(LocationConfig *location,
|
||||
const std::string key, std::string value)
|
||||
const std::string &key, std::string value) const
|
||||
{
|
||||
// should i be sending pointers or references?
|
||||
value = _pre_set_val_check(key, value);
|
||||
|
||||
std::vector<std::string> tmp_val = ::split(value, ' ');
|
||||
@@ -259,7 +252,6 @@ void ConfigParser::_set_location_values(LocationConfig *location,
|
||||
// remove trailing /
|
||||
if (tmp_val[0][tmp_val[0].size() - 1] == '/')
|
||||
tmp_val[0].erase(tmp_val[0].size() - 1, 1);
|
||||
// tmp_val[0].push_back('/');
|
||||
location->root = tmp_val[0];
|
||||
}
|
||||
else if (key == "autoindex" && size == 1)
|
||||
@@ -306,7 +298,6 @@ void ConfigParser::_set_location_values(LocationConfig *location,
|
||||
}
|
||||
else if (key == "upload_dir" && size == 1 && location->upload_dir == "")
|
||||
{
|
||||
// what checks to do?
|
||||
// add trailing /
|
||||
if (tmp_val[0][tmp_val[0].size() - 1] != '/')
|
||||
tmp_val[0].push_back('/');
|
||||
|
||||
Reference in New Issue
Block a user