/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Route.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/19 14:59:41 by adjoly #+# #+# */ /* Updated: 2025/04/22 12:34:00 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #include #include #include #include #include #include #include #include namespace webserv { namespace config { class Route { public: Route(toml::ANode *); ~Route(void); bool getDirList(void) { return _dirlist; } bool getCookies(void) { return _cookies; } bool getRedirect(void) { return _redirect; } int32_t getMaxBody(void) { return _max_body; } std::string getRootDir(void) { return _root; } std::string getUpRoot(void) { return _up_root; } std::string getIndex(void) { return _index; } std::map *getCgi(void) { return _cgi; } bool *getMethods(void) { return _methods; } protected: private: bool _dirlist; bool _cookies; bool _redirect; int32_t _max_body; std::string _root; std::string _up_root; std::string _index; std::map *_cgi; bool _methods[3]; ///> A methods boolean array which correspond to - 0: GET, ///1: POST, 2: DELETE toml::ANode *_table; /** * @brief Can be used to parse a table of cgi * * @param The table to get cgi from * * @return A pointer to a map of cgi */ std::map * _parseCGI(toml::ANode *); /** * @brief Can be used to parse a table of error pages * * @param The table to get the error pages from * * @return A pointer to a map of error pages */ std::map * _parseErrPages(std::map *); /** * @brief Can be used to parse a array of methods * * @param The table to get the methods from */ void _parseMethods(std::vector *); /** * @brief Can be used to sed err pages to the default error pages */ void _defaultErrPages(void); /** * @brief Can be used to parse a string of a number with a size (ex. 10M) * * @param The input string * * @return The number in bytes */ int32_t _parseSize(std::string size) { if (size[size.size()] == 'M') return std::atoi(size.c_str()) * 1024 * 1024; if (size[size.size()] == 'K') return std::atoi(size.c_str()) * 1024; if (isalpha(size[size.size()])) return std::atoi(size.c_str()); return -1; } }; } // namespace config } // namespace webserv