]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use dispatch function for pass2 fixup
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 27 Jan 2019 04:07:29 +0000 (11:07 +0700)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 27 Jan 2019 04:07:29 +0000 (11:07 +0700)
src/lib/unlang/compile.c
src/lib/util/inet.c

index 5b4b7eaf2f31bbc61057413d3ced94507b081c7a..82986074271e324edba87278502b62834e993ec4 100644 (file)
@@ -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;
        }
index e5416d397a9a883641aea947bfbc22a0a3e800b8..b2b919b0a3e0c85f1191fd401d18358772ec02b5 100644 (file)
@@ -25,6 +25,7 @@
 #include <freeradius-devel/util/misc.h>
 #include <freeradius-devel/util/strerror.h>
 #include <freeradius-devel/util/syserror.h>
+#include <freeradius-devel/util/value.h>
 
 #include <ctype.h>
 #include <netdb.h>