clean comment and stuff

This commit is contained in:
lperrey
2022-08-18 12:44:09 +02:00
parent 9b0fcc1520
commit 469eca8aa9
27 changed files with 100 additions and 325 deletions

View File

@@ -8,16 +8,14 @@ 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";
if (client->get_rq_abs_path() != client->assigned_location->path)
client->status = 404; // 404 ? J'ai un doute.
client->status = 404; // 404 or other status better ?
else if (client->assigned_location->upload_dir.empty())
client->status = 404; // 404 ? J'ai un doute.
client->status = 404; // 404 or other status better ?
else if (client->get_rq_multi_bodys().empty())
{
client->status = 415;
client->status = 415; // Unsupported Media Type
client->response.append("Accept: multipart/form-data"); // empty, no encoding accepted
client->response.append(CRLF);
}
@@ -25,7 +23,7 @@ void Webserv::_post(Client *client, const std::string &path)
_upload_files(client);
}
// #include <ctime> // could add date to DEFAULT_NAME to avoid overwriting files
// #include <ctime> // TODO: could add date to DEFAULT_NAME to avoid overwriting files
#define DEFAULT_NAME "unnamed_file"
void Webserv::_upload_files(Client *client)
{
@@ -58,7 +56,7 @@ void Webserv::_upload_files(Client *client)
{
filename = filename.substr(pos + sizeof("filename=")-1);
std::cerr << "filename ="<< filename << "\n";
// A l'arrache pour enlever les "
// Pour enlever les "
filename.erase(0, 1);
std::cerr << "filename ="<< filename << "\n";
filename.erase(filename.size()-1, 1);
@@ -69,7 +67,7 @@ void Webserv::_upload_files(Client *client)
filename = DEFAULT_NAME + ::itos(i_name++);
std::cerr << "filename ="<< filename << "\n";
path = client->assigned_location->upload_dir; // Assume there a final '/'
path = client->assigned_location->upload_dir;
path.append(filename);
@@ -78,7 +76,6 @@ void Webserv::_upload_files(Client *client)
else
file_existed = true;
// How to determine status 403 for file that dont already exist ? access() on the upload_dir ?
if (file_existed && ::access(path.c_str(), W_OK) == -1)
{
std::perror("err access()");