little delete fix in main.cpp
This commit is contained in:
@@ -7,19 +7,19 @@
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
std::vector<ServerConfig>* servers_config = NULL;
|
||||
try
|
||||
{
|
||||
std::string config = (ac == 2 ? av[1] : "./default.config");
|
||||
|
||||
|
||||
ConfigParser configParser(config);
|
||||
// configParser.print_content();
|
||||
|
||||
// i don't love that servers has to be a pointer...
|
||||
std::vector<ServerConfig>* servers = configParser.parse();
|
||||
// i don't love that servers_config has to be a pointer...
|
||||
servers_config = configParser.parse();
|
||||
|
||||
// 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;
|
||||
// std::cout << it->server_name << " ";
|
||||
@@ -33,14 +33,16 @@ int main(int ac, char **av)
|
||||
Webserv serv;
|
||||
|
||||
// serv.init_virtual_servers();
|
||||
serv.init_virtual_servers(servers);
|
||||
delete servers;
|
||||
serv.init_virtual_servers(servers_config);
|
||||
delete servers_config;
|
||||
servers_config = NULL;
|
||||
serv.run();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << '\n';
|
||||
delete servers_config;
|
||||
}
|
||||
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
|
||||
#include "Webserv.hpp"
|
||||
|
||||
|
||||
void Webserv::_post(Client *client, const std::string &path)
|
||||
{
|
||||
/*
|
||||
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
|
||||
std::cout << "_post()\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);
|
||||
}
|
||||
|
||||
// #include <ctime> // could add date to DEFAULT_NAME to avoid overwriting files
|
||||
#define DEFAULT_NAME "unnamed_file"
|
||||
// TODO : Loop for multi body
|
||||
void Webserv::_upload_files(Client *client)
|
||||
{
|
||||
std::cout << "_upload_files()\n";
|
||||
@@ -37,6 +36,7 @@ void Webserv::_upload_files(Client *client)
|
||||
std::string filename;
|
||||
size_t pos;
|
||||
bool file_existed = false;
|
||||
static int i_name = 0;
|
||||
|
||||
client->status = ::eval_file_access(client->assigned_location->upload_dir, W_OK);
|
||||
if (client->status)
|
||||
@@ -64,13 +64,10 @@ void Webserv::_upload_files(Client *client)
|
||||
filename.erase(filename.size()-1, 1);
|
||||
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";
|
||||
path = client->assigned_location->upload_dir; // Assume there a final '/'
|
||||
path.append(filename);
|
||||
|
||||
Reference in New Issue
Block a user