From: Alan T. DeKok Date: Mon, 16 Dec 2019 18:28:50 +0000 (-0500) Subject: add API to push bare instructions into a request X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=600602128e9d417efbe4b2e23a4fe5aac7811571;p=thirdparty%2Ffreeradius-server.git add API to push bare instructions into a request which is faster than doing lookups in CONF_SECTIONS --- diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index 652d765c2f5..a90af3e8b67 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -762,31 +762,31 @@ rlm_rcode_t unlang_interpret(REQUEST *request) return stack->result; } +static unlang_group_t empty_group = { + .self = { + .type = UNLANG_TYPE_GROUP, + .debug_name = "empty-group", + .actions = { + MOD_ACTION_RETURN, + MOD_ACTION_RETURN, + MOD_ACTION_RETURN, + MOD_ACTION_RETURN, + MOD_ACTION_RETURN, + MOD_ACTION_RETURN, + MOD_ACTION_RETURN, + MOD_ACTION_RETURN, + MOD_ACTION_RETURN + }, + }, +}; + + /** Push a configuration section onto the request stack for later interpretation. * */ void unlang_interpret_push_section(REQUEST *request, CONF_SECTION *cs, rlm_rcode_t default_rcode, bool top_frame) { unlang_t *instruction = NULL; - unlang_stack_t *stack = request->stack; - - static unlang_group_t empty_group = { - .self = { - .type = UNLANG_TYPE_GROUP, - .debug_name = "empty-group", - .actions = { - MOD_ACTION_RETURN, - MOD_ACTION_RETURN, - MOD_ACTION_RETURN, - MOD_ACTION_RETURN, - MOD_ACTION_RETURN, - MOD_ACTION_RETURN, - MOD_ACTION_RETURN, - MOD_ACTION_RETURN, - MOD_ACTION_RETURN - }, - }, - }; /* * Interpretable unlang instructions are stored as CONF_DATA @@ -800,7 +800,22 @@ void unlang_interpret_push_section(REQUEST *request, CONF_SECTION *cs, rlm_rcode } } - if (!instruction) instruction = unlang_group_to_generic(&empty_group); + + unlang_interpret_push_instruction(request, instruction, default_rcode, top_frame); +} + +/** Push an instruction onto the request stack for later interpretation. + * + */ +void unlang_interpret_push_instruction(REQUEST *request, void *instruction, rlm_rcode_t default_rcode, bool top_frame) +{ + unlang_stack_t *stack = request->stack; + + if (!instruction) { + instruction = unlang_group_to_generic(&empty_group); + } else { + (void) talloc_get_type_abort(instruction, unlang_t); + } /* * Push the default action, and the instruction which has diff --git a/src/lib/unlang/interpret.h b/src/lib/unlang/interpret.h index 83aa28774b4..e79e4ab9e89 100644 --- a/src/lib/unlang/interpret.h +++ b/src/lib/unlang/interpret.h @@ -92,6 +92,9 @@ void unlang_interpret_push_function(REQUEST *request, void unlang_interpret_push_section(REQUEST *request, CONF_SECTION *cs, rlm_rcode_t default_action, bool top_frame); +void unlang_interpret_push_instruction(REQUEST *request, void *instruction, + rlm_rcode_t default_rcode, bool top_frame); + rlm_rcode_t unlang_interpret(REQUEST *request); rlm_rcode_t unlang_interpret_section(REQUEST *request, CONF_SECTION *cs, rlm_rcode_t default_action);