Browse code

core: kemi - function to get/set pv with long value

Daniel-Constantin Mierla authored on 24/11/2022 09:15:33
Showing 1 changed files
... ...
@@ -3164,6 +3164,51 @@ static int sr_kemi_pv_geti (sip_msg_t *msg, str *pvn)
3164 3164
 	return vi;
3165 3165
 }
3166 3166
 
3167
+/**
3168
+ *
3169
+ */
3170
+static sr_kemi_xval_t* sr_kemi_pv_getl (sip_msg_t *msg, str *pvn)
3171
+{
3172
+	pv_spec_t *pvs;
3173
+	pv_value_t val;
3174
+	int vi;
3175
+
3176
+	memset(&_sr_kemi_xval, 0, sizeof(sr_kemi_xval_t));
3177
+	_sr_kemi_xval.vtype = SR_KEMIP_LONG;
3178
+
3179
+	LM_DBG("pv get: %.*s\n", pvn->len, pvn->s);
3180
+	vi = pv_locate_name(pvn);
3181
+	if(vi != pvn->len) {
3182
+		LM_WARN("invalid pv [%.*s] (%d/%d)\n", pvn->len, pvn->s, vi, pvn->len);
3183
+		return &_sr_kemi_xval;
3184
+	}
3185
+	pvs = pv_cache_get(pvn);
3186
+	if(pvs==NULL) {
3187
+		LM_WARN("cannot get pv spec for [%.*s]\n", pvn->len, pvn->s);
3188
+		return &_sr_kemi_xval;
3189
+	}
3190
+
3191
+	memset(&val, 0, sizeof(pv_value_t));
3192
+	if(pv_get_spec_value(msg, pvs, &val) != 0) {
3193
+		LM_WARN("unable to get pv value for [%.*s]\n", pvn->len, pvn->s);
3194
+		return &_sr_kemi_xval;
3195
+	}
3196
+	if(val.flags&PV_VAL_NULL) {
3197
+		return &_sr_kemi_xval;
3198
+	}
3199
+	if(val.flags&(PV_TYPE_INT|PV_VAL_INT)) {
3200
+		_sr_kemi_xval.v.l = val.ri;
3201
+		return &_sr_kemi_xval;
3202
+	}
3203
+	if(val.ri!=0) {
3204
+		_sr_kemi_xval.v.l = val.ri;
3205
+		return &_sr_kemi_xval;
3206
+	}
3207
+	str2slong(&val.rs, &_sr_kemi_xval.v.l);
3208
+
3209
+	return &_sr_kemi_xval;
3210
+}
3211
+
3167 3212
 /**
3168 3213
  *
3169 3214
  */
... ...
@@ -3197,6 +3242,43 @@ static int sr_kemi_pv_seti (sip_msg_t *msg, str *pvn, int ival)
3197 3242
 	return SR_KEMI_TRUE;
3198 3243
 }
3199 3244
 
3245
+/**
3246
+ *
3247
+ */
3248
+static int sr_kemi_pv_setl (sip_msg_t *msg, str *pvn, sr_kemi_xval_t *xval)
3249
+{
3250
+	pv_spec_t *pvs;
3251
+	pv_value_t val;
3252
+	int pl;
3253
+
3254
+	LM_DBG("pv get: %.*s\n", pvn->len, pvn->s);
3255
+	pl = pv_locate_name(pvn);
3256
+	if(pl != pvn->len) {
3257
+		LM_ERR("invalid pv [%.*s] (%d/%d)\n", pvn->len, pvn->s, pl, pvn->len);
3258
+		return SR_KEMI_FALSE;
3259
+	}
3260
+	pvs = pv_cache_get(pvn);
3261
+	if(pvs==NULL) {
3262
+		LM_ERR("cannot get pv spec for [%.*s]\n", pvn->len, pvn->s);
3263
+		return SR_KEMI_FALSE;
3264
+	}
3265
+
3266
+	memset(&val, 0, sizeof(pv_value_t));
3267
+	if(xval==NULL || !(xval->vtype & SR_KEMIP_LONG)) {
3268
+		val.ri = 0;
3269
+	} else {
3270
+		val.ri = xval->v.l;
3271
+	}
3272
+	val.flags |= PV_TYPE_INT|PV_VAL_INT;
3273
+
3274
+	if(pv_set_spec_value(msg, pvs, 0, &val)<0) {
3275
+		LM_ERR("unable to set pv [%.*s]\n", pvn->len, pvn->s);
3276
+		return SR_KEMI_FALSE;
3277
+	}
3278
+
3279
+	return SR_KEMI_TRUE;
3280
+}
3281
+
3200 3282
 /**
3201 3283
  *
3202 3284
  */
... ...
@@ -3317,6 +3399,11 @@ static sr_kemi_t _sr_kemi_pv[] = {
3317 3399
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
3318 3400
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3319 3401
 	},
3402
+	{ str_init("pv"), str_init("getl"),
3403
+		SR_KEMIP_XVAL, sr_kemi_pv_getl,
3404
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
3405
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3406
+	},
3320 3407
 	{ str_init("pv"), str_init("getvn"),
3321 3408
 		SR_KEMIP_XVAL, sr_kemi_pv_getvn,
3322 3409
 		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
... ...
@@ -3332,6 +3419,11 @@ static sr_kemi_t _sr_kemi_pv[] = {
3332 3419
 		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
3333 3420
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3334 3421
 	},
3422
+	{ str_init("pv"), str_init("setl"),
3423
+		SR_KEMIP_BOOL, sr_kemi_pv_setl,
3424
+		{ SR_KEMIP_STR, SR_KEMIP_LONG, SR_KEMIP_NONE,
3425
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3426
+	},
3335 3427
 	{ str_init("pv"), str_init("sets"),
3336 3428
 		SR_KEMIP_BOOL, sr_kemi_pv_sets,
3337 3429
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,