From 1c694131cd4573b2929c399771f766d1f88341ad Mon Sep 17 00:00:00 2001 From: Adam Joly Date: Fri, 25 Apr 2025 12:03:08 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20Started=20cgi=20handling=20but=20no=20clue=20what=20i=20am?= =?UTF-8?q?=20doing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/config/URL.hpp | 2 +- includes/requests/Cgi.hpp | 29 +++++++++++--------- includes/requests/default.hpp | 3 ++- src/requests_handling/Cgi.cpp | 50 +++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 src/requests_handling/Cgi.cpp diff --git a/includes/config/URL.hpp b/includes/config/URL.hpp index 3295abb..2b4d6ea 100644 --- a/includes/config/URL.hpp +++ b/includes/config/URL.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/22 12:17:48 by adjoly #+# #+# */ -/* Updated: 2025/04/23 17:24:51 by adjoly ### ########.fr */ +/* Updated: 2025/04/24 14:01:15 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/includes/requests/Cgi.hpp b/includes/requests/Cgi.hpp index 4f901c0..e0ce139 100644 --- a/includes/requests/Cgi.hpp +++ b/includes/requests/Cgi.hpp @@ -6,31 +6,36 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/24 14:17:34 by adjoly #+# #+# */ -/* Updated: 2025/04/23 17:27:45 by adjoly ### ########.fr */ +/* Updated: 2025/04/24 14:24:09 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #include "requests/HttpIMessage.hpp" +#include "requests/HttpRequest.hpp" +#include #include #include namespace webserv { - class Cgi { - public: - Cgi(http::IMessage &); - ~Cgi(void); + public: + Cgi(http::IRequest *, config::Server *); + ~Cgi(void); - void initEnvp(void); - - protected: - private: - std::map _envp; + std::string getEnv(std::string &); + void setEnv(std::string &, std::string); + void process(void); - std::string _request; -}; + protected: + private: + void _initEnvp(void); + + std::map _envp; + config::Server *_conf; + http::IMessage *_request; }; +}; // namespace webserv diff --git a/includes/requests/default.hpp b/includes/requests/default.hpp index 6359f52..83c4ad2 100644 --- a/includes/requests/default.hpp +++ b/includes/requests/default.hpp @@ -6,7 +6,7 @@ /* By: mmoussou #include #include +#include using namespace webserv; diff --git a/src/requests_handling/Cgi.cpp b/src/requests_handling/Cgi.cpp new file mode 100644 index 0000000..34777c4 --- /dev/null +++ b/src/requests_handling/Cgi.cpp @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cgi.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/24 13:46:34 by adjoly #+# #+# */ +/* Updated: 2025/04/24 14:38:20 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "requests/HttpIMessage.hpp" +#include "requests/HttpRequest.hpp" +#include "requests/HttpResponse.hpp" +#include "requests/default.hpp" + +Cgi::Cgi(http::IRequest *req, config::Server *conf) : _conf(conf), _request(req) { + _initEnvp(); +} + +void Cgi::_initEnvp(void) { + _envp[] = ""; +} + +std::string Cgi::getEnv(std::string &key) { + auto it = _envp.find(key); + if (it != _envp.end()) { + return it->second; + } + return ""; +} + +void Cgi::setEnv(std::string &key, std::string value) { + _envp[key] = value; +} + +void Cgi::process() { + int pipefd[2]; + int forkPid; + + if (pipe(pipefd) <= -1) { + //throw error + } + + forkPid = fork(); + if (forkPid == 0) { + // in fork + } +}