]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use space separator
authorMatthew Newton <matthew-git@newtoncomputing.co.uk>
Wed, 27 Sep 2023 09:01:26 +0000 (10:01 +0100)
committerMatthew Newton <matthew-git@newtoncomputing.co.uk>
Wed, 27 Sep 2023 09:01:45 +0000 (10:01 +0100)
raddb/mods-available/date
src/modules/rlm_date/rlm_date.c
src/tests/modules/date/date_xlat.attrs
src/tests/modules/date/date_xlat.unlang

index 69d8f6ab9013df3ea0fb8a163d59aae14891dd59..2d7d85ed99f64828b5d8cbfaa4fa88aebce96790 100644 (file)
@@ -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}"
 #    }
index b9f42a5dfa7da2c82b9525ff8587368064140c7b..b46bfe1e8884acc439d3893f774496dfeb052cda 100644 (file)
@@ -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);
index a75e2b84fa1cf9b670a58597769370245e11f4f3..379f11853647ffbdf58c4b48bce29e73e3e66569 100644 (file)
@@ -4,7 +4,6 @@
 Packet-Type = Access-Request
 User-Name = 'Bob'
 User-Password = 'Alice'
-Tmp-Integer-1 = "12345"
 
 #
 #  Expected answer
index 8f09a72cda3c866307113838c4beb8f528eb3015..83f650ec50c82ec93c9857085435b3704d6c98bc 100644 (file)
@@ -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')) {