-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
executable file
·75 lines (64 loc) · 1.42 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
#include "Parser.hpp"
#include "Core.hpp"
#include "color.hpp"
#include <fstream>
bool configFileOpen(int argc, char* argv[], std::ifstream& file)
{
if (argc < 2) {
file.open("./config/default.conf");
return true;
}
else if (argc == 2) {
const std::string ext = ".conf";
std::string input = argv[1];
if (input.find_last_of(".") == std::string::npos || \
input.substr(input.find_last_of(".")) != ext) {
std::cerr << "error: file must have .conf extension" << std::endl;
return false;
}
file.open(argv[1]);
return true;
}
else {
std::cerr << "usage: ./webserv config_file\n";
}
return false;
}
Parser configInit(std::ifstream& file)
{
Parser confParser;
try {
confParser.openFile(file);
confParser.setConfigFile();
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << '\n';
exit(EXIT_FAILURE);
}
return confParser;
}
int kqFd = 0;
bool kqCreate() {
kqFd = kqueue();
if (kqFd < 0 )
return (false);
return (true);
}
// void leaksCheck() {
// system("leaks webserv");
// }
int main(int argc, char **argv)
{
std::ifstream file;
Parser configs;
//atexit(leaksCheck);
if (!configFileOpen(argc, argv, file))
return EXIT_FAILURE;
configs = configInit(file);
if (!kqCreate())
return EXIT_FAILURE;
Core core(configs);
if(core.status() == false)
return(printError("ERROR: shade... \t\t| you could config better next time :(", 0));
core.run();
return EXIT_SUCCESS;
}