🏗️」 wip: cgi workinggg

This commit is contained in:
2025-05-27 22:33:04 +02:00
parent 833458e293
commit adde9e0362
25 changed files with 261 additions and 149 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/29 14:20:09 by mmoussou #+# #+# */
/* Updated: 2025/05/27 13:12:03 by adjoly ### ########.fr */
/* Updated: 2025/05/27 18:54:38 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,6 +35,7 @@ class AClientResource {
virtual void process(void) = 0;
bool isProcessed(void) const { return _processed; }
virtual bool isReady(void) const = 0;
virtual short event(void) const = 0;
protected:

View File

@ -6,7 +6,7 @@
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */
/* Updated: 2025/05/27 16:16:08 by adjoly ### ########.fr */
/* Updated: 2025/05/27 21:32:43 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,9 @@
#include <config/default.hpp>
#include <cstdio>
#include <exception>
#include <map>
#include <server/ResourceManager.hpp>
#include <string>
#include <unistd.h>
@ -52,6 +54,13 @@ class Cgi : public server::AClientResource {
std::string str(void);
short event(void) const { return POLLIN; }
bool isReady(void) const {
if (_is_post == false)
return true;
if (ResourceManager::get(_stdin_pipe[PIPE_WRITE])->isProcessed())
return true;
return false;
}
protected:
private:

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/13 18:14:45 by adjoly #+# #+# */
/* Updated: 2025/05/27 13:08:08 by adjoly ### ########.fr */
/* Updated: 2025/05/27 18:59:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,8 +37,8 @@ class CgiIn : public AClientResource {
// TODO: send the body
}
clientResType type(void) const { return CGI_IN; }
short event(void) const { return POLLIN; }
short event(void) const { return POLLIN; }
bool isReady(void) const { return true; }
protected:
private:

View File

@ -6,13 +6,14 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/14 14:14:39 by adjoly #+# #+# */
/* Updated: 2025/05/27 16:47:20 by adjoly ### ########.fr */
/* Updated: 2025/05/27 22:24:25 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <config/default.hpp>
#include <cstddef>
#include <cstdio>
#include <netinet/in.h>
#include <requests/default.hpp>

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/13 18:14:45 by adjoly #+# #+# */
/* Updated: 2025/05/27 13:07:50 by adjoly ### ########.fr */
/* Updated: 2025/05/27 18:57:27 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,19 +17,19 @@
namespace webserv {
namespace server {
class FileUpload : public AClientResource {
public:
FileUpload(int id) {
_fd = id;
_pfd_event = POLLOUT;
}
~FileUpload(void) {}
clientResType type(void) const { return UP_FILE; }
protected:
private:
};
// class FileUpload : public AClientResource {
// public:
// FileUpload(int id) {
// _fd = id;
// _pfd_event = POLLOUT;
// }
// ~FileUpload(void) {}
//
// clientResType type(void) const { return UP_FILE; }
//
// protected:
// private:
// };
} // namespace server
} // namespace webserv

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/12 17:13:39 by adjoly #+# #+# */
/* Updated: 2025/05/27 17:24:51 by adjoly ### ########.fr */
/* Updated: 2025/05/27 18:40:54 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -81,13 +81,6 @@ class ResourceManager {
}
}
static void process(void) {
for (auto it = range(_res)) {
(*it)->process();
// TODO: check for event and if isProcessed() and process
}
}
protected:
private:
static std::vector<AClientResource *> _res;

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/11 17:45:43 by adjoly #+# #+# */
/* Updated: 2025/05/27 18:38:04 by adjoly ### ########.fr */
/* Updated: 2025/05/27 19:32:38 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,7 +29,7 @@ class Client;
class Server {
public:
Server(config::Config *);
Server(void);
~Server(void);
protected:
@ -74,23 +74,14 @@ class Server {
}
Client *_getClient(int);
config::Config
* _conf; // Pointer to the configuration class (with all config in)
Logger *_log; // Pointer to the log class
std::vector<int> _fds_server; // The fds of the sockets
// std::vector<struct pollfd> _client_fds; // A vector of all the poll fd
std::vector<Client *> _client_data; // vector of all the client sockaddr_in
/**
* @brief Can be used to handle a pollfd that is a server
*/
void _handle_srv(size_t i);
/**
* @brief Can be used to handle pollfd taht is a client
*/
void _handle_client(size_t *i);
void _handle_resource(size_t i);
};
}; // namespace server