changed client_body_limit (now in KB)
+ multiples little adjusts
This commit is contained in:
@@ -183,8 +183,11 @@ void Client::_parse_chunked_body(size_t pos)
|
||||
/* endptr_copy = endptr; */
|
||||
(void)endptr_copy;
|
||||
chunk_size = std::strtoul(&_request.body[pos], &endptr, 16);
|
||||
/* if (chunk_size == LONG_MAX && errno == ERANGE)
|
||||
status = 413; */
|
||||
if (errno == ERANGE)
|
||||
{
|
||||
status = 413;
|
||||
return ;
|
||||
}
|
||||
/* if (endptr == endptr_copy)
|
||||
{
|
||||
std::cerr << "parse_request_body(), no conversion possible\n";
|
||||
@@ -407,7 +410,7 @@ void Client::_parse_port_hostname(std::string host)
|
||||
|
||||
void Client::_check_request_errors()
|
||||
{
|
||||
std::cerr << "Content-Length=" << get_rq_headers("Content-Length") << "\n";
|
||||
std::cerr << "Content-Length=" << get_rq_headers("Content-Length") << "\n";
|
||||
std::cerr << "strtoul=" << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n";
|
||||
std::cerr << "client_body_limit=" << assigned_server->client_body_limit << "\n";
|
||||
///////////////////////
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -11,15 +11,8 @@ int main(int ac, char **av)
|
||||
{
|
||||
std::string config = (ac == 2 ? av[1] : "./default.config");
|
||||
|
||||
// like this just looks kinda gross, why bother creating an instance
|
||||
// and not immediately parsing? like it servers no other purpose...
|
||||
// what if i call parse directly in the constructor?
|
||||
// oh because the constructor has no return, but still
|
||||
// is there a better way?
|
||||
|
||||
ConfigParser configParser(config.c_str());
|
||||
|
||||
// configParser._print_content();
|
||||
ConfigParser configParser(config);
|
||||
// configParser.print_content();
|
||||
|
||||
// i don't love that servers has to be a pointer...
|
||||
std::vector<ServerConfig>* servers = configParser.parse();
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
# define CRLF CR LF
|
||||
# define CRLF_SIZE 2
|
||||
# define NPOS std::string::npos
|
||||
# define KB 1024
|
||||
# define MB 1048576
|
||||
|
||||
/* Equivalent for end of http header size :
|
||||
** std::string(CRLF CRLF).size();
|
||||
|
||||
@@ -39,7 +39,7 @@ void Webserv::_get(Client *client, std::string &path)
|
||||
_get_file(client, path);
|
||||
}
|
||||
|
||||
# define MAX_FILESIZE 1000000 // (1Mo)
|
||||
# define MAX_FILESIZE 1 * MB
|
||||
void Webserv::_get_file(Client *client, const std::string &path)
|
||||
{
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user