🔨」 fix: fixed config and remove default config table

This commit is contained in:
2025-05-03 12:18:32 +02:00
parent bfef8ed76e
commit d369f8ecea
5 changed files with 16 additions and 25 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<Server *> getServers(void) { return _servers; }
Server *getServer(size_t i) {
try {
@ -42,7 +40,6 @@ class Config {
private:
std::vector<Server *> _servers;
Server *_default;
};
}; // namespace config

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<int, std::string> *
_parseErrPages(std::map<std::string, toml::ANode *> *table);
};
} // namespace config

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
};

View File

@ -6,15 +6,15 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <config/default.hpp>
#include <netinet/in.h>
#include <stdexcept>
@ -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;
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);