mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-07-20 15:46:32 +02:00
「🔀」 merge: a very cool feature has been merged ! :D
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/07/12 21:38:36 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/07/15 20:28:04 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -29,6 +29,7 @@ namespace webserv {
|
||||
Logger * _log = not_nullptr;
|
||||
std::vector<server::AClientResource *> server::ResourceManager::_res;
|
||||
config::Config * config::_conf = not_nullptr;
|
||||
server::Server *_server_wtf;
|
||||
} // namespace webserv
|
||||
|
||||
int _sig = 0;
|
||||
@ -82,9 +83,9 @@ int main(int ac, char **av) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
webserv::server::Server *serv = new webserv::server::Server();
|
||||
_server_wtf = new webserv::server::Server();
|
||||
|
||||
delete serv;
|
||||
delete _server_wtf;
|
||||
delete _log;
|
||||
delete config::_conf;
|
||||
}
|
||||
|
@ -6,12 +6,13 @@
|
||||
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */
|
||||
/* Updated: 2025/07/12 13:22:20 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/07/15 20:28:18 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "server/PfdManager.hpp"
|
||||
#include "server/ResourceManager.hpp"
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <help.hpp>
|
||||
#include <ios>
|
||||
@ -31,10 +32,14 @@
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
webserv::Logger _log;
|
||||
// webserv::config::Config *config::_conf;
|
||||
webserv::server::Server *_server_wtf;
|
||||
|
||||
using namespace webserv::server;
|
||||
|
||||
Cgi::Cgi(http::Get *req, config::Route *conf)
|
||||
: _is_post(false), _conf(conf), _request(req) {
|
||||
: _is_post(false), _conf(conf), _request(req), _forkPid(-1), _err(false) {
|
||||
_processed = false;
|
||||
log("➕", "Cgi", "GET constructor called");
|
||||
_initEnvp();
|
||||
@ -42,7 +47,7 @@ Cgi::Cgi(http::Get *req, config::Route *conf)
|
||||
}
|
||||
|
||||
Cgi::Cgi(http::Post *req, config::Route *conf)
|
||||
: _is_post(true), _conf(conf), _request(req) {
|
||||
: _is_post(true), _conf(conf), _request(req), _forkPid(-1), _err(false) {
|
||||
_processed = false;
|
||||
log("➕", "Cgi", "POST constructor called");
|
||||
_initEnvp();
|
||||
@ -158,17 +163,35 @@ void Cgi::process(void) {
|
||||
close(_stdout_pipe[PIPE_READ]);
|
||||
close(_stdout_pipe[PIPE_WRITE]);
|
||||
|
||||
std::string target = _request->getTarget();
|
||||
std::string dir = "/";
|
||||
std::size_t pos = target.find_last_of('/');
|
||||
if (pos != std::string::npos)
|
||||
dir = target.substr(0, pos + 1);
|
||||
chdir((_request->getRoute()->getRootDir() + dir).c_str());
|
||||
|
||||
std::cerr << _request->getRoute()->getRootDir() + dir << std::endl;
|
||||
std::cerr << _script_path << std::endl;
|
||||
char * argv[] = {const_cast<char *>(_script_path.c_str()), NULL};
|
||||
char **env = _genEnv();
|
||||
_script_path = target.substr(pos + 1);
|
||||
|
||||
if (execve(_script_path.c_str(), argv, env) == -1) {
|
||||
if (execve(_script_path.c_str(), argv, env) == -1) {
|
||||
std::stringstream str;
|
||||
str << "execve failed D:";
|
||||
str << errno;
|
||||
_log->error(str.str());
|
||||
if (_is_post) {
|
||||
PfdManager::remove(_stdin_pipe[PIPE_WRITE]);
|
||||
ResourceManager::remove(_stdin_pipe[PIPE_WRITE]);
|
||||
}
|
||||
for (int i = 0; env[i] != NULL; i++)
|
||||
delete env[i];
|
||||
delete env;
|
||||
delete _server_wtf;
|
||||
delete _log;
|
||||
delete config::_conf;
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/30 09:40:16 by adjoly #+# #+# */
|
||||
/* Updated: 2025/07/15 19:16:46 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/07/15 20:28:28 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -146,7 +146,7 @@ Response Get::execute(void) {
|
||||
http::Response response;
|
||||
|
||||
if (_cgi != not_nullptr) {
|
||||
if (_method == "500" || _cgi->isTimedout()) {
|
||||
if (_method == "500" || _cgi->isTimedout() || _cgi->isErr()) {
|
||||
response.setStatusCode(500);
|
||||
response.setProtocol(_protocol);
|
||||
response.addHeader("Content-Type", "text/html");
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/30 09:50:20 by adjoly #+# #+# */
|
||||
/* Updated: 2025/07/15 19:17:08 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/07/15 20:28:41 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -166,7 +166,7 @@ Response Post::execute(void) {
|
||||
http::Response response;
|
||||
|
||||
if (_cgi != not_nullptr) {
|
||||
if (_method == "500" || _cgi->isTimedout()) {
|
||||
if (_method == "500" || _cgi->isTimedout() || _cgi->isErr()) {
|
||||
response.setStatusCode(500);
|
||||
response.setProtocol(_protocol);
|
||||
response.addHeader("Content-Type", "text/html");
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/07/12 20:11:17 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/07/15 20:27:20 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -128,7 +128,7 @@ bool Client::requestParsed(void) {
|
||||
if (_request->getCgi() != not_nullptr) {
|
||||
if (!_request->getCgi()->isProcessed())
|
||||
return false;
|
||||
else if (_request->getCgi()->isTimedout())
|
||||
else if (_request->getCgi()->isTimedout() || _request->getCgi()->isErr())
|
||||
return true;
|
||||
else if (!(PfdManager::get(_request->getCgi()->getId())->revents &
|
||||
_request->getCgi()->event()))
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/27 18:22:48 by adjoly #+# #+# */
|
||||
/* Updated: 2025/07/02 12:45:52 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/07/15 19:17:25 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -130,7 +130,7 @@ void Server::_handle_resource(size_t i) {
|
||||
if (res == not_nullptr)
|
||||
return;
|
||||
|
||||
if (res->type() == CGI && static_cast<Cgi *>(res)->isTimedout()) {
|
||||
if (res->type() == CGI && (static_cast<Cgi *>(res)->isTimedout() || static_cast<Cgi *>(res)->isErr())) {
|
||||
return;
|
||||
}
|
||||
if (!res->isProcessed() && res->isReady()) {
|
||||
|
Reference in New Issue
Block a user