From d98fb98c529309d3ae53654480d2a2cb155d0539 Mon Sep 17 00:00:00 2001 From: whaffman Date: Sun, 26 Oct 2025 13:43:42 +0100 Subject: [PATCH] iwyu --- scripts/.iwyu.imp | 76 +++++++------------ webserv/client/Client.cpp | 38 +++++----- webserv/client/Client.hpp | 17 +++-- webserv/config/AConfig.cpp | 1 + webserv/config/ConfigManager.cpp | 1 + webserv/config/LocationConfig.cpp | 4 +- webserv/config/directive/ADirective.cpp | 5 +- webserv/config/directive/SizeDirective.cpp | 4 +- webserv/config/validation/ConfigValidator.cpp | 6 +- .../config/validation/ValidationEngine.cpp | 3 +- .../config/validation/ValidationResult.cpp | 1 + .../directive_rules/AValidationRule.cpp | 1 - webserv/handler/AHandler.cpp | 21 ++--- webserv/handler/AHandler.hpp | 6 +- webserv/handler/CgiEnvironment.cpp | 11 +-- webserv/handler/CgiEnvironment.hpp | 27 +++---- webserv/handler/CgiHandler.cpp | 22 +++--- webserv/handler/CgiHandler.hpp | 17 +++-- webserv/handler/CgiProcess.cpp | 36 ++++----- webserv/handler/CgiProcess.hpp | 6 +- webserv/handler/ErrorHandler.cpp | 6 +- webserv/handler/ErrorHandler.hpp | 1 + webserv/handler/FileHandler.cpp | 18 ++--- webserv/handler/FileHandler.hpp | 9 ++- webserv/handler/URI.cpp | 8 +- webserv/handler/URI.hpp | 1 - webserv/http/HttpHeaders.cpp | 3 +- webserv/http/HttpRequest.cpp | 25 +++--- webserv/http/HttpRequest.hpp | 4 +- webserv/http/HttpResponse.cpp | 3 +- webserv/http/HttpResponse.hpp | 1 + webserv/log/FileChannel.cpp | 6 +- webserv/main.cpp | 2 +- webserv/router/Router.cpp | 28 ++++--- webserv/router/Router.hpp | 3 +- webserv/server/Server.cpp | 28 ++++--- webserv/server/Server.hpp | 2 +- webserv/socket/ASocket.cpp | 8 +- webserv/socket/CgiSocket.cpp | 10 ++- webserv/socket/CgiSocket.hpp | 3 +- webserv/socket/ClientSocket.cpp | 3 +- webserv/socket/ServerSocket.cpp | 4 +- webserv/socket/TimerSocket.cpp | 16 ++-- webserv/socket/TimerSocket.hpp | 7 +- webserv/utils/utils.cpp | 4 +- webserv/utils/utils.hpp | 2 +- 46 files changed, 267 insertions(+), 241 deletions(-) diff --git a/scripts/.iwyu.imp b/scripts/.iwyu.imp index ec004d4..c9f94f2 100644 --- a/scripts/.iwyu.imp +++ b/scripts/.iwyu.imp @@ -1,11 +1,7 @@ [ # ============================================================================ - # WEBSERV PROJECT IWYU MAPPINGS - # Based on preferences: Forward declarations in headers, central common header, - # umbrella headers for modules, strict standard library includes, stdexcept + # STANDARD LIBRARY PRIVATE IMPLEMENTATION MAPPINGS # ============================================================================ - - # Standard C++ library private implementation mappings { include: ["", "private", "", "public"] }, { include: ["", "private", "", "public"] }, { include: ["", "private", "", "public"] }, @@ -14,23 +10,17 @@ { include: ["", "private", "", "public"] }, { include: ["", "private", "", "public"] }, { include: ["", "private", "", "public"] }, + { include: ["", "private", "", "public"] }, + { include: ["", "private", "", "public"] }, + { include: ["", "private", "", "public"] }, + { include: ["", "private", "", "public"] }, + { include: ["", "private", "", "public"] }, + { include: ["", "private", "", "public"] }, + { include: ["", "private", "", "public"] }, - # Standard library strict mappings (preference 5C - very strict) - { include: ["", "public", "", "public"] }, - { symbol: ["std::cout", "private", "", "public"] }, - { symbol: ["std::cerr", "private", "", "public"] }, - { symbol: ["std::cin", "private", "", "public"] }, - { symbol: ["std::endl", "private", "", "public"] }, - { symbol: ["std::vector", "private", "", "public"] }, - { symbol: ["std::string", "private", "", "public"] }, - { symbol: ["std::map", "private", "", "public"] }, - { symbol: ["std::unordered_map", "private", "", "public"] }, - { symbol: ["std::unique_ptr", "private", "", "public"] }, - { symbol: ["std::shared_ptr", "private", "", "public"] }, - { symbol: ["std::make_unique", "private", "", "public"] }, - { symbol: ["std::make_shared", "private", "", "public"] }, - - # System headers for socket programming + # ============================================================================ + # SYSTEM HEADERS + # ============================================================================ { include: ["", "public", "", "public"] }, { include: ["", "public", "", "public"] }, { include: ["", "public", "", "public"] }, @@ -38,17 +28,9 @@ { include: ["", "public", "", "public"] }, { include: ["", "public", "", "public"] }, - # Error handling (preference 6A - stdexcept) - { symbol: ["std::runtime_error", "private", "", "public"] }, - { symbol: ["std::logic_error", "private", "", "public"] }, - { symbol: ["std::invalid_argument", "private", "", "public"] }, - { symbol: ["std::out_of_range", "private", "", "public"] }, - # ============================================================================ - # PROJECT HEADER MAPPINGS - Standardized on <> angle brackets + # PROJECT HEADERS - Normalize to angle brackets # ============================================================================ - - # Convert quoted includes to angle brackets for consistency { include: ["\"webserv/log/Log.hpp\"", "public", "", "public"] }, { include: ["\"webserv/log/Channel.hpp\"", "public", "", "public"] }, { include: ["\"webserv/log/StdoutChannel.hpp\"", "public", "", "public"] }, @@ -62,31 +44,27 @@ { include: ["\"webserv/config/ConfigManager.hpp\"", "public", "", "public"] }, { include: ["\"webserv/config/ServerConfig.hpp\"", "public", "", "public"] }, { include: ["\"webserv/config/LocationConfig.hpp\"", "public", "", "public"] }, - { include: ["\i"webserv/utils/utls.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/config/AConfig.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/config/GlobalConfig.hpp\"", "public", "", "public"] }, + + { include: ["\"webserv/utils/utils.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/utils/FileUtils.hpp\"", "public", "", "public"] }, { include: ["\"webserv/server/Server.hpp\"", "public", "", "public"] }, { include: ["\"webserv/client/Client.hpp\"", "public", "", "public"] }, - { include: ["\"webserv/socket/Socket.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/socket/ASocket.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/socket/ClientSocket.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/socket/ServerSocket.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/socket/CgiSocket.hpp\"", "public", "", "public"] }, { include: ["\"webserv/router/Router.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/handler/AHandler.hpp\"", "public", "", "public"] }, { include: ["\"webserv/handler/CgiHandler.hpp\"", "public", "", "public"] }, { include: ["\"webserv/handler/FileHandler.hpp\"", "public", "", "public"] }, { include: ["\"webserv/handler/ErrorHandler.hpp\"", "public", "", "public"] }, - - # ============================================================================ - # FORWARD DECLARATION PREFERENCES - # ============================================================================ - - # Suggest forward declarations instead of full includes in headers where possible - { symbol: ["Client", "private", "", "public"] }, - { symbol: ["Server", "private", "", "public"] }, - { symbol: ["HttpRequest", "private", "", "public"] }, - { symbol: ["HttpResponse", "private", "", "public"] }, - { symbol: ["HttpHeaders", "private", "", "public"] }, - { symbol: ["ServerConfig", "private", "", "public"] }, - { symbol: ["ConfigManager", "private", "", "public"] }, - { symbol: ["LocationConfig", "private", "", "public"] }, - { symbol: ["Socket", "private", "", "public"] }, - { symbol: ["Router", "private", "", "public"] }, - { symbol: ["Channel", "private", "", "public"] } + { include: ["\"webserv/handler/URI.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/handler/CgiProcess.hpp\"", "public", "", "public"] }, + { include: ["\"webserv/handler/CgiEnvironment.hpp\"", "public", "", "public"] }, + # CgiHandler needs CgiProcess for unique_ptr deletion + { include: ["", "public", "", "public"] } ] \ No newline at end of file diff --git a/webserv/client/Client.cpp b/webserv/client/Client.cpp index 9cef293..cb66b8f 100644 --- a/webserv/client/Client.cpp +++ b/webserv/client/Client.cpp @@ -1,25 +1,27 @@ -#include "webserv/handler/CgiHandler.hpp" -#include "webserv/handler/ErrorHandler.hpp" -#include "webserv/socket/ASocket.hpp" -#include "webserv/socket/CgiSocket.hpp" - #include -#include // for HttpHeaders -#include // for Log, LOCATION -#include // for Router -#include // for Server -#include // for Socket -#include // for uint8_t -#include -#include // for ref, reference_wrapper +#include // for CgiHandler +#include // for ErrorHandler +#include // for HttpHeaders +#include // for HttpRequest +#include // for HttpResponse +#include // for Log, LOCATION +#include // for Router +#include // for Server +#include // for ASocket +#include // for ClientSocket + +#include // for uint8_t +#include // for function, ref, reference_wrapper #include // for map -#include -#include // for basic_string, to_string, operator+, operator<=> -#include // for pair, move +#include // for unique_ptr, make_unique, allocator, operator==, default_delete +#include // for runtime_error +#include // for basic_string, to_string, operator+, char_traits, operator<=> +#include // for move, pair +#include // for vector -#include -#include // for ssize_t +#include // for send +#include // for ssize_t Client::Client(std::unique_ptr socket, Server &server) : httpRequest_(std::make_unique(this)), httpResponse_(std::make_unique()), diff --git a/webserv/client/Client.hpp b/webserv/client/Client.hpp index e1528b7..54e89fc 100644 --- a/webserv/client/Client.hpp +++ b/webserv/client/Client.hpp @@ -2,25 +2,28 @@ // #include -#include "webserv/handler/AHandler.hpp" -#include "webserv/router/Router.hpp" -#include "webserv/socket/ASocket.hpp" -#include "webserv/socket/CgiSocket.hpp" - #include // for ServerConfig +#include // for AHandler #include // for OK #include // for HttpRequest #include // for HttpResponse +#include #include +#include +#include #include // for ClientSocket -#include // for size_t -#include // for unique_ptr +#include // for size_t +#include // for unique_ptr +#include // for unordered_map class Server; class ClientSocket; class ServerConfig; class HttpResponse; +class ASocket; +class HttpRequest; +class Router; class Client { diff --git a/webserv/config/AConfig.cpp b/webserv/config/AConfig.cpp index 14ead75..1763fae 100644 --- a/webserv/config/AConfig.cpp +++ b/webserv/config/AConfig.cpp @@ -1,4 +1,5 @@ #include // for AConfig + #include // for ADirective #include // for DirectiveFactory #include // for DirectiveValue diff --git a/webserv/config/ConfigManager.cpp b/webserv/config/ConfigManager.cpp index 60e4519..b73ce15 100644 --- a/webserv/config/ConfigManager.cpp +++ b/webserv/config/ConfigManager.cpp @@ -1,4 +1,5 @@ #include + #include // for GlobalConfig #include // for Log #include // for removeComments diff --git a/webserv/config/LocationConfig.cpp b/webserv/config/LocationConfig.cpp index 53e2f4b..1648ac0 100644 --- a/webserv/config/LocationConfig.cpp +++ b/webserv/config/LocationConfig.cpp @@ -1,6 +1,6 @@ -#include // for AConfig #include -#include // for Log, LOCATION + +#include // for AConfig LocationConfig::LocationConfig(const std::string &block, const std::string &path, const AConfig *parent) : AConfig(parent), _path(path) diff --git a/webserv/config/directive/ADirective.cpp b/webserv/config/directive/ADirective.cpp index dd1c082..331a794 100644 --- a/webserv/config/directive/ADirective.cpp +++ b/webserv/config/directive/ADirective.cpp @@ -1,9 +1,10 @@ #include #include // for DirectiveValue, operator<< -#include // for move -ADirective::ADirective(std::string name) : name_(std::move(name)) //TODO Move here but derived classes take const ref +#include // for move + +ADirective::ADirective(std::string name) : name_(std::move(name)) // TODO Move here but derived classes take const ref { } diff --git a/webserv/config/directive/SizeDirective.cpp b/webserv/config/directive/SizeDirective.cpp index 77136e2..0e470b1 100644 --- a/webserv/config/directive/SizeDirective.cpp +++ b/webserv/config/directive/SizeDirective.cpp @@ -1,10 +1,12 @@ +#include // for SizeDirective + #include // for ADirective #include // for DirectiveValueType -#include // for SizeDirective #include // for trim #include // for __transform_fn, transform #include // for tolower +#include // for exception #include // for invalid_argument SizeDirective::SizeDirective(const std::string &name, const std::string &value) diff --git a/webserv/config/validation/ConfigValidator.cpp b/webserv/config/validation/ConfigValidator.cpp index 5faaea2..d252e41 100644 --- a/webserv/config/validation/ConfigValidator.cpp +++ b/webserv/config/validation/ConfigValidator.cpp @@ -1,4 +1,5 @@ #include + #include // for ValidationEngine #include // for AValidationRule #include // for AllowedValuesRule @@ -36,9 +37,8 @@ ConfigValidator::ConfigValidator(const GlobalConfig *config) : engine_(std::make engine_->addServerRule("root", std::make_unique(false)); /*Location Directive Rules*/ - engine_->addLocationRule("allowed_methods", - std::make_unique(std::vector{"GET", "POST", "DELETE", "PUT"}, - true)); + engine_->addLocationRule("allowed_methods", std::make_unique( + std::vector{"GET", "POST", "DELETE", "PUT"}, true)); engine_->addLocationRule("root", std::make_unique(true)); engine_->addLocationRule("cgi_ext", std::make_unique(false)); diff --git a/webserv/config/validation/ValidationEngine.cpp b/webserv/config/validation/ValidationEngine.cpp index 736fcca..80a6b5e 100644 --- a/webserv/config/validation/ValidationEngine.cpp +++ b/webserv/config/validation/ValidationEngine.cpp @@ -1,8 +1,9 @@ +#include + #include // for AConfig #include // for GlobalConfig #include // for LocationConfig #include // for ServerConfig -#include #include // for ValidationResult #include // for AValidationRule #include // for AStructuralValidationRule diff --git a/webserv/config/validation/ValidationResult.cpp b/webserv/config/validation/ValidationResult.cpp index 3564f92..12b104d 100644 --- a/webserv/config/validation/ValidationResult.cpp +++ b/webserv/config/validation/ValidationResult.cpp @@ -1,4 +1,5 @@ #include + #include // for Log #include // for move diff --git a/webserv/config/validation/directive_rules/AValidationRule.cpp b/webserv/config/validation/directive_rules/AValidationRule.cpp index 1838020..eaea12c 100644 --- a/webserv/config/validation/directive_rules/AValidationRule.cpp +++ b/webserv/config/validation/directive_rules/AValidationRule.cpp @@ -2,7 +2,6 @@ #include // for AConfig #include // for ValidationResult -#include // for LOCATION, Log #include // for move diff --git a/webserv/handler/AHandler.cpp b/webserv/handler/AHandler.cpp index 8c0aab3..d6c88c0 100644 --- a/webserv/handler/AHandler.cpp +++ b/webserv/handler/AHandler.cpp @@ -1,14 +1,17 @@ -#include "webserv/log/Log.hpp" +#include // for AHandler -#include -#include -#include -#include -#include +#include // for Client +#include // for AConfig +#include // for URI +#include // for HttpRequest +#include // for Log +#include // for TimerSocket -#include -#include -#include +#include // for operator*, milliseconds +#include // for function +#include // for unique_ptr, make_unique +#include // for optional +#include // for basic_string, operator+, to_string AHandler::AHandler(const HttpRequest &request, HttpResponse &response) : request_(request), response_(response) {} diff --git a/webserv/handler/AHandler.hpp b/webserv/handler/AHandler.hpp index eaca3af..689364e 100644 --- a/webserv/handler/AHandler.hpp +++ b/webserv/handler/AHandler.hpp @@ -1,10 +1,12 @@ #pragma once -#include "webserv/socket/TimerSocket.hpp" +#include + +#include // for unique_ptr -#include class HttpRequest; class HttpResponse; +class TimerSocket; class AHandler { diff --git a/webserv/handler/CgiEnvironment.cpp b/webserv/handler/CgiEnvironment.cpp index 8415385..8c2fe7a 100644 --- a/webserv/handler/CgiEnvironment.cpp +++ b/webserv/handler/CgiEnvironment.cpp @@ -1,8 +1,11 @@ -#include "webserv/handler/CgiEnvironment.hpp" +#include -#include "webserv/log/Log.hpp" +#include // for URI +#include // for HttpHeaders -#include // for strcpy +#include // for strcpy, size_t +#include // for optional +#include // for pair CgiEnvironment::CgiEnvironment(const URI &uri, const HttpRequest &request) { @@ -46,8 +49,6 @@ CgiEnvironment::CgiEnvironment(const URI &uri, const HttpRequest &request) env_["HTTP_ACCEPT"] = headers.get("Accept"); env_["HTTP_ACCEPT_LANGUAGE"] = headers.get("Accept-Language"); env_["HTTP_ACCEPT_ENCODING"] = headers.get("Accept-Encoding"); - - } char **CgiEnvironment::toEnvp() const diff --git a/webserv/handler/CgiEnvironment.hpp b/webserv/handler/CgiEnvironment.hpp index a01b4fd..897a559 100644 --- a/webserv/handler/CgiEnvironment.hpp +++ b/webserv/handler/CgiEnvironment.hpp @@ -1,21 +1,22 @@ #pragma once -#include -#include -#include "webserv/handler/URI.hpp" -#include "webserv/http/HttpRequest.hpp" -#include "webserv/utils/FileUtils.hpp" -#include "webserv/log/Log.hpp" +#include +#include // for HttpRequest +#include +#include + +#include // for map +#include // for basic_string, string + +class URI; class CgiEnvironment { -public: - CgiEnvironment(const URI &uri, const HttpRequest &request); + public: + CgiEnvironment(const URI &uri, const HttpRequest &request); - [[nodiscard]] char **toEnvp() const; + [[nodiscard]] char **toEnvp() const; - -private: - std::map env_; - + private: + std::map env_; }; diff --git a/webserv/handler/CgiHandler.cpp b/webserv/handler/CgiHandler.cpp index a147362..6c2b69f 100644 --- a/webserv/handler/CgiHandler.cpp +++ b/webserv/handler/CgiHandler.cpp @@ -1,15 +1,19 @@ -#include "webserv/handler/ErrorHandler.hpp" +#include #include // for Client -#include -#include // for CgiProcess -#include // for HttpRequest -#include // for HttpResponse -#include // for Log -#include // for CgiSocket -#include // for stoul +#include // for CgiProcess +#include // for ErrorHandler +#include // for HttpRequest +#include // for HttpResponse +#include // for Log, LOCATION +#include // for CgiSocket +#include // for TimerSocket +#include // for trim -#include +#include // for function +#include // for move + +#include // for ssize_t CgiHandler::CgiHandler(const HttpRequest &request, HttpResponse &response) : AHandler(request, response), cgiProcess_(nullptr), cgiStdIn_(nullptr), cgiStdOut_(nullptr) diff --git a/webserv/handler/CgiHandler.hpp b/webserv/handler/CgiHandler.hpp index 2078628..9e2a9bd 100644 --- a/webserv/handler/CgiHandler.hpp +++ b/webserv/handler/CgiHandler.hpp @@ -1,11 +1,18 @@ #pragma once -#include "webserv/handler/AHandler.hpp" -#include "webserv/socket/CgiSocket.hpp" +#include // for AHandler +#include // for HttpRequest +#include // for CgiSocket -#include +#include // for unique_ptr +#include // for string +#include // for vector + +#include // for size_t +#include // for uint8_t class CgiProcess; +class HttpResponse; class CgiHandler : public AHandler { @@ -21,7 +28,8 @@ class CgiHandler : public AHandler void handle() override; void wait() noexcept; - void setCgiSockets(std::unique_ptr cgiStdIn, std::unique_ptr cgiStdOut, std::unique_ptr cgiStdErr); + void setCgiSockets(std::unique_ptr cgiStdIn, std::unique_ptr cgiStdOut, + std::unique_ptr cgiStdErr); void setPid(int pid); protected: @@ -42,7 +50,6 @@ class CgiHandler : public AHandler int pid_ = -1; - void write(); void read(); void error(); diff --git a/webserv/handler/CgiProcess.cpp b/webserv/handler/CgiProcess.cpp index d115848..33edab4 100644 --- a/webserv/handler/CgiProcess.cpp +++ b/webserv/handler/CgiProcess.cpp @@ -1,22 +1,23 @@ -#include "webserv/handler/CgiProcess.hpp" +#include -#include "webserv/handler/CgiEnvironment.hpp" -#include "webserv/http/HttpRequest.hpp" -#include "webserv/log/Log.hpp" -#include "webserv/socket/CgiSocket.hpp" +#include // for CgiEnvironment +#include // for CgiHandler +#include // for URI +#include // for HttpRequest +#include // for Log +#include // for ASocket +#include // for CgiSocket -#include +#include // for kill, SIGKILL +#include // for exit +#include // for allocator, make_unique, unique_ptr +#include // for runtime_error +#include // for basic_string, operator+, to_string, char_traits, string +#include // for move -#include -#include -#include -#include -#include - -#include -#include -#include -#include +#include // for O_CLOEXEC, O_NONBLOCK +#include // for waitpid, WNOHANG +#include // for close, dup2, pipe2, execve, fork, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO CgiProcess::CgiProcess(const HttpRequest &request, CgiHandler &handler) : request_(request), handler_(handler), _pid(-1) { @@ -41,7 +42,8 @@ void CgiProcess::spawn() int pipeStdout[2]; int pipeStderr[2]; - if (pipe2(pipeStdin, O_CLOEXEC | O_NONBLOCK) == -1 || pipe2(pipeStdout, O_CLOEXEC | O_NONBLOCK) == -1 || pipe2(pipeStderr, O_CLOEXEC | O_NONBLOCK) == -1) + if (pipe2(pipeStdin, O_CLOEXEC | O_NONBLOCK) == -1 || pipe2(pipeStdout, O_CLOEXEC | O_NONBLOCK) == -1 + || pipe2(pipeStderr, O_CLOEXEC | O_NONBLOCK) == -1) { throw std::runtime_error("Failed to create pipes"); } diff --git a/webserv/handler/CgiProcess.hpp b/webserv/handler/CgiProcess.hpp index 98bde3a..68221f1 100644 --- a/webserv/handler/CgiProcess.hpp +++ b/webserv/handler/CgiProcess.hpp @@ -1,7 +1,9 @@ #pragma once -#include "webserv/handler/CgiHandler.hpp" -#include "webserv/http/HttpRequest.hpp" +#include +#include // for HttpRequest + +class CgiHandler; class CgiProcess { diff --git a/webserv/handler/ErrorHandler.cpp b/webserv/handler/ErrorHandler.cpp index c3a9c8c..903fc34 100644 --- a/webserv/handler/ErrorHandler.cpp +++ b/webserv/handler/ErrorHandler.cpp @@ -1,15 +1,15 @@ +#include // for ErrorHandler + #include // for AConfig #include // for ConfigManager #include // for GlobalConfig -#include // for ErrorHandler #include // for getStatusCodeReason, INTERNAL_SERVER_ERROR #include // for HttpResponse #include // for Log, LOCATION #include // for basic_ifstream, basic_filebuf, basic_ostream::operator<<, ifstream, stringstream -#include // for allocator, make_unique, unique_ptr #include // for basic_stringstream -#include // for basic_string, char_traits, operator+, string, to_string +#include // for allocator, basic_string, char_traits, operator+, string, to_string void ErrorHandler::createErrorResponse(uint16_t statusCode, HttpResponse &response, const AConfig *config) { diff --git a/webserv/handler/ErrorHandler.hpp b/webserv/handler/ErrorHandler.hpp index a469cda..1e3cf4c 100644 --- a/webserv/handler/ErrorHandler.hpp +++ b/webserv/handler/ErrorHandler.hpp @@ -10,6 +10,7 @@ #include class AConfig; +class HttpResponse; class ErrorHandler { diff --git a/webserv/handler/FileHandler.cpp b/webserv/handler/FileHandler.cpp index 16cd337..60a38be 100644 --- a/webserv/handler/FileHandler.cpp +++ b/webserv/handler/FileHandler.cpp @@ -1,6 +1,7 @@ +#include + #include // for AConfig #include // for ErrorHandler -#include #include // for MIMETypes #include // for URI #include // for NOT_FOUND, FORBIDDEN, OK @@ -8,10 +9,9 @@ #include // for Log, LOCATION #include // for joinPath, getExtension, isFile, readBinaryFile -#include // for unique_ptr, allocator, make_unique #include // for optional #include // for __find_if_fn, find_if -#include // for basic_string, string, operator+, char_traits +#include // for basic_string, allocator, operator+, string, char_traits #include // for vector FileHandler::FileHandler(const HttpRequest &request, HttpResponse &response) @@ -91,16 +91,10 @@ void FileHandler::handle() switch (resourceType) { - case FILE: - handleFile(filepath); - return; + case FILE: handleFile(filepath); return; case DIRECTORY_AUTOINDEX: - case DIRECTORY_INDEX: - handleDirectory(filepath, resourceType); - return; - case NOT_FOUND: - ErrorHandler::createErrorResponse(Http::StatusCode::NOT_FOUND, response_, config_); - return; + case DIRECTORY_INDEX: handleDirectory(filepath, resourceType); return; + case NOT_FOUND: ErrorHandler::createErrorResponse(Http::StatusCode::NOT_FOUND, response_, config_); return; } ErrorHandler::createErrorResponse(Http::StatusCode::NOT_FOUND, response_, config_); } diff --git a/webserv/handler/FileHandler.hpp b/webserv/handler/FileHandler.hpp index 0f604ba..3f94175 100644 --- a/webserv/handler/FileHandler.hpp +++ b/webserv/handler/FileHandler.hpp @@ -1,11 +1,10 @@ #pragma once -#include "webserv/http/HttpRequest.hpp" - #include -#include #include +#include // for AHandler #include +#include // for HttpRequest #include // for HttpResponse #include // for uint8_t @@ -14,6 +13,7 @@ class AConfig; class URI; +class HttpResponse; class FileHandler : public AHandler { @@ -33,8 +33,9 @@ class FileHandler : public AHandler void handleTimeout() override; private: - const URI &uri_; + const URI &uri_; const AConfig *config_; + enum ResourceType : uint8_t { FILE, diff --git a/webserv/handler/URI.cpp b/webserv/handler/URI.cpp index 434614c..f980fa6 100644 --- a/webserv/handler/URI.cpp +++ b/webserv/handler/URI.cpp @@ -1,14 +1,16 @@ -#include "webserv/log/Log.hpp" +#include #include // for AConfig #include // for LocationConfig #include // for ServerConfig -#include #include // for HttpHeaders -#include // for joinPath, getExtension, isDirectory, isFile, isValidPath +#include // for Log, LOCATION +#include // for joinPath, isDirectory, isFile, getExtension, isValidPath #include // for trim, split #include // for size_t +#include // for vector +#include // for map #include // for optional, operator!= #include // for vector diff --git a/webserv/handler/URI.hpp b/webserv/handler/URI.hpp index 39350d5..5e5c168 100644 --- a/webserv/handler/URI.hpp +++ b/webserv/handler/URI.hpp @@ -6,7 +6,6 @@ #include // for HttpRequest #include - #include // for string, basic_string class LocationConfig; diff --git a/webserv/http/HttpHeaders.cpp b/webserv/http/HttpHeaders.cpp index 95b9ea6..766fbc5 100644 --- a/webserv/http/HttpHeaders.cpp +++ b/webserv/http/HttpHeaders.cpp @@ -1,5 +1,6 @@ -#include // for CRLF #include // for HttpHeaders + +#include // for CRLF #include #include // for trim diff --git a/webserv/http/HttpRequest.cpp b/webserv/http/HttpRequest.cpp index bf8811c..248f1a5 100644 --- a/webserv/http/HttpRequest.cpp +++ b/webserv/http/HttpRequest.cpp @@ -1,19 +1,17 @@ -#include "webserv/config/ConfigManager.hpp" -#include "webserv/config/ServerConfig.hpp" -#include "webserv/handler/URI.hpp" - -#include // for Client -#include // for CRLF, DOUBLE_CRLF, BAD_REQUEST #include + +#include // for ConfigManager +#include // for URI +#include // for CRLF, DOUBLE_CRLF #include // for Log, LOCATION #include // for stoul -#include // for map -#include -#include // for optional -#include // for basic_stringstream, basic_istream, stringstream -#include // for pair -#include // for vector +#include // for exception +#include // for map +#include // for allocator, make_unique, unique_ptr +#include // for optional +#include // for basic_stringstream, basic_istream, stringstream +#include // for vector HttpRequest::HttpRequest(Client *client) : client_(client), uri_(nullptr) { @@ -43,8 +41,7 @@ void HttpRequest::setState(State state) state_ = State::ParseError; return; } - uri_ = std::make_unique( - *this, *serverConfig); + uri_ = std::make_unique(*this, *serverConfig); } state_ = state; } diff --git a/webserv/http/HttpRequest.hpp b/webserv/http/HttpRequest.hpp index 4b0a9ec..7dfd0c2 100644 --- a/webserv/http/HttpRequest.hpp +++ b/webserv/http/HttpRequest.hpp @@ -5,8 +5,8 @@ #include // for size_t #include // for uint8_t -#include -#include // for string, basic_string +#include // for unique_ptr +#include // for string, basic_string class Client; class ServerConfig; diff --git a/webserv/http/HttpResponse.cpp b/webserv/http/HttpResponse.cpp index c933cff..2c4997a 100644 --- a/webserv/http/HttpResponse.cpp +++ b/webserv/http/HttpResponse.cpp @@ -1,6 +1,7 @@ -#include // for getStatusCodeReason #include +#include // for getStatusCodeReason + #include // for basic_string, operator+, string, char_traits, to_string #include // for vector diff --git a/webserv/http/HttpResponse.hpp b/webserv/http/HttpResponse.hpp index 1e287e0..9af2b2a 100644 --- a/webserv/http/HttpResponse.hpp +++ b/webserv/http/HttpResponse.hpp @@ -4,6 +4,7 @@ #include // for LOCATION, Log #include // for uint8_t, uint16_t +#include // for vector #include // for unique_ptr #include // for string #include // for vector diff --git a/webserv/log/FileChannel.cpp b/webserv/log/FileChannel.cpp index f074435..bef8800 100644 --- a/webserv/log/FileChannel.cpp +++ b/webserv/log/FileChannel.cpp @@ -1,14 +1,12 @@ #include + #include // for Log -#include // for system_clock -#include +#include // for system_clock #include // for localtime, tm #include // for operator<<, put_time #include // for cerr -#include - struct tm; FileChannel::FileChannel(const std::string &filename) : filename_(filename), fileStream_(filename, std::ios_base::trunc) diff --git a/webserv/main.cpp b/webserv/main.cpp index 4dcdf04..2ed2372 100644 --- a/webserv/main.cpp +++ b/webserv/main.cpp @@ -4,10 +4,10 @@ #include // for Log #include // for Server +#include #include // for ios_base #include // for allocator, basic_string, char_traits, operator+, string #include // for vector -#include int main(int argc, char **argv) { diff --git a/webserv/router/Router.cpp b/webserv/router/Router.cpp index 1164eb7..6807e4e 100644 --- a/webserv/router/Router.cpp +++ b/webserv/router/Router.cpp @@ -1,21 +1,25 @@ -#include "webserv/handler/CgiProcess.hpp" +#include // for Router +#include // for Client #include // for AConfig -#include // for ConfigManager #include // for ADirective #include // for DirectiveValue -#include // for ErrorHandler +#include // for CgiHandler +#include // for CgiProcess #include // for FileHandler #include // for URI -#include // for HttpHeaders -#include // for LOCATION, Log -#include +#include // for HttpRequest +#include // for Log, LOCATION -#include // for unique_ptr -#include // for optional -#include // for __find_fn, find -#include // for basic_string, string -#include // for vector +#include // for exception +#include // for vector +#include // for unique_ptr, make_unique +#include // for optional +#include // for __find_fn, find +#include // for basic_string, string, operator+ +#include // for vector + +class HttpResponse; Router::Router(Client *client) : client_(client) { @@ -41,7 +45,7 @@ std::unique_ptr Router::handleRequest() if (request.getState() == HttpRequest::State::ParseError) { Log::error("Router::handleRequest() called with incomplete request"); - + return nullptr; } HttpResponse &response = client_->getHttpResponse(); diff --git a/webserv/router/Router.hpp b/webserv/router/Router.hpp index f622e91..c399270 100644 --- a/webserv/router/Router.hpp +++ b/webserv/router/Router.hpp @@ -1,8 +1,8 @@ #pragma once -#include "webserv/handler/AHandler.hpp" #include // for AConfig #include +#include // for AHandler #include // for HttpRequest #include // for HttpResponse @@ -11,6 +11,7 @@ class LocationConfig; class ServerConfig; +class Client; class Router { diff --git a/webserv/server/Server.cpp b/webserv/server/Server.cpp index f3b91e8..98c7770 100644 --- a/webserv/server/Server.cpp +++ b/webserv/server/Server.cpp @@ -1,33 +1,31 @@ -#include "webserv/utils/utils.hpp" +#include #include // for Client #include // for ConfigManager #include // for ServerConfig #include // for Log, LOCATION -#include -#include +#include // for ASocket #include // for ClientSocket #include // for ServerSocket +#include // for stateToEpoll -#include // for errno +#include // for errno, EBADF, ENOENT, EINTR +#include // for SIGINT, sig_atomic_t #include // for strerror #include // for exception #include // for unique_ptr, allocator, make_unique #include // for optional -#include // for runtime_error +#include // for runtime_error, invalid_argument #include // for basic_string, operator+, to_string, char_traits, string -#include // for unordered_map, operator== -#include // for move, pair -#include // for vector +#include // for unordered_map +#include // for move +#include // for vector, erase_if -#include -#include // for epoll_event, epoll_ctl, EPOLLIN, EPOLLOUT, epoll_create1, epoll_wait, EPOLLERR, EPOLLHUP, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD -#include // for send, SOMAXCONN -#include // for ssize_t +#include // for O_CLOEXEC +#include // for uint32_t +#include // for epoll_event, epoll_ctl, EPOLLOUT, EPOLL_CTL_MOD, epoll_create1, epoll_wait, EPOLLERR, EPOLLHUP, EPOLLIN, EPOLL_CTL_ADD, EPOLL_CTL_DEL +#include // for SOMAXCONN #include // for close -#include - -class Router; volatile sig_atomic_t Server::stop_ = 0; diff --git a/webserv/server/Server.hpp b/webserv/server/Server.hpp index 7c2d26c..44f6899 100644 --- a/webserv/server/Server.hpp +++ b/webserv/server/Server.hpp @@ -7,7 +7,7 @@ #include #include // for ServerSocket -#include +#include // for sig_atomic_t #include // for uint32_t #include // for unique_ptr #include // for set diff --git a/webserv/socket/ASocket.cpp b/webserv/socket/ASocket.cpp index 7bb4469..98c0704 100644 --- a/webserv/socket/ASocket.cpp +++ b/webserv/socket/ASocket.cpp @@ -1,12 +1,14 @@ -#include // for Log, LOCATION #include +#include // for Log, LOCATION + #include // for runtime_error -#include // for basic_string +#include // for operator+, basic_string, to_string, allocator, char_traits, string #include // for generic_category, system_error +#include // for move #include // for errno -#include // for fcntl, F_SETFL, O_NONBLOCK +#include // for fcntl, FD_CLOEXEC, F_GETFD, F_GETFL, O_NONBLOCK, F_SETFD, F_SETFL #include // for recv, send #include // for close diff --git a/webserv/socket/CgiSocket.cpp b/webserv/socket/CgiSocket.cpp index 73a2dd8..346ff80 100644 --- a/webserv/socket/CgiSocket.cpp +++ b/webserv/socket/CgiSocket.cpp @@ -1,8 +1,12 @@ -#include // for LOCATION, Log -#include // for ASocket #include -#include +#include // for LOCATION, Log +#include // for ASocket + +#include // for generic_category, system_error + +#include // for errno +#include // for read, write CgiSocket::CgiSocket(int fd, ASocket::IoState event) : ASocket(fd, event) { diff --git a/webserv/socket/CgiSocket.hpp b/webserv/socket/CgiSocket.hpp index 4af4ab3..97276c3 100644 --- a/webserv/socket/CgiSocket.hpp +++ b/webserv/socket/CgiSocket.hpp @@ -2,8 +2,9 @@ #include // for ASocket +#include // for size_t #include -#include +#include // for ssize_t #include class CgiSocket : public ASocket diff --git a/webserv/socket/ClientSocket.cpp b/webserv/socket/ClientSocket.cpp index 5a9685e..cf18c1d 100644 --- a/webserv/socket/ClientSocket.cpp +++ b/webserv/socket/ClientSocket.cpp @@ -1,6 +1,7 @@ +#include + #include // for LOCATION, Log #include // for ASocket -#include ClientSocket::ClientSocket(int fd) : ASocket(fd) { diff --git a/webserv/socket/ServerSocket.cpp b/webserv/socket/ServerSocket.cpp index c63bbc0..afd90bc 100644 --- a/webserv/socket/ServerSocket.cpp +++ b/webserv/socket/ServerSocket.cpp @@ -1,13 +1,15 @@ +#include + #include // for Log, LOCATION #include // for ASocket #include // for ClientSocket -#include #include // for allocator, make_unique, unique_ptr #include // for runtime_error #include // for htons, inet_addr #include // for sockaddr_in, in_addr +#include // for uint16_t #include // for AF_INET, accept, bind, listen, setsockopt, socket, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR #include // for close diff --git a/webserv/socket/TimerSocket.cpp b/webserv/socket/TimerSocket.cpp index 1162cb3..75c596c 100644 --- a/webserv/socket/TimerSocket.cpp +++ b/webserv/socket/TimerSocket.cpp @@ -1,12 +1,16 @@ -#include "webserv/log/Log.hpp" -#include "webserv/socket/ASocket.hpp" - #include -#include +#include // for LOCATION, Log +#include // for ASocket -#include -#include +#include // for runtime_error +#include // for generic_category, system_error + +#include // for errno +#include // for CLOCK_MONOTONIC +#include // for timerfd_create, timerfd_settime +#include // for itimerspec, timespec +#include // for read, write TimerSocket::TimerSocket(std::chrono::milliseconds timeout) : ASocket(timerfd_create(CLOCK_MONOTONIC, 0), ASocket::IoState::NONE), timeout_(timeout) diff --git a/webserv/socket/TimerSocket.hpp b/webserv/socket/TimerSocket.hpp index 70895fa..fde093f 100644 --- a/webserv/socket/TimerSocket.hpp +++ b/webserv/socket/TimerSocket.hpp @@ -1,8 +1,11 @@ #pragma once -#include "webserv/socket/ASocket.hpp" +#include // for ASocket -#include +#include // for milliseconds + +#include // for size_t +#include // for ssize_t class TimerSocket : public ASocket { diff --git a/webserv/utils/utils.cpp b/webserv/utils/utils.cpp index b28bd09..d29db36 100644 --- a/webserv/utils/utils.cpp +++ b/webserv/utils/utils.cpp @@ -1,8 +1,8 @@ -#include "webserv/socket/ASocket.hpp" - #include +#include + #include #include #include diff --git a/webserv/utils/utils.hpp b/webserv/utils/utils.hpp index 01c312b..688c84e 100644 --- a/webserv/utils/utils.hpp +++ b/webserv/utils/utils.hpp @@ -1,6 +1,6 @@ #pragma once -#include "webserv/socket/ASocket.hpp" +#include #include // for size_t #include