Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Cheel nakashima committed Jul 4, 2024
2 parents 28f6165 + 2864ae7 commit 0cae3ca
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
3 changes: 2 additions & 1 deletion mandatory/inc/StatusCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: eavedill <eavedill@student.42barcelona> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -37,4 +37,5 @@ class StatusCode {
void setCurrentCode(int);
int getCurrentCode();
void loadErrorPageFromDir(const ExtendedString &);
ExtendedString getInternContent();
};
20 changes: 19 additions & 1 deletion mandatory/src/ListDir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ void ListDir::setContentToList()
{
contentToSend = "";
char buffer[MAX_SENT_BYTES];
if (!isFileOpen)
{
contentToSend = "<html>\n";
contentToSend += "<head>\n";
contentToSend += "<title> List Directory Error</title>\n";
contentToSend += "</head>\n";
contentToSend += "<body>\n";
contentToSend += "<table border = \"0\" cellspacing = \"2\">\n";
contentToSend += "<tr><td><h2>List directory template not found</h2></td></tr>\n";
contentToSend += "<tr><td><h4>Please generate the file ./templates/dir_list.html or define it on ListDir.hpp</h4></td></tr>\n";
contentToSend += "</table>\n";
contentToSend += "</body>\n";
contentToSend += "</html>\n";
isFileOpen = true;
return ;
}
while(file.read(buffer, MAX_SENT_BYTES))
{
contentToSend.append(buffer, file.gcount());
Expand Down Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions mandatory/src/StatusCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* StatusCode.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eavedill <eavedill@student.42.fr> +#+ +:+ +#+ */
/* By: eavedill <eavedill@student.42barcelona> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -139,4 +140,22 @@ void StatusCode::loadErrorPageFromDir(const ExtendedString &dir)
}
}
closedir(dp);
}

ExtendedString StatusCode::getInternContent()
{
ExtendedString content;
content = "<html>\n";
content += "<head>\n";
content += "<title> {{ErrorCode}}</title>\n";
content += "</head>\n";
content += "<body>\n";
content += "<table border = \"0\" cellspacing = \"2\">\n";
content += "<tr><td><h2>This is an internal text defined.</h2></td></tr>\n";
content += "<tr><td><h4>{{ErrorCode}}.<h4></td></tr>\n";
content += "<tr><td><h5>Please generate the file ./templates/error_template.html or define it on statusCodesDefinition.hpp</h5></td></tr>\n";
content += "</table>\n";
content += "</body>\n";
content += "</html>\n";
return content;
}

0 comments on commit 0cae3ca

Please sign in to comment.