mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-07-16 14:46:31 +02:00
「🏗️」 wip: Started fixing cgi but no clue what is happening
This commit is contained in:
@ -6,22 +6,23 @@
|
|||||||
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/24 13:46:34 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
|
#pragma once
|
||||||
|
|
||||||
#include "server/AResource.hpp"
|
|
||||||
#include <config/default.hpp>
|
#include <config/default.hpp>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <server/AResource.hpp>
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <server/CgiIn.hpp>
|
||||||
#include <server/ResourceManager.hpp>
|
#include <server/ResourceManager.hpp>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace webserv {
|
namespace webserv {
|
||||||
namespace http {
|
namespace http {
|
||||||
class Get;
|
class Get;
|
||||||
@ -55,10 +56,19 @@ class Cgi : public server::AClientResource {
|
|||||||
|
|
||||||
short event(void) const { return POLLIN; }
|
short event(void) const { return POLLIN; }
|
||||||
bool isReady(void) const {
|
bool isReady(void) const {
|
||||||
if (_is_post == false)
|
if (_is_post == false) {
|
||||||
|
_log->debug("CGIIII not a post");
|
||||||
return true;
|
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 true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/13 18:14:45 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 "server/AResource.hpp"
|
||||||
#include <log.hpp>
|
#include <log.hpp>
|
||||||
|
#include <server/PfdManager.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <server/PfdManager.hpp>
|
|
||||||
|
|
||||||
namespace webserv {
|
namespace webserv {
|
||||||
namespace server {
|
namespace server {
|
||||||
@ -34,6 +34,7 @@ class CgiIn : public AClientResource {
|
|||||||
~CgiIn(void) { log("➖", "CgiIn", "destructor called"); }
|
~CgiIn(void) { log("➖", "CgiIn", "destructor called"); }
|
||||||
|
|
||||||
void process(void) {
|
void process(void) {
|
||||||
|
std::cout << "process" << std::endl;
|
||||||
_processed = true;
|
_processed = true;
|
||||||
ssize_t bytes_written = write(_fd, _body.c_str(), _body.size());
|
ssize_t bytes_written = write(_fd, _body.c_str(), _body.size());
|
||||||
_log->debug("writting body : " + _body);
|
_log->debug("writting body : " + _body);
|
||||||
@ -49,7 +50,10 @@ class CgiIn : public AClientResource {
|
|||||||
}
|
}
|
||||||
clientResType type(void) const { return CGI_IN; }
|
clientResType type(void) const { return CGI_IN; }
|
||||||
short event(void) const { return POLLIN; }
|
short event(void) const { return POLLIN; }
|
||||||
bool isReady(void) const { return true; }
|
bool isReady(void) const {
|
||||||
|
_log->debug("CgiIn ready");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
|
7
sample.toml
Executable file → Normal file
7
sample.toml
Executable file → Normal file
@ -1,9 +1,8 @@
|
|||||||
[server]
|
[server]
|
||||||
port = 5000
|
|
||||||
host = "0.0.0.0"
|
host = "0.0.0.0"
|
||||||
|
port = 2727
|
||||||
|
|
||||||
[server.location./]
|
[server.location./]
|
||||||
root = "/home/adjoly/workspace/42/webserv/exemples"
|
root = "./exemples/webpage"
|
||||||
|
methods = { "GET", "POST" }
|
||||||
cgi = { ".py"}
|
cgi = { ".py"}
|
||||||
methods = { "GET", "POST"}
|
|
||||||
[server.location./asdf]
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/24 13:46:34 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.events = in->event();
|
||||||
pfd.revents = 0;
|
pfd.revents = 0;
|
||||||
pfd.fd = in->getId();
|
pfd.fd = in->getId();
|
||||||
|
std::cout << pfd.fd << std::endl;
|
||||||
server::PfdManager::append(pfd, server::RES);
|
server::PfdManager::append(pfd, server::RES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +65,8 @@ void Cgi::_prep(void) {
|
|||||||
if (pipe(_stdout_pipe) == -1)
|
if (pipe(_stdout_pipe) == -1)
|
||||||
throw std::runtime_error("stdout pipe failed for cgi D:");
|
throw std::runtime_error("stdout pipe failed for cgi D:");
|
||||||
_script_path = _conf->getRootDir() + _request->getTarget();
|
_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;
|
_pfd_event = POLLIN;
|
||||||
if (access(_script_path.c_str(), X_OK))
|
if (access(_script_path.c_str(), X_OK))
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/27 18:22:48 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;
|
return;
|
||||||
|
|
||||||
if (!res->isProcessed() && res->isReady()) {
|
if (!res->isProcessed() && res->isReady()) {
|
||||||
|
_log->debug("processing resource");
|
||||||
res->process();
|
res->process();
|
||||||
// if (res->type() == CGI) {
|
|
||||||
// } else if (pfd.revents & res->event()) {
|
|
||||||
// res->process();
|
|
||||||
// _log->info("processingggg");
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user