From 19afaf1274da7aba08621384173484eafcba1a9c Mon Sep 17 00:00:00 2001 From: Joseph Cheel nakashima Date: Tue, 25 Jun 2024 16:47:54 +0200 Subject: [PATCH] clean some code removing comments and std::cout --- mandatory/src/FileContent.cpp | 2 - mandatory/src/ListeningSocket.cpp | 30 ++----------- mandatory/src/Location.cpp | 11 ++--- mandatory/src/LocationParser.cpp | 71 +++++++++++-------------------- mandatory/src/Parser.cpp | 38 +++-------------- mandatory/src/Recieve.cpp | 3 +- mandatory/src/Server.cpp | 4 -- mandatory/src/ServerGetters.cpp | 4 -- mandatory/src/StatusCode.cpp | 4 +- mandatory/src/WebServer.cpp | 21 --------- mandatory/src/WebServerLNX.cpp | 6 +-- mandatory/src/WebservParser.cpp | 4 +- mandatory/src/utils.cpp | 39 ----------------- 13 files changed, 45 insertions(+), 192 deletions(-) diff --git a/mandatory/src/FileContent.cpp b/mandatory/src/FileContent.cpp index 6be0ae3..5b3a0f2 100644 --- a/mandatory/src/FileContent.cpp +++ b/mandatory/src/FileContent.cpp @@ -98,11 +98,9 @@ std::string FileContent::getContent() bool FileContent::setFileName(const std::string &file_name, const std::string &fileArgs) { - // std::string FileAndFolder = this->splitFileFromArgs(file_name); bool fileOrFolderExists = this->FileOrFolerExtists(file_name); if (fileOrFolderExists) { - std::cout << "isCGI: " << cgiModule->getIsCGI() << std::endl; if (this->isInputDirectory() && isAutoIndex) { diff --git a/mandatory/src/ListeningSocket.cpp b/mandatory/src/ListeningSocket.cpp index bf4c597..d4a9a05 100644 --- a/mandatory/src/ListeningSocket.cpp +++ b/mandatory/src/ListeningSocket.cpp @@ -132,36 +132,14 @@ std::string ListeningSocket::getAnswerToSend() if (this->getFirstFragment()) { - // if (response.getContentType().find("video/") != std::string::npos && this->request.getAttribute("Sec-Fetch-Dest").find("document") != std::string::npos) - // response.setAttribute("Accept-Ranges", "bytes"); - // sendingValue = minimum(this->getFileSize(), static_cast (MAX_SENT_BYTES)); - // answer = "bytes 0 -" + toString(sendingValue); - // response.setAttribute("Content-Range", answer); - // response.setAttribute("Content-Length", toString(this->getFileSize())); answer = response.generateHeader() + file_content; this->setFirstFragment(false); - std::cout << "Answer: " << answer.substr(0, 200) << std::endl; - std::cout << "------------------------------------------------" << std::endl; - } - else - { - // | Accept - Ranges : bytes | - // | Content - Range : bytes 828604416 - 828908176 / 828908177 | - // | Content - Length : 303761 answer = "bytes=" + toString | - // response.setStatus(this->getCodeContent(PARTIAL_CONTENT_CODE)); - // response.setAttribute("Accept-Ranges", "bytes"); - // answer = "bytes " + toString(this->getLastSendingPosition()) + " - " + toString(this->getCurrentSendingPosition()) + " / 83510215"; - // //+toString(this->getFileSize()); - // response.setAttribute("Content-Range", answer); - // sendingValue = this->getCurrentSendingPosition() - this->getLastSendingPosition(); - // response.setAttribute("Content-Length", toString(sendingValue)); - // answer = response.generateHeader() + file_content; - answer = file_content; // std::cout << "Answer: " << answer.substr(0, 200) << std::endl; // std::cout << "------------------------------------------------" << std::endl; - // std::cout << "filesize: " << this->getFileSize() << std::endl; - // std::cout << "------------------------------------------------" << std::endl; } + else + answer = file_content; + return (answer); } @@ -196,8 +174,6 @@ void ListeningSocket::loadRequest(std::vector servers) this->request = Parser.getRequest(); this->response = Parser.getResponse(); this->setIsAutoIndex(Parser.getIsAutoIndex()); - // std::cout << "LocationParser isCGI: " << Parser.getIsCGI() << std::endl; - // this->setCgiPath(Parser.getCGIPath()); this->setIsCGI(Parser.getIsCGI()); this->setStartRange(Parser.getStartRange()); diff --git a/mandatory/src/Location.cpp b/mandatory/src/Location.cpp index fd5bd44..1a8f593 100644 --- a/mandatory/src/Location.cpp +++ b/mandatory/src/Location.cpp @@ -26,7 +26,7 @@ std::map var_names_location() varnames[VAR_LOC_CGI_EXTENSION] = 0; return varnames; } -// Method to get the methods of the location + std::map getLocationMethods() { std::map locationMethods; @@ -43,7 +43,7 @@ std::map getLocationMethods return locationMethods; } -// Default constructor + Location::Location() { name = ""; @@ -60,10 +60,9 @@ Location::Location() Location::Location(std::string const &content) { this->isCgi = false; - // std::cout << "Location constructor" << std::endl; this->loadData(content); } -// Copy constructor + Location::Location(const Location& other) { setName(other.name); @@ -75,7 +74,7 @@ Location::Location(const Location& other) setAlias(other.alias); } -// Destructor + Location::~Location() {} // Getter methods @@ -217,13 +216,11 @@ void Location::checkVariables(bool serverAutoIndex) switch (Parser::checkLocationName(this->name)) { case 2: - // std::cout << "CGI PATH: " << this->cgiPathStr << std::endl; if (!Parser::checkCgiString(this->cgiPathStr, this->cgiExtensionStr)) exit(1); this->setCgiPath(this->cgiPathStr); this->setCgiExtension(this->cgiExtensionStr); Parser::checkCgi(this->cgiPath, this->cgiExtension); - // std::cout << "Is cgi true: " << std::endl; this->isCgi = true; break ; case 1: diff --git a/mandatory/src/LocationParser.cpp b/mandatory/src/LocationParser.cpp index afab276..d89ca91 100644 --- a/mandatory/src/LocationParser.cpp +++ b/mandatory/src/LocationParser.cpp @@ -63,12 +63,6 @@ int LocationParser::isAllowedMethod(Location *location) return OK; } - -// std::string getCgiPath(std::string extension) -// { - -// } - int LocationParser::matchingLocation() { std::vector locations = this->server->getLocations(); @@ -141,7 +135,6 @@ std::string escapeNonPrintableChars(const std::string& str) { case '\t': escapedStr += "\\t"; break; - // Add more cases for other non-printable characters if needed default: escapedStr += str[i]; break; @@ -152,7 +145,6 @@ std::string escapeNonPrintableChars(const std::string& str) { bool isBadRequest(std::string request) { - // std::cout << "REQUEST: " << escapeNonPrintableChars(request) << std::endl; if (request.empty()) return true; std::istringstream iss(request); @@ -166,11 +158,9 @@ bool isBadRequest(std::string request) if (std::count(line.begin(), line.end(), ' ') != 2 && splitString(line, ' ').size() != 3) return true; firstLine = false; - // std::cout << "FIRST LINE " << line << std::endl; } else { - // std::cout << "line " << line << std::endl; if (line.empty() || line == "\r") break ; @@ -218,7 +208,6 @@ void LocationParser::checks() if (isDirPermissions(path, F_OK | R_OK) == true) path += this->server->getIndex(); this->request.setPath(path); - // this->fileContent->setAutoIndex(server->getAutoIndex()); break ; case NOT_ALLOWED : response.setStatus("405 Method Not Allowed"); @@ -229,7 +218,7 @@ void LocationParser::checks() } this->request.setPath(decodeURL(this->request.getPath())); - std::cout << request.getPath() << std::endl; + // std::cout << request.getPath() << std::endl; if (isBadRequest(receiver->getRequest()))//|| isURIMalformed(this->request.getPath()) { response.setStatus("400 Bad Request"); @@ -258,37 +247,36 @@ void LocationParser::checks() { if (getMimeType(this->request.getPath()).find("video") != std::string::npos) { - std::string attr = request.getAttribute("Range"); - int tt = isFilePermissions(this->request.getPath(), F_OK | R_OK); - (void)tt; - if (isFilePermissions(this->request.getPath(), F_OK | R_OK) == 1 && request.getAttribute("Range") != "") - { + // std::string attr = request.getAttribute("Range"); + // int tt = isFilePermissions(this->request.getPath(), F_OK | R_OK); + // (void)tt; + // if (isFilePermissions(this->request.getPath(), F_OK | R_OK) == 1 && request.getAttribute("Range") != "") + // { - response.setStatus("206 Partial Content"); - response.setContentType(this->request.getPath()); + // response.setStatus("206 Partial Content"); + // response.setContentType(this->request.getPath()); - if (this->request.getAttribute("Range") != "") - { - this->startRange = stringToSizeT(this->request.getAttribute("Range").substr(6, this->request.getAttribute("Range").find("-"))); - std::cout << "STARTRANGE " << this->startRange << std::endl; - std::string endRangeStr = this->request.getAttribute("Range").substr(this->request.getAttribute("Range").find("-") + 1, this->request.getAttribute("Range").size()); - std::cout << "ENDRANGE " << endRangeStr << std::endl; - if (endRangeStr.empty()) - { - this->endRange = getFileSize(this->request.getPath()); - } - else - { - this->endRange = stringToSizeT(endRangeStr); - } - } - } - else if (isFilePermissions(this->request.getPath(), F_OK | R_OK) == 1) + // if (this->request.getAttribute("Range") != "") + // { + // this->startRange = stringToSizeT(this->request.getAttribute("Range").substr(6, this->request.getAttribute("Range").find("-"))); + // std::cout << "STARTRANGE " << this->startRange << std::endl; + // std::string endRangeStr = this->request.getAttribute("Range").substr(this->request.getAttribute("Range").find("-") + 1, this->request.getAttribute("Range").size()); + // std::cout << "ENDRANGE " << endRangeStr << std::endl; + // if (endRangeStr.empty()) + // { + // this->endRange = getFileSize(this->request.getPath()); + // } + // else + // { + // this->endRange = stringToSizeT(endRangeStr); + // } + // } + // } + if (isFilePermissions(this->request.getPath(), F_OK | R_OK) == 1) { response.setContentType(this->request.getPath()); response.setContentLength(getFileSize(this->request.getPath())); response.setStatus("200 OK"); - // response.setAttribute("Accept-Ranges", "bytes"); } else { @@ -298,13 +286,8 @@ void LocationParser::checks() } else if (isFilePermissions(this->request.getPath(), F_OK | R_OK) == 1) { - // std::cout << "FILEPERMISIOn" << this->request.getPath() << std::endl; - response.setContentType(this->request.getPath()); - // response.setLastModified(this->fileContent->getLastModified()); - // response.setContentLength(this->fileContent->getContentSize()); response.setStatus("200 OK"); - // response.setServer(server->getServerName()); } else if (isDirPermissions(this->request.getPath(), F_OK | R_OK) == true && this->isAutoIndex == true) { @@ -319,7 +302,6 @@ void LocationParser::checks() } else if (this->request.getMethod() == "POST") { - // std::cout << this->receiver->getisform() << std::endl; std::string body = receiver->getBody(); if (body.size() > (size_t)this->server->getMaxClientBodySize()) @@ -367,7 +349,6 @@ void LocationParser::checks() } else if (receiver->getisform()) { - // std::cout << "form: " << body << std::endl; this->query = body; response.setStatus("200 Created"); } @@ -379,12 +360,10 @@ void LocationParser::checks() response.setStatus("200 OK"); else response.setStatus("404 Not Found"); - // response.setServer(server->getServerName()); } else { response.setStatus("405 Method Not Allowed"); - // response.setServer(server->getServerName()); throw METHOD_NOT_ALLOWED_CODE; } } diff --git a/mandatory/src/Parser.cpp b/mandatory/src/Parser.cpp index 4d2bbdc..6f053d0 100644 --- a/mandatory/src/Parser.cpp +++ b/mandatory/src/Parser.cpp @@ -51,8 +51,8 @@ in_addr_t Parser::isValidHost(std::string hostname) std::memset(&hints, 0, sizeof(hints)); std::memset(&in_addr, 0, sizeof(in_addr)); - hints.ai_family = AF_INET; // IPv4 - hints.ai_socktype = SOCK_STREAM; // Or SOCK_DGRAM for UDP + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; int status = getaddrinfo(hostname.c_str(), NULL, &hints, &res); @@ -114,9 +114,8 @@ bool Parser::checkErrorPage(std::string errorPage) } closedir(errorDirectory); - // std::cout << "Found files:" << std::endl; std::sort(foundFiles.begin(), foundFiles.end()); - std::cout << CHR_GREEN << getLocalTime() << " [" << "NOTICE" << "]" RESET << "\t\terror_pages found\t" << RESET ;//message << RESET << std::endl; + std::cout << CHR_GREEN << getLocalTime() << " [" << "NOTICE" << "]" RESET << "\t\terror_pages found\t" << RESET ; if (foundFiles.size() == 0) { @@ -187,11 +186,10 @@ bool Parser::checkIndex(std::string index, std::string root) return true; } -// Define the maximum number of bytes allowed const long long MAX_BYTES = 1099511627776; // 1 Terabyte for example -long long convertToBytes(const std::string& sizeStr) { - // Find the position where the numeric part ends and the unit starts +long long convertToBytes(const std::string& sizeStr) +{ size_t pos = 0; while (pos < sizeStr.size() && (std::isdigit(sizeStr[pos]) || sizeStr[pos] == '.')) { pos++; @@ -201,23 +199,19 @@ long long convertToBytes(const std::string& sizeStr) { throw std::invalid_argument("Invalid size format"); } - // Extract the numeric part and the unit part double sizeValue = std::atoll(sizeStr.substr(0, pos).c_str()); std::string unit = sizeStr.substr(pos); - // Convert the unit to lowercase for easier comparison for (size_t i = 0; i < unit.size(); ++i) { unit[i] = std::tolower(unit[i]); } - // Conversion factors const long long BYTES_IN_KB = 1024; const long long BYTES_IN_MB = BYTES_IN_KB * 1024; const long long BYTES_IN_GB = BYTES_IN_MB * 1024; const long long BYTES_IN_TB = BYTES_IN_GB * 1024; const long long BITS_IN_BYTE = 8; - // Calculate the byte value long long bytes; if (unit.empty() || unit == "b") { bytes = static_cast(sizeValue); @@ -243,7 +237,6 @@ long long convertToBytes(const std::string& sizeStr) { throw std::invalid_argument("Unknown size unit"); } - // Check if the byte value exceeds the maximum allowed if (bytes > MAX_BYTES) { throw std::overflow_error("Size exceeds the maximum allowed bytes"); } @@ -256,12 +249,6 @@ long long Parser::checkClientBodySize(std::string maxClientBodySize) if (maxClientBodySize.empty()) return (DEFAULT_MAX_BOD_SIZE); - // if (!isNumber(maxClientBodySize)) - // { - // printLog("ERROR", "max_client_body_size\t<" + maxClientBodySize + ">\tis not a number." ); - // exit(1); - // } - try { long long nbr = convertToBytes(maxClientBodySize); return (nbr); @@ -356,14 +343,7 @@ int Parser::checkRootAliasReturn(std::string root, std::string alias, std::strin return (ALIAS); } else if (!return_.empty()) - { - // if (!isDirPermissions(return_, F_OK ) && (return_.find("http://") == std::string::npos && return_.find("https://") == std::string::npos)) - // { - // printLog("ERROR", "return\t\t<" + return_ + ">\tnot a valid directory." ); - // exit(1); - // } return (RETURN); - } return (0); } @@ -430,14 +410,6 @@ bool Parser::checkCgi(std::vector paths, std::vector e break ; } } - // for (size_t size = 0; size < extensions.size(); size++) - // { - // if (extensions[size].find('.') == std::string::npos) - // { - // printLog("ERROR", "cgi_extension\t\t<" + extensions[size] + ">\tis not a valid extension" ); - // return false; - // } - // } return true; } diff --git a/mandatory/src/Recieve.cpp b/mandatory/src/Recieve.cpp index e3619a7..6c7f646 100644 --- a/mandatory/src/Recieve.cpp +++ b/mandatory/src/Recieve.cpp @@ -75,7 +75,6 @@ bool Receive::receiveHeader(int fd) { if (header.getAttribute("Content-Type").find("boundary") != std::string::npos) this->boundary = header.getAttribute("Content-Type").substr(header.getAttribute("Content-Type").find("boundary=") + 9); - // std::cout << "BOUNDARY $" << this->boundary << "$" << std::endl; } else return true; @@ -141,7 +140,7 @@ bool Receive::receiveBody(int fd) this->body += this->buffer; std::memset(buf, 0, MAX_MSG_SIZE); } - if (ret < 0) // This is not handle as an error + if (ret < 0) return false; else if (ret == 0) { diff --git a/mandatory/src/Server.cpp b/mandatory/src/Server.cpp index 277d32e..e528e3b 100644 --- a/mandatory/src/Server.cpp +++ b/mandatory/src/Server.cpp @@ -9,8 +9,6 @@ std::map var_names_server() varnames[VAR_ERROR_PAGE] = 0; varnames[VAR_ROOT] = 0; varnames[VAR_INDEX] = 0; - // varnames[VAR_CGI_EXTENSION] = 0; - // varnames[VAR_CGI_FOLDER] = 0; varnames[VAR_CLIENT_MAX_BODY_SIZE] = 0; varnames[VAR_AUTOINDEX] = 0; return varnames; @@ -26,8 +24,6 @@ std::map ServerSetters() serverMethods[VAR_ERROR_PAGE] = &Server::setErrorPage; serverMethods[VAR_ROOT] = &Server::setRoot; serverMethods[VAR_INDEX] = &Server::setIndex; - // serverMethods[VAR_CGI_EXTENSION] = &Server::setCGIExtension; - // serverMethods[VAR_CGI_FOLDER] = &Server::setCGIFolder; serverMethods[VAR_CLIENT_MAX_BODY_SIZE] = &Server::setMaxClientBodySizeStr; serverMethods[VAR_AUTOINDEX] = &Server::setAutoindex; return serverMethods; diff --git a/mandatory/src/ServerGetters.cpp b/mandatory/src/ServerGetters.cpp index 13f0a03..39912e6 100644 --- a/mandatory/src/ServerGetters.cpp +++ b/mandatory/src/ServerGetters.cpp @@ -40,10 +40,6 @@ std::vector Server::getServerFds() std::vector fd; std::map::iterator itb = this->port.begin(); std::map::iterator ite = this->port.end(); - // for (std::map::iterator it = this->port.begin(); it != this->port.end(); ++it) - // { - // std::cout << "Listening on port: " << it->first << " with fd " << it->second->getFd() << std::endl; - // } while (itb != ite) { fd.push_back(itb->second->getFd()); itb++; diff --git a/mandatory/src/StatusCode.cpp b/mandatory/src/StatusCode.cpp index aa43382..e46be16 100644 --- a/mandatory/src/StatusCode.cpp +++ b/mandatory/src/StatusCode.cpp @@ -15,8 +15,8 @@ int StatusCode::getCode() return this->currentCode; } -void StatusCode::createDefaultErrorCodes(){ - // Add HTTP error types to the map +void StatusCode::createDefaultErrorCodes() +{ this->mapCodes[0] = "000 Template"; this->mapCodes[100] = "100 Continue"; this->mapCodes[101] = "101 Switching Protocols"; diff --git a/mandatory/src/WebServer.cpp b/mandatory/src/WebServer.cpp index 6d2bfb4..325db0a 100644 --- a/mandatory/src/WebServer.cpp +++ b/mandatory/src/WebServer.cpp @@ -84,11 +84,9 @@ void WebServer::eventLoop() printLog("NOTICE", "Waiting for events..."); while (!WebServer::ExitFlag) { - // std::cout << "Waiting for events..." << std::endl; num_events = waitEvent(evList); if (num_events == -1) continue ; - // std::cerr << "Event " << num_events << std::endl; for (int i = 0; i < num_events; i++) { #ifdef __APPLE__ @@ -107,13 +105,6 @@ void WebServer::eventLoop() } else if (flag & END_EVENT || flag & ERR_EVENT) { - // std::cout << "END_EVENT" << std::endl; - // for (size_t i = 0; i < this->acceptedSocket.size(); i++) - // { - // int currfd = this->acceptedSocket[i]->getFd(); - // delete acceptedSocket[i]; - // acceptedSocket.erase(currfd); - // } delete acceptedSocket[currfd]; acceptedSocket.erase(currfd); break ; @@ -130,22 +121,12 @@ void WebServer::eventLoop() #endif } else - { - if (i == num_events - 1) - { - // std::cerr << "DELETE 2" << std::endl; - // delete acceptedSocket[currfd]; - // acceptedSocket.erase(currfd); - } continue; - } } else if (type_event == (WRITE_EVENT)) { if (acceptedSocket[currfd]->sendData(currfd)) { - // std::cerr << "DELETE " << currfd << std::endl; - // std::cout << "Curffd " << currfd << std::endl; delete acceptedSocket[currfd]; acceptedSocket.erase(currfd); } @@ -155,8 +136,6 @@ void WebServer::eventLoop() std::cerr << "Unknown event " << type_event << std::endl; } } - // std::cout << "SERVERSOCKET " << serverSocket.size() << std::endl; - // std::cout << "ACCEPTESSOCKER " << acceptedSocket.size() << std::endl; } } diff --git a/mandatory/src/WebServerLNX.cpp b/mandatory/src/WebServerLNX.cpp index 5adb08e..788785d 100644 --- a/mandatory/src/WebServerLNX.cpp +++ b/mandatory/src/WebServerLNX.cpp @@ -40,7 +40,7 @@ void WebServer::modifEvent(struct epoll_event eventList, int type) { // struct epoll_event evSet; - eventList.events = type; // Edge-triggered mode + eventList.events = type; if (epoll_ctl(this->kq, EPOLL_CTL_MOD, eventList.data.fd, &eventList) == -1) { std::cerr << "Error: could not modify event" << std::endl; @@ -67,7 +67,7 @@ void WebServer::removeEventFd(int fd, int type) struct epoll_event ev; (void) type; ev.data.fd = fd; - ev.events = EPOLLONESHOT; // Edge-triggered mode + ev.events = EPOLLONESHOT; if (epoll_ctl(this->kq, EPOLL_CTL_DEL, fd, &ev) == -1) { std::cerr << "Error: could not delete event" << std::endl; @@ -96,7 +96,7 @@ int WebServer::acceptNewEvent(int curfd) else { std::cerr << "Error accepting connection" << std::endl; - return fd; // Continue to the next event + return fd; } } fcntl(fd, F_SETFL, O_NONBLOCK, O_CLOEXEC); diff --git a/mandatory/src/WebservParser.cpp b/mandatory/src/WebservParser.cpp index 36a7aa0..ff18163 100644 --- a/mandatory/src/WebservParser.cpp +++ b/mandatory/src/WebservParser.cpp @@ -111,7 +111,7 @@ bool WebServer::checkSyntax() return true; } -void WebServer::loadConfigFile(std::string filename) // WebServer loadConfigFile +void WebServer::loadConfigFile(std::string filename) { switch (isFilePermissions(filename, R_OK)) { @@ -144,7 +144,7 @@ void WebServer::loadConfigFile(std::string filename) // WebServer loadConfigFile } -void WebServer::processConfigFile() // WebServer processConfigFile +void WebServer::processConfigFile() { std::string aux; size_t pos; diff --git a/mandatory/src/utils.cpp b/mandatory/src/utils.cpp index 6e57e1d..e5e082c 100644 --- a/mandatory/src/utils.cpp +++ b/mandatory/src/utils.cpp @@ -135,35 +135,19 @@ int count_chars(const std::string& str, char c) { return count; } -std::string getTime() -{ - std::time_t currentTime = std::time(NULL); - - // Convert the current time to a string in the desired format - std::tm* timeInfo = std::gmtime(¤tTime); - char buffer[80]; - std::strftime(buffer, sizeof(buffer), "%A, %d-%b-%y %H:%M:%S GMT", timeInfo); - - // Set the date in the header - return(buffer); -}; - std::string getLocalTime() { std::time_t currentTime = std::time(NULL); - // Convert the current time to a string in the desired format using local time std::tm* timeInfo = std::localtime(¤tTime); char buffer[20]; std::strftime(buffer, sizeof(buffer), "%Y/%m/%d %H:%M:%S", timeInfo); - // Return the formatted date string return std::string(buffer); } void printLog(std::string type ,std::string message) { - // std::cout << message << std::endl; if (type == "ERROR") std::cout << CHR_RED << getLocalTime() << " [" << type << "]" << "\t\t" RESET << message << RESET << std::endl; else if (type == "WARNING") @@ -207,29 +191,6 @@ std::string decodeURL(const std::string& url) return decoded; } -// void print_visible(const std::string& str) { -// for (char ch : str) { -// switch (ch) { -// case '\n': -// std::cout << "\\n"; -// break; -// case '\r': -// std::cout << "\\r"; -// break; -// case '\t': -// std::cout << "\\t"; -// break; -// default: -// if (std::isprint(static_cast(ch))) { -// std::cout << ch; -// } else { -// std::cout << "\\x" << std::hex << std::uppercase << static_cast(static_cast(ch)); -// std::cout << std::dec; // Reset to decimal for future use -// } -// } -// } -// } - void replaceFirstString(std::string& mainString, const std::string& searchString, const std::string& replaceString) { size_t pos = 0; if ((pos = mainString.find(searchString, pos)) != std::string::npos) {