Remove CHTTPSock::GetErrorPage()

There is no valid reason to use GetErrorPage() instead of PrintErrorPage() which
can be seen from the fact that all the existing callers are *wrong*. So, to
avoid this mistake in the future, inline GetErrorPage() into its only valid
caller (PrintErrorPage()).


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2040 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2010-06-22 15:26:17 +00:00
parent 6d16047113
commit 9ff7a3d05e
2 changed files with 10 additions and 19 deletions
+10 -18
View File
@@ -403,21 +403,19 @@ bool CHTTPSock::PrintErrorPage(unsigned int uStatusId, const CString& sStatusMsg
return false;
}
CString sPage = GetErrorPage(uStatusId, sStatusMsg, sMessage);
PrintHeader(sPage.length(), "text/html", uStatusId, sStatusMsg);
Write(sPage);
Close(Csock::CLT_AFTERWRITE);
return true;
}
CString CHTTPSock::GetErrorPage(unsigned int uStatusId, const CString& sStatusMsg, const CString& sMessage) {
return "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
CString sPage =
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
"<html><head>\r\n<title>" + CString(uStatusId) + " " + sStatusMsg.Escape_n(CString::EHTML) + "</title>\r\n"
"</head><body>\r\n<h1>" + sStatusMsg.Escape_n(CString::EHTML) + "</h1>\r\n"
"<p>" + sMessage.Escape_n(CString::EHTML) + "</p>\r\n"
"<hr />\r\n<address>" + CZNC::GetTag(false).Escape_n(CString::EHTML) + " at " + GetLocalIP().Escape_n(CString::EHTML) + " Port " + CString(GetLocalPort()) + "</address>\r\n"
"</body></html>\r\n";
PrintHeader(sPage.length(), "text/html", uStatusId, sStatusMsg);
Write(sPage);
Close(Csock::CLT_AFTERWRITE);
return true;
}
bool CHTTPSock::ForceLogin() {
@@ -430,11 +428,8 @@ bool CHTTPSock::ForceLogin() {
return false;
}
CString sPage = GetErrorPage(401, "Unauthorized", "You need to login to view this page.");
AddHeader("WWW-Authenticate", "Basic realm=\"" + CZNC::GetTag(false) + "\"");
PrintHeader(sPage.length(), "text/html", 401, "Unauthorized");
Write(sPage);
Close(Csock::CLT_AFTERWRITE);
PrintErrorPage(401, "Unauthorized", "You need to login to view this page.");
return false;
}
@@ -504,11 +499,8 @@ bool CHTTPSock::Redirect(const CString& sURL) {
}
DEBUG("- Redirect to [" << sURL << "]");
CString sPage = GetErrorPage(302, "Found", "The document has moved <a href=\"" + sURL.Escape_n(CString::EHTML) + "\">here</a>.");
AddHeader("Location", sURL);
PrintHeader(sPage.length(), "text/html", 302, "Found");
Write(sPage);
Close(Csock::CLT_AFTERWRITE);
PrintErrorPage(302, "Found", "The document has moved <a href=\"" + sURL.Escape_n(CString::EHTML) + "\">here</a>.");
return true;
}
-1
View File
@@ -45,7 +45,6 @@ public:
bool PrintNotFound();
bool Redirect(const CString& sURL);
CString GetErrorPage(unsigned int uStatusId, const CString& sStatusMsg, const CString& sMessage);
bool PrintErrorPage(unsigned int uStatusId, const CString& sStatusMsg, const CString& sMessage);
static void ParseParams(const CString& sParams, map<CString, VCString>& msvsParams);
void ParseURI();