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:
@ -15,7 +15,7 @@ methods = { "GET" }
|
||||
root = "/home/adjoly"
|
||||
dirlist = true
|
||||
client_max_body_size = "10M"
|
||||
index = "banger.html"
|
||||
index = "index.html"
|
||||
|
||||
[server.location./api]
|
||||
methods = { "GET", "POST" }
|
||||
|
@ -6,18 +6,17 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
|
||||
#include <requests/ARequest.hpp>
|
||||
#include <requests/Cgi.hpp>
|
||||
#include <requests/RequestImplement.hpp>
|
||||
#include <requests/Errors.hpp>
|
||||
#include <requests/IMessage.hpp>
|
||||
#include <requests/Mime.hpp>
|
||||
#include <requests/RequestImplement.hpp>
|
||||
#include <requests/Response.hpp>
|
||||
|
||||
namespace webserv {
|
||||
|
@ -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:
|
||||
|
@ -6,27 +6,29 @@
|
||||
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
|
||||
#include "server/AResource.hpp"
|
||||
#include <config/Route.hpp>
|
||||
#include <config/default.hpp>
|
||||
#include <cstdio>
|
||||
#include <requests/ARequest.hpp>
|
||||
#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(http::ARequest *, config::Route *);
|
||||
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]; }
|
||||
@ -71,6 +73,8 @@ class Cgi : public server::AClientResource {
|
||||
|
||||
void _initEnvp(void);
|
||||
|
||||
void _prepPost(void);
|
||||
|
||||
/**
|
||||
* @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::map<std::string, std::string> _envp; // The envp filled with _initEnvp
|
||||
config::Route *_conf; // The configuration for the route used
|
||||
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 _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 {
|
||||
|
||||
|
@ -6,17 +6,18 @@
|
||||
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <help.hpp>
|
||||
#include <requests/Cgi.hpp>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@ -24,12 +25,13 @@
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace webserv;
|
||||
using namespace webserv::server;
|
||||
|
||||
// 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) {
|
||||
_initEnvp();
|
||||
_res_id = id;
|
||||
_cgi_path = _conf->getCgiPath(req->getTarget());
|
||||
if (_cgi_path == "") {
|
||||
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) {
|
||||
std::stringstream str;
|
||||
str << WEBSRV_NAME << "/" << WEBSRV_VERSION;
|
||||
|
Reference in New Issue
Block a user