]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move "get process function / ctx" to common API
authorAlan T. DeKok <aland@freeradius.org>
Mon, 1 Jun 2020 17:07:46 +0000 (13:07 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 1 Jun 2020 17:07:46 +0000 (13:07 -0400)
where we may be able to use it with unit_test_module

src/lib/server/virtual_servers.c
src/lib/server/virtual_servers.h
src/lib/unlang/call.c

index a044aa6e29ef42948c1b599806bcc4de2085f1bb..b0a82f8bd90e84be5dea2ac6e195d657f63f2bca 100644 (file)
@@ -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;
+}
index fa5af63d3364b6d0273f5472c32f6fdbec48d8df..e70c7b62da3b1d1becdd786b5045059ee0b380e2 100644 (file)
@@ -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
index cfebf0101f47f85b39bcce5835cf197a33301258..be4f7bfdaaf2f8c8cbd0d98a50d7e37037ea767f 100644 (file)
@@ -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;