]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
unify resolution of FUNC_UNRESOLVED and FUNC
authorAlan T. DeKok <aland@freeradius.org>
Thu, 14 Jul 2022 13:48:50 +0000 (09:48 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 14 Jul 2022 14:04:03 +0000 (10:04 -0400)
by turning FUNC_UNRESOLVED into FUNC, and then just falling
through and using the normal FUNC resolution process.

src/lib/unlang/xlat_tokenize.c

index 558a6a55c4aaef48ea543a6ff359bfff062040f2..c6df0507803b4ce4e78f1ef8b73bac5f2cb84827 100644 (file)
@@ -1807,42 +1807,15 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
                        xlat_flags_merge(&node->flags, &node->alternate[1]->flags);
                        break;
 
-               /*
-                *      A resolved function with unresolved args
-                */
-               case XLAT_FUNC:
-                       node->flags = node->call.func->flags;
-
-                       if (node->call.func->resolve) {
-                               void *inst = node->call.inst ? node->call.inst->data : NULL;
-
-                               if (node->call.func->resolve(node, inst, xr_rules) < 0) return -1;
-                       } else {
-                               if (xlat_resolve(node->call.args, xr_rules) < 0) return -1;
-                       }
-
-                       xlat_flags_merge(&node->flags, &node->call.args->flags);
-                       node->flags.can_purify = (node->call.func->flags.pure && node->call.args->flags.pure) | node->call.args->flags.can_purify;
-                       break;
-
                /*
                 *      An unresolved function.
                 */
                case XLAT_FUNC_UNRESOLVED:
-               {
-                       xlat_t          *func;
-
                        /*
-                        *      We can't tell if it's just the function
-                        *      that needs resolving or its children too.
+                        *      Try to find the function
                         */
-                       if (xlat_resolve(node->call.args, xr_rules) < 0) return -1;
-
-                       /*
-                        *      Try and find the function
-                        */
-                       func = xlat_func_find(node->fmt, talloc_array_length(node->fmt) - 1);
-                       if (!func) {
+                       node->call.func = xlat_func_find(node->fmt, talloc_array_length(node->fmt) - 1);
+                       if (!node->call.func) {
                                /*
                                 *      FIXME - Produce proper error with marker
                                 */
@@ -1855,7 +1828,6 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
                        }
 
                        xlat_exp_set_type(node, XLAT_FUNC);
-                       node->call.func = func;
 
                        /*
                         *      Check input arguments of our freshly
@@ -1885,24 +1857,33 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
                        }
 
                        /*
-                        *      Reset node flags
+                        *      Add the freshly resolved function
+                        *      to the bootstrap tree.
                         */
-                       node->flags = func->flags;
+                       if (xlat_bootstrap_func(node) < 0) return -1;
 
                        /*
-                        *      Merge the result of trying to resolve
-                        *      the child nodes.
+                        *      The function is now resolved, so we go through the normal process of resolving
+                        *      its arguments, etc.
                         */
-                       xlat_flags_merge(&node->flags, &node->call.args->flags);
+                       FALL_THROUGH;
 
-                       node->flags.can_purify = (node->call.func->flags.pure && node->call.args->flags.pure) | node->call.args->flags.can_purify;
+               /*
+                *      A resolved function with unresolved args
+                */
+               case XLAT_FUNC:
+                       node->flags = node->call.func->flags;
 
-                       /*
-                        *      Add the freshly resolved function
-                        *      to the bootstrap tree.
-                        */
-                       if (xlat_bootstrap_func(node) < 0) return -1;
-               }
+                       if (node->call.func->resolve) {
+                               void *inst = node->call.inst ? node->call.inst->data : NULL;
+
+                               if (node->call.func->resolve(node, inst, xr_rules) < 0) return -1;
+                       } else {
+                               if (xlat_resolve(node->call.args, xr_rules) < 0) return -1;
+                       }
+
+                       xlat_flags_merge(&node->flags, &node->call.args->flags);
+                       node->flags.can_purify = (node->call.func->flags.pure && node->call.args->flags.pure) | node->call.args->flags.can_purify;
                        break;
 
                /*