mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-06-25 09:33:36 +02:00
「🏗️」 wip: started working towards implementing resources in client
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/13 18:27:46 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/23 18:27:06 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
namespace webserv {
|
||||
namespace server {
|
||||
|
||||
enum clientResType { CGI, UP_FILE };
|
||||
enum clientResType { CGI_IN, CGI, UP_FILE };
|
||||
|
||||
class AClientResource {
|
||||
public:
|
||||
@ -33,7 +33,7 @@ class AClientResource {
|
||||
void setFileDescriptor(struct pollfd *fd) { _fd = 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; }
|
||||
|
||||
protected:
|
||||
|
102
includes/server/Cgi.hpp
Normal file
102
includes/server/Cgi.hpp
Normal file
@ -0,0 +1,102 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cgi.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <config/Route.hpp>
|
||||
#include <config/default.hpp>
|
||||
#include <cstdio>
|
||||
#include <requests/default.hpp>
|
||||
#include <server/AResource.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace webserv {
|
||||
namespace server {
|
||||
|
||||
class Cgi : public server::AClientResource {
|
||||
public:
|
||||
Cgi(webserv::http::Get *, webserv::config::Route *, int);
|
||||
Cgi(webserv::http::Post *, webserv::config::Route *, int);
|
||||
~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
|
||||
*/
|
||||
void process(void);
|
||||
|
||||
/**
|
||||
* @brief Can be used to check if the Cgi have been executed
|
||||
*
|
||||
* @note Need to be used after the process() function and checked before
|
||||
* using str()
|
||||
*/
|
||||
bool isProcessed(void) { return _executed; }
|
||||
|
||||
/**
|
||||
* @brief Can be used to get the output of the Cgi
|
||||
*
|
||||
* @note Need to be used after the outfd is in POLLIN state
|
||||
*/
|
||||
std::string str(void);
|
||||
|
||||
protected:
|
||||
private:
|
||||
bool _prepared;
|
||||
bool _executed;
|
||||
|
||||
void _initEnvp(void);
|
||||
|
||||
void _prepPost(void);
|
||||
|
||||
/**
|
||||
* @brief Can be used to convert the _envp to a char** usable in execve
|
||||
*
|
||||
* @return A newly allocated char** with the env from _envp
|
||||
*/
|
||||
char **_genEnv(void);
|
||||
|
||||
std::string _getEnv(std::string &) const;
|
||||
void _setEnv(const std::string, std::string);
|
||||
|
||||
std::string _script_path; // The full path of the script to be executed
|
||||
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
|
||||
|
||||
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 _in_res; // The id of the stdin resource
|
||||
};
|
||||
|
||||
}; // namespace http
|
||||
}; // namespace webserv
|
32
includes/server/CgiIn.hpp
Normal file
32
includes/server/CgiIn.hpp
Normal 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
|
@ -6,14 +6,19 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
|
||||
#include <server/Server.hpp>
|
||||
#include <server/AResource.hpp>
|
||||
#include <server/Cgi.hpp>
|
||||
#include <server/CgiIn.hpp>
|
||||
#include <server/Client.hpp>
|
||||
#include <server/FileUpload.hpp>
|
||||
#include <server/ResourceManager.hpp>
|
||||
#include <server/Server.hpp>
|
||||
|
||||
namespace webserv {
|
||||
|
||||
|
Reference in New Issue
Block a user