mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
feat(parser): get config file from arg
This commit is contained in:
2
Makefile
2
Makefile
@@ -41,6 +41,6 @@ re:
|
|||||||
$(MAKE) all
|
$(MAKE) all
|
||||||
|
|
||||||
run: $(NAME)
|
run: $(NAME)
|
||||||
ASAN_OPTIONS=detect_leaks=0 ./$(NAME)
|
ASAN_OPTIONS=detect_leaks=0 ./$(NAME) $(filter-out $@,$(MAKECMDGOALS))
|
||||||
|
|
||||||
.PHONY: all clean fclean re
|
.PHONY: all clean fclean re
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ void Server::print_epoll_events(unsigned int events)
|
|||||||
//----------------------------------------------Send--------------------------------------------------------------------------------------------
|
//----------------------------------------------Send--------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
//----------------------------------------------Configuration-----------------------------------------------------------------------------------
|
//----------------------------------------------Configuration-----------------------------------------------------------------------------------
|
||||||
void Server::readConfig(void)
|
void Server::readConfig(char *filename)
|
||||||
{
|
{
|
||||||
TOMLMap *root = parse();
|
TOMLMap *root = parse(filename);
|
||||||
|
|
||||||
|
|
||||||
/* TOMLMap *map; */
|
/* TOMLMap *map; */
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class Server
|
|||||||
Server();
|
Server();
|
||||||
Server(std::string path);
|
Server(std::string path);
|
||||||
|
|
||||||
void readConfig(void);
|
void readConfig(char *filename);
|
||||||
void setupConfig(void);
|
void setupConfig(void);
|
||||||
void start(void);
|
void start(void);
|
||||||
void end(void);
|
void end(void);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
namespace config
|
namespace config
|
||||||
{
|
{
|
||||||
|
|
||||||
TOMLParser::TOMLParser(const std::string filename) : tokenizer(filename)
|
TOMLParser::TOMLParser(char *filename) : tokenizer(filename)
|
||||||
{};
|
{};
|
||||||
|
|
||||||
void TOMLParser::processMap(void)
|
void TOMLParser::processMap(void)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace config
|
|||||||
toml_node *map_node, toml_node::e_type type);
|
toml_node *map_node, toml_node::e_type type);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TOMLParser(const std::string filename);
|
TOMLParser(char *filename);
|
||||||
TOMLMap *parse(void);
|
TOMLMap *parse(void);
|
||||||
|
|
||||||
toml_node *parseMap(void);
|
toml_node *parseMap(void);
|
||||||
|
|||||||
@@ -38,12 +38,13 @@ namespace config
|
|||||||
else
|
else
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
Tokenizer::Tokenizer(std::string filename)
|
Tokenizer::Tokenizer(char *filename)
|
||||||
{
|
{
|
||||||
file.open(filename.c_str(), std::ios::in);
|
file.open(filename, std::ios::in);
|
||||||
if (!file.good())
|
if (!file.good())
|
||||||
{
|
{
|
||||||
std::cerr << "file didn't open" << std::endl;
|
std::cerr << "file didn't open" << std::endl;
|
||||||
|
throw std::logic_error("file didnt open");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Tokenizer::firstToken()
|
bool Tokenizer::firstToken()
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace config
|
|||||||
e_token last_token;
|
e_token last_token;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Tokenizer(std::string filename);
|
Tokenizer(char *filename);
|
||||||
char getWithoutWhiteSpace();
|
char getWithoutWhiteSpace();
|
||||||
struct s_token getToken();
|
struct s_token getToken();
|
||||||
bool hasMoreTokens();
|
bool hasMoreTokens();
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ namespace config
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TOMLMap *parse(void)
|
TOMLMap *parse(char *filename)
|
||||||
{
|
{
|
||||||
std::string filename = "config/tester.toml";
|
// std::string fiцename = "config/simple.toml";
|
||||||
config::TOMLParser parser(filename);
|
config::TOMLParser parser(filename);
|
||||||
TOMLMap *root = parser.parse();
|
TOMLMap *root = parser.parse();
|
||||||
/* config::display(root); */
|
/* config::display(root); */
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "TOMLNode.hpp"
|
#include "TOMLNode.hpp"
|
||||||
#include "TOMLParser.hpp"
|
#include "TOMLParser.hpp"
|
||||||
|
|
||||||
TOMLMap *parse(void);
|
TOMLMap *parse(char *filename);
|
||||||
void display(TOMLMap *config);
|
void display(TOMLMap *config);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
Server server;
|
Server server;
|
||||||
|
|
||||||
server.readConfig();
|
server.readConfig(argv[1]);
|
||||||
server.setupConfig();
|
server.setupConfig();
|
||||||
server.start();
|
server.start();
|
||||||
server.end();
|
server.end();
|
||||||
|
|||||||
Reference in New Issue
Block a user