changed client_body_limit (now in KB)

+ multiples little adjusts
This commit is contained in:
lperrey
2022-08-15 02:14:27 +02:00
parent 9ac84f706d
commit a284e400c1
12 changed files with 48 additions and 127 deletions

View File

@@ -14,8 +14,6 @@
# include <cstdlib> // strtol, stroul
# include <iostream> // cout, cin
# include <fstream> // ifstream
//# include <unistd.h> // access()
# include <dirent.h> // opendir(), doesn't work...
# include <sys/stat.h> // stat(), replaces opendir() don't bother with ERRNO ?
# include <algorithm> // sort() in Post
@@ -23,21 +21,17 @@ class ConfigParser {
public:
// canonical?
ConfigParser(const char* path); // a string?
ConfigParser();
~ConfigParser();
ConfigParser(const std::string &config_file);
// ideally i wouldn't have one cuz it makes no sense, when would i use it?
// ConfigParser & operator=(const ConfigParser& rhs);
void read_config(const std::string &config_file);
std::vector<ServerConfig> * parse(); // const?
// std::vector<ServerConfig> parse(); // const?
// i thought if it were an instance of this class you could call
// private member functions from anywhere...
void _print_content() const;
// private member functions from anywhere... // QUESTION : Wut ?
void print_content() const;
private:
@@ -45,25 +39,22 @@ private:
// explicit?
// what exaclty does explicit do again?
ConfigParser(); // might need a path as arg?
// ConfigParser();
// should this be in private since it always needs a path?
ServerConfig _parse_server(size_t *start);
LocationConfig _parse_location(size_t *start);
void _set_server_values(ServerConfig *server, const std::string key, std::string value);
void _set_location_values(LocationConfig *location, const std::string key, std::string value);
std::string _pre_set_val_check(const std::string key, \
const std::string value);
std::string _get_first_word(size_t *curr); // const?
std::string _get_rest_of_line(size_t *curr); // const?
/* Post Processing */
void _post_processing(std::vector<ServerConfig> *servers);
bool _find_root_path_location(std::vector<LocationConfig> locations); // const?

View File

@@ -1,32 +1,14 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* LocationConfig.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/23 16:08:00 by me #+# #+# */
/* Updated: 2022/08/12 18:12:23 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LOCATIONCONFIG_HPP
# define LOCATIONCONFIG_HPP
# include <map>
# include <vector>
# include <string>
# include <iostream>
# include <sys/stat.h> // stat()
# include "utils.hpp"
// again, struct instead?
class LocationConfig
struct LocationConfig
{
public:
// canonic stuff?
std::string path; // /path and /path/ are fine
// i remove trailing / systematically
std::string root;
@@ -87,13 +69,4 @@ public:
};
#endif

View File

@@ -10,14 +10,9 @@
# include <string> // string
# include <iostream> // cout, cin
// a class that's all public? just so we have options?
class ServerConfig
struct ServerConfig
{
public:
// do i need some canonic stuff?
std::vector<std::string> server_name;
// we could shove default in here if we wanted to...
std::string host;
std::string port;
@@ -25,9 +20,7 @@ public:
std::string root; // ./www/ or www work www/ and www work
// i do remove trailing / tho
size_t client_body_limit; // set to default max if none set
// 413 (Request Entity Too Large) if exceeded
// default is 1m 1 000 000 ?
size_t client_body_limit;
std::vector<std::string> index;
std::map<int, std::string> error_pages;

View File

@@ -1,6 +1,4 @@
#include "ConfigParser.hpp"
// should i be sending & references?
@@ -63,7 +61,7 @@ std::string ConfigParser::_get_rest_of_line(size_t *curr)
}
void ConfigParser::_print_content() const
void ConfigParser::print_content() const
{
std::cout << _content;
}

View File

@@ -1,25 +1,26 @@
#include "ConfigParser.hpp"
// Default
ConfigParser::ConfigParser()
ConfigParser::ConfigParser() {};
ConfigParser::~ConfigParser() {};
ConfigParser::ConfigParser(const std::string &config_file)
{
std::cout << "Default Constructor\n";
// don't use yet, you have no idea what the defaults are
read_config(config_file);
}
ConfigParser::ConfigParser(const char* path)
void ConfigParser::read_config(const std::string &config_file)
{
// std::cout << "Param Constructor\n";
std::ifstream file;
std::string buf;
size_t comment;
_content.clear();
file.open(path);
if (file.is_open())
file.open(config_file.c_str());
if (!file)
throw std::invalid_argument("failed to open config");
else
{
_content.clear();
while (!file.eof())
{
getline(file, buf);
@@ -37,28 +38,9 @@ ConfigParser::ConfigParser(const char* path)
_content.append(tmp + '\n');
}
}
file.close();
}
else
throw std::invalid_argument("failed to open config");
}
ConfigParser::~ConfigParser()
{
// do i need to destroy anything, won't it handle itself?
}
/*
ConfigParser & ConfigParser::operator=(const ConfigParser& rhs)
{
if (this == rhs) // * & ?
return (*this); // * ?
// make some stuff equal
return (*this);
}
*/
// const?
std::vector<ServerConfig> * ConfigParser::parse()
{
@@ -190,7 +172,7 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
server->server_name.push_back(tmp_val[0]);
}
else if (key == "listen" && size == 1 && server->host == "" \
&& server->port == "")
&& server->port == "") // QUESTION LUKE : C'est quoi cette condition ? Si listen est vide ? Je comprends pas trop.
{
if (tmp_val[0].find_first_of(":") == NPOS)
{
@@ -231,6 +213,9 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
if (!::isNumeric(tmp_val[0]))
throw std::invalid_argument("client_body_limit not a number");
server->client_body_limit = std::strtoul(tmp_val[0].c_str(), NULL, 10);
if (errno == ERANGE || server->client_body_limit > (ULONG_MAX / KB) )
throw std::invalid_argument("client_body_limit too big");
server->client_body_limit = server->client_body_limit * KB;
}
else if (key == "index")
{

View File

@@ -22,7 +22,7 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
throw std::invalid_argument("Config file needs an Index");
if (it->client_body_limit == 0)
it->client_body_limit = 5000; // what is the recomended size?
it->client_body_limit = 1 * MB;
// if error_pages is left empty, we'll use the defaults which