From: Matthew Newton Date: Wed, 27 Sep 2023 09:01:26 +0000 (+0100) Subject: use space separator X-Git-Tag: release_3_2_4~132 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ba75d936d30e3882058b17e8c3665cb0ec2139c0;p=thirdparty%2Ffreeradius-server.git use space separator --- diff --git a/raddb/mods-available/date b/raddb/mods-available/date index 69d8f6ab90..2d7d85ed99 100644 --- a/raddb/mods-available/date +++ b/raddb/mods-available/date @@ -41,18 +41,18 @@ date wispr2date { # microseconds; and # - calculate the time elapsed since a given time. # -# Syntax is: %{time_since:BASE[:(number|&attribute)]} +# Syntax is: %{time_since:BASE[ (number|&attribute)]} # where "BASE" is "s", "ms" or "us". # # Examples: # %{time_since:s} # - time in seconds since the epoch, same as %c # -# %{time_since:s:1695753388} +# %{time_since:s 1695753388} # - time in seconds since Tue 26 Sep 19:36:28 BST 2023 # (which is 1695753388 in UNIX time) # -# %{time_since:s:&Tmp-Integer-0} +# %{time_since:s &Tmp-Integer-0} # - Time since the number of seconds in Tmp-Integer-0 # # %{time_since:ms} @@ -76,5 +76,5 @@ date wispr2date { # } # ldap # update request { -# &Tmp-Integer64-1 := %{time_since:us:&Tmp-Integer64-0}" +# &Tmp-Integer64-1 := %{time_since:us &Tmp-Integer64-0}" # } diff --git a/src/modules/rlm_date/rlm_date.c b/src/modules/rlm_date/rlm_date.c index b9f42a5dfa..b46bfe1e88 100644 --- a/src/modules/rlm_date/rlm_date.c +++ b/src/modules/rlm_date/rlm_date.c @@ -121,9 +121,9 @@ DIAG_ON(format-nonliteral) /** Get time in ms since either epoch or another value * * %{time_since:s} - return seconds since epoch - * %{time_since:ms:0} - return milliseconds since epoch - * %{time_since:us:1695745763034443} - return microseconds since Tue 26 Sep 17:29:23.034443 BST 2023 - * %{time_since:us:&Tmp-Integer64-1} - return microseconds since value in &Tmp-Integer64-1 + * %{time_since:ms 0} - return milliseconds since epoch + * %{time_since:us 1695745763034443} - return microseconds since Tue 26 Sep 17:29:23.034443 BST 2023 + * %{time_since:us &Tmp-Integer64-1} - return microseconds since value in &Tmp-Integer64-1 */ static ssize_t xlat_time_since(UNUSED void *instance, REQUEST *request, char const *fmt, char *out, size_t outlen) @@ -161,19 +161,19 @@ static ssize_t xlat_time_since(UNUSED void *instance, REQUEST *request, char con return -1; } - if (fmt[0] != '\0' && fmt[0] != ':') { + if (fmt[0] != '\0' && fmt[0] != ' ') { REDEBUG("Invalid arguments passed to time_since xlat"); goto error; } - if (fmt[0] == ':') fmt++; + while (isspace((uint8_t) *fmt)) fmt++; /* * Handle the different formats that we can be passed */ if (fmt[0] == '\0') { /* - * %{time_since:[mu]?s:} - epoch + * %{time_since:[mu]?s} - epoch */ time_since = 0; @@ -181,7 +181,7 @@ static ssize_t xlat_time_since(UNUSED void *instance, REQUEST *request, char con /* * We were provided with an attribute * - * %{time_since:[mu]?s:&Attr-Name} + * %{time_since:[mu]?s &Attr-Name} */ value_data_t outnum; VALUE_PAIR *vp; @@ -226,7 +226,7 @@ static ssize_t xlat_time_since(UNUSED void *instance, REQUEST *request, char con /* * Otherwise we hope we were provided with an integer value * - * %{time_since:[mu]?s:12345} + * %{time_since:[mu]?s 12345} */ if (sscanf(fmt, "%" PRIu64, &time_since) != 1) { REDEBUG("Failed parsing \"%s\" as integer", fmt); diff --git a/src/tests/modules/date/date_xlat.attrs b/src/tests/modules/date/date_xlat.attrs index a75e2b84fa..379f118536 100644 --- a/src/tests/modules/date/date_xlat.attrs +++ b/src/tests/modules/date/date_xlat.attrs @@ -4,7 +4,6 @@ Packet-Type = Access-Request User-Name = 'Bob' User-Password = 'Alice' -Tmp-Integer-1 = "12345" # # Expected answer diff --git a/src/tests/modules/date/date_xlat.unlang b/src/tests/modules/date/date_xlat.unlang index 8f09a72cda..83f650ec50 100644 --- a/src/tests/modules/date/date_xlat.unlang +++ b/src/tests/modules/date/date_xlat.unlang @@ -6,6 +6,19 @@ # comparisons rather than actual value checks. # +# +# %{time_since:...} should never return 0 +# +update { + &Tmp-Integer64-0 := "%{time_since:s}" + &Tmp-Integer64-1 := "%{time_since:ms}" + &Tmp-Integer64-2 := "%{time_since:us}" +} + +if (&Tmp-Integer64-0 == 0 || &Tmp-Integer64-1 == 0 || &Tmp-Integer64-2 == 0) { + test_fail +} + # # %c and %{time_since:s:0} should match # @@ -15,13 +28,13 @@ update { update { &Tmp-Integer-0 := "%c" - &Tmp-Integer-1 := "%{time_since:s:0}" - &Tmp-Integer-2 := "%{time_since:s:&Tmp-Integer-9}" + &Tmp-Integer-1 := "%{time_since:s 0}" + &Tmp-Integer-2 := "%{time_since:s &Tmp-Integer-9}" } if (&Tmp-Integer-0 != &Tmp-Integer-1) { if (&Tmp-Integer-0 != "%{expr:&Tmp-Integer-1 - 1}") { - # at a push, %{time_since:s:0} might be one second later, + # at a push, %{time_since:s 0} might be one second later, # depending on when the test ran test_fail } @@ -37,11 +50,11 @@ if (&Tmp-Integer-1 != &Tmp-Integer-2) { # If we run time_since 3 times, they should be the same or increasing # update { - &Tmp-Integer64-0 := "%{time_since:s:0}" + &Tmp-Integer64-0 := "%{time_since:s 0}" } update { - &Tmp-Integer64-1 := "%{time_since:s:}" + &Tmp-Integer64-1 := "%{time_since:s }" } update { @@ -67,15 +80,15 @@ if (&Tmp-Integer64-0 < 1600000000) { # Similar for milliseconds # update { - &Tmp-Integer64-3 := "%{time_since:ms:0}" + &Tmp-Integer64-3 := "%{time_since:ms 0}" } update { - &Tmp-Integer64-4 := "%{time_since:ms:}" + &Tmp-Integer64-4 := "%{time_since:ms}" } update { - &Tmp-Integer64-5 := "%{time_since:ms}" + &Tmp-Integer64-5 := "%{time_since:ms &Tmp-Integer-9}" } if (&Tmp-Integer64-3 > &Tmp-Integer64-4 || \ @@ -89,11 +102,11 @@ if (&Tmp-Integer64-3 > &Tmp-Integer64-4 || \ # ...and microseconds # update { - &Tmp-Integer64-6 := "%{time_since:us:0}" + &Tmp-Integer64-6 := "%{time_since:us 0}" } update { - &Tmp-Integer64-7 := "%{time_since:us:}" + &Tmp-Integer64-7 := "%{time_since:us }" } update { @@ -117,15 +130,15 @@ if ("%{expr:&Tmp-Integer64-7 - &Tmp-Integer64-6}" > 250) { # Seconds component * 1000 must always be same or less than # milliseconds, and microseconds. # -if ("%{expr:%{time_since:s:0} * 1000}" > "%{time_since:ms:0}") { +if ("%{expr:%{time_since:s 0} * 1000}" > "%{time_since:ms 0}") { test_fail } -if ("%{expr:%{time_since:ms:0} * 1000}" > "%{time_since:us:0}") { +if ("%{expr:%{time_since:ms 0} * 1000}" > "%{time_since:us 0}") { test_fail } -if ("%{expr:%{time_since:s:0} * 1000000}" > "%{time_since:us:0}") { +if ("%{expr:%{time_since:s 0} * 1000000}" > "%{time_since:us 0}") { test_fail } @@ -164,7 +177,7 @@ update { # negative values update { - &Tmp-Integer-0 := "%{time_since:ms:-1234}" + &Tmp-Integer-0 := "%{time_since:ms -1234}" } if (!(&Module-Failure-Message[*] == 'time_since xlat only accepts positive integers')) { @@ -178,7 +191,7 @@ update { # invalid attribute update { - &Tmp-Integer-0 := "%{time_since:us:&Test-Non-Existant-Attr}" + &Tmp-Integer-0 := "%{time_since:us &Test-Non-Existant-Attr}" } if (!(&Module-Failure-Message[*] == 'Unable to parse attribute in time_ms_since xlat')) { @@ -192,7 +205,7 @@ update { # silly text update { - &Tmp-Integer-0 := "%{time_since:us:test random text}" + &Tmp-Integer-0 := "%{time_since:us test random text}" } if (!(&Module-Failure-Message[*] == 'Failed parsing "test random text" as integer')) {