From 23721d33a5f89fd3b0062285a1d8b79f30aa0362 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Mon, 18 Apr 2016 13:05:25 +0200 Subject: [PATCH] implement an official pretty ordering for DNSRecords and use it --- pdns/dnsparser.hh | 27 +++++++++++++++++++++++++++ pdns/pdnsutil.cc | 18 ++++-------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index baf3a82a71..a0d6a727ac 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -286,6 +286,33 @@ struct DNSRecord return lzrp < rzrp; } + // this orders in canonical order and keeps the SOA record on top + static bool prettyCompare(const DNSRecord& a, const DNSRecord& b) + { + auto aType = (a.d_type == QType::SOA) ? 0 : a.d_type; + auto bType = (b.d_type == QType::SOA) ? 0 : b.d_type; + + if(a.d_name.canonCompare(b.d_name)) + return true; + if(b.d_name.canonCompare(a.d_name)) + return false; + + if(tie(aType, a.d_class, a.d_ttl) < tie(bType, b.d_class, b.d_ttl)) + return true; + + if(tie(aType, a.d_class, a.d_ttl) != tie(bType, b.d_class, b.d_ttl)) + return false; + + string lzrp, rzrp; + if(a.d_content) + lzrp=toLower(a.d_content->getZoneRepresentation()); + if(b.d_content) + rzrp=toLower(b.d_content->getZoneRepresentation()); + + return lzrp < rzrp; + } + + bool operator==(const DNSRecord& rhs) const { string lzrp, rzrp; diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index b664268918..98a9819722 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -923,16 +923,6 @@ int clearZone(DNSSECKeeper& dk, const DNSName &zone) { return EXIT_SUCCESS; } -bool prettyDROrder(const DNSRecord& a, const DNSRecord& b) -{ - if(a.d_type == QType::SOA && b.d_type != QType::SOA) - return true; - if(a.d_type != QType::SOA && b.d_type == QType::SOA) - return false; - - return agetZoneRepresentation(true)< diff; map, string> changed; - set_difference(pre.cbegin(), pre.cend(), post.cbegin(), post.cend(), back_inserter(diff), prettyDROrder); + set_difference(pre.cbegin(), pre.cend(), post.cbegin(), post.cend(), back_inserter(diff), DNSRecord::prettyCompare); for(const auto& d : diff) { ostringstream str; str<<'-'<< d.d_name <<" "<getZoneRepresentation(true)<