From b418e4c25afc4c1e47f2772fef30582572e2eefb Mon Sep 17 00:00:00 2001 From: adjoly Date: Thu, 8 May 2025 12:03:42 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=E2=9C=A8=E3=80=8D=20feat:=20changed?= =?UTF-8?q?=20a=20few=20things=20to=20be=20more=20production=20ready?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.lock | 12 ++++++------ flake.nix | 13 +++++++------ includes/help.hpp | 6 +++++- sample.toml | 5 +++++ src/config/Route.cpp | 2 +- src/help.cpp | 16 ++++++++-------- src/main.cpp | 18 +++++++++++++++--- 7 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 sample.toml diff --git a/flake.lock b/flake.lock index 40b4963..85a8ce6 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1744232761, - "narHash": "sha256-gbl9hE39nQRpZaLjhWKmEu5ejtQsgI5TWYrIVVJn30U=", + "lastModified": 1746461020, + "narHash": "sha256-7+pG1I9jvxNlmln4YgnlW4o+w0TZX24k688mibiFDUE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "f675531bc7e6657c10a18b565cfebd8aa9e24c14", + "rev": "3730d8a308f94996a9ba7c7138ede69c1b9ac4ae", "type": "github" }, "original": { @@ -54,11 +54,11 @@ ] }, "locked": { - "lastModified": 1738098586, - "narHash": "sha256-jibZsqeSh74PLIsOVdp2jIDiYxTHzlVaat0AXRcpeiU=", + "lastModified": 1745683407, + "narHash": "sha256-KBxdhcU39pctJx1yVSxiWVRNazzBRtwch7NYjwstf5s=", "owner": "y-syo", "repo": "pogit", - "rev": "29a0535fea029e1c5e7762f187fc259f93927e31", + "rev": "16adbe5cc1f39314761ec53d348cb86b60c901af", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 53ed6f1..b09b03d 100644 --- a/flake.nix +++ b/flake.nix @@ -34,19 +34,20 @@ name = "webserv"; src = pkgs.fetchgit { url = "https://github.com/keyzox71/webserv.git"; - rev = "8ef2803"; # Specify the revision - sha256 = "kjHPL1LInRv+8RE2Cyqt2R9M8qxpvkmvNjLhQLm3AWs="; # Specify the SHA-256 hash - fetchSubmodules = true; + rev = "8f6875d"; # Specify the revision + sha256 = "XEy48IhXGLHw5+DI2oaV03P7rWzH+gSbOLYrbO2YTrE="; # Specify the SHA-256 hash + fetchSubmodules = true; # need it for tomlpp }; buildInputs = with pkgs; [ clang ]; buildPhase = '' - PKGS=true make + PKGS=true make -j ''; installPhase = '' - mkdir -p $out/bin - cp webserv $out/bin + mkdir -p /etc/webserv + mkdir -p $out/bin + cp webserv $out/bin ''; }; } diff --git a/includes/help.hpp b/includes/help.hpp index e7fdde1..c923d3f 100644 --- a/includes/help.hpp +++ b/includes/help.hpp @@ -6,13 +6,17 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/10 13:43:54 by adjoly #+# #+# */ -/* Updated: 2025/05/06 17:10:16 by adjoly ### ########.fr */ +/* Updated: 2025/05/08 11:54:17 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once +#ifdef PKGS #define SAMPLE_CONF_PATH "./sample.toml" +#else +#define SAMPLE_CONF_PATH "/etc/webserv/default.conf" +#endif #define WEBSRV_VERSION "v0.2" bool help(int, char **); diff --git a/sample.toml b/sample.toml new file mode 100644 index 0000000..f082b19 --- /dev/null +++ b/sample.toml @@ -0,0 +1,5 @@ +[server] +host = "0.0.0.0" +port = 80 + +[server.location./] diff --git a/src/config/Route.cpp b/src/config/Route.cpp index 0dfa248..2096637 100644 --- a/src/config/Route.cpp +++ b/src/config/Route.cpp @@ -80,7 +80,7 @@ Route::Route(toml::ANode *table) if (val != not_nullptr) _dirlist = *static_cast(val); else - _dirlist = true; + _dirlist = false; /* val = accessValue("cookies", toml::BOOL, _table, _log); */ /* if (val != not_nullptr) */ /* _cookies = *static_cast(val); */ diff --git a/src/help.cpp b/src/help.cpp index ff6b84c..38f3efc 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/10 13:08:36 by adjoly #+# #+# */ -/* Updated: 2025/05/08 11:21:10 by adjoly ### ########.fr */ +/* Updated: 2025/05/08 11:58:13 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,18 +29,18 @@ void _printHelp(void) { std::cout << "-------------------------------------" << std::endl; } -void _generateConf(void) { +void _generateConf(const std::string path) { webserv::Logger _log; - if (access(SAMPLE_CONF_PATH, F_OK) == 0) { + if (access(path.c_str(), F_OK) == 0) { _log.warn(std::string(SAMPLE_CONF_PATH) + " already exist, aborting"); } else { std::stringstream str; str << "generating config into " << SAMPLE_CONF_PATH << "..."; _log.info(str.str()); - std::ofstream file(SAMPLE_CONF_PATH); + std::ofstream file(path.c_str()); if (file.is_open()) { file << "[server]\nhost = \"0.0.0.0\"\nport = " - "80\n\n[server.location./]\ndirlist = false\n"; + "80\n\n[server.location./]\n"; file.close(); _log.info("config file successfully generated"); } else { @@ -58,15 +58,15 @@ void _printVersion(void) { bool help(int ac, char **av) { if (ac < 2) { - _printHelp(); - return true; + _generateConf(SAMPLE_CONF_PATH); + return false; } std::string option = av[1]; if (option == "--help" || option == "-v") { _printHelp(); return true; } else if (option == "--generate" || option == "-g") { - _generateConf(); + _generateConf(SAMPLE_CONF_PATH); return true; } else if (option == "--version" || option == "-v") { _printVersion(); diff --git a/src/main.cpp b/src/main.cpp index afd3dcc..b042dd2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ /* By: mmoussou