-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (67 loc) · 1.43 KB
/
main.cpp
File metadata and controls
71 lines (67 loc) · 1.43 KB
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
#include "./ParseConfig/config.hpp"
#include "./AllServer/HttpServer.hpp"
int ConfigeFileFunc(std::string ConfigFilePath, std::vector<ConfigNode> &ConfigPars)
{
try
{
if (ConfigFilePath.size() < 6 || ConfigFilePath.substr(ConfigFilePath.length() - 5) != ".conf")
throw ("Error: Config file does not have the correct extension. {.conf}");
StructConf(ConfigFilePath, ConfigPars);
}
catch (char const *e)
{
std::cerr << e << std::endl;
return 1;
}
catch (const std::string e)
{
std::cerr << e << std::endl;
return 1;
}
return 0;
}
int StartServerFunc(std::vector<ConfigNode> ConfigPars)
{
(void)ConfigPars;
try
{
HttpServer server;
server.setup_server(ConfigPars);
server.run(ConfigPars);
}
catch (char const *e)
{
std::cerr << e << std::endl;
return 1;
}
catch (const std::string e)
{
std::cerr << e << std::endl;
return 1;
}
return 0;
}
int main(int argc, char **argv)
{
if (argc <= 2)
{
signal(SIGPIPE, SIG_IGN);
std::string ConfigFilePath;
if (argc == 2)
ConfigFilePath = argv[1];
else
ConfigFilePath = "./default/default.conf";
std::vector<ConfigNode> ConfigPars;
ConfigNode obj;
if (ConfigeFileFunc(ConfigFilePath, ConfigPars) == 1)
return 1;
if (StartServerFunc(ConfigPars) == 1)
return 1;
}
else
{
std::cerr << "./webserv [configuration file]" << std::endl;
return (1);
}
return 0;
}