clean up
This commit is contained in:
@@ -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<ServerConfig> * parse(); // const?
|
||||
// std::vector<ServerConfig> 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<ServerConfig> *servers);
|
||||
|
||||
bool _find_root_path_location(std::vector<LocationConfig> 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
|
||||
@@ -19,9 +19,6 @@
|
||||
# include <iostream>
|
||||
# include <sys/stat.h> // stat()
|
||||
|
||||
# include <stdio.h> // 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<std::string> 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";
|
||||
|
||||
|
||||
@@ -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<std::string> index;
|
||||
std::map<int, std::string> error_pages;
|
||||
@@ -33,7 +35,7 @@ public:
|
||||
std::vector<LocationConfig> locations;
|
||||
|
||||
|
||||
void print_all()
|
||||
void print_all() // const?
|
||||
{
|
||||
std::cout << "PRINTING A FULL SERVER CONFIG\n\n";
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
|
||||
// prolly get rid of this file...
|
||||
|
||||
|
||||
#include "LocationConfig.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
// 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 <= ?
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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<ServerConfig> * ConfigParser::parse()
|
||||
{
|
||||
std::vector<ServerConfig> * ret = new std::vector<ServerConfig>();
|
||||
// std::vector<ServerConfig> ret;
|
||||
|
||||
size_t start = 0;
|
||||
size_t curr = _content.find_first_not_of(" \t\n", 0);
|
||||
|
||||
@@ -73,17 +73,15 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
|
||||
}
|
||||
}
|
||||
|
||||
// const?
|
||||
bool ConfigParser::_find_root_path_location(std::vector<LocationConfig> locations)
|
||||
{
|
||||
std::vector<LocationConfig>::iterator it = locations.begin();
|
||||
std::vector<LocationConfig>::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;
|
||||
|
||||
@@ -25,6 +25,4 @@
|
||||
"</body>"\
|
||||
"</html>"
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -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 ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,7 @@ ServerConfig *_determine_process_server(Client *client, std::vector<ServerConfig
|
||||
return (&(*default_server));
|
||||
}
|
||||
|
||||
// const?
|
||||
// Temporary Global Scope. Probably move to Client in the future.
|
||||
const LocationConfig *_determine_location(const ServerConfig &server, const std::string &path)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user