#ifndef LOCATIONCONFIG_HPP # define LOCATIONCONFIG_HPP # include # include # include "utils.hpp" struct LocationConfig { std::string path; // /path and /path/ are fine // i remove trailing / systematically std::string root; std::vector index; unsigned int allow_methods; std::vector cgi_ext; // php not .php bool autoindex; std::string upload_dir; int redirect_status; // only in location std::string redirect_uri; // only 1 per location void print_all() const { std::cout << "\nPRINTING A LOCATION\n"; std::cout << "Path: " << path << '\n'; std::cout << "root: " << root << '\n'; std::cout << "autoindex: " << autoindex << '\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"; } bool operator<(const LocationConfig& rhs) const { int comp_lhs = 0; int comp_rhs = 0; size_t tmp = 0; while ((tmp = this->path.find_first_of("/", tmp)) != NPOS) { ++tmp; ++comp_lhs; } if (path[path.find_last_of("/") + 1] != '\0') ++comp_lhs; tmp = 0; while ((tmp = rhs.path.find_first_of("/", tmp)) != NPOS) { ++tmp; ++comp_rhs; } if (rhs.path[rhs.path.find_last_of("/") + 1] != '\0') ++comp_rhs; return (comp_lhs < comp_rhs); }; bool operator==(const LocationConfig& rhs) const { if (path.compare(rhs.path) == 0) return true; return false; } }; #endif