From 961e3a81c60e0a497f86a2bb85182f39a417cf29 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Sun, 26 Feb 2012 14:17:57 +0000 Subject: [PATCH] modpython: Support global module hooks #98 The commit doesn't add support for the following module hooks: void OnClientCapLs(CClient* pClient, SCString& ssCaps) EModRet OnLoginAttempt(CSmartPtr Auth) The reason for this is they do not currently work with codegen.pl --- modules/modpython/codegen.pl | 18 +++++++-------- modules/modpython/functions.in | 12 ++++++++++ modules/modpython/module.h | 18 ++++++++++++++- modules/modpython/znc.py | 40 ++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/modules/modpython/codegen.pl b/modules/modpython/codegen.pl index 2b70cae1..b775354c 100644 --- a/modules/modpython/codegen.pl +++ b/modules/modpython/codegen.pl @@ -307,7 +307,7 @@ while (<$in>) { } say $out "\tif (!$a->{pyvar}) {"; say $out "\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();"; - say $out "\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '."\"/$name: $a->{error}: \" << sPyErr);"; + say $out "\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("")) << "/" << GetModName() << '."\"/$name: $a->{error}: \" << sPyErr);"; print $out $cleanup; say $out "\t\treturn $default;"; say $out "\t}"; @@ -323,14 +323,14 @@ while (<$in>) { say $out "\t\tPyObject* pyVecEl = SWIG_NewInstanceObj(*i, SWIG_TypeQuery(\"$sub*\"), 0);"; say $out "\t\tif (!pyVecEl) {"; say $out "\t\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();"; - say $out "\t\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '. + say $out "\t\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("")) << "/" << GetModName() << '. "\"/$name: can't convert element of vector '$a->{var}' to PyObject: \" << sPyErr);"; print $out $cleanup1; say $out "\t\t\treturn $default;"; say $out "\t\t}"; say $out "\t\tif (PyList_Append($a->{pyvar}, pyVecEl)) {"; say $out "\t\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();"; - say $out "\t\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '. + say $out "\t\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("")) << "/" << GetModName() << '. "\"/$name: can't add element of vector '$a->{var}' to PyObject: \" << sPyErr);"; say $out "\t\t\tPy_CLEAR(pyVecEl);"; print $out $cleanup1; @@ -346,7 +346,7 @@ while (<$in>) { say $out ", NULL);"; say $out "\tif (!pyRes) {"; say $out "\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();"; - say $out "\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '."\"/$name failed: \" << sPyErr);"; + say $out "\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("")) << "/" << GetModName() << '."\"/$name failed: \" << sPyErr);"; print $out $cleanup; say $out "\t\treturn $default;"; say $out "\t}"; @@ -364,7 +364,7 @@ while (<$in>) { when (/^(.*)\*$/) { say $out "\t\tint res = SWIG_ConvertPtr(pyRes, (void**)&result, SWIG_TypeQuery(\"$type\"), 0);"; say $out "\t\tif (!SWIG_IsOK(res)) {"; - say $out "\t\t\tDEBUG(\"modpython: \" << GetUser()->GetUserName() << \"/\" << GetModName() << \"/$name was expected to return '$type' but error=\" << res);"; + say $out "\t\t\tDEBUG(\"modpython: \" << (GetUser() ? GetUser()->GetUserName() : CString(\"\")) << \"/\" << GetModName() << \"/$name was expected to return '$type' but error=\" << res);"; say $out "\t\t\tresult = $default;"; say $out "\t\t}"; } @@ -372,10 +372,10 @@ while (<$in>) { say $out "\t\tCString* p = NULL;"; say $out "\t\tint res = SWIG_AsPtr_std_string(pyRes, &p);"; say $out "\t\tif (!SWIG_IsOK(res)) {"; - say $out "\t\t\tDEBUG(\"modpython: \" << GetUser()->GetUserName() << \"/\" << GetModName() << \"/$name was expected to return '$type' but error=\" << res);"; + say $out "\t\t\tDEBUG(\"modpython: \" << (GetUser() ? GetUser()->GetUserName() : CString(\"\")) << \"/\" << GetModName() << \"/$name was expected to return '$type' but error=\" << res);"; say $out "\t\t\tresult = $default;"; say $out "\t\t} else if (!p) {"; - say $out "\t\t\tDEBUG(\"modpython: \" << GetUser()->GetUserName() << \"/\" << GetModName() << \"/$name was expected to return '$type' but returned NULL\");"; + say $out "\t\t\tDEBUG(\"modpython: \" << (GetUser() ? GetUser()->GetUserName() : CString(\"\")) << \"/\" << GetModName() << \"/$name was expected to return '$type' but returned NULL\");"; say $out "\t\t\tresult = $default;"; say $out "\t\t} else result = *p;"; say $out "\t\tif (SWIG_IsNewObj(res)) free((char*)p); // Don't ask me, that's how SWIG works..."; @@ -384,7 +384,7 @@ while (<$in>) { say $out "\t\tlong int x = PyLong_AsLong(pyRes);"; say $out "\t\tif (PyErr_Occurred()) {"; say $out "\t\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();"; - say $out "\t\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);"; + say $out "\t\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("")) << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);"; say $out "\t\t\tresult = $default;"; say $out "\t\t} else { result = (CModule::EModRet)x; }"; } @@ -392,7 +392,7 @@ while (<$in>) { say $out "\t\tint x = PyObject_IsTrue(pyRes);"; say $out "\t\tif (-1 == x) {"; say $out "\t\t\tCString sPyErr = m_pModPython->GetPyExceptionStr();"; - say $out "\t\t\tDEBUG".'("modpython: " << GetUser()->GetUserName() << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);"; + say $out "\t\t\tDEBUG".'("modpython: " << (GetUser() ? GetUser()->GetUserName() : CString("")) << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);"; say $out "\t\t\tresult = $default;"; say $out "\t\t} else result = x ? true : false;"; } diff --git a/modules/modpython/functions.in b/modules/modpython/functions.in index c12db06c..4d0f26a9 100644 --- a/modules/modpython/functions.in +++ b/modules/modpython/functions.in @@ -61,4 +61,16 @@ void OnServerCapResult(const CString& sCap, bool bSuccess) EModRet OnTimerAutoJoin(CChan& Channel) bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)=false +EModRet OnAddUser(CUser& User, CString& sErrorRet) +EModRet OnDeleteUser(CUser& User) +void OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort) +EModRet OnLoginAttempt(CSmartPtr Auth) +void OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) +EModRet OnUnknownUserRaw(CClient* pClient, CString& sLine) +void OnClientCapLs(CClient* pClient, SCString& ssCaps) +bool IsClientCapSupported(CClient* pClient, const CString& sCap, bool bState)=false +void OnClientCapRequest(CClient* pClient, const CString& sCap, bool bState) EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, CModInfo::EModuleType eType, bool& bSuccess, CString& sRetMsg) +EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) +EModRet OnGetModInfo(CModInfo& ModInfo, const CString& sModule, bool& bSuccess, CString& sRetMsg) +void OnGetAvailableMods(set& ssMods, CModInfo::EModuleType eType) diff --git a/modules/modpython/module.h b/modules/modpython/module.h index f4e83dfc..a8012eda 100644 --- a/modules/modpython/module.h +++ b/modules/modpython/module.h @@ -108,7 +108,23 @@ public: virtual void OnServerCapResult(const CString& sCap, bool bSuccess); virtual EModRet OnTimerAutoJoin(CChan& Channel); bool OnEmbeddedWebRequest(CWebSock&, const CString&, CTemplate&); - EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, CModInfo::EModuleType eType, bool& bSuccess, CString& sRetMsg); + + // Global Modules + virtual EModRet OnAddUser(CUser& User, CString& sErrorRet); + virtual EModRet OnDeleteUser(CUser& User); + virtual void OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort); + virtual EModRet OnLoginAttempt(CSmartPtr Auth); + virtual void OnFailedLogin(const CString& sUsername, const CString& sRemoteIP); + virtual EModRet OnUnknownUserRaw(CClient* pClient, CString& sLine); + virtual void OnClientCapLs(CClient* pClient, SCString& ssCaps); + virtual bool IsClientCapSupported(CClient* pClient, const CString& sCap, bool bState); + virtual void OnClientCapRequest(CClient* pClient, const CString& sCap, bool bState); + virtual EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, + CModInfo::EModuleType eType, bool& bSuccess, CString& sRetMsg); + virtual EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg); + virtual EModRet OnGetModInfo(CModInfo& ModInfo, const CString& sModule, + bool& bSuccess, CString& sRetMsg); + virtual void OnGetAvailableMods(set& ssMods, CModInfo::EModuleType eType); }; static inline CPyModule* AsPyModule(CModule* p) { diff --git a/modules/modpython/znc.py b/modules/modpython/znc.py index fb0741d8..5f0d462e 100644 --- a/modules/modpython/znc.py +++ b/modules/modpython/znc.py @@ -366,6 +366,46 @@ class Module: def OnEmbeddedWebRequest(self, WebSock, sPageName, Tmpl): pass + # Global modules + def OnAddUser(self, User, sErrorRet): + pass + + def OnDeleteUser(self, User): + pass + + def OnClientConnect(self, pSock, sHost, uPort): + pass + + def OnLoginAttempt(self, Auth): + pass + + def OnFailedLogin(self, sUsername, sRemoteIP): + pass + + def OnUnknownUserRaw(self, pClient, sLine): + pass + + def OnClientCapLs(self, pClient, ssCaps): + pass + + def IsClientCapSupported(self, pClient, sCap, bState): + pass + + def OnClientCapRequest(self, pClient, sCap, bState): + pass + + def OnModuleLoading(self, sModName, sArgs, eType, bSuccess, sRetMsg): + pass + + def OnModuleUnloading(self, pModule, bSuccess, sRetMsg): + pass + + def OnGetModInfo(self, ModInfo, sModule, bSuccess, sRetMsg): + pass + + def OnGetAvailableMods(self, ssMods, eType): + pass + def make_inherit(cl, parent, attr): def make_caller(parent, name, attr): return lambda self, *a: parent.__dict__[name](self.__dict__[attr], *a)