some cleanup of config stuff
This commit is contained in:
@@ -31,8 +31,6 @@ ConfigParser::ConfigParser(const char* path)
|
||||
file.open(path);
|
||||
if (file.is_open())
|
||||
{
|
||||
// are there more throws i need to add in case of errors, what would
|
||||
// those errors be?
|
||||
while (!file.eof())
|
||||
{
|
||||
getline(file, buf);
|
||||
@@ -45,7 +43,7 @@ ConfigParser::ConfigParser(const char* path)
|
||||
}
|
||||
else if (comment > 0 && (buf.find_first_not_of(" \t")) < comment)
|
||||
{
|
||||
// is there a comment at the end of the line
|
||||
// check for comment at the end of the line
|
||||
std::string tmp = buf.substr(0, comment - 1);
|
||||
_content.append(tmp + '\n');
|
||||
}
|
||||
@@ -53,7 +51,7 @@ ConfigParser::ConfigParser(const char* path)
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
throw std::invalid_argument("open config");
|
||||
throw std::invalid_argument("failed to open config");
|
||||
}
|
||||
|
||||
ConfigParser::~ConfigParser()
|
||||
@@ -147,8 +145,11 @@ LocationConfig ConfigParser::_parse_location(size_t *start)
|
||||
ret.allow_methods = 0;
|
||||
|
||||
ret.path = _get_first_word(&curr);
|
||||
// if (ret.path[0] != '/')
|
||||
if (ret.path[0] != '/')
|
||||
ret.path.insert(0, "/");
|
||||
// throw std::invalid_argument("Location path require a leading /");
|
||||
if (ret.path.back() != '/')
|
||||
ret.path.push_back('/');
|
||||
// in theory now curr should be right after the "path"
|
||||
|
||||
curr = _content.find_first_not_of(" \t\n", curr);
|
||||
@@ -235,6 +236,10 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
|
||||
// if (tmp_val[0][0] != '/')
|
||||
// throw std::invalid_argument("Root requires leading /");
|
||||
|
||||
// remove trailing /
|
||||
if (tmp_val[0].back() == '/')
|
||||
tmp_val[0].erase(tmp_val[0].size(), 1);
|
||||
|
||||
// std::cout << "root: " << tmp_val[0] << '\n';
|
||||
//might not even do these checks here...
|
||||
// if (path_is_valid(tmp_val[0]) == 1)
|
||||
@@ -307,6 +312,9 @@ void ConfigParser::_set_location_values(LocationConfig *location, \
|
||||
// if (tmp_val[0][0] != '/')
|
||||
// throw std::invalid_argument("Root requires leading /");
|
||||
|
||||
// remove trailing /
|
||||
if (tmp_val[0].back() == '/')
|
||||
tmp_val[0].erase(tmp_val[0].size(), 1);
|
||||
// if (path_is_valid(tmp_val[0]) == 1)
|
||||
location->root = tmp_val[0];
|
||||
// else
|
||||
|
||||
@@ -17,21 +17,18 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
|
||||
if (it->root == "")
|
||||
throw std::invalid_argument("Config file needs a root");
|
||||
|
||||
if (it->client_body_limit == 0)
|
||||
it->client_body_limit = 5000; // what is the recomended size?
|
||||
|
||||
|
||||
// index is mandatory in Server
|
||||
if (it->index.empty())
|
||||
throw std::invalid_argument("Config file needs an Index");
|
||||
|
||||
|
||||
if (it->client_body_limit == 0)
|
||||
it->client_body_limit = 5000; // what is the recomended size?
|
||||
|
||||
|
||||
// if error_pages is left empty, we'll use the defaults which
|
||||
// i believe are set elsewhere...
|
||||
|
||||
|
||||
// actually do this at the end, once we know if there aren't any locations
|
||||
// with path /
|
||||
if (!_find_root_path_location(it->locations))
|
||||
{
|
||||
LocationConfig tmp;
|
||||
@@ -55,10 +52,8 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
|
||||
if (it_l->allow_methods == UNKNOWN)
|
||||
it_l->allow_methods = ANY_METHODS;
|
||||
|
||||
// fill out index from Server?
|
||||
// or do a bunch of checks on what is in there...
|
||||
if (it_l->index.empty())
|
||||
it_l->index = it->index; // right?
|
||||
it_l->index = it->index;
|
||||
|
||||
// same for redirect status i think
|
||||
|
||||
@@ -74,11 +69,6 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
|
||||
|
||||
++it_l;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// std::cout << "made it to sorting...\n";
|
||||
// std::sort(it->locations.begin(), it->locations.end(), compareLocationConfigs);
|
||||
std::sort(it->locations.begin(), it->locations.end());
|
||||
std::reverse(it->locations.begin(), it->locations.end());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user