From 9ae959b800eb5c47bf1d17a84c9448eb2a7e7382 Mon Sep 17 00:00:00 2001 From: psychon Date: Thu, 8 Jul 2010 16:43:23 +0000 Subject: [PATCH] Do all module calls through the macros This commit should make sure that all module calls are done through either MODULECALL, GLOBALMODULECALL or ALLMODULECALL. Also, in the process some module calls where ("accidentally" ;) ) fixed to set correct values for a global module's m_pUser during a module call. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2076 726aef4b-f618-498e-8847-2d620e286838 --- Client.cpp | 17 ++++++++++------- Listener.cpp | 4 ++-- Modules.cpp | 16 ++++++++++------ Modules.h | 8 ++++---- znc.cpp | 36 ++++++++---------------------------- 5 files changed, 34 insertions(+), 47 deletions(-) diff --git a/Client.cpp b/Client.cpp index f8174dfc..6e586413 100644 --- a/Client.cpp +++ b/Client.cpp @@ -67,9 +67,7 @@ void CClient::ReadLine(const CString& sData) { if (IsAttached()) { MODULECALL(OnUserRaw(sLine), m_pUser, this, return); } else { - if (CZNC::Get().GetModules().OnUnknownUserRaw(this, sLine)) { - return; - } + GLOBALMODULECALL(OnUnknownUserRaw(this, sLine), m_pUser, this, return); } CString sCommand = sLine.Token(0); @@ -639,7 +637,7 @@ void CAuthBase::RefuseLogin(const CString& sReason) { "to login as you, but was rejected [" + sReason + "]."); } - CZNC::Get().GetModules().OnFailedLogin(GetUsername(), GetRemoteIP()); + GLOBALMODULECALL(OnFailedLogin(GetUsername(), GetRemoteIP()), NULL, NULL, ); RefusedLogin(sReason); Invalidate(); } @@ -784,7 +782,7 @@ void CClient::HandleCap(const CString& sLine) if (sSubCmd.Equals("LS")) { SCString ssOfferCaps; - CZNC::Get().GetModules().OnClientCapLs(ssOfferCaps); + GLOBALMODULECALL(OnClientCapLs(ssOfferCaps), m_pUser, this, ); CString sRes; for (SCString::iterator i = ssOfferCaps.begin(); i != ssOfferCaps.end(); ++i) { sRes += *i + " "; @@ -805,7 +803,12 @@ void CClient::HandleCap(const CString& sLine) if (sCap.TrimPrefix("-")) bVal = false; - if ("multi-prefix" != sCap && "userhost-in-names" != sCap && !CZNC::Get().GetModules().IsClientCapSupported(sCap, bVal)) { + bool bAccepted = ("multi-prefix" == sCap) || ("userhost-in-names" == sCap); + if (!bAccepted) { + GLOBALMODULECALL(IsClientCapSupported(sCap, bVal), m_pUser, this, bAccepted = true); + } + + if (!bAccepted) { // Some unsupported capability is requested RespondCap("NAK :" + sLine.Token(2, true).TrimPrefix_n(":")); return; @@ -823,7 +826,7 @@ void CClient::HandleCap(const CString& sLine) } else if ("userhost-in-names" == *it) { m_bUHNames = bVal; } else { - CZNC::Get().GetModules().OnClientCapRequest(this, *it, bVal); + GLOBALMODULECALL(OnClientCapRequest(this, *it, bVal), m_pUser, this, ); } if (bVal) { diff --git a/Listener.cpp b/Listener.cpp index 0eb02b8e..52d66184 100644 --- a/Listener.cpp +++ b/Listener.cpp @@ -49,11 +49,11 @@ bool CRealListener::ConnectionFrom(const CString& sHost, unsigned short uPort) { Csock* CRealListener::GetSockObj(const CString& sHost, unsigned short uPort) { CIncomingConnection *pClient = new CIncomingConnection(sHost, uPort, m_pParent->GetAcceptType()); if (CZNC::Get().AllowConnectionFrom(sHost)) { - CZNC::Get().GetModules().OnClientConnect(pClient, sHost, uPort); + GLOBALMODULECALL(OnClientConnect(pClient, sHost, uPort), NULL, NULL, ); } else { pClient->Write(":irc.znc.in 464 unknown-nick :Too many anonymous connections from your IP\r\n"); pClient->Close(Csock::CLT_AFTERWRITE); - CZNC::Get().GetModules().OnFailedLogin("", sHost); + GLOBALMODULECALL(OnFailedLogin("", sHost), NULL, NULL, ); } return pClient; } diff --git a/Modules.cpp b/Modules.cpp index e10277c6..73d0df93 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -529,7 +529,7 @@ bool CModules::OnBoot() { for (unsigned int a = 0; a < size(); a++) { try { if (!(*this)[a]->OnBoot()) { - return false; + return true; } } catch (CModule::EModException e) { if (e == CModule::UNLOAD) { @@ -538,7 +538,7 @@ bool CModules::OnBoot() { } } - return true; + return false; } bool CModules::OnPreRehash() { MODUNLOADCHK(OnPreRehash()); return false; } @@ -614,24 +614,27 @@ bool CGlobalModules::OnDeleteUser(CUser& User) { GLOBALMODHALTCHK(OnDeleteUser(User)); } -void CGlobalModules::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned short uPort) { +bool CGlobalModules::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned short uPort) { GLOBALMODCALL(OnClientConnect(pClient, sHost, uPort)); + return false; } bool CGlobalModules::OnLoginAttempt(CSmartPtr Auth) { GLOBALMODHALTCHK(OnLoginAttempt(Auth)); } -void CGlobalModules::OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) { +bool CGlobalModules::OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) { GLOBALMODCALL(OnFailedLogin(sUsername, sRemoteIP)); + return false; } bool CGlobalModules::OnUnknownUserRaw(CClient* pClient, CString& sLine) { GLOBALMODHALTCHK(OnUnknownUserRaw(pClient, sLine)); } -void CGlobalModules::OnClientCapLs(SCString& ssCaps) { +bool CGlobalModules::OnClientCapLs(SCString& ssCaps) { GLOBALMODCALL(OnClientCapLs(ssCaps)); + return false; } // Maybe create new macro for this? @@ -661,8 +664,9 @@ bool CGlobalModules::IsClientCapSupported(const CString& sCap, bool bState) { return bResult; } -void CGlobalModules::OnClientCapRequest(CClient* pClient, const CString& sCap, bool bState) { +bool CGlobalModules::OnClientCapRequest(CClient* pClient, const CString& sCap, bool bState) { GLOBALMODCALL(OnClientCapRequest(pClient, sCap, bState)); + return false; } diff --git a/Modules.h b/Modules.h index 51a72b7e..07e164a7 100644 --- a/Modules.h +++ b/Modules.h @@ -988,13 +988,13 @@ public: bool OnWriteConfig(CFile& Config); bool OnAddUser(CUser& User, CString& sErrorRet); bool OnDeleteUser(CUser& User); - void OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort); + bool OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort); bool OnLoginAttempt(CSmartPtr Auth); - void OnFailedLogin(const CString& sUsername, const CString& sRemoteIP); + bool OnFailedLogin(const CString& sUsername, const CString& sRemoteIP); bool OnUnknownUserRaw(CClient* pClient, CString& sLine); - void OnClientCapLs(SCString& ssCaps); + bool OnClientCapLs(SCString& ssCaps); bool IsClientCapSupported(const CString& sCap, bool bState); - void OnClientCapRequest(CClient* pClient, const CString& sCap, bool bState); + bool OnClientCapRequest(CClient* pClient, const CString& sCap, bool bState); private: }; diff --git a/znc.cpp b/znc.cpp index d0b5f950..62a66345 100644 --- a/znc.cpp +++ b/znc.cpp @@ -104,15 +104,7 @@ CString CZNC::GetUptime() const { } bool CZNC::OnBoot() { - if (!GetModules().OnBoot()) { - return false; - } - - for (map::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) { - if (!it->second->GetModules().OnBoot()) { - return false; - } - } + ALLMODULECALL(OnBoot(), return false); return true; } @@ -537,9 +529,7 @@ bool CZNC::WriteConfig() { return false; } - if (GetModules().OnWriteConfig(m_LockFile)) { - return false; - } + GLOBALMODULECALL(OnWriteConfig(m_LockFile), NULL, NULL, return false); m_LockFile.Write("AnonIPLimit = " + CString(m_uiAnonIPLimit) + "\n"); m_LockFile.Write("MaxBufferSize= " + CString(m_uiMaxBufferSize) + "\n"); @@ -1002,11 +992,7 @@ bool CZNC::ParseConfig(const CString& sConfig) bool CZNC::RehashConfig(CString& sError) { - GetModules().OnPreRehash(); - for (map::iterator itb = m_msUsers.begin(); - itb != m_msUsers.end(); ++itb) { - itb->second->GetModules().OnPreRehash(); - } + ALLMODULECALL(OnPreRehash(), ); // This clears m_msDelUsers HandleUserDeletion(); @@ -1016,11 +1002,7 @@ bool CZNC::RehashConfig(CString& sError) m_msUsers.clear(); if (DoRehash(sError)) { - GetModules().OnPostRehash(); - for (map::iterator it = m_msUsers.begin(); - it != m_msUsers.end(); ++it) { - it->second->GetModules().OnPostRehash(); - } + ALLMODULECALL(OnPostRehash(), ); return true; } @@ -1717,7 +1699,7 @@ bool CZNC::DoRehash(CString& sError) 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 { - bHandled = GetModules().OnConfigLine(it->m_sName, it->m_sValue, it->m_pUser, it->m_pChan); + 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 + "]"); @@ -1850,11 +1832,11 @@ bool CZNC::AddUser(CUser* pUser, CString& sErrorRet) { << sErrorRet << "]"); return false; } - if (GetModules().OnAddUser(*pUser, sErrorRet)) { + GLOBALMODULECALL(OnAddUser(*pUser, sErrorRet), pUser, NULL, DEBUG("AddUser [" << pUser->GetUserName() << "] aborted by a module [" << sErrorRet << "]"); return false; - } + ); m_msUsers[pUser->GetUserName()] = pUser; return true; } @@ -1951,9 +1933,7 @@ CZNC::TrafficStatsMap CZNC::GetTrafficStats(TrafficStatsPair &Users, void CZNC::AuthUser(CSmartPtr AuthClass) { // TODO unless the auth module calls it, CUser::IsHostAllowed() is not honoured - if (GetModules().OnLoginAttempt(AuthClass)) { - return; - } + GLOBALMODULECALL(OnLoginAttempt(AuthClass), NULL, NULL, return); CUser* pUser = FindUser(AuthClass->GetUsername());