Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merging Change-cgi-in-all-Location to main. Added personalized pages when template error_page and template list dir files ar not found #44

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mandatory/inc/ListDir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
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;
}
Loading