From: Alan T. DeKok Date: Tue, 13 Aug 2024 20:52:48 +0000 (-0400) Subject: add API to get enumv for time precision X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6c9efa174fa01c088f69fef1ed5b4d235785e6e;p=thirdparty%2Ffreeradius-server.git add API to get enumv for time precision --- diff --git a/share/dictionary/freeradius/dictionary.freeradius.internal b/share/dictionary/freeradius/dictionary.freeradius.internal index 9e091ce8a40..7b11c8099b7 100644 --- a/share/dictionary/freeradius/dictionary.freeradius.internal +++ b/share/dictionary/freeradius/dictionary.freeradius.internal @@ -489,6 +489,22 @@ VALUE TLS-Client-Error-Code No-Application-Protocol 120 ATTRIBUTE TLS-Session-Version 1947 string ATTRIBUTE TLS-Session-Cipher-Suite 1948 string +# 1949 + +# +# Attributes for casting +# +ATTRIBUTE Cast-Time-Res-Sec 1950 time_delta seconds +ATTRIBUTE Cast-Time-Res-Min 1951 time_delta minutes +ATTRIBUTE Cast-Time-Res-Hour 1952 time_delta hours +ATTRIBUTE Cast-Time-Res-Day 1953 time_delta days +ATTRIBUTE Cast-Time-Res-Week 1954 time_delta weeks +ATTRIBUTE Cast-Time-Res-Month 1955 time_delta months +ATTRIBUTE Cast-Time-Res-Year 1956 time_delta years +ATTRIBUTE Cast-Time-Res-Centi-Sec 1957 time_delta centiseconds +ATTRIBUTE Cast-Time-Res-Milli-Sec 1958 time_delta milliseconds +ATTRIBUTE Cast-Time-Res-Micro-Sec 1959 time_delta microseconds +ATTRIBUTE Cast-Time-Res-Nano-Sec 1960 time_delta nanoseconds # # Range: 1951-2199 diff --git a/src/lib/unlang/xlat_eval.c b/src/lib/unlang/xlat_eval.c index 1c5452c7bea..7ef9022d1e1 100644 --- a/src/lib/unlang/xlat_eval.c +++ b/src/lib/unlang/xlat_eval.c @@ -51,9 +51,34 @@ static fr_dict_autoload_t xlat_eval_dict[] = { fr_dict_attr_t const *attr_expr_bool_enum; /* xlat_expr.c */ fr_dict_attr_t const *attr_cast_base; /* xlat_expr.c */ +static fr_dict_attr_t const *attr_cast_time_res_sec; +static fr_dict_attr_t const *attr_cast_time_res_min; +static fr_dict_attr_t const *attr_cast_time_res_hour; +static fr_dict_attr_t const *attr_cast_time_res_day; +static fr_dict_attr_t const *attr_cast_time_res_week; +static fr_dict_attr_t const *attr_cast_time_res_month; +static fr_dict_attr_t const *attr_cast_time_res_year; +static fr_dict_attr_t const *attr_cast_time_res_csec; +static fr_dict_attr_t const *attr_cast_time_res_msec; +static fr_dict_attr_t const *attr_cast_time_res_usec; +static fr_dict_attr_t const *attr_cast_time_res_nsec; + static fr_dict_attr_autoload_t xlat_eval_dict_attr[] = { { .out = &attr_expr_bool_enum, .name = "Expr-Bool-Enum", .type = FR_TYPE_BOOL, .dict = &dict_freeradius }, { .out = &attr_cast_base, .name = "Cast-Base", .type = FR_TYPE_UINT8, .dict = &dict_freeradius }, + + { .out = &attr_cast_time_res_sec, .name = "Cast-Time-Res-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_min, .name = "Cast-Time-Res-Min", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_hour, .name = "Cast-Time-Res-Hour", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_day, .name = "Cast-Time-Res-Day", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_week, .name = "Cast-Time-Res-Week", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_month, .name = "Cast-Time-Res-Month", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_year, .name = "Cast-Time-Res-Year", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_csec, .name = "Cast-Time-Res-Centi-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_msec, .name = "Cast-Time-Res-Milli-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_usec, .name = "Cast-Time-Res-Micro-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { .out = &attr_cast_time_res_nsec, .name = "Cast-Time-Res-Nano-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius }, + { NULL } }; @@ -65,6 +90,59 @@ fr_table_num_sorted_t const xlat_action_table[] = { }; size_t xlat_action_table_len = NUM_ELEMENTS(xlat_action_table); +/* + * This should be updated if fr_time_precision_table[] adds more time resolutions. + */ +static fr_table_ptr_ordered_t const xlat_time_precision_table[] = { + { L("microseconds"), &attr_cast_time_res_usec }, + { L("us"), &attr_cast_time_res_usec }, + + { L("nanoseconds"), &attr_cast_time_res_nsec }, + { L("ns"), &attr_cast_time_res_nsec }, + + { L("milliseconds"), &attr_cast_time_res_msec }, + { L("ms"), &attr_cast_time_res_msec }, + + { L("centiseconds"), &attr_cast_time_res_csec }, + { L("cs"), &attr_cast_time_res_csec }, + + { L("seconds"), &attr_cast_time_res_sec }, + { L("s"), &attr_cast_time_res_sec }, + + { L("minutes"), &attr_cast_time_res_min }, + { L("m"), &attr_cast_time_res_min }, + + { L("hours"), &attr_cast_time_res_hour }, + { L("h"), &attr_cast_time_res_hour }, + + { L("days"), &attr_cast_time_res_day }, + { L("d"), &attr_cast_time_res_day }, + + { L("weeks"), &attr_cast_time_res_week }, + { L("w"), &attr_cast_time_res_week }, + + /* + * These use special values FR_TIME_DUR_MONTH and FR_TIME_DUR_YEAR + */ + { L("months"), &attr_cast_time_res_month }, + { L("M"), &attr_cast_time_res_month }, + + { L("years"), &attr_cast_time_res_year }, + { L("y"), &attr_cast_time_res_year }, + +}; +static size_t xlat_time_precision_table_len = NUM_ELEMENTS(xlat_time_precision_table); + +fr_dict_attr_t const *xlat_time_res_attr(char const *res) +{ + fr_dict_attr_t const **da_p; + + da_p = fr_table_value_by_str(xlat_time_precision_table, res, NULL); + if (!da_p) return NULL; + + return *da_p; +} + static ssize_t xlat_eval_sync(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_head_t const * const head, xlat_escape_legacy_t escape, void const *escape_ctx); diff --git a/src/lib/unlang/xlat_priv.h b/src/lib/unlang/xlat_priv.h index 2f120137c79..806163ed2b9 100644 --- a/src/lib/unlang/xlat_priv.h +++ b/src/lib/unlang/xlat_priv.h @@ -294,6 +294,8 @@ extern fr_dict_attr_t const *attr_expr_bool_enum; extern fr_dict_attr_t const *attr_module_return_code; extern fr_dict_attr_t const *attr_cast_base; +fr_dict_attr_t const *xlat_time_res_attr(char const *res); + /* * xlat_tokenize.c */