well, restructured things a bit, but mostly started trying to sort LocationConfigs, it is sort of going well, good ideas, implementations is still a bit lacking...

This commit is contained in:
Me
2022-08-04 01:09:40 +02:00
parent b0c524a8bd
commit 3d46505411
13 changed files with 363 additions and 122 deletions

View File

@@ -16,7 +16,9 @@
# include <map>
# include <vector>
# include <string>
# include <iostream>
# include "utils.hpp"
// again, struct instead?
class LocationConfig
@@ -24,12 +26,18 @@ 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<std::string> index;
std::vector<http_method> allow_methods;
unsigned int allow_methods;
std::map<std::string, std::string> cgi_info;
// wait if i can call several times, shouldn't it be a map?
@@ -40,10 +48,57 @@ public:
// 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...
bool operator<(const LocationConfig& rhs) const
{
size_t len_lhs = 0;
size_t len_rhs = 0;
size_t tmp = 0;
// consider adding 1 to path that ends in a file not folder.
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 << (len_lhs < len_rhs) << "\n";
return (len_lhs < len_rhs); // right comparison ? not <= ?
};
};
// ok it needs to go somewhere else
#endif