]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Convert JSON integers to the smallest signed or unsigned integer type
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 13 Feb 2018 16:55:00 +0000 (16:55 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 13 Feb 2018 16:55:00 +0000 (16:55 +0000)
When the code was first writen we didn't have the full range of signed types.

raddb/mods-available/json
src/modules/rlm_json/json.c

index 0ed1ad607f08ff116ac07f715dcfb8482135add4..cfe71c0f6ba8d44405e8fc420e7b74420420fd86 100644 (file)
@@ -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/
 #
 # 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.
 #
index 5e3da14fd005c32d0214a5cd674ad17328aa1cbc..2e102f1b014b4c796e7fce2940d6766fa1922928 100644 (file)
@@ -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;
                }