Browse code

pv: added set function for variable $rcv(buf)

Daniel-Constantin Mierla authored on 08/04/2022 17:17:35
Showing 3 changed files
... ...
@@ -91,7 +91,7 @@ static pv_export_t mod_pvs[] = {
91 91
 		pv_parse_snd_name, 0, 0, 0 },
92 92
 	{ {"sndfrom", (sizeof("sndfrom")-1)}, PVT_OTHER, pv_get_sndfrom, 0,
93 93
 		pv_parse_snd_name, 0, 0, 0 },
94
-	{ {"rcv", (sizeof("rcv")-1)}, PVT_OTHER, pv_get_rcv, 0,
94
+	{ {"rcv", (sizeof("rcv")-1)}, PVT_OTHER, pv_get_rcv, pv_set_rcv,
95 95
 		pv_parse_rcv_name, 0, 0, 0 },
96 96
 	{ {"xavp", sizeof("xavp")-1}, /* xavp */
97 97
 		PVT_XAVP, pv_get_xavp, pv_set_xavp,
... ...
@@ -617,6 +617,60 @@ int pv_get_rcv(struct sip_msg *msg, pv_param_t *param,
617 617
 	return 0;
618 618
 }
619 619
 
620
+int pv_set_rcv(sip_msg_t *msg, pv_param_t *param, int op, pv_value_t *val)
621
+{
622
+	sr_net_info_t *neti = NULL;
623
+	str s;
624
+
625
+	neti = ksr_evrt_rcvnetinfo_get();
626
+
627
+	if (neti==NULL || neti->rcv==NULL || neti->rcv->bind_address==NULL) {
628
+		LM_ERR("received info not set\n");
629
+		return -1;
630
+	}
631
+
632
+	if(param==NULL) {
633
+		LM_ERR("bad parameters\n");
634
+		return -1;
635
+	}
636
+	switch(param->pvn.u.isname.name.n)
637
+	{
638
+		case 1: /* buf */
639
+			if (neti->bufsize <= 0) {
640
+				LM_ERR("received data cannot be changed\n");
641
+				return -1;
642
+			}
643
+			if(val==NULL || (val->flags&PV_VAL_NULL)) {
644
+				neti->data.s[0] = '\0';
645
+				neti->data.len = 0;
646
+				break;
647
+			}
648
+			if(!(val->flags&PV_VAL_STR)) {
649
+				LM_ERR("str value required to set received data\n");
650
+				return -1;
651
+			}
652
+			if(val->rs.len<=0) {
653
+				neti->data.s[0] = '\0';
654
+				neti->data.len = 0;
655
+				break;
656
+			}
657
+
658
+			if (unlikely(val->rs.len >= neti->bufsize - 1)) {
659
+				LM_ERR("new data is too long: %.*s\n",
660
+								val->rs.len, val->rs.s);
661
+				return -1;
662
+			}
663
+			memcpy(neti->data.s, val->rs.s, val->rs.len);
664
+			neti->data.s[val->rs.len] = '\0';
665
+			neti->data.len = val->rs.len;
666
+		break;
667
+		default:
668
+			LM_DBG("set operation not supported for field %d\n",
669
+					param->pvn.u.isname.name.n);
670
+	}
671
+	return 0;
672
+}
673
+
620 674
 int pv_parse_rcv_name(pv_spec_p sp, str *in)
621 675
 {
622 676
 	if(sp==NULL || in==NULL || in->len<=0)
... ...
@@ -42,6 +42,7 @@ int pv_parse_snd_name(pv_spec_p sp, str *in);
42 42
 
43 43
 int pv_get_rcv(struct sip_msg *msg, pv_param_t *param,
44 44
 		pv_value_t *res);
45
+int pv_set_rcv(sip_msg_t *msg, pv_param_t *param, int op, pv_value_t *val);
45 46
 int pv_parse_rcv_name(pv_spec_p sp, str *in);
46 47
 
47 48
 int pv_get_nh(struct sip_msg *msg, pv_param_t *param,