autoindex in progress but need to check stuff on master branch

This commit is contained in:
Me
2022-08-07 20:37:53 +02:00
parent 4870b2c05d
commit f777441edf
9 changed files with 90 additions and 69 deletions

View File

@@ -145,7 +145,11 @@ void Webserv::_get(Client *client, ServerConfig &server, LocationConfig &locatio
std::cout << "ERIC path: " << path << '\n';
// if (path_is_valid(
/* if (path_is_valid(path) == 1 && location.autoindex == true)
{
_autoindex(client, location, path);
}
*/
// TMP HUGO
//
@@ -162,7 +166,10 @@ void Webserv::_get(Client *client, ServerConfig &server, LocationConfig &locatio
// i might need some sort of _generate_autoindex()
void Webserv::_autoindex(Client *client, std::string &path)
#include <stdio.h>
#include <dirent.h>
void Webserv::_autoindex(Client *client, LocationConfig &location, std::string &path)
{
// i think the plan is to generate an html file and return it
// it should be filled with the stuff that is found in that repo
@@ -174,7 +181,39 @@ void Webserv::_autoindex(Client *client, std::string &path)
// Let's try the 2nd one first.
std::cout << "made it to _autoindex\n";
DIR *dir;
struct dirent *ent;
if ((dir = opendir ((location.root + location.path).c_str())) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
printf ("%s\n", ent->d_name);
}
closedir (dir);
} else {
/* could not open directory */
// perror ("");
std::cout << "could not open dir\n";
return ;
}
std::string dir_list;
dir_list.append(AUTOINDEX_START);
dir_list.append(location.path);
dir_list.append(AUTOINDEX_MID);
// loop something
dir_list.append(location.path);
dir_list.append(AUTOINDEX_END);
_append_body(client, dir_list.c_str(), dir_list.size(), "html");