]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Move rlm_dict xlats to mod_load
authorNick Porter <nick@portercomputing.co.uk>
Fri, 19 May 2023 15:21:44 +0000 (16:21 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 19 May 2023 18:35:45 +0000 (14:35 -0400)
src/modules/rlm_dict/rlm_dict.c

index f4d1345750061be0b2c857e51db2566165b3bc0e..2e8c8bd6293eb61f1f1ceb252cd53f9053666929 100644 (file)
@@ -216,48 +216,40 @@ static xlat_action_t xlat_attr_num(TALLOC_CTX *ctx, fr_dcursor_t *out,
        return XLAT_ACTION_DONE;
 }
 
-/*
- *     Do any per-module initialization that is separate to each
- *     configured instance of the module.  e.g. set up connections
- *     to external databases, read configuration files, set up
- *     dictionary entries, etc.
- *
- *     If configuration information is given in the config section
- *     that must be referenced in later calls, store a handle to it
- *     in *instance otherwise put a null pointer there.
- */
-static int mod_bootstrap(module_inst_ctx_t const *mctx)
-{
-       void *inst = mctx->inst->data;
+#define XLAT_REGISTER(_name, _func, _type, _args) \
+if (unlikely(!(xlat = xlat_func_register(NULL, _name, _func, _type)))) return -1; \
+xlat_func_args_set(xlat, _args)
 
+static int mod_load(void)
+{
        xlat_t  *xlat;
 
-       /*
-        *      Only register these xlats for the first instance of the dictionary module.
-        */
-       if (cf_section_name2(mctx->inst->conf) != NULL) return 0;
-
-       xlat = xlat_func_register_module(inst, mctx, "attr_by_num", xlat_dict_attr_by_num, FR_TYPE_STRING);
-       xlat_func_args_set(xlat, xlat_dict_attr_by_num_args);
-       xlat = xlat_func_register_module(inst, mctx, "attr_by_oid", xlat_dict_attr_by_oid, FR_TYPE_STRING);
-       xlat_func_args_set(xlat, xlat_dict_attr_by_oid_args);
-       xlat = xlat_func_register_module(inst, mctx, "vendor", xlat_vendor, FR_TYPE_STRING);
-       xlat_func_args_set(xlat, xlat_vendor_args);
-       xlat = xlat_func_register_module(inst, mctx, "vendor_num", xlat_vendor_num, FR_TYPE_UINT32);
-       xlat_func_args_set(xlat, xlat_vendor_num_args);
-       xlat = xlat_func_register_module(inst, mctx, "attr", xlat_attr, FR_TYPE_STRING);
-       xlat_func_args_set(xlat, xlat_attr_args);
-       xlat = xlat_func_register_module(inst, mctx, "attr_num", xlat_attr_num, FR_TYPE_UINT32);
-       xlat_func_args_set(xlat, xlat_attr_num_args);
+       XLAT_REGISTER("attr_by_num", xlat_dict_attr_by_num, FR_TYPE_STRING, xlat_dict_attr_by_num_args);
+       XLAT_REGISTER("attr_by_oid", xlat_dict_attr_by_oid, FR_TYPE_STRING, xlat_dict_attr_by_oid_args);
+       XLAT_REGISTER("vendor", xlat_vendor, FR_TYPE_STRING, xlat_vendor_args);
+       XLAT_REGISTER("vendor_num", xlat_vendor_num, FR_TYPE_UINT32, xlat_vendor_num_args);
+       XLAT_REGISTER("attr", xlat_attr, FR_TYPE_STRING, xlat_attr_args);
+       XLAT_REGISTER("attr_num", xlat_attr_num, FR_TYPE_UINT32, xlat_attr_num_args);
 
        return 0;
 }
 
+static void mod_unload(void)
+{
+       xlat_func_unregister("attr_by_num");
+       xlat_func_unregister("attr_by_oid");
+       xlat_func_unregister("vendor");
+       xlat_func_unregister("vendor_num");
+       xlat_func_unregister("attr");
+       xlat_func_unregister("attr_num");
+}
+
 extern module_rlm_t rlm_dict;
 module_rlm_t rlm_dict = {
        .common = {
                .magic          = MODULE_MAGIC_INIT,
                .name           = "dict",
-               .bootstrap      = mod_bootstrap
+               .onload         = mod_load,
+               .unload         = mod_unload
        }
 };