From d663a4c7e6e1f5226bb65152d964011a59c5f0da Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sun, 14 Aug 2022 16:17:24 +0200 Subject: [PATCH] added debug print --- srcs/Client.cpp | 5 ----- srcs/webserv/cgi_script.cpp | 9 +-------- srcs/webserv/response.cpp | 9 +++++++++ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/srcs/Client.cpp b/srcs/Client.cpp index f101c03..2de52e4 100644 --- a/srcs/Client.cpp +++ b/srcs/Client.cpp @@ -213,18 +213,13 @@ void Client::fill_script_path(std::string &path, size_t pos) { std::string tmp; - /*DEBUG*/ std::cout << "\n" << B_PURPLE << "debug path dot" << RESET << "\npath:[" << path << "]\n" << "&path[pos]:[" << &path[pos] << "]\n"; if (path[0] == '.') { path.erase(0, 1); pos--; } - /*DEBUG*/ std::cout << "path:[" << path << "]\n" << "&path[pos]:[" << &path[pos] << "]\n"; - _request.script.path = path.substr(0, pos); - /*DEBUG*/ std::cout << "script_path:[" << _request.script.path << "]\n"; _request.script.info = path.substr(pos); - /*DEBUG*/ std::cout << "script_info:[" << _request.script.info << "]\n" << B_PURPLE << "end debug path dot" << RESET << "\n"; } void Client::clear() diff --git a/srcs/webserv/cgi_script.cpp b/srcs/webserv/cgi_script.cpp index e1b4d52..3981666 100644 --- a/srcs/webserv/cgi_script.cpp +++ b/srcs/webserv/cgi_script.cpp @@ -11,7 +11,6 @@ bool Webserv::_is_cgi(Client *client, std::string path) while (pos != NPOS) { pos = _cgi_pos(client, path, pos); - /*DEBUG*/ std::cout << "pos:" << pos << "\n&path[pos]:" << &path[pos] << "\n" << B_YELLOW << "fin debug _cgi_pos()\n\n" << RESET; if (pos == NPOS) break; client->fill_script_path(path, pos); @@ -27,7 +26,6 @@ bool Webserv::_is_cgi(Client *client, std::string path) } } client->clear_script(); - client->clear_script(); client->status = file_mode; // 404 not_found OR 403 forbidden return false; } @@ -40,25 +38,20 @@ size_t Webserv::_cgi_pos(Client *client, std::string &path, size_t pos) 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()) return NPOS; - /*DEBUG*/ std::cout << "ext:[" << *it << "]\n" << "path:[" << path << "]\n\n"; it_end = client->assigned_location->cgi_ext.end(); while (pos < path.size()) { - /*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"; len = (*it).size(); if (path.compare(pos + 1, len, *it) == 0) if ( !std::isalpha(path[pos + 1 + len], loc) ) @@ -164,7 +157,7 @@ std::string Webserv::_exec_script(Client *client, char **env) dup2(FD_RD_FR_PRNT, STDIN_FILENO); dup2(FD_WR_TO_PRNT, STDOUT_FILENO); path = "." + client->get_rq_script_path(); - /*DEBUG*/std::cerr << "execve\n" << "path:[" << path << "]\n"; +/*DEBUG*/std::cerr << "execve:[" << path << "]\n"; execve(path.c_str(), nll, env); // for tests execve crash : //execve("wrong", nll, env); diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 7acae2a..587db23 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -44,6 +44,8 @@ int Webserv::_send_response(Client *client) if (client->status >= 400) _error_html_response(client); +/*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output + headers]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; + std::cerr << "client->response.size() = " << client->response.size() << "\n"; // DEBUG ret = ::send(client->get_cl_fd(), client->response.c_str(), client->response.size(), 0); if (ret == -1) @@ -77,8 +79,15 @@ void Webserv::_construct_response(Client *client) if (_is_cgi(client, path)) { script_output = _exec_cgi(client); + +/*DEBUG*/ std::cout << "\n" B_PURPLE "[script output]:" RESET "\n"; ::print_special(script_output); std::cout << B_PURPLE "-----------" RESET "\n\n"; +/*DEBUG*/ std::cout << "\n" B_PURPLE "[response]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; + _check_script_output(client, script_output); client->response += script_output; + +/*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; + return; } _process_method(client, path);