Module: kamailio
Branch: master
Commit: 71d7d5835dd256201f50d14d7c7285f7d2881bb6
URL:
https://github.com/kamailio/kamailio/commit/71d7d5835dd256201f50d14d7c7285f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-05-12T08:15:33+02:00
core: kemi - exported KSR.pv.geti("pv")
- return integer value of the pv, trying to convert if its value is
string
---
Modified: src/core/kemi.c
---
Diff:
https://github.com/kamailio/kamailio/commit/71d7d5835dd256201f50d14d7c7285f…
Patch:
https://github.com/kamailio/kamailio/commit/71d7d5835dd256201f50d14d7c7285f…
---
diff --git a/src/core/kemi.c b/src/core/kemi.c
index 0932339996..324e7cd6cf 100644
--- a/src/core/kemi.c
+++ b/src/core/kemi.c
@@ -2855,6 +2855,47 @@ static sr_kemi_xval_t* sr_kemi_pv_getvn (sip_msg_t *msg, str *pvn,
int xival)
return sr_kemi_pv_get_valx (msg, pvn, NULL, xival, 1);
}
+/**
+ *
+ */
+static int sr_kemi_pv_geti (sip_msg_t *msg, str *pvn)
+{
+ pv_spec_t *pvs;
+ pv_value_t val;
+ int vi;
+
+ 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 0;
+ }
+ pvs = pv_cache_get(pvn);
+ if(pvs==NULL) {
+ LM_WARN("cannot get pv spec for [%.*s]\n", pvn->len, pvn->s);
+ return 0;
+ }
+
+ 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 0;
+ }
+ if(val.flags&PV_VAL_NULL) {
+ return 0;
+ }
+ if(val.flags&(PV_TYPE_INT|PV_VAL_INT)) {
+ return val.ri;
+ }
+ if(val.ri!=0) {
+ return val.ri;
+ }
+ vi = 0;
+ str2sint(&val.rs, &vi);
+
+ return vi;
+}
+
/**
*
*/
@@ -3003,6 +3044,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("geti"),
+ SR_KEMIP_INT, sr_kemi_pv_geti,
+ { 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,