From 23fb4df67aa52667006a5c27335727ff1946730b Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 31 Mar 2011 17:29:49 +0200 Subject: [PATCH] Remove config-related module hooks This removes the following module hooks: OnConfigLine() OnWriteConfig() OnWriteUserConfig() OnWriteChanConfig() Modules could use these hooks for writing/reading their own stuff to/from znc.conf. However, no module (ever?) did this and IMHO no module should ever do this either. Modules can save stuff via SetNV(), module arguments (SetArgs()) and in their GetSavePath(). Signed-off-by: Uli Schlachter --- Chan.cpp | 2 -- Modules.cpp | 11 --------- Modules.h | 39 -------------------------------- User.cpp | 2 -- modules/modperl/functions.in | 3 --- modules/modperl/module.h | 3 --- modules/modperl/startup.pl | 3 --- modules/modpython/functions.in | 3 --- modules/modpython/module.h | 3 --- modules/modpython/znc.py | 3 --- znc.cpp | 41 ---------------------------------- 11 files changed, 113 deletions(-) diff --git a/Chan.cpp b/Chan.cpp index f0867aa3..8d26391f 100644 --- a/Chan.cpp +++ b/Chan.cpp @@ -63,8 +63,6 @@ bool CChan::WriteConfig(CFile& File) { if (!GetDefaultModes().empty()) m_pUser->PrintLine(File, "\tModes", GetDefaultModes()); - MODULECALL(OnWriteChanConfig(File, *this), m_pUser, NULL, NOTHING); - File.Write("\t\n"); return true; } diff --git a/Modules.cpp b/Modules.cpp index de6cade6..ecf0e294 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -464,9 +464,6 @@ CModule::EModRet CModule::OnIRCConnecting(CIRCSock *IRCSock) { return CONTINUE; void CModule::OnIRCConnectionError(CIRCSock *IRCSock) {} CModule::EModRet CModule::OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName) { return CONTINUE; } CModule::EModRet CModule::OnBroadcast(CString& sMessage) { return CONTINUE; } -CModule::EModRet CModule::OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan) { return CONTINUE; } -void CModule::OnWriteUserConfig(CFile& Config) {} -void CModule::OnWriteChanConfig(CFile& Config, CChan& Chan) {} CModule::EModRet CModule::OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) { return CONTINUE; } @@ -564,7 +561,6 @@ bool CModule::PutModNotice(const CString& sLine) { /////////////////// // CGlobalModule // /////////////////// -CModule::EModRet CGlobalModule::OnWriteConfig(CFile& Config) { return CONTINUE; } 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) {} @@ -624,9 +620,6 @@ bool CModules::OnIRCConnecting(CIRCSock *pIRCSock) { MODHALTCHK(OnIRCConnecting( bool CModules::OnIRCConnectionError(CIRCSock *pIRCSock) { MODUNLOADCHK(OnIRCConnectionError(pIRCSock)); return false; } bool CModules::OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName) { MODHALTCHK(OnIRCRegistration(sPass, sNick, sIdent, sRealName)); } bool CModules::OnBroadcast(CString& sMessage) { MODHALTCHK(OnBroadcast(sMessage)); } -bool CModules::OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan) { MODHALTCHK(OnConfigLine(sName, sValue, pUser, pChan)); } -bool CModules::OnWriteUserConfig(CFile& Config) { MODUNLOADCHK(OnWriteUserConfig(Config)); return false; } -bool CModules::OnWriteChanConfig(CFile& Config, CChan& Chan) { MODUNLOADCHK(OnWriteChanConfig(Config, Chan)); return false; } bool CModules::OnIRCDisconnected() { MODUNLOADCHK(OnIRCDisconnected()); return false; } bool CModules::OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) { MODHALTCHK(OnDCCUserSend(RemoteNick, uLongIP, uPort, sFile, uFileSize)); } bool CModules::OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange) { MODUNLOADCHK(OnChanPermission(OpNick, Nick, Channel, uMode, bAdded, bNoChange)); return false; } @@ -708,10 +701,6 @@ bool CModules::OnServerCapResult(const CString& sCap, bool bSuccess) { MODUNLOAD //////////////////// // CGlobalModules // //////////////////// -bool CGlobalModules::OnWriteConfig(CFile& Config) { - GLOBALMODHALTCHK(OnWriteConfig(Config)); -} - bool CGlobalModules::OnAddUser(CUser& User, CString& sErrorRet) { GLOBALMODHALTCHK(OnAddUser(User, sErrorRet)); } diff --git a/Modules.h b/Modules.h index 682f0913..a740184a 100644 --- a/Modules.h +++ b/Modules.h @@ -414,33 +414,6 @@ public: */ virtual EModRet OnBroadcast(CString& sMessage); - /** Called when a module-specific config line is read from znc.conf. - * Module specific config lines are always prefixed with "GM:". - * @param sName Name of the config entry without the "GM:" prefix. - * @param sValue The value of the config entry. - * @param pUser If this line was found in a user section, then this is - * the corresponding CUser instance. - * @param pChan If this line was found in a chan section, then this is - * the corresponding CChan instance. - * @return See CModule::EModRet. - */ - virtual EModRet OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan); - /** Called just before ZNC finishes a user section in the config file. - * This can be used to re-write the "GM:" lines for OnConfigLine() - * which would get lost otherwise. - * @param Config Reference to the CFile which will be used for writing - * the config file. - */ - virtual void OnWriteUserConfig(CFile& Config); - /** Called just before ZNC finishes a chan section in the config file. - * This can be used to re-write the "GM:" lines for OnConfigLine() - * which would get lost otherwise. - * @param Config Reference to the CFile which will be used for writing - * the config file. - * @param Chan The channel which is being written. - */ - virtual void OnWriteChanConfig(CFile& Config, CChan& Chan); - /** This module hook is called when a user sends a DCC SEND request to * your module fake-nickname. */ @@ -921,9 +894,6 @@ public: bool OnIRCConnectionError(CIRCSock *pIRCSock); bool OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName); bool OnBroadcast(CString& sMessage); - bool OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan); - bool OnWriteUserConfig(CFile& Config); - bool OnWriteChanConfig(CFile& Config, CChan& Chan); bool OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize); @@ -1024,14 +994,6 @@ public: const CString &sDataDir) : CModule(pDLL, sModName, sDataDir) {} virtual ~CGlobalModule() {} - /** Called when ZNC starts rewriting the config file. This can be used - * re-write the "GM:" lines for OnConfigLine() which would get lost - * otherwise. - * @param Config Reference to the CFile which will be used for writing - * the config file. - * @return See CModule::EModRet. - */ - virtual EModRet OnWriteConfig(CFile& Config); /** 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 @@ -1129,7 +1091,6 @@ public: CGlobalModules() : CModules() {} ~CGlobalModules() {} - bool OnWriteConfig(CFile& Config); bool OnAddUser(CUser& User, CString& sErrorRet); bool OnDeleteUser(CUser& User); bool OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort); diff --git a/User.cpp b/User.cpp index 382fe33b..b3c28f51 100644 --- a/User.cpp +++ b/User.cpp @@ -720,8 +720,6 @@ bool CUser::WriteConfig(CFile& File) { } } - MODULECALL(OnWriteUserConfig(File), this, NULL, NOTHING); - File.Write("\n"); return true; diff --git a/modules/modperl/functions.in b/modules/modperl/functions.in index 925497f3..0f13a30c 100644 --- a/modules/modperl/functions.in +++ b/modules/modperl/functions.in @@ -13,9 +13,6 @@ EModRet OnIRCConnecting(CIRCSock *pIRCSock) void OnIRCConnectionError(CIRCSock *pIRCSock) EModRet OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName) EModRet OnBroadcast(CString& sMessage) -EModRet OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan) -void OnWriteUserConfig(CFile& Config) -void OnWriteChanConfig(CFile& Config, CChan& Chan) EModRet OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) void OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange) void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) diff --git a/modules/modperl/module.h b/modules/modperl/module.h index 0cfdcaaf..c14285f4 100644 --- a/modules/modperl/module.h +++ b/modules/modperl/module.h @@ -36,9 +36,6 @@ public: virtual void OnIRCConnectionError(CIRCSock *pIRCSock); virtual EModRet OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName); virtual EModRet OnBroadcast(CString& sMessage); - virtual EModRet OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan); - virtual void OnWriteUserConfig(CFile& Config); - virtual void OnWriteChanConfig(CFile& Config, CChan& Chan); virtual EModRet OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize); virtual void OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange); virtual void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange); diff --git a/modules/modperl/startup.pl b/modules/modperl/startup.pl index 871f54d2..6424f93f 100644 --- a/modules/modperl/startup.pl +++ b/modules/modperl/startup.pl @@ -298,9 +298,6 @@ sub OnIRCConnecting {} sub OnIRCConnectionError {} sub OnIRCRegistration {} sub OnBroadcast {} -sub OnConfigLine {} -sub OnWriteUserConfig {} -sub OnWriteChanConfig {} sub OnDCCUserSend {} sub OnChanPermission {} sub OnOp {} diff --git a/modules/modpython/functions.in b/modules/modpython/functions.in index 925497f3..0f13a30c 100644 --- a/modules/modpython/functions.in +++ b/modules/modpython/functions.in @@ -13,9 +13,6 @@ EModRet OnIRCConnecting(CIRCSock *pIRCSock) void OnIRCConnectionError(CIRCSock *pIRCSock) EModRet OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName) EModRet OnBroadcast(CString& sMessage) -EModRet OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan) -void OnWriteUserConfig(CFile& Config) -void OnWriteChanConfig(CFile& Config, CChan& Chan) EModRet OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) void OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange) void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) diff --git a/modules/modpython/module.h b/modules/modpython/module.h index 41991233..d1d7a84d 100644 --- a/modules/modpython/module.h +++ b/modules/modpython/module.h @@ -58,9 +58,6 @@ public: virtual void OnIRCConnectionError(CIRCSock *pIRCSock); virtual EModRet OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName); virtual EModRet OnBroadcast(CString& sMessage); - virtual EModRet OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan); - virtual void OnWriteUserConfig(CFile& Config); - virtual void OnWriteChanConfig(CFile& Config, CChan& Chan); virtual EModRet OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize); virtual void OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange); virtual void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange); diff --git a/modules/modpython/znc.py b/modules/modpython/znc.py index cee1c6b3..0b60f063 100644 --- a/modules/modpython/znc.py +++ b/modules/modpython/znc.py @@ -142,9 +142,6 @@ class Module: def OnIRCConnectionError(self, IRCSock): pass def OnIRCRegistration(self, sPass, sNick, sIdent, sRealName): pass def OnBroadcast(self, sMessage): pass - def OnConfigLine(self, sName, sValue, pUser, pChan): pass - def OnWriteUserConfig(self, Config): pass - def OnWriteChanConfig(self, Config, Chan): pass def OnDCCUserSend(self, RemoteNick, uLongIP, uPort, sFile, uFileSize): pass def OnChanPermission(self, OpNick, Nick, Channel, uMode, bAdded, bNoChange): pass def OnOp(self, OpNick, Nick, Channel, bNoChange): pass diff --git a/znc.cpp b/znc.cpp index d5390d06..346a1c65 100644 --- a/znc.cpp +++ b/znc.cpp @@ -14,17 +14,6 @@ #include "Listener.h" #include -namespace -{ // private namespace for local things - struct CGlobalModuleConfigLine - { - CString m_sName; - CString m_sValue; - CUser *m_pUser; - CChan *m_pChan; - }; -} - static inline CString FormatBindError() { CString sError = (errno == 0 ? CString("unknown error, check the host name") : CString(strerror(errno))); return "Unable to bind [" + sError + "]"; @@ -435,8 +424,6 @@ bool CZNC::WriteConfig() { m_LockFile.Write(MakeConfigHeader() + "\n"); - GLOBALMODULECALL(OnWriteConfig(m_LockFile), NULL, NULL, return false); - m_LockFile.Write("AnonIPLimit = " + CString(m_uiAnonIPLimit) + "\n"); m_LockFile.Write("MaxBufferSize= " + CString(m_uiMaxBufferSize) + "\n"); m_LockFile.Write("SSLCertFile = " + CString(m_sSSLCertFile) + "\n"); @@ -1014,8 +1001,6 @@ bool CZNC::DoRehash(CString& sError) unsigned int uLineNum = 0; MCString msModules; // Modules are queued for later loading - std::list lGlobalModuleConfigLine; - while (File.ReadLine(sLine)) { uLineNum++; @@ -1605,16 +1590,6 @@ bool CZNC::DoRehash(CString& sError) } - if (sName.Equals("GM:", false, 3)) - { // GM: prefix is a pass through to config lines for global modules - CGlobalModuleConfigLine cTmp; - cTmp.m_sName = sName.substr(3, CString::npos); - cTmp.m_sValue = sValue; - cTmp.m_pChan = pChan; - cTmp.m_pUser = pUser; - lGlobalModuleConfigLine.push_back(cTmp); - } - else { sError = "Unhandled line " + CString(uLineNum) + " in config: [" + sLine + "]"; CUtils::PrintError(sError); @@ -1638,22 +1613,6 @@ bool CZNC::DoRehash(CString& sError) CUtils::PrintMessage("Could not unload [" + *it + "]"); } - // last step, throw unhandled config items at global config - for (std::list::iterator it = lGlobalModuleConfigLine.begin(); it != lGlobalModuleConfigLine.end(); ++it) - { - if ((pChan && pChan == it->m_pChan) || (pUser && pUser == it->m_pUser)) - continue; // skip unclosed user or chan - bool bHandled = false; - if (it->m_pUser) { - MODULECALL(OnConfigLine(it->m_sName, it->m_sValue, it->m_pUser, it->m_pChan), it->m_pUser, NULL, bHandled = true); - } else { - GLOBALMODULECALL(OnConfigLine(it->m_sName, it->m_sValue, it->m_pUser, it->m_pChan), it->m_pUser, NULL, bHandled = true); - } - if (!bHandled) { - CUtils::PrintMessage("unhandled global module config line [GM:" + it->m_sName + "] = [" + it->m_sValue + "]"); - } - } - if (pChan) { sError = "Last section not properly closed. File truncated?"; CUtils::PrintError(sError);