From 3b6205979e6fff2d70b52af9d68449a3ff367159 Mon Sep 17 00:00:00 2001 From: psychon Date: Mon, 3 May 2010 13:49:45 +0000 Subject: [PATCH] WebMods: Calculate the module's web path correctly Until now, the code checked for /www/ and just used ./modules/www/ if the other dir didn't exist. Now we calculate the correct path from the module's shared object's path, which is the correct thing to do. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1967 726aef4b-f618-498e-8847-2d620e286838 --- WebModules.cpp | 19 +++++++++++-------- WebModules.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/WebModules.cpp b/WebModules.cpp index d3d9b26a..3e30d586 100644 --- a/WebModules.cpp +++ b/WebModules.cpp @@ -276,7 +276,7 @@ void CWebSock::SetPaths(CModule* pModule, bool bIsTemplate) { // 3. ./modules// // - m_Template.AppendPath(GetModWebPath(sModName)); + m_Template.AppendPath(GetModWebPath(pModule)); // 4. ~/.znc/webskins//mods// // @@ -444,14 +444,17 @@ CWebSock::EPageReqResult CWebSock::PrintTemplate(const CString& sPageName, CStri } } -CString CWebSock::GetModWebPath(const CString& sModName) const { - CString sRet = CZNC::Get().GetCurPath() + "/modules/www/" + sModName; +CString CWebSock::GetModWebPath(const CModule* pModule) const { + // This is: /path/to/module.so + const CString& sModPath = pModule->GetModPath(); - if (!CFile::IsDir(sRet)) { - sRet = CString(_MODDIR_) + "/www/" + sModName; - } + // Find the last '/' in sModPath... + CString::size_type pos = sModPath.find_last_of('/'); - return sRet + "/"; + // ...and set sModDir to the dir in which sModPath resides + CString sModDir = sModPath.substr(0, pos); + + return sModDir + "/www/" + pModule->GetModName(); } CString CWebSock::GetSkinPath(const CString& sSkinName) const { @@ -640,7 +643,7 @@ CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CS if (sURI.Left(10) == "/modfiles/") { m_Template.AppendPath(GetSkinPath(GetSkinName()) + "/mods/" + m_sModName + "/files/"); - m_Template.AppendPath(GetModWebPath(m_sModName) + "/files/"); + m_Template.AppendPath(GetModWebPath(pModule) + "/files/"); std::cerr << "===================== fffffffffffffffffffff [" << m_sModName << "] [" << m_sPage << "]" << std::endl; if (PrintFile(m_Template.ExpandFile(m_sPage.TrimLeft_n("/")))) { diff --git a/WebModules.h b/WebModules.h index f34f4bec..d067dc32 100644 --- a/WebModules.h +++ b/WebModules.h @@ -150,7 +150,7 @@ public: CString GetCSRFCheck(); virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort); - CString GetModWebPath(const CString& sModName) const; + CString GetModWebPath(const CModule* pModule) const; CString GetSkinPath(const CString& sSkinName) const; CModule* GetModule() const { return (CModule*) m_pModule; } size_t GetAvailSkins(vector& vRet);