Module: kamailio
Branch: master
Commit: 3406b9143a399a0445d09b83f40fe2fbe1781761
URL:
https://github.com/kamailio/kamailio/commit/3406b9143a399a0445d09b83f40fe2f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-11-24T10:15:33+01:00
core: kemi - function to get/set pv with long value
---
Modified: src/core/kemi.c
---
Diff:
https://github.com/kamailio/kamailio/commit/3406b9143a399a0445d09b83f40fe2f…
Patch:
https://github.com/kamailio/kamailio/commit/3406b9143a399a0445d09b83f40fe2f…
---
diff --git a/src/core/kemi.c b/src/core/kemi.c
index d6716507b3..ed98bffd44 100644
--- a/src/core/kemi.c
+++ b/src/core/kemi.c
@@ -3164,6 +3164,51 @@ static int sr_kemi_pv_geti (sip_msg_t *msg, str *pvn)
return vi;
}
+/**
+ *
+ */
+static sr_kemi_xval_t* sr_kemi_pv_getl (sip_msg_t *msg, str *pvn)
+{
+ pv_spec_t *pvs;
+ pv_value_t val;
+ int vi;
+
+ memset(&_sr_kemi_xval, 0, sizeof(sr_kemi_xval_t));
+ _sr_kemi_xval.vtype = SR_KEMIP_LONG;
+
+ LM_DBG("pv get: %.*s\n", pvn->len, pvn->s);
+ vi = pv_locate_name(pvn);
+ if(vi != pvn->len) {
+ LM_WARN("invalid pv [%.*s] (%d/%d)\n", pvn->len, pvn->s, vi,
pvn->len);
+ return &_sr_kemi_xval;
+ }
+ pvs = pv_cache_get(pvn);
+ if(pvs==NULL) {
+ LM_WARN("cannot get pv spec for [%.*s]\n", pvn->len, pvn->s);
+ return &_sr_kemi_xval;
+ }
+
+ memset(&val, 0, sizeof(pv_value_t));
+ if(pv_get_spec_value(msg, pvs, &val) != 0) {
+ LM_WARN("unable to get pv value for [%.*s]\n", pvn->len, pvn->s);
+ return &_sr_kemi_xval;
+ }
+ if(val.flags&PV_VAL_NULL) {
+ return &_sr_kemi_xval;
+ }
+ if(val.flags&(PV_TYPE_INT|PV_VAL_INT)) {
+ _sr_kemi_xval.v.l = val.ri;
+ return &_sr_kemi_xval;
+ }
+ if(val.ri!=0) {
+ _sr_kemi_xval.v.l = val.ri;
+ return &_sr_kemi_xval;
+ }
+ str2slong(&val.rs, &_sr_kemi_xval.v.l);
+
+ return &_sr_kemi_xval;
+}
+
/**
*
*/
@@ -3197,6 +3242,43 @@ static int sr_kemi_pv_seti (sip_msg_t *msg, str *pvn, int ival)
return SR_KEMI_TRUE;
}
+/**
+ *
+ */
+static int sr_kemi_pv_setl (sip_msg_t *msg, str *pvn, sr_kemi_xval_t *xval)
+{
+ pv_spec_t *pvs;
+ pv_value_t val;
+ int pl;
+
+ LM_DBG("pv get: %.*s\n", pvn->len, pvn->s);
+ pl = pv_locate_name(pvn);
+ if(pl != pvn->len) {
+ LM_ERR("invalid pv [%.*s] (%d/%d)\n", pvn->len, pvn->s, pl,
pvn->len);
+ return SR_KEMI_FALSE;
+ }
+ pvs = pv_cache_get(pvn);
+ if(pvs==NULL) {
+ LM_ERR("cannot get pv spec for [%.*s]\n", pvn->len, pvn->s);
+ return SR_KEMI_FALSE;
+ }
+
+ memset(&val, 0, sizeof(pv_value_t));
+ if(xval==NULL || !(xval->vtype & SR_KEMIP_LONG)) {
+ val.ri = 0;
+ } else {
+ val.ri = xval->v.l;
+ }
+ val.flags |= PV_TYPE_INT|PV_VAL_INT;
+
+ if(pv_set_spec_value(msg, pvs, 0, &val)<0) {
+ LM_ERR("unable to set pv [%.*s]\n", pvn->len, pvn->s);
+ return SR_KEMI_FALSE;
+ }
+
+ return SR_KEMI_TRUE;
+}
+
/**
*
*/
@@ -3317,6 +3399,11 @@ static sr_kemi_t _sr_kemi_pv[] = {
{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("pv"), str_init("getl"),
+ SR_KEMIP_XVAL, sr_kemi_pv_getl,
+ { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ str_init("pv"), str_init("getvn"),
SR_KEMIP_XVAL, sr_kemi_pv_getvn,
{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
@@ -3332,6 +3419,11 @@ static sr_kemi_t _sr_kemi_pv[] = {
{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("pv"), str_init("setl"),
+ SR_KEMIP_BOOL, sr_kemi_pv_setl,
+ { SR_KEMIP_STR, SR_KEMIP_LONG, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ str_init("pv"), str_init("sets"),
SR_KEMIP_BOOL, sr_kemi_pv_sets,
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,