From 5a03f111ecdd86e8f5760c52cfc16f16bfea16a3 Mon Sep 17 00:00:00 2001 From: Talyx Date: Wed, 16 Feb 2022 00:16:16 +0300 Subject: [PATCH] fix: segv --- config/real.toml | 34 +++++++++++++++------------------- src/Client/Config.cpp | 4 ++++ src/Client/Response.cpp | 10 ++-------- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/config/real.toml b/config/real.toml index a38df35..297a318 100644 --- a/config/real.toml +++ b/config/real.toml @@ -1,18 +1,18 @@ [[server]] name = "pohek1.org" - host = "127.0.0.1" - port = 8080 - body_size_limit = 10000000 + host = "127.0.0.1" # check inet_addr() + port = 8080 # check num, (0, 65536) + body_size_limit = 10000000 #(pofig and > 0) [server.error_page] - 403 = "www/errorFolder/index2.html" + "404" = "www/errorFolder/error_404.html" # throw exception if not string [[server.location]] - location = "/" - root = "www/" - methods = ["GET", "POST", "DELETE"] - autoindex = true + location = "/" # mandatory + root = "www/" # check valid + methods = ["GET", "POST", "DELETE"] + autoindex = true #check if bool directory_file = "index.html" - upload_accept = true - upload_dir = "/var/www/html/upload" + upload_accept = true #throw exception if not bool + upload_dir = "www/upload" # check valid [[server.location]] location = "/images" root = "www/images" @@ -20,7 +20,7 @@ autoindex = true [[server.location]] location = "/images/168.png" - redirect = ["301", "http://127.0.0.1:8080/168.png"] + redirect = ["301", "http://127.0.0.1:8080/168.png"] #throw exception if no array, or more 2 elem, or elem is not str [[server.location]] location = "/errorFolder/images/168.png" redirect = ["301", "http://127.0.0.1:8080/168.png"] @@ -32,20 +32,16 @@ location = "*.png" root = "www/images/pngImg" methods = ["GET"] - [[server.location]] - location = "*.ico" - root = "www/images/icoImg" - methods = ["GET"] [[server.location]] location = "/errorFolder" root = "www/errorFolder" methods = ["GET", "POST"] - autoindex = false + autoindex = true [[server.location]] location = "*.php" root = "www/script" autoindex = false - cgi_pass = "/usr/bin/php-cgi" + cgi_pass = "/usr/bin/php-cgi" #check valid [[server]] name = "pohek2.org" host = "127.0.0.1" @@ -63,7 +59,7 @@ autoindex = true directory_file = "index.html" upload_accept = false - upload_dir = "/var/www/html/upload" + upload_dir = "www/upload" [[server]] name = "localhost" host = "127.0.0.1" @@ -81,4 +77,4 @@ autoindex = true directory_file = "index.html" upload_accept = false - upload_dir = "/var/www/html/upload" + upload_dir = "www/upload" diff --git a/src/Client/Config.cpp b/src/Client/Config.cpp index 682268b..0109d9d 100644 --- a/src/Client/Config.cpp +++ b/src/Client/Config.cpp @@ -135,7 +135,11 @@ location *Config::getLocation(std::vector &arr, std::string &URI) { tmp = *it; if (tmp->location == "/") + { + tmp = new location; + copyLocation(tmp, *it); return (tmp); + } it++; } diff --git a/src/Client/Response.cpp b/src/Client/Response.cpp index a9c4c97..bfe7755 100644 --- a/src/Client/Response.cpp +++ b/src/Client/Response.cpp @@ -228,6 +228,8 @@ std::string Response::getFullURI(void) else ret = tmp; + DBOUT << PINK << "location " << _location->location << ENDL; + DBOUT << PINK << "fullURI " << ret << ENDL; return (ret); } @@ -415,14 +417,6 @@ void Response::methodPost(void) _body.erase(_body.begin(), _body.begin() + pos + 4); } } - else - { - std::ofstream outfile(_fullURI.c_str(), std::ios::out | std::ios::binary); - - outfile.write(_request.getBody().data(), _request.getBody().size()); - outfile.close(); - _code = 204; - } setHeaderBlocks(); generateHeader(); DBOUT << GREEN << "POST method called" << ENDL;