From: Alan T. DeKok Date: Mon, 2 Sep 2024 20:41:21 +0000 (-0400) Subject: add function to evaluate xlat in place X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=990942d357d16d66f652c1fd229cb3ee5b10bdf6;p=thirdparty%2Ffreeradius-server.git add function to evaluate xlat in place without returning "yield" --- diff --git a/src/lib/unlang/xlat.c b/src/lib/unlang/xlat.c index 365a0d3105..4644f48ca3 100644 --- a/src/lib/unlang/xlat.c +++ b/src/lib/unlang/xlat.c @@ -579,6 +579,34 @@ xlat_action_t unlang_xlat_yield(request_t *request, return XLAT_ACTION_YIELD; } +/** Evaluate a "pure" (or not impure) xlat + * + * @param[in] ctx To allocate value boxes and values in. + * @param[out] out Where to write the result of the expansion. + * @param[in] request to push xlat onto. + * @param[in] xlat to evaluate. + * @return + * - 0 on success. + * - -1 on failure. + */ +int unlang_xlat_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, xlat_exp_head_t const *xlat) +{ + bool success = false; + + if (xlat->flags.impure_func) { + fr_strerror_const("Expansion requires async operations"); + return -1; + } + + if (unlang_xlat_push(ctx, &success, out, request, xlat, UNLANG_TOP_FRAME) < 0) return -1; + + (void) unlang_interpret(request); + + if (!success) return -1; + + return 0; +} + /** Register xlat operation with the interpreter * diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index 48fc8a45a4..a93a0ba95a 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -491,6 +491,10 @@ int unlang_xlat_push(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out request_t *request, xlat_exp_head_t const *head, bool top_frame) CC_HINT(warn_unused_result); +int unlang_xlat_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, + request_t *request, xlat_exp_head_t const *head) + CC_HINT(warn_unused_result); + xlat_action_t unlang_xlat_yield(request_t *request, xlat_func_t callback, xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx);