+ in fill_script_path() : scipt_path and script_info are filled, removing leadin dot
+ in _cgi_pos() : check validity of extension if it's only alpha characters + severall pbm appears
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
# include <cstdio> // perror, remove
|
||||
# include <cstdlib> // strtol, strtoul
|
||||
# include <dirent.h> // opendir()
|
||||
# include <locale> // isalpha, local
|
||||
|
||||
# include "Client.hpp"
|
||||
# include "ServerConfig.hpp"
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
|
||||
#include "Webserv.hpp"
|
||||
|
||||
// TODO HUGO : go ameliorer la recherche comme on a dit.
|
||||
// TODO HUGO : for the moment, this url valid a cgi, it shouldn't :
|
||||
// http://localhost:4040/cgi-bin/cgi.phpp
|
||||
// check the output for an alpha value maybe ? check rfc
|
||||
size_t Webserv::_cgi_pos(Client *client, std::string &path)
|
||||
{
|
||||
std::vector<std::string> v_ext;
|
||||
std::vector<std::string>::const_iterator it;
|
||||
std::vector<std::string>::const_iterator it_end;
|
||||
size_t pos = 0;
|
||||
size_t len;
|
||||
std::locale loc; // for isalpha()
|
||||
/*DEBUG*/ it = client->assigned_location->cgi_ext.begin(); std::cout << B_YELLOW << "\nDEBUG _cgi_pos()\n" << RESET << "vector_ext.size():[" << client->assigned_location->cgi_ext.size() << "]\n\n";
|
||||
v_ext = client->assigned_location->cgi_ext;
|
||||
if (v_ext.empty())
|
||||
@@ -23,8 +27,10 @@ size_t Webserv::_cgi_pos(Client *client, std::string &path)
|
||||
it = client->assigned_location->cgi_ext.begin();
|
||||
for ( ; it != it_end; ++it)
|
||||
{ /*DEBUG*/ std::cout << " for\n"; std::cout << " &path[pos]:[" << &path[pos] << "]\n" << " *it:[" << *it << "]\n" << " (*it).size():[" << (*it).size() << "]\n" << " path.substr(pos, (*it).size()):[" << path.substr(pos + 1, (*it).size()) << "]\n\n";
|
||||
if (path.compare(pos + 1, (*it).size(), *it) == 0)
|
||||
return pos;
|
||||
len = (*it).size();
|
||||
if (path.compare(pos + 1, len, *it) == 0)
|
||||
if ( !std::isalpha(path[pos + 1 + len], loc) )
|
||||
return pos + 1 + len;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
@@ -111,6 +117,7 @@ std::string Webserv::_exec_script(Client *client, char **env)
|
||||
int fd_out[2];
|
||||
int save_in = dup(STDIN_FILENO);
|
||||
int save_out = dup(STDOUT_FILENO);
|
||||
std::string path;
|
||||
|
||||
pipe(fd_in);
|
||||
pipe(fd_out);
|
||||
@@ -123,10 +130,10 @@ std::string Webserv::_exec_script(Client *client, char **env)
|
||||
close(FD_WR_TO_CHLD);
|
||||
close(FD_RD_FR_CHLD);
|
||||
dup2(FD_RD_FR_PRNT, STDIN_FILENO);
|
||||
dup2(FD_WR_TO_PRNT, STDOUT_FILENO);
|
||||
// DEBUG
|
||||
std::cerr << "execve:\n";
|
||||
execve(client->get_rq_script_path().c_str(), nll, env);
|
||||
dup2(FD_WR_TO_PRNT, STDOUT_FILENO); /*DEBUG*/std::cerr << "execve:\n";
|
||||
|
||||
path = "." + client->get_rq_script_path();
|
||||
execve(path.c_str(), nll, env);
|
||||
// for tests execve crash :
|
||||
//execve("wrong", nll, env);
|
||||
std::cerr << "execve crashed.\n";
|
||||
|
||||
@@ -69,19 +69,20 @@ void Webserv::_append_base_headers(Client *client)
|
||||
|
||||
void Webserv::_construct_response(Client *client)
|
||||
{
|
||||
std::string path = _replace_url_root(client, client->get_rq_abs_path());
|
||||
std::string path;
|
||||
std::string script_output;
|
||||
|
||||
size_t pos = _cgi_pos(client, path); /*DEBUG*/ std::cout << "pos:" << pos << B_YELLOW << "\nfin debug _cgi_pos()\n\n" << RESET;
|
||||
(void)pos;
|
||||
path = _replace_url_root(client, client->get_rq_abs_path());
|
||||
size_t pos = _cgi_pos(client, path); /*DEBUG*/ std::cout << "pos:" << pos << "\n&path[pos]:" << &path[pos] << "\n" << B_YELLOW << "fin debug _cgi_pos()\n\n" << RESET;
|
||||
|
||||
// if (pos != NPOS)
|
||||
// {
|
||||
// client->fill_script_path(path, pos);
|
||||
// std::string script_output = _exec_cgi(client);
|
||||
// _check_script_output(client, script_output);
|
||||
// client->response += script_output;
|
||||
// return;
|
||||
// }
|
||||
if (pos != NPOS)
|
||||
{
|
||||
client->fill_script_path(path, pos);
|
||||
script_output = _exec_cgi(client);
|
||||
_check_script_output(client, script_output);
|
||||
client->response += script_output;
|
||||
return;
|
||||
}
|
||||
_process_method(client, path);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user