🏗️」 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: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/14 12:20:06 by adjoly #+# #+# */
/* Updated: 2025/05/03 09:42:35 by adjoly ### ########.fr */
/* Updated: 2025/05/27 19:22:15 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 14:59:41 by adjoly #+# #+# */
/* Updated: 2025/05/27 09:37:23 by adjoly ### ########.fr */
/* Updated: 2025/05/27 20:05:20 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,6 +40,9 @@ class Route {
bool * getMethods(void) { return _methods; }
bool isCgi(std::string target) {
std::string target_ext = target.substr(target.find('.'));
if (_cgi == not_nullptr)
return false;
for (auto it = prange(_cgi)) {
if (target_ext == *it)
return true;

View File

@ -6,12 +6,13 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 12:17:48 by adjoly #+# #+# */
/* Updated: 2025/05/04 12:21:03 by adjoly ### ########.fr */
/* Updated: 2025/05/27 19:46:54 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include "log.hpp"
#include <cstring>
#include <ostream>
#include <sstream>
@ -29,7 +30,7 @@ class URL {
}
int countMatchingSegments(const URL &url) const {
if (_path_segments.size() == 0 || url._path_segments.size() == 0)
if (_path_segments.size() == 0 || url._path_segments.size() == 0)
return 0;
int i = 0;
@ -80,7 +81,7 @@ class URL {
}
}
void _splitPath(const std::string &path,
void _splitPath(const std::string & path,
std::vector<std::string> &segments) const {
std::stringstream ss(path);
std::string segment;

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 14:15:51 by adjoly #+# #+# */
/* Updated: 2025/04/22 15:28:31 by adjoly ### ########.fr */
/* Updated: 2025/05/27 19:29:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,5 +55,7 @@ static inline void *accessValue(const std::string &name, toml::nodeType type,
}
}
extern config::Config *_conf;
}; // namespace config
}; // namespace webserv

View File

@ -6,14 +6,16 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:23:00 by mmoussou #+# #+# */
/* Updated: 2025/05/15 12:12:47 by adjoly ### ########.fr */
/* Updated: 2025/05/27 22:22:56 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <config/URL.hpp>
#include "config/Server.hpp"
#include "cppeleven.hpp"
#include <config/Route.hpp>
#include <config/URL.hpp>
#include <ctime>
#include <fstream>
#include <iostream>
@ -26,13 +28,17 @@
#include <config/default.hpp>
namespace webserv {
namespace server {
class Cgi;
}
namespace http {
class ARequest : public http::IMessage {
public:
virtual ~ARequest(void) {
log("", "ARequest", "destructor called");
delete _url;
if (_url != not_nullptr)
delete _url;
}
virtual void parse(std::string const &data) = 0;
@ -40,24 +46,27 @@ class ARequest : public http::IMessage {
std::string str(void) const;
std::string getMethod(void) const;
std::string getTarget(void) const;
std::string getProtocol(void) const;
webserv::config::Route *getRoute(void) const;
URL getUrl() const;
std::string getMethod(void) const;
std::string getTarget(void) const;
std::string getProtocol(void) const;
webserv::config::Route *getRoute(void) const;
URL getUrl() const;
virtual server::Cgi * getCgi() const { return not_nullptr; }
void setMethod(std::string const method);
void setTarget(std::string const target);
void setProtocol(std::string const protocol);
void setServer(std::string const protocol);
void setRoute(config::Route *route);
void setSrv(config::Server *srv);
protected:
std::string _method;
std::string _target;
std::string _protocol;
webserv::config::Route *_route;
URL *_url;
std::string _method;
std::string _target;
std::string _protocol;
webserv::config::Route *_route;
config::Server * _srv;
URL * _url;
std::string _sanitizeStr(std::string &str) {
std::string newStr = str;

View File

@ -6,10 +6,11 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/30 09:30:15 by adjoly #+# #+# */
/* Updated: 2025/05/27 16:49:00 by adjoly ### ########.fr */
/* Updated: 2025/05/27 22:23:15 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <cstddef>
#include <requests/ARequest.hpp>
namespace webserv {
@ -22,16 +23,19 @@ namespace http {
class Get : public ARequest {
public:
Get(void) {}
Get(std::string &data);
Get(std::string &data, config::Server *srv);
void parse(std::string const &data);
Response execute(void);
// private:
// server::Cgi *_cgi;
server::Cgi *getCgi() const { return _cgi; }
private:
server::Cgi *_cgi;
};
// TODO: pass _srv to other
class Post : public ARequest {
public:
Post(void) {}

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

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 13:29:21 by mmoussou #+# #+# */
/* Updated: 2025/05/26 10:16:08 by adjoly ### ########.fr */
/* Updated: 2025/05/27 19:25:07 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,19 +14,18 @@
#define auto __auto_type
#include <sys/types.h>
#include <csignal>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <netinet/in.h>
#include <sstream>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <vector>
#include <sstream>
#define range(x) \
x.begin(); \
@ -39,7 +38,4 @@
#define BUFFER_SIZE 4096
namespace webserv {
} // namespace webserv
namespace webserv {} // namespace webserv