More tests for conditions and =* and =*
authorAlan T. DeKok <aland@freeradius.org>
Sun, 12 May 2013 13:53:51 +0000 (09:53 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 12 May 2013 13:53:51 +0000 (09:53 -0400)
src/main/map.c
src/main/parser.c
src/tests/condition.txt

index a514736..376ef48 100644 (file)
@@ -257,6 +257,9 @@ value_pair_map_t *radius_str2map(TALLOC_CTX *ctx, const char *lhs, FR_TOKEN lhs_
 
        map->op = op;
 
+       /*
+        *      Ignore the RHS if it's a true / false comparison.
+        */
        if ((map->op == T_OP_CMP_TRUE) || (map->op == T_OP_CMP_FALSE)) {
                return map;
        }
index d180a85..e1f2a07 100644 (file)
@@ -443,14 +443,6 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, char const *start, int brace,
                                p += 2;
 
                                } else if (p[1] == '*') {
-                                       /*
-                                        *      FOO !* BAR
-                                        *
-                                        *      is really !(FOO)
-                                        *
-                                        *      FIXME: we should
-                                        *      really re-write it...
-                                        */
                                        if (lhs_type != T_BARE_WORD) {
                                                return_P("Cannot use !* on a string");
                                        }
@@ -561,6 +553,30 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, char const *start, int brace,
                        }
 
                        /*
+                        *      foo =* bar is just (foo)
+                        *      foo !* bar is just (!foo)
+                        */
+                       if ((op == T_OP_CMP_TRUE) || (op == T_OP_CMP_FALSE)) {
+                               value_pair_tmpl_t *vpt;
+
+                               vpt = talloc_steal(c, c->data.map->dst);
+                               c->data.map->dst = NULL;
+
+                               talloc_free(c->data.map);
+                               c->type = COND_TYPE_EXISTS;
+                               c->data.vpt = vpt;
+
+                               /*
+                                *      Invert the negation bit.
+                                */
+                               if (op == T_OP_CMP_FALSE) {
+                                       c->negate = !c->negate;
+                               }
+
+                               goto done_cond;
+                       }
+
+                       /*
                         *      @todo: check LHS and RHS separately, to
                         *      get better errors
                         */
@@ -613,6 +629,8 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, char const *start, int brace,
                                        return 0;
                                }
                        }
+
+               done_cond:
                        p += slen;
 
                        while (isspace((int) *p)) p++; /* skip spaces after RHS */
index f0c75d3..3a62484 100644 (file)
@@ -178,4 +178,15 @@ condition "foo" =* bar
 data ERROR offset 6 Cannot use =* on a string
 
 condition User-Name =* bar
-data 
+data &User-Name
+
+condition User-Name !* bar
+data !&User-Name
+
+condition !User-Name =* bar
+data !&User-Name
+
+condition !User-Name !* bar
+data &User-Name
+
+