mirror of
https://github.com/znc/znc.git
synced 2026-08-07 01:13:25 +02:00
Add CModules::GetModDirs()
This function returns a list of <module dir, data dir> 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
This commit is contained in:
+44
-55
@@ -915,47 +915,23 @@ void CModules::GetAvailableMods(set<CModInfo>& ssMods, bool bGlobal) {
|
|||||||
unsigned int a = 0;
|
unsigned int a = 0;
|
||||||
CDir Dir;
|
CDir Dir;
|
||||||
|
|
||||||
Dir.FillByWildcard(CZNC::Get().GetCurPath() + "/modules", "*.so");
|
ModDirList dirs = GetModDirs();
|
||||||
for (a = 0; a < Dir.size(); a++) {
|
|
||||||
CFile& File = *Dir[a];
|
|
||||||
CString sName = File.GetShortName();
|
|
||||||
CModInfo ModInfo;
|
|
||||||
sName.RightChomp(3);
|
|
||||||
|
|
||||||
CString sIgnoreRetMsg;
|
while (!dirs.empty()) {
|
||||||
if (GetModInfo(ModInfo, sName, sIgnoreRetMsg)) {
|
Dir.FillByWildcard(dirs.top().first, "*.so");
|
||||||
if (ModInfo.IsGlobal() == bGlobal) {
|
dirs.pop();
|
||||||
ssMods.insert(ModInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Dir.FillByWildcard(CZNC::Get().GetModPath(), "*.so");
|
for (a = 0; a < Dir.size(); a++) {
|
||||||
for (a = 0; a < Dir.size(); a++) {
|
CFile& File = *Dir[a];
|
||||||
CFile& File = *Dir[a];
|
CString sName = File.GetShortName();
|
||||||
CString sName = File.GetShortName();
|
CModInfo ModInfo;
|
||||||
CModInfo ModInfo;
|
sName.RightChomp(3);
|
||||||
sName.RightChomp(3);
|
|
||||||
|
|
||||||
CString sIgnoreRetMsg;
|
CString sIgnoreRetMsg;
|
||||||
if (GetModInfo(ModInfo, sName, sIgnoreRetMsg)) {
|
if (GetModInfo(ModInfo, sName, sIgnoreRetMsg)) {
|
||||||
if (ModInfo.IsGlobal() == bGlobal) {
|
if (ModInfo.IsGlobal() == bGlobal) {
|
||||||
ssMods.insert(ModInfo);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -968,32 +944,45 @@ bool CModules::FindModPath(const CString& sModule, CString& sModPath,
|
|||||||
if (sModule.find(".") == CString::npos)
|
if (sModule.find(".") == CString::npos)
|
||||||
sMod += ".so";
|
sMod += ".so";
|
||||||
|
|
||||||
sDataPath = CZNC::Get().GetCurPath() + "/modules/";
|
ModDirList dirs = GetModDirs();
|
||||||
sModPath = sDataPath + sMod;
|
|
||||||
|
|
||||||
if (!CFile::Exists(sModPath)) {
|
while (!dirs.empty()) {
|
||||||
sDataPath = CZNC::Get().GetModPath() + "/";
|
sModPath = dirs.top().first + sMod;
|
||||||
sModPath = sDataPath + sMod;
|
sDataPath = dirs.top().second;
|
||||||
|
dirs.pop();
|
||||||
|
|
||||||
if (!CFile::Exists(sModPath)) {
|
if (CFile::Exists(sModPath)) {
|
||||||
sDataPath = _DATADIR_ + CString("/");
|
sDataPath += sDir;
|
||||||
sModPath = _MODDIR_ + CString("/") + sMod;
|
return true;
|
||||||
|
|
||||||
if (!CFile::Exists(sModPath)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sDataPath += sDir;
|
return false;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
// <moduledir> and <datadir> (<prefix>/lib/znc)
|
||||||
|
ret.push(std::make_pair(_MODDIR_ + CString("/"), _DATADIR_ + CString("/")));
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
ModHandle CModules::OpenModule(const CString& sModule, CString& sModPath, CString& sDataPath,
|
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++) {
|
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] != '_')) {
|
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.";
|
sRetMsg = "Module names can only contain letters, numbers and underscores, [" + sModule + "] is invalid.";
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::set;
|
using std::set;
|
||||||
@@ -467,6 +468,10 @@ public:
|
|||||||
// which is where static data (webadmin skins) are saved
|
// which is where static data (webadmin skins) are saved
|
||||||
static bool FindModPath(const CString& sModule, CString& sModPath,
|
static bool FindModPath(const CString& sModule, CString& sModPath,
|
||||||
CString& sDataPath);
|
CString& sDataPath);
|
||||||
|
// Return a list of <module dir, data dir> pairs for directories in
|
||||||
|
// which modules can be found.
|
||||||
|
typedef std::stack<std::pair<CString, CString> > ModDirList;
|
||||||
|
static ModDirList GetModDirs();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ModHandle OpenModule(const CString& sModule, CString& sModPath, CString& sDataPath,
|
ModHandle OpenModule(const CString& sModule, CString& sModPath, CString& sDataPath,
|
||||||
|
|||||||
Reference in New Issue
Block a user