From: Alan T. DeKok Date: Mon, 30 Jun 2025 16:09:25 +0000 (-0400) Subject: move unlang_ext_t fields to unlang_op_t X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=42498b00576ac07b798ebe8888e91791485a3b30;p=thirdparty%2Ffreeradius-server.git move unlang_ext_t fields to unlang_op_t in preparation for adding function-style arguments to keywords --- diff --git a/src/lib/unlang/call.c b/src/lib/unlang/call.c index 3169b358a6..53f35896c3 100644 --- a/src/lib/unlang/call.c +++ b/src/lib/unlang/call.c @@ -250,8 +250,14 @@ void unlang_call_init(void) { unlang_register(UNLANG_TYPE_CALL, &(unlang_op_t){ - .name = "call", - .interpret = unlang_call_frame_init, - .flag = UNLANG_OP_FLAG_RCODE_SET | UNLANG_OP_FLAG_DEBUG_BRACES + .name = "call", + .flag = UNLANG_OP_FLAG_RCODE_SET | UNLANG_OP_FLAG_DEBUG_BRACES, + .type = UNLANG_TYPE_CALL, + + .interpret = unlang_call_frame_init, + + + .unlang_size = sizeof(unlang_call_t), + .unlang_name = "unlang_call_t", }); } diff --git a/src/lib/unlang/caller.c b/src/lib/unlang/caller.c index 578e082d67..def5c58345 100644 --- a/src/lib/unlang/caller.c +++ b/src/lib/unlang/caller.c @@ -57,7 +57,12 @@ void unlang_caller_init(void) unlang_register(UNLANG_TYPE_CALLER, &(unlang_op_t){ .name = "caller", + .type = UNLANG_TYPE_CALLER, + .flag = UNLANG_OP_FLAG_DEBUG_BRACES, + .interpret = unlang_caller, - .flag = UNLANG_OP_FLAG_DEBUG_BRACES + + .unlang_size = sizeof(unlang_caller_t), + .unlang_name = "unlang_caller_t", }); } diff --git a/src/lib/unlang/catch.c b/src/lib/unlang/catch.c index 5aa85e5175..c607be9f27 100644 --- a/src/lib/unlang/catch.c +++ b/src/lib/unlang/catch.c @@ -104,7 +104,12 @@ void unlang_catch_init(void) unlang_register(UNLANG_TYPE_CATCH, &(unlang_op_t){ .name = "catch", + .type = UNLANG_TYPE_CATCH, + .flag = UNLANG_OP_FLAG_DEBUG_BRACES, + .interpret = unlang_catch, - .flag = UNLANG_OP_FLAG_DEBUG_BRACES + + .unlang_size = sizeof(unlang_catch_t), + .unlang_name = "unlang_catch_t", }); } diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 5b5a25f1d7..537880159a 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -131,7 +131,7 @@ void compile_copy_context(unlang_compile_t *dst, unlang_compile_t const *src) #define UPDATE_CTX2 compile_copy_context(&unlang_ctx2, unlang_ctx) -static unlang_t *compile_empty(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_SECTION *cs, unlang_ext_t const *ext); +static unlang_t *compile_empty(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type); static char const unlang_spaces[] = " "; @@ -553,20 +553,23 @@ int unlang_fixup_update(map_t *map, void *ctx) } -static unlang_group_t *group_allocate(unlang_t *parent, CONF_SECTION *cs, unlang_ext_t const *ext) +static unlang_group_t *group_allocate(unlang_t *parent, CONF_SECTION *cs, unlang_type_t type) { unlang_group_t *g; unlang_t *c; TALLOC_CTX *ctx; + unlang_op_t const *op = &unlang_ops[type]; ctx = parent; if (!ctx) ctx = cs; + fr_assert(op->unlang_size > 0); + /* * All the groups have a common header */ - g = (unlang_group_t *)_talloc_zero_pooled_object(ctx, ext->len, ext->type_name, - ext->pool_headers, ext->pool_len); + g = (unlang_group_t *)_talloc_zero_pooled_object(ctx, op->unlang_size, op->unlang_name, + op->pool_headers, op->pool_len); if (!g) return NULL; g->children = NULL; @@ -575,7 +578,7 @@ static unlang_group_t *group_allocate(unlang_t *parent, CONF_SECTION *cs, unlang c = unlang_group_to_generic(g); c->parent = parent; - c->type = ext->type; + c->type = type; c->ci = CF_TO_ITEM(cs); return g; @@ -695,12 +698,6 @@ static unlang_t *compile_map(unlang_t *parent, unlang_compile_t *unlang_ctx, CON tmpl_rules_t t_rules; - static unlang_ext_t const map_ext = { - .type = UNLANG_TYPE_MAP, - .len = sizeof(unlang_map_t), - .type_name = "unlang_map_t" - }; - /* * The RHS is NOT resolved in the context of the LHS. */ @@ -721,7 +718,7 @@ static unlang_t *compile_map(unlang_t *parent, unlang_compile_t *unlang_ctx, CON } t_rules.literals_safe_for = map_proc_literals_safe_for(proc); - g = group_allocate(parent, cs, &map_ext); + g = group_allocate(parent, cs, UNLANG_TYPE_MAP); if (!g) return NULL; gext = unlang_group_to_map(g); @@ -1145,12 +1142,6 @@ static unlang_t *compile_update(unlang_t *parent, unlang_compile_t *unlang_ctx, tmpl_rules_t t_rules; - static unlang_ext_t const update_ext = { - .type = UNLANG_TYPE_UPDATE, - .len = sizeof(unlang_map_t), - .type_name = "unlang_map_t" - }; - if (main_config_migrate_option_get("forbid_update")) { cf_log_err(cs, "The use of 'update' sections is forbidden by the server configuration"); return NULL; @@ -1172,7 +1163,7 @@ static unlang_t *compile_update(unlang_t *parent, unlang_compile_t *unlang_ctx, t_rules.attr.allow_wildcard = true; RULES_VERIFY(&t_rules); - g = group_allocate(parent, cs, &update_ext); + g = group_allocate(parent, cs, UNLANG_TYPE_UPDATE); if (!g) return NULL; gext = unlang_group_to_map(g); @@ -1908,7 +1899,7 @@ bool unlang_compile_actions(unlang_mod_actions_t *actions, CONF_SECTION *action_ return true; } -static unlang_t *compile_empty(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_SECTION *cs, unlang_ext_t const *ext) +static unlang_t *compile_empty(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type) { unlang_group_t *g; unlang_t *c; @@ -1918,12 +1909,12 @@ static unlang_t *compile_empty(unlang_t *parent, unlang_compile_t *unlang_ctx, C * *interpreter* type is GROUP, even if the *debug names* * are something else. */ - g = group_allocate(parent, cs, ext); + g = group_allocate(parent, cs, type); if (!g) return NULL; c = unlang_group_to_generic(g); if (!cs) { - c->name = unlang_ops[ext->type].name; + c->name = unlang_ops[type].name; c->debug_name = c->name; } else { @@ -2242,8 +2233,7 @@ static unlang_t *compile_children(unlang_group_t *g, unlang_compile_t *unlang_ct /* * Generic "compile a section with more unlang inside of it". */ -static unlang_t *compile_section(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_SECTION *cs, - unlang_ext_t const *ext) +static unlang_t *compile_section(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type) { unlang_group_t *g; unlang_t *c; @@ -2255,7 +2245,7 @@ static unlang_t *compile_section(unlang_t *parent, unlang_compile_t *unlang_ctx, /* * We always create a group, even if the section is empty. */ - g = group_allocate(parent, cs, ext); + g = group_allocate(parent, cs, type); if (!g) return NULL; c = unlang_group_to_generic(g); @@ -2271,7 +2261,7 @@ static unlang_t *compile_section(unlang_t *parent, unlang_compile_t *unlang_ctx, * Make sure to tell the user that we're running a * policy, and not anything else. */ - if (ext->type == UNLANG_TYPE_POLICY) { + if (type == UNLANG_TYPE_POLICY) { MEM(c->debug_name = talloc_typed_asprintf(c, "policy %s", name1)); } else if (!name2) { @@ -2287,15 +2277,9 @@ static unlang_t *compile_section(unlang_t *parent, unlang_compile_t *unlang_ctx, static unlang_t *compile_group(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_ITEM const *ci) { - static unlang_ext_t const group = { - .type = UNLANG_TYPE_GROUP, - .len = sizeof(unlang_group_t), - .type_name = "unlang_group_t", - }; - if (!cf_item_next(ci, NULL)) return UNLANG_IGNORE; - return compile_section(parent, unlang_ctx, cf_item_to_section(ci), &group); + return compile_section(parent, unlang_ctx, cf_item_to_section(ci), UNLANG_TYPE_GROUP); } static fr_table_num_sorted_t transaction_keywords[] = { @@ -2386,12 +2370,6 @@ static unlang_t *compile_transaction(unlang_t *parent, unlang_compile_t *unlang_ unlang_t *c; unlang_compile_t unlang_ctx2; - static unlang_ext_t const transaction = { - .type = UNLANG_TYPE_TRANSACTION, - .len = sizeof(unlang_transaction_t), - .type_name = "unlang_transaction_t", - }; - if (cf_section_name2(cs) != NULL) { cf_log_err(cs, "Unexpected argument to 'transaction' section"); cf_log_err(ci, DOC_KEYWORD_REF(transaction)); @@ -2415,7 +2393,7 @@ static unlang_t *compile_transaction(unlang_t *parent, unlang_compile_t *unlang_ unlang_ctx2.actions.actions[RLM_MODULE_INVALID] = MOD_ACTION_RETURN; unlang_ctx2.actions.actions[RLM_MODULE_DISALLOW] = MOD_ACTION_RETURN; - g = group_allocate(parent, cs, &transaction); + g = group_allocate(parent, cs, UNLANG_TYPE_TRANSACTION); if (!g) return NULL; c = unlang_group_to_generic(g); @@ -2443,12 +2421,6 @@ static unlang_t *compile_try(unlang_t *parent, unlang_compile_t *unlang_ctx, CON unlang_t *c; CONF_ITEM *next; - static unlang_ext_t const ext = { - .type = UNLANG_TYPE_TRY, - .len = sizeof(unlang_try_t), - .type_name = "unlang_try_t", - }; - /* * The transaction is empty, ignore it. */ @@ -2473,7 +2445,7 @@ static unlang_t *compile_try(unlang_t *parent, unlang_compile_t *unlang_ctx, CON goto print_url; } - g = group_allocate(parent, cs, &ext); + g = group_allocate(parent, cs, UNLANG_TYPE_TRY); if (!g) return NULL; c = unlang_group_to_generic(g); @@ -2511,12 +2483,6 @@ static unlang_t *compile_catch(unlang_t *parent, unlang_compile_t *unlang_ctx, C CONF_ITEM *prev; char const *name; - static unlang_ext_t const ext = { - .type = UNLANG_TYPE_CATCH, - .len = sizeof(unlang_catch_t), - .type_name = "unlang_catch_t", - }; - prev = cf_item_prev(cf_parent(ci), ci); while (prev && cf_item_is_data(prev)) prev = cf_item_prev(cf_parent(ci), prev); @@ -2538,7 +2504,7 @@ static unlang_t *compile_catch(unlang_t *parent, unlang_compile_t *unlang_ctx, C goto fail; } - g = group_allocate(parent, cs, &ext); + g = group_allocate(parent, cs, UNLANG_TYPE_CATCH); if (!g) return NULL; c = unlang_group_to_generic(g); @@ -2627,14 +2593,6 @@ static unlang_t *compile_switch(unlang_t *parent, unlang_compile_t *unlang_ctx, fr_type_t type; fr_htrie_type_t htype; - static unlang_ext_t const switch_ext = { - .type = UNLANG_TYPE_SWITCH, - .len = sizeof(unlang_switch_t), - .type_name = "unlang_switch_t", - .pool_headers = TMPL_POOL_DEF_HEADERS, - .pool_len = TMPL_POOL_DEF_LEN - }; - /* * We allow unknown attributes here. */ @@ -2652,7 +2610,7 @@ static unlang_t *compile_switch(unlang_t *parent, unlang_compile_t *unlang_ctx, if (!cf_item_next(cs, NULL)) return UNLANG_IGNORE; - g = group_allocate(parent, cs, &switch_ext); + g = group_allocate(parent, cs, UNLANG_TYPE_SWITCH); if (!g) return NULL; gext = unlang_group_to_switch(g); @@ -2872,12 +2830,6 @@ static unlang_t *compile_case(unlang_t *parent, unlang_compile_t *unlang_ctx, CO tmpl_t *vpt = NULL; tmpl_rules_t t_rules; - static unlang_ext_t const case_ext = { - .type = UNLANG_TYPE_CASE, - .len = sizeof(unlang_case_t), - .type_name = "unlang_case_t", - }; - /* * We allow unknown attributes here. */ @@ -2969,7 +2921,7 @@ static unlang_t *compile_case(unlang_t *parent, unlang_compile_t *unlang_ctx, CO * will silently skip the match, and then fall through to * the "default" statement. */ - c = compile_section(parent, unlang_ctx, cs, &case_ext); + c = compile_section(parent, unlang_ctx, cs, UNLANG_TYPE_CASE); if (!c) { talloc_free(vpt); return NULL; @@ -3000,12 +2952,6 @@ static unlang_t *compile_timeout(unlang_t *parent, unlang_compile_t *unlang_ctx, tmpl_t *vpt = NULL; fr_token_t token; - static unlang_ext_t const timeout_ext = { - .type = UNLANG_TYPE_TIMEOUT, - .len = sizeof(unlang_timeout_t), - .type_name = "unlang_timeout_t", - }; - /* * Timeout