/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* LocationConfig.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/23 16:08:00 by me #+# #+# */ /* Updated: 2022/08/04 01:40:40 by me ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef LOCATIONCONFIG_HPP # define LOCATIONCONFIG_HPP # include # include # include # include # include "utils.hpp" // again, struct instead? class LocationConfig { public: // canonic stuff? // i thought this might fix the "non static member function" // shit i'm getting with the comparator... LocationConfig() {} ~LocationConfig() {} std::string path; int client_body_limit; std::string root; std::vector index; unsigned int allow_methods; std::map cgi_info; // wait if i can call several times, shouldn't it be a map? // wait no there can only be 1 and i think it might have to be in // location only... int redirect_status; std::string redirect_uri; // au pire you do location / { return 301 http://location; } // and that's how you get the redirect from the root. void print_all() { std::cout << "\nPRINTING A LOCATION\n"; std::cout << "Path: " << path << '\n'; std::cout << "client_body_limit: " << client_body_limit << '\n'; std::cout << "root: " << root << '\n'; std::cout << "Skipping index...\n"; std::cout << "Location allow_methods: "; std::cout << ::http_methods_to_str(allow_methods) << "\n"; std::cout << "Skipping redirect status etc...\n"; std::cout << "------\n"; } // works a lot better than using a compare function... // but it still doesn't work... // problem is the logic bool operator<(const LocationConfig& rhs) const { // size_t len_lhs = 0; // size_t len_rhs = 0; int len_lhs = 0; int len_rhs = 0; // size_t tmp = 0; // consider adding 1 to path that ends in a file not folder. // What are the rules... // / is smaller than /test // and /test/test1 is bigger than test // so we want to count / // len_lhs = _count_chars(this->path); // len_rhs = _count_chars(rhs.path); const char *tmp1 = this->path.c_str(); size_t i = 0; while (tmp1[i]) { if (tmp1[i] == '/') ++len_lhs; ++i; } const char *tmp2 = rhs.path.c_str(); i = 0; while (tmp2[i]) { if (tmp2[i] == '/') ++len_rhs; ++i; } /* while ((tmp = this->path.find_first_of("/", tmp)) != std::string::npos) { std::cout << "tmp_lhs: " << tmp << "\n"; ++tmp; ++len_lhs; } tmp = 0; while ((tmp = rhs.path.find_first_of("/", tmp)) != std::string::npos) { std::cout << "tmp_rhs: " << tmp << "\n"; ++tmp; ++len_rhs; } */ std::cout << "len_lhs: " << len_lhs << " len_rhs: " << len_rhs \ << " bool res: " << (len_lhs > len_rhs) << "\n"; // i honestly can't tell you how or why but using > rather than < // fixed all my problems // the fact that the bool was always 0 before, and the correct order // i want... super weird... return (len_lhs > len_rhs); // right comparison ? not <= ? }; /* size_t _count_chars(std::string str) { const char *tmp = str.c_str(); size_t i = 0; size_t count = 0; while (i < str.lenght()) { if (tmp[i] == '/') ++count; ++i; } return (count); } */ }; // ok it needs to go somewhere else #endif