From: Arran Cudbard-Bell Date: Fri, 24 Nov 2017 14:43:32 +0000 (+0000) Subject: Pass in result as a cursor to async xlat functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47f956a65062a5ebde2bb2f08f6fd89ca2077dd9;p=thirdparty%2Ffreeradius-server.git Pass in result as a cursor to async xlat functions This helps if the function is processing arguments and yielding between each argument. --- diff --git a/src/include/interpreter.h b/src/include/interpreter.h index d55a0c15507..52d348410f9 100644 --- a/src/include/interpreter.h +++ b/src/include/interpreter.h @@ -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; diff --git a/src/include/xlat.h b/src/include/xlat.h index c86640165e7..e73129ac876 100644 --- a/src/include/xlat.h +++ b/src/include/xlat.h @@ -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); diff --git a/src/main/unlang_interpret.c b/src/main/unlang_interpret.c index e235f08bb33..b58855835d8 100644 --- a/src/main/unlang_interpret.c +++ b/src/main/unlang_interpret.c @@ -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: diff --git a/src/main/xlat_eval.c b/src/main/xlat_eval.c index 16c293ab9c4..0137645d463 100644 --- a/src/main/xlat_eval.c +++ b/src/main/xlat_eval.c @@ -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;