diff --git a/.clang-format b/.clang-format index 0e612b8..be4867f 100644 --- a/.clang-format +++ b/.clang-format @@ -35,4 +35,7 @@ AllowShortFunctionsOnASingleLine: Inline AllowShortIfStatementsOnASingleLine: true AllowShortLoopsOnASingleLine: true AllowShortBlocksOnASingleLine: Empty -AllowShortCaseLabelsOnASingleLine: true \ No newline at end of file +AllowShortCaseLabelsOnASingleLine: true + +# Add empty line between function definitions +SeparateDefinitionBlocks: Always \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d3c7b17..ca93617 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -67,6 +67,34 @@ "dependsOn": "Build ASAN", "detail": "Build and run AddressSanitizer version" }, + { + "label": "Format Code", + "type": "shell", + "command": "find webserv -name '*.cpp' -o -name '*.hpp' | xargs clang-format -i", + "group": "build", + "detail": "Format all C++ source and header files using clang-format", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": false + } + }, + { + "label": "Check Format", + "type": "shell", + "command": "find webserv -name '*.cpp' -o -name '*.hpp' | xargs clang-format --dry-run --Werror", + "group": "test", + "detail": "Check if all files are properly formatted (without modifying them)", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared" + } + }, { "label": "Clean", "type": "shell", diff --git a/webserv/client/Client.hpp b/webserv/client/Client.hpp index 2414c22..7924d8c 100644 --- a/webserv/client/Client.hpp +++ b/webserv/client/Client.hpp @@ -3,8 +3,9 @@ #include "webserv/socket/Socket.hpp" #include -#include #include +#include + #include class Server; diff --git a/webserv/config/ConfigManager.hpp b/webserv/config/ConfigManager.hpp index 3e8cacf..4e59515 100644 --- a/webserv/config/ConfigManager.hpp +++ b/webserv/config/ConfigManager.hpp @@ -5,7 +5,6 @@ #include #include - class ConfigManager { public: @@ -16,7 +15,8 @@ class ConfigManager void init(const std::string &filePath); static ConfigManager &getInstance(); - const std::vector &getServerConfigs() const { return serverConfigs_; } + + [[nodiscard]] const std::vector &getServerConfigs() const { return serverConfigs_; } private: bool initialized_; diff --git a/webserv/config/LocationConfig.cpp b/webserv/config/LocationConfig.cpp index 1914fe0..3ad2e59 100644 --- a/webserv/config/LocationConfig.cpp +++ b/webserv/config/LocationConfig.cpp @@ -14,6 +14,7 @@ void LocationConfig::parseLocationBlock(const std::string &block) { parseDirectives(block); } + void LocationConfig::parseDirectives(const std::string &declarations) { std::istringstream stream(declarations); diff --git a/webserv/config/ServerConfig.hpp b/webserv/config/ServerConfig.hpp index a87deee..26a3a67 100644 --- a/webserv/config/ServerConfig.hpp +++ b/webserv/config/ServerConfig.hpp @@ -12,16 +12,24 @@ class ServerConfig ServerConfig(const std::string &serverBlock); [[nodiscard]] const std::string &getHost() const { return host_; } + [[nodiscard]] int getPort() const { return port_; } + [[nodiscard]] const std::string &getRoot() const { return root_; } + [[nodiscard]] const std::string &getCgiPass() const { return cgi_pass_; } + [[nodiscard]] const std::string &getCgiExt() const { return cgi_ext_; } + [[nodiscard]] const std::map &getErrorPages() const { return error_page_; } + [[nodiscard]] const std::vector &getIndexFiles() const { return index_files_; } + [[nodiscard]] const LocationConfig &getLocation(const std::string &path) const; [[nodiscard]] std::vector getLocationPaths() const; void setServerFD(int fd) { server_fd_ = fd; } + [[nodiscard]] int getServerFD() const { return server_fd_; } private: diff --git a/webserv/http/HttpRequest.cpp b/webserv/http/HttpRequest.cpp index e508585..4316f7a 100644 --- a/webserv/http/HttpRequest.cpp +++ b/webserv/http/HttpRequest.cpp @@ -1,14 +1,15 @@ +#include +#include +#include #include #include -#include -#include -#include HttpRequest::HttpRequest(const ServerConfig *serverConfig, const Client *client) : serverConfig_(serverConfig), client_(client) { Log::trace("HttpRequest constructor called"); } + HttpRequest::~HttpRequest() { Log::trace("HttpRequest destructor called"); diff --git a/webserv/http/HttpRequest.hpp b/webserv/http/HttpRequest.hpp index aff01be..1868f83 100644 --- a/webserv/http/HttpRequest.hpp +++ b/webserv/http/HttpRequest.hpp @@ -7,6 +7,7 @@ #include class Client; + class HttpRequest { public: diff --git a/webserv/http/HttpResponse.cpp b/webserv/http/HttpResponse.cpp index 6abe1f8..5170b35 100644 --- a/webserv/http/HttpResponse.cpp +++ b/webserv/http/HttpResponse.cpp @@ -1,5 +1,3 @@ #include -HttpResponse::HttpResponse() -{ -} +HttpResponse::HttpResponse() {} diff --git a/webserv/http/HttpResponse.hpp b/webserv/http/HttpResponse.hpp index 13bc871..1865c99 100644 --- a/webserv/http/HttpResponse.hpp +++ b/webserv/http/HttpResponse.hpp @@ -4,4 +4,4 @@ class HttpResponse { public: HttpResponse(); -}; \ No newline at end of file +}; \ No newline at end of file diff --git a/webserv/main.cpp b/webserv/main.cpp index 6b8fe0f..0e97fd3 100644 --- a/webserv/main.cpp +++ b/webserv/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char **argv) Log::setFileChannel("webserv.log", std::ios_base::app, Log::Level::Trace); Log::setStdoutChannel(Log::Level::Trace); Log::info("\n======================\nStarting webserv...\n======================\n"); - Log::warning("Testing context", {{ "key1", "value1"}, {"key2", "value2"}}); + Log::warning("Testing context", {{"key1", "value1"}, {"key2", "value2"}}); ConfigManager::getInstance().init(argv[1]); // NOLINT Server server(ConfigManager::getInstance()); server.start(); diff --git a/webserv/router/Router.cpp b/webserv/router/Router.cpp index 786a566..09e4afe 100644 --- a/webserv/router/Router.cpp +++ b/webserv/router/Router.cpp @@ -1,5 +1,3 @@ #include -Router::Router() -{ -} +Router::Router() {} diff --git a/webserv/router/Router.hpp b/webserv/router/Router.hpp index 224b5d9..10e1177 100644 --- a/webserv/router/Router.hpp +++ b/webserv/router/Router.hpp @@ -7,5 +7,4 @@ class Router { public: Router(); - }; \ No newline at end of file diff --git a/webserv/socket/Socket.cpp b/webserv/socket/Socket.cpp index fbfec79..60a584a 100644 --- a/webserv/socket/Socket.cpp +++ b/webserv/socket/Socket.cpp @@ -54,6 +54,7 @@ void Socket::listen(int backlog) const throw std::runtime_error("Listen failed"); } } + void Socket::bind(const std::string &host, const int port) const {