From f324a1a432b02137cab73978fe5df5e11005d938 Mon Sep 17 00:00:00 2001 From: Vlad Paiu Date: Tue, 3 Dec 2024 11:18:05 +0000 Subject: [PATCH 1/2] Add support for bigints ( store as string when exposing to opensips script ) --- modules/json/json.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/json/json.c b/modules/json/json.c index 9fdbd20b8e8..35fef714652 100644 --- a/modules/json/json.c +++ b/modules/json/json.c @@ -457,10 +457,16 @@ int pv_get_json_ext(struct sip_msg* msg, pv_param_t* pvp, pv_value_t* val, int if( json_object_is_type(obj, json_type_int) ) { - val->rs.s = sint2str(json_object_get_int(obj), &val->rs.len); - val->ri = json_object_get_int(obj);; - val->flags |= PV_VAL_INT|PV_TYPE_INT|PV_VAL_STR; - + int_value = json_object_get_int64(obj); + val->rs.s = sint2str(int_value, &val->rs.len); + if (int_value<=INT_MAX && int_value>=INT_MIN) { + /* safe to store it as an INT in the pvar */ + val->ri = int_value;; + val->flags |= PV_VAL_INT|PV_TYPE_INT|PV_VAL_STR; + } else { + /* we would overflow/underflow, store as string only */ + val->flags |= PV_VAL_STR; + } } else if( json_object_is_type(obj, json_type_string)) { From ae113c7271ef0a5baa4674972d3b713ac6def6c7 Mon Sep 17 00:00:00 2001 From: Vlad Paiu Date: Thu, 5 Dec 2024 12:18:03 +0000 Subject: [PATCH 2/2] Fixed undefined int_value --- modules/json/json.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/json/json.c b/modules/json/json.c index 35fef714652..44ed602e2e7 100644 --- a/modules/json/json.c +++ b/modules/json/json.c @@ -415,6 +415,7 @@ int pv_get_json_ext(struct sip_msg* msg, pv_param_t* pvp, pv_value_t* val, int json_t * obj; json_name * id = (json_name *) pvp->pvn.u.dname; UNUSED(id); + int64_t int_value; if( expand_tag_list( msg, ((json_name *)pvp->pvn.u.dname)->tags ) < 0) { @@ -461,7 +462,7 @@ int pv_get_json_ext(struct sip_msg* msg, pv_param_t* pvp, pv_value_t* val, int val->rs.s = sint2str(int_value, &val->rs.len); if (int_value<=INT_MAX && int_value>=INT_MIN) { /* safe to store it as an INT in the pvar */ - val->ri = int_value;; + val->ri = int_value; val->flags |= PV_VAL_INT|PV_TYPE_INT|PV_VAL_STR; } else { /* we would overflow/underflow, store as string only */