diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index fc100abecf7a3..0daa5d66e84b9 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -1114,40 +1114,17 @@ int dict_attr_child_add(fr_dict_attr_t *parent, fr_dict_attr_t *child) * Attributes are inserted into the bin in order of their attribute * numbers to allow slightly more efficient lookups. */ - bin = &children[child->attr & 0xff]; - for (;;) { - bool child_is_struct = false; - bool bin_is_struct = false; - - if (!*bin) break; - + for (bin = &children[child->attr & 0xff]; *bin; bin = &(*bin)->next) { /* * Workaround for vendors that overload the RFC space. * Structural attributes always take priority. */ - switch (child->type) { - case FR_TYPE_STRUCTURAL: - child_is_struct = true; - break; - - default: - break; - } - - switch ((*bin)->type) { - case FR_TYPE_STRUCTURAL: - bin_is_struct = true; - break; - - default: - break; - } + bool child_is_struct = fr_type_is_structural(child->type); + bool bin_is_struct = fr_type_is_structural((*bin)->type); if (child_is_struct && !bin_is_struct) break; - else if (fr_dict_vendor_num_by_da(child) <= fr_dict_vendor_num_by_da(*bin)) break; /* Prioritise RFC attributes */ - else if (child->attr <= (*bin)->attr) break; - - bin = &(*bin)->next; + if (fr_dict_vendor_num_by_da(child) <= fr_dict_vendor_num_by_da(*bin)) break; /* Prioritise RFC attributes */ + if (child->attr <= (*bin)->attr) break; } memcpy(&this, &bin, sizeof(this)); diff --git a/src/lib/util/types.h b/src/lib/util/types.h index d7a8376c8d9f8..4bc2900305ffc 100644 --- a/src/lib/util/types.h +++ b/src/lib/util/types.h @@ -217,6 +217,19 @@ typedef enum { _mid(FR_TYPE_TLV) \ _end(FR_TYPE_VENDOR) +/** Hack for truthiness check + * + * - VSAs + * - Structs + * - TLVs + * - Vendors + */ +#define FR_TYPE_STRUCTURAL_EXCEPT_GROUP_DEF(_beg, _mid, _end) \ + _beg(FR_TYPE_VSA) \ + _mid(FR_TYPE_STRUCT) \ + _mid(FR_TYPE_TLV) \ + _end(FR_TYPE_VENDOR) + /** Match all non value types in case statements * * - Groups @@ -279,6 +292,7 @@ typedef enum { #define FR_TYPE_QUOTED FR_TYPE_QUOTED_DEF(CASE_BEG, CASE_MID, CASE_END) #define FR_TYPE_STRUCTURAL_EXCEPT_VSA FR_TYPE_STRUCTURAL_EXCEPT_VSA_DEF(CASE_BEG, CASE_MID, CASE_END) +#define FR_TYPE_STRUCTURAL_EXCEPT_GROUP FR_TYPE_STRUCTURAL_EXCEPT_GROUP_DEF(CASE_BEG, CASE_MID, CASE_END) #define FR_TYPE_STRUCTURAL FR_TYPE_STRUCTURAL_DEF(CASE_BEG, CASE_MID, CASE_END) #define FR_TYPE_LEAF FR_TYPE_LEAF_DEF(CASE_BEG, CASE_MID, CASE_END) #define FR_TYPE_NON_LEAF FR_TYPE_NON_LEAF_DEF(CASE_BEG, CASE_MID, CASE_END) diff --git a/src/lib/util/value.c b/src/lib/util/value.c index 74210811fb9e0..24ae9855b1b0e 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -6063,11 +6063,11 @@ bool fr_value_box_is_truthy(fr_value_box_t const *in) switch (in->type) { case FR_TYPE_NULL: + case FR_TYPE_STRUCTURAL_EXCEPT_GROUP: return false; - case FR_TYPE_STRUCTURAL: - if (in->type == FR_TYPE_GROUP) return (fr_value_box_list_num_elements(&in->vb_group) > 0); - return false; + case FR_TYPE_GROUP: + return (fr_value_box_list_num_elements(&in->vb_group) > 0); case FR_TYPE_BOOL: return in->vb_bool;