From: Arran Cudbard-Bell Date: Tue, 13 Feb 2018 16:55:00 +0000 (+0000) Subject: Convert JSON integers to the smallest signed or unsigned integer type X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7da2c8851eee4824aa946edb95d2e6a5e434b341;p=thirdparty%2Ffreeradius-server.git Convert JSON integers to the smallest signed or unsigned integer type When the code was first writen we didn't have the full range of signed types. --- diff --git a/raddb/mods-available/json b/raddb/mods-available/json index 0ed1ad607f0..cfe71c0f6ba 100644 --- a/raddb/mods-available/json +++ b/raddb/mods-available/json @@ -5,7 +5,7 @@ # JSON module registers a map function to allow mapping fields from JSON # structures to attributes. # -# The path through the JSON document's tree is specified with FR jpath, +# The path through the JSON document's tree is specified with FR jpath, # which is the FreeRADIUS implementation of the jpath grammar described here: # # http://goessner.net/articles/JsonPath/ @@ -22,10 +22,6 @@ # # Automatic casting will occur between JSON and attribute types where possible. # -# FreeRADIUS does not currently have a signed64 or floating point type, to map -# large signed numbers and JSON doubles to. These may instead be written to -# string type attributes. -# # Assignment of JSON objects/arrays to strings is supported, in which case the # JSON serialized form of the object/array is used. # diff --git a/src/modules/rlm_json/json.c b/src/modules/rlm_json/json.c index 5e3da14fd00..2e102f1b014 100644 --- a/src/modules/rlm_json/json.c +++ b/src/modules/rlm_json/json.c @@ -77,25 +77,30 @@ int fr_json_object_to_value_box(TALLOC_CTX *ctx, fr_value_box_t *out, json_objec num = json_object_get_int(object); #else num = json_object_get_int64(object); - if (num < INT32_MIN) { /* 64bit signed (not supported)*/ - fr_strerror_printf("Signed 64bit integers are not supported"); - return -1; - } - if (num > UINT32_MAX) { /* 64bit unsigned (supported) */ + if (num < INT32_MIN) { /* 64bit signed*/ + in.type = FR_TYPE_INT64; + in.vb_int64 = (int64_t) num; + } else if (num > UINT32_MAX) { /* 64bit unsigned */ in.type = FR_TYPE_UINT64; in.vb_uint64 = (uint64_t) num; } else #endif - if (num < 0) { /* 32bit signed (supported) */ + if (num < INT16_MIN) { /* 32bit signed */ in.type = FR_TYPE_INT32; - in.vb_int32 = num; - } else if (num > UINT16_MAX) { /* 32bit unsigned (supported) */ + in.vb_int32 = (int32_t)num; + } else if (num < INT8_MIN) { /* 16bit signed */ + in.type = FR_TYPE_INT16; + in.vb_int16 = (int16_t)num; + } else if (num < 0) { /* 8bit signed */ + in.type = FR_TYPE_INT8; + in.vb_int8 = (int8_t)num; + } else if (num > UINT16_MAX) { /* 32bit unsigned */ in.type = FR_TYPE_UINT32; in.vb_uint32 = (uint32_t) num; - } else if (num > UINT8_MAX) { /* 16bit unsigned (supported) */ + } else if (num > UINT8_MAX) { /* 16bit unsigned */ in.type = FR_TYPE_UINT16; in.vb_uint16 = (uint16_t) num; - } else { /* 8bit unsigned (supported) */ + } else { /* 8bit unsigned */ in.type = FR_TYPE_UINT8; in.vb_uint8 = (uint8_t) num; }