mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 23:48:46 +02:00
「🎉」 init: started cgi handling (for real this time)
This commit is contained in:
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* Cgi.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/24 14:17:34 by adjoly #+# #+# */
|
||||
/* Updated: 2025/04/30 09:36:02 by adjoly ### ########.fr */
|
||||
/* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */
|
||||
/* Updated: 2025/05/06 19:34:11 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -3,14 +3,14 @@
|
||||
/* ::: :::::::: */
|
||||
/* Cgi.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/24 13:46:34 by adjoly #+# #+# */
|
||||
/* Updated: 2025/04/30 09:49:32 by adjoly ### ########.fr */
|
||||
/* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */
|
||||
/* Updated: 2025/05/06 19:36:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "requests/default.hpp"
|
||||
#include <requests/default.hpp>
|
||||
|
||||
using namespace webserv;
|
||||
|
||||
@ -18,11 +18,18 @@ Cgi::Cgi(http::ARequest *req, config::Server *conf) : _conf(conf), _request(req)
|
||||
_initEnvp();
|
||||
}
|
||||
|
||||
void Cgi::_initEnvp(void) {
|
||||
//_envp[] = "";
|
||||
void Cgi::_initEnvp(void)
|
||||
{
|
||||
|
||||
setEnv("REQUEST_METHOD", _request->getMethod()); //url get ou pour post
|
||||
setEnv("?", _request->getParamRequest()); //apres le ?
|
||||
setEnv("TYPE", _request->getType()); //type de requete, genre html
|
||||
setEnv("LENGTH", _request->getLength()); //taille pour les requetes post
|
||||
setEnv("SCRIPT", _request->getScript()); //chemin relatif du serveur
|
||||
setEnv("MORE_INFO", _request->getMoreInfo()); //chemin supplementaire
|
||||
}
|
||||
|
||||
std::string Cgi::getEnv(std::string &key) {
|
||||
char *Cgi::getEnv(std::string &key) {
|
||||
auto it = _envp.find(key);
|
||||
if (it != _envp.end()) {
|
||||
return it->second;
|
||||
@ -43,7 +50,36 @@ void Cgi::process() {
|
||||
}
|
||||
|
||||
forkPid = fork();
|
||||
if (forkPid == 0) {
|
||||
// in fork
|
||||
if (forkPid == 0)
|
||||
{
|
||||
int fd = open("kanel/cheminfichier", O_RDONLY); //chemin vers ce que je dois ouvrir
|
||||
if (fd == -1)
|
||||
//throw erreur
|
||||
dup2(fd, 0);
|
||||
dup2(pipefd[1], 1);
|
||||
close(fd);
|
||||
close(pipefd[0]);
|
||||
close(pipefd[1]);
|
||||
|
||||
std::string cgipath = "kanel/chemincgi"; // chemin du cgi
|
||||
char *envp[] = {getEnv("REQUEST_METHOD"), getEnv("?"), getEnv("TYPE"), getEnv("LENGTH"), NULL };
|
||||
execve(cgipath, NULL, env);
|
||||
//throw si execve echou
|
||||
}
|
||||
else if (forkPid >= 1)
|
||||
{
|
||||
close(pipefd[1]);
|
||||
|
||||
int nb;
|
||||
waitpid(forkPid, &nb, 0);
|
||||
|
||||
char buffer[4096] //jsp quoi mettre le temps
|
||||
while (read(pipefd[0], buffer, sizeof(buffer)))
|
||||
{
|
||||
//tranfert donnees
|
||||
}
|
||||
close(pipefd[0]);
|
||||
}
|
||||
else
|
||||
throw error;
|
||||
}
|
||||
|
Reference in New Issue
Block a user