🏗️」 wip: started working towards implementing resources in client

This commit is contained in:
2025-05-23 18:30:33 +02:00
parent 0823ce2894
commit 41ca9eacd3
7 changed files with 82 additions and 21 deletions

View File

@ -15,7 +15,7 @@ methods = { "GET" }
root = "/home/adjoly" root = "/home/adjoly"
dirlist = true dirlist = true
client_max_body_size = "10M" client_max_body_size = "10M"
index = "banger.html" index = "index.html"
[server.location./api] [server.location./api]
methods = { "GET", "POST" } methods = { "GET", "POST" }

View File

@ -6,18 +6,17 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 15:48:22 by mmoussou #+# #+# */ /* Created: 2025/02/03 15:48:22 by mmoussou #+# #+# */
/* Updated: 2025/04/30 09:36:57 by adjoly ### ########.fr */ /* Updated: 2025/05/23 18:22:50 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#pragma once #pragma once
#include <requests/ARequest.hpp> #include <requests/ARequest.hpp>
#include <requests/Cgi.hpp> #include <requests/RequestImplement.hpp>
#include <requests/Errors.hpp> #include <requests/Errors.hpp>
#include <requests/IMessage.hpp> #include <requests/IMessage.hpp>
#include <requests/Mime.hpp> #include <requests/Mime.hpp>
#include <requests/RequestImplement.hpp>
#include <requests/Response.hpp> #include <requests/Response.hpp>
namespace webserv { namespace webserv {

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/29 14:20:09 by mmoussou #+# #+# */ /* Created: 2025/04/29 14:20:09 by mmoussou #+# #+# */
/* Updated: 2025/05/13 18:27:46 by adjoly ### ########.fr */ /* Updated: 2025/05/23 18:27:06 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@
namespace webserv { namespace webserv {
namespace server { namespace server {
enum clientResType { CGI, UP_FILE }; enum clientResType { CGI_IN, CGI, UP_FILE };
class AClientResource { class AClientResource {
public: public:
@ -33,7 +33,7 @@ class AClientResource {
void setFileDescriptor(struct pollfd *fd) { _fd = fd; } void setFileDescriptor(struct pollfd *fd) { _fd = fd; }
struct pollfd getFileDescriptor(void) const { return *_fd; } struct pollfd getFileDescriptor(void) const { return *_fd; }
virtual clientResType type(void) const ; virtual clientResType type(void) const = 0;
int getId(void) const { return _res_id; } int getId(void) const { return _res_id; }
protected: protected:

View File

@ -6,27 +6,29 @@
/* 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/20 20:01:38 by adjoly ### ########.fr */ /* Updated: 2025/05/23 18:24:29 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#pragma once #pragma once
#include "server/AResource.hpp"
#include <config/Route.hpp> #include <config/Route.hpp>
#include <config/default.hpp> #include <config/default.hpp>
#include <cstdio> #include <cstdio>
#include <requests/ARequest.hpp> #include <requests/default.hpp>
#include <server/AResource.hpp>
#include <map> #include <map>
#include <string> #include <string>
#include <unistd.h> #include <unistd.h>
namespace webserv { namespace webserv {
namespace server {
class Cgi : public server::AClientResource { class Cgi : public server::AClientResource {
public: public:
Cgi(http::ARequest *, config::Route *); Cgi(webserv::http::Get *, webserv::config::Route *, int);
Cgi(webserv::http::Post *, webserv::config::Route *, int);
~Cgi(void); ~Cgi(void);
int getFdOut(void) const { return _stdout_pipe[0]; } int getFdOut(void) const { return _stdout_pipe[0]; }
@ -71,6 +73,8 @@ class Cgi : public server::AClientResource {
void _initEnvp(void); void _initEnvp(void);
void _prepPost(void);
/** /**
* @brief Can be used to convert the _envp to a char** usable in execve * @brief Can be used to convert the _envp to a char** usable in execve
* *
@ -85,11 +89,14 @@ class Cgi : public server::AClientResource {
std::string _cgi_path; std::string _cgi_path;
std::map<std::string, std::string> _envp; // The envp filled with _initEnvp std::map<std::string, std::string> _envp; // The envp filled with _initEnvp
config::Route *_conf; // The configuration for the route used webserv::config::Route *_conf; // The configuration for the route used
http::ARequest *_request; // The requests that will be used for the cgi 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
int _stdout_pipe[2]; // The pipefd for the stdout of the cgi int _stdout_pipe[2]; // The pipefd for the stdout of the cgi
int _in_res; // The id of the stdin resource
}; };
}; // namespace http
}; // namespace webserv }; // namespace webserv

32
includes/server/CgiIn.hpp Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* CgiIn.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#pragma once
#include "server/AResource.hpp"
namespace webserv {
namespace server {
class CgiIn: public AClientResource {
public:
CgiIn(int id) { _res_id = id; }
~CgiIn(void) {}
clientResType type(void) const { return CGI_IN; }
protected:
private:
};
} // namespace server
} // namespace webserv

View File

@ -6,14 +6,19 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 13:29:05 by mmoussou #+# #+# */ /* Created: 2025/02/11 13:29:05 by mmoussou #+# #+# */
/* Updated: 2025/04/22 12:04:53 by mmoussou ### ########.fr */ /* Updated: 2025/05/23 18:23:02 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#pragma once #pragma once
#include <server/Server.hpp> #include <server/AResource.hpp>
#include <server/Cgi.hpp>
#include <server/CgiIn.hpp>
#include <server/Client.hpp> #include <server/Client.hpp>
#include <server/FileUpload.hpp>
#include <server/ResourceManager.hpp>
#include <server/Server.hpp>
namespace webserv { namespace webserv {

View File

@ -6,17 +6,18 @@
/* 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/21 09:50:23 by adjoly ### ########.fr */ /* Updated: 2025/05/23 18:26:45 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <help.hpp>
#include <requests/default.hpp>
#include <server/default.hpp>
#include <cerrno> #include <cerrno>
#include <cstddef> #include <cstddef>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <help.hpp>
#include <requests/Cgi.hpp>
#include <fcntl.h> #include <fcntl.h>
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -24,12 +25,13 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
using namespace webserv; using namespace webserv::server;
// WARN: construtor will probably be changed and practicly do nothing // WARN: construtor will probably be changed and practicly do nothing
Cgi::Cgi(http::ARequest *req, config::Route *conf) Cgi::Cgi(http::Get *req, config::Route *conf, int id)
: _prepared(false), _executed(false), _conf(conf), _request(req) { : _prepared(false), _executed(false), _conf(conf), _request(req) {
_initEnvp(); _initEnvp();
_res_id = id;
_cgi_path = _conf->getCgiPath(req->getTarget()); _cgi_path = _conf->getCgiPath(req->getTarget());
if (_cgi_path == "") { if (_cgi_path == "") {
throw; throw;
@ -38,6 +40,22 @@ Cgi::Cgi(http::ARequest *req, config::Route *conf)
} }
} }
Cgi::Cgi(http::Post *req, config::Route *conf, int id)
: _prepared(false), _executed(false), _conf(conf), _request(req) {
_initEnvp();
_res_id = id;
_cgi_path = _conf->getCgiPath(req->getTarget());
if (_cgi_path == "") {
throw;
// TODO: need to make something probably will be checked before by
// client
}
}
Cgi::~Cgi(void) {
}
void Cgi::_initEnvp(void) { void Cgi::_initEnvp(void) {
std::stringstream str; std::stringstream str;
str << WEBSRV_NAME << "/" << WEBSRV_VERSION; str << WEBSRV_NAME << "/" << WEBSRV_VERSION;