mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Fix global python modules.
This commit is contained in:
committed by
Kyle Fuller
parent
76aaafd4d0
commit
0c9eae226e
@@ -61,3 +61,4 @@ void OnServerCapResult(const CString& sCap, bool bSuccess)
|
||||
EModRet OnTimerAutoJoin(CChan& Channel)
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl)=false
|
||||
|
||||
EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, bool& bSuccess, CString& sRetMsg)
|
||||
|
||||
@@ -73,6 +73,15 @@ namespace std {
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) CString&, CString* {
|
||||
if ($1) {
|
||||
$result = CPyRetString::wrap(*$1);
|
||||
} else {
|
||||
$result = Py_None;
|
||||
Py_INCREF(Py_None);
|
||||
}
|
||||
}
|
||||
|
||||
#define u_short unsigned short
|
||||
#define u_int unsigned int
|
||||
#include "../ZNCString.h"
|
||||
|
||||
@@ -23,6 +23,13 @@ class CPyModule : public CModule {
|
||||
CModPython* m_pModPython;
|
||||
VWebSubPages* _GetSubPages();
|
||||
public:
|
||||
CPyModule(const CString& sModName, const CString& sDataPath,
|
||||
PyObject* pyObj, CModule* pModPython)
|
||||
: CModule(NULL, sModName, sDataPath) {
|
||||
m_pyObj = pyObj;
|
||||
Py_INCREF(pyObj);
|
||||
m_pModPython = reinterpret_cast<CModPython*>(pModPython);
|
||||
}
|
||||
CPyModule(CUser* pUser, const CString& sModName, const CString& sDataPath,
|
||||
PyObject* pyObj, CModule* pModPython)
|
||||
: CModule(NULL, pUser, sModName, sDataPath) {
|
||||
@@ -108,16 +115,21 @@ 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, bool& bSuccess, CString& sRetMsg);
|
||||
};
|
||||
|
||||
static inline CPyModule* AsPyModule(CModule* p) {
|
||||
return dynamic_cast<CPyModule*>(p);
|
||||
}
|
||||
|
||||
inline CPyModule* CreatePyModule(CUser* pUser, const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
|
||||
inline CPyModule* CreateUserPyModule(CUser* pUser, const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
|
||||
return new CPyModule(pUser, sModName, sDataPath, pyObj, pModPython);
|
||||
}
|
||||
|
||||
inline CPyModule* CreateGlobalPyModule(const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
|
||||
return new CPyModule(sModName, sDataPath, pyObj, pModPython);
|
||||
}
|
||||
|
||||
class CPyTimer : public CTimer {
|
||||
PyObject* m_pyObj;
|
||||
CModPython* m_pModPython;
|
||||
|
||||
@@ -438,11 +438,15 @@ def load_module(modname, args, user, retmsg, modpython):
|
||||
return 1
|
||||
cl = pymodule.__dict__[modname]
|
||||
module = cl()
|
||||
module._cmod = CreatePyModule(user, modname, datapath, module, modpython)
|
||||
if user:
|
||||
module._cmod = CreateUserPyModule(user, modname, datapath, module, modpython)
|
||||
else:
|
||||
module._cmod = CreateGlobalPyModule(modname, datapath, module, modpython)
|
||||
module.nv = ModuleNV(module._cmod)
|
||||
module.SetDescription(cl.description)
|
||||
module.SetArgs(args)
|
||||
module.SetModPath(pymodule.__file__)
|
||||
module.SetType(cl.module_type)
|
||||
|
||||
if user:
|
||||
user.GetModules().push_back(module._cmod)
|
||||
@@ -488,8 +492,11 @@ def load_module(modname, args, user, retmsg, modpython):
|
||||
def unload_module(module):
|
||||
module.OnShutdown()
|
||||
cmod = module._cmod
|
||||
if module.GetType() == ModuleTypeUser:
|
||||
cmod.GetUser().GetModules().removeModule(cmod)
|
||||
elif module.GetType() == ModuleTypeGlobal:
|
||||
CZNC.Get().GetModules().removeModule(cmod)
|
||||
del module._cmod
|
||||
cmod.GetUser().GetModules().removeModule(cmod)
|
||||
cmod.DeletePyModule()
|
||||
del cmod
|
||||
|
||||
|
||||
Reference in New Issue
Block a user