Also, just use the sandard comparison function instead of duplicating the comparison logic.
static inline CC_HINT(always_inline) int cf_tmpl_rules_verify(CONF_SECTION *cs, tmpl_rules_t const *rules)
{
- if (cf_section_has_parent(cs, "policy", NULL)) {
+ if (cf_section_find_parent(cs, "policy", NULL)) {
if (!fr_cond_assert_msg(!rules->attr.dict_def || (rules->attr.dict_def == fr_dict_internal()),
"Protocol dictionary must be NULL not %s",
fr_dict_root(rules->attr.dict_def)->name)) return -1;
CONF_ITEM_SECTION, name1, name2));
}
-/** Find a CONF_SECTION with name1 and optionally name2 in the specified conf section of one of its parents
+/** Find a section in the lineage of a CONF_SECTION which matches a specific name1 and optionally name2.
*
* Will walk up the configuration tree, searching in each parent until a matching section is found or
* we hit the root.
* - The first matching subsection.
* - NULL if no subsections match.
*/
-CONF_SECTION *cf_section_has_parent(CONF_SECTION const *cs,
- char const *name1, char const *name2)
+CONF_SECTION *cf_section_find_parent(CONF_SECTION const *cs,
+ char const *name1, char const *name2)
{
- CONF_ITEM *parent;
+ CONF_ITEM *parent = cf_section_to_item(cs);
- for (parent = cf_parent(cf_section_to_item(cs));
- parent != NULL;
- parent = cf_parent(parent)) {
+ while ((parent = cf_parent(parent))) {
CONF_SECTION *found = cf_item_to_section(parent);
- if (IS_WILDCARD(name1)) return found;
-
- if (strcmp(found->name1, name1) != 0) continue;
-
- if (IS_WILDCARD(name2)) return found;
-
- if (!name2) {
- if (!found->name2) return found;
-
- return NULL;
- }
-
- if (strcmp(found->name2, name2) == 0) return found;
- }
+ if (cf_section_name_cmp(found, name1, name2) == 0) return found;
+ };
return NULL;
}
char const *name1, char const *name2);
CONF_SECTION *cf_section_find_in_parent(CONF_SECTION const *cs,
char const *name1, char const *name2);
-CONF_SECTION *cf_section_has_parent(CONF_SECTION const *cs,
+CONF_SECTION *cf_section_find_parent(CONF_SECTION const *cs,
char const *name1, char const *name2);
char const *cf_section_value_find(CONF_SECTION const *, char const *attr);
/*
* Ensure that the server CONF_SECTION is always set.
*/
- inst->io.server_cs = cf_section_find_in_parent(mctx->inst->conf, "server", CF_IDENT_ANY);
+ inst->io.server_cs = cf_section_find_parent(mctx->inst->conf, "server", CF_IDENT_ANY);
fr_assert(dict_dns != NULL);
fr_assert(attr_packet_type != NULL);
}
}
- server_cs = cf_section_find_in_parent(inst->cs, "server", CF_IDENT_ANY);
+ server_cs = cf_section_find_parent(inst->cs, "server", CF_IDENT_ANY);
fr_assert(server_cs != NULL);
/*