From: Alan T. DeKok Date: Wed, 25 Aug 2021 12:57:48 +0000 (-0400) Subject: move actions to struct X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d1121936bbf37459e9b021d393f183d732990d0;p=thirdparty%2Ffreeradius-server.git move actions to struct --- diff --git a/src/lib/unlang/call.c b/src/lib/unlang/call.c index c08df388b2b..84d56de20a2 100644 --- a/src/lib/unlang/call.c +++ b/src/lib/unlang/call.c @@ -165,16 +165,18 @@ unlang_action_t unlang_call_push(request_t *request, CONF_SECTION *server_cs, bo .name = name, .debug_name = name, .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0 - } + .actions = { + [RLM_MODULE_REJECT] = 0, + [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ + [RLM_MODULE_OK] = 0, + [RLM_MODULE_HANDLED] = 0, + [RLM_MODULE_INVALID] = 0, + [RLM_MODULE_DISALLOW] = 0, + [RLM_MODULE_NOTFOUND] = 0, + [RLM_MODULE_NOOP] = 0, + [RLM_MODULE_UPDATED] = 0 + }, + }, } }, .server_cs = server_cs, diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 44388342c50..714454168a7 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -82,10 +82,6 @@ static char const * const comp2str[] = { "post-auth" }; -typedef struct { - int actions[RLM_MODULE_NUMCODES]; -} unlang_actions_t; - typedef struct { rlm_components_t component; char const *section_name1; @@ -1098,15 +1094,15 @@ static void compile_action_defaults(unlang_t *c, unlang_compile_t *unlang_ctx) ((c->parent->type == UNLANG_TYPE_REDUNDANT) || (c->parent->type == UNLANG_TYPE_REDUNDANT_LOAD_BALANCE))) { for (i = 0; i < RLM_MODULE_NUMCODES; i++) { if (i == RLM_MODULE_FAIL) { - if (!c->actions[i]) { - c->actions[i] = 1; + if (!c->actions.actions[i]) { + c->actions.actions[i] = 1; } continue; } - if (!c->actions[i]) { - c->actions[i] = MOD_ACTION_RETURN; + if (!c->actions.actions[i]) { + c->actions.actions[i] = MOD_ACTION_RETURN; } } @@ -1118,8 +1114,8 @@ static void compile_action_defaults(unlang_t *c, unlang_compile_t *unlang_ctx) * set. */ for (i = 0; i < RLM_MODULE_NUMCODES; i++) { - if (!c->actions[i]) { - c->actions[i] = unlang_ctx->actions[0].actions[i]; + if (!c->actions.actions[i]) { + c->actions.actions[i] = unlang_ctx->actions[0].actions[i]; } } } @@ -1480,13 +1476,13 @@ static int compile_action_pair(unlang_t *c, CONF_PAIR *cp) attr); return 0; } - c->actions[rcode] = action; + c->actions.actions[rcode] = action; } else { /* set all unset values to the default */ int i; for (i = 0; i < RLM_MODULE_NUMCODES; i++) { - if (!c->actions[i]) c->actions[i] = action; + if (!c->actions.actions[i]) c->actions.actions[i] = action; } } @@ -2211,7 +2207,7 @@ static unlang_t *compile_case(unlang_t *parent, unlang_compile_t *unlang_ctx, CO * when we pick a 'case' statement, we don't * fall through to processing the next one. */ - for (i = 0; i < RLM_MODULE_NUMCODES; i++) c->actions[i] = MOD_ACTION_RETURN; + for (i = 0; i < RLM_MODULE_NUMCODES; i++) c->actions.actions[i] = MOD_ACTION_RETURN; return c; } diff --git a/src/lib/unlang/compile.h b/src/lib/unlang/compile.h index 4b233e6178f..6f23fd99d91 100644 --- a/src/lib/unlang/compile.h +++ b/src/lib/unlang/compile.h @@ -32,6 +32,10 @@ extern "C" { #include #include +typedef struct { + int actions[RLM_MODULE_NUMCODES]; +} unlang_actions_t; + int unlang_compile(CONF_SECTION *cs, rlm_components_t component, tmpl_rules_t const *rules, void **instruction); bool unlang_compile_is_keyword(const char *name); diff --git a/src/lib/unlang/function.c b/src/lib/unlang/function.c index 73c87f168a3..063c9b8602a 100644 --- a/src/lib/unlang/function.c +++ b/src/lib/unlang/function.c @@ -49,16 +49,18 @@ static unlang_t function_instruction = { .name = "function", .debug_name = "function", .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = 0, - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0 - } + .actions = { + [RLM_MODULE_REJECT] = 0, + [RLM_MODULE_FAIL] = 0, + [RLM_MODULE_OK] = 0, + [RLM_MODULE_HANDLED] = 0, + [RLM_MODULE_INVALID] = 0, + [RLM_MODULE_DISALLOW] = 0, + [RLM_MODULE_NOTFOUND] = 0, + [RLM_MODULE_NOOP] = 0, + [RLM_MODULE_UPDATED] = 0 + }, + }, }; /** Generic signal handler diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index 676aba95155..92f2cd9e122 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -221,7 +221,7 @@ unlang_frame_action_t result_calculate(request_t *request, unlang_stack_frame_t /* * The child's action says return. Do so. */ - if (instruction->actions[*result] == MOD_ACTION_RETURN) { + if (instruction->actions.actions[*result] == MOD_ACTION_RETURN) { if (*priority < 0) *priority = 0; RDEBUG4("** [%i] %s - action says to return with (%s %d)", @@ -237,7 +237,7 @@ unlang_frame_action_t result_calculate(request_t *request, unlang_stack_frame_t * If "reject", break out of the loop and return * reject. */ - if (instruction->actions[*result] == MOD_ACTION_REJECT) { + if (instruction->actions.actions[*result] == MOD_ACTION_REJECT) { if (*priority < 0) *priority = 0; RDEBUG4("** [%i] %s - action says to return with (%s %d)", @@ -254,7 +254,7 @@ unlang_frame_action_t result_calculate(request_t *request, unlang_stack_frame_t * code. Grab it in preference to any unset priority. */ if (*priority < 0) { - *priority = instruction->actions[*result]; + *priority = instruction->actions.actions[*result]; RDEBUG4("** [%i] %s - setting priority to (%s %d)", stack->depth, __FUNCTION__, @@ -479,7 +479,7 @@ unlang_frame_action_t frame_eval(request_t *request, unlang_stack_frame_t *frame * RLM_MODULE_NOT_SET means the instruction * doesn't want to modify the result. */ - if (*result != RLM_MODULE_NOT_SET) *priority = instruction->actions[*result]; + if (*result != RLM_MODULE_NOT_SET) *priority = instruction->actions.actions[*result]; if (result_calculate(request, frame, result, priority) == UNLANG_FRAME_ACTION_POP) { return UNLANG_FRAME_ACTION_POP; diff --git a/src/lib/unlang/load_balance.c b/src/lib/unlang/load_balance.c index 00d1075d8f5..06531214c27 100644 --- a/src/lib/unlang/load_balance.c +++ b/src/lib/unlang/load_balance.c @@ -73,7 +73,7 @@ static unlang_action_t unlang_load_balance_next(rlm_rcode_t *p_result, request_t * If the current child says "return", then do * so. */ - if (redundant->child->actions[*p_result] == MOD_ACTION_RETURN) { + if (redundant->child->actions.actions[*p_result] == MOD_ACTION_RETURN) { /* DON'T change p_result, as it is taken from the child */ return UNLANG_ACTION_CALCULATE_RESULT; } diff --git a/src/lib/unlang/module.c b/src/lib/unlang/module.c index eedffae1c27..668cc8507c4 100644 --- a/src/lib/unlang/module.c +++ b/src/lib/unlang/module.c @@ -363,16 +363,18 @@ int unlang_module_push(rlm_rcode_t *p_result, request_t *request, .name = module_instance->name, .debug_name = module_instance->name, .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0 - } + .actions = { + [RLM_MODULE_REJECT] = 0, + [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ + [RLM_MODULE_OK] = 0, + [RLM_MODULE_HANDLED] = 0, + [RLM_MODULE_INVALID] = 0, + [RLM_MODULE_DISALLOW] = 0, + [RLM_MODULE_NOTFOUND] = 0, + [RLM_MODULE_NOOP] = 0, + [RLM_MODULE_UPDATED] = 0 + }, + }, }, .instance = module_instance, .method = method diff --git a/src/lib/unlang/subrequest_child.c b/src/lib/unlang/subrequest_child.c index 45b378d0f65..21d8969e0e5 100644 --- a/src/lib/unlang/subrequest_child.c +++ b/src/lib/unlang/subrequest_child.c @@ -389,16 +389,18 @@ int unlang_subrequest_child_op_init(void) .name = "subrequest", .debug_name = "subrequest", .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = 0, - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, + .actions = { + [RLM_MODULE_REJECT] = 0, + [RLM_MODULE_FAIL] = 0, + [RLM_MODULE_OK] = 0, + [RLM_MODULE_HANDLED] = 0, + [RLM_MODULE_INVALID] = 0, + [RLM_MODULE_DISALLOW] = 0, + [RLM_MODULE_NOTFOUND] = 0, [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0 - } + [RLM_MODULE_UPDATED] = 0 + }, + }, } } }; diff --git a/src/lib/unlang/tmpl.c b/src/lib/unlang/tmpl.c index 5536b2ea822..ac8bd63ccc0 100644 --- a/src/lib/unlang/tmpl.c +++ b/src/lib/unlang/tmpl.c @@ -137,15 +137,17 @@ int unlang_tmpl_push(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *reque .name = "tmpl", .debug_name = "tmpl", .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = 0, - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0 + .actions = { + [RLM_MODULE_REJECT] = 0, + [RLM_MODULE_FAIL] = 0, + [RLM_MODULE_OK] = 0, + [RLM_MODULE_HANDLED] = 0, + [RLM_MODULE_INVALID] = 0, + [RLM_MODULE_DISALLOW] = 0, + [RLM_MODULE_NOTFOUND] = 0, + [RLM_MODULE_NOOP] = 0, + [RLM_MODULE_UPDATED] = 0 + }, }, }; diff --git a/src/lib/unlang/unlang_priv.h b/src/lib/unlang/unlang_priv.h index eb447b6bc9a..8302e44352a 100644 --- a/src/lib/unlang/unlang_priv.h +++ b/src/lib/unlang/unlang_priv.h @@ -120,7 +120,7 @@ struct unlang_s { char const *debug_name; //!< Printed in log messages when the node is executed. unlang_type_t type; //!< The specialisation of this node. bool closed; //!< whether or not this section is closed to new statements - int actions[RLM_MODULE_NUMCODES]; //!< Priorities for the various return codes. + unlang_actions_t actions; //!< Priorities, etc. for the various return codes. }; /** Describes how to allocate an #unlang_group_t with additional memory keyword specific data diff --git a/src/lib/unlang/xlat.c b/src/lib/unlang/xlat.c index 44d9f0b6632..446b88c6134 100644 --- a/src/lib/unlang/xlat.c +++ b/src/lib/unlang/xlat.c @@ -79,15 +79,17 @@ static unlang_t xlat_instruction = { .name = "xlat", .debug_name = "xlat", .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0 + .actions = { + [RLM_MODULE_REJECT] = 0, + [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ + [RLM_MODULE_OK] = 0, + [RLM_MODULE_HANDLED] = 0, + [RLM_MODULE_INVALID] = 0, + [RLM_MODULE_DISALLOW] = 0, + [RLM_MODULE_NOTFOUND] = 0, + [RLM_MODULE_NOOP] = 0, + [RLM_MODULE_UPDATED] = 0 + }, }, };