From 41ca9eacd3eace6c3c3a7742aab8068c27845385 Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 23 May 2025 18:30:33 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20started=20working=20towards=20implementing=20resources=20in?= =?UTF-8?q?=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exemples/test.toml | 2 +- includes/requests/default.hpp | 5 ++--- includes/server/AResource.hpp | 6 ++--- includes/{requests => server}/Cgi.hpp | 19 +++++++++++----- includes/server/CgiIn.hpp | 32 +++++++++++++++++++++++++++ includes/server/default.hpp | 9 ++++++-- src/requests_handling/Cgi.cpp | 30 ++++++++++++++++++++----- 7 files changed, 82 insertions(+), 21 deletions(-) rename includes/{requests => server}/Cgi.hpp (83%) create mode 100644 includes/server/CgiIn.hpp diff --git a/exemples/test.toml b/exemples/test.toml index ac1d78c..534b04e 100644 --- a/exemples/test.toml +++ b/exemples/test.toml @@ -15,7 +15,7 @@ methods = { "GET" } root = "/home/adjoly" dirlist = true client_max_body_size = "10M" -index = "banger.html" +index = "index.html" [server.location./api] methods = { "GET", "POST" } diff --git a/includes/requests/default.hpp b/includes/requests/default.hpp index c0226f9..de209f3 100644 --- a/includes/requests/default.hpp +++ b/includes/requests/default.hpp @@ -6,18 +6,17 @@ /* By: mmoussou -#include +#include #include #include #include -#include #include namespace webserv { diff --git a/includes/server/AResource.hpp b/includes/server/AResource.hpp index ed20fff..4e94124 100644 --- a/includes/server/AResource.hpp +++ b/includes/server/AResource.hpp @@ -6,7 +6,7 @@ /* By: mmoussou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */ -/* Updated: 2025/05/20 20:01:38 by adjoly ### ########.fr */ +/* Updated: 2025/05/23 18:24:29 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once -#include "server/AResource.hpp" #include #include #include -#include +#include +#include #include #include #include namespace webserv { +namespace server { class Cgi : public server::AClientResource { public: - Cgi(http::ARequest *, config::Route *); + Cgi(webserv::http::Get *, webserv::config::Route *, int); + Cgi(webserv::http::Post *, webserv::config::Route *, int); ~Cgi(void); int getFdOut(void) const { return _stdout_pipe[0]; } @@ -71,6 +73,8 @@ class Cgi : public server::AClientResource { void _initEnvp(void); + void _prepPost(void); + /** * @brief Can be used to convert the _envp to a char** usable in execve * @@ -85,11 +89,14 @@ class Cgi : public server::AClientResource { std::string _cgi_path; std::map _envp; // The envp filled with _initEnvp - config::Route *_conf; // The configuration for the route used - http::ARequest *_request; // The requests that will be used for the cgi + webserv::config::Route *_conf; // The configuration for the route used + webserv::http::ARequest *_request; // The requests that will be used for the cgi int _stdin_pipe[2]; // The pipefd for the stdin of the cgi int _stdout_pipe[2]; // The pipefd for the stdout of the cgi + + int _in_res; // The id of the stdin resource }; +}; // namespace http }; // namespace webserv diff --git a/includes/server/CgiIn.hpp b/includes/server/CgiIn.hpp new file mode 100644 index 0000000..cfe0218 --- /dev/null +++ b/includes/server/CgiIn.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* CgiIn.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/13 18:14:45 by adjoly #+# #+# */ +/* Updated: 2025/05/23 12:51:22 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "server/AResource.hpp" + +namespace webserv { +namespace server { + +class CgiIn: public AClientResource { + public: + CgiIn(int id) { _res_id = id; } + ~CgiIn(void) {} + + clientResType type(void) const { return CGI_IN; } + + protected: + private: +}; + +} // namespace server +} // namespace webserv diff --git a/includes/server/default.hpp b/includes/server/default.hpp index 76c1351..f900bfc 100644 --- a/includes/server/default.hpp +++ b/includes/server/default.hpp @@ -6,14 +6,19 @@ /* By: mmoussou +#include +#include +#include #include +#include +#include +#include namespace webserv { diff --git a/src/requests_handling/Cgi.cpp b/src/requests_handling/Cgi.cpp index ea5c2be..ee220ab 100644 --- a/src/requests_handling/Cgi.cpp +++ b/src/requests_handling/Cgi.cpp @@ -6,17 +6,18 @@ /* By: gadelbes +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */ -/* Updated: 2025/05/21 09:50:23 by adjoly ### ########.fr */ +/* Updated: 2025/05/23 18:26:45 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ +#include +#include +#include + #include #include #include #include -#include -#include - #include #include #include @@ -24,12 +25,13 @@ #include #include -using namespace webserv; +using namespace webserv::server; // WARN: construtor will probably be changed and practicly do nothing -Cgi::Cgi(http::ARequest *req, config::Route *conf) +Cgi::Cgi(http::Get *req, config::Route *conf, int id) : _prepared(false), _executed(false), _conf(conf), _request(req) { _initEnvp(); + _res_id = id; _cgi_path = _conf->getCgiPath(req->getTarget()); if (_cgi_path == "") { throw; @@ -38,6 +40,22 @@ Cgi::Cgi(http::ARequest *req, config::Route *conf) } } +Cgi::Cgi(http::Post *req, config::Route *conf, int id) + : _prepared(false), _executed(false), _conf(conf), _request(req) { + _initEnvp(); + _res_id = id; + _cgi_path = _conf->getCgiPath(req->getTarget()); + if (_cgi_path == "") { + throw; + // TODO: need to make something probably will be checked before by + // client + } +} + +Cgi::~Cgi(void) { + +} + void Cgi::_initEnvp(void) { std::stringstream str; str << WEBSRV_NAME << "/" << WEBSRV_VERSION;