From ab9e2dfd33c21d3bfddc6367aa313a6ea0b267ce Mon Sep 17 00:00:00 2001 From: psychon Date: Sun, 23 Aug 2009 12:46:47 +0000 Subject: [PATCH] Add CModules::GetModDirs() This function returns a list of pairs which lists all places in which modules should be looked for. FindModPath() and GetAvailableMods() are changed to use this new function. The list of places to look at is the same that was used before, but this now also adds ./modules/extra so that modules enabled via --enable-extra are found before 'make install'. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1612 726aef4b-f618-498e-8847-2d620e286838 --- Modules.cpp | 99 ++++++++++++++++++++++++----------------------------- Modules.h | 5 +++ 2 files changed, 49 insertions(+), 55 deletions(-) diff --git a/Modules.cpp b/Modules.cpp index 9052c55d..5f9374e4 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -915,47 +915,23 @@ void CModules::GetAvailableMods(set& ssMods, bool bGlobal) { unsigned int a = 0; CDir Dir; - Dir.FillByWildcard(CZNC::Get().GetCurPath() + "/modules", "*.so"); - for (a = 0; a < Dir.size(); a++) { - CFile& File = *Dir[a]; - CString sName = File.GetShortName(); - CModInfo ModInfo; - sName.RightChomp(3); + ModDirList dirs = GetModDirs(); - CString sIgnoreRetMsg; - if (GetModInfo(ModInfo, sName, sIgnoreRetMsg)) { - if (ModInfo.IsGlobal() == bGlobal) { - ssMods.insert(ModInfo); - } - } - } + while (!dirs.empty()) { + Dir.FillByWildcard(dirs.top().first, "*.so"); + dirs.pop(); - Dir.FillByWildcard(CZNC::Get().GetModPath(), "*.so"); - for (a = 0; a < Dir.size(); a++) { - CFile& File = *Dir[a]; - CString sName = File.GetShortName(); - CModInfo ModInfo; - sName.RightChomp(3); + for (a = 0; a < Dir.size(); a++) { + CFile& File = *Dir[a]; + CString sName = File.GetShortName(); + CModInfo ModInfo; + sName.RightChomp(3); - CString sIgnoreRetMsg; - if (GetModInfo(ModInfo, sName, sIgnoreRetMsg)) { - if (ModInfo.IsGlobal() == bGlobal) { - ssMods.insert(ModInfo); - } - } - } - - Dir.FillByWildcard(_MODDIR_, "*.so"); - for (a = 0; a < Dir.size(); a++) { - CFile& File = *Dir[a]; - CString sName = File.GetShortName(); - CModInfo ModInfo; - sName.RightChomp(3); - - CString sIgnoreRetMsg; - if (GetModInfo(ModInfo, sName, sIgnoreRetMsg)) { - if (ModInfo.IsGlobal() == bGlobal) { - ssMods.insert(ModInfo); + CString sIgnoreRetMsg; + if (GetModInfo(ModInfo, sName, sIgnoreRetMsg)) { + if (ModInfo.IsGlobal() == bGlobal) { + ssMods.insert(ModInfo); + } } } } @@ -968,32 +944,45 @@ bool CModules::FindModPath(const CString& sModule, CString& sModPath, if (sModule.find(".") == CString::npos) sMod += ".so"; - sDataPath = CZNC::Get().GetCurPath() + "/modules/"; - sModPath = sDataPath + sMod; + ModDirList dirs = GetModDirs(); - if (!CFile::Exists(sModPath)) { - sDataPath = CZNC::Get().GetModPath() + "/"; - sModPath = sDataPath + sMod; + while (!dirs.empty()) { + sModPath = dirs.top().first + sMod; + sDataPath = dirs.top().second; + dirs.pop(); - if (!CFile::Exists(sModPath)) { - sDataPath = _DATADIR_ + CString("/"); - sModPath = _MODDIR_ + CString("/") + sMod; - - if (!CFile::Exists(sModPath)) { - return false; - } + if (CFile::Exists(sModPath)) { + sDataPath += sDir; + return true; } } - sDataPath += sDir; - - return true; + return false; } +CModules::ModDirList CModules::GetModDirs() { + ModDirList ret; + + // ./modules + CString sDir = CZNC::Get().GetCurPath() + "/modules/"; + ret.push(std::make_pair(sDir, sDir)); + + // ./modules/extra + sDir = CZNC::Get().GetCurPath() + "/modules/extra/"; + ret.push(std::make_pair(sDir, sDir)); + + // ~/.znc/modules + sDir = CZNC::Get().GetModPath() + "/"; + ret.push(std::make_pair(sDir, sDir)); + + // and (/lib/znc) + ret.push(std::make_pair(_MODDIR_ + CString("/"), _DATADIR_ + CString("/"))); + + return ret; +} ModHandle CModules::OpenModule(const CString& sModule, CString& sModPath, CString& sDataPath, - bool &bVersionMismatch, bool &bIsGlobal, CString& sDesc, CString& sRetMsg) -{ + bool &bVersionMismatch, bool &bIsGlobal, CString& sDesc, CString& sRetMsg) { for (unsigned int a = 0; a < sModule.length(); a++) { if (((sModule[a] < '0') || (sModule[a] > '9')) && ((sModule[a] < 'a') || (sModule[a] > 'z')) && ((sModule[a] < 'A') || (sModule[a] > 'Z')) && (sModule[a] != '_')) { sRetMsg = "Module names can only contain letters, numbers and underscores, [" + sModule + "] is invalid."; diff --git a/Modules.h b/Modules.h index c375c745..093be091 100644 --- a/Modules.h +++ b/Modules.h @@ -15,6 +15,7 @@ #include "Utils.h" #include #include +#include using std::vector; using std::set; @@ -467,6 +468,10 @@ public: // which is where static data (webadmin skins) are saved static bool FindModPath(const CString& sModule, CString& sModPath, CString& sDataPath); + // Return a list of pairs for directories in + // which modules can be found. + typedef std::stack > ModDirList; + static ModDirList GetModDirs(); private: ModHandle OpenModule(const CString& sModule, CString& sModPath, CString& sDataPath,