diff --git a/includes/config/Route.hpp b/includes/config/Route.hpp index 8edddc4..777555b 100644 --- a/includes/config/Route.hpp +++ b/includes/config/Route.hpp @@ -6,13 +6,14 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/19 14:59:41 by adjoly #+# #+# */ -/* Updated: 2025/03/20 09:27:58 by adjoly ### ########.fr */ +/* Updated: 2025/03/21 11:09:38 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #include "cppeleven.hpp" +#include "log.hpp" #include "node/ANode.hpp" #include "node/Array.hpp" #include @@ -42,115 +43,6 @@ class Route { Route(std::map *node) { if (node == not_nullptr) throw std::runtime_error("location table does not exist"); - - _methods[0] = false; - _methods[1] = false; - _methods[2] = false; - - std::map::iterator it; - - it = (*node).find("redirect"); - if (it != node->end()) { - toml::ANode *redirNode = it->second; - if (redirNode->type() == toml::STRING) { - _redirect = true; - _root = *(std::string *)redirNode->getValue(); - _cookies = false; - _uploads = false; - _dirlist = false; - _cgi = not_nullptr; - _methods[0] = false; - _methods[1] = false; - _methods[2] = false; - _err_pages = not_nullptr; - _upRoot = not_nullptr; - return; - } - } - - it = (*node).find("uploads"); - if (it != node->end()) { - toml::ANode *uploadsNode = it->second; - if (uploadsNode->type() == toml::BOOL) - _uploads = *(bool *)uploadsNode->getValue(); - } - it = (*node).find("dirlist"); - if (it != node->end()) { - toml::ANode *dirlistNode = it->second; - if (dirlistNode->type() == toml::BOOL) - _dirlist = *(bool *)dirlistNode->getValue(); - } - it = (*node).find("cookies"); - if (it != node->end()) { - toml::ANode *cookiesNode = it->second; - if (cookiesNode->type() == toml::BOOL) - _cookies = *(bool *)cookiesNode->getValue(); - } - it = (*node).find("root"); - if (it != node->end()) { - toml::ANode *rootNode = it->second; - if (rootNode->type() == toml::STRING) - _root = *(std::string *)rootNode->getValue(); - } - it = (*node).find("client_max_body_size"); - if (it != node->end()) { - toml::ANode *rootNode = it->second; - if (rootNode->type() == toml::STRING) { - int32_t maxBody = - parseSize(*(std::string *)rootNode->getValue()); - if (maxBody != 0 && maxBody != -1) - _max_body = maxBody; - else { - std::cerr << "root size is not correctttt" - << std::endl; /// change that later TODO - _max_body = 10485760; - } - } - } - - it = (*node).find("methods"); - if (it != node->end()) { - toml::ANode *methodsNode = it->second; - if (methodsNode->type() == toml::ARRAY) { - std::vector::iterator methods = - methodsNode->getArray()->begin(); - for (; methods != methodsNode->getArray()->end(); methods++) { - if ((*methods)->type() == toml::STRING) { - std::string method = - *(std::string *)(*methods)->getValue(); - if (method == "GET") - _methods[0] = true; - else if (method == "POST") - _methods[1] = true; - else if (method == "DELETE") - _methods[2] = true; - else - throw std::runtime_error("da fuk that not a valid " - "methods bro"); // replace - // with - // warning - // log - } else { - throw std::runtime_error( - "error why did you put something elle than a " - "string"); // replace with log func - } - } - } - } - - it = (*node).find("error_pages"); - if (it != node->end()) { - toml::ANode *errorPagesNode = it->second; - // for loop on it and add to error pages and atoi the name of the - // page(need to be a deep copy) TODO - } - - it = (*node).find("cgi"); - if (it != node->end()) { - toml::ANode *cgiNode = it->second; - // for loop on it and add to cgi (need to be a deep copy) TODO - } } ~Route(void) {} @@ -167,6 +59,8 @@ class Route { std::string _upRoot; std::map *_cgi; + Logger *_log; + bool _methods[3]; // 1: GET, 2: POST, 3: DELETE std::map *_err_pages; }; diff --git a/includes/log.hpp b/includes/log.hpp index d863e80..755147d 100644 --- a/includes/log.hpp +++ b/includes/log.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/20 09:28:27 by adjoly #+# #+# */ -/* Updated: 2025/03/20 14:42:26 by adjoly ### ########.fr */ +/* Updated: 2025/03/20 14:55:09 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,14 +35,14 @@ class Logger { ~Logger(void) { _file.close(); } - void info(std::string &msg) { + void info(std::string msg) { std::stringstream ss = printPogitMsg("✏️", "webserv", "info", msg); std::cerr << ss << std::endl; if (!_ttyOnly) { _file << ss << std::endl; } } - void warn(std::string &msg) { + void warn(std::string msg) { std::stringstream ss = printPogitMsg("🔨", "webserv", "warning", msg); std::cerr << ss << std::endl; if (!_ttyOnly) { @@ -50,7 +50,7 @@ class Logger { } } - void error(std::string &msg) { + void error(std::string msg) { std::stringstream ss = printPogitMsg("🚧", "webserv", "error", msg); std::cerr << ss << std::endl; if (!_ttyOnly) {