mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-06-25 09:33:36 +02:00
「🏗️」 wip: cgi workinggg
This commit is contained in:
@ -6,21 +6,23 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/05/27 16:48:09 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/27 22:26:09 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cppeleven.hpp"
|
||||
#include "requests/RedirectResp.hpp"
|
||||
#include "requests/default.hpp"
|
||||
#include <cstddef>
|
||||
#include <log.hpp>
|
||||
#include <server/Cgi.hpp>
|
||||
#include <server/Client.hpp>
|
||||
#include <sstream>
|
||||
#include <sys/poll.h>
|
||||
|
||||
using namespace webserv::server;
|
||||
|
||||
Client::Client(int fd, config::Server *conf)
|
||||
: _fd(fd), _conf(conf) {
|
||||
Client::Client(int fd, config::Server *conf) : _fd(fd), _conf(conf) {
|
||||
_request = not_nullptr;
|
||||
log("➕", "Client", "constructor called");
|
||||
_response_done = false;
|
||||
@ -50,16 +52,15 @@ void Client::parse(void) {
|
||||
_getRequest(received_data);
|
||||
|
||||
_route = _conf->whatRoute(URL(this->_request->getTarget()));
|
||||
this->_request->setRoute(_route);
|
||||
|
||||
if (_conf->getServerNames() != not_nullptr) {
|
||||
std::string host = _request->getHeader("Host");
|
||||
bool ret = _conf->isServerName(host.substr(0, host.find(':')));
|
||||
bool ret = _conf->isServerName(host.substr(0, host.find(':')));
|
||||
if (ret == false) {
|
||||
throw std::runtime_error("serverName not correcponding");
|
||||
throw std::runtime_error("serverName not corresponding");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!this->_route || this->_route == not_nullptr) {
|
||||
this->_request->setMethod("404");
|
||||
return;
|
||||
@ -79,6 +80,8 @@ void Client::parse(void) {
|
||||
}
|
||||
|
||||
bool Client::requestParsed(void) {
|
||||
if (_request->getCgi() != not_nullptr && !_request->getCgi()->isProcessed())
|
||||
return false;
|
||||
if (_request == not_nullptr)
|
||||
return false;
|
||||
return true;
|
||||
@ -89,7 +92,7 @@ void Client::_getRequest(std::string request_str) {
|
||||
0, request_str.substr(0, 4).find_last_not_of(" ") + 1);
|
||||
|
||||
if (method == "GET") {
|
||||
this->_request = new http::Get(request_str);
|
||||
this->_request = new http::Get(request_str, _conf);
|
||||
std::stringstream str;
|
||||
str << "get request received on port : ";
|
||||
str << _conf->getPort();
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */
|
||||
/* Updated: 2025/05/27 18:39:00 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/27 21:19:49 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <cmath>
|
||||
#include <config/default.hpp>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
@ -68,7 +69,7 @@ std::string getMethod(std::string &data) {
|
||||
|
||||
int Server::_fillHostsPorts(std::vector<std::string> &hosts,
|
||||
std::vector<int> & ports) {
|
||||
std::vector<config::Server *> config = _conf->getServers();
|
||||
std::vector<config::Server *> config = config::_conf->getServers();
|
||||
|
||||
for (auto it = range(config)) {
|
||||
hosts.push_back((*it)->getHost());
|
||||
@ -133,16 +134,15 @@ void Server::_run(void) {
|
||||
_handle_client(&i);
|
||||
break;
|
||||
case RES:
|
||||
_log->warn("not handling resource for now");
|
||||
_handle_resource(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Server::Server(config::Config *conf) : _conf(conf) {
|
||||
Server::Server() {
|
||||
log("➕", "Server::Server", "config constructor called");
|
||||
_log = conf->getLogger();
|
||||
try {
|
||||
_setup();
|
||||
_run();
|
||||
|
@ -6,13 +6,15 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/27 18:22:48 by adjoly #+# #+# */
|
||||
/* Updated: 2025/05/27 18:38:28 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/27 22:24:35 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cppeleven.hpp"
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include <server/default.hpp>
|
||||
#include <sys/poll.h>
|
||||
|
||||
using namespace webserv::server;
|
||||
|
||||
@ -33,7 +35,7 @@ void Server::_handle_srv(size_t i) {
|
||||
_log->error(str.str());
|
||||
return;
|
||||
}
|
||||
config::Server *conf_srv = _conf->getServer(i);
|
||||
config::Server *conf_srv = config::_conf->getServer(i);
|
||||
if (conf_srv == not_nullptr) {
|
||||
_log->warn("where the f does he come from"); // does can't
|
||||
// actually happen
|
||||
@ -69,7 +71,7 @@ void Server::_handle_client(size_t *i) {
|
||||
Client *client = _getClient(PfdManager::at(*i).fd);
|
||||
if (client == not_nullptr) {
|
||||
_log->error("client does not exist");
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
client->parse();
|
||||
@ -110,3 +112,22 @@ void Server::_handle_client(size_t *i) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Server::_handle_resource(size_t i) {
|
||||
struct pollfd pfd = PfdManager::at(i);
|
||||
AClientResource *res = ResourceManager::get(pfd.fd);
|
||||
if (res == not_nullptr) {
|
||||
std::cout << "wtff" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!res->isProcessed() && res->isReady()) {
|
||||
if (res->type() == CGI) {
|
||||
res->process();
|
||||
_log->info("processingggg");
|
||||
} else if (pfd.revents & res->event()) {
|
||||
res->process();
|
||||
_log->info("processingggg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user