wip test path cgi :

- _cgi_pos seems to be ok
  - construct url from return is not implemented yet
+ renamed script with extension .php and .cpp
This commit is contained in:
hugogogo
2022-08-12 23:31:59 +02:00
parent c7bbf29a1b
commit f17bc9fa58
7 changed files with 45 additions and 18 deletions

View File

@@ -31,6 +31,7 @@
# include "utils.hpp"
# include "http_status.hpp"
# include "autoindex.hpp"
# include "colors.h"
extern bool g_run;
extern int g_last_signal;

View File

@@ -4,18 +4,36 @@
// TODO HUGO : go ameliorer la recherche comme on a dit.
size_t Webserv::_cgi_pos(Client *client, std::string &path)
{
size_t pos = NPOS;
std::vector<std::string> v_ext;
std::vector<std::string>::const_iterator it;
it = client->assigned_location->cgi_ext.begin();
while (it != client->assigned_location->cgi_ext.end())
std::vector<std::string>::const_iterator it_end;
size_t pos = 0;
/*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())
return NPOS;
/*DEBUG*/ std::cout << "ext:[" << *it << "]\n" << "path:[" << path << "]\n\n";
it_end = client->assigned_location->cgi_ext.end();
while (pos < path.size())
{
pos = std::min(path.find(*it) + it->size(), pos);
++it;
/*DEBUG*/ std::cout << "\nwhile\n";
if (path.compare(pos, 2, "./") == 0)
pos += 2;
/*DEBUG*/ std::cout << "&path[pos]:[" << &path[pos] << "]\n";
pos = path.find('.', pos);
if (pos == NPOS)
return pos;
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;
}
pos++;
}
if (pos == NPOS)
return false;
else
return true;
return pos;
}
std::string Webserv::_exec_cgi(Client *client)

View File

@@ -71,15 +71,18 @@ void Webserv::_construct_response(Client *client)
{
std::string path = _replace_url_root(client, client->get_rq_abs_path());
/* size_t pos = _cgi_pos(client, path);
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;
} */
size_t pos = _cgi_pos(client, path);
//debug
std::cout << "pos:" << pos << B_YELLOW << "\nfin debug _cgi_pos()\n\n" << RESET;
(void)pos;
// 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;
// }
_process_method(client, path);
}