nicolas-arnaud
2 years ago
8 changed files with 55 additions and 13 deletions
@ -1 +1,19 @@ |
|||
#include "webserv.hpp" |
|||
|
|||
Route::Route(JSONNode *datas) { |
|||
JSONObject object = datas->obj(); |
|||
if (object["root"]) |
|||
_root = object["root"]->str(); |
|||
if (object["return"]) |
|||
_ret = object["return"]->str(); |
|||
if (object["autoindex"]) |
|||
_autoindex = object["autoindex"]->boo(); |
|||
if (object["indexs"]) { |
|||
JSONList indexs = object["indexs"]->lst(); |
|||
for (JSONList::iterator it = indexs.begin(); it < indexs.end(); it++) { |
|||
_indexs.push_back((*it)->str()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Route::~Route(void) {} |
|||
|
@ -1,37 +1,50 @@ |
|||
#include "webserv.hpp" |
|||
|
|||
Server::Server(JSONNode *server) { |
|||
Server::Server(JSONNode *server):Route(server) { |
|||
JSONObject datas = server->obj(); |
|||
if (datas["server_name"]) |
|||
_name = datas["server_name"]->str(); |
|||
if (datas["listens"]) { |
|||
JSONList listens = datas["listens"]->lst(); |
|||
for (JSONList::iterator i = listens.begin(); i < listens.end(); i++) { |
|||
Socket *sock = new Socket((*i)->str()); |
|||
for (JSONList::iterator it = listens.begin(); it < listens.end(); it++) { |
|||
Socket *sock = new Socket(this, (*it)->str()); |
|||
if (sock->launch() == EXIT_SUCCESS) |
|||
_sockets.push_back(sock); |
|||
else |
|||
delete sock; |
|||
} |
|||
} |
|||
//_routes["default"] = new Route(datas["root"], datas["return"],
|
|||
// datas["index"], datas["autoindex"]);
|
|||
if (datas["locations"]) { |
|||
JSONObject locations = datas["locations"]->obj(); |
|||
for (JSONObject::iterator it = locations.begin(); it != locations.end(); it++) { |
|||
Route *route = new Route((*it).second); |
|||
_routes[(*it).first] = route; |
|||
} |
|||
} |
|||
} |
|||
|
|||
Server::~Server() { |
|||
Server::~Server(void) { |
|||
cout << "Server destroyed!\n"; |
|||
} |
|||
|
|||
void Server::set_fds() { |
|||
void Server::set_fds(void) { |
|||
for (std::vector<Socket *>::iterator it = _sockets.begin(); |
|||
it < _sockets.end(); it++) { |
|||
(*it)->set_fds(); |
|||
} |
|||
} |
|||
|
|||
void Server::refresh() { |
|||
void Server::refresh(void) { |
|||
for (std::vector<Socket *>::iterator it = _sockets.begin(); |
|||
it < _sockets.end(); it++) { |
|||
(*it)->refresh(); |
|||
} |
|||
} |
|||
|
|||
Route *Server::get_route(string uri) { |
|||
for (std::map<string, Route *>::iterator it = _routes.begin(); it != _routes.end(); it++) { |
|||
if (uri == (*it).first) |
|||
return (*it).second; |
|||
} |
|||
return this; |
|||
} |
|||
|
Loading…
Reference in new issue