return record;
}
+ virtual bool operator==(const DNSRecordContent& rhs) const
+ {
+ return typeid(*this)==typeid(rhs) && this->getZoneRepresentation() == rhs.getZoneRepresentation();
+ }
+
static shared_ptr<DNSRecordContent> unserialize(const DNSName& qname, uint16_t qtype, const string& serialized);
void doRecordCheck(const struct DNSRecord&){}
if(d_type != rhs.d_type || d_class != rhs.d_class || d_name != rhs.d_name)
return false;
- string lzrp, rzrp;
- if(d_content)
- lzrp=toLower(d_content->getZoneRepresentation());
- if(rhs.d_content)
- rzrp=toLower(rhs.d_content->getZoneRepresentation());
-
- return lzrp == rzrp;
+ return *d_content == *rhs.d_content;
}
};
includeboilerplate(A);
void doRecordCheck(const DNSRecord& dr);
ComboAddress getCA(int port=0) const;
+ bool operator==(const DNSRecordContent& rhs) const override
+ {
+ if(typeid(*this) != typeid(rhs))
+ return false;
+ return d_ip == dynamic_cast<const ARecordContent&>(rhs).d_ip;
+ }
private:
uint32_t d_ip;
};
explicit AAAARecordContent(const ComboAddress& ca);
includeboilerplate(AAAA);
ComboAddress getCA(int port=0) const;
+ bool operator==(const DNSRecordContent& rhs) const override
+ {
+ if(typeid(*this) != typeid(rhs))
+ return false;
+ return d_ip6 == dynamic_cast<const decltype(this)>(&rhs)->d_ip6;
+ }
private:
string d_ip6; // why??
};
uint16_t d_preference;
DNSName d_mxname;
+
+ bool operator==(const DNSRecordContent& rhs) const override
+ {
+ if(typeid(*this) != typeid(rhs))
+ return false;
+ auto rrhs =dynamic_cast<const decltype(this)>(&rhs);
+ return std::tie(d_preference, d_mxname) == std::tie(rrhs->d_preference, rrhs->d_mxname);
+ }
+
};
class KXRecordContent : public DNSRecordContent
public:
includeboilerplate(NS)
explicit NSRecordContent(const DNSName& content) : d_content(content){}
- const DNSName& getNS() const { return d_content; }
+ const DNSName& getNS() const { return d_content; }
+ bool operator==(const DNSRecordContent& rhs) const override
+ {
+ if(typeid(*this) != typeid(rhs))
+ return false;
+ auto rrhs =dynamic_cast<const decltype(this)>(&rhs);
+ return d_content == rrhs->d_content;
+ }
+
private:
DNSName d_content;
};
--- /dev/null
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_NO_MAIN
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <boost/test/unit_test.hpp>
+#include "dnsrecords.hh"
+#include "iputils.hh"
+
+BOOST_AUTO_TEST_SUITE(test_dnsrecordcontent)
+
+BOOST_AUTO_TEST_CASE(test_equality) {
+ reportAllTypes();
+ ComboAddress ip("1.2.3.4"), ip2("10.0.0.1"), ip6("::1");
+ ARecordContent a1(ip), a2(ip), a3(ip2);
+ AAAARecordContent aaaa(ip6), aaaa1(ip6);
+
+ BOOST_CHECK(a1==a2);
+ BOOST_CHECK(!(a1==a3));
+
+ BOOST_CHECK(aaaa == aaaa1);
+
+
+ auto rec1=DNSRecordContent::makeunique(QType::A, 1, "192.168.0.1");
+ auto rec2=DNSRecordContent::makeunique(QType::A, 1, "192.168.222.222");
+ auto rec3=DNSRecordContent::makeunique(QType::AAAA, 1, "::1");
+ auto recMX=DNSRecordContent::makeunique(QType::MX, 1, "25 smtp.powerdns.com");
+ auto recMX2=DNSRecordContent::makeunique(QType::MX, 1, "26 smtp.powerdns.com");
+ auto recMX3=DNSRecordContent::makeunique(QType::MX, 1, "26 SMTP.powerdns.com");
+ BOOST_CHECK(!(*rec1==*rec2));
+ BOOST_CHECK(*rec1==*rec1);
+ BOOST_CHECK(*rec3==*rec3);
+
+ BOOST_CHECK(*recMX==*recMX);
+ BOOST_CHECK(*recMX2==*recMX3);
+ BOOST_CHECK(!(*recMX==*recMX3));
+
+
+ BOOST_CHECK(!(*rec1==*rec3));
+
+ NSRecordContent ns1(DNSName("ns1.powerdns.com")), ns2(DNSName("NS1.powerdns.COM")), ns3(DNSName("powerdns.net"));
+ BOOST_CHECK(ns1==ns2);
+ BOOST_CHECK(!(ns1==ns3));
+}
+
+BOOST_AUTO_TEST_SUITE_END()