Module: kamailio
Branch: master
Commit: ba28855a1745e0b084d230958bd3fbb5b0e23847
URL:
https://github.com/kamailio/kamailio/commit/ba28855a1745e0b084d230958bd3fbb…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-04-08T19:17:35+02:00
pv: added set function for variable $rcv(buf)
---
Modified: src/modules/pv/pv.c
Modified: src/modules/pv/pv_branch.c
Modified: src/modules/pv/pv_branch.h
---
Diff:
https://github.com/kamailio/kamailio/commit/ba28855a1745e0b084d230958bd3fbb…
Patch:
https://github.com/kamailio/kamailio/commit/ba28855a1745e0b084d230958bd3fbb…
---
diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index c34ce5dd31..cdd34ce5b9 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -91,7 +91,7 @@ static pv_export_t mod_pvs[] = {
pv_parse_snd_name, 0, 0, 0 },
{ {"sndfrom", (sizeof("sndfrom")-1)}, PVT_OTHER, pv_get_sndfrom, 0,
pv_parse_snd_name, 0, 0, 0 },
- { {"rcv", (sizeof("rcv")-1)}, PVT_OTHER, pv_get_rcv, 0,
+ { {"rcv", (sizeof("rcv")-1)}, PVT_OTHER, pv_get_rcv, pv_set_rcv,
pv_parse_rcv_name, 0, 0, 0 },
{ {"xavp", sizeof("xavp")-1}, /* xavp */
PVT_XAVP, pv_get_xavp, pv_set_xavp,
diff --git a/src/modules/pv/pv_branch.c b/src/modules/pv/pv_branch.c
index ecce3156e7..83cc273f12 100644
--- a/src/modules/pv/pv_branch.c
+++ b/src/modules/pv/pv_branch.c
@@ -617,6 +617,60 @@ int pv_get_rcv(struct sip_msg *msg, pv_param_t *param,
return 0;
}
+int pv_set_rcv(sip_msg_t *msg, pv_param_t *param, int op, pv_value_t *val)
+{
+ sr_net_info_t *neti = NULL;
+ str s;
+
+ neti = ksr_evrt_rcvnetinfo_get();
+
+ if (neti==NULL || neti->rcv==NULL || neti->rcv->bind_address==NULL) {
+ LM_ERR("received info not set\n");
+ return -1;
+ }
+
+ if(param==NULL) {
+ LM_ERR("bad parameters\n");
+ return -1;
+ }
+ switch(param->pvn.u.isname.name.n)
+ {
+ case 1: /* buf */
+ if (neti->bufsize <= 0) {
+ LM_ERR("received data cannot be changed\n");
+ return -1;
+ }
+ if(val==NULL || (val->flags&PV_VAL_NULL)) {
+ neti->data.s[0] = '\0';
+ neti->data.len = 0;
+ break;
+ }
+ if(!(val->flags&PV_VAL_STR)) {
+ LM_ERR("str value required to set received data\n");
+ return -1;
+ }
+ if(val->rs.len<=0) {
+ neti->data.s[0] = '\0';
+ neti->data.len = 0;
+ break;
+ }
+
+ if (unlikely(val->rs.len >= neti->bufsize - 1)) {
+ LM_ERR("new data is too long: %.*s\n",
+ val->rs.len, val->rs.s);
+ return -1;
+ }
+ memcpy(neti->data.s, val->rs.s, val->rs.len);
+ neti->data.s[val->rs.len] = '\0';
+ neti->data.len = val->rs.len;
+ break;
+ default:
+ LM_DBG("set operation not supported for field %d\n",
+ param->pvn.u.isname.name.n);
+ }
+ return 0;
+}
+
int pv_parse_rcv_name(pv_spec_p sp, str *in)
{
if(sp==NULL || in==NULL || in->len<=0)
diff --git a/src/modules/pv/pv_branch.h b/src/modules/pv/pv_branch.h
index a83c98208b..5252db0d6b 100644
--- a/src/modules/pv/pv_branch.h
+++ b/src/modules/pv/pv_branch.h
@@ -42,6 +42,7 @@ int pv_parse_snd_name(pv_spec_p sp, str *in);
int pv_get_rcv(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
+int pv_set_rcv(sip_msg_t *msg, pv_param_t *param, int op, pv_value_t *val);
int pv_parse_rcv_name(pv_spec_p sp, str *in);
int pv_get_nh(struct sip_msg *msg, pv_param_t *param,