Files
42_INT_12_webserv/srcs/config/ConfigParser.hpp
2022-08-15 19:40:21 +02:00

70 lines
1.7 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:
ConfigParser(const char* path); // a string?
// might not need this either, ask Luke
~ConfigParser();
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:
std::string _content;
// not sure i even need this...
ConfigParser();
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);
/* Extra */
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;
};
#endif