]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Move TTL check of ldns_is_rrset() to a new, separate function 251/head
author[Thomas Green] <thomas.green@afnic.fr>
Thu, 20 Mar 2025 09:30:15 +0000 (10:30 +0100)
committer[Thomas Green] <thomas.green@afnic.fr>
Thu, 20 Mar 2025 09:30:15 +0000 (10:30 +0100)
ldns/rr.h
rr.c

index 314f159707b3373dc74af056107b7f93351dae85..dc5ccf98333490a753da53e841d566517d9ec0f3 100644 (file)
--- a/ldns/rr.h
+++ b/ldns/rr.h
@@ -724,6 +724,13 @@ bool ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, const ldns_rr *rr);
  */
 bool ldns_is_rrset(const ldns_rr_list *rr_list);
 
+/**
+ * checks if an rr_list is a rrset, including checking for TTL.
+ * \param[in] rr_list the rr_list to check
+ * \return true if it is an rrset otherwise false
+ */
+bool ldns_is_rrset_strict(const ldns_rr_list *rr_list);
+
 /**
  * pushes an rr to an rrset (which really are rr_list's).
  * \param[in] *rr_list the rrset to push the rr to
diff --git a/rr.c b/rr.c
index 1a9d62afa439dc82d0a987e2e6eb14d16a57f05f..876848c085d24a734785e70f75281c27443945d1 100644 (file)
--- a/rr.c
+++ b/rr.c
@@ -1261,6 +1261,41 @@ ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, const ldns_rr *rr)
 
 bool
 ldns_is_rrset(const ldns_rr_list *rr_list)
+{
+       ldns_rr_type t;
+       ldns_rr_class c;
+       ldns_rdf *o;
+       ldns_rr *tmp;
+       size_t i;
+
+       if (!rr_list || ldns_rr_list_rr_count(rr_list) == 0) {
+               return false;
+       }
+
+       tmp = ldns_rr_list_rr(rr_list, 0);
+
+       t = ldns_rr_get_type(tmp);
+       c = ldns_rr_get_class(tmp);
+       o = ldns_rr_owner(tmp);
+
+       /* compare these with the rest of the rr_list, start with 1 */
+       for (i = 1; i < ldns_rr_list_rr_count(rr_list); i++) {
+               tmp = ldns_rr_list_rr(rr_list, i);
+               if (t != ldns_rr_get_type(tmp)) {
+                       return false;
+               }
+               if (c != ldns_rr_get_class(tmp)) {
+                       return false;
+               }
+               if (ldns_dname_compare(o, ldns_rr_owner(tmp)) != 0) {
+                       return false;
+               }
+       }
+       return true;
+}
+
+bool
+ldns_is_rrset_strict(const ldns_rr_list *rr_list)
 {
        ldns_rr_type t;
        ldns_rr_class c;