return true;
}
-static bool pass2_cond_callback(fr_cond_t *c, void *uctx)
+static bool pass2_fixup_map(fr_cond_t *c, vp_tmpl_rules_t const *rules)
{
- vp_map_t *map;
vp_tmpl_t *vpt;
- unlang_compile_t *unlang_ctx = uctx;
-
- /*
- * These don't get optimized.
- */
- if ((c->type == COND_TYPE_TRUE) ||
- (c->type == COND_TYPE_FALSE)) {
- return true;
- }
-
- /*
- * Call children.
- */
- if (c->type == COND_TYPE_CHILD) {
- return pass2_cond_callback(c->data.child, uctx);
- }
-
- /*
- * Fix up the template.
- */
- if (c->type == COND_TYPE_EXISTS) {
- rad_assert(c->data.vpt->type != TMPL_TYPE_REGEX);
- return pass2_fixup_tmpl(c->ci, &c->data.vpt, unlang_ctx->rules, true);
- }
-
- /*
- * And tons of complicated checks.
- */
- rad_assert(c->type == COND_TYPE_MAP);
+ vp_map_t *map;
map = c->data.map; /* shorter */
* Resolve the attribute references first
*/
if (map->lhs->type == TMPL_TYPE_ATTR_UNDEFINED) {
- if (!pass2_fixup_undefined(map->ci, map->lhs, unlang_ctx->rules)) return false;
+ if (!pass2_fixup_undefined(map->ci, map->lhs, rules)) return false;
if (!cast) cast = map->lhs->tmpl_da;
}
if (map->rhs->type == TMPL_TYPE_ATTR_UNDEFINED) {
- if (!pass2_fixup_undefined(map->ci, map->rhs, unlang_ctx->rules)) return false;
+ if (!pass2_fixup_undefined(map->ci, map->rhs, rules)) return false;
if (!cast) cast = map->rhs->tmpl_da;
}
* @todo v3.1: allow anything anywhere.
*/
if (map->rhs->type != TMPL_TYPE_UNPARSED) {
- if (!pass2_fixup_xlat(map->ci, &map->lhs, false, NULL, unlang_ctx->rules)) {
+ if (!pass2_fixup_xlat(map->ci, &map->lhs, false, NULL, rules)) {
return false;
}
} else {
- if (!pass2_fixup_xlat(map->ci, &map->lhs, true, NULL, unlang_ctx->rules)) {
+ if (!pass2_fixup_xlat(map->ci, &map->lhs, true, NULL, rules)) {
return false;
}
if (!c->cast) da = map->lhs->tmpl_da;
- if (!pass2_fixup_xlat(map->ci, &map->rhs, true, da, unlang_ctx->rules)) {
+ if (!pass2_fixup_xlat(map->ci, &map->rhs, true, da, rules)) {
return false;
}
} else {
- if (!pass2_fixup_xlat(map->ci, &map->rhs, false, NULL, unlang_ctx->rules)) {
+ if (!pass2_fixup_xlat(map->ci, &map->rhs, false, NULL, rules)) {
return false;
}
}
#ifdef HAVE_REGEX
if (map->rhs->type == TMPL_TYPE_REGEX) {
- if (!pass2_fixup_regex(map->ci, map->rhs, unlang_ctx->rules)) {
+ if (!pass2_fixup_regex(map->ci, map->rhs, rules)) {
return false;
}
}
return true;
}
+static bool pass2_cond_callback(fr_cond_t *c, void *uctx)
+{
+ unlang_compile_t *unlang_ctx = uctx;
+
+ switch (c->type) {
+ /*
+ * These don't get optimized.
+ */
+ case COND_TYPE_TRUE:
+ case COND_TYPE_FALSE:
+ return true;
+
+ /*
+ * Call children.
+ */
+ case COND_TYPE_CHILD:
+ return pass2_cond_callback(c->data.child, uctx);
+
+ /*
+ * Fix up the template.
+ */
+ case COND_TYPE_EXISTS:
+ rad_assert(c->data.vpt->type != TMPL_TYPE_REGEX);
+ return pass2_fixup_tmpl(c->ci, &c->data.vpt, unlang_ctx->rules, true);
+
+ /*
+ * Fixup the map
+ */
+ case COND_TYPE_MAP:
+ return pass2_fixup_map(c, unlang_ctx->rules);
+
+ /*
+ * Nothing else has pass2 fixups
+ */
+ default:
+ rad_assert(0);
+ return false;
+ }
+}
+
/*
* Compile the RHS of update sections to xlat_exp_t
/*
* Compile the RHS of map sections to xlat_exp_t
*/
-static bool pass2_fixup_map(unlang_group_t *g, vp_tmpl_rules_t const *rules)
+static bool pass2_fixup_map_rhs(unlang_group_t *g, vp_tmpl_rules_t const *rules)
{
/*
* Compile the map
* header? Or ensure that the map is registered in the
* "boostrap" phase, so that it's always available here.
*/
- if (!pass2_fixup_map(g, unlang_ctx->rules)) {
+ if (!pass2_fixup_map_rhs(g, unlang_ctx->rules)) {
talloc_free(g);
return NULL;
}