From 64b0e392fe4624a7dfcd2ecd712cb6c34d3fb640 Mon Sep 17 00:00:00 2001 From: psychon Date: Sun, 23 Aug 2009 14:11:37 +0000 Subject: [PATCH] Add CModules::GetModPathInfo() This function works like GetModInfo(), but takes the full path to the module, too. This is used to speed up GetAvailableMods(). Before it created a list of module paths, extracted the names and then called GetModInfo() on those module names which looked up the path for the modules again. This extra step is now skipped and the module's path is used directly. To make this work, the call to FindModPath() was moved from OpenModule() into its two callers LoadModule() and GetModInfo(). git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1613 726aef4b-f618-498e-8847-2d620e286838 --- Modules.cpp | 32 ++++++++++++++++++++++---------- Modules.h | 3 ++- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Modules.cpp b/Modules.cpp index 5f9374e4..eea54896 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -734,7 +734,13 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p CString sDesc; bool bVersionMismatch; bool bIsGlobal; - ModHandle p = OpenModule(sModule, sModPath, sDataPath, bVersionMismatch, bIsGlobal, sDesc, sRetMsg); + + if (!FindModPath(sModule, sModPath, sDataPath)) { + sRetMsg = "Unable to find module [" + sModule + "]"; + return false; + } + + ModHandle p = OpenModule(sModule, sModPath, bVersionMismatch, bIsGlobal, sDesc, sRetMsg); if (!p) return false; @@ -886,11 +892,21 @@ bool CModules::ReloadModule(const CString& sModule, const CString& sArgs, CUser* bool CModules::GetModInfo(CModInfo& ModInfo, const CString& sModule, CString& sRetMsg) { CString sModPath, sTmp; + + if (!FindModPath(sModule, sModPath, sTmp)) { + sRetMsg = "Unable to find module [" + sModule + "]"; + return false; + } + + return GetModPathInfo(ModInfo, sModule, sModPath, sRetMsg); +} + +bool CModules::GetModPathInfo(CModInfo& ModInfo, const CString& sModule, const CString& sModPath, CString& sRetMsg) { CString sDesc; bool bVersionMismatch; bool bIsGlobal; - ModHandle p = OpenModule(sModule, sModPath, sTmp, bVersionMismatch, bIsGlobal, sDesc, sRetMsg); + ModHandle p = OpenModule(sModule, sModPath, bVersionMismatch, bIsGlobal, sDesc, sRetMsg); if (!p) return false; @@ -924,11 +940,12 @@ void CModules::GetAvailableMods(set& ssMods, bool bGlobal) { for (a = 0; a < Dir.size(); a++) { CFile& File = *Dir[a]; CString sName = File.GetShortName(); + CString sPath = File.GetLongName(); CModInfo ModInfo; sName.RightChomp(3); CString sIgnoreRetMsg; - if (GetModInfo(ModInfo, sName, sIgnoreRetMsg)) { + if (GetModPathInfo(ModInfo, sName, sPath, sIgnoreRetMsg)) { if (ModInfo.IsGlobal() == bGlobal) { ssMods.insert(ModInfo); } @@ -981,8 +998,8 @@ CModules::ModDirList CModules::GetModDirs() { return ret; } -ModHandle CModules::OpenModule(const CString& sModule, CString& sModPath, CString& sDataPath, - bool &bVersionMismatch, bool &bIsGlobal, CString& sDesc, CString& sRetMsg) { +ModHandle CModules::OpenModule(const CString& sModule, const CString& sModPath, 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."; @@ -990,11 +1007,6 @@ ModHandle CModules::OpenModule(const CString& sModule, CString& sModPath, CStrin } } - if (!FindModPath(sModule, sModPath, sDataPath)) { - sRetMsg = "Unable to find module [" + sModule + "]"; - return NULL; - } - ModHandle p = dlopen((sModPath).c_str(), RTLD_NOW | RTLD_LOCAL); if (!p) { diff --git a/Modules.h b/Modules.h index 093be091..35d1aca1 100644 --- a/Modules.h +++ b/Modules.h @@ -462,6 +462,7 @@ public: bool ReloadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg); bool GetModInfo(CModInfo& ModInfo, const CString& sModule, CString &sRetMsg); + bool GetModPathInfo(CModInfo& ModInfo, const CString& sModule, const CString& sModPath, CString &sRetMsg); void GetAvailableMods(set& ssMods, bool bGlobal = false); // This returns the path to the .so and to the data dir @@ -474,7 +475,7 @@ public: static ModDirList GetModDirs(); private: - ModHandle OpenModule(const CString& sModule, CString& sModPath, CString& sDataPath, + ModHandle OpenModule(const CString& sModule, const CString& sModPath, bool &bVersionMismatch, bool &bIsGlobal, CString& sDesc, CString& sRetMsg); protected: