From: <ps...@us...> - 2010-03-15 15:58:23
|
Revision: 1833 http://znc.svn.sourceforge.net/znc/?rev=1833&view=rev Author: psychon Date: 2010-03-15 15:58:15 +0000 (Mon, 15 Mar 2010) Log Message: ----------- Change the return type of OnPageRequestInternal() Instead of return a bool, this now returns an enum. This explains the meaning of the returned value better and will be used in the next commit to fix a bug. Modified Paths: -------------- trunk/WebModules.cpp trunk/WebModules.h Modified: trunk/WebModules.cpp =================================================================== --- trunk/WebModules.cpp 2010-03-15 15:43:22 UTC (rev 1832) +++ trunk/WebModules.cpp 2010-03-15 15:58:15 UTC (rev 1833) @@ -412,13 +412,17 @@ return false; } -bool CWebSock::PrintStaticFile(const CString& sPath, CString& sPageRet, CModule* pModule) { +CWebSock::EPageReqResult CWebSock::PrintStaticFile(const CString& sPath, CString& sPageRet, CModule* pModule) { SetPaths(pModule); DEBUG("About to print [" + m_Template.ExpandFile(sPath) + "]"); - return PrintFile(m_Template.ExpandFile(sPath.TrimLeft_n("/"))); + if (PrintFile(m_Template.ExpandFile(sPath.TrimLeft_n("/")))) { + return PAGE_PRINT; + } else { + return PAGE_NOTFOUND; + } } -bool CWebSock::PrintTemplate(const CString& sPageName, CString& sPageRet, CModule* pModule) { +CWebSock::EPageReqResult CWebSock::PrintTemplate(const CString& sPageName, CString& sPageRet, CModule* pModule) { SetVars(); m_Template["PageName"] = sPageName; @@ -437,10 +441,14 @@ } if (m_Template.GetFileName().empty() && !m_Template.SetFile(sPageName + ".tmpl")) { - return false; + return PAGE_NOTFOUND; } - return m_Template.PrintString(sPageRet); + if (m_Template.PrintString(sPageRet)) { + return PAGE_PRINT; + } else { + return PAGE_NOTFOUND; + } } CString CWebSock::GetModWebPath(const CString& sModName) const { @@ -495,14 +503,18 @@ void CWebSock::OnPageRequest(const CString& sURI) { CString sPageRet; - if (OnPageRequestInternal(sURI, sPageRet)) { + EPageReqResult eRet = OnPageRequestInternal(sURI, sPageRet); + switch (eRet) { + case PAGE_PRINT: PrintPage(sPageRet); - } else { + break; + default: PrintNotFound(); + break; } } -bool CWebSock::OnPageRequestInternal(const CString& sURI, CString& sPageRet) { +CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CString& sPageRet) { DEBUG("CWebSock::OnPageRequest(" + sURI + ")"); m_spSession = GetSession(); SetCookie("SessionId", m_spSession->GetId()); @@ -522,7 +534,7 @@ SetLoggedIn(false); Redirect("/"); - return true; + return PAGE_PRINT; } else if (sURI == "/login" || sURI.Left(7) == "/login/") { if (GetParam("submitted").ToBool()) { m_sUser = GetParam("user"); @@ -530,7 +542,7 @@ m_bLoggedIn = OnLogin(m_sUser, m_sPass); Redirect("/"); - return true; + return PAGE_PRINT; } return PrintTemplate("login", sPageRet); @@ -541,7 +553,7 @@ // Make sure modules are treated as directories if (sURI.Right(1) != "/" && sURI.find(".") == CString::npos && sURI.TrimLeft_n("/mods/").TrimLeft_n("/").find("/") == CString::npos) { Redirect(sURI + "/"); - return true; + return PAGE_PRINT; } if (m_sModName.empty()) { @@ -553,22 +565,22 @@ if (!pModule && m_sForceUser.empty()) { if (!ForceLogin()) { - return true; + return PAGE_PRINT; } pModule = CZNC::Get().FindModule(m_sModName, m_spSession->GetUser()); } if (!pModule) { - return false; + return PAGE_NOTFOUND; } else if (pModule->WebRequiresLogin() && !ForceLogin()) { - return true; + return PAGE_PRINT; } else if (pModule->WebRequiresAdmin() && !m_spSession->IsAdmin()) { sPageRet = GetErrorPage(403, "Forbidden", "You need to be an admin to access this module"); - return true; + return PAGE_PRINT; } else if (pModule && !pModule->IsGlobal() && pModule->GetUser() != m_spSession->GetUser()) { sPageRet = GetErrorPage(403, "Forbidden", "You must login as " + pModule->GetUser()->GetUserName() + " in order to view this page"); - return true; + return PAGE_PRINT; } VWebSubPages& vSubPages = pModule->GetSubPages(); @@ -580,7 +592,7 @@ if (bActive && SubPage->RequiresAdmin() && !m_spSession->IsAdmin()) { sPageRet = GetErrorPage(403, "Forbidden", "You need to be an admin to access this page"); - return true; + return PAGE_PRINT; } } @@ -593,7 +605,11 @@ m_Template.AppendPath(GetModWebPath(m_sModName) + "/files/"); std::cerr << "===================== fffffffffffffffffffff [" << m_sModName << "] [" << m_sPage << "]" << std::endl; - return PrintFile(m_Template.ExpandFile(m_sPage.TrimLeft_n("/"))); + if (PrintFile(m_Template.ExpandFile(m_sPage.TrimLeft_n("/")))) { + return PAGE_PRINT; + } else { + return PAGE_NOTFOUND; + } } else { SetPaths(pModule, true); @@ -602,7 +618,7 @@ } sPageRet = GetErrorPage(404, "Not Implemented", "The requested module does not acknowledge web requests"); - return false; + return PAGE_PRINT; } } else { CString sPage(sURI.Trim_n("/")); @@ -611,7 +627,7 @@ unsigned char c = sPage[a]; if ((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_') { - return false; + return PAGE_NOTFOUND; } } @@ -619,7 +635,7 @@ } } - return false; + return PAGE_NOTFOUND; } void CWebSock::PrintErrorPage(const CString& sMessage) { Modified: trunk/WebModules.h =================================================================== --- trunk/WebModules.h 2010-03-15 15:43:22 UTC (rev 1832) +++ trunk/WebModules.h 2010-03-15 15:58:15 UTC (rev 1833) @@ -112,6 +112,11 @@ class CWebSock : public CHTTPSock { public: + enum EPageReqResult { + PAGE_NOTFOUND, + PAGE_PRINT + }; + CWebSock(CModule* pModule); CWebSock(CModule* pModule, const CString& sHostname, unsigned short uPort, int iTimeout = 60); virtual ~CWebSock(); @@ -124,8 +129,8 @@ CModule* ResolveModule(); //virtual bool PrintFile(const CString& sFileName, CString sContentType = ""); - bool PrintTemplate(const CString& sPageName, CString& sPageRet, CModule* pModule = NULL); - bool PrintStaticFile(const CString& sPath, CString& sPageRet, CModule* pModule = NULL); + EPageReqResult PrintTemplate(const CString& sPageName, CString& sPageRet, CModule* pModule = NULL); + EPageReqResult PrintStaticFile(const CString& sPath, CString& sPageRet, CModule* pModule = NULL); bool AddModLoop(const CString& sLoopName, CModule& Module); void SetPaths(CModule* pModule, bool bIsTemplate = false); @@ -158,7 +163,7 @@ } private: - bool OnPageRequestInternal(const CString& sURI, CString& sPageRet); + EPageReqResult OnPageRequestInternal(const CString& sURI, CString& sPageRet); bool m_bPathsSet; CTemplate m_Template; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |