-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
82 lines (71 loc) · 2.27 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jerperez <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/03 15:20:58 by jerperez #+# #+# */
/* Updated: 2024/10/17 12:38:47 by jerperez ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <fstream>
#include "tokenizer.hpp"
#include "parser.hpp"
#include "Directive.hpp"
#include "DirectiveBlock.hpp"
#include <iomanip>
#include <cstdlib>
#include "Server.hpp"
#include <csignal>
volatile sig_atomic_t stopper = 0;
void handle_sigint(int sig) {
std::cout << "\r\033[1;32mCaught signal " << sig << ", stopping server...\033[0m" << std::endl;
stopper = 1;
}
static int _parse(char *pathname, std::list<ConfigServer> &servers)
{
std::fstream f;
token_deq_t list;
f.open(pathname);
if (false == f.is_open())
{
std::cerr << "error: fstream: Failed to open configuration file" << std::endl;
return (1);
}
if (cf_tokenize(f, list))
{
std::cerr << "error: tokenizer: Failed to tokentize" << std::endl;
f.close();
return (1);
}
f.close();
std::cout << "\e[34m##############################\e[0m" << std::endl;
if (pr_parse(list, servers))
{
std::cerr << "main error: parsing failed" << std::endl;
return (1);
}
return (0);
}
int main(int ac, char *av[])
{
int ret = 0;
std::list<ConfigServer> servers;
signal(SIGINT, handle_sigint);
if (2 == ac)
{
if ((ret = _parse(av[1], servers)) != 0)
return 1;
}
else
{
std::cerr << "main: error: expected 1 argument, received: " << (ac - 1) << std::endl;
return 2;
}
Server server(servers);
server.ServerStart();
std::cout << "\n\t\t\033[1;31m<<< EXIT >>>\033[0m\n\n";
return 0;
}