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

@@ -9,7 +9,7 @@ if path is a valid dir check if index is specified and serve that
if no index and autoindex, server that
if file, server that!
WHere does cgi fit in in all this ???
Where does cgi fit in in all this ???
*/
@@ -39,15 +39,12 @@ WHere does cgi fit in in all this ???
{
// std::cout << "found a valid index\n";
path.append(client->assigned_location->index[i]);
break ; // what if index and autoindex in a single location?
// does this completely fail?
// do this instead of break?
//_get_file(client, path);
_get_file(client, path);
return ;
}
}
if (client->assigned_location->autoindex == true)
{
// _autoindex(client, client->assigned_location, path);
_autoindex(client, path);
return ;
}
@@ -189,4 +186,4 @@ void Webserv::_autoindex(Client *client, std::string &path)
std::cout << "could not open dir\n";
return ;
}
}
}

View File

@@ -171,25 +171,58 @@ ServerConfig *Webserv::_determine_process_server(Client *client)
const LocationConfig *Webserv::_determine_location(const ServerConfig &server, const std::string &path) const
{
// std::cout << "determin location path sent: " << path << '\n';
std::cout << "determin location path sent: " << path << '\n';
std::vector<LocationConfig>::const_iterator it = server.locations.begin();
while (it != server.locations.end())
/// NO FUCKING IDEA WHY BUT...
// basically if 2 strings are identical to a point, compare from
// longer one or it'll freak out cuz of \0 or something idk
//// Basically: str.compare() from the larger string...
/* RULES ***
If a path coresponds exactly to a location, use that one
if no path coresponds then use the most correct one
most correct means the most precise branch that is still above
the point we are aiming for
*/
std::vector<LocationConfig>::const_iterator best;
std::cout << "\nMade it to weird location picker case.\n";
for (std::vector<LocationConfig>::const_iterator it = server.locations.begin(); it != server.locations.end(); it++)
{
// std::cout << it->path << " -- ";
// if (it->path.compare(0, path.size(), path) == 0)
if (it->path.compare(0, it->path.size(), path) == 0)
break;
// kinda gross i know but... have to deal with when there's a / at the end
if (it->path[it->path.size() - 1] == '/' \
std::cout << it->path << " -- ";
// if (rit->path.size() > path.size())
/* if ((rit->path[rit->path.size() - 1] == '/' ? rit->path.size() : rit->path.size() - 1) > path.size())
{
std::cout << "skipping this one\n";
continue ;
}
*/
// OK I REALLY DON"T LOVE THIS PART, BUT IT DOES WORK FOR NOW...
// if (it->path[it->path.size() - 1] == '/'
// && it->path.compare(0, it->path.size(), path + "/") == 0)
// HOLD ON THIS MIGHT BE GOOD, BUT I COULD USE SOME HELP...
if (it->path[it->path.size() - 1] == '/'
&& it->path.compare(0, it->path.size() - 1, path) == 0)
break;
++it;
{
best = it;
std::cout << "Picked a best! 1\n";
}
// int comp = path.compare(0, rit->path.size(), rit->path);
//int comp = rit->path.compare(0, rit->path.size() - 1, path);
// std::cout << "rit path size: " << rit->path.size() << " comp: " << comp << '\n';
// if (rit->path.compare(0, rit->path.size(), path) == 0)
// if (comp == 0)
if (path.compare(0, it->path.size(), it->path) == 0)
{
best = it;
std::cout << "Picked a best! 2\n";
}
}
if (it != server.locations.end())
return (&(*it));
else
return (&(server.locations.back()));
return (&(*best));
}
std::string Webserv::_determine_file_extension(const std::string &path) const