-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.cpp
More file actions
76 lines (70 loc) · 1.86 KB
/
server.cpp
File metadata and controls
76 lines (70 loc) · 1.86 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
72
73
74
75
76
# include "ConfigBlocks.hpp"
# include "ConfigMime.hpp"
# include "ConfigStatus.hpp"
# include "SocketController.hpp"
# include "ServerProcess.hpp"
# include "KernelQueueController.hpp"
# include "ErrorHandler.hpp"
# include "ErrorPageController.hpp"
# define CONF_PATH "./setting/nginx.conf"
# define MIME_PATH "./setting/mime.types"
# define STAT_PATH "./setting/status_code.txt"
NginxConfig::GlobalConfig
_config;
extern NginxConfig::GlobalConfig
_config;
MimeConfig
_mime;
extern MimeConfig
_mime;
StatusConfig
_status;
extern StatusConfig
_status;
void
check_argv_str(
std::string& _conf_uri,
std::string& _mime_uri,
std::string& _stat_uri,
std::string _tmp)
{
if (_tmp.substr(_tmp.length() - 5, _tmp.length()).compare(".conf") == 0)
_conf_uri = _tmp;
else if (_tmp.substr(_tmp.length() - 6, _tmp.length()).compare(".types") == 0)
_mime_uri = _tmp;
else if (_tmp.substr(_tmp.length() - 3, _tmp.length()).compare(".txt") == 0)
_stat_uri = _tmp;
else
throw ErrorHandler(__FILE__, __func__, __LINE__,
"Invalid file name on argument(.conf, .types and .txt only) : " + _tmp);
}
int
main(int _arc, char** _arv)
{
try
{
std::string
_conf_uri = CONF_PATH,
_mime_uri = MIME_PATH,
_stat_uri = STAT_PATH;
if (_arc == 2)
check_argv_str(_conf_uri, _mime_uri, _stat_uri, _arv[2]);
if (_arc == 3)
check_argv_str(_conf_uri, _mime_uri, _stat_uri, _arv[3]);
if (_arc == 4)
check_argv_str(_conf_uri, _mime_uri, _stat_uri, _arv[4]);
else if (_arc != 1)
throw ErrorHandler(__FILE__, __func__, __LINE__,
"Too many arguments. Please input one ~ three, or just nothing.");
_config.startConfig(_conf_uri);
_mime.startConfig(_mime_uri);
_status.startConfig(_stat_uri);
ServerProcess::serverProcess();
}
catch (const ErrorHandler& err)
{
std::cerr << err.what() << std::endl;
return (-1);
}
return (0);
}