From d369f8ecea836f947083a433acbaf5dd431f4b21 Mon Sep 17 00:00:00 2001 From: adjoly Date: Sat, 3 May 2025 12:18:32 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fixed?= =?UTF-8?q?=20config=20and=20remove=20default=20config=20table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/config/Config.hpp | 5 +---- includes/config/Server.hpp | 4 +--- includes/requests/RequestImplement.hpp | 6 +++++- src/config/Config.cpp | 20 ++++++------------- .../requestImplementation/Post.cpp | 6 +++--- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/includes/config/Config.hpp b/includes/config/Config.hpp index 7ee6421..3df4af6 100644 --- a/includes/config/Config.hpp +++ b/includes/config/Config.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/14 12:20:06 by adjoly #+# #+# */ -/* Updated: 2025/05/01 15:29:53 by adjoly ### ########.fr */ +/* Updated: 2025/05/03 09:42:35 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,8 +28,6 @@ class Config { Logger *getLogger(void) { return _log; } - Server *getDefaultServer(void) const { return _default; } - std::vector getServers(void) { return _servers; } Server *getServer(size_t i) { try { @@ -42,7 +40,6 @@ class Config { private: std::vector _servers; - Server *_default; }; }; // namespace config diff --git a/includes/config/Server.hpp b/includes/config/Server.hpp index b1aec94..c701c5e 100644 --- a/includes/config/Server.hpp +++ b/includes/config/Server.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/19 14:11:28 by adjoly #+# #+# */ -/* Updated: 2025/05/01 15:32:31 by adjoly ### ########.fr */ +/* Updated: 2025/05/03 09:42:27 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,8 +83,6 @@ class Server { std::map * _parseErrPages(std::map *table); - - }; } // namespace config diff --git a/includes/requests/RequestImplement.hpp b/includes/requests/RequestImplement.hpp index 5c72556..efb4d2e 100644 --- a/includes/requests/RequestImplement.hpp +++ b/includes/requests/RequestImplement.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/30 09:30:15 by adjoly #+# #+# */ -/* Updated: 2025/04/30 09:34:17 by adjoly ### ########.fr */ +/* Updated: 2025/05/03 12:07:57 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,10 @@ class Post : public ARequest { void parse(std::string const &data); + std::string extractFilename(const std::string &header); + void handleMultipartData(const std::string &body, + const std::string &boundary); + Response execute(void); }; diff --git a/src/config/Config.cpp b/src/config/Config.cpp index 2ec0eba..9555a37 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -6,15 +6,15 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/14 12:53:54 by adjoly #+# #+# */ -/* Updated: 2025/05/01 17:00:00 by adjoly ### ########.fr */ +/* Updated: 2025/05/03 09:42:44 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ +#include "cppeleven.hpp" #include "log.hpp" +#include "node/ANode.hpp" #include "node/default.hpp" #include "webserv.hpp" -#include "cppeleven.hpp" -#include "node/ANode.hpp" #include #include #include @@ -23,7 +23,7 @@ using namespace webserv::config; Config::Config(std::string &filename) { toml::Toml *file = new toml::Toml(filename); - + try { file->parse(); } catch (std::runtime_error &e) { @@ -45,21 +45,14 @@ Config::Config(std::string &filename) { if (it->second->type() == toml::TABLE) { _log->info("taking server from table : " + it->first); try { - if (it->first == "default") { - _default = new Server(it->second, not_nullptr); - } else { - Server *srv = new Server(it->second); - _servers.push_back(srv); - } + Server *srv = new Server(it->second); + _servers.push_back(srv); } catch (std::runtime_error &e) { _log->error(e.what()); if (!_servers.empty()) { for (auto it = range(_servers)) delete (*it); } - if (_default != not_nullptr) { - delete _default; - } delete table; delete file; throw e; @@ -74,5 +67,4 @@ Config::~Config(void) { for (auto it = range(_servers)) { delete *it; } - delete _default; } diff --git a/src/requests_handling/requestImplementation/Post.cpp b/src/requests_handling/requestImplementation/Post.cpp index 227ff5f..067f966 100644 --- a/src/requests_handling/requestImplementation/Post.cpp +++ b/src/requests_handling/requestImplementation/Post.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/30 09:50:20 by adjoly #+# #+# */ -/* Updated: 2025/05/02 15:02:56 by mmoussou ### ########.fr */ +/* Updated: 2025/05/03 09:44:41 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,13 +67,13 @@ void Post::parse(std::string const &data) { */ } -std::string extractFilename(const std::string &header) { +std::string Post::extractFilename(const std::string &header) { size_t start = header.find("filename=\"") + 10; size_t end = header.find("\"", start); return this->_route->getUpRoot() + header.substr(start, end - start); } -void handleMultipartData(const std::string &body, const std::string &boundary) { +void Post::handleMultipartData(const std::string &body, const std::string &boundary) { size_t i = 0; std::string delim = "--" + boundary; delim.erase(delim.size() - 1);