]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add function to evaluate xlat in place
authorAlan T. DeKok <aland@freeradius.org>
Mon, 2 Sep 2024 20:41:21 +0000 (16:41 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 2 Sep 2024 21:38:58 +0000 (17:38 -0400)
without returning "yield"

src/lib/unlang/xlat.c
src/lib/unlang/xlat.h

index 365a0d31051755865ca841d1ff373bbc3818bc3f..4644f48ca3d8ef96261f5cbca4eac3aac9983263 100644 (file)
@@ -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
  *
index 48fc8a45a414da0f3197dfadf24d2bee9b9e27a7..a93a0ba95a148f7240e57ed0db8a057814ed84c0 100644 (file)
@@ -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);