mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 23:48:46 +02:00
「🏗️」 wip: implemented url class in config need to fix compilation
This commit is contained in:
@ -6,16 +6,18 @@
|
|||||||
/* 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/22 12:34:14 by adjoly ### ########.fr */
|
/* Updated: 2025/04/22 12:44:16 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <webserv.hpp>
|
||||||
#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>
|
#include <webserv.hpp>
|
||||||
|
#include <config/URL.hpp>
|
||||||
|
|
||||||
namespace webserv {
|
namespace webserv {
|
||||||
namespace config {
|
namespace config {
|
||||||
@ -66,15 +68,18 @@ class Server {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Route *whatRoute(const std::string &route_path) {
|
Route *whatRoute(const URL &url) {
|
||||||
for (auto it = prange(_routes)) {
|
for (auto it = prange(_routes)) {
|
||||||
|
if (it->first == url) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return not_nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
std::map<std::string, Route *>
|
std::map<URL, Route *>
|
||||||
*_routes; ///> A map of all the route present in the config file
|
*_routes; ///> A map of all the route present in the config file
|
||||||
std::map<int, std::string> *_err_pages; ///> An error pages map to map error
|
std::map<int, std::string> *_err_pages; ///> An error pages map to map error
|
||||||
/// specified in the config file
|
/// specified in the config file
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/22 12:17:48 by adjoly #+# #+# */
|
/* Created: 2025/04/22 12:17:48 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/04/22 12:26:21 by adjoly ### ########.fr */
|
/* Updated: 2025/04/22 12:42:21 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,6 +26,8 @@ class URL {
|
|||||||
return comparePathSegments(other);
|
return comparePathSegments(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator<(const URL &other) const { return _full_url < other._full_url; }
|
||||||
|
|
||||||
std::vector<std::string> getSegments(void) { return _path_segments; }
|
std::vector<std::string> getSegments(void) { return _path_segments; }
|
||||||
std::string getFullUrl(void) { return _full_url; }
|
std::string getFullUrl(void) { return _full_url; }
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/19 14:15:51 by adjoly #+# #+# */
|
/* Created: 2025/03/19 14:15:51 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/04/22 12:03:30 by mmoussou ### ########.fr */
|
/* Updated: 2025/04/22 12:40:20 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,19 +6,13 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/11 13:29:21 by mmoussou #+# #+# */
|
/* Created: 2025/02/11 13:29:21 by mmoussou #+# #+# */
|
||||||
<<<<<<< HEAD
|
/* Updated: 2025/04/22 12:43:26 by adjoly ### ########.fr */
|
||||||
/* Updated: 2025/04/22 11:54:13 by mmoussou ### ########.fr */
|
|
||||||
=======
|
|
||||||
/* Updated: 2025/04/22 12:32:23 by adjoly ### ########.fr */
|
|
||||||
>>>>>>> 8129f45 (「🏗️」 wip: added url class for easier manipulation)
|
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <sys/types.h>
|
|
||||||
#ifndef __WEBSERV_WEBSERV_HPP__
|
|
||||||
#define __WEBSERV_WEBSERV_HPP__
|
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -47,4 +41,3 @@ namespace webserv {
|
|||||||
|
|
||||||
} // namespace webserv
|
} // namespace webserv
|
||||||
|
|
||||||
#endif // __WEBSERV_WEBSERV_HPP__
|
|
||||||
|
@ -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/18 10:09:25 by adjoly ### ########.fr */
|
/* Updated: 2025/04/22 12:38:59 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -65,21 +65,20 @@ Server::Server(toml::ANode *node) : _table(node) {
|
|||||||
// location parsing
|
// location parsing
|
||||||
it = _table->accessIt("location", toml::TABLE, found);
|
it = _table->accessIt("location", toml::TABLE, found);
|
||||||
if (found == true && it != _table->getTable()->end()) {
|
if (found == true && it != _table->getTable()->end()) {
|
||||||
_routes = new std::map<std::string, Route *>;
|
_routes = new std::map<URL, Route *>;
|
||||||
std::map<std::string, toml::ANode *> *location_table =
|
std::map<std::string, toml::ANode *> *location_table =
|
||||||
it->second->getTable();
|
it->second->getTable();
|
||||||
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(URL(it->first)) != _routes->end())
|
||||||
continue;
|
continue;
|
||||||
(*_routes)[it->first] = new Route(it->second);
|
(*_routes)[URL(it->first)] = new Route(it->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete _table;
|
delete _table;
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::~Server(void) {
|
Server::~Server(void) {
|
||||||
std::map<std::string, Route *>::iterator it = _routes->begin();
|
for (auto it = prange(_routes)) {
|
||||||
for (; it != _routes->end(); it++) {
|
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
delete _routes;
|
delete _routes;
|
||||||
|
Reference in New Issue
Block a user