From: [Thomas Green] Date: Thu, 20 Mar 2025 09:30:15 +0000 (+0100) Subject: Move TTL check of ldns_is_rrset() to a new, separate function X-Git-Tag: 1.9.0-rc.1~26^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fd9031e2e34f291de0687739acf23469d4744a9;p=thirdparty%2Fldns.git Move TTL check of ldns_is_rrset() to a new, separate function --- diff --git a/ldns/rr.h b/ldns/rr.h index 314f1597..dc5ccf98 100644 --- 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 1a9d62af..876848c0 100644 --- 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;