]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add set purify callback, and use it in xlat_purify()
authorAlan T. DeKok <aland@freeradius.org>
Tue, 31 May 2022 14:14:10 +0000 (10:14 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 3 Jun 2022 11:15:50 +0000 (07:15 -0400)
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_purify.c

index 1188a8818ade61cdf690cbe20b722d3f35fa9d27..bbe946df94efce1607b79e05ca89785649be85cd 100644 (file)
@@ -40,6 +40,7 @@ extern "C" {
 
 typedef fr_slen_t (*xlat_print_t)(fr_sbuff_t *in, xlat_exp_t const *self, void *inst, fr_sbuff_escape_rules_t const *e_rules);
 typedef int (*xlat_resolve_t)(xlat_exp_t *self, void *inst, xlat_res_rules_t const *xr_rules);
+typedef int (*xlat_purify_t)(xlat_exp_t *self, void *inst);
 
 typedef struct xlat_s {
        fr_rb_node_t            node;                   //!< Entry in the xlat function tree.
@@ -67,6 +68,7 @@ typedef struct xlat_s {
 
        xlat_print_t            print;                  //!< function to call when printing
        xlat_resolve_t          resolve;                //!< function to call when resolving
+       xlat_purify_t           purify;                 //!< function to call when purifying the node.
 
        xlat_flags_t            flags;                  //!< various flags
 
@@ -282,6 +284,16 @@ static inline void xlat_resolve_set(xlat_t *xlat, xlat_resolve_t func)
 }
 
 
+/** Set a resolve routine for an xlat function.
+ *
+ * @param[in] xlat to set
+ */
+static inline void xlat_purify_set(xlat_t *xlat, xlat_purify_t func)
+{
+       xlat->purify = func;
+}
+
+
 /** Walker callback for xlat_walk()
  *
  * @param[in] exp      being evaluated.
index 1f455ee77fbf4a8161f2b2c2aa3c17e806aefbf9..7808f1d9da96094ba9503531f21f8bf428db6713 100644 (file)
@@ -105,11 +105,24 @@ static int xlat_purify_list(xlat_exp_head_t *head, request_t *request)
                        break;
                        
                case XLAT_FUNC:
-                       if (!node->flags.pure && node->flags.can_purify) {
-                               if (xlat_purify_list(node->call.args, request) < 0) return -1;
+                       /*
+                        *      If the node is not pure, then maybe there's a callback to purify it, OR maybe
+                        *      we can purify the function arguments.
+                        */
+                       if (!node->flags.pure) {
+                               if (node->call.func->purify) {
+                                       if (node->call.func->purify(node, node->call.inst->data) < 0) return -1;
+
+                               } else {
+                                       if (xlat_purify_list(node->call.args, request) < 0) return -1;
+                               }
                                break;
                        }
 
+                       /*
+                        *      The node is entirely pure, we don't worry about any callbacks, we just
+                        *      evaluate the entire thing to purify it.
+                        */
                        fr_assert(node->flags.pure);
 
                        fr_value_box_list_init(&list);