Module: kamailio
Branch: master
Commit: eebdabe4850d99ff937171d4b723122726c0aa43
URL:
https://github.com/kamailio/kamailio/commit/eebdabe4850d99ff937171d4b723122…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-05-11T16:11:42+02:00
pv: added $shvinc(name) - return incremented value of $shv(inc)
- leverage internal mutex to avoid config locks
---
Modified: src/modules/pv/pv.c
Modified: src/modules/pv/pv_shv.c
Modified: src/modules/pv/pv_shv.h
---
Diff:
https://github.com/kamailio/kamailio/commit/eebdabe4850d99ff937171d4b723122…
Patch:
https://github.com/kamailio/kamailio/commit/eebdabe4850d99ff937171d4b723122…
---
diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index 685c0ef9f0..2113115a15 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -526,6 +526,8 @@ static pv_export_t mod_pvs[] = {
{ {"shv", (sizeof("shv")-1)}, PVT_OTHER, pv_get_shvar,
pv_set_shvar, pv_parse_shvar_name, 0, 0, 0},
+ { {"shvinc", (sizeof("shvinc")-1)}, PVT_OTHER, pv_get_shvinc,
+ 0, pv_parse_shvar_name, 0, 0, 0},
{ {"time", (sizeof("time")-1)}, PVT_CONTEXT, pv_get_local_time,
0, pv_parse_time_name, 0, 0, 0},
{ {"timef", (sizeof("timef")-1)}, PVT_CONTEXT,
pv_get_local_strftime,
diff --git a/src/modules/pv/pv_shv.c b/src/modules/pv/pv_shv.c
index fb4de51114..392c4d823d 100644
--- a/src/modules/pv/pv_shv.c
+++ b/src/modules/pv/pv_shv.c
@@ -387,6 +387,38 @@ int pv_get_shvar(struct sip_msg *msg, pv_param_t *param,
return 0;
}
+int pv_get_shvinc(struct sip_msg *msg, pv_param_t *param,
+ pv_value_t *res)
+{
+ int len = 0;
+ char *sval = NULL;
+ sh_var_t *shv=NULL;
+
+ if(msg==NULL || res==NULL)
+ return -1;
+
+ if(param==NULL || param->pvn.u.dname==0)
+ return pv_get_null(msg, param, res);
+
+ shv= (sh_var_t*)param->pvn.u.dname;
+
+ lock_shvar(shv);
+ if(shv->v.flags&VAR_VAL_STR)
+ {
+ res->ri = 0;
+ } else {
+ shv->v.value.n++;
+ res->ri = shv->v.value.n;
+ }
+ unlock_shvar(shv);
+
+ sval = sint2str(res->ri, &len);
+ res->rs.s = sval;
+ res->rs.len = len;
+ res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
+ return 0;
+}
+
int pv_set_shvar(struct sip_msg* msg, pv_param_t *param,
int op, pv_value_t *val)
{
diff --git a/src/modules/pv/pv_shv.h b/src/modules/pv/pv_shv.h
index b7873a037e..65a4d1afc9 100644
--- a/src/modules/pv/pv_shv.h
+++ b/src/modules/pv/pv_shv.h
@@ -57,6 +57,7 @@ int pv_parse_shvar_name(pv_spec_p sp, str *in);
int pv_get_shvar(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
int pv_set_shvar(struct sip_msg* msg, pv_param_t *param, int op,
pv_value_t *val);
+int pv_get_shvinc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
int shvar_init_locks(void);
void shvar_destroy_locks(void);