Skip to content

Commit

Permalink
Merge pull request #3534 from vladpaiu/json_bigint
Browse files Browse the repository at this point in the history
Add support for bigints in JSON ( store as string )
  • Loading branch information
liviuchircu authored Dec 5, 2024
2 parents 5eae5fb + ae113c7 commit 3197a61
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions modules/json/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -457,10 +458,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))
{
Expand Down

0 comments on commit 3197a61

Please sign in to comment.