From: Arran Cudbard-Bell Date: Thu, 30 Jun 2022 20:59:25 +0000 (-0500) Subject: Simple function for matching name1/name2 to a section name X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37f7a2d377fd91fe1f16e4175964ddf2bfb1542a;p=thirdparty%2Ffreeradius-server.git Simple function for matching name1/name2 to a section name --- diff --git a/src/lib/server/cf_util.c b/src/lib/server/cf_util.c index a7d104670b4..2e3cb00ac21 100644 --- a/src/lib/server/cf_util.c +++ b/src/lib/server/cf_util.c @@ -1026,6 +1026,36 @@ char const *cf_section_value_find(CONF_SECTION const *cs, char const *attr) return (cp ? cp->value : NULL); } +/** Check if a given section matches the specified name1/name2 identifiers + * + * @param[in] cs to check. + * @param[in] name1 identifier. May be CF_IDENT_ANY for wildcard matches. + * @param[in] name2 identifier. May be CF_IDENT_ANY for wildcard matches. + * @return + * - >1 if cs is greater than the identifiers. + * - 0 if cs matches the identifiers. + * - <0 if cs is less than the identifiers. + */ +int8_t *cf_section_name_cmp(CONF_SECTION const *cs, char const *name1, char const *name2) +{ + int8_t ret; + + if (name1 != CF_IDENT_ANY) { + ret = CMP(strcmp(cf_section_name1(cs), name1), 0); + if (ret != 0) return ret; + } + + if (name2 != CF_IDENT_ANY) { + char const *cs_name2 = cf_section_name2(cs); + + if (!cs_name2) return 1; + + return CMP(strcmp(cs_name2, name2), 0); + } + + return 0; +} + /** Return the second identifier of a #CONF_SECTION * * @param[in] cs to return identifiers for. diff --git a/src/lib/server/cf_util.h b/src/lib/server/cf_util.h index 65425552fcb..c0ab349b2d2 100644 --- a/src/lib/server/cf_util.h +++ b/src/lib/server/cf_util.h @@ -157,6 +157,7 @@ CONF_SECTION *cf_section_has_parent(CONF_SECTION const *cs, char const *cf_section_value_find(CONF_SECTION const *, char const *attr); +int8_t *cf_section_name_cmp(CONF_SECTION const *cs, char const *name1, char const *name2); /** @hidecallergraph */ char const *cf_section_name1(CONF_SECTION const *cs); /** @hidecallergraph */