From: Alan T. DeKok Date: Fri, 4 Feb 2022 20:45:24 +0000 (-0500) Subject: add xlat_print_t callback for xlat functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26016967ff5c967ca742d8f09642ebc0d15ef204;p=thirdparty%2Ffreeradius-server.git add xlat_print_t callback for xlat functions --- diff --git a/src/lib/unlang/xlat_priv.h b/src/lib/unlang/xlat_priv.h index b6ebb36eb7f..d4e87f2348b 100644 --- a/src/lib/unlang/xlat_priv.h +++ b/src/lib/unlang/xlat_priv.h @@ -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. diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 88b8c223de1..5f30917570d 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -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; /*