add extern function for http message parsing

+ wip compare fields server and script
+ g tout cassey
This commit is contained in:
hugogogo
2022-08-09 11:19:46 +02:00
parent ae9a9b37f1
commit 3dad938e3c
13 changed files with 225 additions and 86 deletions

View File

@@ -102,7 +102,8 @@ std::string Webserv::_exec_script(Client *client, char **env)
close(FD_RD_FR_CHLD);
dup2(FD_RD_FR_PRNT, STDIN_FILENO);
dup2(FD_WR_TO_PRNT, STDOUT_FILENO);
execve(client->get_rq_script_path().c_str(), nll, env);
//execve(client->get_rq_script_path().c_str(), nll, env);
execve("truc", nll, env);
std::cerr << "execve crashed.\n";
}
else
@@ -119,13 +120,42 @@ std::string Webserv::_exec_script(Client *client, char **env)
script_output += buf;
memset(buf, '\0', CGI_BUF_SIZE);
}
close(FD_RD_FR_CHLD);
}
if (script_output.empty())
script_output = "Status: 500\r\n\r\n";
// DEBUG
std::cout << "\n______response______\n" << script_output << "\n____end response____\n";
return script_output;
}
void Webserv::_check_script_output(Client *client, std::string output)
{
// TODO: it doesn't work with execve error, i don't know why yet ?
_check_script_status(client, output);
_check_script_fields(client, output);
}
void Webserv::_check_script_status(Client *client, std::string output)
{
size_t pos;
int status_pos;
pos = output.find("Status:");
if (pos != std::string::npos)
{
status_pos = pos + std::string("Status:").size();
client->status = atoi(output.c_str() + status_pos);
::delete_line_in_string(&output, pos, CRLF);
}
client->status = 200;
}
void Webserv::_check_script_fields(Client *client, std::string output)
{
std::map<std::string, std::string> server_fields;
std::map<std::string, std::string> script_fields;
server_fields = parse_http_headers(client->response);
script_fields = parse_http_headers(output);
// TODO: compare both map to supress duplicates
}