93 lines
2.3 KiB
C++
93 lines
2.3 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ConfigParser.hpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: me <erlazo@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/07/11 23:01:41 by me #+# #+# */
|
|
/* Updated: 2022/07/27 19:27:57 by me ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef CONFIGPARSER_HPP
|
|
# define CONFIGPARSER_HPP
|
|
|
|
# include "Webserv.hpp" // easier to just do this?
|
|
// add includes properly
|
|
|
|
|
|
// This is gonna be temporary cuz i don't konw if i like it
|
|
#define MAX_REQUEST_SIZE 2048
|
|
#define MAX_URI_SIZE 64
|
|
#define BSIZE 1024
|
|
|
|
enum MethodType
|
|
{
|
|
GET,
|
|
POST,
|
|
DELETE,
|
|
INVALID,
|
|
};
|
|
|
|
|
|
|
|
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<Server> * parse(); // const?
|
|
std::vector<ServerConfig> parse(); // const?
|
|
|
|
// other parses?
|
|
|
|
|
|
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 _get_first_word(size_t *curr); // const?
|
|
std::string _get_rest_of_line(size_t *curr); // const?
|
|
|
|
|
|
// why static? it's an enum...
|
|
static MethodType _str_to_method_type(std::string str);
|
|
|
|
// just for testing purposes
|
|
void _print_content() const;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|