mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 23:48:46 +02:00
「🔨」 fix: fixed config and remove default config table
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/14 12:20:06 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; }
|
Logger *getLogger(void) { return _log; }
|
||||||
|
|
||||||
Server *getDefaultServer(void) const { return _default; }
|
|
||||||
|
|
||||||
std::vector<Server *> getServers(void) { return _servers; }
|
std::vector<Server *> getServers(void) { return _servers; }
|
||||||
Server *getServer(size_t i) {
|
Server *getServer(size_t i) {
|
||||||
try {
|
try {
|
||||||
@ -42,7 +40,6 @@ class Config {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Server *> _servers;
|
std::vector<Server *> _servers;
|
||||||
Server *_default;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace config
|
}; // namespace config
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/19 14:11:28 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<int, std::string> *
|
std::map<int, std::string> *
|
||||||
_parseErrPages(std::map<std::string, toml::ANode *> *table);
|
_parseErrPages(std::map<std::string, toml::ANode *> *table);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace config
|
} // namespace config
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/30 09:30:15 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);
|
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);
|
Response execute(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,15 +6,15 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/14 12:53:54 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 "log.hpp"
|
||||||
|
#include "node/ANode.hpp"
|
||||||
#include "node/default.hpp"
|
#include "node/default.hpp"
|
||||||
#include "webserv.hpp"
|
#include "webserv.hpp"
|
||||||
#include "cppeleven.hpp"
|
|
||||||
#include "node/ANode.hpp"
|
|
||||||
#include <config/default.hpp>
|
#include <config/default.hpp>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@ -23,7 +23,7 @@ using namespace webserv::config;
|
|||||||
|
|
||||||
Config::Config(std::string &filename) {
|
Config::Config(std::string &filename) {
|
||||||
toml::Toml *file = new toml::Toml(filename);
|
toml::Toml *file = new toml::Toml(filename);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
file->parse();
|
file->parse();
|
||||||
} catch (std::runtime_error &e) {
|
} catch (std::runtime_error &e) {
|
||||||
@ -45,21 +45,14 @@ Config::Config(std::string &filename) {
|
|||||||
if (it->second->type() == toml::TABLE) {
|
if (it->second->type() == toml::TABLE) {
|
||||||
_log->info("taking server from table : " + it->first);
|
_log->info("taking server from table : " + it->first);
|
||||||
try {
|
try {
|
||||||
if (it->first == "default") {
|
Server *srv = new Server(it->second);
|
||||||
_default = new Server(it->second, not_nullptr);
|
_servers.push_back(srv);
|
||||||
} else {
|
|
||||||
Server *srv = new Server(it->second);
|
|
||||||
_servers.push_back(srv);
|
|
||||||
}
|
|
||||||
} catch (std::runtime_error &e) {
|
} catch (std::runtime_error &e) {
|
||||||
_log->error(e.what());
|
_log->error(e.what());
|
||||||
if (!_servers.empty()) {
|
if (!_servers.empty()) {
|
||||||
for (auto it = range(_servers))
|
for (auto it = range(_servers))
|
||||||
delete (*it);
|
delete (*it);
|
||||||
}
|
}
|
||||||
if (_default != not_nullptr) {
|
|
||||||
delete _default;
|
|
||||||
}
|
|
||||||
delete table;
|
delete table;
|
||||||
delete file;
|
delete file;
|
||||||
throw e;
|
throw e;
|
||||||
@ -74,5 +67,4 @@ Config::~Config(void) {
|
|||||||
for (auto it = range(_servers)) {
|
for (auto it = range(_servers)) {
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
delete _default;
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/30 09:50:20 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 start = header.find("filename=\"") + 10;
|
||||||
size_t end = header.find("\"", start);
|
size_t end = header.find("\"", start);
|
||||||
return this->_route->getUpRoot() + header.substr(start, end - 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;
|
size_t i = 0;
|
||||||
std::string delim = "--" + boundary;
|
std::string delim = "--" + boundary;
|
||||||
delim.erase(delim.size() - 1);
|
delim.erase(delim.size() - 1);
|
||||||
|
Reference in New Issue
Block a user