mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 23:28:46 +02:00
「🏗️」 wip: passed _log to a global pointer
This commit is contained in:
@ -8,4 +8,6 @@ RUN apk add --no-cache clang make \
|
|||||||
&& chmod +x webserv \
|
&& chmod +x webserv \
|
||||||
&& cp webserv /bin/webserv
|
&& cp webserv /bin/webserv
|
||||||
|
|
||||||
|
STOPSIGNAL SIGINT
|
||||||
|
|
||||||
RUN [ "/bin/webserv", "$WEBSERV-CONF"]
|
RUN [ "/bin/webserv", "$WEBSERV-CONF"]
|
||||||
|
@ -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/04/14 13:36:42 by adjoly ### ########.fr */
|
/* Updated: 2025/04/18 10:03:09 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -27,7 +27,6 @@ class Config {
|
|||||||
std::vector<Server *> *getServers(void) { return _servers; }
|
std::vector<Server *> *getServers(void) { return _servers; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Logger *_log;
|
|
||||||
std::vector<Server *> *_servers;
|
std::vector<Server *> *_servers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/19 14:59:41 by adjoly #+# #+# */
|
/* Created: 2025/03/19 14:59:41 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/03/26 08:31:41 by adjoly ### ########.fr */
|
/* Updated: 2025/04/18 10:05:22 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ namespace config {
|
|||||||
|
|
||||||
class Route {
|
class Route {
|
||||||
public:
|
public:
|
||||||
Route(toml::ANode *, Logger *);
|
Route(toml::ANode *);
|
||||||
~Route(void);
|
~Route(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -42,8 +42,6 @@ class Route {
|
|||||||
std::string _index;
|
std::string _index;
|
||||||
std::map<std::string, std::string> *_cgi;
|
std::map<std::string, std::string> *_cgi;
|
||||||
|
|
||||||
Logger *_log;
|
|
||||||
|
|
||||||
bool _methods[3]; ///> A methods boolean array which correspond to - 0: GET,
|
bool _methods[3]; ///> A methods boolean array which correspond to - 0: GET,
|
||||||
///1: POST, 2: DELETE
|
///1: POST, 2: DELETE
|
||||||
toml::ANode *_table;
|
toml::ANode *_table;
|
||||||
|
@ -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/04/14 12:39:17 by adjoly ### ########.fr */
|
/* Updated: 2025/04/18 10:08:33 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ namespace config {
|
|||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
public:
|
public:
|
||||||
Server(toml::ANode *, Logger *);
|
Server(toml::ANode *);
|
||||||
~Server();
|
~Server();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,7 +70,6 @@ class Server {
|
|||||||
|
|
||||||
toml::ANode *_table; ///> The table used for the parsing (is deleted at the
|
toml::ANode *_table; ///> The table used for the parsing (is deleted at the
|
||||||
/// end of the constructor)
|
/// end of the constructor)
|
||||||
Logger *_log; ///> A pointer to the logger class
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/20 09:28:27 by adjoly #+# #+# */
|
/* Created: 2025/03/20 09:28:27 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/04/14 13:03:31 by adjoly ### ########.fr */
|
/* Updated: 2025/04/18 10:03:06 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -134,4 +134,6 @@ class Logger {
|
|||||||
std::ofstream _file;
|
std::ofstream _file;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Logger *_log = NULL;
|
||||||
|
|
||||||
}; // namespace webserv
|
}; // namespace webserv
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* 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/04/14 13:36:46 by adjoly ### ########.fr */
|
/* Updated: 2025/04/18 09:57:01 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -57,12 +57,11 @@ void Route::_parseMethods(std::vector<toml::ANode *> *table) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Route::Route(toml::ANode *table, Logger *logger)
|
Route::Route(toml::ANode *table)
|
||||||
: _max_body(10485760), _log(logger) {
|
: _max_body(10485760) {
|
||||||
void *val;
|
void *val;
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
_log = logger;
|
|
||||||
_table = table;
|
_table = table;
|
||||||
if (_table->type() != toml::TABLE) {
|
if (_table->type() != toml::TABLE) {
|
||||||
_log->warn("location need to be a table and not a :" +
|
_log->warn("location need to be a table and not a :" +
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/24 15:10:07 by adjoly #+# #+# */
|
/* 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;
|
using namespace webserv::config;
|
||||||
|
|
||||||
Server::Server(toml::ANode *node, Logger *log) : _table(node), _log(log) {
|
Server::Server(toml::ANode *node) : _table(node) {
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
// host parsing
|
// host parsing
|
||||||
@ -23,7 +23,6 @@ Server::Server(toml::ANode *node, Logger *log) : _table(node), _log(log) {
|
|||||||
_host = *static_cast<std::string *>(host);
|
_host = *static_cast<std::string *>(host);
|
||||||
} else {
|
} else {
|
||||||
delete _table;
|
delete _table;
|
||||||
delete _log;
|
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"no host specified - please specify one in server.host");
|
"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);
|
_port = *static_cast<unsigned short *>(port);
|
||||||
} else {
|
} else {
|
||||||
delete _table;
|
delete _table;
|
||||||
delete _log;
|
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"no port specified - please specify one in server.port");
|
"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++) {
|
for (it = location_table->begin(); it != location_table->end(); it++) {
|
||||||
if (_routes->find(it->first) != _routes->end())
|
if (_routes->find(it->first) != _routes->end())
|
||||||
continue;
|
continue;
|
||||||
(*_routes)[it->first] = new Route(it->second, _log);
|
(*_routes)[it->first] = new Route(it->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete _table;
|
delete _table;
|
||||||
@ -88,7 +86,6 @@ Server::~Server(void) {
|
|||||||
delete _err_pages;
|
delete _err_pages;
|
||||||
if (_server_names != not_nullptr)
|
if (_server_names != not_nullptr)
|
||||||
delete _server_names;
|
delete _server_names;
|
||||||
delete _log; // to see if nessecary
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, std::string> *
|
std::map<int, std::string> *
|
||||||
|
20
src/main.cpp
20
src/main.cpp
@ -6,12 +6,14 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
|
/* 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 <config/default.hpp>
|
||||||
|
#include <csignal>
|
||||||
#include <server/default.hpp>
|
#include <server/default.hpp>
|
||||||
|
#include <config/Config.hpp>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <help.hpp>
|
#include <help.hpp>
|
||||||
@ -20,6 +22,12 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <webserv.hpp>
|
#include <webserv.hpp>
|
||||||
|
|
||||||
|
int _sig = 0;
|
||||||
|
|
||||||
|
void ft_sig(int sig) {
|
||||||
|
_sig = sig;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int ac, char **av) {
|
int main(int ac, char **av) {
|
||||||
if (help(ac, av)) {
|
if (help(ac, av)) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
@ -30,13 +38,19 @@ int main(int ac, char **av) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
config::Server *conf;
|
|
||||||
|
config::Config *conf;
|
||||||
try {
|
try {
|
||||||
conf = new config::Config(std::string(av[1]));
|
std::string str = av[1];
|
||||||
|
conf = new config::Config(str);
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
return 1;
|
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);
|
webserv::Server *serv = new webserv::Server(conf);
|
||||||
|
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
|
/* 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 <server/Client.hpp>
|
||||||
|
#include <log.hpp>
|
||||||
|
|
||||||
using namespace server;
|
using namespace server;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */
|
/* 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);
|
_client_fds.push_back(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// to add signal instead of 727
|
||||||
while (727) {
|
while (727) {
|
||||||
int ret = poll(_client_fds.data(), nbr_client, -1);
|
int ret = poll(_client_fds.data(), nbr_client, -1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/17 11:58:42 by adjoly #+# #+# */
|
/* 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;
|
str << port;
|
||||||
throw std::runtime_error("socket binding failed for : " + host + ":" +
|
throw std::runtime_error("socket binding failed for : " + host + ":" +
|
||||||
str.str());
|
str.str());
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||||
|
close(fd);
|
||||||
|
throw std::runtime_error("fcntl failed");
|
||||||
|
}
|
||||||
|
|
||||||
int opt = 1;
|
int opt = 1;
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
|
||||||
|
Reference in New Issue
Block a user