From: Arran Cudbard-Bell Date: Thu, 24 Oct 2024 23:00:50 +0000 (-0600) Subject: Add comparator for dictionary attributes based on their contents X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62761340a9be641d41c70ca92c253fa632627346;p=thirdparty%2Ffreeradius-server.git Add comparator for dictionary attributes based on their contents --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index 4cb1fdb509c..573068780e8 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -531,7 +531,7 @@ fr_dict_attr_t const *fr_dict_attr_unknown_resolve(fr_dict_t const *dict, fr_dic * * @{ */ -static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a, fr_dict_attr_t const *b) +static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a, fr_dict_attr_t const *b) { int8_t ret; @@ -558,6 +558,31 @@ static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a, */ return CMP(a, b); } + +/** Compare two dictionary attributes by their contents + * + * @param[in] a First attribute to compare. + * @param[in] b Second attribute to compare. + * @return + * - 0 if the attributes are equal. + * - -1 if a < b. + * - +1 if a > b. + */ +static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp_fields(const fr_dict_attr_t *a, const fr_dict_attr_t *b) +{ + int8_t ret; + + ret = CMP(a->attr, b->attr); + if (ret != 0) return ret; + + ret = CMP(a->parent, b->parent); + if (ret != 0) return ret; + + ret = CMP(fr_dict_vendor_num_by_da(a), fr_dict_vendor_num_by_da(b)); + if (ret != 0) return ret; + + return CMP(memcmp(&a->flags, &b->flags, sizeof(a->flags)), 0); +} /** @} */ /** @name Debugging functions