From: Nick Porter Date: Tue, 7 Mar 2023 17:48:39 +0000 (+0000) Subject: Define method_env_count() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e44a452e46d831de356920e823bc09d5d52c107b;p=thirdparty%2Ffreeradius-server.git Define method_env_count() --- diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 863d70c5266..07e96fd5fdc 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -4768,6 +4768,44 @@ static int method_env_parse(unlang_module_t *single, unlang_compile_t *unlang_ct return 0; } +/** Perform a quick assesment of how many parsed module env will be produced. + * + * @param[in,out] vallen Where to write the sum of the length of pair values. + * @param[in] cs Conf section to search for pairs. + * @param[in] module_env to parse. + * @return Number of parsed_module_env expected to be required. + */ +static size_t method_env_count(size_t *vallen, CONF_SECTION const *cs, module_env_t const *module_env) { + size_t pair_count, tmpl_count = 0; + CONF_PAIR const *cp; + + while (module_env->name) { + if (FR_BASE_TYPE(module_env->type) == FR_TYPE_SUBSECTION) { + CONF_SECTION const *subcs; + subcs = cf_section_find(cs, module_env->name, module_env->section.ident2); + if (!subcs) goto next; + + tmpl_count += method_env_count(vallen, subcs, module_env->section.subcs); + goto next; + } + pair_count = 0; + cp = NULL; + while ((cp = cf_pair_find_next(cs, cp, module_env->name))) { + pair_count++; + *vallen += talloc_array_length(cf_pair_value(cp)); + } + if (!pair_count && module_env->dflt) { + pair_count = 1; + *vallen += strlen(module_env->dflt); + } + tmpl_count += pair_count; + next: + module_env++; + } + + return tmpl_count; +} + static unlang_t *compile_module(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_ITEM *ci, module_instance_t *inst, module_method_t method, char const *realname)