-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
69 lines (60 loc) · 2.25 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: framdani <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/28 11:12:07 by iidzim #+# #+# */
/* Updated: 2022/05/26 17:18:32 by framdani ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/Server.hpp"
#include "includes/configurationReader.hpp"
void signalhandler(int signum){
broken_pipe = true;
(void)signum;
// std::cout << "Interrupt signal (" << signum << ") received.\n";
}
std::string getCurrentDirectory(){
char cwd[256];
std::string currPath(getcwd(cwd, sizeof(cwd)));
return currPath;
}
int main(int argc, char** argv){
std::string pwd;
broken_pipe = false;
signal(SIGPIPE, signalhandler);
if (argc > 2){
std::cerr << "usage:\t./webserv [configuration file]" << std::endl;
return (-1);
}
pwd = getCurrentDirectory();
try{
std::string path;
if (argc == 1)
path = pwd+"configFile/valid_confg/default";
else
path = argv[1];
std::vector<int> ports;
std::vector<Socket> sockets;
configurationReader cfg_reader(path);
cfg_reader.parser();
std::vector<serverInfo> virtualServer = cfg_reader.getVirtualServer();
// std::cout<<cfg_reader<<std::endl;
for (size_t i = 0; i < virtualServer.size(); i++){
if (std::find(ports.begin(), ports.end(), virtualServer[i].port) == ports.end()){
ports.push_back(virtualServer[i].port);
sockets.push_back(Socket(virtualServer[i].port));
}
}
Server s(sockets, virtualServer, pwd);
ports.clear();
sockets.clear();
}
catch (std::exception &e){
std::cerr << e.what() << std::endl;
}
return (0);
}
//+ curl --resolve ok.ma:8081:127.0.0.1 http://ok.ma:8081