🏗️」 wip: new config should be working

This commit is contained in:
2025-04-14 13:25:20 +02:00
parent c21612d873
commit 81b837eceb
6 changed files with 104 additions and 87 deletions

View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Config.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/14 12:20:06 by adjoly #+# #+# */
/* Updated: 2025/04/14 12:55:46 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include "config/default.hpp"
namespace webserv {
namespace config {
class Config {
public:
Config(std::string &);
~Config();
Logger *getLogger(void) { return _log; }
std::vector<Server *> *getServers(void) { return _servers; }
private:
toml::ANode *_table;
Logger *_log;
std::vector<Server *> *_servers;
};
}; // namespace config
}; // namespace webserv

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 14:11:28 by adjoly #+# #+# */
/* Updated: 2025/03/25 17:56:34 by adjoly ### ########.fr */
/* Updated: 2025/04/14 12:39:17 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@ namespace config {
class Server {
public:
Server(std::string);
Server(toml::ANode *, Logger *);
~Server();
/**
@ -48,11 +48,6 @@ class Server {
return not_nullptr;
}
/**
* @brief Can be used to get the Logger pointer
*/
Logger *getLogger(void) { return _log; }
// @brief Can be used to get a server name
std::vector<std::string> *getServerNames(void) { return _server_names; }
// @brief Can be used to get the host specified in the config file
@ -79,13 +74,6 @@ class Server {
std::map<int, std::string> *
_parseErrPages(std::map<std::string, toml::ANode *> *table);
/**
* @brief Can be used to get the [server] table in _table
*
* @return A pointer to the [server] table as an ANode
*/
toml::ANode *_getServerTable(void);
};
} // namespace config

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 14:15:51 by adjoly #+# #+# */
/* Updated: 2025/03/26 08:39:08 by adjoly ### ########.fr */
/* Updated: 2025/04/14 12:54:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
#include "Route.hpp"
#include "Server.hpp"
#include "Config.hpp"
#include "cppeleven.hpp"
#include "node/Table.hpp"
#include "node/default.hpp"

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/20 09:28:27 by adjoly #+# #+# */
/* Updated: 2025/04/11 15:49:38 by adjoly ### ########.fr */
/* Updated: 2025/04/14 13:03:31 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,8 +25,7 @@ namespace webserv {
*
* @note Only work if VERBOSE mode is active
*/
static inline void log(std::string emoji, std::string who,
std::string str) {
static inline void log(std::string emoji, std::string who, std::string str) {
#ifdef VERBOSE
if (who.empty())
std::cout << "" << emoji << "」debug: " << str << std::endl;
@ -40,18 +39,17 @@ static inline void log(std::string emoji, std::string who,
class Logger {
public:
Logger(void) : _ttyOnly(true) {
log("", "Logger", "default constructor called");
}
Logger(const std::string &fileName) : _fileName(fileName) {
log("", "Logger", "filename constructor called");
if (fileName.empty()) {
_file.open(fileName.c_str(), std::ios::app);
if (!_file.is_open() && !_ttyOnly) {
_ttyOnly = true;
} else {
_file.open(fileName.c_str(), std::ios::app);
if (!_file.is_open() && !_ttyOnly) {
_ttyOnly = true;
warn("could not open log file, going tty only");
} else
_ttyOnly = false;
}
warn("could not open log file, going tty only");
} else
_ttyOnly = false;
}
Logger(const Logger &other) : _ttyOnly(other._ttyOnly) {