Files
42_INT_12_webserv/srcs/config/ConfigParser.hpp
LuckyLaszlo 400efbe720 Wip chunked decoding
+ Need to test normal body parsing
+ path_is_valid() renamed eval_file_type()
+ replaced atoi with strtol/strtoul
2022-08-12 05:50:00 +02:00

110 lines
2.5 KiB
C++

#ifndef CONFIGPARSER_HPP
# define CONFIGPARSER_HPP
# include "ServerConfig.hpp"
# include "LocationConfig.hpp"
# include "utils.hpp"
# include <map>
# include <vector>
# include <exception> // exception, what
# include <stdexcept> // runtime_error, invalid_argument
# include <string> // string
# 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
class ConfigParser {
public:
// canonical
ConfigParser(const char* path); // a string?
~ConfigParser();
// 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;
// explicit?
// what exaclty does explicit do again?
ConfigParser(); // might need a path as arg?
// 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?
// some sort of 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