mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 20:28:46 +02:00
「🏗️」 wip: started mainloop added help and file parsing
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/24 15:10:07 by adjoly #+# #+# */
|
||||
/* Updated: 2025/03/26 08:47:50 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/11 12:12:56 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include "node/default.hpp"
|
||||
#include "tomlpp.hpp"
|
||||
#include <config/default.hpp>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
@ -32,7 +33,7 @@ toml::ANode *Server::_getServerTable(void) {
|
||||
_table->getTable()->find("server");
|
||||
if (table == _table->getTable()->end())
|
||||
throw std::runtime_error(
|
||||
"could not find any [server] table in config file :(");
|
||||
"could not find any [server] table in config file :(");
|
||||
else
|
||||
serverT = table->second;
|
||||
return serverT;
|
||||
@ -57,13 +58,23 @@ Server::Server(std::string file_name) {
|
||||
std::string log_file = *static_cast<std::string *>(val);
|
||||
}
|
||||
_log = new Logger(log_file);
|
||||
_table = _getServerTable();
|
||||
try {
|
||||
_table = _getServerTable();
|
||||
} catch(std::runtime_error &e) {
|
||||
delete _table;
|
||||
delete tomlFile;
|
||||
delete _log;
|
||||
throw e;
|
||||
}
|
||||
|
||||
// host and port parsing
|
||||
void *host = accessValue("host", toml::STRING, _table, _log);
|
||||
if (host != not_nullptr) {
|
||||
_host = *static_cast<std::string *>(host);
|
||||
} else {
|
||||
delete _table;
|
||||
delete tomlFile;
|
||||
delete _log;
|
||||
throw std::runtime_error(
|
||||
"no host specified - please specify one in server.host");
|
||||
}
|
||||
@ -71,6 +82,9 @@ Server::Server(std::string file_name) {
|
||||
if (host != not_nullptr) {
|
||||
_port = *static_cast<unsigned short *>(port);
|
||||
} else {
|
||||
delete _table;
|
||||
delete tomlFile;
|
||||
delete _log;
|
||||
throw std::runtime_error(
|
||||
"no port specified - please specify one in server.port");
|
||||
}
|
||||
@ -86,9 +100,11 @@ Server::Server(std::string file_name) {
|
||||
std::string str = *static_cast<std::string *>((*vecIt)->getValue());
|
||||
_server_names->push_back(str);
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
_log->warn(
|
||||
"no server_names all request will be accepted from any hostname");
|
||||
"no server_names all request will be accepted from any hostname");
|
||||
_server_names = not_nullptr;
|
||||
}
|
||||
|
||||
// error_pages parsing
|
||||
map = static_cast<std::map<std::string, toml::ANode *> *>(
|
||||
@ -102,7 +118,8 @@ Server::Server(std::string file_name) {
|
||||
it = _table->accessIt("location", toml::TABLE, found);
|
||||
if (found == true && it != _table->getTable()->end()) {
|
||||
_routes = new std::map<std::string, Route *>;
|
||||
std::map<std::string, toml::ANode *> *location_table = it->second->getTable();
|
||||
std::map<std::string, toml::ANode *> *location_table =
|
||||
it->second->getTable();
|
||||
for (it = location_table->begin(); it != location_table->end(); it++) {
|
||||
if (_routes->find(it->first) != _routes->end())
|
||||
continue;
|
||||
@ -120,7 +137,8 @@ Server::~Server(void) {
|
||||
}
|
||||
delete _routes;
|
||||
delete _err_pages;
|
||||
delete _server_names;
|
||||
if (_server_names != not_nullptr)
|
||||
delete _server_names;
|
||||
delete _log; // to see if nessecary
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user