]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Move time precision table into value.c
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 28 Oct 2021 16:29:00 +0000 (12:29 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 28 Oct 2021 16:31:10 +0000 (12:31 -0400)
src/lib/util/dict_print.c
src/lib/util/dict_priv.h
src/lib/util/dict_tokenize.c
src/lib/util/dict_util.c
src/lib/util/time.c
src/lib/util/time.h

index 69a0cb471a9749822e0c90386e7474223924644c..bca36b7acd90986986270039a812b4a5dd3e336d 100644 (file)
@@ -88,7 +88,7 @@ ssize_t fr_dict_attr_flags_print(fr_sbuff_t *out, fr_dict_t const *dict, fr_type
         */
        if ((type == FR_TYPE_DATE) || (type == FR_TYPE_TIME_DELTA)) {
                FR_SBUFF_IN_STRCPY_RETURN(&our_out,
-                                         fr_table_str_by_value(date_precision_table, flags->flag_time_res, "?"));
+                                         fr_table_str_by_value(fr_time_precision_table, flags->flag_time_res, "?"));
        }
 
        fr_sbuff_trim(&our_out, (bool[UINT8_MAX + 1]){ [','] = true });
index 5345ef694a93124e1978dc87ba5e88f72b765118..68a25fa9667c513ee2b7cb87b71c696df5a4b66b 100644 (file)
@@ -135,9 +135,6 @@ struct fr_dict_gctx_s {
 
 extern fr_dict_gctx_t *dict_gctx;
 
-extern fr_table_num_ordered_t const    date_precision_table[];
-extern size_t                          date_precision_table_len;
-
 bool                   dict_has_dependents(fr_dict_t *dict);
 
 int                    dict_dependent_add(fr_dict_t *dict, char const *dependent);
index fe142d8201a671324f58541c9a40b22b127e34bd..33e1903b30e66f5867fde77b329026a973056d2a 100644 (file)
@@ -445,7 +445,7 @@ static int dict_process_flag_field(dict_tokenize_ctx_t *ctx, char *name, fr_type
                        } else {
                                int precision;
 
-                               precision = fr_table_value_by_str(date_precision_table, key, -1);
+                               precision = fr_table_value_by_str(fr_time_precision_table, key, -1);
                                if (precision < 0) {
                                        fr_strerror_printf("Unknown %s precision '%s'",
                                                           fr_table_str_by_value(fr_value_box_type_table, type, "<UNKNOWN>"),
index ed6ee86d087f0524d410c2a3cd892c1476efb768..74b0da71a0bf0b4702be8da2e1838d865935f238 100644 (file)
@@ -34,25 +34,6 @@ RCSID("$Id$")
 
 fr_dict_gctx_t *dict_gctx = NULL;      //!< Top level structure containing global dictionary state.
 
-fr_table_num_ordered_t const date_precision_table[] = {
-       { L("microseconds"),    FR_TIME_RES_USEC },
-       { L("us"),              FR_TIME_RES_USEC },
-
-       { L("nanoseconds"),     FR_TIME_RES_NSEC },
-       { L("ns"),              FR_TIME_RES_NSEC },
-
-       { L("milliseconds"),    FR_TIME_RES_MSEC },
-       { L("ms"),              FR_TIME_RES_MSEC },
-
-       { L("centiseconds"),    FR_TIME_RES_CSEC },
-       { L("cs"),              FR_TIME_RES_CSEC },
-
-       { L("seconds"),         FR_TIME_RES_SEC },
-       { L("s"),               FR_TIME_RES_SEC }
-
-};
-size_t date_precision_table_len = NUM_ELEMENTS(date_precision_table);
-
 /** Characters allowed in dictionary names
  *
  */
index e23a4149bf16d21a36e30afaebb484bfdfc38bbe..bec951f7c4af5b9bcb7242452b3ec4220cc2c27a 100644 (file)
@@ -26,7 +26,7 @@
 RCSID("$Id$")
 
 #include <freeradius-devel/autoconf.h>
-#include <freeradius-devel/util/dict.h>
+#include <freeradius-devel/util/time.h>
 
 /*
  *     Avoid too many ifdef's later in the code.
@@ -47,6 +47,44 @@ USES_APPLE_DEPRECATED_API
 #  include <mach/mach_time.h>
 #endif
 
+int64_t const fr_time_multiplier_by_res[] = {
+       [FR_TIME_RES_NSEC]      = 1,
+       [FR_TIME_RES_USEC]      = NSEC / USEC,
+       [FR_TIME_RES_MSEC]      = NSEC / MSEC,
+       [FR_TIME_RES_CSEC]      = NSEC / CSEC,
+       [FR_TIME_RES_SEC]       = NSEC,
+       [FR_TIME_RES_MIN]       = (int64_t)NSEC * 60,
+       [FR_TIME_RES_HOUR]      = (int64_t)NSEC * 3600,
+       [FR_TIME_RES_DAY]       = (int64_t)NSEC * 386400
+};
+
+fr_table_num_ordered_t const fr_time_precision_table[] = {
+       { L("microseconds"),    FR_TIME_RES_USEC },
+       { L("us"),              FR_TIME_RES_USEC },
+
+       { L("nanoseconds"),     FR_TIME_RES_NSEC },
+       { L("ns"),              FR_TIME_RES_NSEC },
+
+       { L("milliseconds"),    FR_TIME_RES_MSEC },
+       { L("ms"),              FR_TIME_RES_MSEC },
+
+       { L("centiseconds"),    FR_TIME_RES_CSEC },
+       { L("cs"),              FR_TIME_RES_CSEC },
+
+       { L("seconds"),         FR_TIME_RES_SEC },
+       { L("s"),               FR_TIME_RES_SEC },
+
+       { L("minutes"),         FR_TIME_RES_MIN },
+       { L("m"),               FR_TIME_RES_MIN },
+
+       { L("hours"),           FR_TIME_RES_HOUR },
+       { L("h"),               FR_TIME_RES_HOUR },
+
+       { L("days"),            FR_TIME_RES_DAY },
+       { L("d"),               FR_TIME_RES_DAY }
+
+};
+size_t fr_time_precision_table_len = NUM_ELEMENTS(fr_time_precision_table);
 
 _Atomic int64_t                        our_realtime;   //!< realtime at the start of the epoch in nanoseconds.
 static char const              *tz_names[2] = { NULL, NULL };  //!< normal, DST, from localtime_r(), tm_zone
index 3be05a2478435ff17d88e5ec62c4d5ebd7ffaef4..5308e61de6ff9179841957af8d813a356aafb83a 100644 (file)
@@ -88,6 +88,9 @@ typedef struct fr_unix_time_s {
        uint64_t value;
 } fr_unix_time_t;
 
+extern int64_t const                   fr_time_multiplier_by_res[];
+extern fr_table_num_ordered_t const    fr_time_precision_table[];
+extern size_t                          fr_time_precision_table_len;
 #define fr_unix_time_max() (fr_unix_time_t){ .value = UINT64_MAX }
 #define fr_unix_time_min() (fr_unix_time_t){ .value = 0 }
 #define fr_unix_time_wrap(_time) (fr_unix_time_t){ .value = (_time) }