🏗️」 wip: Started fixing cgi but no clue what is happening

This commit is contained in:
2025-07-01 11:28:27 +02:00
parent 8e5f80b994
commit 36f4609a25
5 changed files with 31 additions and 20 deletions

View File

@ -6,22 +6,23 @@
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <config/default.hpp>
#include <cstdio>
#include <server/AResource.hpp>
#include <exception>
#include <map>
#include <server/CgiIn.hpp>
#include <server/ResourceManager.hpp>
#include <sstream>
#include <string>
#include <unistd.h>
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<CgiIn *>(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;
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <log.hpp>
#include <server/PfdManager.hpp>
#include <stdexcept>
#include <unistd.h>
#include <server/PfdManager.hpp>
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:

7
sample.toml Executable file → Normal file
View File

@ -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]

View File

@ -6,7 +6,7 @@
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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(

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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");
// }
}
}