]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Actually implement "break".
authorAlan T. DeKok <aland@freeradius.org>
Thu, 25 Jun 2015 15:28:37 +0000 (11:28 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 25 Jun 2015 15:28:37 +0000 (11:28 -0400)
And add unit tests

src/main/modcall.c
src/tests/keywords/foreach-break-2
src/tests/keywords/foreach-break-3 [new file with mode: 0644]

index 2f77906a1caf6761f3df086c7ec47464fdfe4a14..394e2a339b3f5e9ad7bf7895dbdfe9761b60b744 100644 (file)
@@ -687,10 +687,12 @@ redo:
                        }
 
                        /*
-                        *      We've unwound to the enclosing
-                        *      "foreach".  Stop the unwinding.
+                        *      We've been asked to unwind to the
+                        *      enclosing "foreach".  We're here, so
+                        *      we can stop unwinding.
                         */
-                       if (next->unwind == MOD_FOREACH) {
+                       if (next->unwind == MOD_BREAK) {
+                               entry->unwind = 0;
                                break;
                        }
 
@@ -1075,7 +1077,6 @@ calculate_result:
         */
        if (entry->unwind == MOD_BREAK) {
                RDEBUG2("# unwind to enclosing foreach");
-               entry->unwind = 0;
                goto finish;
        }
 
index baa54aa94aaa14509b2fa2aeb2179d76e32e140d..b1f60407a6aee25cbcecfefcbc542708339bf047 100644 (file)
@@ -38,6 +38,9 @@ foreach control:Tmp-String-0 {
                break
        }
        elsif ("%{Foreach-Variable-0}" == '9') {
+               update reply {
+                       Filter-Id := "fail-9"
+               }
                reject
        }
 }
diff --git a/src/tests/keywords/foreach-break-3 b/src/tests/keywords/foreach-break-3
new file mode 100644 (file)
index 0000000..af03da6
--- /dev/null
@@ -0,0 +1,44 @@
+#
+#  PRE: foreach foreach-break
+#
+
+update request {
+       Calling-Station-Id := "8"
+}
+
+update control {
+       &Calling-Station-Id := "0"
+       &Calling-Station-Id += "1"
+       &Calling-Station-Id += "2"
+       &Calling-Station-Id += "3"
+       &Calling-Station-Id += "4"
+       &Calling-Station-Id += "5"
+       &Calling-Station-Id += "6"
+       &Calling-Station-Id += "7"
+       &Calling-Station-Id += "8"
+       &Calling-Station-Id += "9"
+       &Calling-Station-Id += "a"
+       &Calling-Station-Id += "b"
+       &Calling-Station-Id += "c"
+       &Calling-Station-Id += "d"
+       &Calling-Station-Id += "e"
+       &Calling-Station-Id += "f"
+       &Calling-Station-Id += "g"
+}
+
+foreach &control:Calling-Station-Id {
+       if (&request:Calling-Station-Id == "%{Foreach-Variable-0}") {
+               update reply {
+                       Filter-Id := "filter"
+               }
+
+               break
+       }
+       elsif ("%{Foreach-Variable-0}" == '9') {
+               update reply {
+                       Filter-Id := "fail-9"
+               }
+
+               reject
+       }
+}