Browse code

pv: new variable $xavp_count

Retrieve the number of rows stored in an xavp

As discussed on the mailing list, this is useful to at least two people.

Nicolas C authored on 17/11/2021 12:35:28
Showing 3 changed files
... ...
@@ -96,6 +96,9 @@ static pv_export_t mod_pvs[] = {
96 96
 	{ {"xavp", sizeof("xavp")-1}, /* xavp */
97 97
 		PVT_XAVP, pv_get_xavp, pv_set_xavp,
98 98
 		pv_parse_xavp_name, 0, 0, 0 },
99
+	{ {"xavp_count", sizeof("xavp_count")-1},
100
+		PVT_OTHER, pv_get_xavp_count, 0,
101
+		pv_parse_xavp_count_name, 0, 0, 0 },
99 102
 	{ {"xavu", sizeof("xavu")-1}, /* xavu */
100 103
 		PVT_XAVU, pv_get_xavu, pv_set_xavu,
101 104
 		pv_parse_xavu_name, 0, 0, 0 },
... ...
@@ -1499,3 +1499,36 @@ int pv_set_xavi(struct sip_msg* msg, pv_param_t *param,
1499 1499
 
1500 1500
 	return 0;
1501 1501
 }
1502
+
1503
+/**
1504
+ * Get the number of rows stored in an xavp.
1505
+ */
1506
+int pv_get_xavp_count(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
1507
+{
1508
+	if (msg == NULL || param == NULL || param->pvn.type != PV_NAME_INTSTR) {
1509
+		LM_ERR("Invalid parameters\n");
1510
+		return -1;
1511
+	}
1512
+
1513
+	int c = xavp_count(&param->pvn.u.isname.name.s, NULL);
1514
+
1515
+	return pv_get_sintval(msg, param, res, c);
1516
+}
1517
+
1518
+int pv_parse_xavp_count_name(pv_spec_p sp, str *in)
1519
+{
1520
+	if (sp == NULL || in == NULL || in->len <= 0) {
1521
+		LM_ERR("Invalid parameters\n");
1522
+		return -1;
1523
+	}
1524
+
1525
+	str pvs;
1526
+	pvs = *in;
1527
+	trim(&pvs);
1528
+
1529
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
1530
+	sp->pvp.pvn.u.isname.type = AVP_NAME_STR;
1531
+	sp->pvp.pvn.u.isname.name.s = pvs;
1532
+
1533
+	return 0;
1534
+}
... ...
@@ -49,4 +49,7 @@ int xavu_params_explode(str *params, str *xname);
49 49
 int pv_var_to_xavp(str *varname, str *xname);
50 50
 int pv_xavp_to_var(str *xname);
51 51
 
52
+int pv_get_xavp_count(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
53
+int pv_parse_xavp_count_name(pv_spec_p sp, str *in);
54
+
52 55
 #endif