mirror of
https://github.com/znc/znc.git
synced 2026-05-06 05:22:26 +02:00
Added ability to load modules as 'fake' just to act as a placeholder
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@519 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
31
Modules.cpp
31
Modules.cpp
@@ -160,6 +160,7 @@ const CString& CSocket::GetLabel() const { return m_sLabel; }
|
||||
/////////////////// !Socket ///////////////////
|
||||
|
||||
CModule::CModule(void* pDLL, CUser* pUser, const CString& sModName) {
|
||||
m_bFake = false;
|
||||
m_pDLL = pDLL;
|
||||
m_pManager = &(CZNC::Get().GetManager());;
|
||||
m_pUser = pUser;
|
||||
@@ -172,6 +173,7 @@ CModule::CModule(void* pDLL, CUser* pUser, const CString& sModName) {
|
||||
}
|
||||
|
||||
CModule::CModule(void* pDLL, const CString& sModName) {
|
||||
m_bFake = false;
|
||||
m_pDLL = pDLL;
|
||||
m_pManager = &(CZNC::Get().GetManager());
|
||||
m_pUser = NULL;
|
||||
@@ -497,7 +499,9 @@ CModules::CModules() {
|
||||
m_pUser = NULL;
|
||||
}
|
||||
|
||||
CModules::~CModules() {}
|
||||
CModules::~CModules() {
|
||||
UnloadAll();
|
||||
}
|
||||
|
||||
void CModules::UnloadAll() {
|
||||
while (size()) {
|
||||
@@ -666,7 +670,7 @@ CModule* CModules::FindModule(const CString& sModule) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg) {
|
||||
bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg, bool bFake) {
|
||||
#ifndef _MODULES
|
||||
sRetMsg = "Unable to load module [" + sModule + "] module support was not enabled.";
|
||||
return false;
|
||||
@@ -692,6 +696,16 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bFake) {
|
||||
CModule* pModule = new CModule(NULL, sModule);
|
||||
pModule->SetArgs(sArgs);
|
||||
pModule->SetDescription("<<Fake Module>>");
|
||||
pModule->SetFake(true);
|
||||
push_back(pModule);
|
||||
sRetMsg = "Loaded fake module [" + sModule + "] [" + sModPath + "]";
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int uDLFlags = RTLD_LAZY;
|
||||
|
||||
if (!pUser) {
|
||||
@@ -808,6 +822,19 @@ bool CModules::UnloadModule(const CString& sModule, CString& sRetMsg) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pModule->IsFake()) {
|
||||
for (iterator it = begin(); it != end(); it++) {
|
||||
if (*it == pModule) {
|
||||
erase(it);
|
||||
sRetMsg = "Fake module [" + sMod + "] unloaded";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
sRetMsg = "Fake module [" + sMod + "] not loaded.";
|
||||
return false;
|
||||
}
|
||||
|
||||
void* p = pModule->GetDLL();
|
||||
|
||||
if (p) {
|
||||
|
||||
@@ -279,11 +279,13 @@ public:
|
||||
const CString& GetSavePath() const { if (!CFile::Exists(m_sSavePath)) { CUtils::MakeDir(m_sSavePath); } return m_sSavePath; }
|
||||
|
||||
// Setters
|
||||
void SetFake(bool b) { m_bFake = b; }
|
||||
void SetDescription(const CString& s) { m_sDescription = s; }
|
||||
void SetArgs(const CString& s) { m_sArgs = s; }
|
||||
// !Setters
|
||||
|
||||
// Getters
|
||||
bool IsFake() const { return m_bFake; }
|
||||
const CString& GetDescription() const { return m_sDescription; }
|
||||
const CString& GetArgs() const { return m_sArgs; }
|
||||
CUser* GetUser() { return m_pUser; }
|
||||
@@ -291,6 +293,7 @@ public:
|
||||
// !Getters
|
||||
|
||||
protected:
|
||||
bool m_bFake;
|
||||
CString m_sDescription;
|
||||
vector<CTimer*> m_vTimers;
|
||||
vector<CSocket*> m_vSockets;
|
||||
@@ -355,7 +358,7 @@ public:
|
||||
virtual bool OnChanNotice(const CNick& Nick, CChan& Channel, CString& sMessage);
|
||||
|
||||
CModule* FindModule(const CString& sModule) const;
|
||||
bool LoadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg);
|
||||
bool LoadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg, bool bFake = false);
|
||||
bool UnloadModule(const CString& sModule);
|
||||
bool UnloadModule(const CString& sModule, CString& sRetMsg);
|
||||
bool ReloadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg);
|
||||
|
||||
Reference in New Issue
Block a user