]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Simple function for matching name1/name2 to a section name
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 30 Jun 2022 20:59:25 +0000 (15:59 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 30 Jun 2022 20:59:25 +0000 (15:59 -0500)
src/lib/server/cf_util.c
src/lib/server/cf_util.h

index a7d104670b4154ce58c8dcf3266aa3ac7b34f0d0..2e3cb00ac21ad7eb088bace02f1236632a750ec7 100644 (file)
@@ -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.
index 65425552fcb3273851937b94827af5cafae89dac..c0ab349b2d22d15d59ab798fca39a69d00e1d14c 100644 (file)
@@ -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 */