22 if (datas[
"server_name"])
23 _name = datas[
"server_name"]->str();
24 if (datas[
"locations"]) {
25 JSONObject locations = datas[
"locations"]->obj();
26 for (JSONObject::iterator it = locations.begin(); it != locations.end(); it++) {
27 Route *route =
new Route(
this, (*it).first, (*it).second);
39 for (std::map<string, Route *>::iterator it =
_routes.begin(); it !=
_routes.end(); it++)
41 cout <<
"Server destroyed!\n";
58 if (listen.
ip.at(0) !=
'[') {
63 }
catch (std::exception &e) {
64 std::cerr << e.what() <<
'\n';
67 cout <<
"Listen: IPv6 isn't supported\n";
81 std::vector<Master *> ret;
84 if (datas[
"listens"]) {
85 JSONList listens = datas[
"listens"]->lst();
86 for (JSONList::iterator it = listens.begin(); it != listens.end(); it++) {
104 uri_words =
split(uri,
"/");
105 for (std::map<string, Route *>::iterator loc_it =
_routes.begin(); loc_it !=
_routes.end(); loc_it++) {
106 loc_words =
split((*loc_it).first,
"/");
107 vec_string::iterator loc_word = loc_words.begin();
108 for (vec_string::iterator uri_word = uri_words.begin(); uri_word < uri_words.end(); uri_word++) {
109 while (uri_word != uri_words.end() && *uri_word ==
"")
111 if (*uri_word != *(loc_word++))
113 while (loc_word != loc_words.end() && *loc_word ==
"")
115 if (loc_word == loc_words.end())
116 return ((*loc_it).second);
Route * choose_route(string uri)
Choose the route an uri asked to the server.
std::vector< Master * > get_sockets(JSONNode *server)
Create server's defined sockets:
Master * create_master(string str)
Master socket safe creation.
std::vector< ip_port_t > _listens
The list of listens the server which are linked to the server.
string _name
The server name.
Server(JSONNode *server)
Constructor.
std::map< string, Route * > _routes
The server's routings with a route object as object and his location as key.
std::vector< JSONNode * > JSONList
std::vector< string > vec_string
std::map< string, JSONNode * > JSONObject