Browse Source

save 22-11-4-2

test
nicolas-arnaud 2 years ago
parent
commit
c119d34186
  1. 4
      .gitignore
  2. 4
      Makefile
  3. 30
      default.json
  4. 11
      srcs/load/Env.hpp
  5. 14
      srcs/load/Server.hpp

4
.gitignore

@ -1,5 +1,7 @@
* *
!srcs/*/ !srcs/
!srcs/load/
!srcs/json/
!srcs/*/*.cpp !srcs/*/*.cpp
!srcs/*/*.hpp !srcs/*/*.hpp
!srcs/*.hpp !srcs/*.hpp

4
Makefile

@ -2,13 +2,13 @@ NAME= server
SRCS= srcs/webserv.cpp srcs/tools.cpp SRCS= srcs/webserv.cpp srcs/tools.cpp
OBJS= $(SRCS:.cpp=.o) OBJS= $(SRCS:.cpp=.o)
CXX=c++ CXX=c++
CXXFLAGS= -Werror -Wextra -Wall -std=c++98 CXXFLAGS= -g -Werror -Wextra -Wall -std=c++98
all : $(NAME) all : $(NAME)
$(NAME): $(OBJS) $(NAME): $(OBJS)
$(CXX) $(OBJS) -o $(NAME) $(CXX) -g -fsanitize=address $(OBJS) -o $(NAME)
clean: clean:
rm -rf $(OBJS) rm -rf $(OBJS)

30
default.json

@ -0,0 +1,30 @@
{
"max_clients": 30,
"root_folder": "./www",
"servers": [
{
"server_name": "localhost",
"listens": ["15000", "[::]:88"],
"return": "301 https://$host$uri"
},
{
"server_name": "localhost",
"listens": ["150005", "[::]:88"],
"root": "./public",
"index": ["index.html"],
"locations":
{
"/docs":
{
"root": "./documents",
"autoindex": true
},
"/img":
{
"root": "./images"
}
}
}
]
}

11
srcs/load/Env.hpp

@ -6,18 +6,17 @@ class Env {
std::vector<Server> _servers; std::vector<Server> _servers;
public: public:
Env(JSONNode *conf) { Env(JSONNode *conf) {
conf->obj()["max_clients"]->nbr();
JSONList servers = conf->obj()["servers"]->lst(); JSONList servers = conf->obj()["servers"]->lst();
int i = 0; int i = 0;
string th[8]= {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eigth"}; string th[8]= {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eigth"};
for (std::vector<JSONNode *>::iterator it = servers.begin(); for (std::vector<JSONNode *>::iterator it = servers.begin();
it < servers.end(); it++) { it < servers.end(); it++) {
Server *server = new Server(*it); Server *server = new Server(*it);
delete *it; server->launch();
server->launch(); //delete *it;
cout << th[i] << " server launched."; cout << th[i] << " server launched.\n";
i++; i++;
} }
delete conf; //delete conf;
} }
}; };

14
srcs/load/Server.hpp

@ -9,11 +9,17 @@ class Server {
public: public:
Server(JSONNode *server) { Server(JSONNode *server) {
_port = 80;
JSONObject datas = server->obj(); JSONObject datas = server->obj();
_name = datas["server_name"]->str(); if (datas["server_name"])
JSONList listens = datas["listens"]->lst(); _name = datas["server_name"]->str();
for (JSONList::iterator i = listens.begin(); i < listens.end(); i++) if (datas["listens"]) {
_listens.push_back((*i)->str()); JSONList listens = datas["listens"]->lst();
for (JSONList::iterator i = listens.begin(); i < listens.end(); i++)
_listens.push_back((*i)->str());
_port = std::atoi(_listens.front().c_str());
}
//_routes["default"] = new Route(datas["root"], datas["return"], datas["index"], datas["autoindex"]); //_routes["default"] = new Route(datas["root"], datas["return"], datas["index"], datas["autoindex"]);
} }
void launch() { void launch() {

Loading…
Cancel
Save