]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add cf_item_has_no_children()
authorAlan T. DeKok <aland@freeradius.org>
Sat, 26 Mar 2022 13:04:42 +0000 (09:04 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 28 Mar 2022 16:15:59 +0000 (12:15 -0400)
src/lib/server/cf_priv.h
src/lib/server/cf_util.c

index 06c059b90648a236e7b0025db00463ca50580de9..a6dcb7ed664dcb2679b220ad9230ff66d1efcc78 100644 (file)
@@ -127,6 +127,18 @@ typedef struct {
        bool                    from_dir;       //!< was read from a directory
 } cf_file_t;
 
+/** Check if the CONF_ITEM has no children.
+ *
+ *  Which is the common use-case
+ *
+ * @param[in] ci               to check
+ * @return                     true/false
+ */
+static inline CC_HINT(nonnull) bool cf_item_has_no_children(CONF_ITEM const *ci)
+{
+       return fr_dlist_empty(&ci->children);
+}
+
 #ifdef __cplusplus
 }
 #endif
index 7e7884329062f77a36ce254bcd28e79df3e30c8c..babfbc5db6c45b334ab5dd4cba019637779c0431 100644 (file)
@@ -75,7 +75,7 @@ static CONF_ITEM *cf_find(CONF_ITEM const *parent, CONF_ITEM_TYPE type, char con
        CONF_ITEM       *find;
 
        if (!parent) return NULL;
-       if (fr_dlist_empty(&parent->children)) return NULL;     /* No children */
+       if (cf_item_has_no_children(parent)) return NULL;
 
        if (!ident1) return cf_next(parent, NULL, type);
 
@@ -387,7 +387,7 @@ CONF_ITEM *_cf_item_remove(CONF_ITEM *parent, CONF_ITEM *child)
        CONF_ITEM       *found = NULL;
        bool            in_ident1, in_ident2;
 
-       if (!parent || fr_dlist_empty(&parent->children)) return NULL;
+       if (!parent || cf_item_has_no_children(parent)) return NULL;
        if (parent != child->parent) return NULL;
 
        cf_item_foreach(parent, ci) {
@@ -2062,11 +2062,11 @@ void _cf_debug(CONF_ITEM const *ci)
        DEBUG("  line          : %i", ci->lineno);
        DEBUG("  next          : %p", fr_dlist_next(&ci->parent->children, ci));
        DEBUG("  parent        : %p", ci->parent);
-       DEBUG("  children      : %s", !fr_dlist_empty(&ci->children) ? "yes" : "no");
+       DEBUG("  children      : %s", cf_item_has_no_children(ci) ? "no" : "yes");
        DEBUG("  ident1 tree   : %p (%u entries)", ci->ident1, ci->ident1 ? fr_rb_num_elements(ci->ident1) : 0);
        DEBUG("  ident2 tree   : %p (%u entries)", ci->ident2, ci->ident2 ? fr_rb_num_elements(ci->ident2) : 0);
 
-       if (fr_dlist_empty(&ci->children)) return;
+       if (cf_item_has_no_children(ci)) return;
 
        /*
         *      Print summary of the item's children