]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
arguments are grouped, so ungroup them.
authorAlan T. DeKok <aland@freeradius.org>
Wed, 9 Feb 2022 20:25:05 +0000 (15:25 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 9 Feb 2022 20:25:05 +0000 (15:25 -0500)
for now, we only handle one element per argument

src/lib/unlang/xlat_expr.c

index bae29a012c1c08c4026d7d9e5159c53a067c1c2d..6c84ca132f4dc976dc37beede7d96b85a688fd1f 100644 (file)
@@ -283,7 +283,7 @@ static xlat_arg_parser_t const binary_op_xlat_args[] = {
 
 static xlat_action_t xlat_binary_op(TALLOC_CTX *ctx, fr_dcursor_t *out,
                                    UNUSED xlat_ctx_t const *xctx,
-                                   UNUSED request_t *request, fr_value_box_list_t *in,
+                                   request_t *request, fr_value_box_list_t *in,
                                    fr_token_t op)
 {
        int rcode;
@@ -292,10 +292,7 @@ static xlat_action_t xlat_binary_op(TALLOC_CTX *ctx, fr_dcursor_t *out,
        MEM(dst = fr_value_box_alloc_null(ctx));
 
        /*
-        *      @todo - A and B must be FR_TYPE_GROUP, and the actual values are inside them.
-        *
-        *      This means... what, exactly?  If the types are addition / substraction, etc., then do operate
-        *      on each list member?  If the types are comparison, do we do the same?
+        *      Each argument is a FR_TYPE_GROUP, with one or more elements in a list.
         */
        a = fr_dlist_head(in);
        b = fr_dlist_next(in, a);
@@ -307,7 +304,24 @@ static xlat_action_t xlat_binary_op(TALLOC_CTX *ctx, fr_dcursor_t *out,
        fr_assert(b != NULL);
 #endif
 
-       rcode = fr_value_calc_binary_op(dst, dst, FR_TYPE_NULL, a, op, b);
+       fr_assert(a->type == FR_TYPE_GROUP);
+       if (fr_dlist_num_elements(&a->vb_group) != 1) {
+               REDEBUG("Expected one value as the first argument, got %d",
+                       fr_dlist_num_elements(&a->vb_group));
+               return XLAT_ACTION_FAIL;
+       }
+
+
+       if (fr_dlist_num_elements(&b->vb_group) != 1) {
+               REDEBUG("Expected one value as the second argument, got %d",
+                       fr_dlist_num_elements(&b->vb_group));
+               return XLAT_ACTION_FAIL;
+       }
+
+       rcode = fr_value_calc_binary_op(dst, dst, FR_TYPE_NULL,
+                                       fr_dlist_head(&a->vb_group),
+                                       op,
+                                       fr_dlist_head(&b->vb_group));
        if (rcode < 0) {
                talloc_free(dst);
                return XLAT_ACTION_FAIL;