From: Alan T. DeKok Date: Tue, 23 Nov 2021 17:43:15 +0000 (-0500) Subject: mark up a bunch of functions as PURE. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9256a8cc25a0dcc50c13bc9aa09cae792e9322ec;p=thirdparty%2Ffreeradius-server.git mark up a bunch of functions as PURE. Nothing uses the flag yet, but that's coming. Note that any function which uses 'request->foo' at runtime is NOT pure. However, the xlat functions MAY use RDEBUG, REDEBUG, or other R macros --- diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index 66d12523846..6e14385a05e 100644 --- a/src/lib/server/main_config.c +++ b/src/lib/server/main_config.c @@ -1288,7 +1288,7 @@ do {\ /* * Register the %(config:section.subsection) xlat function. */ - xlat = xlat_register(NULL, "config", xlat_config, NULL); + xlat = xlat_register(NULL, "config", xlat_config, XLAT_FLAG_PURE); xlat_func_args(xlat, xlat_config_args); /* diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 579cbdca030..f94f98e99d6 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -3342,30 +3342,48 @@ int xlat_init(void) XLAT_REGISTER(xlat); + /* + * These are all "pure" functions. + */ #define XLAT_REGISTER_ARGS(_xlat, _func, _args) \ do { \ - if (!(xlat = xlat_register(NULL, _xlat, _func, NULL))) return -1; \ + if (!(xlat = xlat_register(NULL, _xlat, _func, XLAT_FLAG_PURE))) return -1; \ xlat_func_args(xlat, _args); \ } while (0) XLAT_REGISTER_ARGS("concat", xlat_func_concat, xlat_func_concat_args); - XLAT_REGISTER_ARGS("debug", xlat_func_debug, xlat_func_debug_args); - XLAT_REGISTER_ARGS("debug_attr", xlat_func_debug_attr, xlat_func_debug_attr_args); XLAT_REGISTER_ARGS("explode", xlat_func_explode, xlat_func_explode_args); XLAT_REGISTER_ARGS("hmacmd5", xlat_func_hmac_md5, xlat_hmac_args); XLAT_REGISTER_ARGS("hmacsha1", xlat_func_hmac_sha1, xlat_hmac_args); XLAT_REGISTER_ARGS("integer", xlat_func_integer, xlat_func_integer_args); XLAT_REGISTER_ARGS("join", xlat_func_join, xlat_func_join_args); XLAT_REGISTER_ARGS("length", xlat_func_length, xlat_func_length_args); - XLAT_REGISTER_ARGS("nexttime", xlat_func_next_time, xlat_func_next_time_args); - XLAT_REGISTER_ARGS("pairs", xlat_func_pairs, xlat_func_pairs_args); XLAT_REGISTER_ARGS("lpad", xlat_func_lpad, xlat_func_pad_args); XLAT_REGISTER_ARGS("rpad", xlat_func_rpad, xlat_func_pad_args); + + /* + * The inputs to these functions are variable. + */ +#undef XLAT_REGISTER_ARGS +#define XLAT_REGISTER_ARGS(_xlat, _func, _args) \ +do { \ + if (!(xlat = xlat_register(NULL, _xlat, _func, NULL))) return -1; \ + xlat_func_args(xlat, _args); \ +} while (0) + + XLAT_REGISTER_ARGS("debug", xlat_func_debug, xlat_func_debug_args); + XLAT_REGISTER_ARGS("debug_attr", xlat_func_debug_attr, xlat_func_debug_attr_args); + XLAT_REGISTER_ARGS("nexttime", xlat_func_next_time, xlat_func_next_time_args); + XLAT_REGISTER_ARGS("pairs", xlat_func_pairs, xlat_func_pairs_args); + XLAT_REGISTER_ARGS("sub", xlat_func_sub, xlat_func_sub_args); XLAT_REGISTER_ARGS("trigger", trigger_xlat, trigger_xlat_args); + /* + * All of these functions are pure. + */ #define XLAT_REGISTER_MONO(_xlat, _func, _arg) \ do { \ - if (!(xlat = xlat_register(NULL, _xlat, _func, NULL))) return -1; \ + if (!(xlat = xlat_register(NULL, _xlat, _func, XLAT_FLAG_PURE))) return -1; \ xlat_func_mono(xlat, &_arg); \ } while (0) @@ -3376,7 +3394,6 @@ do { \ XLAT_REGISTER_MONO("map", xlat_func_map, xlat_func_map_arg); XLAT_REGISTER_MONO("md4", xlat_func_md4, xlat_func_md4_arg); XLAT_REGISTER_MONO("md5", xlat_func_md5, xlat_func_md5_arg); - xlat_register(NULL, "module", xlat_func_module, NULL); XLAT_REGISTER_MONO("pack", xlat_func_pack, xlat_func_pack_arg); XLAT_REGISTER_MONO("rand", xlat_func_rand, xlat_func_rand_arg); XLAT_REGISTER_MONO("randstr", xlat_func_randstr, xlat_func_randstr_arg); @@ -3404,12 +3421,13 @@ do { \ XLAT_REGISTER_MONO("string", xlat_func_string, xlat_func_string_arg); XLAT_REGISTER_MONO("strlen", xlat_func_strlen, xlat_func_strlen_arg); - XLAT_REGISTER_ARGS("sub", xlat_func_sub, xlat_func_sub_args); XLAT_REGISTER_MONO("tolower", xlat_func_tolower, xlat_change_case_arg); XLAT_REGISTER_MONO("toupper", xlat_func_toupper, xlat_change_case_arg); XLAT_REGISTER_MONO("urlquote", xlat_func_urlquote, xlat_func_urlquote_arg); XLAT_REGISTER_MONO("urlunquote", xlat_func_urlunquote, xlat_func_urlunquote_arg); + xlat_register(NULL, "module", xlat_func_module, NULL); + return 0; } diff --git a/src/modules/rlm_escape/rlm_escape.c b/src/modules/rlm_escape/rlm_escape.c index c9dfcc6221a..5badcb1f634 100644 --- a/src/modules/rlm_escape/rlm_escape.c +++ b/src/modules/rlm_escape/rlm_escape.c @@ -199,11 +199,11 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) xlat_t *xlat; MEM(unescape = talloc_asprintf(NULL, "un%s", mctx->inst->name)); - xlat = xlat_register(NULL, mctx->inst->name, escape_xlat, NULL); + xlat = xlat_register(NULL, mctx->inst->name, escape_xlat, XLAT_FLAG_PURE); xlat_func_mono(xlat, &escape_xlat_arg); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_escape_t *, NULL, inst); - xlat = xlat_register(NULL, unescape, unescape_xlat, NULL); + xlat = xlat_register(NULL, unescape, unescape_xlat, XLAT_FLAG_PURE); xlat_func_mono(xlat, &unescape_xlat_arg); talloc_free(unescape); diff --git a/src/modules/rlm_idn/rlm_idn.c b/src/modules/rlm_idn/rlm_idn.c index 738e832e122..4e7cb45f73a 100644 --- a/src/modules/rlm_idn/rlm_idn.c +++ b/src/modules/rlm_idn/rlm_idn.c @@ -160,7 +160,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) rlm_idn_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_idn_t); xlat_t *xlat; - xlat = xlat_register(inst, mctx->inst->name, xlat_idna, NULL); + xlat = xlat_register(inst, mctx->inst->name, xlat_idna, XLAT_FLAG_PURE); xlat_func_mono(xlat, &xlat_idna_arg); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_idn_t *, NULL, inst); diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index 722975e40a6..e7e5abcec6e 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -1880,9 +1880,9 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) xlat_func_mono(xlat, &ldap_xlat_arg); xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, ldap_xlat_thread_inst_t, NULL, inst); - xlat = xlat_register(NULL, "ldap_escape", ldap_escape_xlat, NULL); + xlat = xlat_register(NULL, "ldap_escape", ldap_escape_xlat, XLAT_FLAG_PURE); if (xlat) xlat_func_mono(xlat, &ldap_escape_xlat_arg); - xlat = xlat_register(NULL, "ldap_unescape", ldap_unescape_xlat, NULL); + xlat = xlat_register(NULL, "ldap_unescape", ldap_unescape_xlat, XLAT_FLAG_PURE); if (xlat) xlat_func_mono(xlat, &ldap_escape_xlat_arg); map_proc_register(inst, mctx->inst->name, mod_map_proc, ldap_map_verify, 0); diff --git a/src/modules/rlm_unpack/rlm_unpack.c b/src/modules/rlm_unpack/rlm_unpack.c index 13afbfbcd5f..af50a33a49c 100644 --- a/src/modules/rlm_unpack/rlm_unpack.c +++ b/src/modules/rlm_unpack/rlm_unpack.c @@ -149,7 +149,7 @@ static int mod_bootstrap(UNUSED module_inst_ctx_t const *mctx) { xlat_t *xlat; - xlat = xlat_register(NULL, "unpack", unpack_xlat, NULL); + xlat = xlat_register(NULL, "unpack", unpack_xlat, XLAT_FLAG_PURE); if (xlat) xlat_func_args(xlat, unpack_xlat_args); return 0; diff --git a/src/modules/rlm_yubikey/rlm_yubikey.c b/src/modules/rlm_yubikey/rlm_yubikey.c index 73028e0db93..5497586ce25 100644 --- a/src/modules/rlm_yubikey/rlm_yubikey.c +++ b/src/modules/rlm_yubikey/rlm_yubikey.c @@ -195,7 +195,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) } #endif - xlat = xlat_register(inst, "modhextohex", modhex_to_hex_xlat, NULL); + xlat = xlat_register(inst, "modhextohex", modhex_to_hex_xlat, XLAT_FLAG_PURE); if (xlat) xlat_func_mono(xlat, &modhex_to_hex_xlat_arg); return 0;