MEM(head = talloc_zero(ctx, xlat_exp_head_t));
fr_dlist_init(&head->dlist, xlat_exp_t, entry);
- head->flags.pure = true;
+ head->flags.pure = head->flags.can_purify = true;
#ifndef NDEBUG
head->file = file;
head->line = line;
xlat_exp_t *node;
MEM(node = talloc_zero_pooled_object(ctx, xlat_exp_t, extra_hdrs, extra));
- node->flags.pure = true; /* everything starts pure */
+ node->flags.pure = node->flags.can_purify = true; /* everything starts pure */
node->quote = T_BARE_WORD;
#ifndef NDEBUG
node->file = file;
}
node->flags.constant = true;
- node->flags.pure = true;
+ node->flags.pure = node->flags.can_purify = true;
} else if (tmpl_contains_xlat(node->vpt)) {
node->flags = tmpl_xlat(vpt)->flags;
} else if (tmpl_is_attr(node->vpt)) {
- node->flags.pure = false;
+ node->flags.pure = node->flags.can_purify = false;
#ifndef NDEBUG
if (vpt->name[0] == '%') {
{
parent->needs_resolving |= child->needs_resolving;
parent->pure &= child->pure; /* purity can only be removed, never added */
- parent->can_purify |= child->can_purify;
+ parent->can_purify |= child->can_purify; /* there is SOME node under us which can be purified */
parent->constant &= child->constant;
parent->impure_func |= child->impure_func;
}
node->flags = child->flags;
break;
}
- FALL_THROUGH;
+ break;
+
+ case XLAT_BOX:
+ case XLAT_ONE_LETTER:
+ case XLAT_REGEX:
+ break;
- default:
- fr_strerror_printf("Internal error - cannot purify xlat");
+ case XLAT_INVALID:
+ case XLAT_FUNC_UNRESOLVED:
+ case XLAT_VIRTUAL:
+ case XLAT_VIRTUAL_UNRESOLVED:
+ fr_assert(0);
return -1;
case XLAT_GROUP:
rcode = xlat_purify_list(head, request);
talloc_free(request);
+ if (rcode < 0) return rcode;
- return rcode;
+ fr_assert(!head->flags.can_purify);
+
+ return 0;
}
static fr_value_box_t *xlat_value_box(xlat_exp_t *node)
xlat_purify (2 + 3) * 4 + 5
match 25
+#
+# Not the same as a regex %{3}, but we can't tell the difference here.
+#
+xlat_purify %{1 + 2}
+match %{3}
+
+xlat_purify %{'a' + 'b'}
+match %{"ab"}
+
xlat_purify NAS-Port + 5
match (NAS-Port + 5)
# @todo - xlat_tokenize() does not call purify
#
xlat_purify (string)(%{1 + 2})
-match %cast(string, %{(1 + 2)})
+match "3"
#
# This is a different code path than the above.
#
xlat_purify (string)%{1 + 2}
-match (string)%{(1 + 2)}
+match (string)%{3}
xlat_purify "hello"
match "hello"
xlat_purify "hello " + (string)%{1 + 2} + " bob"
match "hello 3 bob"
-#
-# @todo - this seems wrong, but likely a bug in unit_test_attribute.c
-# The real run-time tests work
-#
xlat_purify "hello %{1 + 2} bob"
-match "hello %{(1 + 2)} bob"
+match "hello %{3} bob"
#
# New syntax!
match 0xacbd18db4cc2f85cedef654fccc4a4d8
count
-match 116
+match 120