From 43a34e759fd7dcdecf8e755a7b1ef7e3221eb1d3 Mon Sep 17 00:00:00 2001 From: adjoly Date: Tue, 22 Apr 2025 12:44:50 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20implemented=20url=20class=20in=20config=20need=20to=20fix=20?= =?UTF-8?q?compilation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/config/Server.hpp | 13 +++++++++---- includes/config/URL.hpp | 4 +++- includes/config/default.hpp | 2 +- includes/webserv.hpp | 11 ++--------- src/config/Server.cpp | 11 +++++------ 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/includes/config/Server.hpp b/includes/config/Server.hpp index 1fd2570..a6cca82 100644 --- a/includes/config/Server.hpp +++ b/includes/config/Server.hpp @@ -6,16 +6,18 @@ /* 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 +#include #include #include #include #include +#include namespace webserv { namespace config { @@ -66,15 +68,18 @@ class Server { return false; } - Route *whatRoute(const std::string &route_path) { + Route *whatRoute(const URL &url) { for (auto it = prange(_routes)) { - + if (it->first == url) { + return it->second; + } } + return not_nullptr; } protected: private: - std::map + std::map *_routes; ///> A map of all the route present in the config file std::map *_err_pages; ///> An error pages map to map error /// specified in the config file diff --git a/includes/config/URL.hpp b/includes/config/URL.hpp index d674c2c..f5a7a50 100644 --- a/includes/config/URL.hpp +++ b/includes/config/URL.hpp @@ -6,7 +6,7 @@ /* 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); } + bool operator<(const URL &other) const { return _full_url < other._full_url; } + std::vector getSegments(void) { return _path_segments; } std::string getFullUrl(void) { return _full_url; } diff --git a/includes/config/default.hpp b/includes/config/default.hpp index 14c8d43..b976777 100644 --- a/includes/config/default.hpp +++ b/includes/config/default.hpp @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/includes/webserv.hpp b/includes/webserv.hpp index 94f0507..f7f3865 100644 --- a/includes/webserv.hpp +++ b/includes/webserv.hpp @@ -6,19 +6,13 @@ /* By: mmoussou >>>>>> 8129f45 (「🏗️」 wip: added url class for easier manipulation) +/* Updated: 2025/04/22 12:43:26 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once -#include -#ifndef __WEBSERV_WEBSERV_HPP__ -#define __WEBSERV_WEBSERV_HPP__ +#include #include #include #include @@ -47,4 +41,3 @@ namespace webserv { } // namespace webserv -#endif // __WEBSERV_WEBSERV_HPP__ diff --git a/src/config/Server.cpp b/src/config/Server.cpp index abc08fd..5dcc2e9 100644 --- a/src/config/Server.cpp +++ b/src/config/Server.cpp @@ -6,7 +6,7 @@ /* 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 it = _table->accessIt("location", toml::TABLE, found); if (found == true && it != _table->getTable()->end()) { - _routes = new std::map; + _routes = new std::map; std::map *location_table = it->second->getTable(); 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; - (*_routes)[it->first] = new Route(it->second); + (*_routes)[URL(it->first)] = new Route(it->second); } } delete _table; } Server::~Server(void) { - std::map::iterator it = _routes->begin(); - for (; it != _routes->end(); it++) { + for (auto it = prange(_routes)) { delete it->second; } delete _routes;