From 9aac91c93591b9c8711607116cc2629845521a9a Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sun, 24 Apr 2016 09:53:32 +0200 Subject: [PATCH] app_python: exported special kemi function to execute a module function - KSR.x.modf(self, msg, fname, params...) --- modules/app_python/apy_kemi.c | 21 ++++++++++++++--- modules/app_python/msgobj_struct.h | 36 ++++++++++++++++++++++++++++++ modules/app_python/python_msgobj.c | 23 ++++++++++--------- modules/app_python/python_msgobj.h | 2 +- 4 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 modules/app_python/msgobj_struct.h diff --git a/modules/app_python/apy_kemi.c b/modules/app_python/apy_kemi.c index 61270daa885..974d232aa14 100644 --- a/modules/app_python/apy_kemi.c +++ b/modules/app_python/apy_kemi.c @@ -31,6 +31,7 @@ #include "../../pvar.h" #include "../../mem/pkg.h" +#include "msgobj_struct.h" #include "python_exec.h" #include "apy_kemi_export.h" #include "apy_kemi.h" @@ -547,7 +548,7 @@ PyMethodDef *_sr_KSRMethods = NULL; /** * */ -static int sr_apy_kemi_f_dbg(sip_msg_t *msg, str *txt) +static int sr_apy_kemi_f_ktest(sip_msg_t *msg, str *txt) { if(txt!=NULL && txt->s!=NULL) LM_DBG("%.*s", txt->len, txt->s); @@ -559,7 +560,7 @@ static int sr_apy_kemi_f_dbg(sip_msg_t *msg, str *txt) */ static sr_kemi_t _sr_apy_kemi_test[] = { { str_init(""), str_init("ktest"), - SR_KEMIP_NONE, sr_apy_kemi_f_dbg, + SR_KEMIP_NONE, sr_apy_kemi_f_ktest, { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, @@ -832,7 +833,6 @@ static PyObject *sr_apy_kemi_f_pv_is_null(PyObject *self, PyObject *args) return sr_apy_kemi_return_false(); } - pvn.len = strlen(pvn.s); LM_DBG("pv is null test: %s\n", pvn.s); pl = pv_locate_name(&pvn); @@ -872,6 +872,14 @@ static PyMethodDef _sr_apy_kemi_pv_Methods[] = { {NULL, NULL, 0, NULL} }; +/** + * + */ +static PyMethodDef _sr_apy_kemi_x_Methods[] = { + {"modf", (PyCFunction)msg_call_function, METH_VARARGS, + "Invoke function exported by the other module."}, + {NULL, NULL, 0, NULL} /* sentinel */ +}; /** * @@ -950,6 +958,13 @@ int sr_apy_init_ksr(void) "pv", _sr_apy_ksr_modules_list[m]); Py_INCREF(_sr_apy_ksr_modules_list[m]); m++; + /* special sub-modules - x.modf() can have variable number of params */ + _sr_apy_ksr_modules_list[m] = Py_InitModule("KSR.x", + _sr_apy_kemi_x_Methods); + PyDict_SetItemString(_sr_apy_ksr_module_dict, + "x", _sr_apy_ksr_modules_list[m]); + Py_INCREF(_sr_apy_ksr_modules_list[m]); + m++; if(emods_size>1) { for(k=1; k + +typedef struct { + PyObject_HEAD + struct sip_msg *msg; +} msgobject; + +PyObject *msg_call_function(msgobject *, PyObject *); + +#endif diff --git a/modules/app_python/python_msgobj.c b/modules/app_python/python_msgobj.c index f27f7c3d7e5..a46225dc96b 100644 --- a/modules/app_python/python_msgobj.c +++ b/modules/app_python/python_msgobj.c @@ -27,13 +27,9 @@ #include "../../dset.h" #include "../../parser/msg_parser.h" +#include "msgobj_struct.h" #include "structmember.h" -typedef struct { - PyObject_HEAD - struct sip_msg *msg; -} msgobject; - static PyTypeObject MSGtype; #define is_msgobject(v) ((v)->ob_type == &MSGtype) @@ -165,7 +161,7 @@ static PyObject *msg_getHeader(msgobject *self, PyObject *args) return PyString_FromStringAndSize(hbody->s, hbody->len); } -static PyObject *msg_call_function(msgobject *self, PyObject *args) +PyObject *msg_call_function(msgobject *self, PyObject *args) { int i, rval; char *fname, *arg1, *arg2; @@ -263,11 +259,16 @@ PyDoc_STRVAR(copy_doc, Return a copy (``clone'') of the msg object."); static PyMethodDef msg_methods[] = { - {"copy", (PyCFunction)msg_copy, METH_NOARGS, copy_doc}, - {"rewrite_ruri", (PyCFunction)msg_rewrite_ruri, METH_VARARGS, "Rewrite Request-URI."}, - {"set_dst_uri", (PyCFunction)msg_set_dst_uri, METH_VARARGS, "Set destination URI."}, - {"getHeader", (PyCFunction)msg_getHeader, METH_VARARGS, "Get SIP header field by name."}, - {"call_function", (PyCFunction)msg_call_function, METH_VARARGS, "Invoke function exported by the other module."}, + {"copy", (PyCFunction)msg_copy, METH_NOARGS, + copy_doc}, + {"rewrite_ruri", (PyCFunction)msg_rewrite_ruri, METH_VARARGS, + "Rewrite Request-URI."}, + {"set_dst_uri", (PyCFunction)msg_set_dst_uri, METH_VARARGS, + "Set destination URI."}, + {"getHeader", (PyCFunction)msg_getHeader, METH_VARARGS, + "Get SIP header field by name."}, + {"call_function", (PyCFunction)msg_call_function, METH_VARARGS, + "Invoke function exported by the other module."}, {NULL, NULL, 0, NULL} /* sentinel */ }; diff --git a/modules/app_python/python_msgobj.h b/modules/app_python/python_msgobj.h index 825025fcd27..c25afd11812 100644 --- a/modules/app_python/python_msgobj.h +++ b/modules/app_python/python_msgobj.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2009 Sippy Software, Inc., http://www.sippysoft.com * * This file is part of Kamailio, a free SIP server.