[sr-dev] git:master:5d0f147b: pv: added function to set the value for $ccp(key)
Daniel-Constantin Mierla
miconda at gmail.com
Mon May 17 08:09:07 CEST 2021
Module: kamailio
Branch: master
Commit: 5d0f147be45495cd836da4656ece5549f9859815
URL: https://github.com/kamailio/kamailio/commit/5d0f147be45495cd836da4656ece5549f9859815
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-05-16T12:23:02+02:00
pv: added function to set the value for $ccp(key)
---
Modified: src/modules/pv/pv.c
Modified: src/modules/pv/pv_core.c
Modified: src/modules/pv/pv_core.h
---
Diff: https://github.com/kamailio/kamailio/commit/5d0f147be45495cd836da4656ece5549f9859815.diff
Patch: https://github.com/kamailio/kamailio/commit/5d0f147be45495cd836da4656ece5549f9859815.patch
---
diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index 16460f9bb3..ea6dab4940 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -540,7 +540,7 @@ static pv_export_t mod_pvs[] = {
pv_parse_ksr_attrs_name, 0, 0, 0 },
{{"rpl", (sizeof("rpl")-1)}, PVT_OTHER, pv_get_rpl_attrs, 0,
pv_parse_rpl_attrs_name, 0, 0, 0},
- {{"ccp", (sizeof("ccp")-1)}, PVT_OTHER, pv_get_ccp_attrs, 0,
+ {{"ccp", (sizeof("ccp")-1)}, PVT_OTHER, pv_get_ccp_attrs, pv_set_ccp_attrs,
pv_parse_ccp_attrs_name, 0, 0, 0},
{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c
index 15ab3acb48..2c4692fecc 100644
--- a/src/modules/pv/pv_core.c
+++ b/src/modules/pv/pv_core.c
@@ -4057,3 +4057,54 @@ int pv_get_ccp_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
LM_ERR("unknown type for variable [%.*s]\n", s.len, s.s);
return pv_get_null(msg, param, res);
}
+
+/**
+ *
+ */
+int pv_set_ccp_attrs(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val)
+{
+ str gname = STR_NULL;
+ str vname = STR_NULL;
+ unsigned int *grpid = NULL;
+ str s = STR_NULL;
+ char *sep = NULL;
+
+ if(val == NULL || (val->flags&PV_VAL_NULL)) {
+ LM_WARN("ignoring null asignment\n");
+ return 0;
+ }
+
+ s = param->pvn.u.isname.name.s;
+
+ sep = q_memrchr(s.s, '.', s.len);
+ if(sep==NULL) {
+ LM_ERR("invalid pv name [%.*s]\n", s.len, s.s);
+ return -1;
+ }
+ gname.s = s.s;
+ gname.len = sep - s.s;
+ vname.s = sep + 1;
+ vname.len = s.s + s.len - sep - 1;
+
+ if (cfg_get_group_id(&gname, &grpid)) {
+ LM_ERR("wrong group syntax. Use either 'group', or 'group[id]'\n");
+ return -1;
+ }
+
+ LM_DBG("setting value for variable: %.*s.%.*s\n", gname.len, gname.s,
+ vname.len, vname.s);
+
+ if(val->flags&PV_TYPE_INT) {
+ if(cfg_set_now_int(_pv_ccp_ctx, &gname, grpid, &vname, val->ri)) {
+ LM_ERR("failed to set int to the variable: [%.*s]\n", s.len, s.s);
+ return -1;
+ }
+ } else {
+ if(cfg_set_now_str(_pv_ccp_ctx, &gname, grpid, &vname, &val->rs)) {
+ LM_ERR("failed to set str to the variable: [%.*s]\n", s.len, s.s);
+ return -1;
+ }
+ }
+ return 0;
+}
diff --git a/src/modules/pv/pv_core.h b/src/modules/pv/pv_core.h
index 70ef3f155c..359fabf850 100644
--- a/src/modules/pv/pv_core.h
+++ b/src/modules/pv/pv_core.h
@@ -402,6 +402,8 @@ int pv_ccp_ctx_init(void);
int pv_parse_ccp_attrs_name(pv_spec_p sp, str *in);
int pv_get_ccp_attrs(sip_msg_t *msg, pv_param_t *param,
pv_value_t *res);
+int pv_set_ccp_attrs(struct sip_msg* msg, pv_param_t *param,
+ int op, pv_value_t *val);
#endif
More information about the sr-dev
mailing list