Browse code

pv: kemi function to get $shvinc(name) value

Daniel-Constantin Mierla authored on 11/05/2022 14:42:19
Showing 3 changed files
... ...
@@ -2872,6 +2872,11 @@ static sr_kemi_t sr_kemi_pvx_exports[] = {
2872 2872
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
2873 2873
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2874 2874
 	},
2875
+	{ str_init("pvx"), str_init("shvinc_get"),
2876
+		SR_KEMIP_XVAL, ki_shvinc_get,
2877
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
2878
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2879
+	},
2875 2880
 	{ str_init("pvx"), str_init("pv_var_to_xavp"),
2876 2881
 		SR_KEMIP_INT, ki_var_to_xavp,
2877 2882
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
... ...
@@ -796,4 +796,34 @@ sr_kemi_xval_t* ki_shv_get(sip_msg_t *msg, str *vname)
796 796
 	}
797 797
 }
798 798
 
799
+/**
800
+ *
801
+ */
802
+sr_kemi_xval_t* ki_shvinc_get(sip_msg_t *msg, str *vname)
803
+{
804
+	sh_var_t *shv = NULL;
805
+
806
+	memset(&_sr_kemi_shv_xval, 0, sizeof(sr_kemi_xval_t));
807
+
808
+	shv = get_shvar_by_name(vname);
809
+	if(shv==NULL) {
810
+		LM_WARN("$shv(%.*s) is not defined - return value 0\n",
811
+				vname->len, vname->s);
812
+		_sr_kemi_shv_xval.vtype = SR_KEMIP_INT;
813
+		_sr_kemi_shv_xval.v.n = 0;
814
+		return &_sr_kemi_shv_xval;
815
+	}
816
+
817
+	lock_shvar(shv);
818
+	if(shv->v.flags&VAR_VAL_STR) {
819
+		_sr_kemi_shv_xval.v.n = 0;
820
+	} else {
821
+		shv->v.value.n++;
822
+		_sr_kemi_shv_xval.v.n = shv->v.value.n;
823
+	}
824
+	unlock_shvar(shv);
825
+	_sr_kemi_shv_xval.vtype = SR_KEMIP_INT;
826
+	return &_sr_kemi_shv_xval;
827
+}
828
+
799 829
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -71,6 +71,7 @@ void rpc_shv_set(rpc_t* rpc, void* c);
71 71
 int ki_shv_seti(sip_msg_t *msg, str *vname, int ival);
72 72
 int ki_shv_sets(sip_msg_t *msg, str *vname, str *sval);
73 73
 sr_kemi_xval_t* ki_shv_get(sip_msg_t *msg, str *vname);
74
+sr_kemi_xval_t* ki_shvinc_get(sip_msg_t *msg, str *vname);
74 75
 
75 76
 #endif
76 77