From ad9f1f8ab9a60391ce93ff9979d8afa58de01789 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 11 Jun 2011 17:19:36 +0700 Subject: [PATCH 1/6] Change a way for modules to provide description. Now there're only 2 functions which modules export: ZNCModVersion() and ZNCModInfo(). ZNCModInfo() returns CModInfo instance, which contains description, globality, function for loading the module. It needs to be deleted afterwise. --- Modules.cpp | 105 ++++++++++++++++++---------------------------------- Modules.h | 82 ++++++++++++++++++++++------------------ 2 files changed, 82 insertions(+), 105 deletions(-) diff --git a/Modules.cpp b/Modules.cpp index aa28c2b2..1692cbad 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -816,16 +816,15 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p GLOBALMODULECALL(OnModuleLoading(sModule, sArgs, bSuccess, sRetMsg), pUser, NULL, return bSuccess); CString sModPath, sDataPath; - CString sDesc; bool bVersionMismatch; - bool bIsGlobal; + CModInfo* Info; if (!FindModPath(sModule, sModPath, sDataPath)) { sRetMsg = "Unable to find module [" + sModule + "]"; return false; } - ModHandle p = OpenModule(sModule, sModPath, bVersionMismatch, bIsGlobal, sDesc, sRetMsg); + ModHandle p = OpenModule(sModule, sModPath, bVersionMismatch, Info, sRetMsg); if (!p) return false; @@ -836,10 +835,11 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p return false; } - if ((pUser == NULL) != bIsGlobal) { + if ((pUser == NULL) != Info->IsGlobal()) { + delete Info; dlclose(p); sRetMsg = "Module [" + sModule + "] is "; - sRetMsg += (bIsGlobal) ? "" : "not "; + sRetMsg += Info->IsGlobal() ? "" : "not "; sRetMsg += "a global module."; return false; } @@ -847,37 +847,19 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p CModule* pModule = NULL; if (pUser) { - typedef CModule* (*fp)(ModHandle, CUser* pUser, - const CString& sModName, const CString& sDataPath); - fp Load = (fp) dlsym(p, "ZNCModLoad"); - - if (!Load) { - dlclose(p); - sRetMsg = "Could not find ZNCModLoad() in module [" + sModule + "]"; - return false; - } - - pModule = Load(p, pUser, sModule, sDataPath); + pModule = Info->GetLoader()(p, pUser, sModule, sDataPath); } else { - typedef CModule* (*fp)(ModHandle, const CString& sModName, - const CString& sDataPath); - fp Load = (fp) dlsym(p, "ZNCModLoad"); - - if (!Load) { - dlclose(p); - sRetMsg = "Could not find ZNCModLoad() in module [" + sModule + "]"; - return false; - } - - pModule = Load(p, sModule, sDataPath); + pModule = Info->GetGlobalLoader()(p, sModule, sDataPath); } - pModule->SetDescription(sDesc); - pModule->SetGlobal(bIsGlobal); + pModule->SetDescription(Info->GetDescription()); + pModule->SetGlobal(Info->IsGlobal()); pModule->SetArgs(sArgs); pModule->SetModPath(CDir::ChangeDir(CZNC::Get().GetCurPath(), sModPath)); push_back(pModule); + delete Info; + bool bLoaded; try { bLoaded = pModule->OnLoad(sArgs, sRetMsg); @@ -923,27 +905,19 @@ bool CModules::UnloadModule(const CString& sModule, CString& sRetMsg) { ModHandle p = pModule->GetDLL(); if (p) { - typedef void (*fp)(CModule*); - fp Unload = (fp)dlsym(p, "ZNCModUnload"); + delete pModule; - if (Unload) { - Unload(pModule); - - for (iterator it = begin(); it != end(); ++it) { - if (*it == pModule) { - erase(it); - break; - } + for (iterator it = begin(); it != end(); ++it) { + if (*it == pModule) { + erase(it); + break; } - - dlclose(p); - sRetMsg = "Module [" + sMod + "] unloaded"; - - return true; - } else { - sRetMsg = "Unable to unload module [" + sMod + "] could not find ZNCModUnload()"; - return false; } + + dlclose(p); + sRetMsg = "Module [" + sMod + "] unloaded"; + + return true; } sRetMsg = "Unable to unload module [" + sMod + "]"; @@ -980,17 +954,18 @@ bool CModules::GetModInfo(CModInfo& ModInfo, const CString& sModule, CString& sR } bool CModules::GetModPathInfo(CModInfo& ModInfo, const CString& sModule, const CString& sModPath, CString& sRetMsg) { - CString sDesc; bool bVersionMismatch; - bool bIsGlobal; + CModInfo* Info; - ModHandle p = OpenModule(sModule, sModPath, bVersionMismatch, bIsGlobal, sDesc, sRetMsg); + ModHandle p = OpenModule(sModule, sModPath, bVersionMismatch, Info, sRetMsg); if (!p) return false; - ModInfo.SetGlobal(bIsGlobal); - ModInfo.SetDescription(sDesc); + if (Info) { + ModInfo.SetGlobal(Info->IsGlobal()); + ModInfo.SetDescription(Info->GetDescription()); + } ModInfo.SetName(sModule); ModInfo.SetPath(sModPath); @@ -998,6 +973,7 @@ bool CModules::GetModPathInfo(CModInfo& ModInfo, const CString& sModule, const C ModInfo.SetDescription("--- Version mismatch, recompile this module. ---"); } + delete Info; dlclose(p); return true; @@ -1082,11 +1058,10 @@ CModules::ModDirList CModules::GetModDirs() { } ModHandle CModules::OpenModule(const CString& sModule, const CString& sModPath, bool &bVersionMismatch, - bool &bIsGlobal, CString& sDesc, CString& sRetMsg) { + CModInfo*& Info, CString& sRetMsg) { // Some sane defaults in case anything errors out below bVersionMismatch = false; - bIsGlobal = false; - sDesc.clear(); + Info = NULL; sRetMsg.clear(); for (unsigned int a = 0; a < sModule.length(); a++) { @@ -1124,21 +1099,12 @@ ModHandle CModules::OpenModule(const CString& sModule, const CString& sModPath, return NULL; } - typedef bool (*bFP)(); - bFP IsGlobal = (bFP) dlsym(p, "ZNCModGlobal"); + typedef CModInfo* (*InfoFP)(); + InfoFP ZNCModInfo = (InfoFP) dlsym(p, "ZNCModInfo"); - if (!IsGlobal) { + if (!ZNCModInfo) { dlclose(p); - sRetMsg = "Could not find ZNCModGlobal() in module [" + sModule + "]"; - return NULL; - } - - typedef const char *(*sFP)(); - sFP GetDesc = (sFP) dlsym(p, "ZNCModDescription"); - - if (!GetDesc) { - dlclose(p); - sRetMsg = "Could not find ZNCModDescription() in module [" + sModule + "]"; + sRetMsg = "Could not find ZNCModInfo() in module [" + sModule + "]"; return NULL; } @@ -1146,10 +1112,9 @@ ModHandle CModules::OpenModule(const CString& sModule, const CString& sModPath, bVersionMismatch = true; sRetMsg = "Version mismatch, recompile this module."; } else { + Info = ZNCModInfo(); sRetMsg = ""; bVersionMismatch = false; - bIsGlobal = IsGlobal(); - sDesc = GetDesc(); } return p; diff --git a/Modules.h b/Modules.h index 9b50fab2..f216b6d3 100644 --- a/Modules.h +++ b/Modules.h @@ -24,6 +24,9 @@ class CClient; class CWebSock; class CTemplate; class CIRCSock; +class CModule; +class CGlobalModule; +class CModInfo; // !Forward Declarations // User Module Macros @@ -39,13 +42,28 @@ class CIRCSock; typedef void* ModHandle; -#define MODCOMMONDEFS(DESCRIPTION, GLOBAL) \ - const char *ZNCModDescription(); \ - bool ZNCModGlobal(); \ - double ZNCModVersion(); \ - const char *ZNCModDescription() { return DESCRIPTION; } \ - double ZNCModVersion() { return VERSION; } \ - bool ZNCModGlobal() { return GLOBAL; } \ +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, + const CString& sModName, const CString& sModPath) { + return new M(p, sModName, sModPath); +} + +#define MODCOMMONDEFS(CLASS, DESCRIPTION, GLOBAL, LOADER) \ + extern "C" { \ + double ZNCModVersion(); \ + double ZNCModVersion() { return VERSION; } \ + CModInfo* ZNCModInfo(); \ + CModInfo* ZNCModInfo() { \ + CModInfo* Info = new CModInfo(); \ + Info->SetDescription(DESCRIPTION); \ + Info->SetGlobal(GLOBAL); \ + LOADER; \ + return Info; \ + } \ + } /** Instead of writing a constructor, you should call this macro. It accepts all * the necessary arguments and passes them on to CModule's constructor. You @@ -75,17 +93,7 @@ typedef void* ModHandle; * @see For global modules you need GLOBALMODULEDEFS. */ #define MODULEDEFS(CLASS, DESCRIPTION) \ - extern "C" { \ - MODCOMMONDEFS(DESCRIPTION, false) \ - /* First the definitions to shut up some compiler warnings */ \ - CModule* ZNCModLoad(ModHandle p, CUser* pUser, const CString& sModName, \ - const CString& sModPath); \ - void ZNCModUnload(CModule* pMod); \ - CModule* ZNCModLoad(ModHandle p, CUser* pUser, const CString& sModName, \ - const CString& sModPath) \ - { return new CLASS(p, pUser, sModName, sModPath); } \ - void ZNCModUnload(CModule* pMod) { if (pMod) { delete pMod; } } \ - } + MODCOMMONDEFS(CLASS, DESCRIPTION, false, Info->SetLoader(TModLoad)) // !User Module Macros // Global Module Macros @@ -96,17 +104,7 @@ typedef void* ModHandle; /** This works exactly like MODULEDEFS, but for global modules. */ #define GLOBALMODULEDEFS(CLASS, DESCRIPTION) \ - extern "C" { \ - MODCOMMONDEFS(DESCRIPTION, true) \ - /* First the definitions to shut up some compiler warnings */ \ - CGlobalModule* ZNCModLoad(ModHandle p, const CString& sModName, \ - const CString& sModPath); \ - void ZNCModUnload(CGlobalModule* pMod); \ - CGlobalModule* ZNCModLoad(ModHandle p, const CString& sModName, \ - const CString& sModPath) \ - { return new CLASS(p, sModName, sModPath); } \ - void ZNCModUnload(CGlobalModule* pMod) { if (pMod) { delete pMod; } } \ - } + MODCOMMONDEFS(CLASS, DESCRIPTION, true, Info->SetGlobalLoader(TModLoadGlobal)) // !Global Module Macros // Forward Declarations @@ -166,11 +164,19 @@ private: class CModInfo { public: - CModInfo() {} + typedef CModule* (*ModLoader)(ModHandle p, CUser* pUser, const CString& sModName, const CString& sModPath); + typedef CGlobalModule* (*GlobalModLoader)(ModHandle p, const CString& sModName, const CString& sModPath); + + CModInfo() { + m_fGlobalLoader = NULL; + m_fLoader = NULL; + } CModInfo(const CString& sName, const CString& sPath, bool bGlobal) { m_bGlobal = bGlobal; m_sName = sName; m_sPath = sPath; + m_fGlobalLoader = NULL; + m_fLoader = NULL; } ~CModInfo() {} @@ -183,6 +189,8 @@ public: const CString& GetPath() const { return m_sPath; } const CString& GetDescription() const { return m_sDescription; } bool IsGlobal() const { return m_bGlobal; } + ModLoader GetLoader() const { return m_fLoader; } + GlobalModLoader GetGlobalLoader() const { return m_fGlobalLoader; } // !Getters // Setters @@ -190,13 +198,17 @@ public: void SetPath(const CString& s) { m_sPath = s; } void SetDescription(const CString& s) { m_sDescription = s; } void SetGlobal(bool b) { m_bGlobal = b; } + void SetLoader(ModLoader fLoader) { m_fLoader = fLoader; } + void SetGlobalLoader(GlobalModLoader fGlobalLoader) { m_fGlobalLoader = fGlobalLoader; } // !Setters private: protected: - bool m_bGlobal; - CString m_sName; - CString m_sPath; - CString m_sDescription; + bool m_bGlobal; + CString m_sName; + CString m_sPath; + CString m_sDescription; + ModLoader m_fLoader; + GlobalModLoader m_fGlobalLoader; }; /** A helper class for handling commands in modules. */ @@ -964,7 +976,7 @@ public: private: static ModHandle OpenModule(const CString& sModule, const CString& sModPath, - bool &bVersionMismatch, bool &bIsGlobal, CString& sDesc, CString& sRetMsg); + bool &bVersionMismatch, CModInfo*& Info, CString& sRetMsg); protected: CUser* m_pUser; From e6e3331457aa50051b2cc9af2816c379e9e95227 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 11 Jun 2011 17:28:15 +0700 Subject: [PATCH 2/6] Add a way for module to customize additional info. For that you need to write a specialization of template function void TModInfo(CModInfo&), and inside it put needed values to the argument. --- Modules.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules.h b/Modules.h index f216b6d3..cc495426 100644 --- a/Modules.h +++ b/Modules.h @@ -42,6 +42,8 @@ class CModInfo; typedef void* ModHandle; +template void TModInfo(CModInfo& Info) {} + template CModule* TModLoad(ModHandle p, CUser* pUser, const CString& sModName, const CString& sModPath) { return new M(p, pUser, sModName, sModPath); @@ -61,6 +63,7 @@ template CGlobalModule* TModLoadGlobal(ModHandle p, Info->SetDescription(DESCRIPTION); \ Info->SetGlobal(GLOBAL); \ LOADER; \ + TModInfo(*Info); \ return Info; \ } \ } From 0c840f922d177ab356095589b5941a5208847417 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 11 Jun 2011 17:46:37 +0700 Subject: [PATCH 3/6] Modules can now provide its wiki page name. It's shown on webadmin as a link. --- Modules.cpp | 3 +-- Modules.h | 3 +++ modules/data/webadmin/tmpl/add_edit_user.tmpl | 2 +- modules/data/webadmin/tmpl/settings.tmpl | 2 +- modules/webadmin.cpp | 2 ++ 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Modules.cpp b/Modules.cpp index 1692cbad..f5d26d92 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -963,8 +963,7 @@ bool CModules::GetModPathInfo(CModInfo& ModInfo, const CString& sModule, const C return false; if (Info) { - ModInfo.SetGlobal(Info->IsGlobal()); - ModInfo.SetDescription(Info->GetDescription()); + ModInfo = *Info; } ModInfo.SetName(sModule); ModInfo.SetPath(sModPath); diff --git a/Modules.h b/Modules.h index cc495426..8593a462 100644 --- a/Modules.h +++ b/Modules.h @@ -191,6 +191,7 @@ public: const CString& GetName() const { return m_sName; } const CString& GetPath() const { return m_sPath; } const CString& GetDescription() const { return m_sDescription; } + const CString& GetWikiPage() const { return m_sWikiPage; } bool IsGlobal() const { return m_bGlobal; } ModLoader GetLoader() const { return m_fLoader; } GlobalModLoader GetGlobalLoader() const { return m_fGlobalLoader; } @@ -200,6 +201,7 @@ public: 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 SetWikiPage(const CString& s) { m_sWikiPage = s; } void SetGlobal(bool b) { m_bGlobal = b; } void SetLoader(ModLoader fLoader) { m_fLoader = fLoader; } void SetGlobalLoader(GlobalModLoader fGlobalLoader) { m_fGlobalLoader = fGlobalLoader; } @@ -210,6 +212,7 @@ protected: CString m_sName; CString m_sPath; CString m_sDescription; + CString m_sWikiPage; ModLoader m_fLoader; GlobalModLoader m_fGlobalLoader; }; diff --git a/modules/data/webadmin/tmpl/add_edit_user.tmpl b/modules/data/webadmin/tmpl/add_edit_user.tmpl index ab489087..ab7c1310 100644 --- a/modules/data/webadmin/tmpl/add_edit_user.tmpl +++ b/modules/data/webadmin/tmpl/add_edit_user.tmpl @@ -136,7 +136,7 @@ - checked="checked" disabled="disabled" /> + checked="checked" disabled="disabled" /> diff --git a/modules/data/webadmin/tmpl/settings.tmpl b/modules/data/webadmin/tmpl/settings.tmpl index e0681d4b..4828267a 100644 --- a/modules/data/webadmin/tmpl/settings.tmpl +++ b/modules/data/webadmin/tmpl/settings.tmpl @@ -132,7 +132,7 @@ - checked="checked" disabled="disabled" /> + checked="checked" disabled="disabled" /> diff --git a/modules/webadmin.cpp b/modules/webadmin.cpp index bc5e6c1b..543a2221 100644 --- a/modules/webadmin.cpp +++ b/modules/webadmin.cpp @@ -745,6 +745,7 @@ public: l["Name"] = Info.GetName(); l["Description"] = Info.GetDescription(); l["Args"] = GetModArgs(pUser, Info.GetName()); + l["Wiki"] = Info.GetWikiPage(); if (pUser && pUser->GetModules().FindModule(Info.GetName())) { l["Checked"] = "true"; @@ -1039,6 +1040,7 @@ public: l["Name"] = Info.GetName(); l["Description"] = Info.GetDescription(); l["Args"] = GetModArgs(NULL, Info.GetName(), true); + l["Wiki"] = Info.GetWikiPage(); } return true; From 262216731b742a2888b3363facb19115671470b8 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 11 Jun 2011 18:09:56 +0700 Subject: [PATCH 4/6] Add link to wiki page from any nonextra module. --- modules/admin.cpp | 4 ++++ modules/adminlog.cpp | 4 ++++ modules/autoattach.cpp | 4 ++++ modules/autocycle.cpp | 4 ++++ modules/autoop.cpp | 4 ++++ modules/autoreply.cpp | 4 ++++ modules/awaynick.cpp | 4 ++++ modules/blockuser.cpp | 4 ++++ modules/buffextras.cpp | 4 ++++ modules/cert.cpp | 4 ++++ modules/certauth.cpp | 4 ++++ modules/chansaver.cpp | 4 ++++ modules/clientnotify.cpp | 4 ++++ modules/crypt.cpp | 4 ++++ modules/disconkick.cpp | 4 ++++ modules/fail2ban.cpp | 4 ++++ modules/fixfreenode.cpp | 4 ++++ modules/identfile.cpp | 4 ++++ modules/keepnick.cpp | 4 ++++ modules/kickrejoin.cpp | 4 ++++ modules/lastseen.cpp | 4 ++++ modules/modperl.cpp | 4 ++++ modules/modpython.cpp | 4 ++++ modules/modtcl.cpp | 4 ++++ modules/nickserv.cpp | 4 ++++ modules/notes.cpp | 4 ++++ modules/partyline.cpp | 4 ++++ modules/perform.cpp | 4 ++++ modules/q.cpp | 4 ++++ modules/raw.cpp | 4 ++++ modules/route_replies.cpp | 4 ++++ modules/sample.cpp | 4 ++++ modules/savebuff.cpp | 4 ++++ modules/schat.cpp | 5 +++++ modules/simple_away.cpp | 3 +++ modules/stickychan.cpp | 4 ++++ modules/watch.cpp | 4 ++++ modules/webadmin.cpp | 4 ++++ 38 files changed, 152 insertions(+) diff --git a/modules/admin.cpp b/modules/admin.cpp index 37b46c17..aaaf6a37 100644 --- a/modules/admin.cpp +++ b/modules/admin.cpp @@ -857,4 +857,8 @@ public: virtual ~CAdminMod() {} }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("admin"); +} + MODULEDEFS(CAdminMod, "Dynamic configuration of users/settings through IRC") diff --git a/modules/adminlog.cpp b/modules/adminlog.cpp index fa21e1ae..64bc9b42 100644 --- a/modules/adminlog.cpp +++ b/modules/adminlog.cpp @@ -163,4 +163,8 @@ private: CString m_sLogFile; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("adminlog"); +} + GLOBALMODULEDEFS(CAdminLogMod, "Log ZNC events to file and/or syslog.") diff --git a/modules/autoattach.cpp b/modules/autoattach.cpp index bd54863b..3dfd136a 100644 --- a/modules/autoattach.cpp +++ b/modules/autoattach.cpp @@ -246,4 +246,8 @@ private: VAttachMatch m_vMatches; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("autoattach"); +} + MODULEDEFS(CChanAttach, "Reattaches you to channels on activity.") diff --git a/modules/autocycle.cpp b/modules/autocycle.cpp index db7a19bd..969cf81a 100644 --- a/modules/autocycle.cpp +++ b/modules/autocycle.cpp @@ -224,4 +224,8 @@ private: vector m_vsNegChans; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("autocycle"); +} + MODULEDEFS(CAutoCycleMod, "Rejoins channels to gain Op if you're the only user left") diff --git a/modules/autoop.cpp b/modules/autoop.cpp index b48cbb52..ebbf34d2 100644 --- a/modules/autoop.cpp +++ b/modules/autoop.cpp @@ -463,4 +463,8 @@ void CAutoOpTimer::RunJob() { m_pParent->ProcessQueue(); } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("autoop"); +} + MODULEDEFS(CAutoOpMod, "Auto op the good guys") diff --git a/modules/autoreply.cpp b/modules/autoreply.cpp index d76f298e..72145264 100644 --- a/modules/autoreply.cpp +++ b/modules/autoreply.cpp @@ -88,5 +88,9 @@ private: TCacheMap m_Messaged; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("autoreply"); +} + MODULEDEFS(CAutoReplyMod, "Reply to queries when you are away") diff --git a/modules/awaynick.cpp b/modules/awaynick.cpp index 82a22d1b..298f90ed 100644 --- a/modules/awaynick.cpp +++ b/modules/awaynick.cpp @@ -186,4 +186,8 @@ void CAwayNickTimer::RunJob() { } } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("awaynick"); +} + MODULEDEFS(CAwayNickMod, "Change your nick while you are away") diff --git a/modules/blockuser.cpp b/modules/blockuser.cpp index f5a6d881..e43d28e4 100644 --- a/modules/blockuser.cpp +++ b/modules/blockuser.cpp @@ -168,4 +168,8 @@ private: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("blockuser"); +} + GLOBALMODULEDEFS(CBlockUser, "Block certain users from logging in") diff --git a/modules/buffextras.cpp b/modules/buffextras.cpp index 0f1b6e8a..02655f9f 100644 --- a/modules/buffextras.cpp +++ b/modules/buffextras.cpp @@ -66,5 +66,9 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("buffextras"); +} + MODULEDEFS(CBuffExtras, "Add joins, parts etc. to the playback buffer") diff --git a/modules/cert.cpp b/modules/cert.cpp index 656a61ce..07fb5a97 100644 --- a/modules/cert.cpp +++ b/modules/cert.cpp @@ -85,4 +85,8 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("cert"); +} + MODULEDEFS(CCertMod, "Use a ssl certificate to connect to a server") diff --git a/modules/certauth.cpp b/modules/certauth.cpp index ec42cd66..96d870e3 100644 --- a/modules/certauth.cpp +++ b/modules/certauth.cpp @@ -276,4 +276,8 @@ private: MSCString m_PubKeys; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("certauth"); +} + GLOBALMODULEDEFS(CSSLClientCertMod, "Allow users to authenticate via SSL client certificates") diff --git a/modules/chansaver.cpp b/modules/chansaver.cpp index 7223aa0c..1da6614a 100644 --- a/modules/chansaver.cpp +++ b/modules/chansaver.cpp @@ -72,4 +72,8 @@ private: bool m_bWriteConf; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("chansaver"); +} + MODULEDEFS(CChanSaverMod, "Keep config up-to-date when user joins/parts") diff --git a/modules/clientnotify.cpp b/modules/clientnotify.cpp index ff3fea15..59b1c085 100644 --- a/modules/clientnotify.cpp +++ b/modules/clientnotify.cpp @@ -102,5 +102,9 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("clientnotify"); +} + MODULEDEFS(CClientNotifyMod, "Notifies you when another IRC client logs into or out of your account. Configurable.") diff --git a/modules/crypt.cpp b/modules/crypt.cpp index a5ef87f3..e492d521 100644 --- a/modules/crypt.cpp +++ b/modules/crypt.cpp @@ -151,4 +151,8 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("crypt"); +} + MODULEDEFS(CCryptMod, "Encryption for channel/private messages") diff --git a/modules/disconkick.cpp b/modules/disconkick.cpp index 619d610c..60938122 100644 --- a/modules/disconkick.cpp +++ b/modules/disconkick.cpp @@ -29,4 +29,8 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("disconkick"); +} + MODULEDEFS(CKickClientOnIRCDisconnect, "Kicks the client from all channels when the connection to the IRC server is lost") diff --git a/modules/fail2ban.cpp b/modules/fail2ban.cpp index 9e2e9a6a..a1595b0b 100644 --- a/modules/fail2ban.cpp +++ b/modules/fail2ban.cpp @@ -95,4 +95,8 @@ private: unsigned int m_uiAllowedFailed; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("fail2ban"); +} + GLOBALMODULEDEFS(CFailToBanMod, "Block IPs for some time after a failed login") diff --git a/modules/fixfreenode.cpp b/modules/fixfreenode.cpp index a14b52ac..f737c495 100644 --- a/modules/fixfreenode.cpp +++ b/modules/fixfreenode.cpp @@ -22,4 +22,8 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("fixfreenode"); +} + MODULEDEFS(CPreventIdMsgMod, "Prevent client from sending IDENTIFY-MSG to server") diff --git a/modules/identfile.cpp b/modules/identfile.cpp index f7111b66..05a61be9 100644 --- a/modules/identfile.cpp +++ b/modules/identfile.cpp @@ -162,4 +162,8 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("identfile"); +} + GLOBALMODULEDEFS(CIdentFileModule, "Write the ident of a user to a file when they are trying to connect") diff --git a/modules/keepnick.cpp b/modules/keepnick.cpp index 3a8a18ac..601607b3 100644 --- a/modules/keepnick.cpp +++ b/modules/keepnick.cpp @@ -192,4 +192,8 @@ void CKeepNickTimer::RunJob() { m_pMod->KeepNick(); } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("keepnick"); +} + MODULEDEFS(CKeepNickMod, "Keep trying for your primary nick") diff --git a/modules/kickrejoin.cpp b/modules/kickrejoin.cpp index 3a4f3cf0..68b05c23 100644 --- a/modules/kickrejoin.cpp +++ b/modules/kickrejoin.cpp @@ -108,4 +108,8 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("kickrejoin"); +} + MODULEDEFS(CRejoinMod, "Autorejoin on kick") diff --git a/modules/lastseen.cpp b/modules/lastseen.cpp index 500f93a3..49a79ab2 100644 --- a/modules/lastseen.cpp +++ b/modules/lastseen.cpp @@ -148,4 +148,8 @@ public: }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("lastseen"); +} + GLOBALMODULEDEFS(CLastSeenMod, "Collects data about when a user last logged in") diff --git a/modules/modperl.cpp b/modules/modperl.cpp index 1dc46d77..1c3aa2ed 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -316,4 +316,8 @@ CPerlSocket::~CPerlSocket() { } } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("modperl"); +} + GLOBALMODULEDEFS(CModPerl, "Loads perl scripts as ZNC modules") diff --git a/modules/modpython.cpp b/modules/modpython.cpp index 2f597c89..3b12de54 100644 --- a/modules/modpython.cpp +++ b/modules/modpython.cpp @@ -478,4 +478,8 @@ PyObject* CPySocket::WriteBytes(PyObject* data) { } } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("modpython"); +} + GLOBALMODULEDEFS(CModPython, "Loads python scripts as ZNC modules") diff --git a/modules/modtcl.cpp b/modules/modtcl.cpp index 918ad871..0ba8a82f 100644 --- a/modules/modtcl.cpp +++ b/modules/modtcl.cpp @@ -494,4 +494,8 @@ void CModTclStartTimer::RunJob() { p->Start(); } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("modtcl"); +} + MODULEDEFS(CModTcl, "Loads Tcl scripts as ZNC modules") diff --git a/modules/nickserv.cpp b/modules/nickserv.cpp index 90d615e7..05da5b35 100644 --- a/modules/nickserv.cpp +++ b/modules/nickserv.cpp @@ -76,4 +76,8 @@ private: CString m_sPass; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("nickserv"); +} + MODULEDEFS(CNickServ, "Auths you with NickServ") diff --git a/modules/notes.cpp b/modules/notes.cpp index 553157e1..37dd7983 100644 --- a/modules/notes.cpp +++ b/modules/notes.cpp @@ -212,4 +212,8 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("notes"); +} + MODULEDEFS(CNotesMod, "Keep and replay notes") diff --git a/modules/partyline.cpp b/modules/partyline.cpp index 2624b819..f7e6f4e4 100644 --- a/modules/partyline.cpp +++ b/modules/partyline.cpp @@ -715,4 +715,8 @@ private: set m_ssDefaultChans; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("partyline"); +} + GLOBALMODULEDEFS(CPartylineMod, "Internal channels and queries for users connected to znc") diff --git a/modules/perform.cpp b/modules/perform.cpp index 6e62c733..e1ce0bf2 100644 --- a/modules/perform.cpp +++ b/modules/perform.cpp @@ -166,4 +166,8 @@ private: VCString m_vPerform; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("perform"); +} + MODULEDEFS(CPerform, "Keeps a list of commands to be executed when ZNC connects to IRC.") diff --git a/modules/q.cpp b/modules/q.cpp index 2ca11cf5..157eb36f 100644 --- a/modules/q.cpp +++ b/modules/q.cpp @@ -483,4 +483,8 @@ private: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("Q"); +} + MODULEDEFS(CQModule, "Auths you with QuakeNet's Q bot.") diff --git a/modules/raw.cpp b/modules/raw.cpp index 143dc70e..237c99ad 100644 --- a/modules/raw.cpp +++ b/modules/raw.cpp @@ -28,5 +28,9 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("raw"); +} + MODULEDEFS(CRawMod, "View all of the raw traffic") diff --git a/modules/route_replies.cpp b/modules/route_replies.cpp index 6ac8feac..925e8893 100644 --- a/modules/route_replies.cpp +++ b/modules/route_replies.cpp @@ -422,4 +422,8 @@ void CRouteTimeout::RunJob() pMod->Timeout(); } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("route_replies"); +} + MODULEDEFS(CRouteRepliesMod, "Send replies (e.g. to /who) to the right client only") diff --git a/modules/sample.cpp b/modules/sample.cpp index 5c48f6b3..68d5bc4f 100644 --- a/modules/sample.cpp +++ b/modules/sample.cpp @@ -230,5 +230,9 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("sample"); +} + MODULEDEFS(CSampleMod, "To be used as a sample for writing modules") diff --git a/modules/savebuff.cpp b/modules/savebuff.cpp index 9490336a..5083b18d 100644 --- a/modules/savebuff.cpp +++ b/modules/savebuff.cpp @@ -335,5 +335,9 @@ void CSaveBuffJob::RunJob() p->SaveBufferToDisk(); } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("savebuff"); +} + MODULEDEFS(CSaveBuff, "Stores channel buffers to disk, encrypted") diff --git a/modules/schat.cpp b/modules/schat.cpp index 6d50f46d..bdfa78c9 100644 --- a/modules/schat.cpp +++ b/modules/schat.cpp @@ -463,5 +463,10 @@ void CRemMarkerJob::RunJob() // store buffer } + +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("schat"); +} + MODULEDEFS(CSChat, "Secure cross platform (:P) chat system") diff --git a/modules/simple_away.cpp b/modules/simple_away.cpp index 88df0873..bf0ded7f 100644 --- a/modules/simple_away.cpp +++ b/modules/simple_away.cpp @@ -216,5 +216,8 @@ void CSimpleAwayJob::RunJob() { ((CSimpleAway*)m_pModule)->SetAway(false); } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("simple_away"); +} MODULEDEFS(CSimpleAway, "Auto away when last client disconnects") diff --git a/modules/stickychan.cpp b/modules/stickychan.cpp index f57c9edf..5c7a9f0c 100644 --- a/modules/stickychan.cpp +++ b/modules/stickychan.cpp @@ -187,4 +187,8 @@ bool CStickyChan::OnLoad(const CString& sArgs, CString& sMessage) return(true); } +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("stickychan"); +} + MODULEDEFS(CStickyChan, "configless sticky chans, keeps you there very stickily even") diff --git a/modules/watch.cpp b/modules/watch.cpp index 4f778b11..62573321 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -550,4 +550,8 @@ private: CBuffer m_Buffer; }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("watch"); +} + MODULEDEFS(CWatcherMod, "Copy activity from a specific user into a separate window") diff --git a/modules/webadmin.cpp b/modules/webadmin.cpp index 543a2221..40c22316 100644 --- a/modules/webadmin.cpp +++ b/modules/webadmin.cpp @@ -1126,4 +1126,8 @@ public: } }; +template<> void TModInfo(CModInfo& Info) { + Info.SetWikiPage("webadmin"); +} + GLOBALMODULEDEFS(CWebAdminMod, "Web based administration module") From 79e78608b3b12ca039472b535fed618b2f5faa79 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 11 Jun 2011 18:21:06 +0700 Subject: [PATCH 5/6] Support wiki pages names for perl modules. --- modules/modperl.cpp | 6 ++++-- modules/modperl/startup.pl | 8 ++++++-- modules/perleval.pm | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/modperl.cpp b/modules/modperl.cpp index 1c3aa2ed..2fdf7800 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -147,11 +147,12 @@ public: break; case Perl_Loaded: result = HALT; - if (3 == ret) { + if (4 == ret) { ModInfo.SetGlobal(false); ModInfo.SetDescription(PString(ST(2))); ModInfo.SetName(sModule); ModInfo.SetPath(PString(ST(1))); + ModInfo.SetWikiPage(PString(ST(3))); bSuccess = true; } else { bSuccess = false; @@ -201,11 +202,12 @@ public: PUSH_STR(sPath); PUSH_STR(sName); PCALL("ZNC::Core::ModInfoByPath"); - if (!SvTRUE(ERRSV) && ret == 1) { + if (!SvTRUE(ERRSV) && ret == 2) { ModInfo.SetGlobal(false); ModInfo.SetDescription(PString(ST(0))); ModInfo.SetName(sName); ModInfo.SetPath(sPath); + ModInfo.SetWikiPage(PString(ST(1))); ssMods.insert(ModInfo); } PEND; diff --git a/modules/modperl/startup.pl b/modules/modperl/startup.pl index 501ad4d3..0e8cee5d 100644 --- a/modules/modperl/startup.pl +++ b/modules/modperl/startup.pl @@ -154,7 +154,7 @@ sub GetModInfo { return ($ZNC::Perl_LoadError, "Incorrect perl module.") unless IsModule $modpath, $modname; require $modpath; my $pmod = bless {}, $modname; - return ($ZNC::Perl_Loaded, $modpath, $pmod->description) + return ($ZNC::Perl_Loaded, $modpath, $pmod->description, $pmod->wiki_page) } sub ModInfoByPath { @@ -162,7 +162,7 @@ sub ModInfoByPath { die "Incorrect perl module." unless IsModule $modpath, $modname; require $modpath; my $pmod = bless {}, $modname; - return ($pmod->description) + return ($pmod->description, $pmod->wiki_page) } sub CallModFunc { @@ -279,6 +279,10 @@ sub description { "< Placeholder for a description >" } +sub wiki_page { + '' +} + # Default implementations for module hooks. They can be overriden in derived modules. sub OnLoad {1} sub OnBoot {} diff --git a/modules/perleval.pm b/modules/perleval.pm index ffba9ad8..4ec2139a 100644 --- a/modules/perleval.pm +++ b/modules/perleval.pm @@ -8,6 +8,10 @@ sub description { 'Evaluates perl code' } +sub wiki_page { + 'perleval' +} + sub OnLoad { my $self = shift; if (!$self->GetUser->IsAdmin) { From f7c4f5459c681fef86003dbc57f24ba49efc01a8 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 11 Jun 2011 18:27:13 +0700 Subject: [PATCH 6/6] Support wiki pages names in python modules. Also this fixes showing python modules in available modules list. --- modules/modpython/znc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/modpython/znc.py b/modules/modpython/znc.py index 054316a6..3cc89b61 100644 --- a/modules/modpython/znc.py +++ b/modules/modpython/znc.py @@ -151,6 +151,8 @@ class ModuleNV(collections.MutableMapping): class Module: description = '< Placeholder for a description >' + wiki_page = '' + def __str__(self): return self.GetModName() @@ -498,6 +500,7 @@ def get_mod_info(modname, retmsg, modinfo): cl = pymodule.__dict__[modname] modinfo.SetGlobal(False) modinfo.SetDescription(cl.description) + modinfo.SetWikiPage(cl.wiki_page) modinfo.SetName(modname) modinfo.SetPath(pymodule.__file__) return 2 @@ -524,7 +527,8 @@ def get_mod_info_path(path, modname, modinfo): return 0 cl = pymodule.__dict__[modname] modinfo.SetGlobal(False) - modinfo.SetDescription(get_descr(cl)) + modinfo.SetDescription(cl.description) + modinfo.SetWikiPage(cl.wiki_page) modinfo.SetName(modname) modinfo.SetPath(pymodule.__file__) return 1