From: Arran Cudbard-Bell Date: Sun, 27 Jan 2019 04:07:29 +0000 (+0700) Subject: Use dispatch function for pass2 fixup X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b60b85eacb9abc1dd09758eaf350b1ed59cad968;p=thirdparty%2Ffreeradius-server.git Use dispatch function for pass2 fixup --- diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 5b4b7eaf2f3..82986074271 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -574,39 +574,10 @@ static bool pass2_fixup_tmpl(CONF_ITEM const *ci, vp_tmpl_t **pvpt, vp_tmpl_rule 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 */ @@ -637,12 +608,12 @@ static bool pass2_cond_callback(fr_cond_t *c, void *uctx) * 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; } @@ -724,11 +695,11 @@ static bool pass2_cond_callback(fr_cond_t *c, void *uctx) * @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; } @@ -801,12 +772,12 @@ static bool pass2_cond_callback(fr_cond_t *c, void *uctx) 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; } } @@ -844,7 +815,7 @@ static bool pass2_cond_callback(fr_cond_t *c, void *uctx) #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; } } @@ -908,6 +879,46 @@ static bool pass2_cond_callback(fr_cond_t *c, void *uctx) 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 @@ -960,7 +971,7 @@ static bool pass2_fixup_update(unlang_group_t *g, vp_tmpl_rules_t const *rules) /* * 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 @@ -1555,7 +1566,7 @@ static unlang_t *compile_map(unlang_t *parent, unlang_compile_t *unlang_ctx, * 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; } diff --git a/src/lib/util/inet.c b/src/lib/util/inet.c index e5416d397a9..b2b919b0a3e 100644 --- a/src/lib/util/inet.c +++ b/src/lib/util/inet.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include