mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 21:08:45 +02:00
「✨」 feat: added getserver in config to get a server from a server_name
This commit is contained in:
@ -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/18 10:03:09 by adjoly ### ########.fr */
|
/* Updated: 2025/04/22 10:57:26 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,10 +24,11 @@ class Config {
|
|||||||
|
|
||||||
Logger *getLogger(void) { return _log; }
|
Logger *getLogger(void) { return _log; }
|
||||||
|
|
||||||
std::vector<Server *> *getServers(void) { return _servers; }
|
std::vector<Server *> getServers(void) { return _servers; }
|
||||||
|
Server *getServer(const std::string &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Server *> *_servers;
|
std::vector<Server *> _servers;
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace config
|
}; // namespace config
|
||||||
|
@ -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/18 10:08:33 by adjoly ### ########.fr */
|
/* Updated: 2025/04/22 10:59:27 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,6 +15,7 @@
|
|||||||
#include "config/default.hpp"
|
#include "config/default.hpp"
|
||||||
#include "cppeleven.hpp"
|
#include "cppeleven.hpp"
|
||||||
#include "node/ANode.hpp"
|
#include "node/ANode.hpp"
|
||||||
|
#include "webserv.hpp"
|
||||||
|
|
||||||
namespace webserv {
|
namespace webserv {
|
||||||
namespace config {
|
namespace config {
|
||||||
@ -55,6 +56,16 @@ class Server {
|
|||||||
// @brief Can be used to get the port specified in the config file
|
// @brief Can be used to get the port specified in the config file
|
||||||
int getPort(void) { return _port; }
|
int getPort(void) { return _port; }
|
||||||
|
|
||||||
|
// @brief Can be used to check if a servername is present in this config
|
||||||
|
bool isServerName(const std::string &server_name) {
|
||||||
|
for (auto it = prange(_server_names)) {
|
||||||
|
if (*it == server_name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
std::map<std::string, Route *>
|
std::map<std::string, Route *>
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
/* 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/18 10:21:36 by adjoly ### ########.fr */
|
/* Updated: 2025/04/22 11:11:26 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cppeleven.hpp"
|
||||||
#include "node/ANode.hpp"
|
#include "node/ANode.hpp"
|
||||||
#include <config/default.hpp>
|
#include <config/default.hpp>
|
||||||
|
#include <webserv.hpp>
|
||||||
|
|
||||||
using namespace webserv::config;
|
using namespace webserv::config;
|
||||||
|
|
||||||
@ -30,19 +32,25 @@ Config::Config(std::string &filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, toml::ANode *> *node = table->getTable();
|
std::map<std::string, toml::ANode *> *node = table->getTable();
|
||||||
for (std::map<std::string, toml::ANode *>::iterator it = node->begin();
|
for (auto it = prange(node)) {
|
||||||
it != node->end(); it++) {
|
|
||||||
Server *srv = new Server(it->second);
|
Server *srv = new Server(it->second);
|
||||||
_servers->push_back(srv);
|
_servers.push_back(srv);
|
||||||
}
|
}
|
||||||
delete table;
|
delete table;
|
||||||
delete file;
|
delete file;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::~Config(void) {
|
Config::~Config(void) {
|
||||||
std::vector<Server *>::iterator it = _servers->begin();
|
for (auto it = range(_servers)) {
|
||||||
for (; it != _servers->end() ; it++) {
|
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
delete _servers;
|
}
|
||||||
|
|
||||||
|
Server *Config::getServer(const std::string &server_name) {
|
||||||
|
for (auto it = range(_servers)) {
|
||||||
|
if ((*it)->isServerName(server_name)) {
|
||||||
|
return (*it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (not_nullptr);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user