static int cf_file_fill(cf_stack_t *stack);
+static const fr_sbuff_term_t if_terminals = FR_SBUFF_TERMS(
+ L(""),
+ L("{"),
+);
+
static CONF_ITEM *process_if(cf_stack_t *stack)
{
ssize_t slen = 0;
fr_cond_t *cond = NULL;
+ xlat_exp_head_t *head = NULL;
fr_dict_t const *dict = NULL;
CONF_SECTION *cs;
char *p;
CONF_SECTION *parent = frame->current;
char *buff[4];
tmpl_rules_t t_rules;
+ fr_sbuff_parse_rules_t p_rules = { };
/*
* Short names are nicer.
.allow_unknown = true
}
};
+
+ p_rules.terminals = &if_terminals;
+
/*
* fr_cond_tokenize needs the current section, so we
* create it first. We don't pass a name2, as it hasn't
slen = my_slen;
goto parse_error;
}
+
+ my_slen = xlat_tokenize_expression(cs, &head, &FR_SBUFF_IN(buff[3], strlen(buff[3])), &p_rules, &t_rules);
+ fr_assert(my_slen > 0);
+ } else {
+ ssize_t my_slen;
+
+ my_slen = xlat_tokenize_expression(cs, &head, &FR_SBUFF_IN(buff[2], strlen(buff[2])), &p_rules, &t_rules);
+ fr_assert(my_slen > 0);
}
MEM(cs->name2 = talloc_typed_strdup(cs, buff[2]));
* the condition to the CONF_SECTION.
*/
cf_data_add(cs, cond, NULL, false);
+ cf_data_add(cs, head, NULL, false);
stack->ptr = ptr;
cs->allow_unlang = true;
case UNLANG_TYPE_IF:
was_if = true;
{
- unlang_group_t *f;
+ unlang_group_t *f;
unlang_cond_t *gext;
f = unlang_generic_to_group(single);
unlang_cond_t *gext;
fr_cond_t *cond;
+ xlat_exp_head_t *head;
+ bool is_truthy, value;
if (!cf_section_name2(cs)) {
cf_log_err(cs, "'%s' without condition", unlang_ops[ext->type].name);
cond = cf_data_value(cf_data_find(cs, fr_cond_t, NULL));
fr_assert(cond != NULL);
+ head = cf_data_value(cf_data_find(cs, xlat_exp_head_t, NULL));
+ fr_assert(head != NULL);
+
+ /*
+ * Resolve the xlat first.
+ */
+ if (xlat_resolve(head, NULL) < 0) {
+ cf_log_err(cs, "Failed resolving condition - %s", fr_strerror());
+ return NULL;
+ }
+
+ is_truthy = xlat_is_truthy(head, &value);
+
if (cond->type == COND_TYPE_FALSE) {
cf_log_debug_prefix(cs, "Skipping contents of '%s' as it is always 'false'",
unlang_ops[ext->type].name);
+
+ c = compile_section(parent, unlang_ctx, cs, ext);
+ talloc_free(c);
+
c = compile_empty(parent, unlang_ctx, cs, ext);
+
} else {
fr_cond_iter_t iter;
fr_cond_t *leaf;
}
fr_cond_async_update(cond);
+
c = compile_section(parent, unlang_ctx, cs, ext);
}
if (!c) return NULL;
g = unlang_generic_to_group(c);
gext = unlang_group_to_cond(g);
gext->cond = cond;
+ gext->head = head;
+ gext->is_truthy = is_truthy;
+ gext->value = value;
return c;
}