Skip to content

Commit

Permalink
check dupplicate ports
Browse files Browse the repository at this point in the history
  • Loading branch information
ggjulio committed Nov 2, 2021
1 parent 9e1cc04 commit 823ea03
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ re: fclean all

-include $(DEP)

.PHONY: all run debug valgrind norminette bonus show check jest clean fclean re
.PHONY: all run debug valgrind norminette bonus show check jest jest-sanitize sanitize clean fclean re


#******************************************************************************#
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[![C/C++ CI](https://github.com/Working-From-Home/webserv/actions/workflows/ci.yml/badge.svg)](https://github.com/Working-From-Home/webserv/actions/workflows/ci.yml)

# Webserv - Written in c++98 (The subject force us to use 98)
# Webserv

#### firsts things first, must install php-cgi at least php-cgi
###### linux
- sudo apt install php-cgi
###### macos
- idk, try with brew bro.

## Documentation

Expand Down
3 changes: 3 additions & 0 deletions includes/config/ServerConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class ServerConfig {
void _skipSemiColonNewLine(config::ScannerConfig & scanner);
void _throw_SyntaxError(config::Token t, const std::string &error_str, const ft::filesystem::path& file = ft::filesystem::path());

void _checkNoDupplicatePortListen(ServerBlock& server, config::Token tokenListen);


static ServerConfig* _singleton;
std::vector<ServerBlock> _servers;
ft::filesystem::path _configFilePath;
Expand Down
18 changes: 18 additions & 0 deletions src/config/ServerConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,21 @@ void ServerConfig::_parse(std::istream & in)
}
}

void ServerConfig::_checkNoDupplicatePortListen(ServerBlock& server, pr::Token tokenListen)
{
std::vector<Host>::iterator it = server.getListens().begin();
std::vector<Host>::iterator end = server.getListens().end();
std::set<uint32_t> ports;

while (it != end)
{
if (ports.count(it->getPort()))
_throw_SyntaxError(tokenListen, "listening port defined several times");
ports.insert(it->getPort());
++it;
}
}

ServerBlock ServerConfig::_parseServer(pr::ScannerConfig & scanner, pr::Token serverToken)
{
ServerBlock result;
Expand All @@ -340,7 +355,10 @@ ServerBlock ServerConfig::_parseServer(pr::ScannerConfig & scanner, pr::Token se
if (t.value == "server")
_throw_SyntaxError(serverToken, "Missing closing bracket at end of server directive");
else if (t.value == "listen")
{
result.addListen(_parseListen(scanner));
_checkNoDupplicatePortListen(result, t);
}
else if (t.value == "root")
result.setRoot(_parseRoot(scanner));
else if (t.value == "index")
Expand Down

0 comments on commit 823ea03

Please sign in to comment.