Module: kamailio
Branch: master
Commit: d014e2c726001268133a4b1bddaff77495a7be1d
URL:
https://github.com/kamailio/kamailio/commit/d014e2c726001268133a4b1bddaff77…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-08-28T09:56:28+02:00
app_python3: implemented KSR.pv.getvs(...) an KSR.pv.getvn(...)
---
Modified: src/modules/app_python3/apy_kemi.c
---
Diff:
https://github.com/kamailio/kamailio/commit/d014e2c726001268133a4b1bddaff77…
Patch:
https://github.com/kamailio/kamailio/commit/d014e2c726001268133a4b1bddaff77…
---
diff --git a/src/modules/app_python3/apy_kemi.c b/src/modules/app_python3/apy_kemi.c
index 69666e2d5e..9f78e53089 100755
--- a/src/modules/app_python3/apy_kemi.c
+++ b/src/modules/app_python3/apy_kemi.c
@@ -828,6 +828,106 @@ static PyObject *sr_apy_kemi_f_pv_gete(PyObject *self, PyObject
*args)
return sr_apy_kemi_f_pv_get_mode(self, args, "s:pv.gete", 2);
}
+/**
+ *
+ */
+static PyObject *sr_apy_kemi_pv_push_valx(int rmode, int xival, str *xsval)
+{
+ if(rmode==1) {
+ return sr_kemi_apy_return_int(NULL, xival);
+ } else {
+ return sr_apy_kemi_return_str(NULL, xsval->s, xsval->len);
+ }
+}
+
+/**
+ *
+ */
+static PyObject *sr_apy_kemi_f_pv_get_valx(PyObject *self, PyObject *args,
+ int rmode)
+{
+ str pvn;
+ pv_spec_t *pvs;
+ pv_value_t val;
+ int pl;
+ sr_apy_env_t *env_P;
+ sip_msg_t *lmsg = NULL;
+ int xival = 0;
+ str xsval = str_init("");
+
+ env_P = sr_apy_env_get();
+
+ if(env_P==NULL) {
+ LM_ERR("invalid Python environment attributes\n");
+ return sr_apy_kemi_return_none_mode(rmode);
+ }
+ if(env_P->msg==NULL) {
+ lmsg = faked_msg_next();
+ } else {
+ lmsg = env_P->msg;
+ }
+
+ memset(&val, 0, sizeof(pv_value_t));
+ if(rmode==1) {
+ if(!PyArg_ParseTuple(args, "si:pv.getvn", &pvn.s, &xival)) {
+ LM_ERR("unable to retrieve str-int params\n");
+ return sr_apy_kemi_return_none_mode(rmode);
+ }
+ } else {
+ if(!PyArg_ParseTuple(args, "ss:pv.getvs", &pvn.s, &xival)) {
+ LM_ERR("unable to retrieve str-int params\n");
+ return sr_apy_kemi_return_none_mode(rmode);
+ }
+ }
+
+ if(pvn.s==NULL || lmsg==NULL) {
+ LM_ERR("invalid context attributes\n");
+ return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
+ }
+ val.flags |= PV_TYPE_INT|PV_VAL_INT;
+ pvn.len = strlen(pvn.s);
+
+ LM_DBG("pv set: %s\n", pvn.s);
+ pl = pv_locate_name(&pvn);
+ if(pl != pvn.len) {
+ LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
+ return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
+ }
+ pvs = pv_cache_get(&pvn);
+ if(pvs==NULL) {
+ LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
+ return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
+ }
+ 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);
+ return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
+ }
+ if(val.flags&PV_VAL_NULL) {
+ return sr_apy_kemi_pv_push_valx(rmode, xival, &xsval);
+ }
+ if(val.flags&PV_TYPE_INT) {
+ return sr_kemi_apy_return_int(NULL, val.ri);
+ }
+ return sr_apy_kemi_return_str(NULL, val.rs.s, val.rs.len);
+}
+
+/**
+ *
+ */
+static PyObject *sr_apy_kemi_f_pv_getvs(PyObject *self, PyObject *args)
+{
+ return sr_apy_kemi_f_pv_get_valx(self, args, 0);
+}
+
+/**
+ *
+ */
+static PyObject *sr_apy_kemi_f_pv_getvn(PyObject *self, PyObject *args)
+{
+ return sr_apy_kemi_f_pv_get_valx(self, args, 1);
+}
+
/**
*
*/
@@ -1063,6 +1163,10 @@ static PyMethodDef _sr_apy_kemi_pv_Methods[] = {
NAME " - pv get value or <<null>>"},
{"gete", sr_apy_kemi_f_pv_gete, METH_VARARGS,
NAME " - pv get value or <<null>>"},
+ {"getvs", sr_apy_kemi_f_pv_getvs, METH_VARARGS,
+ NAME " - pv get value of pv or str val param"},
+ {"getvn", sr_apy_kemi_f_pv_getvn, METH_VARARGS,
+ NAME " - pv get value of pv or int val param"},
{"seti", sr_apy_kemi_f_pv_seti, METH_VARARGS,
NAME " - pv set int value"},
{"sets", sr_apy_kemi_f_pv_sets, METH_VARARGS,