little delete fix in main.cpp

This commit is contained in:
lperrey
2022-08-17 20:55:58 +02:00
parent e537e9bb78
commit 2613ca2e1a
3 changed files with 18 additions and 34 deletions

View File

@@ -1,7 +1,4 @@
----Priorité élevée------------------------ ----Priorité élevée------------------------
- CGI (TODO HUGO)
- Need to test normal body parsing (Verif avec HUGO)
- curl --resolve, for testing hostname - curl --resolve, for testing hostname
curl -v --resolve server1:4040:127.0.0.1 --resolve server2:4040:127.0.0.1 server1:4040 curl -v --resolve server1:4040:127.0.0.1 --resolve server2:4040:127.0.0.1 server1:4040
@@ -12,20 +9,10 @@
- cgi_cpp_status.cpp with POST dont show error page. Normal or not ? - cgi_cpp_status.cpp with POST dont show error page. Normal or not ?
For non blocking CGI :
// We could maybe,
// add FD_RD_FR_CHLD to epoll,
// return to the main loop,
// read FD_RD_FR_CHLD each time epoll say its ready,
// then try waitpid() with WNOHANG after each read.
// when waitpid() tell us its finish (or maybe when epoll return EPOLLHUP)
// then actually parse the script_output and send it to the client.
- check status in autoindex - check status in autoindex
- merge changes from hugo5 to master (attention a pas casse svp :clown:) - merge changes from hugo5 to master (attention a pas casse svp :clown:)
----Priorité modérée------------------------ ----Priorité modérée------------------------
- namespace utils ? - namespace utils ?
- change "std::string" to reference "std::string &" in most functions - change "std::string" to reference "std::string &" in most functions
@@ -36,8 +23,8 @@ and add "const" if apropriate.
----Priorité faible------------------------ ----Priorité faible------------------------
- idealy, we should not clear() raw_request after a response, - idealy, we should not clear() raw_request after a response,
but just the part we actually parsed for this response. but just the part we actually parsed for this response.
I think the client could send multiples request on the same connection one after the other without waiting for response. I think in HTTP/1 the client could not send multiples request on the same connection one after the other without waiting for response.
So raw_request could contain more than the first request we handle. So only for HTTP/2 adn HTTP/3 raw_request could contain more than the first request we handle.
- chunked request (need testing) - chunked request (need testing)
- client_body_limit 0 valeur special pour desactiver dans config - client_body_limit 0 valeur special pour desactiver dans config
- gerer le champ "Accept" du client - gerer le champ "Accept" du client
@@ -47,8 +34,6 @@ and add "const" if apropriate.
little global timeout on epoll, like 100ms, then find client that actualy need to timeout little global timeout on epoll, like 100ms, then find client that actualy need to timeout
if (actual_time - client.last_action_time > 10000ms){timeout(client)} if (actual_time - client.last_action_time > 10000ms){timeout(client)}
- add headers "Date" and "Last-Modified" to response - add headers "Date" and "Last-Modified" to response
- change "std::string" to reference "std::string &" in most functions
and add "const" if apropriate.
- Il faut vérifier le path de la requête, voir si le serveur est bien censé délivrer cette ressource et si le client y a accès, avant d'appeler le CGI. - Il faut vérifier le path de la requête, voir si le serveur est bien censé délivrer cette ressource et si le client y a accès, avant d'appeler le CGI.
Valgrind error RESOLVED ! : Valgrind error RESOLVED ! :

View File

@@ -7,19 +7,19 @@
int main(int ac, char **av) int main(int ac, char **av)
{ {
std::vector<ServerConfig>* servers_config = NULL;
try try
{ {
std::string config = (ac == 2 ? av[1] : "./default.config"); std::string config = (ac == 2 ? av[1] : "./default.config");
ConfigParser configParser(config); ConfigParser configParser(config);
// configParser.print_content(); // configParser.print_content();
// i don't love that servers has to be a pointer... // i don't love that servers_config has to be a pointer...
std::vector<ServerConfig>* servers = configParser.parse(); servers_config = configParser.parse();
// use an iterator you moron // use an iterator you moron
for (std::vector<ServerConfig>::iterator it = servers->begin(); it < servers->end(); it++) for (std::vector<ServerConfig>::iterator it = servers_config->begin(); it < servers_config->end(); it++)
{ {
(void)0; (void)0;
// std::cout << it->server_name << " "; // std::cout << it->server_name << " ";
@@ -33,14 +33,16 @@ int main(int ac, char **av)
Webserv serv; Webserv serv;
// serv.init_virtual_servers(); // serv.init_virtual_servers();
serv.init_virtual_servers(servers); serv.init_virtual_servers(servers_config);
delete servers; delete servers_config;
servers_config = NULL;
serv.run(); serv.run();
} }
catch (std::exception& e) catch (std::exception& e)
{ {
std::cerr << e.what() << '\n'; std::cerr << e.what() << '\n';
delete servers_config;
} }
return (0); return (0);
} }

View File

@@ -1,12 +1,11 @@
#include "Webserv.hpp" #include "Webserv.hpp"
void Webserv::_post(Client *client, const std::string &path)
{
/* /*
https://www.rfc-editor.org/rfc/rfc9110.html#name-post https://www.rfc-editor.org/rfc/rfc9110.html#name-post
*/ */
void Webserv::_post(Client *client, const std::string &path)
{
(void)path; // unused, we use "assigned_location->upload_dir" instead (void)path; // unused, we use "assigned_location->upload_dir" instead
std::cout << "_post()\n"; std::cout << "_post()\n";
std::cerr << "upload_dir = " << client->assigned_location->upload_dir << "\n"; std::cerr << "upload_dir = " << client->assigned_location->upload_dir << "\n";
@@ -26,8 +25,8 @@ void Webserv::_post(Client *client, const std::string &path)
_upload_files(client); _upload_files(client);
} }
// #include <ctime> // could add date to DEFAULT_NAME to avoid overwriting files
#define DEFAULT_NAME "unnamed_file" #define DEFAULT_NAME "unnamed_file"
// TODO : Loop for multi body
void Webserv::_upload_files(Client *client) void Webserv::_upload_files(Client *client)
{ {
std::cout << "_upload_files()\n"; std::cout << "_upload_files()\n";
@@ -37,6 +36,7 @@ void Webserv::_upload_files(Client *client)
std::string filename; std::string filename;
size_t pos; size_t pos;
bool file_existed = false; bool file_existed = false;
static int i_name = 0;
client->status = ::eval_file_access(client->assigned_location->upload_dir, W_OK); client->status = ::eval_file_access(client->assigned_location->upload_dir, W_OK);
if (client->status) if (client->status)
@@ -64,13 +64,10 @@ void Webserv::_upload_files(Client *client)
filename.erase(filename.size()-1, 1); filename.erase(filename.size()-1, 1);
std::cerr << "filename ="<< filename << "\n"; std::cerr << "filename ="<< filename << "\n";
std::cerr << "filename ="<< filename << "\n"; std::cerr << "filename ="<< filename << "\n";
if (filename.empty())
filename = DEFAULT_NAME;
}
else
{
filename = DEFAULT_NAME;
} }
if (pos == NPOS || filename.empty())
filename = DEFAULT_NAME + ::itos(i_name++);
std::cerr << "filename ="<< filename << "\n"; std::cerr << "filename ="<< filename << "\n";
path = client->assigned_location->upload_dir; // Assume there a final '/' path = client->assigned_location->upload_dir; // Assume there a final '/'
path.append(filename); path.append(filename);