From: Arran Cudbard-Bell Date: Thu, 28 Oct 2021 16:29:00 +0000 (-0400) Subject: Move time precision table into value.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49ec3bc20d5b9a56a85193c5f4a325ae63e7643e;p=thirdparty%2Ffreeradius-server.git Move time precision table into value.c --- diff --git a/src/lib/util/dict_print.c b/src/lib/util/dict_print.c index 69a0cb471a9..bca36b7acd9 100644 --- a/src/lib/util/dict_print.c +++ b/src/lib/util/dict_print.c @@ -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 }); diff --git a/src/lib/util/dict_priv.h b/src/lib/util/dict_priv.h index 5345ef694a9..68a25fa9667 100644 --- a/src/lib/util/dict_priv.h +++ b/src/lib/util/dict_priv.h @@ -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); diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index fe142d8201a..33e1903b30e 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -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, ""), diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index ed6ee86d087..74b0da71a0b 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -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 * */ diff --git a/src/lib/util/time.c b/src/lib/util/time.c index e23a4149bf1..bec951f7c4a 100644 --- a/src/lib/util/time.c +++ b/src/lib/util/time.c @@ -26,7 +26,7 @@ RCSID("$Id$") #include -#include +#include /* * Avoid too many ifdef's later in the code. @@ -47,6 +47,44 @@ USES_APPLE_DEPRECATED_API # include #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 diff --git a/src/lib/util/time.h b/src/lib/util/time.h index 3be05a24784..5308e61de6f 100644 --- a/src/lib/util/time.h +++ b/src/lib/util/time.h @@ -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) }