]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Switch CF_IDENT_ANY to a macro instead of a static variable
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 Jun 2017 00:04:32 +0000 (20:04 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 Jun 2017 00:04:32 +0000 (20:04 -0400)
So it can be used as a compile time constant

src/include/cf_util.h
src/main/cf_util.c

index 6975b2f3ed7dce5822af38682e018d4184da65e3..52b24c7341e6642011d52c1f40b30b33a90a8aa4 100644 (file)
@@ -76,7 +76,7 @@ _Generic((_cf), \
 
 typedef int (*cf_walker_t)(void *data, void *ctx);
 
-extern char const *CF_IDENT_ANY;
+#define CF_IDENT_ANY "<any>"
 
 /*
  *     Generic functions that apply to all types of #CONF_ITEM
index f577a182fa354e55bcef363731edfa1a00a7496a..7fe9453dc3e86280db13341895473c8970076dcc 100644 (file)
@@ -33,8 +33,6 @@ RCSID("$Id$")
 
 #include <freeradius-devel/radiusd.h>
 
-char const *CF_IDENT_ANY = "<any>";
-
 static inline int cf_ident2_cmp(void const *a, void const *b);
 static int _cf_ident1_cmp(void const *a, void const *b);
 static int _cf_ident2_cmp(void const *a, void const *b);
@@ -61,6 +59,8 @@ static CONF_ITEM *cf_next(CONF_ITEM const *parent, CONF_ITEM const *prev, CONF_I
        return NULL;
 }
 
+#define IS_WILDCARD(_ident) ((_ident) && ((_ident == CF_IDENT_ANY) || (strcmp(_ident, CF_IDENT_ANY) == 0)))
+
 /** Return the next child that's of the specified type with the specified identifiers
  *
  * @param[in] parent   The section we're searching in.
@@ -89,13 +89,13 @@ static CONF_ITEM *cf_find(CONF_ITEM const *parent, CONF_ITEM_TYPE type, char con
                memset(&cs_find, 0, sizeof(cs_find));
                cs_find.item.type = CONF_ITEM_SECTION;
                cs_find.name1 = ident1;
-               if (ident2 != CF_IDENT_ANY) cs_find.name2 = ident2;
+               if (!IS_WILDCARD(ident2)) cs_find.name2 = ident2;
 
                find = (CONF_ITEM *)&cs_find;
                break;
 
        case CONF_ITEM_PAIR:
-               rad_assert((ident2 == NULL) || (ident2 == CF_IDENT_ANY));
+               rad_assert((ident2 == NULL) || IS_WILDCARD(ident2));
 
                memset(&cp_find, 0, sizeof(cp_find));
                cp_find.item.type = CONF_ITEM_PAIR;
@@ -108,7 +108,7 @@ static CONF_ITEM *cf_find(CONF_ITEM const *parent, CONF_ITEM_TYPE type, char con
                memset(&cd_find, 0, sizeof(cd_find));
                cd_find.item.type = CONF_ITEM_DATA;
                cd_find.type = ident1;
-               if (ident2 != CF_IDENT_ANY) cd_find.name = ident2;
+               if (!IS_WILDCARD(ident2)) cd_find.name = ident2;
 
                find = (CONF_ITEM *)&cd_find;
                break;
@@ -120,7 +120,7 @@ static CONF_ITEM *cf_find(CONF_ITEM const *parent, CONF_ITEM_TYPE type, char con
        /*
         *      No ident1, iterate over the child list
         */
-       if (ident1 == CF_IDENT_ANY) {
+       if (IS_WILDCARD(ident1)) {
                CONF_ITEM *ci;
 
                for (ci = parent->child;
@@ -133,7 +133,7 @@ static CONF_ITEM *cf_find(CONF_ITEM const *parent, CONF_ITEM_TYPE type, char con
        /*
         *      No ident2, use the ident1 tree.
         */
-       if (ident2 == CF_IDENT_ANY) return rbtree_finddata(parent->ident1, find);
+       if (IS_WILDCARD(ident2)) return rbtree_finddata(parent->ident1, find);
 
        /*
         *      Both ident1 and ident2 use the ident2 tree.
@@ -175,13 +175,13 @@ static CONF_ITEM *cf_find_next(CONF_ITEM const *parent, CONF_ITEM const *prev,
                memset(&cs_find, 0, sizeof(cs_find));
                cs_find.item.type = CONF_ITEM_SECTION;
                cs_find.name1 = ident1;
-               if (ident2 != CF_IDENT_ANY) cs_find.name2 = ident2;
+               if (!IS_WILDCARD(ident2)) cs_find.name2 = ident2;
 
                find = (CONF_ITEM *)&cs_find;
                break;
 
        case CONF_ITEM_PAIR:
-               rad_assert((ident2 == NULL) || (ident2 == CF_IDENT_ANY));
+               rad_assert((ident2 == NULL) || IS_WILDCARD(ident2));
 
                memset(&cp_find, 0, sizeof(cp_find));
                cp_find.item.type = CONF_ITEM_PAIR;
@@ -194,7 +194,7 @@ static CONF_ITEM *cf_find_next(CONF_ITEM const *parent, CONF_ITEM const *prev,
                memset(&cd_find, 0, sizeof(cd_find));
                cd_find.item.type = CONF_ITEM_DATA;
                cd_find.type = ident1;
-               if (ident2 != CF_IDENT_ANY) cd_find.name = ident2;
+               if (!IS_WILDCARD(ident2)) cd_find.name = ident2;
 
                find = (CONF_ITEM *)&cd_find;
                break;
@@ -203,7 +203,7 @@ static CONF_ITEM *cf_find_next(CONF_ITEM const *parent, CONF_ITEM const *prev,
                if (!rad_cond_assert(0)) return NULL;
        }
 
-       if (ident1 == CF_IDENT_ANY) {
+       if (IS_WILDCARD(ident1)) {
                for (ci = prev->next;
                     ci && (cf_ident2_cmp(ci, find) != 0);
                     ci = ci->next);
@@ -211,7 +211,7 @@ static CONF_ITEM *cf_find_next(CONF_ITEM const *parent, CONF_ITEM const *prev,
                return ci;
        }
 
-       if (ident2 == CF_IDENT_ANY) {
+       if (IS_WILDCARD(ident2)) {
                for (ci = prev->next;
                     ci && (_cf_ident1_cmp(ci, find) != 0);
                     ci = ci->next);