diff --git a/Modules.cpp b/Modules.cpp index 57872645..2b0e46af 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -19,10 +19,10 @@ # warning "your crap box doesnt define RTLD_LOCAL !?" #endif -#define _MODUNLOADCHK(func, type) \ +#define MODUNLOADCHK(func) \ for (unsigned int a = 0; a < size(); a++) { \ try { \ - type* pMod = (type *) (*this)[a]; \ + CModule* pMod = (CModule *) (*this)[a]; \ CClient* pOldClient = pMod->GetClient(); \ pMod->SetClient(m_pClient); \ if (m_pUser) { \ @@ -41,14 +41,12 @@ } \ } -#define MODUNLOADCHK(func) _MODUNLOADCHK(func, CModule) -#define GLOBALMODCALL(func) _MODUNLOADCHK(func, CGlobalModule) -#define _MODHALTCHK(func, type) \ +#define MODHALTCHK(func) \ bool bHaltCore = false; \ for (unsigned int a = 0; a < size(); a++) { \ try { \ - type* pMod = (type*) (*this)[a]; \ + CModule* pMod = (CModule*) (*this)[a]; \ CModule::EModRet e = CModule::CONTINUE; \ CClient* pOldClient = pMod->GetClient(); \ pMod->SetClient(m_pClient); \ @@ -77,9 +75,6 @@ } \ return bHaltCore; -#define MODHALTCHK(func) _MODHALTCHK(func, CModule) -#define GLOBALMODHALTCHK(func) _MODHALTCHK(func, CGlobalModule) - /////////////////// Timer /////////////////// CTimer::CTimer(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription) : CCron() { SetName(sLabel); @@ -570,25 +565,25 @@ bool CModule::PutModNotice(const CString& sLine) { } /////////////////// -// CGlobalModule // +// Global Module // /////////////////// -CModule::EModRet CGlobalModule::OnAddUser(CUser& User, CString& sErrorRet) { return CONTINUE; } -CModule::EModRet CGlobalModule::OnDeleteUser(CUser& User) { return CONTINUE; } -void CGlobalModule::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned short uPort) {} -CModule::EModRet CGlobalModule::OnLoginAttempt(CSmartPtr Auth) { return CONTINUE; } -void CGlobalModule::OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) {} -CModule::EModRet CGlobalModule::OnUnknownUserRaw(CString& sLine) { return CONTINUE; } -void CGlobalModule::OnClientCapLs(SCString& ssCaps) {} -bool CGlobalModule::IsClientCapSupported(const CString& sCap, bool bState) { return false; } -void CGlobalModule::OnClientCapRequest(const CString& sCap, bool bState) {} -CModule::EModRet CGlobalModule::OnModuleLoading(const CString& sModName, const CString& sArgs, +CModule::EModRet CModule::OnAddUser(CUser& User, CString& sErrorRet) { return CONTINUE; } +CModule::EModRet CModule::OnDeleteUser(CUser& User) { return CONTINUE; } +void CModule::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned short uPort) {} +CModule::EModRet CModule::OnLoginAttempt(CSmartPtr Auth) { return CONTINUE; } +void CModule::OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) {} +CModule::EModRet CModule::OnUnknownUserRaw(CString& sLine) { return CONTINUE; } +void CModule::OnClientCapLs(SCString& ssCaps) {} +bool CModule::IsClientCapSupported(const CString& sCap, bool bState) { return false; } +void CModule::OnClientCapRequest(const CString& sCap, bool bState) {} +CModule::EModRet CModule::OnModuleLoading(const CString& sModName, const CString& sArgs, bool& bSuccess, CString& sRetMsg) { return CONTINUE; } -CModule::EModRet CGlobalModule::OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) { +CModule::EModRet CModule::OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) { return CONTINUE; } -CModule::EModRet CGlobalModule::OnGetModInfo(CModInfo& ModInfo, const CString& sModule, +CModule::EModRet CModule::OnGetModInfo(CModInfo& ModInfo, const CString& sModule, bool& bSuccess, CString& sRetMsg) { return CONTINUE; } -void CGlobalModule::OnGetAvailableMods(set& ssMods, EModuleType eType) {} +void CModule::OnGetAvailableMods(set& ssMods, EModuleType eType) {} CModules::CModules() { @@ -709,45 +704,45 @@ bool CModules::OnServerCapAvailable(const CString& sCap) { bool CModules::OnServerCapResult(const CString& sCap, bool bSuccess) { MODUNLOADCHK(OnServerCapResult(sCap, bSuccess)); return false; } //////////////////// -// CGlobalModules // +// Global Modules // //////////////////// -bool CGlobalModules::OnAddUser(CUser& User, CString& sErrorRet) { - GLOBALMODHALTCHK(OnAddUser(User, sErrorRet)); +bool CModules::OnAddUser(CUser& User, CString& sErrorRet) { + MODHALTCHK(OnAddUser(User, sErrorRet)); } -bool CGlobalModules::OnDeleteUser(CUser& User) { - GLOBALMODHALTCHK(OnDeleteUser(User)); +bool CModules::OnDeleteUser(CUser& User) { + MODHALTCHK(OnDeleteUser(User)); } -bool CGlobalModules::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned short uPort) { - GLOBALMODCALL(OnClientConnect(pClient, sHost, uPort)); +bool CModules::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned short uPort) { + MODUNLOADCHK(OnClientConnect(pClient, sHost, uPort)); return false; } -bool CGlobalModules::OnLoginAttempt(CSmartPtr Auth) { - GLOBALMODHALTCHK(OnLoginAttempt(Auth)); +bool CModules::OnLoginAttempt(CSmartPtr Auth) { + MODHALTCHK(OnLoginAttempt(Auth)); } -bool CGlobalModules::OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) { - GLOBALMODCALL(OnFailedLogin(sUsername, sRemoteIP)); +bool CModules::OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) { + MODUNLOADCHK(OnFailedLogin(sUsername, sRemoteIP)); return false; } -bool CGlobalModules::OnUnknownUserRaw(CString& sLine) { - GLOBALMODHALTCHK(OnUnknownUserRaw(sLine)); +bool CModules::OnUnknownUserRaw(CString& sLine) { + MODHALTCHK(OnUnknownUserRaw(sLine)); } -bool CGlobalModules::OnClientCapLs(SCString& ssCaps) { - GLOBALMODCALL(OnClientCapLs(ssCaps)); +bool CModules::OnClientCapLs(SCString& ssCaps) { + MODUNLOADCHK(OnClientCapLs(ssCaps)); return false; } // Maybe create new macro for this? -bool CGlobalModules::IsClientCapSupported(const CString& sCap, bool bState) { +bool CModules::IsClientCapSupported(const CString& sCap, bool bState) { bool bResult = false; for (unsigned int a = 0; a < size(); ++a) { try { - CGlobalModule* pMod = (CGlobalModule*) (*this)[a]; + CModule* pMod = (CModule*) (*this)[a]; CClient* pOldClient = pMod->GetClient(); pMod->SetClient(m_pClient); if (m_pUser) { @@ -769,27 +764,27 @@ bool CGlobalModules::IsClientCapSupported(const CString& sCap, bool bState) { return bResult; } -bool CGlobalModules::OnClientCapRequest(const CString& sCap, bool bState) { - GLOBALMODCALL(OnClientCapRequest(sCap, bState)); +bool CModules::OnClientCapRequest(const CString& sCap, bool bState) { + MODUNLOADCHK(OnClientCapRequest(sCap, bState)); return false; } -bool CGlobalModules::OnModuleLoading(const CString& sModName, const CString& sArgs, +bool CModules::OnModuleLoading(const CString& sModName, const CString& sArgs, bool& bSuccess, CString& sRetMsg) { - GLOBALMODHALTCHK(OnModuleLoading(sModName, sArgs, bSuccess, sRetMsg)); + MODHALTCHK(OnModuleLoading(sModName, sArgs, bSuccess, sRetMsg)); } -bool CGlobalModules::OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) { - GLOBALMODHALTCHK(OnModuleUnloading(pModule, bSuccess, sRetMsg)); +bool CModules::OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) { + MODHALTCHK(OnModuleUnloading(pModule, bSuccess, sRetMsg)); } -bool CGlobalModules::OnGetModInfo(CModInfo& ModInfo, const CString& sModule, +bool CModules::OnGetModInfo(CModInfo& ModInfo, const CString& sModule, bool& bSuccess, CString& sRetMsg) { - GLOBALMODHALTCHK(OnGetModInfo(ModInfo, sModule, bSuccess, sRetMsg)); + MODHALTCHK(OnGetModInfo(ModInfo, sModule, bSuccess, sRetMsg)); } -bool CGlobalModules::OnGetAvailableMods(set& ssMods, EModuleType eType) { - GLOBALMODCALL(OnGetAvailableMods(ssMods, eType)); +bool CModules::OnGetAvailableMods(set& ssMods, EModuleType eType) { + MODUNLOADCHK(OnGetAvailableMods(ssMods, eType)); return false; } diff --git a/Modules.h b/Modules.h index e92b4e49..67ffa568 100644 --- a/Modules.h +++ b/Modules.h @@ -25,7 +25,6 @@ class CWebSock; class CTemplate; class CIRCSock; class CModule; -class CGlobalModule; class CModInfo; // !Forward Declarations @@ -53,7 +52,7 @@ template CModule* TModLoad(ModHandle p, CUser* pUser, const CString& sModName, const CString& sModPath) { return new M(p, pUser, sModName, sModPath); } -template CGlobalModule* TModLoadGlobal(ModHandle p, +template CModule* TModLoadGlobal(ModHandle p, const CString& sModName, const CString& sModPath) { return new M(p, sModName, sModPath); } @@ -113,7 +112,7 @@ template CGlobalModule* TModLoadGlobal(ModHandle p, /** This works exactly like MODCONSTRUCTOR, but for global modules. */ #define GLOBALMODCONSTRUCTOR(CLASS) \ CLASS(ModHandle pDLL, const CString& sModName, const CString& sModPath) \ - : CGlobalModule(pDLL, sModName, sModPath) + : CModule(pDLL, sModName, sModPath) /** This works exactly like MODULEDEFS, but for global modules. */ #define GLOBALMODULEDEFS(CLASS, DESCRIPTION) \ @@ -178,7 +177,7 @@ private: class CModInfo { public: typedef CModule* (*ModLoader)(ModHandle p, CUser* pUser, const CString& sModName, const CString& sModPath); - typedef CGlobalModule* (*GlobalModLoader)(ModHandle p, const CString& sModName, const CString& sModPath); + typedef CModule* (*GlobalModLoader)(ModHandle p, const CString& sModName, const CString& sModPath); CModInfo() { m_fGlobalLoader = NULL; @@ -874,6 +873,98 @@ public: CSockManager* GetManager() { return m_pManager; } // !Getters + // Global Modules + /** This module hook is called when a user is being added. + * @param User The user which will be added. + * @param sErrorRet A message that may be displayed to the user if + * the module stops adding the user. + * @return See CModule::EModRet. + */ + virtual EModRet OnAddUser(CUser& User, CString& sErrorRet); + /** This module hook is called when a user is deleted. + * @param User The user which will be deleted. + * @return See CModule::EModRet. + */ + virtual EModRet OnDeleteUser(CUser& User); + /** This module hook is called when there is an incoming connection on + * any of ZNC's listening sockets. + * @param pSock The incoming client socket. + * @param sHost The IP the client is connecting from. + * @param uPort The port the client is connecting from. + */ + virtual void OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort); + /** This module hook is called when a client tries to login. If your + * module wants to handle the login attempt, it must return + * CModule::EModRet::HALT; + * @param Auth The necessary authentication info for this login attempt. + * @return See CModule::EModRet. + */ + virtual EModRet OnLoginAttempt(CSmartPtr Auth); + /** Called after a client login was rejected. + * @param sUsername The username that tried to log in. + * @param sRemoteIP The IP address from which the client tried to login. + */ + virtual void OnFailedLogin(const CString& sUsername, const CString& sRemoteIP); + /** This function behaves like CModule::OnRaw(), but is also called + * before the client successfully logged in to ZNC. You should always + * prefer to use CModule::OnRaw() if possible. + * @param sLine The raw traffic line which the client sent. + * @todo Why doesn't this use m_pUser and m_pClient? + * (Well, ok, m_pUser isn't known yet...) + */ + virtual EModRet OnUnknownUserRaw(CString& sLine); + + /** Called when a client told us CAP LS. Use ssCaps.insert("cap-name") + * for announcing capabilities which your module supports. + * @param ssCaps set of caps which will be sent to client. + */ + virtual void OnClientCapLs(SCString& ssCaps); + /** Called only to check if your module supports turning on/off named capability. + * @param sCap name of capability. + * @param bState On or off, depending on which case is interesting for client. + * @return true if your module supports this capability in the specified state. + */ + virtual bool IsClientCapSupported(const CString& sCap, bool bState); + /** Called when we actually need to turn a capability on or off for a client. + * @param sCap name of wanted capability. + * @param bState On or off, depending on which case client needs. + */ + virtual void OnClientCapRequest(const CString& sCap, bool bState); + + /** Called when a module is going to be loaded. + * @param sModName name of the module. + * @param sArgs arguments of the module. + * @param[out] bSuccess the module was loaded successfully + * as result of this module hook? + * @param[out] sRetMsg text about loading of the module. + * @return See CModule::EModRet. + */ + virtual EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, + bool& bSuccess, CString& sRetMsg); + /** Called when a module is going to be unloaded. + * @param pModule the module. + * @param[out] bSuccess the module was unloaded successfully + * as result of this module hook? + * @param[out] sRetMsg text about unloading of the module. + * @return See CModule::EModRet. + */ + virtual EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg); + /** Called when info about a module is needed. + * @param[out] ModInfo put result here, if your module knows it. + * @param sModule name of the module. + * @param bSuccess this module provided info about the module. + * @param sRetMsg text describing possible issues. + * @return See CModule::EModRet. + */ + virtual EModRet OnGetModInfo(CModInfo& ModInfo, const CString& sModule, + bool& bSuccess, CString& sRetMsg); + /** Called when list of available mods is requested. + * @param ssMods put new modules here. + * @param bGlobal true if global modules are needed. + */ + virtual void OnGetAvailableMods(set& ssMods, EModuleType eType); + // !Global Modules + protected: EModuleType m_eType; CString m_sDescription; @@ -989,127 +1080,7 @@ public: typedef std::queue > ModDirList; static ModDirList GetModDirs(); -private: - static ModHandle OpenModule(const CString& sModule, const CString& sModPath, - bool &bVersionMismatch, CModInfo& Info, CString& sRetMsg); - -protected: - CUser* m_pUser; - CClient* m_pClient; -}; - -/** Base class for global modules. If you want to write a global module, your - * module class has to derive from CGlobalModule instead of CModule. - * - * All the module hooks from CModule work here, too. The difference is that - * they are now called for all users instead of just a specific one. - * - * Instead of MODCONSTRUCTOR and MODULEDEFS, you will have to use - * GLOBALMODCONSTRUCTOR and GLOBALMODULEDEFS. - */ -class CGlobalModule : public CModule { -public: - CGlobalModule(ModHandle pDLL, const CString& sModName, - const CString &sDataDir) : CModule(pDLL, sModName, sDataDir) {} - virtual ~CGlobalModule() {} - - /** This module hook is called when a user is being added. - * @param User The user which will be added. - * @param sErrorRet A message that may be displayed to the user if - * the module stops adding the user. - * @return See CModule::EModRet. - */ - virtual EModRet OnAddUser(CUser& User, CString& sErrorRet); - /** This module hook is called when a user is deleted. - * @param User The user which will be deleted. - * @return See CModule::EModRet. - */ - virtual EModRet OnDeleteUser(CUser& User); - /** This module hook is called when there is an incoming connection on - * any of ZNC's listening sockets. - * @param pSock The incoming client socket. - * @param sHost The IP the client is connecting from. - * @param uPort The port the client is connecting from. - */ - virtual void OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort); - /** This module hook is called when a client tries to login. If your - * module wants to handle the login attempt, it must return - * CModule::EModRet::HALT; - * @param Auth The necessary authentication info for this login attempt. - * @return See CModule::EModRet. - */ - virtual EModRet OnLoginAttempt(CSmartPtr Auth); - /** Called after a client login was rejected. - * @param sUsername The username that tried to log in. - * @param sRemoteIP The IP address from which the client tried to login. - */ - virtual void OnFailedLogin(const CString& sUsername, const CString& sRemoteIP); - /** This function behaves like CModule::OnRaw(), but is also called - * before the client successfully logged in to ZNC. You should always - * prefer to use CModule::OnRaw() if possible. - * @param sLine The raw traffic line which the client sent. - * @todo Why doesn't this use m_pUser and m_pClient? - * (Well, ok, m_pUser isn't known yet...) - */ - virtual EModRet OnUnknownUserRaw(CString& sLine); - - /** Called when a client told us CAP LS. Use ssCaps.insert("cap-name") - * for announcing capabilities which your module supports. - * @param ssCaps set of caps which will be sent to client. - */ - virtual void OnClientCapLs(SCString& ssCaps); - /** Called only to check if your module supports turning on/off named capability. - * @param sCap name of capability. - * @param bState On or off, depending on which case is interesting for client. - * @return true if your module supports this capability in the specified state. - */ - virtual bool IsClientCapSupported(const CString& sCap, bool bState); - /** Called when we actually need to turn a capability on or off for a client. - * @param sCap name of wanted capability. - * @param bState On or off, depending on which case client needs. - */ - virtual void OnClientCapRequest(const CString& sCap, bool bState); - - /** Called when a module is going to be loaded. - * @param sModName name of the module. - * @param sArgs arguments of the module. - * @param[out] bSuccess the module was loaded successfully - * as result of this module hook? - * @param[out] sRetMsg text about loading of the module. - * @return See CModule::EModRet. - */ - virtual EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, - bool& bSuccess, CString& sRetMsg); - /** Called when a module is going to be unloaded. - * @param pModule the module. - * @param[out] bSuccess the module was unloaded successfully - * as result of this module hook? - * @param[out] sRetMsg text about unloading of the module. - * @return See CModule::EModRet. - */ - virtual EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg); - /** Called when info about a module is needed. - * @param[out] ModInfo put result here, if your module knows it. - * @param sModule name of the module. - * @param bSuccess this module provided info about the module. - * @param sRetMsg text describing possible issues. - * @return See CModule::EModRet. - */ - virtual EModRet OnGetModInfo(CModInfo& ModInfo, const CString& sModule, - bool& bSuccess, CString& sRetMsg); - /** Called when list of available mods is requested. - * @param ssMods put new modules here. - * @param bGlobal true if global modules are needed. - */ - virtual void OnGetAvailableMods(set& ssMods, EModuleType eType); -private: -}; - -class CGlobalModules : public CModules { -public: - CGlobalModules() : CModules() {} - ~CGlobalModules() {} - + // Global Modules bool OnAddUser(CUser& User, CString& sErrorRet); bool OnDeleteUser(CUser& User); bool OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort); @@ -1125,7 +1096,15 @@ public: bool OnGetModInfo(CModInfo& ModInfo, const CString& sModule, bool& bSuccess, CString& sRetMsg); bool OnGetAvailableMods(set& ssMods, EModuleType eType); + // !Global Modules + private: + static ModHandle OpenModule(const CString& sModule, const CString& sModPath, + bool &bVersionMismatch, CModInfo& Info, CString& sRetMsg); + +protected: + CUser* m_pUser; + CClient* m_pClient; }; #endif // !_MODULES_H diff --git a/WebModules.cpp b/WebModules.cpp index c2404c8b..27bc059b 100644 --- a/WebModules.cpp +++ b/WebModules.cpp @@ -334,7 +334,7 @@ void CWebSock::SetVars() { GetSession()->ClearMessageLoops(); // Global Mods - CGlobalModules& vgMods = CZNC::Get().GetModules(); + CModules& vgMods = CZNC::Get().GetModules(); for (unsigned int a = 0; a < vgMods.size(); a++) { AddModLoop("GlobalModLoop", *vgMods[a]); } diff --git a/main.h b/main.h index 6b1b27df..af4b66ed 100644 --- a/main.h +++ b/main.h @@ -26,7 +26,7 @@ #define ALLMODULECALL(macFUNC, macEXITER) \ do { \ - CGlobalModules& GMods = CZNC::Get().GetModules(); \ + CModules& GMods = CZNC::Get().GetModules(); \ if (GMods.macFUNC) { \ macEXITER; \ } else { \ @@ -44,7 +44,7 @@ #define GLOBALMODULECALL(macFUNC, macUSER, macCLIENT, macEXITER) \ do { \ - CGlobalModules& GMods = CZNC::Get().GetModules(); \ + CModules& GMods = CZNC::Get().GetModules(); \ CUser* pOldGUser = GMods.GetUser(); \ CClient* pOldGClient = GMods.GetClient(); \ GMods.SetUser(macUSER); \ @@ -79,7 +79,7 @@ * call #MODULEDEFS at the end of your source file. * Congratulations, you just wrote your first module.
* For global modules, the procedure is similar. Instead of CModule you inherit - * from CGlobalModule. The two macros are replaced by #GLOBALMODCONSTRUCTOR and + * from CModule. The two macros are replaced by #GLOBALMODCONSTRUCTOR and * #GLOBALMODULEDEFS. * * If you want your module to actually do something, you should override some diff --git a/modules/adminlog.cpp b/modules/adminlog.cpp index 64bc9b42..e6bdf6a7 100644 --- a/modules/adminlog.cpp +++ b/modules/adminlog.cpp @@ -13,7 +13,7 @@ #include -class CAdminLogMod : public CGlobalModule { +class CAdminLogMod : public CModule { public: GLOBALMODCONSTRUCTOR(CAdminLogMod) { openlog("znc", LOG_PID, LOG_DAEMON); diff --git a/modules/blockuser.cpp b/modules/blockuser.cpp index e43d28e4..71f37fd3 100644 --- a/modules/blockuser.cpp +++ b/modules/blockuser.cpp @@ -12,7 +12,7 @@ #define MESSAGE "Your account has been disabled. Contact your administrator." -class CBlockUser : public CGlobalModule { +class CBlockUser : public CModule { public: GLOBALMODCONSTRUCTOR(CBlockUser) {} diff --git a/modules/certauth.cpp b/modules/certauth.cpp index 96d870e3..d3747ffc 100644 --- a/modules/certauth.cpp +++ b/modules/certauth.cpp @@ -13,7 +13,7 @@ #include "Listener.h" #include "znc.h" -class CSSLClientCertMod : public CGlobalModule { +class CSSLClientCertMod : public CModule { public: GLOBALMODCONSTRUCTOR(CSSLClientCertMod) { AddHelpCommand(); diff --git a/modules/extra/droproot.cpp b/modules/extra/droproot.cpp index cd17402d..9cc3c364 100644 --- a/modules/extra/droproot.cpp +++ b/modules/extra/droproot.cpp @@ -18,7 +18,7 @@ #include #include -class CDroproot : public CGlobalModule { +class CDroproot : public CModule { public: GLOBALMODCONSTRUCTOR(CDroproot) { diff --git a/modules/extra/imapauth.cpp b/modules/extra/imapauth.cpp index fcf9570f..5545bee7 100644 --- a/modules/extra/imapauth.cpp +++ b/modules/extra/imapauth.cpp @@ -39,7 +39,7 @@ protected: }; -class CIMAPAuthMod : public CGlobalModule { +class CIMAPAuthMod : public CModule { public: GLOBALMODCONSTRUCTOR(CIMAPAuthMod) { m_Cache.SetTTL(60000); diff --git a/modules/extra/motdfile.cpp b/modules/extra/motdfile.cpp index 5c2d3331..fc1afba2 100644 --- a/modules/extra/motdfile.cpp +++ b/modules/extra/motdfile.cpp @@ -10,7 +10,7 @@ #include "Client.h" #include "FileUtils.h" -class CMotdFileMod : public CGlobalModule { +class CMotdFileMod : public CModule { public: GLOBALMODCONSTRUCTOR(CMotdFileMod) {} virtual ~CMotdFileMod() {} diff --git a/modules/extra/notify_connect.cpp b/modules/extra/notify_connect.cpp index d5755046..70d023d4 100644 --- a/modules/extra/notify_connect.cpp +++ b/modules/extra/notify_connect.cpp @@ -9,7 +9,7 @@ #include "znc.h" #include "User.h" -class CNotifyConnectMod : public CGlobalModule { +class CNotifyConnectMod : public CModule { public: GLOBALMODCONSTRUCTOR(CNotifyConnectMod) {} diff --git a/modules/extra/saslauth.cpp b/modules/extra/saslauth.cpp index 616face0..b2f61687 100644 --- a/modules/extra/saslauth.cpp +++ b/modules/extra/saslauth.cpp @@ -15,7 +15,7 @@ #include "znc.h" #include -class CSASLAuthMod : public CGlobalModule { +class CSASLAuthMod : public CModule { public: GLOBALMODCONSTRUCTOR(CSASLAuthMod) { m_Cache.SetTTL(60000/*ms*/); diff --git a/modules/fail2ban.cpp b/modules/fail2ban.cpp index a1595b0b..a232d4c8 100644 --- a/modules/fail2ban.cpp +++ b/modules/fail2ban.cpp @@ -8,7 +8,7 @@ #include "znc.h" -class CFailToBanMod : public CGlobalModule { +class CFailToBanMod : public CModule { public: GLOBALMODCONSTRUCTOR(CFailToBanMod) {} virtual ~CFailToBanMod() {} diff --git a/modules/identfile.cpp b/modules/identfile.cpp index 05a61be9..d0961db0 100644 --- a/modules/identfile.cpp +++ b/modules/identfile.cpp @@ -11,7 +11,7 @@ #include "User.h" #include "znc.h" -class CIdentFileModule : public CGlobalModule { +class CIdentFileModule : public CModule { CString m_sOrigISpoof; CFile* m_pISpoofLockFile; CIRCSock *m_pIRCSock; diff --git a/modules/lastseen.cpp b/modules/lastseen.cpp index 49a79ab2..048a32e2 100644 --- a/modules/lastseen.cpp +++ b/modules/lastseen.cpp @@ -14,7 +14,7 @@ using std::map; using std::pair; using std::multimap; -class CLastSeenMod : public CGlobalModule { +class CLastSeenMod : public CModule { private: time_t GetTime(const CUser *pUser) { return GetNV(pUser->GetUserName()).ToULong(); diff --git a/modules/modperl.cpp b/modules/modperl.cpp index 24560b16..690f7397 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -31,7 +31,7 @@ extern "C" { } } -class CModPerl: public CGlobalModule { +class CModPerl: public CModule { PerlInterpreter *m_pPerl; public: GLOBALMODCONSTRUCTOR(CModPerl) { diff --git a/modules/modpython.cpp b/modules/modpython.cpp index d8fb83b3..f0d635a4 100644 --- a/modules/modpython.cpp +++ b/modules/modpython.cpp @@ -20,7 +20,7 @@ #include "modpython/module.h" #include "modpython/retstring.h" -class CModPython: public CGlobalModule { +class CModPython: public CModule { PyObject* m_PyZNCModule; PyObject* m_PyFormatException; @@ -140,7 +140,7 @@ public: sArgs.c_str(), SWIG_NewInstanceObj(GetUser(), SWIG_TypeQuery("CUser*"), 0), CPyRetString::wrap(sRetMsg), - SWIG_NewInstanceObj(reinterpret_cast(this), SWIG_TypeQuery("CGlobalModule*"), 0)); + SWIG_NewInstanceObj(reinterpret_cast(this), SWIG_TypeQuery("CModule*"), 0)); if (!pyRes) { sRetMsg = GetPyExceptionStr(); DEBUG("modpython: " << sRetMsg); diff --git a/modules/modpython/module.h b/modules/modpython/module.h index 3e2fa50b..de2cbe98 100644 --- a/modules/modpython/module.h +++ b/modules/modpython/module.h @@ -24,7 +24,7 @@ class CPyModule : public CModule { VWebSubPages* _GetSubPages(); public: CPyModule(CUser* pUser, const CString& sModName, const CString& sDataPath, - PyObject* pyObj, CGlobalModule* pModPython) + PyObject* pyObj, CModule* pModPython) : CModule(NULL, pUser, sModName, sDataPath) { m_pyObj = pyObj; Py_INCREF(pyObj); @@ -114,7 +114,7 @@ static inline CPyModule* AsPyModule(CModule* p) { return dynamic_cast(p); } -inline CPyModule* CreatePyModule(CUser* pUser, const CString& sModName, const CString& sDataPath, PyObject* pyObj, CGlobalModule* pModPython) { +inline CPyModule* CreatePyModule(CUser* pUser, const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) { return new CPyModule(pUser, sModName, sDataPath, pyObj, pModPython); } diff --git a/modules/modpython/znc.py b/modules/modpython/znc.py index 61a55919..100ce165 100644 --- a/modules/modpython/znc.py +++ b/modules/modpython/znc.py @@ -443,7 +443,12 @@ def load_module(modname, args, user, retmsg, modpython): module.SetDescription(cl.description) module.SetArgs(args) module.SetModPath(pymodule.__file__) - user.GetModules().push_back(module._cmod) + + if user: + user.GetModules().push_back(module._cmod) + else: + CZNC.Get().GetModules().push_back(module._cmod) + try: loaded = True if not module.OnLoad(args, retmsg): diff --git a/modules/partyline.cpp b/modules/partyline.cpp index f7e6f4e4..f37add05 100644 --- a/modules/partyline.cpp +++ b/modules/partyline.cpp @@ -41,7 +41,7 @@ protected: set m_ssFixedNicks; }; -class CPartylineMod : public CGlobalModule { +class CPartylineMod : public CModule { public: GLOBALMODCONSTRUCTOR(CPartylineMod) {} diff --git a/modules/webadmin.cpp b/modules/webadmin.cpp index 59c228f0..1418cfb2 100644 --- a/modules/webadmin.cpp +++ b/modules/webadmin.cpp @@ -51,7 +51,7 @@ inline bool FOR_EACH_MODULE_CanContinue(FOR_EACH_MODULE_Type& state, CModules::i if (FOR_EACH_MODULE_Type FOR_EACH_MODULE_Var = pUser) {} else\ for (CModules::iterator I = CZNC::Get().GetModules().begin(); FOR_EACH_MODULE_CanContinue(FOR_EACH_MODULE_Var, I); ++I) -class CWebAdminMod : public CGlobalModule { +class CWebAdminMod : public CModule { public: GLOBALMODCONSTRUCTOR(CWebAdminMod) { VPair vParams; diff --git a/znc.cpp b/znc.cpp index a3a1d4cc..fca9dda8 100644 --- a/znc.cpp +++ b/znc.cpp @@ -27,7 +27,7 @@ CZNC::CZNC() { exit(-1); } - m_pModules = new CGlobalModules(); + m_pModules = new CModules(); m_uiConnectDelay = 5; m_uiAnonIPLimit = 10; m_uBytesRead = 0; @@ -496,7 +496,7 @@ bool CZNC::WriteConfig() { pFile->Write("BindHost = " + m_vsBindHosts[v].FirstLine() + "\n"); } - CGlobalModules& Mods = GetModules(); + CModules& Mods = GetModules(); for (unsigned int a = 0; a < Mods.size(); a++) { CString sName = Mods[a]->GetModName(); diff --git a/znc.h b/znc.h index fc56b8bd..c6e8de15 100644 --- a/znc.h +++ b/znc.h @@ -92,7 +92,7 @@ public: enum ConfigState GetConfigState() const { return m_eConfigState; } CSockManager& GetManager() { return m_Manager; } const CSockManager& GetManager() const { return m_Manager; } - CGlobalModules& GetModules() { return *m_pModules; } + CModules& GetModules() { return *m_pModules; } size_t FilterUncommonModules(set& ssModules); CString GetSkinName() const { return m_sSkinName; } const CString& GetStatusPrefix() const { return m_sStatusPrefix; } @@ -178,7 +178,7 @@ protected: unsigned int m_uiConnectDelay; unsigned int m_uiAnonIPLimit; unsigned int m_uiMaxBufferSize; - CGlobalModules* m_pModules; + CModules* m_pModules; unsigned long long m_uBytesRead; unsigned long long m_uBytesWritten; CConnectUserTimer *m_pConnectUserTimer;