]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Pass in result as a cursor to async xlat functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 24 Nov 2017 14:43:32 +0000 (14:43 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 24 Nov 2017 15:19:13 +0000 (15:19 +0000)
This helps if the function is processing arguments and yielding between each argument.

src/include/interpreter.h
src/include/xlat.h
src/main/unlang_interpret.c
src/main/xlat_eval.c

index d55a0c15507495709299a557a0e6f905485d9c6b..52d348410f9ac7bfe407784c79738c002de4763f 100644 (file)
@@ -272,7 +272,9 @@ typedef struct {
        /*
         *      For func and alternate
         */
-       fr_value_box_t          *result;                        //!< Of nested expansion.
+       fr_value_box_t          *rhead;                         //!< Of nested expansion.
+       fr_cursor_t             result;                         //!< Result cursor, mainly useful for
+                                                               ///< asynchronous xlat functions.
        bool                    alternate;                      //!< record which alternate branch we
                                                                ///< previously took.
 } unlang_stack_state_xlat_t;
index c86640165e74a059c0281cd8e1f0e609c021dff8..e73129ac876947b461810c2a92c960987d6d30be 100644 (file)
@@ -117,7 +117,7 @@ typedef int (*xlat_thread_instantiate_t)(void *xlat_inst, void *xlat_thread_inst
 xlat_action_t  xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_cursor_t *out,
                                       xlat_exp_t const **child, bool *alternate,
                                       REQUEST *request, xlat_exp_t const **in,
-                                      fr_value_box_t *result);
+                                      fr_cursor_t *result);
 
 xlat_action_t  xlat_frame_eval(TALLOC_CTX *ctx, fr_cursor_t *out, xlat_exp_t const **child,
                                REQUEST *request, xlat_exp_t const **in);
index e235f08bb335352f04ce22d1f16fff776fcf83c3..b58855835d8f8a37836e9ca1a80520c4cb4ed8bd 100644 (file)
@@ -918,10 +918,11 @@ static unlang_action_t unlang_xlat(REQUEST *request,
        xlat_action_t                   xa;
 
        if (frame->repeat) {
+               fr_cursor_init(&xs->result, &xs->rhead);
                xa = xlat_frame_eval_repeat(xs->ctx, &xs->values,
                                            &child, &xs->alternate,
                                            request, &xs->exp,
-                                           xs->result);
+                                           &xs->result);
        } else {
                xa = xlat_frame_eval(xs->ctx, &xs->values, &child, request, &xs->exp);
        }
@@ -931,7 +932,7 @@ static unlang_action_t unlang_xlat(REQUEST *request,
                rad_assert(child);
 
                frame->repeat = true;
-               unlang_push_xlat(xs->ctx, &xs->result, request, child, false);
+               unlang_push_xlat(xs->ctx, &xs->rhead, request, child, false);
                return UNLANG_ACTION_PUSHED_CHILD;
 
        case XLAT_ACTION_YIELD:
index 16c293ab9c4fe770cd85bd5dd989299e014263ad..0137645d4635ecca53720ff6f1269008326a2ea2 100644 (file)
@@ -505,7 +505,7 @@ static const char xlat_spaces[] = "
 xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_cursor_t *out,
                                     xlat_exp_t const **child, bool *alternate,
                                     REQUEST *request, xlat_exp_t const **in,
-                                    fr_value_box_t *result)
+                                    fr_cursor_t *result)
 {
        xlat_exp_t const *node = *in;
 
@@ -523,7 +523,7 @@ xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_cursor_t *out,
                        char            *result_str;
                        ssize_t         slen;
 
-                       result_str = fr_value_box_list_asprint(NULL, result, NULL, '\0');
+                       result_str = fr_value_box_list_asprint(NULL, fr_cursor_head(result), NULL, '\0');
                        if (!result_str) return XLAT_ACTION_FAIL;
 
                        if (node->xlat->buf_len > 0) {
@@ -592,8 +592,6 @@ xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_cursor_t *out,
 
        case XLAT_ALTERNATE:
        {
-               fr_cursor_t alt_result;
-
                rad_assert(alternate);
                rad_assert(child);
 
@@ -617,9 +615,7 @@ xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_cursor_t *out,
 
                        return XLAT_ACTION_PUSH_CHILD;
                }
-
-               fr_cursor_init(&alt_result, &result);
-               fr_cursor_merge(out, &alt_result);
+               fr_cursor_merge(out, result);
        }
                break;