a bit messy but merged index and autoindex work
This commit is contained in:
@@ -128,21 +128,13 @@ if file, server that!
|
||||
|
||||
WHere does cgi fit in in all this ???
|
||||
|
||||
THIS NEEDS WORK...
|
||||
|
||||
*/
|
||||
(void)server; // To remove from arg if we determine its useless
|
||||
std::string path = client->get_path();
|
||||
|
||||
/* if (path == "/") // TODO : index and autoindex
|
||||
path.append(INDEX);
|
||||
<<<<<<< HEAD
|
||||
path.insert(0, location.root);
|
||||
*/
|
||||
// this might not be the best thing, a voir
|
||||
path.insert(0, client->assigned_location->root);
|
||||
|
||||
// that was actually a horrible idea...
|
||||
// path.insert(0, location.root);
|
||||
std::cerr << "path = " << path << "\n";
|
||||
|
||||
// path = root + location.path
|
||||
@@ -152,27 +144,28 @@ THIS NEEDS WORK...
|
||||
|
||||
if (path_is_valid(path) == 1)
|
||||
{
|
||||
std::cout << "path is valid\n";
|
||||
// std::cout << "path is valid\n";
|
||||
if (path[path.size() - 1] != '/')
|
||||
path.push_back('/');
|
||||
for (size_t i = 0; i < location.index.size(); i++)
|
||||
for (size_t i = 0; i < client->assigned_location->index.size(); i++)
|
||||
{
|
||||
std::cout << "location path: " << location.path << '\n';
|
||||
std::cout << "location index: " << location.index[i] << '\n';
|
||||
// std::cout << "path with index: " << path + location.index[i] << '\n';
|
||||
if (path_is_valid(path + location.index[i]) == 2)
|
||||
// std::cout << "location path: " << client->assigned_location->path << '\n';
|
||||
// std::cout << "location index: " << client->assigned_location->index[i] << '\n';
|
||||
// std::cout << "path with index: " << path + assigned_location->index[i] << '\n';
|
||||
if (path_is_valid(path + client->assigned_location->index[i]) == 2)
|
||||
{
|
||||
std::cout << "found a valid index\n";
|
||||
path.append(location.index[i]);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
if (location.autoindex == true)
|
||||
if (client->assigned_location->autoindex == true)
|
||||
{
|
||||
_autoindex(client, location, path);
|
||||
// _autoindex(client, client->assigned_location, path);
|
||||
_autoindex(client, path);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
@@ -198,32 +191,34 @@ THIS NEEDS WORK...
|
||||
|
||||
// i only sort of need &path...
|
||||
// def can improve but works for now...
|
||||
void Webserv::_autoindex(Client *client, LocationConfig &location, std::string &path)
|
||||
//void Webserv::_autoindex(Client *client, LocationConfig &location, std::string &path)
|
||||
void Webserv::_autoindex(Client *client, std::string &path)
|
||||
{
|
||||
std::cout << "made it to _autoindex\n";
|
||||
// std::cout << "made it to _autoindex\n";
|
||||
|
||||
(void)path;
|
||||
std::string dir_list;
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
|
||||
std::cout << "location root: " << location.root << " location path: " \
|
||||
<< location.path << '\n';
|
||||
// std::cout << "location root: " << client->assigned_location->root << " location path: "
|
||||
// << client->assigned_location->path << '\n';
|
||||
|
||||
// if ((dir = opendir (path.c_str())) != NULL)
|
||||
if ((dir = opendir ((location.root + location.path).c_str())) != NULL)
|
||||
if ((dir = opendir ((client->assigned_location->root + client->assigned_location->path).c_str())) != NULL)
|
||||
{
|
||||
/* print all the files and directories within directory */
|
||||
dir_list.append(AUTOINDEX_START);
|
||||
dir_list.append(location.path);
|
||||
dir_list.append(client->assigned_location->path);
|
||||
dir_list.append(AUTOINDEX_MID1);
|
||||
dir_list.append(location.path);
|
||||
dir_list.append(client->assigned_location->path);
|
||||
dir_list.append(AUTOINDEX_MID2);
|
||||
while ((ent = readdir (dir)) != NULL)
|
||||
{
|
||||
if (strcmp(".", ent->d_name) == 0)
|
||||
continue ;
|
||||
dir_list.append("<a href=\"");
|
||||
dir_list.append(location.path.c_str());
|
||||
dir_list.append(client->assigned_location->path.c_str());
|
||||
dir_list.append(ent->d_name);
|
||||
dir_list.append("\">");
|
||||
dir_list.append(ent->d_name);
|
||||
@@ -238,9 +233,9 @@ void Webserv::_autoindex(Client *client, LocationConfig &location, std::string &
|
||||
// <a href="/test/test_deeper/..">..</a>
|
||||
|
||||
dir_list.append(AUTOINDEX_END);
|
||||
std::cout << "\n\n" << dir_list << '\n';
|
||||
// std::cout << "\n\n" << dir_list << '\n';
|
||||
closedir (dir);
|
||||
_append_body(client, dir_list.c_str(), dir_list.size(), "html");
|
||||
_append_body(client, dir_list, "html");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user