autoindex in progress but need to check stuff on master branch
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
# include "ServerConfig.hpp"
|
||||
# include "utils.hpp"
|
||||
# include "http_status.hpp"
|
||||
# include "autoindex.hpp"
|
||||
|
||||
extern bool g_run;
|
||||
extern int g_last_signal;
|
||||
@@ -83,7 +84,7 @@ class Webserv
|
||||
void _get(Client *client, ServerConfig &server, LocationConfig &location);
|
||||
|
||||
// in progress
|
||||
void _autoindex(Client *client, std::string &path);
|
||||
void _autoindex(Client *client, LocationConfig &location, std::string &path);
|
||||
|
||||
|
||||
void _get_file(Client *client, const std::string &path);
|
||||
|
||||
25
srcs/webserv/autoindex.hpp
Normal file
25
srcs/webserv/autoindex.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#ifndef AUTOINDEX_HPP
|
||||
# define AUTOINDEX_HPP
|
||||
|
||||
// # define HTML_ERROR(STATUS) "\r\n<!DOCTYPE html><html><head><title>"STATUS"</title></head><body><h1 style=\"text-align:center\">"STATUS"</h1><hr><p style=\"text-align:center\">Le Webserv/0.1</p></body></html>"
|
||||
|
||||
# define AUTOINDEX_START \
|
||||
"<!DOCTYPE html>"\
|
||||
"<html>"\
|
||||
"<head>"\
|
||||
"<title> Index of "
|
||||
|
||||
# define AUTOINDEX_MID \
|
||||
"</title>"\
|
||||
"</head>"\
|
||||
"<body>"
|
||||
|
||||
|
||||
# define AUTOINDEX_END \
|
||||
"</body>"\
|
||||
"</html>"
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -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");
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user