diff --git a/.github/workflows/compile-check.yml b/.github/workflows/compile-check.yml index 78a8038..20e48ff 100644 --- a/.github/workflows/compile-check.yml +++ b/.github/workflows/compile-check.yml @@ -3,12 +3,7 @@ name: Compilation Check on: push: branches: - - main - - server/* - - conf-parser - - CGI-Parser - - handle_connection - - parsing + - '**' jobs: build-linux: diff --git a/Makefile b/Makefile index a404aaa..624aec6 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,8 @@ NAME:= webserv ### MODULES & INCLUDES ### MODULES:= $(PARSER_DIR) $(HTTP_DIR) $(SERVER_DIR) $(CGI_DIR) -INCLUDES:= -I./includes/ $(patsubst %,-I./%,$(MODULES)) +SUB_DIRS:= $(shell find $(SRCS_DIR) -type d -name $(TESTS_DIR) -prune -o -type d -print) +INCLUDES:= -I./includes/ $(patsubst %,-I./%,$(MODULES)) $(patsubst %,-I./%,$(SUB_DIRS)) ### SOURCES ### SRCS:= $(SRCS_DIR)/main.cpp @@ -43,7 +44,6 @@ SRCS:= $(SRCS_DIR)/main.cpp ### OBJECTS & SUBDIRS ### include $(patsubst %,%/module.mk,$(MODULES)) OBJS += $(patsubst $(SRCS_DIR)%.cpp,$(OBJS_DIR)%.o,$(SRCS)) -SUB_DIRS:= $(patsubst $(SRCS_DIR)%,$(OBJS_DIR)%,$(shell find $(SRCS_DIR) -type d)) all: $(NAME) @@ -56,7 +56,7 @@ $(OBJS_DIR)/%.o: $(SRCS_DIR)/%.cpp | $(OBJS_DIR) @echo "$(GREEN)[ COMPILE ]$(RESET) $<." $(OBJS_DIR): - @mkdir -p $@ $(SUB_DIRS) + @mkdir -p $@ $(patsubst $(SRCS_DIR)%,$(OBJS_DIR)%,$(SUB_DIRS)) run: re ./$(NAME) configs/webserv.conf @@ -90,7 +90,7 @@ test_parser: @echo "$(BLUE)[ TEST ]$(RESET) Parser ready for testing." test_http: - @$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEBUGFLAGS) $(HTTP_SRCS) $(TEST_HTTP_SRC) -o $(TEST_HTTP) + @$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEBUGFLAGS) $(CGI_SRCS) $(HTTP_SRCS) $(TEST_HTTP_SRC) -o $(TEST_HTTP) @echo "$(BLUE)[ TEST ]$(RESET) HTTP ready for testing." #! SOCKET_main.cpp has a compile error so this test has been commented out @@ -103,14 +103,6 @@ test_cgi: @$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEBUGFLAGS) $(SANITIZE) $(HTTP_SRCS) $(CGI_SRCS) $(TEST_CGI_SRC) -o $(TEST_CGI) @echo "$(BLUE)[ TEST ]$(RESET) CGI ready for testing." -format: - @echo "$(BLUE)[ FORMAT ]$(RESET) Formatting code..." - @find ./$(SRCS_DIR) -name "*.cpp" -o -name "*.hpp" \ - -exec clang-format -i {} + - @find ./includes -name "*.hpp" \ - -exec clang-format -i {} + - @echo "$(BLUE)[ FORMAT ]$(RESET) Code has been formatted." - -include $(OBJS:.o=.d) .PHONY: clean fclean all re debug run test_parser test_http test_socket test_cgi diff --git a/README.md b/README.md new file mode 100644 index 0000000..9fc3a34 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# webserv + +### References: +- [Why Recursive Makefiles Are Harmful](https://accu.org/journals/overload/14/71/miller_2004/) diff --git a/includes/webserv.hpp b/includes/webserv.hpp index 15c9ff4..2883438 100644 --- a/includes/webserv.hpp +++ b/includes/webserv.hpp @@ -82,6 +82,13 @@ typedef vector > vsp; // socket_descriptor type typedef int fd; /* ----------------------------- ERROR MESSAGES ----------------------------- */ +#define THROW_EXCEPTION_WITH_INFO(msg) \ + do { \ + std::ostringstream oss; \ + oss << __FILE__ << ":" << __LINE__ << ": " << R << "error: " << RE << (msg); \ + throw std::runtime_error(oss.str()); \ + } while (0) + static std::string ERR_NULL("Socket: null ptr error"); static std::string ERR_CREAT("Socket: creation failed"); static std::string ERR_BIND("Socket: binding failed"); diff --git a/sources/CGI/.tests/test_cgi.cpp b/sources/CGI/.tests/test_cgi.cpp index 387ecbe..05e3614 100644 --- a/sources/CGI/.tests/test_cgi.cpp +++ b/sources/CGI/.tests/test_cgi.cpp @@ -7,7 +7,7 @@ // # include // # include // # include -#include "../Cgi.hpp" +#include "Cgi.hpp" //using namespace webserv::http; diff --git a/sources/CGI/Cgi.hpp b/sources/CGI/Cgi.hpp index dc7d1df..efc1279 100644 --- a/sources/CGI/Cgi.hpp +++ b/sources/CGI/Cgi.hpp @@ -13,7 +13,6 @@ #ifndef CGI_HPP #define CGI_HPP -//#include "../../includes/webserv.hpp" #include #include #include @@ -21,7 +20,7 @@ #include #include #include "webserv.hpp" -#include "../sources/http/request/Request.hpp" +#include "Request.hpp" class Cgi { public: diff --git a/sources/http/.tests/test_http.cpp b/sources/http/.tests/test_http.cpp index eb17a08..1f1a3cb 100644 --- a/sources/http/.tests/test_http.cpp +++ b/sources/http/.tests/test_http.cpp @@ -1,6 +1,6 @@ -#include "../request/Request.hpp" -#include "../response/Response.hpp" -#include "../includes/webserv.hpp" +#include "Request.hpp" +#include "Response.hpp" +#include "webserv.hpp" int main() { diff --git a/sources/http/FileType.hpp b/sources/http/FileType.hpp index 4322929..ce16caa 100644 --- a/sources/http/FileType.hpp +++ b/sources/http/FileType.hpp @@ -1,4 +1,4 @@ -#include "../../includes/webserv.hpp" +#include "webserv.hpp" #ifndef FILETYPE_HPP #define FILETYPE_HPP diff --git a/sources/http/FindHeaderKey.hpp b/sources/http/FindHeaderKey.hpp index 42fc389..7c2f772 100644 --- a/sources/http/FindHeaderKey.hpp +++ b/sources/http/FindHeaderKey.hpp @@ -1,4 +1,4 @@ -#include "../../includes/webserv.hpp" +#include "webserv.hpp" #ifndef FINDHEADERKEY_HPP #define FINDHEADERKEY_HPP diff --git a/sources/http/Message.hpp b/sources/http/Message.hpp index 7bec0c9..a744453 100644 --- a/sources/http/Message.hpp +++ b/sources/http/Message.hpp @@ -1,4 +1,4 @@ -#include "../../includes/webserv.hpp" +#include "webserv.hpp" #ifndef MESSAGE_HPP #define MESSAGE_HPP diff --git a/sources/http/handler/GetRequestHandler.cpp b/sources/http/handler/GetRequestHandler.cpp index 5be1fce..d79c5de 100644 --- a/sources/http/handler/GetRequestHandler.cpp +++ b/sources/http/handler/GetRequestHandler.cpp @@ -1,7 +1,7 @@ -#include "./GetRequestHandler.hpp" -#include "../../../includes/debug.hpp" -#include "../FileType.hpp" -#include "../server/CachedPages.hpp" +#include "GetRequestHandler.hpp" +#include "debug.hpp" +#include "FileType.hpp" +#include "CachedPages.hpp" GetRequestHandler::GetRequestHandler() { diff --git a/sources/http/handler/GetRequestHandler.hpp b/sources/http/handler/GetRequestHandler.hpp index 15e8d54..863bcfc 100644 --- a/sources/http/handler/GetRequestHandler.hpp +++ b/sources/http/handler/GetRequestHandler.hpp @@ -1,8 +1,8 @@ -#include "../request/Request.hpp" -#include "./RequestHandlerBase.hpp" -#include "../response/Response.hpp" -#include "../../server/Server.hpp" -#include "../../../includes/webserv.hpp" +#include "Request.hpp" +#include "RequestHandlerBase.hpp" +#include "Response.hpp" +#include "Server.hpp" +#include "webserv.hpp" #ifndef GETREQUESTHANDLER_HPP #define GETREQUESTHANDLER_HPP diff --git a/sources/http/handler/IRequestHandler.hpp b/sources/http/handler/IRequestHandler.hpp index cd7ff6d..482f964 100644 --- a/sources/http/handler/IRequestHandler.hpp +++ b/sources/http/handler/IRequestHandler.hpp @@ -1,5 +1,5 @@ -#include "../response/Response.hpp" -#include "../../server/Server.hpp" +#include "Response.hpp" +#include "Server.hpp" #ifndef IRequestHandler_HPP #define IRequestHandler_HPP diff --git a/sources/http/handler/RequestHandlerBase.hpp b/sources/http/handler/RequestHandlerBase.hpp index c3c13e1..f13c69c 100644 --- a/sources/http/handler/RequestHandlerBase.hpp +++ b/sources/http/handler/RequestHandlerBase.hpp @@ -1,4 +1,4 @@ -#include "./IRequestHandler.hpp" +#include "IRequestHandler.hpp" #ifndef REQUESTHANDLERBASE_HPP #define REQUESTHANDLERBASE_HPP diff --git a/sources/http/handler/RequestHandlerFactory.hpp b/sources/http/handler/RequestHandlerFactory.hpp index 7cc3e03..c47159d 100644 --- a/sources/http/handler/RequestHandlerFactory.hpp +++ b/sources/http/handler/RequestHandlerFactory.hpp @@ -1,6 +1,6 @@ -#include "../FindHeaderKey.hpp" -#include "./GetRequestHandler.hpp" -#include "./IRequestHandler.hpp" +#include "FindHeaderKey.hpp" +#include "GetRequestHandler.hpp" +#include "IRequestHandler.hpp" #ifndef REQUESTHANDLERFACTORY_HPP #define REQUESTHANDLERFACTORY_HPP @@ -20,7 +20,7 @@ class RequestHandlerFactory switch (m) { case GET: return new GetRequestHandler; - default: throw runtime_error("Request Method not implemented\n"); + default: THROW_EXCEPTION_WITH_INFO("Request Method not implemented\n"); } } }; diff --git a/sources/http/request/Request.cpp b/sources/http/request/Request.cpp index 9317f2f..bb421f0 100644 --- a/sources/http/request/Request.cpp +++ b/sources/http/request/Request.cpp @@ -1,6 +1,6 @@ -#include "./Request.hpp" -#include "../../../includes/debug.hpp" -#include "../../../includes/enum_utils.hpp" +#include "Request.hpp" +#include "debug.hpp" +#include "enum_utils.hpp" Request::Request(const string &rawRequest) : rawRequest(rawRequest) @@ -11,7 +11,7 @@ Request::Request(const string &rawRequest) } catch (std::ios_base::failure &f) { - throw runtime_error("Invalid request\n"); + THROW_EXCEPTION_WITH_INFO("Invalid request\n"); } } diff --git a/sources/http/request/Request.hpp b/sources/http/request/Request.hpp index 82432b8..5f1b06d 100644 --- a/sources/http/request/Request.hpp +++ b/sources/http/request/Request.hpp @@ -1,5 +1,5 @@ -#include "../Message.hpp" -#include "../../../includes/webserv.hpp" +#include "Message.hpp" +#include "webserv.hpp" #ifndef REQUEST_HPP #define REQUEST_HPP diff --git a/sources/http/request/parse_request.cpp b/sources/http/request/parse_request.cpp index d6226df..0b91ceb 100644 --- a/sources/http/request/parse_request.cpp +++ b/sources/http/request/parse_request.cpp @@ -1,6 +1,6 @@ -#include "../Message.hpp" -#include "./Request.hpp" -#include "../../../includes/enum_utils.hpp" +#include "Message.hpp" +#include "Request.hpp" +#include "enum_utils.hpp" // defining the char * array #define X(a) ws_tostr(a), // stringify the enum diff --git a/sources/http/response/Response.cpp b/sources/http/response/Response.cpp index 8dfd0dc..b456cf9 100644 --- a/sources/http/response/Response.cpp +++ b/sources/http/response/Response.cpp @@ -1,7 +1,7 @@ #include "Response.hpp" -#include "../../../includes/debug.hpp" -#include "../../../includes/enum_utils.hpp" -#include "../../server/Server.hpp" +#include "debug.hpp" +#include "enum_utils.hpp" +#include "Server.hpp" /** * This constant string represents the HTTP version "HTTP/1.1" that is used in the @@ -115,7 +115,7 @@ void Response::send_response(fd recv_socket) const { result = send(recv_socket, &message[bytesSent], message.size() - bytesSent, 0); if (result == -1) - throw runtime_error(ERR_SEND_FAIL + strerror(errno)); + THROW_EXCEPTION_WITH_INFO(ERR_SEND_FAIL + strerror(errno)); bytesSent += result; } } diff --git a/sources/http/response/Response.hpp b/sources/http/response/Response.hpp index 055b93c..d456f2d 100644 --- a/sources/http/response/Response.hpp +++ b/sources/http/response/Response.hpp @@ -1,6 +1,6 @@ -#include "../../../includes/webserv.hpp" -#include "../Message.hpp" -#include "../request/Request.hpp" +#include "webserv.hpp" +#include "Message.hpp" +#include "Request.hpp" #ifndef RESPONSE_HPP #define RESPONSE_HPP diff --git a/sources/main.cpp b/sources/main.cpp index 69ac841..0e6b513 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -1,11 +1,12 @@ -#include "./server/Server.hpp" -#include "./parser/ConfigParser.hpp" -#include "./server/ServerConfig.hpp" -#include "../includes/webserv.hpp" +#include "Server.hpp" +#include "ConfigParser.hpp" +#include "ServerConfig.hpp" +#include "webserv.hpp" int main(int argc, char **argv) { - if (argc > 2) { - std::cerr << "Usage: " << argv[0] << " []" << std::endl; + if (argc > 2) + { + cerr << "Usage: " << argv[0] << " []" << endl; exit(1); } @@ -18,8 +19,8 @@ int main(int argc, char **argv) { Server &webserv = Server::get_instance(configs[0], 10); webserv.start(SELECT); } - catch (std::exception &e) + catch (std::exception &error) { - std::cerr << e.what(); + cerr << error.what() << endl; } } diff --git a/sources/parser/.tests/test_parser.cpp b/sources/parser/.tests/test_parser.cpp index 6f765fa..baab5d7 100644 --- a/sources/parser/.tests/test_parser.cpp +++ b/sources/parser/.tests/test_parser.cpp @@ -1,4 +1,4 @@ -#include "../ConfigParser.hpp" +#include "ConfigParser.hpp" int main(int argc, char **argv) { if (argc != 2) { diff --git a/sources/parser/ConfigParser.cpp b/sources/parser/ConfigParser.cpp index 693cf9a..df6f851 100644 --- a/sources/parser/ConfigParser.cpp +++ b/sources/parser/ConfigParser.cpp @@ -5,19 +5,19 @@ ConfigParser::ConfigParser(string const& configFile) { // checking file extension if (configFile.find(".conf") == string::npos) - throw runtime_error(ERR_INVALID_FILE); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_FILE); // check if file exists and is a regular file struct stat fileStat; if (stat(configFile.c_str(), &fileStat) == -1 || !S_ISREG(fileStat.st_mode)) - throw runtime_error(ERR_STAT); + THROW_EXCEPTION_WITH_INFO(ERR_STAT); // open file ifstream file(configFile.c_str()); if (!file.is_open()) - throw runtime_error(ERR_OPEN); + THROW_EXCEPTION_WITH_INFO(ERR_OPEN); else if (file.peek() == ifstream::traits_type::eof()) // check if file is empty - throw runtime_error(ERR_EMPTY); + THROW_EXCEPTION_WITH_INFO(ERR_EMPTY); string line; while (std::getline(file, line)) { @@ -44,11 +44,11 @@ void ConfigParser::_parse_error_page(map& errorPages, strin DEBUG_MSG("Parsing error_page directive", RE); if (root.empty()) - throw runtime_error(ERR_MISSING_ROOT); + THROW_EXCEPTION_WITH_INFO(ERR_MISSING_ROOT); ++_itr; // move to error code if (*_itr == ";") - throw runtime_error(ERR_ERROR_CODE); + THROW_EXCEPTION_WITH_INFO(ERR_ERROR_CODE); vector codes; while (_is_string_number(*_itr)) { @@ -56,20 +56,20 @@ void ConfigParser::_parse_error_page(map& errorPages, strin ++_itr; // move to next error code } if (*_itr == ";") - throw runtime_error(ERR_ERROR_PATH); + THROW_EXCEPTION_WITH_INFO(ERR_ERROR_PATH); string errorPath = *_itr; if (errorPath.find(".html") == string::npos && errorPath.find(".htm") == string::npos && errorPath.find(".txt") == string::npos) - throw runtime_error(ERR_INVALID_ERROR_PATH); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_ERROR_PATH); if (errorPath.find("/") == string::npos) - throw runtime_error(ERR_INVALID_ERROR_PATH); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_ERROR_PATH); else if (errorPath.find_first_of("/") != errorPath.find_last_of("/")) - throw runtime_error(ERR_INVALID_ERROR_PATH); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_ERROR_PATH); if (errorPath.find("x") == string::npos) { if (errorPath.find_first_of("x") != errorPath.find_last_of("x")) - throw runtime_error(ERR_INVALID_ERROR_PATH); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_ERROR_PATH); } for (vector::const_iterator itr = codes.begin(); itr != codes.end(); ++itr) { @@ -90,12 +90,12 @@ vector ConfigParser::_parse_index(string const& root) { vector indexFiles; if (root.empty()) - throw runtime_error(ERR_MISSING_ROOT); + THROW_EXCEPTION_WITH_INFO(ERR_MISSING_ROOT); ++_itr; // move to index file while (*_itr != ";") { if (_is_keyword(*_itr)) - throw runtime_error(ERR_INVALID_INDEX); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_INDEX); indexFiles.push_back(root + "/" + *_itr); ++_itr; } @@ -108,7 +108,7 @@ Location ConfigParser::_parse_location_context(void) { ++_itr; // move to location modifier/path if (*_itr == "{") - throw runtime_error(ERR_INVALID_LOCATION); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_LOCATION); Location location; if (*_itr == "=" || *_itr == "~") { @@ -119,7 +119,7 @@ Location ConfigParser::_parse_location_context(void) { ++_itr; // move to { if (*_itr != "{") - throw runtime_error(ERR_INVALID_LOCATION); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_LOCATION); ++_itr; // move to location content while (*_itr != "}") { @@ -131,7 +131,7 @@ Location ConfigParser::_parse_location_context(void) { location.indexFiles = _parse_index(location.root); else { cout << *_itr << endl; - throw runtime_error(ERR_UNEXPECTED_TOKENS_IN_LOCATION); + THROW_EXCEPTION_WITH_INFO(ERR_UNEXPECTED_TOKENS_IN_LOCATION); } ++_itr; } @@ -145,14 +145,14 @@ fd ConfigParser::_parse_listen(void) { ++_itr; // move to port number if (*(_itr + 1) != ";") - throw runtime_error(ERR_MISSING_SEMICOLON); + THROW_EXCEPTION_WITH_INFO(ERR_MISSING_SEMICOLON); if (!_is_string_number(*_itr)) - throw runtime_error(ERR_INVALID_LISTEN); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_LISTEN); fd listenerPort = std::atoi(_itr->c_str()); //! listen can also handle IP address like 0.0.0.0:80 if (listenerPort > MAX_PORT || listenerPort < 0) - throw runtime_error(ERR_INVALID_LISTEN); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_LISTEN); _check_semicolon(); return listenerPort; @@ -164,7 +164,7 @@ void ConfigParser::_parse_server_name(vector& serverName) { ++_itr; // move to server name while (*_itr != ";") { if (_is_keyword(*_itr)) - throw runtime_error(ERR_INVALID_SERVER_NAME); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_SERVER_NAME); serverName.push_back(*_itr); ++_itr; } @@ -175,7 +175,7 @@ string ConfigParser::_parse_root(void) { ++_itr; // move to root path if (*(_itr + 1) != ";") - throw runtime_error(ERR_MISSING_SEMICOLON); + THROW_EXCEPTION_WITH_INFO(ERR_MISSING_SEMICOLON); string rootPath = *_itr; _check_semicolon(); @@ -188,13 +188,13 @@ string ConfigParser::_parse_client_max_body_size(void) { ++_itr; // move to max body size if (*(_itr + 1) != ";") - throw runtime_error(ERR_MISSING_SEMICOLON); + THROW_EXCEPTION_WITH_INFO(ERR_MISSING_SEMICOLON); string maxBodySize = *_itr; //! need to handle suffixes like 1m, 1k, 1g if (maxBodySize.find_first_not_of("0123456789kKmMgG") != string::npos) - throw runtime_error(ERR_INVALID_BODY_SIZE); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_BODY_SIZE); else if (maxBodySize.find_first_of("0123456789") == string::npos) - throw runtime_error(ERR_INVALID_BODY_SIZE); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_BODY_SIZE); _check_semicolon(); @@ -207,7 +207,7 @@ bool ConfigParser::_parse_autoindex(void) { ++_itr; // move to on/off string autoindex = *_itr; if (autoindex != "on" && autoindex != "off") - throw runtime_error(ERR_INVALID_AUTOINDEX); + THROW_EXCEPTION_WITH_INFO(ERR_INVALID_AUTOINDEX); _check_semicolon(); return autoindex == "on"; } @@ -217,7 +217,7 @@ ServerConfig ConfigParser::_parse_server_context(void) { ++_itr; // move to { if (*_itr != "{") - throw runtime_error(ERR_OPENINING_BRACE); + THROW_EXCEPTION_WITH_INFO(ERR_OPENINING_BRACE); ++_itr; // move to first directive ServerConfig _serverConfig; @@ -239,7 +239,7 @@ ServerConfig ConfigParser::_parse_server_context(void) { else if (*_itr == "autoindex") _serverConfig.autoindex = _parse_autoindex(); else - throw runtime_error(ERR_UNEXPECTED_TOKENS_IN_SERVER); + THROW_EXCEPTION_WITH_INFO(ERR_UNEXPECTED_TOKENS_IN_SERVER); if (*_itr == ";") ++_itr; } @@ -253,11 +253,11 @@ vector ConfigParser::_parse_HTTP_context(void) { // setting values for Config object _itr = _tokens.begin(); if (*_itr != "http") //! maybe there's stuff in the global context - throw runtime_error(ERR_MISSING_HTTP); + THROW_EXCEPTION_WITH_INFO(ERR_MISSING_HTTP); ++_itr; // move to { if (*_itr != "{") - throw runtime_error(ERR_OPENINING_BRACE); + THROW_EXCEPTION_WITH_INFO(ERR_OPENINING_BRACE); ++_itr; // move to first directive vector serverConfigs; @@ -265,12 +265,12 @@ vector ConfigParser::_parse_HTTP_context(void) { if (*_itr == "server") serverConfigs.push_back(_parse_server_context()); else - throw runtime_error(ERR_UNEXPECTED_TOKENS_IN); + THROW_EXCEPTION_WITH_INFO(ERR_UNEXPECTED_TOKENS_IN); ++_itr; } if ((_itr + 1) != _tokens.end()) - throw runtime_error(ERR_UNEXPECTED_TOKENS_OUT); + THROW_EXCEPTION_WITH_INFO(ERR_UNEXPECTED_TOKENS_OUT); return serverConfigs; } @@ -303,17 +303,17 @@ vector ConfigParser::parse(void) { if (*itr == "{") { if (*(itr - 1) != "server" && *(itr - 1) != "http" && *(itr - 2) != "location" && *(itr - 3) != "location") - throw runtime_error(ERR_MISSING_CONTEXT); + THROW_EXCEPTION_WITH_INFO(ERR_MISSING_CONTEXT); braces.push("{"); } else if (*itr == "}") { if (braces.empty()) // missing opening brace - throw runtime_error(ERR_OPENINING_BRACE); + THROW_EXCEPTION_WITH_INFO(ERR_OPENINING_BRACE); braces.pop(); } } if (!braces.empty()) // missing closing brace - throw runtime_error(ERR_CLOSING_BRACE); + THROW_EXCEPTION_WITH_INFO(ERR_CLOSING_BRACE); return _parse_HTTP_context(); } diff --git a/sources/parser/ConfigParser.hpp b/sources/parser/ConfigParser.hpp index 24be91b..60f425a 100644 --- a/sources/parser/ConfigParser.hpp +++ b/sources/parser/ConfigParser.hpp @@ -1,5 +1,5 @@ -#include "../../includes/webserv.hpp" -#include "../server/ServerConfig.hpp" +#include "webserv.hpp" +#include "ServerConfig.hpp" #include #include @@ -99,7 +99,7 @@ class ConfigParser { } void _check_semicolon(void) { if (*(_itr + 1) != ";") - throw runtime_error(ERR_MISSING_SEMICOLON); + THROW_EXCEPTION_WITH_INFO(ERR_MISSING_SEMICOLON); ++_itr; // move to semicolon } }; diff --git a/sources/server/.tests/ClientTest.cpp b/sources/server/.tests/ClientTest.cpp index 34443e6..68ca923 100644 --- a/sources/server/.tests/ClientTest.cpp +++ b/sources/server/.tests/ClientTest.cpp @@ -1,6 +1,6 @@ -#include "../../http/Message.hpp" -#include "../Server.hpp" -#include "../../../includes/webserv.hpp" +#include "Message.hpp" +#include "Server.hpp" +#include "webserv.hpp" #include int main() diff --git a/sources/server/.tests/SOCKET_main.cpp b/sources/server/.tests/SOCKET_main.cpp index 88964d5..1140eba 100644 --- a/sources/server/.tests/SOCKET_main.cpp +++ b/sources/server/.tests/SOCKET_main.cpp @@ -1,4 +1,4 @@ -#include "../Server.hpp" +#include "Server.hpp" #include #include #include diff --git a/sources/server/CachedPages.hpp b/sources/server/CachedPages.hpp index 0e76be8..9dac917 100644 --- a/sources/server/CachedPages.hpp +++ b/sources/server/CachedPages.hpp @@ -1,5 +1,5 @@ -#include "./ServerConfig.hpp" -#include "../../includes/webserv.hpp" +#include "ServerConfig.hpp" +#include "webserv.hpp" #ifndef CACHED_PAGES_HPP #define CACHED_PAGES_HPP diff --git a/sources/server/Server.cpp b/sources/server/Server.cpp index 959afeb..1f5f425 100644 --- a/sources/server/Server.cpp +++ b/sources/server/Server.cpp @@ -1,10 +1,10 @@ /* -------------------------------- INCLUDES -------------------------------- */ -#include "./Server.hpp" -#include "../http/handler/GetRequestHandler.hpp" -#include "../http/handler/IRequestHandler.hpp" -#include "../http/request/Request.hpp" -#include "../http/handler/RequestHandlerFactory.hpp" -#include "../../includes/debug.hpp" +#include "Server.hpp" +#include "GetRequestHandler.hpp" +#include "IRequestHandler.hpp" +#include "Request.hpp" +#include "RequestHandlerFactory.hpp" +#include "debug.hpp" #include #include #include @@ -80,7 +80,7 @@ bool Server::handle_connection(fd recvSocket) bytesReceived = recv(recvSocket, &buffer[0], BUFFER_SIZE, 0); if (bytesReceived == -1) - throw runtime_error(strerror(errno)); + THROW_EXCEPTION_WITH_INFO(strerror(errno)); if (bytesReceived == 0) return CLOSE_CONNECTION; @@ -134,7 +134,7 @@ void Server::select_strat() readytoRead = activeSockets; if (select(maxSocketDescriptor + 1, &readytoRead, NULL, NULL, &selectTimeOut) < 0) - throw runtime_error(strerror(errno)); + THROW_EXCEPTION_WITH_INFO(strerror(errno)); selectTimeOut.tv_sec = SELECTWAITTIME; for (fd currentSocket = 0; currentSocket <= maxSocketDescriptor; currentSocket++) @@ -177,6 +177,6 @@ void Server::start(enum polling_strat strategy) // case KQUEUE: kqueue_strat(); break; // case POLL: poll_strat(); break; // case EPOLL: epoll_strat(); break; - default: throw runtime_error("Invalid strategy"); break; + default: THROW_EXCEPTION_WITH_INFO("Invalid strategy"); break; } } diff --git a/sources/server/Server.hpp b/sources/server/Server.hpp index 00e23a4..718629f 100644 --- a/sources/server/Server.hpp +++ b/sources/server/Server.hpp @@ -1,8 +1,8 @@ -#include "./CachedPages.hpp" -#include "./ServerConfig.hpp" -#include "./connection_manager/ConnectionManager.hpp" -#include "./socket/TCPSocket.hpp" -#include "../../includes/debug.hpp" +#include "CachedPages.hpp" +#include "ServerConfig.hpp" +#include "ConnectionManager.hpp" +#include "TCPSocket.hpp" +#include "debug.hpp" #ifndef SERVER_HPP #define SERVER_HPP diff --git a/sources/server/ServerConfig.hpp b/sources/server/ServerConfig.hpp index 6e48308..090f206 100644 --- a/sources/server/ServerConfig.hpp +++ b/sources/server/ServerConfig.hpp @@ -1,5 +1,5 @@ -#include "../../includes/webserv.hpp" -#include "../http/Message.hpp" +#include "webserv.hpp" +#include "Message.hpp" #ifndef CONFIG_HPP #define CONFIG_HPP diff --git a/sources/server/connection_manager/ConnectionManager.cpp b/sources/server/connection_manager/ConnectionManager.cpp index 8609065..86ac584 100644 --- a/sources/server/connection_manager/ConnectionManager.cpp +++ b/sources/server/connection_manager/ConnectionManager.cpp @@ -1,4 +1,4 @@ -#include "./ConnectionManager.hpp" +#include "ConnectionManager.hpp" void ConnectionManager::remove_expired(fd_set ¤tSockets) { diff --git a/sources/server/connection_manager/ConnectionManager.hpp b/sources/server/connection_manager/ConnectionManager.hpp index b5c615c..dabb098 100644 --- a/sources/server/connection_manager/ConnectionManager.hpp +++ b/sources/server/connection_manager/ConnectionManager.hpp @@ -1,5 +1,5 @@ -#include "./TimeOut.hpp" -#include "../../../includes/webserv.hpp" +#include "TimeOut.hpp" +#include "webserv.hpp" #ifndef CONNECTION_MANAGER_HPP #define CONNECTION_MANAGER_HPP diff --git a/sources/server/socket/Socket.hpp b/sources/server/socket/Socket.hpp index 12b55ef..5c6fa3a 100644 --- a/sources/server/socket/Socket.hpp +++ b/sources/server/socket/Socket.hpp @@ -1,4 +1,4 @@ -#include "../../../includes/webserv.hpp" +#include "webserv.hpp" #ifndef SOCKET_HPP #define SOCKET_HPP diff --git a/sources/server/socket/TCPSocket.cpp b/sources/server/socket/TCPSocket.cpp index a7f24f9..ae77200 100644 --- a/sources/server/socket/TCPSocket.cpp +++ b/sources/server/socket/TCPSocket.cpp @@ -1,4 +1,4 @@ -#include "./TCPSocket.hpp" +#include "TCPSocket.hpp" #ifdef __DEBUG__ #include diff --git a/sources/server/socket/TCPSocket.hpp b/sources/server/socket/TCPSocket.hpp index 1073bfc..2e659db 100644 --- a/sources/server/socket/TCPSocket.hpp +++ b/sources/server/socket/TCPSocket.hpp @@ -1,4 +1,4 @@ -#include "./Socket.hpp" +#include "Socket.hpp" #ifndef TCPSOCKET_HPP #define TCPSOCKET_HPP