mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 13:27:59 +03:00
Merge remote-tracking branch 'origin/roman' into fara
This commit is contained in:
8
Makefile
8
Makefile
@@ -6,7 +6,9 @@ SANFLAGS = -fsanitize=address
|
|||||||
|
|
||||||
# SANFLAGS = -fsanitize=leak
|
# SANFLAGS = -fsanitize=leak
|
||||||
|
|
||||||
CXXFLAGS = -Wall -Wextra -Werror -g -std=c++98 -fno-limit-debug-info $(SANFLAGS) -DDEBUG
|
DEBUGFLAGS = -g -fno-limit-debug-info
|
||||||
|
|
||||||
|
CXXFLAGS = -Wall -Wextra -Werror -std=c++98 $(DEBUGFLAGS) $(SANFLAGS) -DDEBUG
|
||||||
|
|
||||||
CPPFLAGS += -MD -MP
|
CPPFLAGS += -MD -MP
|
||||||
|
|
||||||
@@ -20,12 +22,12 @@ OBJ = $(SRC:.cpp=.o)
|
|||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
$(OBJ): %.o: %.cpp $(SRC) Makefile
|
$(OBJ): %.o: %.cpp $(SRC) Makefile
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -I $(INCLUDES) -o $@
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -I $(INCLUDES) -o $@
|
||||||
|
|
||||||
-include $(SRC:%.cpp=%.d)
|
-include $(SRC:%.cpp=%.d)
|
||||||
|
|
||||||
$(NAME): $(OBJ)
|
$(NAME): $(OBJ)
|
||||||
$(CXX) $(CXXFLAGS) $(OBJ) -o $(NAME)
|
$(CXX) $(CXXFLAGS) $(OBJ) -o $(NAME)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(OBJ)
|
$(RM) $(OBJ)
|
||||||
|
|||||||
@@ -11,14 +11,12 @@
|
|||||||
Server::Server()
|
Server::Server()
|
||||||
{
|
{
|
||||||
bzero(_events, sizeof(_events));
|
bzero(_events, sizeof(_events));
|
||||||
_client = 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::Server(std::string path)
|
Server::Server(std::string path)
|
||||||
{
|
{
|
||||||
(void)path;
|
(void)path;
|
||||||
_client = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::print_epoll_events(unsigned int events)
|
void Server::print_epoll_events(unsigned int events)
|
||||||
@@ -55,6 +53,8 @@ void Server::readConfig(void)
|
|||||||
_configs.push_back(new ServerConfig(*it));
|
_configs.push_back(new ServerConfig(*it));
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clean_parsed(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendData(Client &client, int fd)
|
void Server::sendData(Client &client, int fd)
|
||||||
@@ -69,8 +69,8 @@ void Server::sendData(Client &client, int fd)
|
|||||||
else
|
else
|
||||||
send_len = BUFFSIZE;
|
send_len = BUFFSIZE;
|
||||||
|
|
||||||
/* std::cout << YELLO << tmp << RESET << std::endl; */
|
/* DBOUT << YELLO << tmp << ENDL; */
|
||||||
/* std::cout << GREEN << client.getCounter() << RESET << std::endl; */
|
/* DBOUT << GREEN << client.getCounter() << ENDL; */
|
||||||
|
|
||||||
|
|
||||||
if (send(fd, tmp + client.getCounter(), send_len, MSG_NOSIGNAL) < 0)
|
if (send(fd, tmp + client.getCounter(), send_len, MSG_NOSIGNAL) < 0)
|
||||||
@@ -89,7 +89,7 @@ void Server::readSocket(Client &client, int fd)
|
|||||||
int bytes_read;
|
int bytes_read;
|
||||||
char buf[BUFFSIZE + 1];
|
char buf[BUFFSIZE + 1];
|
||||||
|
|
||||||
DBOUT << TURQ << "IN readSocket" << RESET << std::endl;
|
DBOUT << TURQ << "IN readSocket" << ENDL;
|
||||||
DBOUT << "client in readSocket "<< &client << ENDL;
|
DBOUT << "client in readSocket "<< &client << ENDL;
|
||||||
bytes_read = recv(fd, buf, BUFFSIZE, 0);
|
bytes_read = recv(fd, buf, BUFFSIZE, 0);
|
||||||
if (bytes_read == 0)
|
if (bytes_read == 0)
|
||||||
@@ -108,13 +108,13 @@ void Server::readSocket(Client &client, int fd)
|
|||||||
client.allRead = true;
|
client.allRead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "recvCounter " << client.getRecvCounter() << std::endl;
|
DBOUT << GREEN << "recvCounter " << client.getRecvCounter() << ENDL;
|
||||||
std::cerr << "contentLength " << client.getRequest().getContentLength() << std::endl;
|
DBOUT << GREEN << "contentLength " << client.getRequest().getContentLength() << ENDL;
|
||||||
std::cerr << "allRead " << client.allRead << std::endl;
|
DBOUT << GREEN << "allRead " << client.allRead << ENDL;
|
||||||
|
|
||||||
DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << RESET << std::endl;
|
DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << ENDL;
|
||||||
bzero(buf, BUFFSIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server::delete_client(std::map<int,Client *> &client_map, int fd)
|
int Server::delete_client(std::map<int,Client *> &client_map, int fd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@@ -149,12 +149,11 @@ void Server::add_to_epoll_list(int fd, unsigned int ep_events)
|
|||||||
ev.data.fd = fd;
|
ev.data.fd = fd;
|
||||||
|
|
||||||
assert(epoll_ctl(_epoll_fd, EPOLL_CTL_ADD, fd, &ev) == 0);
|
assert(epoll_ctl(_epoll_fd, EPOLL_CTL_ADD, fd, &ev) == 0);
|
||||||
_client++;
|
DBOUT << YELLO
|
||||||
std::cerr << YELLO
|
|
||||||
<< "add socket "
|
<< "add socket "
|
||||||
<< fd
|
<< fd
|
||||||
<< " to epoll_list"
|
<< " to epoll_list"
|
||||||
<< RESET << std::endl;
|
<< ENDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::start(void)
|
void Server::start(void)
|
||||||
@@ -178,7 +177,7 @@ void Server::start(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
ready_num = epoll_wait(_epoll_fd, _events, MAX_CLIENT, -1);
|
ready_num = epoll_wait(_epoll_fd, _events, MAX_CLIENT, -1);
|
||||||
/* std::cout << TURQ << "ready_num " << ready_num << RESET << std::endl; */
|
/* DBOUT << TURQ << "ready_num " << ready_num << ENDL; */
|
||||||
|
|
||||||
if (ready_num < 0)
|
if (ready_num < 0)
|
||||||
throw std::logic_error("epoll_ret");
|
throw std::logic_error("epoll_ret");
|
||||||
@@ -267,14 +266,110 @@ void Server::checkError(int fd, std::string str)
|
|||||||
{
|
{
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
std::cout << RED << "Server ERROR: " << str << ZERO_C << std::endl;
|
DBOUT << RED << "Server ERROR: " << str << ENDL;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cout << GREEN << "Server SUCCESS: " << str << ZERO_C << std::endl;
|
DBOUT << GREEN << "Server SUCCESS: " << str << ENDL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server::clean_generic(toml_node *node)
|
||||||
|
{
|
||||||
|
switch (node->type)
|
||||||
|
{
|
||||||
|
case toml_node::STRING:
|
||||||
|
{
|
||||||
|
DBOUT << "cleaning string" << ENDL;
|
||||||
|
delete node->getString();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case toml_node::MAPARRAY:
|
||||||
|
{
|
||||||
|
DBOUT << "cleaning MAPARRAY" << ENDL;
|
||||||
|
TOMLMapArray *map_array = node->getMapArray();
|
||||||
|
for (TOMLMapArray::iterator it = map_array->begin();
|
||||||
|
it != map_array->end(); ++it)
|
||||||
|
{
|
||||||
|
DBOUT << "cleaning a MAP of MAPARRAY" << ENDL;
|
||||||
|
TOMLMap *map = *it;
|
||||||
|
TOMLMap::iterator map_it = map->begin();
|
||||||
|
for (map_it = map->begin();
|
||||||
|
map_it != map->end(); ++map_it)
|
||||||
|
{
|
||||||
|
DBOUT << "cleaning a MAP item " << map_it->first << ENDL;
|
||||||
|
clean_generic(map_it->second);
|
||||||
|
/* map->erase(map_it); */
|
||||||
|
}
|
||||||
|
map->clear();
|
||||||
|
delete map;
|
||||||
|
}
|
||||||
|
map_array->clear();
|
||||||
|
delete map_array;
|
||||||
|
DBOUT << "end cleaning MAPARRAY" << ENDL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case toml_node::MAP:
|
||||||
|
{
|
||||||
|
DBOUT << "cleaning MAP" << ENDL;
|
||||||
|
TOMLMap *map = node->getMap();
|
||||||
|
for (TOMLMap::iterator it = map->begin(); it != map->end(); ++it)
|
||||||
|
{
|
||||||
|
DBOUT << "key is " << it->first << ENDL;
|
||||||
|
clean_generic(it->second);
|
||||||
|
/* map->erase(it); */
|
||||||
|
}
|
||||||
|
map->clear();
|
||||||
|
delete map;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case toml_node::ARRAY:
|
||||||
|
{
|
||||||
|
DBOUT << "cleaning ARRAY" << ENDL;
|
||||||
|
TOMLArray *arr = node->getArray();
|
||||||
|
for (TOMLArray::iterator it = arr->begin();
|
||||||
|
it != arr->end(); ++it)
|
||||||
|
{
|
||||||
|
clean_generic(*it);
|
||||||
|
}
|
||||||
|
arr->clear();
|
||||||
|
delete arr;
|
||||||
|
DBOUT << "end cleaning MAP" << ENDL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
DBOUT << "Cleaning type " << node->type << " not implemented :)" << ENDL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete node;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server::clean_parsed(TOMLMap *root)
|
||||||
|
{
|
||||||
|
TOMLMap::iterator it;
|
||||||
|
|
||||||
|
DBOUT << ">>> cleaning up: <<<" << std::endl;
|
||||||
|
for (it = root->begin(); it != root->end(); ++it)
|
||||||
|
{
|
||||||
|
/* DBOUT << RED << it->first */
|
||||||
|
/* << ": " << GREEN */
|
||||||
|
/* << *(it->second->toString()); */
|
||||||
|
|
||||||
|
clean_generic(it->second);
|
||||||
|
/* delete it->second; */
|
||||||
|
std::cout << ", " << std::endl;
|
||||||
|
}
|
||||||
|
DBOUT << YELLO << "end of clean" << ENDL;
|
||||||
|
root->clear();
|
||||||
|
delete root;
|
||||||
|
root = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::~Server()
|
Server::~Server()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class Server
|
|||||||
private:
|
private:
|
||||||
int _port;
|
int _port;
|
||||||
int _epoll_fd;
|
int _epoll_fd;
|
||||||
int _client;
|
|
||||||
struct epoll_event _events[MAX_CLIENT];
|
struct epoll_event _events[MAX_CLIENT];
|
||||||
struct sockaddr_in _addres;
|
struct sockaddr_in _addres;
|
||||||
std::string _ip;
|
std::string _ip;
|
||||||
@@ -34,6 +33,9 @@ class Server
|
|||||||
void readSocket(Client &client, int fd);
|
void readSocket(Client &client, int fd);
|
||||||
int delete_client(std::map<int,Client *> &map, int fd);
|
int delete_client(std::map<int,Client *> &map, int fd);
|
||||||
|
|
||||||
|
static void clean_generic(toml_node *node);
|
||||||
|
static void clean_parsed(TOMLMap *root);
|
||||||
|
|
||||||
enum e_req_status
|
enum e_req_status
|
||||||
{
|
{
|
||||||
READING,
|
READING,
|
||||||
|
|||||||
@@ -444,6 +444,7 @@ namespace config
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
(it->second)->getMapArray()->push_back(map_node->getMap());
|
(it->second)->getMapArray()->push_back(map_node->getMap());
|
||||||
|
delete map_node;
|
||||||
}
|
}
|
||||||
else if (type == toml_node::MAP)
|
else if (type == toml_node::MAP)
|
||||||
{
|
{
|
||||||
@@ -460,13 +461,13 @@ namespace config
|
|||||||
{
|
{
|
||||||
it = local_root->find(*subname);
|
it = local_root->find(*subname);
|
||||||
|
|
||||||
toml_node *map_node2;
|
|
||||||
map_node2 = new toml_node;
|
|
||||||
TOMLMap *map = new TOMLMap;
|
|
||||||
map_node2->setObject(map);
|
|
||||||
/* subname not found in local_root */
|
/* subname not found in local_root */
|
||||||
if (it == local_root->end())
|
if (it == local_root->end())
|
||||||
{
|
{
|
||||||
|
toml_node *map_node2;
|
||||||
|
map_node2 = new toml_node;
|
||||||
|
TOMLMap *map = new TOMLMap;
|
||||||
|
map_node2->setObject(map);
|
||||||
(*local_root)[*subname] = map_node2;
|
(*local_root)[*subname] = map_node2;
|
||||||
local_root = map;
|
local_root = map;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user