]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add xlat_print_t callback for xlat functions
authorAlan T. DeKok <aland@freeradius.org>
Fri, 4 Feb 2022 20:45:24 +0000 (15:45 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 6 Feb 2022 21:55:26 +0000 (16:55 -0500)
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_tokenize.c

index b6ebb36eb7f271a903eda9003e6c5a42a075fa44..d4e87f2348b42b7a247cc0bcf8915636ced8e5ec 100644 (file)
@@ -38,6 +38,9 @@ extern "C" {
 #  define XLAT_DEBUG(...)
 #endif
 
+typedef ssize_t (*xlat_print_t)(fr_sbuff_t *in, xlat_exp_t const *self, void *inst, fr_sbuff_escape_rules_t const *e_rules);
+
+
 typedef enum {
        XLAT_EXPR_TYPE_NONE,
        XLAT_EXPR_TYPE_UNARY,
@@ -69,6 +72,8 @@ typedef struct xlat_s {
        size_t                  thread_inst_size;       //!< Size of the thread instance data to pre-allocate.
        void                    *thread_uctx;           //!< uctx to pass to instantiation functions.
 
+       xlat_print_t            print;                  //!< function to call when printing
+
        xlat_flags_t            flags;                  //!< various flags
 
        xlat_input_type_t       input_type;             //!< Type of input used.
@@ -251,6 +256,16 @@ static inline void xlat_internal(xlat_t *xlat)
        xlat->internal = true;
 }
 
+/** Set a print routine for an xlat function.
+ *
+ * @param[in] xlat to mark as internal.
+ */
+static inline void xlat_print_set(xlat_t *xlat, xlat_print_t func)
+{
+       xlat->print = func;
+}
+
+
 /** Walker callback for xlat_walk()
  *
  * @param[in] exp      being evaluated.
index 88b8c223de1978f78ab4dbdb1089f9a8fb91e0dd..5f30917570d2644f9da27e1507fbd63ce396f75a 100644 (file)
@@ -1172,6 +1172,15 @@ static ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_t const *head, fr_sbuff
        case XLAT_FUNC:
                if (node->call.func->input_type != XLAT_INPUT_ARGS) break;
 
+               /*
+                *      We have a callback for printing this node, go
+                *      call it.
+                */
+               if (node->call.func->print) {
+                       slen = node->call.func->print(out, node, node->call.inst->data, e_rules);
+                       goto done;
+               }
+
                if (!node->call.func->internal || (node->call.func->expr_type == XLAT_EXPR_TYPE_NONE)) break;
 
                /*