From 210de713fbc40c8577437cd028854b6a8c161294 Mon Sep 17 00:00:00 2001 From: eavedill Date: Thu, 4 Jul 2024 07:39:28 +0200 Subject: [PATCH 1/2] Siimple intern error htlm file generated --- mandatory/inc/StatusCode.hpp | 3 ++- mandatory/src/StatusCode.cpp | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/mandatory/inc/StatusCode.hpp b/mandatory/inc/StatusCode.hpp index 2b7eb5d..b7c848e 100644 --- a/mandatory/inc/StatusCode.hpp +++ b/mandatory/inc/StatusCode.hpp @@ -6,7 +6,7 @@ /* By: eavedill +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/30 13:49:24 by eavedill #+# #+# */ -/* Updated: 2024/06/30 13:49:24 by eavedill ### ########.fr */ +/* Updated: 2024/07/04 07:19:29 by eavedill ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,4 +37,5 @@ class StatusCode { void setCurrentCode(int); int getCurrentCode(); void loadErrorPageFromDir(const ExtendedString &); + ExtendedString getInternContent(); }; \ No newline at end of file diff --git a/mandatory/src/StatusCode.cpp b/mandatory/src/StatusCode.cpp index 7a13dfd..0a8152b 100644 --- a/mandatory/src/StatusCode.cpp +++ b/mandatory/src/StatusCode.cpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* StatusCode.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: eavedill +#+ +:+ +#+ */ +/* By: eavedill +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/30 13:51:07 by eavedill #+# #+# */ -/* Updated: 2024/06/30 15:15:28 by eavedill ### ########.fr */ +/* Updated: 2024/07/04 07:37:03 by eavedill ### ########.fr */ /* */ /* ************************************************************************** */ @@ -86,6 +86,7 @@ void StatusCode::setFileContentForStatusCode(int CodeNumber, const std::string & } else { + content = this->getInternContent(); printLog("WARNING", CodeFileContent + " File does not exist.\t Set error page to default " CHR_GREEN "GET" RESET " value"); } mapCodesFileContent[CodeNumber] = content; @@ -139,4 +140,22 @@ void StatusCode::loadErrorPageFromDir(const ExtendedString &dir) } } closedir(dp); +} + +ExtendedString StatusCode::getInternContent() +{ + ExtendedString content; + content = "\n"; + content += "\n"; + content += " {{ErrorCode}}\n"; + content += "\n"; + content += "\n"; + content += "\n"; + content += "\n"; + content += "\n"; + content += "\n"; + content += "
This is an internal text defined.
{{ErrorCode}}.
Please generate the file ./Templates/ErrorTemplate.html
<\n"; + content += "\n"; + content += "\n"; + return content; } \ No newline at end of file From 5cc3876aa4658a349393e2cd1ef7df6419942dce Mon Sep 17 00:00:00 2001 From: Joseph Cheel nakashima Date: Thu, 4 Jul 2024 17:10:06 +0200 Subject: [PATCH 2/2] Added special page to lisdir template not found --- mandatory/inc/ListDir.hpp | 2 +- mandatory/src/ListDir.cpp | 20 +++++++++++++++++++- mandatory/src/StatusCode.cpp | 8 ++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/mandatory/inc/ListDir.hpp b/mandatory/inc/ListDir.hpp index d3b5ccd..992bbce 100644 --- a/mandatory/inc/ListDir.hpp +++ b/mandatory/inc/ListDir.hpp @@ -20,7 +20,7 @@ #include "Attributes.hpp" #include "utils.hpp" #include "colors.h" -#define TEMPLATE_LIST_DIR "./Templates/dir_list.html" +#define TEMPLATE_LIST_DIR "./templates/dir_list.html" class ListDir { diff --git a/mandatory/src/ListDir.cpp b/mandatory/src/ListDir.cpp index d1d5b75..378dd65 100644 --- a/mandatory/src/ListDir.cpp +++ b/mandatory/src/ListDir.cpp @@ -97,6 +97,22 @@ void ListDir::setContentToList() { contentToSend = ""; char buffer[MAX_SENT_BYTES]; + if (!isFileOpen) + { + contentToSend = "\n"; + contentToSend += "\n"; + contentToSend += " List Directory Error\n"; + contentToSend += "\n"; + contentToSend += "\n"; + contentToSend += "\n"; + contentToSend += "\n"; + contentToSend += "\n"; + contentToSend += "

List directory template not found

Please generate the file ./templates/dir_list.html or define it on ListDir.hpp

\n"; + contentToSend += "\n"; + contentToSend += "\n"; + isFileOpen = true; + return ; + } while(file.read(buffer, MAX_SENT_BYTES)) { contentToSend.append(buffer, file.gcount()); @@ -135,7 +151,9 @@ void ListDir::openMasterListFile() std::string ListDir::getContentToSend() { - std::string subStrToSend = contentToSend.substr(posToSend, MAX_SENT_BYTES); + std::string subStrToSend; + subStrToSend = contentToSend.substr(posToSend, MAX_SENT_BYTES); + if(posToSend + MAX_SENT_BYTES >= contentToSend.size()) posToSend = contentToSend.size(); else diff --git a/mandatory/src/StatusCode.cpp b/mandatory/src/StatusCode.cpp index 0a8152b..92e76ab 100644 --- a/mandatory/src/StatusCode.cpp +++ b/mandatory/src/StatusCode.cpp @@ -151,10 +151,10 @@ ExtendedString StatusCode::getInternContent() content += "\n"; content += "\n"; content += "\n"; - content += "\n"; - content += "\n"; - content += "\n"; - content += "
This is an internal text defined.
{{ErrorCode}}.
Please generate the file ./Templates/ErrorTemplate.html
<\n"; + content += "

This is an internal text defined.

\n"; + content += "

{{ErrorCode}}.

\n"; + content += "

Please generate the file ./templates/error_template.html or define it on statusCodesDefinition.hpp
\n"; + content += "\n"; content += "\n"; content += "\n"; return content;