Skip to content

Commit 0cae3ca

Browse files
author
Joseph Cheel nakashima
committed
2 parents 28f6165 + 2864ae7 commit 0cae3ca

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

mandatory/inc/StatusCode.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: eavedill <eavedill@student.42barcelona> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/06/30 13:49:24 by eavedill #+# #+# */
9-
/* Updated: 2024/06/30 13:49:24 by eavedill ### ########.fr */
9+
/* Updated: 2024/07/04 07:19:29 by eavedill ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -37,4 +37,5 @@ class StatusCode {
3737
void setCurrentCode(int);
3838
int getCurrentCode();
3939
void loadErrorPageFromDir(const ExtendedString &);
40+
ExtendedString getInternContent();
4041
};

mandatory/src/ListDir.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ void ListDir::setContentToList()
9797
{
9898
contentToSend = "";
9999
char buffer[MAX_SENT_BYTES];
100+
if (!isFileOpen)
101+
{
102+
contentToSend = "<html>\n";
103+
contentToSend += "<head>\n";
104+
contentToSend += "<title> List Directory Error</title>\n";
105+
contentToSend += "</head>\n";
106+
contentToSend += "<body>\n";
107+
contentToSend += "<table border = \"0\" cellspacing = \"2\">\n";
108+
contentToSend += "<tr><td><h2>List directory template not found</h2></td></tr>\n";
109+
contentToSend += "<tr><td><h4>Please generate the file ./templates/dir_list.html or define it on ListDir.hpp</h4></td></tr>\n";
110+
contentToSend += "</table>\n";
111+
contentToSend += "</body>\n";
112+
contentToSend += "</html>\n";
113+
isFileOpen = true;
114+
return ;
115+
}
100116
while(file.read(buffer, MAX_SENT_BYTES))
101117
{
102118
contentToSend.append(buffer, file.gcount());
@@ -135,7 +151,9 @@ void ListDir::openMasterListFile()
135151

136152
std::string ListDir::getContentToSend()
137153
{
138-
std::string subStrToSend = contentToSend.substr(posToSend, MAX_SENT_BYTES);
154+
std::string subStrToSend;
155+
subStrToSend = contentToSend.substr(posToSend, MAX_SENT_BYTES);
156+
139157
if(posToSend + MAX_SENT_BYTES >= contentToSend.size())
140158
posToSend = contentToSend.size();
141159
else

mandatory/src/StatusCode.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/* ::: :::::::: */
44
/* StatusCode.cpp :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: eavedill <eavedill@student.42.fr> +#+ +:+ +#+ */
6+
/* By: eavedill <eavedill@student.42barcelona> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/06/30 13:51:07 by eavedill #+# #+# */
9-
/* Updated: 2024/06/30 15:15:28 by eavedill ### ########.fr */
9+
/* Updated: 2024/07/04 07:37:03 by eavedill ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -86,6 +86,7 @@ void StatusCode::setFileContentForStatusCode(int CodeNumber, const std::string &
8686
}
8787
else
8888
{
89+
content = this->getInternContent();
8990
printLog("WARNING", CodeFileContent + " File does not exist.\t Set error page to default " CHR_GREEN "GET" RESET " value");
9091
}
9192
mapCodesFileContent[CodeNumber] = content;
@@ -139,4 +140,22 @@ void StatusCode::loadErrorPageFromDir(const ExtendedString &dir)
139140
}
140141
}
141142
closedir(dp);
143+
}
144+
145+
ExtendedString StatusCode::getInternContent()
146+
{
147+
ExtendedString content;
148+
content = "<html>\n";
149+
content += "<head>\n";
150+
content += "<title> {{ErrorCode}}</title>\n";
151+
content += "</head>\n";
152+
content += "<body>\n";
153+
content += "<table border = \"0\" cellspacing = \"2\">\n";
154+
content += "<tr><td><h2>This is an internal text defined.</h2></td></tr>\n";
155+
content += "<tr><td><h4>{{ErrorCode}}.<h4></td></tr>\n";
156+
content += "<tr><td><h5>Please generate the file ./templates/error_template.html or define it on statusCodesDefinition.hpp</h5></td></tr>\n";
157+
content += "</table>\n";
158+
content += "</body>\n";
159+
content += "</html>\n";
160+
return content;
142161
}

0 commit comments

Comments
 (0)