location picker works, needs to be tested more tho

This commit is contained in:
Me
2022-08-10 01:59:10 +02:00
parent 1eb989a3fd
commit 8e90221058
8 changed files with 141 additions and 68 deletions

View File

@@ -145,10 +145,9 @@ LocationConfig ConfigParser::_parse_location(size_t *start)
ret.allow_methods = 0;
ret.path = _get_first_word(&curr);
// are you sure about this?
if (ret.path[0] != '/')
ret.path.insert(0, "/");
// throw std::invalid_argument("Location path require a leading /");
throw std::invalid_argument("Location path require a leading /");
// ret.path.insert(0, "/");
// in theory now curr should be right after the "path"
curr = _content.find_first_not_of(" \t\n", curr);
@@ -158,7 +157,6 @@ LocationConfig ConfigParser::_parse_location(size_t *start)
if ((curr = _content.find_first_of(" \t\n", curr + 1)) == std::string::npos)
throw std::invalid_argument("bad config file syntax");
// are there other things to check for?
while (curr != std::string::npos)
{
// so this moves curr to past the word...
@@ -181,9 +179,11 @@ 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)
{
// should i be sending pointers or references?
value = _pre_set_val_check(key, value);
std::vector<std::string> tmp_val = ::split(value, ' ');
@@ -206,7 +206,6 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
{
if (tmp_val[0].find_first_of(":") == std::string::npos)
{
// should i limit which ports can be used?
if (!::isNumeric(tmp_val[0]))
throw std::invalid_argument("bad port number");
server->host = "0.0.0.0";
@@ -246,31 +245,19 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
}
else if (key == "index")
{
// i think you can call index several times...
for (unsigned long i = 0; i != tmp_val.size(); i++)
server->index.push_back(tmp_val[i]);
}
else if (key == "error_page")
{
// so it can either be just a /here/is/the/repo
// or it can be http://some_domain.com/here
// wtf... how should we handle...
// you can definitely call Error_pages several times, i think
std::string path = tmp_val[tmp_val.size() - 1];
for (unsigned long i = 0; i != tmp_val.size() - 1; i++)
{
// what are the bounds for Error codes?
if (!(isNumeric_btw(0, 600, tmp_val[i])))
throw std::invalid_argument("value not a valid number");
if (!(isNumeric_btw(400, 599, tmp_val[i])))
throw std::invalid_argument("invalid error code");
int status_code = atoi(tmp_val[i].c_str());
// yea cuz here we continue.. why suddenly flexible not throw ?
if (server->error_pages.find(status_code) != server->error_pages.end())
continue ;
throw std::invalid_argument("redeclaring error page");
server->error_pages[status_code] = path;
}
}
@@ -279,9 +266,11 @@ 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)
{
// should i be sending pointers or references?
value = _pre_set_val_check(key, value);
std::vector<std::string> tmp_val = ::split(value, ' ');
@@ -297,14 +286,9 @@ void ConfigParser::_set_location_values(LocationConfig *location, \
location->root = tmp_val[0];
}
else if (key == "autoindex" && size == 1)
{
location->autoindex = (tmp_val[0] == "on" ? true : false);
std::cout << "in parser " << location->path << " autoindex: " << location->autoindex << '\n';
}
else if (key == "index")
{
// what about index /index.html; aka at the root? not handle?
// you can definitely call Index several times, i think
for (unsigned long i = 0; i != tmp_val.size(); i++)
location->index.push_back(tmp_val[i]);
}
@@ -330,28 +314,27 @@ void ConfigParser::_set_location_values(LocationConfig *location, \
else if (key == "redirect" && location->redirect_status == 0 \
&& location->redirect_uri == "")
{
// actually i think there can only be one per location...
// you can definitely call return several times, i think
if (tmp_val.size() != 2)
throw std::invalid_argument("wrong number of values");
// and tmp_val[0] should be a number and tmp_val[1] a string?
if (tmp_val[0] != "301" && tmp_val[0] != "302"
&& tmp_val[0] != "303" && tmp_val[0] != "307"
&& tmp_val[0] != "308")
throw std::invalid_argument("bad redirect status");
// double check this
// it means we aren't allowing internal redirects.
std::cout << tmp_val[1] << '\n';
if (tmp_val[1].compare(0, 7, "http://")
|| tmp_val[1].compare(0, 8, "https://"))
&& tmp_val[1].compare(0, 8, "https://"))
throw std::invalid_argument("bad redirect uri");
location->redirect_status = atoi(tmp_val[0].c_str());
location->redirect_uri = tmp_val[1];
}
else if (key == "upload_repo" && size == 1 && location->upload_repo == "")
else if (key == "upload_dir" && size == 1 && location->upload_dir == "")
{
// what checks to do?
location->upload_repo = tmp_val[0];
// add trailing /
if (tmp_val[0][tmp_val[0].size() - 1] != '/')
tmp_val[0].push_back('/');
location->upload_dir = tmp_val[0];
}
else
throw std::invalid_argument("bad key value pair");