From: Alan T. DeKok Date: Mon, 1 Jun 2020 17:07:46 +0000 (-0400) Subject: move "get process function / ctx" to common API X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ae9e4adb0162fd3fc0b1778a0fb3013b19819b2;p=thirdparty%2Ffreeradius-server.git move "get process function / ctx" to common API where we may be able to use it with unit_test_module --- diff --git a/src/lib/server/virtual_servers.c b/src/lib/server/virtual_servers.c index a044aa6e29..b0a82f8bd9 100644 --- a/src/lib/server/virtual_servers.c +++ b/src/lib/server/virtual_servers.c @@ -1488,3 +1488,19 @@ virtual_server_method_t *virtual_server_section_methods(char const *name1, char return entry->methods; } +int virtual_server_get_process_by_name(CONF_SECTION *server, char const *type, module_method_t **method_p, void **ctx) +{ + *method_p = (module_method_t *) cf_data_value(cf_data_find(server, module_method_t, type)); + if (!method_p) { + fr_strerror_printf("No processing section found for '%s'", type); + return -1; + } + + /* + * We MUST use _cd_data_find() so that we don't try to + * find the "value" with talloc type "CF_IDENT_ANY". + */ + *ctx = cf_data_value(_cf_data_find(cf_section_to_item(server), CF_IDENT_ANY, type)); + + return 0; +} diff --git a/src/lib/server/virtual_servers.h b/src/lib/server/virtual_servers.h index fa5af63d33..e70c7b62da 100644 --- a/src/lib/server/virtual_servers.h +++ b/src/lib/server/virtual_servers.h @@ -128,6 +128,8 @@ int virtual_server_compile_sections(CONF_SECTION *server, virtual_server_compil int virtual_server_section_component(rlm_components_t *component, char const *name1, char const *name2); virtual_server_method_t *virtual_server_section_methods(char const *name1, char const *name2) CC_HINT(nonnull(1)); +int virtual_server_get_process_by_name(CONF_SECTION *server, char const *type, module_method_t **method_p, void **ctx); + #ifdef __cplusplus } #endif diff --git a/src/lib/unlang/call.c b/src/lib/unlang/call.c index cfebf0101f..be4f7bfdaa 100644 --- a/src/lib/unlang/call.c +++ b/src/lib/unlang/call.c @@ -161,21 +161,12 @@ static unlang_action_t unlang_call(REQUEST *request, rlm_rcode_t *presult) return UNLANG_ACTION_CALCULATE_RESULT; } - process_p = (module_method_t *) cf_data_value(cf_data_find(g->server_cs, module_method_t, type_enum->name)); - if (!process_p) { - REDEBUG("No such packet type '%s' in server '%s'", - type_enum->name, cf_section_name2(g->server_cs)); + if (virtual_server_get_process_by_name(g->server_cs, type_enum->name, &process_p, &process_inst) < 0) { + REDEBUG("Cannot call virtual server '%s' - %s", server, fr_strerror()); *presult = RLM_MODULE_FAIL; return UNLANG_ACTION_CALCULATE_RESULT; } - /* - * We MUST use _cd_data_find() so that we don't try to - * find the "value" with talloc type "CF_IDENT_ANY". - */ - process_inst = cf_data_value(_cf_data_find(cf_section_to_item(g->server_cs), CF_IDENT_ANY, type_enum->name)); - /* can be NULL */ - child = unlang_io_subrequest_alloc(request, dict, UNLANG_NORMAL_CHILD); if (!child) { *presult = RLM_MODULE_FAIL;