From 0a26702457a12de3b0cc3dca5035dbff5103b64d Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Tue, 16 Sep 2025 15:35:04 +0200 Subject: [PATCH] Update server configuration and improve utility functions: change host to 127.0.0.1, modify root path, enhance trimSemi function, and adjust directive parsing logic. --- config/default.conf | 1 + webserv/config/ConfigManager.cpp | 2 +- webserv/config/ServerConfig.cpp | 8 ++++---- webserv/config/utils.cpp | 11 +++++++++++ webserv/config/utils.hpp | 3 ++- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/config/default.conf b/config/default.conf index 8c90f38..6488c39 100644 --- a/config/default.conf +++ b/config/default.conf @@ -42,6 +42,7 @@ server { asdfasdfasdf server { listen 80; + host 127.0.0.1; server_name mylocal; root /var/www/html2; diff --git a/webserv/config/ConfigManager.cpp b/webserv/config/ConfigManager.cpp index bb7ccce..e3c1264 100644 --- a/webserv/config/ConfigManager.cpp +++ b/webserv/config/ConfigManager.cpp @@ -43,7 +43,7 @@ void removeEmptyLines(std::string &str) { if (!trim(line).empty()) { - result += line + '\n'; + result += trimSemi(trim(line)) + '\n'; } } str = result; diff --git a/webserv/config/ServerConfig.cpp b/webserv/config/ServerConfig.cpp index 24542fb..ac90454 100644 --- a/webserv/config/ServerConfig.cpp +++ b/webserv/config/ServerConfig.cpp @@ -59,7 +59,7 @@ void ServerConfig::parseDirectives(const std::string &declarations) while (std::getline(stream, line)) { std::string directive; - std::istringstream lineStream{trim(line)}; + std::istringstream lineStream{line}; lineStream >> directive; if (!directive.empty()) { @@ -80,10 +80,10 @@ void ServerConfig::parseDirectives(const std::string &declarations) root = value; std::cout << "Set root to " << root << '\n'; } - else if (directive == "server_name") + else if (directive == "host") { host = value; - std::cout << "Set server_name to " << host << '\n'; + std::cout << "Set host to " << host << '\n'; } else if (directive == "cgi_pass") { @@ -123,7 +123,7 @@ void ServerConfig::parseDirectives(const std::string &declarations) const LocationConfig &ServerConfig::getLocation(const std::string &path) const { - if (locations.count(path) > 0 ) // NOLINT + if (locations.count(path) > 0) // NOLINT { return locations.at(path); } diff --git a/webserv/config/utils.cpp b/webserv/config/utils.cpp index d845e19..74e3f82 100644 --- a/webserv/config/utils.cpp +++ b/webserv/config/utils.cpp @@ -13,6 +13,17 @@ std::string trim(const std::string &str) return str.substr(first, last - first + 1); } +std::string trimSemi(const std::string &str) +{ + size_t semi = str.find(';'); + + if (semi == str.length() - 1) + { + return str.substr(0, semi); + } + return str; +} + size_t findCorrespondingClosingBrace(const std::string &str, size_t openPos) { int braceCount = 1; diff --git a/webserv/config/utils.hpp b/webserv/config/utils.hpp index 0b24b58..5242ad9 100644 --- a/webserv/config/utils.hpp +++ b/webserv/config/utils.hpp @@ -2,5 +2,6 @@ #include +std::string trimSemi(const std::string &str); std::string trim(const std::string &str); -size_t findCorrespondingClosingBrace(const std::string &str, size_t openPos); +size_t findCorrespondingClosingBrace(const std::string &str, size_t openPos); \ No newline at end of file