Browse code

pv: new var $defn(name)

- return the value of a define converted to numbaer (signed int)

Daniel-Constantin Mierla authored on 11/12/2020 13:21:53
Showing 3 changed files
... ...
@@ -196,8 +196,10 @@ static pv_export_t mod_pvs[] = {
196 196
 	{{"dd", (sizeof("dd")-1)}, /* */
197 197
 		PVT_OTHER, pv_get_dsturi_attr, 0,
198 198
 		0, 0, pv_init_iname, 1},
199
-	{{"def", (sizeof("env")-1)}, PVT_OTHER, pv_get_def, 0,
199
+	{{"def", (sizeof("def")-1)}, PVT_OTHER, pv_get_def, 0,
200 200
 		pv_parse_def_name, 0, 0, 0},
201
+	{{"defn", (sizeof("defn")-1)}, PVT_OTHER, pv_get_defn, 0,
202
+		pv_parse_defn_name, 0, 0, 0},
201 203
 	{{"di", (sizeof("di")-1)}, /* */
202 204
 		PVT_OTHER, pv_get_diversion, 0,
203 205
 		0, 0, pv_init_iname, 1},
... ...
@@ -3797,3 +3797,29 @@ int pv_get_def(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
3797 3797
 	return pv_get_null(msg, param, res);
3798 3798
 }
3799 3799
 
3800
+int pv_parse_defn_name(pv_spec_p sp, str *in)
3801
+{
3802
+	if (in == NULL || in->s == NULL || sp == NULL) {
3803
+		LM_ERR("INVALID DEF NAME\n");
3804
+		return -1;
3805
+	}
3806
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
3807
+	sp->pvp.pvn.u.isname.type = AVP_NAME_STR;
3808
+	sp->pvp.pvn.u.isname.name.s = *in;
3809
+	return 0;
3810
+
3811
+}
3812
+
3813
+int pv_get_defn(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
3814
+{
3815
+	int n = 0;
3816
+	str *val = pp_define_get(param->pvn.u.isname.name.s.len,
3817
+			param->pvn.u.isname.name.s.s);
3818
+
3819
+	if (val) {
3820
+		str2sint(val, &n);
3821
+		return pv_get_intstrval(msg, param, res, n, val);
3822
+	} else {
3823
+		return pv_get_sintval(msg, param, res, n);
3824
+	}
3825
+}
... ...
@@ -397,5 +397,8 @@ int pv_get_ksr_attrs(sip_msg_t *msg, pv_param_t *param,
397 397
 int pv_parse_def_name(pv_spec_p sp, str *in);
398 398
 int pv_get_def(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
399 399
 
400
+int pv_parse_defn_name(pv_spec_p sp, str *in);
401
+int pv_get_defn(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
402
+
400 403
 #endif
401 404