wip debug comparison fields output script
This commit is contained in:
@@ -106,9 +106,9 @@ std::string Webserv::_exec_script(Client *client, char **env)
|
||||
dup2(FD_WR_TO_PRNT, STDOUT_FILENO);
|
||||
// DEBUG
|
||||
std::cerr << "execve:\n";
|
||||
//execve(client->get_rq_script_path().c_str(), nll, env);
|
||||
execve(client->get_rq_script_path().c_str(), nll, env);
|
||||
// for tests execve crash :
|
||||
execve("wrong", nll, env);
|
||||
//execve("wrong", nll, env);
|
||||
std::cerr << "execve crashed.\n";
|
||||
}
|
||||
else
|
||||
@@ -135,19 +135,13 @@ std::string Webserv::_exec_script(Client *client, char **env)
|
||||
return script_output;
|
||||
}
|
||||
|
||||
void Webserv::_check_script_output(Client *client, std::string output)
|
||||
void Webserv::_check_script_output(Client *client, std::string & output)
|
||||
{
|
||||
// DEBUG
|
||||
std::cout << "outpu:__________\n" << output << "__________\n"
|
||||
<< "\nstatus:" << client->status << "__________\n";
|
||||
_check_script_status(client, output);
|
||||
// DEBUG
|
||||
std::cout << "outpu:__________\n" << output << "__________\n"
|
||||
<< "\nstatus:" << client->status << "__________\n";
|
||||
_check_script_fields(client, output);
|
||||
}
|
||||
|
||||
void Webserv::_check_script_status(Client *client, std::string output)
|
||||
void Webserv::_check_script_status(Client *client, std::string & output)
|
||||
{
|
||||
size_t pos;
|
||||
int status_pos;
|
||||
@@ -163,27 +157,79 @@ void Webserv::_check_script_status(Client *client, std::string output)
|
||||
client->status = 200;
|
||||
}
|
||||
|
||||
void Webserv::_check_script_fields(Client *client, std::string output)
|
||||
void Webserv::_check_script_fields(Client *client, std::string & output)
|
||||
{
|
||||
std::map<std::string, std::string> srv_fld; // server_field
|
||||
std::map<std::string, std::string> scr_fld; // script_field
|
||||
std::map<std::string, std::string>::iterator it_srv;
|
||||
std::map<std::string, std::string>::iterator it_scr;
|
||||
std::string tmp;
|
||||
size_t pos;
|
||||
|
||||
::parse_http_headers(client->response, srv_fld);
|
||||
::parse_http_headers(output, scr_fld);
|
||||
// wip: compare both map to supress duplicates
|
||||
// put server headers in map
|
||||
tmp = client->response;
|
||||
pos = tmp.find(CRLF CRLF);
|
||||
if (pos != std::string::npos)
|
||||
tmp.erase(pos);
|
||||
::parse_http_headers(tmp, srv_fld);
|
||||
// put script headers in map
|
||||
tmp = output;
|
||||
pos = tmp.find(CRLF CRLF);
|
||||
if (pos != std::string::npos)
|
||||
tmp.erase(pos);
|
||||
::parse_http_headers(tmp, scr_fld);
|
||||
// compare both map to supress duplicates
|
||||
|
||||
// debug
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
std::cout << "\n\n+++++\ndebug comparison:\nBEFORE\nserver headers:\n";
|
||||
for (it = srv_fld.begin(); it != srv_fld.end(); it++) {
|
||||
std::cout << " " << it->first << ": [" << it->second << "]\n"; }
|
||||
std::cout << "\nscript headers:\n";
|
||||
for (it = scr_fld.begin(); it != scr_fld.end(); it++) {
|
||||
std::cout << " " << it->first << ": [" << it->second << "]\n"; }
|
||||
// en debug
|
||||
|
||||
for (it_srv = srv_fld.begin(); it_srv != srv_fld.end(); it_srv++)
|
||||
{
|
||||
for (it_scr = scr_fld.begin(); it_scr != scr_fld.end(); it_scr++)
|
||||
{
|
||||
if (it_srv->first == it_scr->first)
|
||||
if (str_tolower(it_srv->first) == str_tolower(it_scr->first))
|
||||
{
|
||||
pos = client->response.find(it_srv->first);
|
||||
::extract_line(client->response, pos, CRLF);
|
||||
// debug
|
||||
std::cout << "helloooooooooooooooooooooooooooooo\n";
|
||||
std::cout << pos << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// debug
|
||||
srv_fld.clear();
|
||||
scr_fld.clear();
|
||||
// put server headers in map
|
||||
tmp = client->response;
|
||||
pos = tmp.find(CRLF CRLF);
|
||||
if (pos != std::string::npos)
|
||||
tmp.erase(pos);
|
||||
::parse_http_headers(tmp, srv_fld);
|
||||
// put script headers in map
|
||||
tmp = output;
|
||||
pos = tmp.find(CRLF CRLF);
|
||||
if (pos != std::string::npos)
|
||||
tmp.erase(pos);
|
||||
::parse_http_headers(tmp, scr_fld);
|
||||
// compare both map to supress duplicates
|
||||
|
||||
std::cout << "\nAFTER\nserver headers:\n";
|
||||
for (it = srv_fld.begin(); it != srv_fld.end(); it++) {
|
||||
std::cout << " " << it->first << ": [" << it->second << "]\n"; }
|
||||
std::cout << "\nscript headers:\n";
|
||||
for (it = scr_fld.begin(); it != scr_fld.end(); it++) {
|
||||
std::cout << " " << it->first << ": [" << it->second << "]\n"; }
|
||||
std::cout << "\nend debug comparison\n+++++\n\n";
|
||||
// end debug
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user