Browse code

core: kemi - exported KSR.pv.geti("pv")

- return integer value of the pv, trying to convert if its value is
string

Daniel-Constantin Mierla authored on 12/05/2021 06:15:33
Showing 1 changed files
... ...
@@ -2855,6 +2855,47 @@ static sr_kemi_xval_t* sr_kemi_pv_getvn (sip_msg_t *msg, str *pvn, int xival)
2855 2855
 	return sr_kemi_pv_get_valx (msg, pvn, NULL, xival, 1);
2856 2856
 }
2857 2857
 
2858
+/**
2859
+ *
2860
+ */
2861
+static int sr_kemi_pv_geti (sip_msg_t *msg, str *pvn)
2862
+{
2863
+	pv_spec_t *pvs;
2864
+	pv_value_t val;
2865
+	int vi;
2866
+
2867
+	LM_DBG("pv get: %.*s\n", pvn->len, pvn->s);
2868
+	vi = pv_locate_name(pvn);
2869
+	if(vi != pvn->len) {
2870
+		LM_WARN("invalid pv [%.*s] (%d/%d)\n", pvn->len, pvn->s, vi, pvn->len);
2871
+		return 0;
2872
+	}
2873
+	pvs = pv_cache_get(pvn);
2874
+	if(pvs==NULL) {
2875
+		LM_WARN("cannot get pv spec for [%.*s]\n", pvn->len, pvn->s);
2876
+		return 0;
2877
+	}
2878
+
2879
+	memset(&val, 0, sizeof(pv_value_t));
2880
+	if(pv_get_spec_value(msg, pvs, &val) != 0) {
2881
+		LM_WARN("unable to get pv value for [%.*s]\n", pvn->len, pvn->s);
2882
+		return 0;
2883
+	}
2884
+	if(val.flags&PV_VAL_NULL) {
2885
+		return 0;
2886
+	}
2887
+	if(val.flags&(PV_TYPE_INT|PV_VAL_INT)) {
2888
+		return val.ri;
2889
+	}
2890
+	if(val.ri!=0) {
2891
+		return val.ri;
2892
+	}
2893
+	vi = 0;
2894
+	str2sint(&val.rs, &vi);
2895
+
2896
+	return vi;
2897
+}
2898
+
2858 2899
 /**
2859 2900
  *
2860 2901
  */
... ...
@@ -3003,6 +3044,11 @@ static sr_kemi_t _sr_kemi_pv[] = {
3003 3044
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
3004 3045
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3005 3046
 	},
3047
+	{ str_init("pv"), str_init("geti"),
3048
+		SR_KEMIP_INT, sr_kemi_pv_geti,
3049
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
3050
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3051
+	},
3006 3052
 	{ str_init("pv"), str_init("getvn"),
3007 3053
 		SR_KEMIP_XVAL, sr_kemi_pv_getvn,
3008 3054
 		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,