From c52542e4692ddc21882b8f4aebb3f00e600c226f Mon Sep 17 00:00:00 2001 From: prozacx Date: Thu, 26 May 2005 20:42:13 +0000 Subject: [PATCH] Moved GetDescription() into second argument of MODULEDEFS() git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@366 726aef4b-f618-498e-8847-2d620e286838 --- Modules.cpp | 19 ++++++++++++++----- Modules.h | 20 +++++++++++++++++--- modules/away.cpp | 10 ++++------ modules/email.cpp | 10 ++++------ modules/modperl.cpp | 2 +- modules/raw.cpp | 6 +----- modules/sample.cpp | 6 +----- modules/savebuff.cpp | 10 ++++------ modules/schat.cpp | 10 ++++------ modules/shell.cpp | 6 +----- modules/stickychan.cpp | 7 +------ modules/watch.cpp | 6 +----- 12 files changed, 53 insertions(+), 59 deletions(-) diff --git a/Modules.cpp b/Modules.cpp index f8364be4..a719d7ca 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -280,8 +280,6 @@ void CModule::ListTimers() { const CString& CModule::GetModName() { return m_sModName; } CString CModule::GetModNick() { return ((m_pUser) ? m_pUser->GetStatusPrefix() : "*") + m_sModName; } -CString CModule::GetDescription() { return "Unknown"; } - bool CModule::OnLoad(const CString& sArgs) { return true; } bool CModule::OnBoot() { return true; } void CModule::OnUserAttached() {} @@ -595,6 +593,15 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p return false; } + typedef CString (*sFP)(); + sFP GetDesc = (sFP) dlsym(p, "GetDescription"); + + if (!GetDesc) { + dlclose(p); + sRetMsg = "Could not find GetDescription() in module [" + sModule + "]"; + return false; + } + bool bIsGlobal = IsGlobal(); if ((pUser == NULL) != bIsGlobal) { dlclose(p); @@ -630,6 +637,7 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p pModule = Load(p, m_pZNC, sModule); } + pModule->SetDescription(GetDesc()); push_back(pModule); if (!pModule->OnLoad(sArgs)) { @@ -759,15 +767,16 @@ bool CModules::GetModInfo(CModInfo& ModInfo, const CString& sModule) { return false; } - typedef CModule* (*fp)(void*, CZNC*, const CString&); - fp Load = (fp) dlsym(p, "Load"); + typedef CString (*sFP)(); + sFP GetDescription = (sFP) dlsym(p, "GetDescription"); - if (!Load) { + if (!GetDescription) { dlclose(p); return false; } ModInfo.SetGlobal(IsGlobal()); + ModInfo.SetDescription(GetDescription()); ModInfo.SetName(sModule); ModInfo.SetPath(sModPath); dlclose(p); diff --git a/Modules.h b/Modules.h index 1cea96cd..a5f48e30 100644 --- a/Modules.h +++ b/Modules.h @@ -11,8 +11,9 @@ using std::set; // User Module Macros #define MODCONSTRUCTOR(CLASS) \ CLASS(void *pDLL, CUser* pUser, const CString& sModName) : CModule(pDLL, pUser, sModName) -#define MODULEDEFS(CLASS) \ +#define MODULEDEFS(CLASS, DESCRIPTION) \ extern "C" { \ + CString GetDescription() { return DESCRIPTION; } \ bool IsGlobal() { return false; } \ CModule* Load(void* p, CUser* pUser, const CString& sModName); \ void Unload(CModule* pMod); double GetVersion(); } \ @@ -25,8 +26,9 @@ using std::set; // Global Module Macros #define GLOBALMODCONSTRUCTOR(CLASS) \ CLASS(void *pDLL, CZNC* pZNC, const CString& sModName) : CGlobalModule(pDLL, pZNC, sModName) -#define GLOBALMODULEDEFS(CLASS) \ +#define GLOBALMODULEDEFS(CLASS, DESCRIPTION) \ extern "C" { \ + CString GetDescription() { return DESCRIPTION; } \ bool IsGlobal() { return true; } \ CGlobalModule* Load(void* p, CZNC* pZNC, const CString& sModName); \ void Unload(CGlobalModule* pMod); double GetVersion(); } \ @@ -36,6 +38,7 @@ using std::set; } // !Global Module Macros + //const char* GetDescription() { static char sz[] = DESCRIPTION; return sz; } // Forward Declarations class CZNC; class CUser; @@ -111,6 +114,7 @@ public: // Getters const CString& GetName() const { return m_sName; } const CString& GetPath() const { return m_sPath; } + const CString& GetDescription() const { return m_sDescription; } bool IsSystem() const { return m_bSystem; } bool IsGlobal() const { return m_bGlobal; } // !Getters @@ -118,6 +122,7 @@ public: // Setters void SetName(const CString& s) { m_sName = s; } void SetPath(const CString& s) { m_sPath = s; } + void SetDescription(const CString& s) { m_sDescription = s; } void SetSystem(bool b) { m_bSystem = b; } void SetGlobal(bool b) { m_bGlobal = b; } // !Setters @@ -127,6 +132,7 @@ protected: bool m_bGlobal; CString m_sName; CString m_sPath; + CString m_sDescription; }; class CModule { @@ -148,7 +154,6 @@ public: void SetUser(CUser* pUser); void Unload(); - virtual CString GetDescription(); virtual bool OnLoad(const CString& sArgs); virtual bool OnBoot(); @@ -223,7 +228,16 @@ public: MCString::iterator BeginNV() { return m_mssRegistry.begin(); } void DelNV(MCString::iterator it) { m_mssRegistry.erase(it); } + // Setters + void SetDescription(const CString& s) { m_sDescription = s; } + // !Setters + + // Getters + const CString& GetDescription() const { return m_sDescription; } + // !Getters + protected: + CString m_sDescription; vector m_vTimers; void* m_pDLL; TSocketManager* m_pManager; diff --git a/modules/away.cpp b/modules/away.cpp index 64772a08..225be1bc 100644 --- a/modules/away.cpp +++ b/modules/away.cpp @@ -20,6 +20,9 @@ * * * $Log$ + * Revision 1.14 2005/05/26 20:42:13 prozacx + * Moved GetDescription() into second argument of MODULEDEFS() + * * Revision 1.13 2005/05/15 08:27:27 prozacx * Changed return value from bool to EModRet on most hooks * @@ -182,11 +185,6 @@ public: Away(); } - virtual CString GetDescription() - { - return ( "Stores messages while away, also auto away" ); - } - virtual void OnModCommand( const CString& sCommand ) { CString sCmdName = sCommand.Token(0); @@ -443,5 +441,5 @@ void CAwayJob::RunJob() } } -MODULEDEFS(CAway) +MODULEDEFS(CAway, "Stores messages while away, also auto away") diff --git a/modules/email.cpp b/modules/email.cpp index c4579e1c..a9707638 100644 --- a/modules/email.cpp +++ b/modules/email.cpp @@ -15,6 +15,9 @@ * Author: imaginos * * $Log$ + * Revision 1.8 2005/05/26 20:42:13 prozacx + * Moved GetDescription() into second argument of MODULEDEFS() + * * Revision 1.7 2005/05/08 06:42:02 prozacx * Moved CUtils::ToString() into CString class * @@ -108,11 +111,6 @@ public: } } - virtual CString GetDescription() - { - return ( "Monitors Email activity on local disk /var/mail/user" ); - } - virtual void OnModCommand( const CString& sCommand ); void StartParser(); @@ -287,5 +285,5 @@ void CEmailJob::RunJob() CEmail *p = (CEmail *)m_pModule; p->StartParser(); } -MODULEDEFS(CEmail) +MODULEDEFS(CEmail, "Monitors Email activity on local disk /var/mail/user") diff --git a/modules/modperl.cpp b/modules/modperl.cpp index 82655850..0fa573a1 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -489,7 +489,7 @@ private: }; -GLOBALMODULEDEFS( CModPerl ) +GLOBALMODULEDEFS( CModPerl, "Loads perl scripts as ZNC modules" ) diff --git a/modules/raw.cpp b/modules/raw.cpp index 32d033f5..39bb1a48 100644 --- a/modules/raw.cpp +++ b/modules/raw.cpp @@ -9,10 +9,6 @@ public: MODCONSTRUCTOR(CRawMod) {} virtual ~CRawMod() {} - virtual CString GetDescription() { - return "View all of the raw traffic."; - } - virtual EModRet OnRaw(CString& sLine) { PutModule("IRC -> [" + sLine + "]"); return CONTINUE; @@ -24,5 +20,5 @@ public: } }; -MODULEDEFS(CRawMod) +MODULEDEFS(CRawMod, "View all of the raw traffic") diff --git a/modules/sample.cpp b/modules/sample.cpp index 5f74cf31..21822383 100644 --- a/modules/sample.cpp +++ b/modules/sample.cpp @@ -38,10 +38,6 @@ public: return true; } - virtual CString GetDescription() { - return "To be used as a sample for writing modules."; - } - virtual void OnIRCConnected() { PutModule("You got connected BoyOh."); } @@ -200,5 +196,5 @@ public: } }; -MODULEDEFS(CSampleMod) +MODULEDEFS(CSampleMod, "To be used as a sample for writing modules") diff --git a/modules/savebuff.cpp b/modules/savebuff.cpp index cd7db372..c4f739e5 100644 --- a/modules/savebuff.cpp +++ b/modules/savebuff.cpp @@ -26,6 +26,9 @@ * better solution then plain text. * * $Log$ + * Revision 1.25 2005/05/26 20:42:13 prozacx + * Moved GetDescription() into second argument of MODULEDEFS() + * * Revision 1.24 2005/05/17 17:18:35 prozacx * Changed CChan reference to non-const in all hooks * @@ -242,11 +245,6 @@ public: } } - virtual CString GetDescription() - { - return ( "Stores channel buffers to disk, encrypted." ); - } - virtual void OnModCommand( const CString& sCommand ) { CString::size_type iPos = sCommand.find( " " ); @@ -414,5 +412,5 @@ void CSaveBuffJob::RunJob() p->SaveBufferToDisk(); } -MODULEDEFS(CSaveBuff) +MODULEDEFS(CSaveBuff, "Stores channel buffers to disk, encrypted") diff --git a/modules/schat.cpp b/modules/schat.cpp index d723e7bd..7ff8e441 100644 --- a/modules/schat.cpp +++ b/modules/schat.cpp @@ -18,6 +18,9 @@ using std::pair; * Author: imaginos * * $Log$ + * Revision 1.15 2005/05/26 20:42:13 prozacx + * Moved GetDescription() into second argument of MODULEDEFS() + * * Revision 1.14 2005/05/18 03:22:52 imaginos * bring Csocket up to date, includes new needed function GetSockByFD() * @@ -215,11 +218,6 @@ public: m_pManager->DelSock( a-- ); } } - - virtual CString GetDescription() - { - return ( "Secure cross platform (:P) chat system" ); - } virtual EModRet OnUserRaw( CString & sLine ) { @@ -569,5 +567,5 @@ void CRemMarkerJob::RunJob() // store buffer } -MODULEDEFS(CSChat) +MODULEDEFS(CSChat, "Secure cross platform (:P) chat system") diff --git a/modules/shell.cpp b/modules/shell.cpp index c837f666..987e0514 100644 --- a/modules/shell.cpp +++ b/modules/shell.cpp @@ -98,10 +98,6 @@ public: } } - virtual CString GetDescription() { - return "Gives shell access."; - } - virtual void OnModCommand(const CString& sCommand) { if ((strcasecmp(sCommand.c_str(), "cd") == 0) || (strncasecmp(sCommand.c_str(), "cd ", 3) == 0)) { CString sPath = CUtils::ChangeDir(m_sPath, ((sCommand.length() == 2) ? CString(m_pUser->GetHomePath()) : CString(sCommand.substr(3))), m_pUser->GetHomePath()); @@ -214,5 +210,5 @@ void CExecSock::Disconnected() { m_pParent->PutShell("znc$"); } -MODULEDEFS(CShellMod) +MODULEDEFS(CShellMod, "Gives shell access") diff --git a/modules/stickychan.cpp b/modules/stickychan.cpp index 3ea33b48..45e45dd0 100644 --- a/modules/stickychan.cpp +++ b/modules/stickychan.cpp @@ -20,11 +20,6 @@ public: virtual bool OnLoad(const CString& sArgs); - virtual CString GetDescription() - { - return ( "configless sticky chans, keeps you there very stickily even" ); - } - virtual void OnModCommand( const CString& sCommand ) { CString sCmdName = sCommand.Token(0); @@ -80,4 +75,4 @@ bool CStickyChan::OnLoad(const CString& sArgs) return( true ); } -MODULEDEFS(CStickyChan) +MODULEDEFS(CStickyChan, "configless sticky chans, keeps you there very stickily even") diff --git a/modules/watch.cpp b/modules/watch.cpp index c45f0b38..6882fe0d 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -160,10 +160,6 @@ public: virtual ~CWatcherMod() { } - virtual CString GetDescription() { - return "Copy activity from a specific user into a separate window."; - } - virtual void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs) { Process(OpNick, "* " + OpNick.GetNick() + " sets mode: " + sModes + " " + sArgs + " on " + Channel.GetName(), Channel.GetName()); } @@ -506,4 +502,4 @@ private: CBuffer m_Buffer; }; -MODULEDEFS(CWatcherMod) +MODULEDEFS(CWatcherMod, "Copy activity from a specific user into a separate window")