mirror of
https://github.com/znc/znc.git
synced 2026-05-18 07:15:54 +02:00
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<CAuthBase> Auth)
The reason for this is they do not currently work with codegen.pl
This commit is contained in:
@@ -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("<no user>")) << "/" << 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("<no user>")) << "/" << 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("<no user>")) << "/" << 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("<no user>")) << "/" << 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(\"<no user>\")) << \"/\" << 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(\"<no user>\")) << \"/\" << 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(\"<no user>\")) << \"/\" << 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("<no user>")) << "/" << 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("<no user>")) << "/" << GetModName() << '."\"/$name was expected to return EModRet but: \" << sPyErr);";
|
||||
say $out "\t\t\tresult = $default;";
|
||||
say $out "\t\t} else result = x ? true : false;";
|
||||
}
|
||||
|
||||
@@ -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<CAuthBase> 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<CModInfo>& ssMods, CModInfo::EModuleType eType)
|
||||
|
||||
@@ -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<CAuthBase> 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<CModInfo>& ssMods, CModInfo::EModuleType eType);
|
||||
};
|
||||
|
||||
static inline CPyModule* AsPyModule(CModule* p) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user