mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 20:48:46 +02:00
「🏗️」 wip: passed _log to a global pointer
This commit is contained in:
18
Dockerfile
18
Dockerfile
@ -1,11 +1,13 @@
|
||||
FROM alpine:3.21
|
||||
FROM alpine:3.21
|
||||
|
||||
COPY ./ /build
|
||||
COPY ./ /build
|
||||
|
||||
RUN apk add --no-cache clang make \
|
||||
&& cd /build \
|
||||
&& make \
|
||||
&& chmod +x webserv \
|
||||
&& cp webserv /bin/webserv
|
||||
RUN apk add --no-cache clang make \
|
||||
&& cd /build \
|
||||
&& make \
|
||||
&& chmod +x webserv \
|
||||
&& cp webserv /bin/webserv
|
||||
|
||||
RUN [ "/bin/webserv", "$WEBSERV-CONF"]
|
||||
STOPSIGNAL SIGINT
|
||||
|
||||
RUN [ "/bin/webserv", "$WEBSERV-CONF"]
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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; }
|
||||
|
||||
private:
|
||||
Logger *_log;
|
||||
std::vector<Server *> *_servers;
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 {
|
||||
public:
|
||||
Route(toml::ANode *, Logger *);
|
||||
Route(toml::ANode *);
|
||||
~Route(void);
|
||||
|
||||
protected:
|
||||
@ -42,8 +42,6 @@ class Route {
|
||||
std::string _index;
|
||||
std::map<std::string, std::string> *_cgi;
|
||||
|
||||
Logger *_log;
|
||||
|
||||
bool _methods[3]; ///> A methods boolean array which correspond to - 0: GET,
|
||||
///1: POST, 2: DELETE
|
||||
toml::ANode *_table;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 {
|
||||
public:
|
||||
Server(toml::ANode *, Logger *);
|
||||
Server(toml::ANode *);
|
||||
~Server();
|
||||
|
||||
/**
|
||||
@ -70,7 +70,6 @@ class Server {
|
||||
|
||||
toml::ANode *_table; ///> The table used for the parsing (is deleted at the
|
||||
/// end of the constructor)
|
||||
Logger *_log; ///> A pointer to the logger class
|
||||
|
||||
std::map<int, std::string> *
|
||||
_parseErrPages(std::map<std::string, toml::ANode *> *table);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
};
|
||||
|
||||
Logger *_log = NULL;
|
||||
|
||||
}; // namespace webserv
|
||||
|
@ -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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -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 :" +
|
||||
|
@ -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> *
|
||||
|
20
src/main.cpp
20
src/main.cpp
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user