diff --git a/default.config b/default.config index 088b63d..a5dc5f7 100644 --- a/default.config +++ b/default.config @@ -19,6 +19,11 @@ server { autoindex on; } + location /cgi-bin { + root ./srcs/cgi-bin/; + cgi_ext cgi php txt; + } + location /redirect { redirect 307 https://fr.wikipedia.org/wiki/Ketchup; # redirect 307 https://www.youtube.com/watch?v=rG6b8gjMEkw; diff --git a/srcs/cgi-bin/cgi.cpp b/srcs/cgi-bin/cgi.cpp old mode 100644 new mode 100755 index 3882239..95013cb Binary files a/srcs/cgi-bin/cgi.cpp and b/srcs/cgi-bin/cgi.cpp differ diff --git a/srcs/cgi-bin/php-cgi b/srcs/cgi-bin/cgi.php similarity index 100% rename from srcs/cgi-bin/php-cgi rename to srcs/cgi-bin/cgi.php diff --git a/srcs/cgi-bin/cgi_cpp.cgi b/srcs/cgi-bin/cgi_cpp.cgi deleted file mode 100755 index 95013cb..0000000 Binary files a/srcs/cgi-bin/cgi_cpp.cgi and /dev/null differ diff --git a/srcs/webserv/Webserv.hpp b/srcs/webserv/Webserv.hpp index 12964a3..ee058d3 100644 --- a/srcs/webserv/Webserv.hpp +++ b/srcs/webserv/Webserv.hpp @@ -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; diff --git a/srcs/webserv/cgi_script.cpp b/srcs/webserv/cgi_script.cpp index fe81ff4..e928180 100644 --- a/srcs/webserv/cgi_script.cpp +++ b/srcs/webserv/cgi_script.cpp @@ -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 v_ext; std::vector::const_iterator it; - it = client->assigned_location->cgi_ext.begin(); - while (it != client->assigned_location->cgi_ext.end()) + std::vector::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) diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 436e478..302e20b 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -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); }