cgi_ext, redirect and upload_repo now functional in config, fixed location picker, some cleanup

This commit is contained in:
Me
2022-08-09 02:37:28 +02:00
parent a44b9b493a
commit 97c90236b9
7 changed files with 79 additions and 47 deletions

View File

@@ -145,6 +145,7 @@ 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 /");
@@ -290,18 +291,10 @@ void ConfigParser::_set_location_values(LocationConfig *location, \
throw std::invalid_argument("missing value");
else if (key == "root" && size == 1 && location->root == "")
{
// std::cout << "location root: " << tmp_val[0] << '\n';
// if (tmp_val[0][0] != '/')
// throw std::invalid_argument("Root requires leading /");
// remove trailing /
// if (tmp_val[0].back() == '/')
if (tmp_val[0][tmp_val[0].size() - 1] == '/')
tmp_val[0].erase(tmp_val[0].size() - 1, 1);
// if (path_is_valid(tmp_val[0]) == 1)
location->root = tmp_val[0];
// else
// throw std::invalid_argument("Root dir invalid");
location->root = tmp_val[0];
}
else if (key == "autoindex" && size == 1)
{
@@ -310,6 +303,7 @@ void ConfigParser::_set_location_values(LocationConfig *location, \
}
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]);
@@ -341,14 +335,24 @@ void ConfigParser::_set_location_values(LocationConfig *location, \
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 (!(::isNumeric(tmp_val[0])))
throw std::invalid_argument("value not a number");
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.
if (tmp_val[1].compare(0, 7, "http://")
|| tmp_val[1].compare(0, 8, "https://"))
throw std::invalid_argument("bad redirect uri");
// somehow check that tmp_val[1] is a string? or valid? how?
// something about using access() to see if
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 == "")
{
// what checks to do?
location->upload_repo = tmp_val[0];
}
else
throw std::invalid_argument("bad key value pair");
}