Module: kamailio
Branch: master
Commit: e8b434f13f56b2f34d5b30bf728c4685c488e63c
URL:
https://github.com/kamailio/kamailio/commit/e8b434f13f56b2f34d5b30bf728c468…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-05-18T09:03:04+02:00
app_python: added KSR.pv.getw() to kemi expors
- wrapper function for returning the value
---
Modified: src/modules/app_python/apy_kemi.c
---
Diff:
https://github.com/kamailio/kamailio/commit/e8b434f13f56b2f34d5b30bf728c468…
Patch:
https://github.com/kamailio/kamailio/commit/e8b434f13f56b2f34d5b30bf728c468…
---
diff --git a/src/modules/app_python/apy_kemi.c b/src/modules/app_python/apy_kemi.c
index b7cca69bdf..6ea72e3d1c 100644
--- a/src/modules/app_python/apy_kemi.c
+++ b/src/modules/app_python/apy_kemi.c
@@ -657,6 +657,18 @@ static sr_kemi_t _sr_apy_kemi_test[] = {
{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};
+/**
+ *
+ */
+PyObject *sr_apy_kemi_return_none_mode(int rmode)
+{
+ if(rmode) {
+ return sr_apy_kemi_return_str(NULL, "<<null>>", 8);
+ } else {
+ return sr_apy_kemi_return_none();
+ }
+}
+
/**
*
*/
@@ -674,11 +686,7 @@ static PyObject *sr_apy_kemi_f_pv_get_mode(PyObject *self, PyObject
*args,
if(env_P==NULL) {
LM_ERR("invalid Python environment attributes\n");
- if(rmode) {
- return sr_apy_kemi_return_str(NULL, "<<null>>", 8);
- } else {
- return sr_apy_kemi_return_none();
- }
+ return sr_apy_kemi_return_none_mode(rmode);
}
if(env_P->msg==NULL) {
lmsg = faked_msg_next();
@@ -688,20 +696,12 @@ static PyObject *sr_apy_kemi_f_pv_get_mode(PyObject *self, PyObject
*args,
if(!PyArg_ParseTuple(args, "s:pv.get", &pvn.s)) {
LM_ERR("unable to retrieve str param\n");
- if(rmode) {
- return sr_apy_kemi_return_str(NULL, "<<null>>", 8);
- } else {
- return sr_apy_kemi_return_none();
- }
+ return sr_apy_kemi_return_none_mode(rmode);
}
if(pvn.s==NULL || lmsg==NULL) {
LM_ERR("invalid context attributes\n");
- if(rmode) {
- return sr_apy_kemi_return_str(NULL, "<<null>>", 8);
- } else {
- return sr_apy_kemi_return_none();
- }
+ return sr_apy_kemi_return_none_mode(rmode);
}
pvn.len = strlen(pvn.s);
@@ -709,37 +709,21 @@ static PyObject *sr_apy_kemi_f_pv_get_mode(PyObject *self, PyObject
*args,
pl = pv_locate_name(&pvn);
if(pl != pvn.len) {
LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
- if(rmode) {
- return sr_apy_kemi_return_str(NULL, "<<null>>", 8);
- } else {
- return sr_apy_kemi_return_none();
- }
+ return sr_apy_kemi_return_none_mode(rmode);
}
pvs = pv_cache_get(&pvn);
if(pvs==NULL) {
LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
- if(rmode) {
- return sr_apy_kemi_return_str(NULL, "<<null>>", 8);
- } else {
- return sr_apy_kemi_return_none();
- }
+ return sr_apy_kemi_return_none_mode(rmode);
}
memset(&val, 0, sizeof(pv_value_t));
if(pv_get_spec_value(lmsg, pvs, &val) != 0)
{
LM_ERR("unable to get pv value for [%s]\n", pvn.s);
- if(rmode) {
- return sr_apy_kemi_return_str(NULL, "<<null>>", 8);
- } else {
- return sr_apy_kemi_return_none();
- }
+ return sr_apy_kemi_return_none_mode(rmode);
}
if(val.flags&PV_VAL_NULL) {
- if(rmode) {
- return sr_apy_kemi_return_str(NULL, "<<null>>", 8);
- } else {
- return sr_apy_kemi_return_none();
- }
+ return sr_apy_kemi_return_none_mode(rmode);
}
if(val.flags&PV_TYPE_INT) {
return sr_kemi_apy_return_int(NULL, val.ri);
@@ -758,7 +742,7 @@ static PyObject *sr_apy_kemi_f_pv_get(PyObject *self, PyObject *args)
/**
*
*/
-static PyObject *sr_apy_kemi_f_pv_get_w(PyObject *self, PyObject *args)
+static PyObject *sr_apy_kemi_f_pv_getw(PyObject *self, PyObject *args)
{
return sr_apy_kemi_f_pv_get_mode(self, args, 1);
}
@@ -994,6 +978,8 @@ static PyObject *sr_apy_kemi_f_pv_is_null(PyObject *self, PyObject
*args)
static PyMethodDef _sr_apy_kemi_pv_Methods[] = {
{"get", sr_apy_kemi_f_pv_get, METH_VARARGS,
NAME " - pv get value"},
+ {"getw", sr_apy_kemi_f_pv_getw, METH_VARARGS,
+ NAME " - pv get value or <<null>>"},
{"seti", sr_apy_kemi_f_pv_seti, METH_VARARGS,
NAME " - pv set int value"},
{"sets", sr_apy_kemi_f_pv_sets, METH_VARARGS,