diff --git a/src/CGIHandler.cpp b/src/CGIHandler.cpp index b174385a..15084092 100644 --- a/src/CGIHandler.cpp +++ b/src/CGIHandler.cpp @@ -8,14 +8,21 @@ CGIHandler::~CGIHandler() { } -CGIHandler &CGIHandler::operator=(const CGIHandler &other) -{ - if (this != &other) - { - AResponseHandler::operator=(other); - } - return *this; -} +// CGIHandler::CGIHandler(Connection *conn) +// { +// _conn = conn; +// } + +// CGIHandler &CGIHandler::operator=(const CGIHandler &other) +// { +// if (this != &other) +// { +// _conn = other._conn; +// _FDsRef = other._FDsRef; +// _pollFd = other._pollFd; +// } +// return *this; +// } void CGIHandler::handleRequest(const HTTPRequest &request, HTTPResponse &response) { @@ -26,7 +33,7 @@ void CGIHandler::handleRequest(const HTTPRequest &request, HTTPResponse &respons // std::cout << env; std::string cgiOutput = executeCGI(env); CGIStringToResponse(cgiOutput, response); - // std::cout << response; + std::cout << response; std::cout << "------------------CGIHandler::handleRequest-------------------" << std::endl; std::cout << "CGIHandler: path: " << request.getPath() << std::endl; @@ -93,6 +100,7 @@ void CGIHandler::CGIStringToResponse(const std::string &cgiOutput, HTTPResponse response.setBody(bodyPart); response.setIsCGI(true); response.setStatusCode(200, ""); + return; } @@ -135,6 +143,14 @@ std::string CGIHandler::executeCGI(const MetaVariables &env) } pid_t pid = fork(); + + // _conn->setPID(pid); + // _conn->setHasCGI(true); + // _conn->setCGIexpired(false); + // _conn->_cgiCounter++; + // TODO: start a timer : + // time_t, struct timeval, alarm, getitimer, timer_create, gettimeofday + if (pid == -1) { perror("fork failed"); @@ -153,16 +169,33 @@ std::string CGIHandler::executeCGI(const MetaVariables &env) // Debug::log("Executing CGI script: " + std::string(argvPointers[0]), Debug::NORMAL); // Debug::log("CGI script path: " + std::string(argvPointers[1]), Debug::NORMAL); - - execve(argvPointers[0], &argvPointers[0], &envpPointers[0]); + if (access(argvPointers[0], X_OK) == -1) + { + perror("access"); + cgiOutput = "HTTP/1.1 500 Internal Server Error\r\n" + "Content-Type: text/html\r\n" + "Connection: close\r\n" + "\r\n" + "