diff --git a/srcs/config/ConfigParser.hpp b/srcs/config/ConfigParser.hpp index 32197eb..6632c4d 100644 --- a/srcs/config/ConfigParser.hpp +++ b/srcs/config/ConfigParser.hpp @@ -34,7 +34,7 @@ class ConfigParser { public: - // canonical + // canonical? ConfigParser(const char* path); // a string? ~ConfigParser(); @@ -42,23 +42,15 @@ public: // ideally i wouldn't have one cuz it makes no sense, when would i use it? // ConfigParser & operator=(const ConfigParser& rhs); -// void parse(); // return void cuz throw exceptions. std::vector * parse(); // const? // std::vector parse(); // const? - // other parses? // i thought if it were an instance of this class you could call // private member functions from anywhere... void _print_content() const; -// I don't love that this is here but... -// doesn't work use the operator overload -// bool compareLocationConfigs(const LocationConfig &a, const LocationConfig &b); - - - private: std::string _content; @@ -83,38 +75,10 @@ private: std::string _get_rest_of_line(size_t *curr); // const? - - - - // some sort of post processing... - +/* Post Processing */ void _post_processing(std::vector *servers); - bool _find_root_path_location(std::vector locations); // const? - }; - -// no idea if it should go here... -//bool compareLocationConfigs(const LocationConfig &a, -// const LocationConfig &b); - - - - - -// def needs work line a better name an do i even need this? -// should it be in Utils instead? -class MyException : public std::invalid_argument -{ - MyException(const std::string str) - : std::invalid_argument(str) {} -}; - - -#endif - - - - +#endif \ No newline at end of file diff --git a/srcs/config/LocationConfig.hpp b/srcs/config/LocationConfig.hpp index b6b5b3e..8168eea 100644 --- a/srcs/config/LocationConfig.hpp +++ b/srcs/config/LocationConfig.hpp @@ -19,9 +19,6 @@ # include # include // stat() -# include // printf(), gotta go - - # include "utils.hpp" // again, struct instead? @@ -31,7 +28,7 @@ public: // canonic stuff? std::string path; // /path and /path/ are fine - // i add trailing / if a dir + // i remove trailing / systematically std::string root; std::vector index; unsigned int allow_methods; @@ -42,10 +39,8 @@ public: int redirect_status; // only in location std::string redirect_uri; // only 1 per location - // au pire you do location / { return 301 http://location; } - // and that's how you get the redirect from the root. - void print_all() + void print_all() // const? { std::cout << "\nPRINTING A LOCATION\n"; diff --git a/srcs/config/ServerConfig.hpp b/srcs/config/ServerConfig.hpp index c0feecf..3ba3548 100644 --- a/srcs/config/ServerConfig.hpp +++ b/srcs/config/ServerConfig.hpp @@ -20,12 +20,14 @@ public: // we could shove default in here if we wanted to... std::string host; - std::string port; // port needs to be something else... not quite an int + std::string port; std::string root; // ./www/ or www work www/ and www work // i do remove trailing / tho unsigned int client_body_limit; // set to default max if none set + // 413 (Request Entity Too Large) if exceeded + // default is 1m 1 000 000 ? std::vector index; std::map error_pages; @@ -33,7 +35,7 @@ public: std::vector locations; - void print_all() + void print_all() // const? { std::cout << "PRINTING A FULL SERVER CONFIG\n\n"; diff --git a/srcs/config/compareLocationConfigs.cpp b/srcs/config/compareLocationConfigs.cpp deleted file mode 100644 index 8851968..0000000 --- a/srcs/config/compareLocationConfigs.cpp +++ /dev/null @@ -1,27 +0,0 @@ - - -// prolly get rid of this file... - - -#include "LocationConfig.hpp" - -#include -#include - -// Ok so maybe it can't be a member functions? -bool compareLocationConfigs(const LocationConfig &a, const LocationConfig &b) -{ - int len_a; - int len_b; - size_t tmp = 0; - - // consider adding 1 to path that ends in a file not folder. - - - while ((tmp = a.path.find_first_of("/", tmp)) != std::string::npos) - ++len_a; - tmp = 0; - while ((tmp = b.path.find_first_of("/", tmp)) != std::string::npos) - ++len_b; - return (len_a < len_b); // right comparison ? not <= ? -} diff --git a/srcs/config/extraConfig.cpp b/srcs/config/extraConfig.cpp index 747e2cd..25a1bdf 100644 --- a/srcs/config/extraConfig.cpp +++ b/srcs/config/extraConfig.cpp @@ -3,8 +3,8 @@ #include "ConfigParser.hpp" - - +// should i be sending & references? +// const? std::string ConfigParser::_pre_set_val_check(const std::string key, \ const std::string value) { @@ -16,12 +16,8 @@ std::string ConfigParser::_pre_set_val_check(const std::string key, \ if (key.find_first_of(";") != std::string::npos) throw std::invalid_argument("bad config file arguments 2"); - // there shouldn't be any tabs, right? not between values... if (value.find_first_of("\t") != std::string::npos) - { -// std::cout << value << "\n"; throw std::invalid_argument("why would you put tabs between values"); - } size_t i = value.find_first_of(";"); // so you can't have no ; @@ -36,25 +32,22 @@ std::string ConfigParser::_pre_set_val_check(const std::string key, \ return (value.substr(0, i)); } - - +// const? // assumes curr is on a space or \t or \n -// get first word? next word? word? std::string ConfigParser::_get_first_word(size_t *curr) { size_t start; -// are these checks excessive? if ((start = _content.find_first_not_of(" \t\n", *curr)) == std::string::npos) throw std::invalid_argument("bad config file arguments"); if ((*curr = _content.find_first_of(" \t\n", start)) == std::string::npos) throw std::invalid_argument("bad config file arguments"); std::string key = _content.substr(start, *curr - start); - return (key); } +// const? // also assumes curr is on a space \t or \n std::string ConfigParser::_get_rest_of_line(size_t *curr) { @@ -62,7 +55,6 @@ std::string ConfigParser::_get_rest_of_line(size_t *curr) if ((start = _content.find_first_not_of(" \t\n", *curr)) == std::string::npos) throw std::invalid_argument("bad config file arguments"); - if ((*curr = _content.find_first_of("\n", start)) == std::string::npos) throw std::invalid_argument("bad config file arguments"); @@ -71,8 +63,6 @@ std::string ConfigParser::_get_rest_of_line(size_t *curr) } - - void ConfigParser::_print_content() const { std::cout << _content; diff --git a/srcs/config/parser.cpp b/srcs/config/parser.cpp index fe47799..77015a3 100644 --- a/srcs/config/parser.cpp +++ b/srcs/config/parser.cpp @@ -10,7 +10,7 @@ ConfigParser::ConfigParser() ConfigParser::ConfigParser(const char* path) { - std::cout << "Param Constructor\n"; +// std::cout << "Param Constructor\n"; std::ifstream file; std::string buf; @@ -59,11 +59,10 @@ ConfigParser & ConfigParser::operator=(const ConfigParser& rhs) } */ - +// const? std::vector * ConfigParser::parse() { std::vector * ret = new std::vector(); -// std::vector ret; size_t start = 0; size_t curr = _content.find_first_not_of(" \t\n", 0); diff --git a/srcs/config/postProcessing.cpp b/srcs/config/postProcessing.cpp index bfc3a29..aaa99bd 100644 --- a/srcs/config/postProcessing.cpp +++ b/srcs/config/postProcessing.cpp @@ -73,17 +73,15 @@ void ConfigParser::_post_processing(std::vector *servers) } } +// const? bool ConfigParser::_find_root_path_location(std::vector locations) { - std::vector::iterator it = locations.begin(); + std::vector::const_iterator it = locations.begin(); while (it != locations.end()) { if (it->path.compare("/") == 0) - { - // std::cout << "in compare: " << it->path << " -- "; return true; - } ++it; } return false; diff --git a/srcs/webserv/autoindex.hpp b/srcs/webserv/autoindex.hpp index 7138a7a..66e4764 100644 --- a/srcs/webserv/autoindex.hpp +++ b/srcs/webserv/autoindex.hpp @@ -25,6 +25,4 @@ ""\ "" - - -#endif +#endif \ No newline at end of file diff --git a/srcs/webserv/method_get.cpp b/srcs/webserv/method_get.cpp index 12b5751..ceb25d1 100644 --- a/srcs/webserv/method_get.cpp +++ b/srcs/webserv/method_get.cpp @@ -1,7 +1,7 @@ #include "Webserv.hpp" -// TODO : path_is_valid() Macro for return value +// const? void Webserv::_get(Client *client) { std::string path = client->get_rq_abs_path(); @@ -114,6 +114,7 @@ void Webserv::_get_file(Client *client, const std::string &path) } } +// const? void Webserv::_autoindex(Client *client, std::string &path) { std::cout << "made it to _autoindex\n"; @@ -162,9 +163,8 @@ void Webserv::_autoindex(Client *client, std::string &path) else { // in theory not possible cuz we already checked... - /* could not open directory */ -// perror (""); - std::cout << "could not open dir\n"; + std::cerr << "could not open dir\n"; + // throw? return ; } } diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 7540cdf..a2c459d 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -169,6 +169,7 @@ ServerConfig *_determine_process_server(Client *client, std::vector