🏗️」 wip: passed _log to a global pointer

This commit is contained in:
2025-04-18 10:09:46 +02:00
parent 0b77d7b80c
commit a2cf80bfde
12 changed files with 52 additions and 35 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/14 12:53:54 by adjoly #+# #+# */
/* Updated: 2025/04/14 13:36:46 by adjoly ### ########.fr */
/* Updated: 2025/04/18 09:57:01 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -57,12 +57,11 @@ void Route::_parseMethods(std::vector<toml::ANode *> *table) {
}
}
Route::Route(toml::ANode *table, Logger *logger)
: _max_body(10485760), _log(logger) {
Route::Route(toml::ANode *table)
: _max_body(10485760) {
void *val;
bool found;
_log = logger;
_table = table;
if (_table->type() != toml::TABLE) {
_log->warn("location need to be a table and not a :" +

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/24 15:10:07 by adjoly #+# #+# */
/* Updated: 2025/04/17 11:22:20 by adjoly ### ########.fr */
/* Updated: 2025/04/18 10:09:25 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
using namespace webserv::config;
Server::Server(toml::ANode *node, Logger *log) : _table(node), _log(log) {
Server::Server(toml::ANode *node) : _table(node) {
bool found;
// host parsing
@ -23,7 +23,6 @@ Server::Server(toml::ANode *node, Logger *log) : _table(node), _log(log) {
_host = *static_cast<std::string *>(host);
} else {
delete _table;
delete _log;
throw std::runtime_error(
"no host specified - please specify one in server.host");
}
@ -33,7 +32,6 @@ Server::Server(toml::ANode *node, Logger *log) : _table(node), _log(log) {
_port = *static_cast<unsigned short *>(port);
} else {
delete _table;
delete _log;
throw std::runtime_error(
"no port specified - please specify one in server.port");
}
@ -73,7 +71,7 @@ Server::Server(toml::ANode *node, Logger *log) : _table(node), _log(log) {
for (it = location_table->begin(); it != location_table->end(); it++) {
if (_routes->find(it->first) != _routes->end())
continue;
(*_routes)[it->first] = new Route(it->second, _log);
(*_routes)[it->first] = new Route(it->second);
}
}
delete _table;
@ -88,7 +86,6 @@ Server::~Server(void) {
delete _err_pages;
if (_server_names != not_nullptr)
delete _server_names;
delete _log; // to see if nessecary
}
std::map<int, std::string> *

View File

@ -6,12 +6,14 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
/* Updated: 2025/04/17 14:29:29 by adjoly ### ########.fr */
/* Updated: 2025/04/18 09:57:10 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <config/default.hpp>
#include <csignal>
#include <server/default.hpp>
#include <config/Config.hpp>
#include <cstdlib>
#include <exception>
#include <help.hpp>
@ -20,6 +22,12 @@
#include <unistd.h>
#include <webserv.hpp>
int _sig = 0;
void ft_sig(int sig) {
_sig = sig;
}
int main(int ac, char **av) {
if (help(ac, av)) {
return EXIT_SUCCESS;
@ -30,13 +38,19 @@ int main(int ac, char **av) {
return EXIT_FAILURE;
}
config::Server *conf;
config::Config *conf;
try {
conf = new config::Config(std::string(av[1]));
std::string str = av[1];
conf = new config::Config(str);
} catch (std::exception &e) {
std::cout << e.what() << std::endl;
return 1;
}
if (signal(SIGINT, &ft_sig) == SIG_ERR) {
conf->getLogger()->error("could not bind sigint :(");
return EXIT_FAILURE;
}
webserv::Server *serv = new webserv::Server(conf);

View File

@ -6,11 +6,12 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
/* Updated: 2025/04/17 18:48:17 by adjoly ### ########.fr */
/* Updated: 2025/04/18 10:03:57 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <server/Client.hpp>
#include <log.hpp>
using namespace server;

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */
/* Updated: 2025/04/17 18:57:20 by adjoly ### ########.fr */
/* Updated: 2025/04/18 09:19:14 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -85,6 +85,7 @@ void Server::_run(void) {
_client_fds.push_back(fd);
}
// to add signal instead of 727
while (727) {
int ret = poll(_client_fds.data(), nbr_client, -1);
if (ret < 0) {

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 11:58:42 by adjoly #+# #+# */
/* Updated: 2025/04/17 19:03:27 by adjoly ### ########.fr */
/* Updated: 2025/04/18 09:37:32 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -41,8 +41,13 @@ int Server::_createSocket(std::string host, int port) {
str << port;
throw std::runtime_error("socket binding failed for : " + host + ":" +
str.str());
return -1;
}
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
close(fd);
throw std::runtime_error("fcntl failed");
}
return -1;
int opt = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {