]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add fr_dict_attr_compatible
authorAlan T. DeKok <aland@freeradius.org>
Mon, 6 Dec 2021 21:12:53 +0000 (16:12 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 7 Dec 2021 13:32:23 +0000 (08:32 -0500)
for list to list copies.  Does the copy make sense?

src/lib/util/dict.h
src/lib/util/dict_util.c

index ce3305be2b0e8ddd64ef5b303dd524d2f797817a..47aa9385519381a527e99d2c80ec0a4d10031f0d 100644 (file)
@@ -464,6 +464,9 @@ ssize_t                     fr_dict_attr_by_oid_substr(fr_dict_attr_err_t *err,
 fr_dict_attr_t const   *fr_dict_attr_by_oid(fr_dict_attr_err_t *err,
                                             fr_dict_attr_t const *parent, char const *oid)
                                             CC_HINT(nonnull(2,3));
+
+bool                   fr_dict_attr_compatible(fr_dict_attr_t const *a, fr_dict_attr_t const *b) CC_HINT(nonnull);
+
 /** @} */
 
 /** @name Attribute, vendor and dictionary lookup
index 7ad3ec79647536f9637a6c4a486d69b9970f955a..df10c65d696038d35f5a97a05688114342931829 100644 (file)
@@ -3924,3 +3924,36 @@ void fr_dict_attr_verify(char const *file, int line, fr_dict_attr_t const *da)
                break;
        }
 }
+
+/** See if two DAs are compatible, and can contain the same things.
+ *
+ */
+bool fr_dict_attr_compatible(fr_dict_attr_t const *a, fr_dict_attr_t const *b)
+{
+       fr_dict_attr_t const *ref;
+
+       /*
+        *      They're the same DA, they're compatible.
+        */
+       if (a == b) return true;
+
+       /*
+        *      @todo - TLVs and STRUCTs can clone other things.  In
+        *      which case we want to allow the various cloned src/dst
+        *      attributes to be able to copy child VPs to each other.
+        */
+
+       if ((a->type != FR_TYPE_GROUP) && (b->type != FR_TYPE_GROUP)) return false;
+
+       /*
+        *      Groups can reference other things.  In which case we
+        *      check the reference, not the input attribute.
+        */
+       ref = fr_dict_attr_ref(a);
+       if (ref) a = ref;
+
+       ref = fr_dict_attr_ref(b);
+       if (ref) b = ref;
+
+       return (a == b);
+}