From 36f4609a25e614470368eb22961ab922c6743753 Mon Sep 17 00:00:00 2001 From: adjoly Date: Tue, 1 Jul 2025 11:28:27 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20Started=20fixing=20cgi=20but=20no=20clue=20what=20is=20happe?= =?UTF-8?q?ning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/server/Cgi.hpp | 20 +++++++++++++++----- includes/server/CgiIn.hpp | 10 +++++++--- sample.toml | 7 +++---- src/requests_handling/Cgi.cpp | 6 ++++-- src/server/ServerHandle.cpp | 8 ++------ 5 files changed, 31 insertions(+), 20 deletions(-) mode change 100755 => 100644 sample.toml diff --git a/includes/server/Cgi.hpp b/includes/server/Cgi.hpp index 21dbb66..33c32d3 100644 --- a/includes/server/Cgi.hpp +++ b/includes/server/Cgi.hpp @@ -6,22 +6,23 @@ /* By: gadelbes +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */ -/* Updated: 2025/05/27 21:32:43 by adjoly ### ########.fr */ +/* Updated: 2025/07/01 11:21:31 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once -#include "server/AResource.hpp" #include #include +#include #include #include +#include #include +#include #include #include - namespace webserv { namespace http { class Get; @@ -55,10 +56,19 @@ class Cgi : public server::AClientResource { short event(void) const { return POLLIN; } bool isReady(void) const { - if (_is_post == false) + if (_is_post == false) { + _log->debug("CGIIII not a post"); return true; - if (ResourceManager::get(_stdin_pipe[PIPE_WRITE])->isProcessed()) + } + if (static_cast(ResourceManager::get(_stdin_pipe[PIPE_WRITE])) + ->isProcessed() == true) { + std::cout << "in " + << ResourceManager::get(_stdin_pipe[PIPE_WRITE])->getId() + << std::endl; + std::cout << ResourceManager::get(_stdin_pipe[PIPE_WRITE])->type() << std::endl; + _log->debug("CGIIII post readyyy"); return true; + } return false; } diff --git a/includes/server/CgiIn.hpp b/includes/server/CgiIn.hpp index 0aacf91..4dfb8e2 100644 --- a/includes/server/CgiIn.hpp +++ b/includes/server/CgiIn.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/13 18:14:45 by adjoly #+# #+# */ -/* Updated: 2025/06/23 21:25:26 by adjoly ### ########.fr */ +/* Updated: 2025/07/01 11:17:52 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,9 @@ #include "server/AResource.hpp" #include +#include #include #include -#include namespace webserv { namespace server { @@ -34,6 +34,7 @@ class CgiIn : public AClientResource { ~CgiIn(void) { log("➖", "CgiIn", "destructor called"); } void process(void) { + std::cout << "process" << std::endl; _processed = true; ssize_t bytes_written = write(_fd, _body.c_str(), _body.size()); _log->debug("writting body : " + _body); @@ -49,7 +50,10 @@ class CgiIn : public AClientResource { } clientResType type(void) const { return CGI_IN; } short event(void) const { return POLLIN; } - bool isReady(void) const { return true; } + bool isReady(void) const { + _log->debug("CgiIn ready"); + return true; + } protected: private: diff --git a/sample.toml b/sample.toml old mode 100755 new mode 100644 index 24db8a6..d32a357 --- a/sample.toml +++ b/sample.toml @@ -1,9 +1,8 @@ [server] -port = 5000 host = "0.0.0.0" +port = 2727 [server.location./] -root = "/home/adjoly/workspace/42/webserv/exemples" +root = "./exemples/webpage" +methods = { "GET", "POST" } cgi = { ".py"} -methods = { "GET", "POST"} -[server.location./asdf] diff --git a/src/requests_handling/Cgi.cpp b/src/requests_handling/Cgi.cpp index ff30401..9cb3f7a 100644 --- a/src/requests_handling/Cgi.cpp +++ b/src/requests_handling/Cgi.cpp @@ -6,7 +6,7 @@ /* By: gadelbes +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */ -/* Updated: 2025/06/24 18:02:34 by adjoly ### ########.fr */ +/* Updated: 2025/07/01 11:26:11 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,6 +52,7 @@ Cgi::Cgi(http::Post *req, config::Route *conf) pfd.events = in->event(); pfd.revents = 0; pfd.fd = in->getId(); + std::cout << pfd.fd << std::endl; server::PfdManager::append(pfd, server::RES); } @@ -64,7 +65,8 @@ void Cgi::_prep(void) { if (pipe(_stdout_pipe) == -1) throw std::runtime_error("stdout pipe failed for cgi D:"); _script_path = _conf->getRootDir() + _request->getTarget(); - _fd = _stdout_pipe[STDIN_FILENO]; + _fd = _stdout_pipe[PIPE_READ]; + std::cout << "sus = " << _fd << std::endl; _pfd_event = POLLIN; if (access(_script_path.c_str(), X_OK)) throw std::runtime_error( diff --git a/src/server/ServerHandle.cpp b/src/server/ServerHandle.cpp index f4e32bb..b0988c2 100644 --- a/src/server/ServerHandle.cpp +++ b/src/server/ServerHandle.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/27 18:22:48 by adjoly #+# #+# */ -/* Updated: 2025/06/24 18:02:10 by adjoly ### ########.fr */ +/* Updated: 2025/07/01 10:47:05 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -130,11 +130,7 @@ void Server::_handle_resource(size_t i) { return; if (!res->isProcessed() && res->isReady()) { + _log->debug("processing resource"); res->process(); - // if (res->type() == CGI) { - // } else if (pfd.revents & res->event()) { - // res->process(); - // _log->info("processingggg"); - // } } }