-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
61 lines (51 loc) · 1.62 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
#include "inc/config_file/ConfigFileParsing.hpp"
#include "inc/configuration_key/ConfigurationKey.hpp"
#include "inc/configuration_key/ServerBlock.hpp"
#include "inc/debugger/DebuggerPrinter.hpp"
#include "inc/http/Response.hpp"
#include "inc/network/ServerSocket.hpp"
#include "inc/utility/utility.hpp"
/**
* @brief Checks the argument count of the program and the filename of the configuration
* Returns true on success.
*/
bool check_arguments_and_filename(int argc, char**argv)
{
if (argc != 2 || !check_config_file(argv[1]))
{
std::cout << "usage: ./webserv [path/webserv.conf]" << std::endl;
return (false);
}
return (true);
}
/**
* @brief Entrypoint
* Validates input and then starts the configuration file parsing.
*/
int main(int argc, char **argv)
{
USE_DEBUGGER;
if (!check_arguments_and_filename(argc, argv)) return (1);
ConfigFileParsing *configurationFileParsing = new ConfigFileParsing();
std::string file_content;
if (argc == 1)
file_content = get_file_content("./conf/webserv.conf");
else
file_content = get_file_content(argv[1]);
try {
configurationFileParsing->parseConfigFile(file_content);
debugger.info("CONFIG FILE OK");
} catch (const std::exception& e) {
std::cout << R << "Something went wrong: " << Reset << e.what() << std::endl;
return (1);
}
try {
ServerSocket server(configurationFileParsing->serverBlocks[0], *configurationFileParsing, INADDR_ANY);
} catch (int e) {
// print exception information
std::cout << "Something went wrong with error code " << e << std::endl;
}
delete configurationFileParsing;
std::cout << "Program exited cleanly." << std::endl;
return (0);
}