mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-06-25 09:33:36 +02:00
「🏗️」 wip: cgi should be able to be implemented
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/29 14:20:09 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/05/23 18:27:06 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/24 10:09:33 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -25,7 +25,7 @@ class AClientResource {
|
||||
virtual ~AClientResource() {}
|
||||
|
||||
bool operator==(int i) const {
|
||||
if (i == _res_id)
|
||||
if (i == _fd->fd)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@ -34,12 +34,10 @@ class AClientResource {
|
||||
struct pollfd getFileDescriptor(void) const { return *_fd; }
|
||||
|
||||
virtual clientResType type(void) const = 0;
|
||||
int getId(void) const { return _res_id; }
|
||||
int getId(void) const { return _fd->fd; }
|
||||
|
||||
protected:
|
||||
struct pollfd *_fd;
|
||||
|
||||
int _res_id;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */
|
||||
/* Updated: 2025/05/23 18:24:29 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/24 11:18:49 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -25,27 +25,15 @@
|
||||
namespace webserv {
|
||||
namespace server {
|
||||
|
||||
#define PIPE_READ 0
|
||||
#define PIPE_WRITE 1
|
||||
|
||||
class Cgi : public server::AClientResource {
|
||||
public:
|
||||
Cgi(webserv::http::Get *, webserv::config::Route *, int);
|
||||
Cgi(webserv::http::Post *, webserv::config::Route *, int);
|
||||
Cgi(webserv::http::Get *, webserv::config::Route *);
|
||||
Cgi(webserv::http::Post *, webserv::config::Route *);
|
||||
~Cgi(void);
|
||||
|
||||
int getFdOut(void) const { return _stdout_pipe[0]; }
|
||||
|
||||
/**
|
||||
* @brief Can be used to prepare the Cgi execution
|
||||
*
|
||||
* @note To be used after the main fd is in POLLOUT state
|
||||
*/
|
||||
void prepare(void);
|
||||
|
||||
/**
|
||||
* @brief Can be used to know if the prepare function has already been
|
||||
* called
|
||||
*/
|
||||
bool isPrepared(void) { return _prepared; }
|
||||
|
||||
/**
|
||||
* @brief Can be used to process the Cgi script
|
||||
*/
|
||||
@ -68,12 +56,12 @@ class Cgi : public server::AClientResource {
|
||||
|
||||
protected:
|
||||
private:
|
||||
bool _prepared;
|
||||
bool _executed;
|
||||
bool _is_post;
|
||||
|
||||
void _initEnvp(void);
|
||||
|
||||
void _prepPost(void);
|
||||
void _prep(void);
|
||||
|
||||
/**
|
||||
* @brief Can be used to convert the _envp to a char** usable in execve
|
||||
@ -89,14 +77,14 @@ class Cgi : public server::AClientResource {
|
||||
std::string _cgi_path;
|
||||
|
||||
std::map<std::string, std::string> _envp; // The envp filled with _initEnvp
|
||||
webserv::config::Route *_conf; // The configuration for the route used
|
||||
webserv::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 _stdin_pipe[2]; // The pipefd for the stdin of the cgi in the case of a
|
||||
// post
|
||||
int _stdout_pipe[2]; // The pipefd for the stdout of the cgi
|
||||
|
||||
int _in_res; // The id of the stdin resource
|
||||
};
|
||||
|
||||
}; // namespace http
|
||||
}; // namespace server
|
||||
}; // namespace webserv
|
||||
|
@ -6,26 +6,35 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/13 18:14:45 by adjoly #+# #+# */
|
||||
/* Updated: 2025/05/23 12:51:22 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/24 11:15:25 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "server/AResource.hpp"
|
||||
#include <log.hpp>
|
||||
|
||||
namespace webserv {
|
||||
namespace server {
|
||||
|
||||
class CgiIn: public AClientResource {
|
||||
class CgiIn : public AClientResource {
|
||||
public:
|
||||
CgiIn(int id) { _res_id = id; }
|
||||
~CgiIn(void) {}
|
||||
CgiIn(std::string body, int id) : _body(body) {
|
||||
log("➕", "CgiIn", "constructor called");
|
||||
_fd->fd = id;
|
||||
_fd->events = POLLOUT;
|
||||
}
|
||||
~CgiIn(void) { log("➖", "CgiIn", "destructor called"); }
|
||||
|
||||
void send(void) {
|
||||
// TODO: send the body
|
||||
}
|
||||
clientResType type(void) const { return CGI_IN; }
|
||||
|
||||
protected:
|
||||
private:
|
||||
std::string _body;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/13 18:14:45 by adjoly #+# #+# */
|
||||
/* Updated: 2025/05/13 18:56:25 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/24 11:06:33 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,7 +19,10 @@ namespace server {
|
||||
|
||||
class FileUpload : public AClientResource {
|
||||
public:
|
||||
FileUpload(int id) { _res_id = id; }
|
||||
FileUpload(int id) {
|
||||
_fd->fd = id;
|
||||
_fd->events = POLLOUT;
|
||||
}
|
||||
~FileUpload(void) {}
|
||||
|
||||
clientResType type(void) const { return UP_FILE; }
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/12 17:13:39 by adjoly #+# #+# */
|
||||
/* Updated: 2025/05/16 10:18:25 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/24 11:00:26 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -77,7 +77,6 @@ class ResourceManager {
|
||||
delete (*it);
|
||||
_res.erase(it);
|
||||
}
|
||||
// NOTE: throw or not - to see
|
||||
}
|
||||
|
||||
protected:
|
||||
|
Reference in New Issue
Block a user