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

@@ -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)