Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make modpython support network modules

  • Loading branch information...
commit 260421e6e85a368c177524020e98b247a2a26f4e 1 parent 9a2fed6
@kylef kylef authored
View
5 modules/modpython.cpp
@@ -135,11 +135,12 @@ class CModPython: public CModule {
bSuccess = false;
return HALT;
}
- PyObject* pyRes = PyObject_CallFunction(pyFunc, const_cast<char*>("ssiNNN"),
+ PyObject* pyRes = PyObject_CallFunction(pyFunc, const_cast<char*>("ssiNNNN"),
sModName.c_str(),
sArgs.c_str(),
(int)eType,
- (eType == CModInfo::UserModule ? SWIG_NewInstanceObj(GetUser(), SWIG_TypeQuery("CUser*"), 0) : Py_None),
+ (eType == CModInfo::GlobalModule ? Py_None : SWIG_NewInstanceObj(GetUser(), SWIG_TypeQuery("CUser*"), 0)),
+ (eType == CModInfo::NetworkModule ? SWIG_NewInstanceObj(GetNetwork(), SWIG_TypeQuery("CNetwork*"), 0) : Py_None),
CPyRetString::wrap(sRetMsg),
SWIG_NewInstanceObj(reinterpret_cast<CModule*>(this), SWIG_TypeQuery("CModule*"), 0));
if (!pyRes) {
View
11 modules/modpython/modpython.i
@@ -15,6 +15,7 @@
#include "../Nick.h"
#include "../Chan.h"
#include "../User.h"
+#include "../IRCNetwork.h"
#include "../Client.h"
#include "../IRCSock.h"
#include "../Listener.h"
@@ -97,6 +98,7 @@ namespace std {
%include "../Nick.h"
%include "../Chan.h"
%include "../User.h"
+%include "../IRCNetwork.h"
%include "../Client.h"
%include "../IRCSock.h"
%include "../Listener.h"
@@ -165,6 +167,15 @@ public:
}
};
+%extend CIRCNetwork {
+ CString __str__() {
+ return $self->GetName();
+ }
+ CString __repr__() {
+ return "<CIRCNetwork " + $self->GetName() + ">";
+ }
+}
+
%extend CChan {
CString __str__() {
return $self->GetName();
View
19 modules/modpython/module.h
@@ -23,16 +23,9 @@ class CPyModule : public CModule {
CModPython* m_pModPython;
VWebSubPages* _GetSubPages();
public:
- CPyModule(const CString& sModName, const CString& sDataPath,
+ CPyModule(CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, const CString& sDataPath,
PyObject* pyObj, CModule* pModPython)
- : CModule(NULL, 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) {
+ : CModule(NULL, pUser, pNetwork, sModName, sDataPath) {
m_pyObj = pyObj;
Py_INCREF(pyObj);
m_pModPython = reinterpret_cast<CModPython*>(pModPython);
@@ -122,12 +115,8 @@ static inline CPyModule* AsPyModule(CModule* p) {
return dynamic_cast<CPyModule*>(p);
}
-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);
+inline CPyModule* CreatePyModule(CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, const CString& sDataPath, PyObject* pyObj, CModule* pModPython) {
+ return new CPyModule(pUser, pNetwork, sModName, sDataPath, pyObj, pModPython);
}
class CPyTimer : public CTimer {
View
19 modules/modpython/znc.py
@@ -423,7 +423,7 @@ def find_open(modname):
return (None, None)
-def load_module(modname, args, module_type, user, retmsg, modpython):
+def load_module(modname, args, module_type, user, network, retmsg, modpython):
'''Returns 0 if not found, 1 on loading error, 2 on success'''
if re.search(r'[^a-zA-Z0-9_]', modname) is not None:
retmsg.s = 'Module names can only contain letters, numbers and ' \
@@ -443,14 +443,7 @@ def load_module(modname, args, module_type, user, retmsg, modpython):
return 1
module = cl()
- if module_type == CModInfo.UserModule:
- module._cmod = CreateUserPyModule(user, modname, datapath, module, modpython)
- elif module_type == CModInfo.GlobalModule:
- module._cmod = CreateGlobalPyModule(modname, datapath, module, modpython)
- else:
- retmsg.s = "Module [modpython] doesn't support module type."
- return 1
-
+ module._cmod = CreatePyModule(user, network, modname, datapath, module, modpython)
module.nv = ModuleNV(module._cmod)
module.SetDescription(cl.description)
module.SetArgs(args)
@@ -463,6 +456,12 @@ def load_module(modname, args, module_type, user, retmsg, modpython):
unload_module(module)
return 1
user.GetModules().push_back(module._cmod)
+ elif module_type == CModInfo.NetworkModule:
+ if not network:
+ retmsg.s = "Module [modpython] needs a network for for NetworkModule."
+ unload_module(module)
+ return 1
+ network.GetModules().push_back(module._cmod)
elif module_type == CModInfo.GlobalModule:
CZNC.Get().GetModules().push_back(module._cmod)
else:
@@ -511,6 +510,8 @@ def unload_module(module):
cmod = module._cmod
if module.GetType() == CModInfo.UserModule:
cmod.GetUser().GetModules().removeModule(cmod)
+ elif module.GetType() == CModInfo.NetworkModule:
+ cmod.GetNetwork().GetModules().removeModule(cmod)
elif module.GetType() == CModInfo.GlobalModule:
CZNC.Get().GetModules().removeModule(cmod)
del module._cmod
Please sign in to comment.
Something went wrong with that request. Please try again.