mirror of
https://github.com/znc/znc.git
synced 2026-08-10 19:02:51 +02:00
Create EModuleType, creating SetType which replaces SetGlobal
This commit is contained in:
+4
-4
@@ -148,7 +148,7 @@ public:
|
||||
case Perl_Loaded:
|
||||
result = HALT;
|
||||
if (4 == ret) {
|
||||
ModInfo.SetGlobal(false);
|
||||
ModInfo.SetType(ModuleTypeUser);
|
||||
ModInfo.SetDescription(PString(ST(2)));
|
||||
ModInfo.SetName(sModule);
|
||||
ModInfo.SetPath(PString(ST(1)));
|
||||
@@ -178,8 +178,8 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual void OnGetAvailableMods(set<CModInfo>& ssMods, bool bGlobal) {
|
||||
if (bGlobal) {
|
||||
virtual void OnGetAvailableMods(set<CModInfo>& ssMods, EModuleType eType) {
|
||||
if (eType != ModuleTypeUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public:
|
||||
PUSH_STR(sName);
|
||||
PCALL("ZNC::Core::ModInfoByPath");
|
||||
if (!SvTRUE(ERRSV) && ret == 2) {
|
||||
ModInfo.SetGlobal(false);
|
||||
ModInfo.SetType(ModuleTypeUser);
|
||||
ModInfo.SetDescription(PString(ST(0)));
|
||||
ModInfo.SetName(sName);
|
||||
ModInfo.SetPath(sPath);
|
||||
|
||||
+6
-13
@@ -128,9 +128,6 @@ public:
|
||||
|
||||
virtual EModRet OnModuleLoading(const CString& sModName, const CString& sArgs,
|
||||
bool& bSuccess, CString& sRetMsg) {
|
||||
if (!GetUser()) {
|
||||
return CONTINUE;
|
||||
}
|
||||
PyObject* pyFunc = PyObject_GetAttrString(m_PyZNCModule, "load_module");
|
||||
if (!pyFunc) {
|
||||
sRetMsg = GetPyExceptionStr();
|
||||
@@ -252,7 +249,7 @@ public:
|
||||
return HALT;
|
||||
}
|
||||
|
||||
void TryAddModInfo(const CString& sPath, const CString& sName, set<CModInfo>& ssMods, set<CString>& ssAlready) {
|
||||
void TryAddModInfo(const CString& sPath, const CString& sName, set<CModInfo>& ssMods, set<CString>& ssAlready, EModuleType eType) {
|
||||
if (ssAlready.count(sName)) {
|
||||
return;
|
||||
}
|
||||
@@ -282,17 +279,13 @@ public:
|
||||
return;
|
||||
}
|
||||
Py_CLEAR(pyRes);
|
||||
if (x) {
|
||||
if (x && ModInfo.GetType() == eType) {
|
||||
ssMods.insert(ModInfo);
|
||||
ssAlready.insert(sName);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnGetAvailableMods(set<CModInfo>& ssMods, bool bGlobal) {
|
||||
if (bGlobal) {
|
||||
return;
|
||||
}
|
||||
|
||||
virtual void OnGetAvailableMods(set<CModInfo>& ssMods, EModuleType eType) {
|
||||
CDir Dir;
|
||||
CModules::ModDirList dirs = CModules::GetModDirs();
|
||||
|
||||
@@ -306,7 +299,7 @@ public:
|
||||
CString sPath = File.GetLongName();
|
||||
sPath.TrimSuffix(sName);
|
||||
sName.RightChomp(3);
|
||||
TryAddModInfo(sPath, sName, ssMods, already);
|
||||
TryAddModInfo(sPath, sName, ssMods, already, eType);
|
||||
}
|
||||
|
||||
Dir.FillByWildcard(dirs.front().first, "*.pyc");
|
||||
@@ -316,7 +309,7 @@ public:
|
||||
CString sPath = File.GetLongName();
|
||||
sPath.TrimSuffix(sName);
|
||||
sName.RightChomp(4);
|
||||
TryAddModInfo(sPath, sName, ssMods, already);
|
||||
TryAddModInfo(sPath, sName, ssMods, already, eType);
|
||||
}
|
||||
|
||||
Dir.FillByWildcard(dirs.front().first, "*.so");
|
||||
@@ -326,7 +319,7 @@ public:
|
||||
CString sPath = File.GetLongName();
|
||||
sPath.TrimSuffix(sName);
|
||||
sName.RightChomp(3);
|
||||
TryAddModInfo(sPath, sName, ssMods, already);
|
||||
TryAddModInfo(sPath, sName, ssMods, already, eType);
|
||||
}
|
||||
|
||||
dirs.pop();
|
||||
|
||||
@@ -150,6 +150,7 @@ class ModuleNV(collections.MutableMapping):
|
||||
|
||||
class Module:
|
||||
description = '< Placeholder for a description >'
|
||||
module_type = ModuleTypeUser
|
||||
|
||||
wiki_page = ''
|
||||
|
||||
@@ -498,7 +499,7 @@ def get_mod_info(modname, retmsg, modinfo):
|
||||
pymodule.__file__, modname)
|
||||
return 1
|
||||
cl = pymodule.__dict__[modname]
|
||||
modinfo.SetGlobal(False)
|
||||
modinfo.SetType(cl.module_type)
|
||||
modinfo.SetDescription(cl.description)
|
||||
modinfo.SetWikiPage(cl.wiki_page)
|
||||
modinfo.SetName(modname)
|
||||
@@ -526,7 +527,7 @@ def get_mod_info_path(path, modname, modinfo):
|
||||
if modname not in pymodule.__dict__:
|
||||
return 0
|
||||
cl = pymodule.__dict__[modname]
|
||||
modinfo.SetGlobal(False)
|
||||
modinfo.SetType(cl.module_type)
|
||||
modinfo.SetDescription(cl.description)
|
||||
modinfo.SetWikiPage(cl.wiki_page)
|
||||
modinfo.SetName(modname)
|
||||
|
||||
+9
-23
@@ -143,24 +143,6 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
CString GetModArgs(CUser* pUser, const CString& sModName, bool bGlobal = false) {
|
||||
if (!bGlobal && !pUser) {
|
||||
return "";
|
||||
}
|
||||
|
||||
CModules& Modules = (bGlobal) ? CZNC::Get().GetModules() : pUser->GetModules();
|
||||
|
||||
for (unsigned int a = 0; a < Modules.size(); a++) {
|
||||
CModule* pModule = Modules[a];
|
||||
|
||||
if (pModule->GetModName() == sModName) {
|
||||
return pModule->GetArgs();
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
CUser* GetNewUser(CWebSock& WebSock, CUser* pUser) {
|
||||
CSmartPtr<CWebSession> spSession = WebSock.GetSession();
|
||||
CString sUsername = WebSock.GetParam("newuser");
|
||||
@@ -744,11 +726,14 @@ public:
|
||||
|
||||
l["Name"] = Info.GetName();
|
||||
l["Description"] = Info.GetDescription();
|
||||
l["Args"] = GetModArgs(pUser, Info.GetName());
|
||||
l["Wiki"] = Info.GetWikiPage();
|
||||
|
||||
if (pUser && pUser->GetModules().FindModule(Info.GetName())) {
|
||||
l["Checked"] = "true";
|
||||
CModule *pModule = pUser->GetModules().FindModule(Info.GetName());
|
||||
if (pModule) {
|
||||
l["Checked"] = "true";
|
||||
l["Args"] = pModule->GetArgs();
|
||||
}
|
||||
}
|
||||
|
||||
if (!spSession->IsAdmin() && pUser && pUser->DenyLoadMod()) {
|
||||
@@ -1023,14 +1008,16 @@ public:
|
||||
}
|
||||
|
||||
set<CModInfo> ssGlobalMods;
|
||||
CZNC::Get().GetModules().GetAvailableMods(ssGlobalMods, true);
|
||||
CZNC::Get().GetModules().GetAvailableMods(ssGlobalMods, ModuleTypeGlobal);
|
||||
|
||||
for (set<CModInfo>::iterator it = ssGlobalMods.begin(); it != ssGlobalMods.end(); ++it) {
|
||||
const CModInfo& Info = *it;
|
||||
CTemplate& l = Tmpl.AddRow("ModuleLoop");
|
||||
|
||||
if (CZNC::Get().GetModules().FindModule(Info.GetName())) {
|
||||
CModule *pModule = CZNC::Get().GetModules().FindModule(Info.GetName());
|
||||
if (pModule) {
|
||||
l["Checked"] = "true";
|
||||
l["Args"] = pModule->GetArgs();
|
||||
}
|
||||
|
||||
if (Info.GetName() == GetModName()) {
|
||||
@@ -1039,7 +1026,6 @@ public:
|
||||
|
||||
l["Name"] = Info.GetName();
|
||||
l["Description"] = Info.GetDescription();
|
||||
l["Args"] = GetModArgs(NULL, Info.GetName(), true);
|
||||
l["Wiki"] = Info.GetWikiPage();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user