From aec57bc4f4227362427463f19e3b9e21f4ce2ac3 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 7 Jun 2018 11:21:04 +0200 Subject: [PATCH] Allocate DNSRecord objects as smart pointers right away (cherry picked from commit 1339125af5afe6d6ecfe0a500c5fdc76d790459d) --- modules/bindbackend/binddnssec.cc | 3 +- modules/tinydnsbackend/tinydnsbackend.cc | 3 +- pdns/dnsparser.cc | 30 ++++++------------ pdns/dnsparser.hh | 11 +++---- pdns/dnsrecords.cc | 16 +++++----- pdns/dnsrecords.hh | 40 ++++++++++++------------ pdns/nsecrecords.cc | 24 +++++++------- pdns/pdnsutil.cc | 6 ++-- pdns/rec-lua-conf.cc | 4 +-- pdns/rec_channel_rec.cc | 2 +- pdns/sillyrecords.cc | 8 ++--- pdns/speedtest.cc | 15 +++++---- pdns/test-dnsrecords_cc.cc | 6 ++-- pdns/test-signers.cc | 4 +-- pdns/toysdig.cc | 2 +- pdns/ws-auth.cc | 2 +- 16 files changed, 80 insertions(+), 96 deletions(-) diff --git a/modules/bindbackend/binddnssec.cc b/modules/bindbackend/binddnssec.cc index f6d90d778..27792a891 100644 --- a/modules/bindbackend/binddnssec.cc +++ b/modules/bindbackend/binddnssec.cc @@ -164,9 +164,8 @@ bool Bind2Backend::getNSEC3PARAM(const DNSName& name, NSEC3PARAMRecordContent* n static int maxNSEC3Iterations=::arg().asNum("max-nsec3-iterations"); if(ns3p) { - NSEC3PARAMRecordContent* tmp=dynamic_cast(DNSRecordContent::mastermake(QType::NSEC3PARAM, 1, value)); + auto tmp=std::dynamic_pointer_cast(DNSRecordContent::mastermake(QType::NSEC3PARAM, 1, value)); *ns3p = *tmp; - delete tmp; if (ns3p->d_iterations > maxNSEC3Iterations) { ns3p->d_iterations = maxNSEC3Iterations; diff --git a/modules/tinydnsbackend/tinydnsbackend.cc b/modules/tinydnsbackend/tinydnsbackend.cc index 73b88fcca..ba595496d 100644 --- a/modules/tinydnsbackend/tinydnsbackend.cc +++ b/modules/tinydnsbackend/tinydnsbackend.cc @@ -300,10 +300,9 @@ bool TinyDNSBackend::get(DNSResourceRecord &rr) dr.d_type = rr.qtype.getCode(); dr.d_clen = val.size()-pr.d_pos; - DNSRecordContent *drc = DNSRecordContent::mastermake(dr, pr); + auto drc = DNSRecordContent::mastermake(dr, pr); rr.content = drc->getZoneRepresentation(); DLOG(cerr<<"CONTENT: "< DNSRecordContent::unserialize(const DNSName& qname, return ret; } -DNSRecordContent* DNSRecordContent::mastermake(const DNSRecord &dr, - PacketReader& pr) +std::shared_ptr DNSRecordContent::mastermake(const DNSRecord &dr, + PacketReader& pr) { uint16_t searchclass = (dr.d_type == QType::OPT) ? 1 : dr.d_class; // class is invalid for OPT typemap_t::const_iterator i=getTypemap().find(make_pair(searchclass, dr.d_type)); if(i==getTypemap().end() || !i->second) { - return new UnknownRecordContent(dr, pr); + return std::make_shared(dr, pr); } return i->second(dr, pr); } -DNSRecordContent* DNSRecordContent::mastermake(uint16_t qtype, uint16_t qclass, - const string& content) +std::shared_ptr DNSRecordContent::mastermake(uint16_t qtype, uint16_t qclass, + const string& content) { zmakermap_t::const_iterator i=getZmakermap().find(make_pair(qclass, qtype)); if(i==getZmakermap().end()) { - return new UnknownRecordContent(content); + return std::make_shared(content); } return i->second(content); } -std::unique_ptr DNSRecordContent::makeunique(uint16_t qtype, uint16_t qclass, - const string& content) -{ - zmakermap_t::const_iterator i=getZmakermap().find(make_pair(qclass, qtype)); - if(i==getZmakermap().end()) { - return std::unique_ptr(new UnknownRecordContent(content)); - } - - return std::unique_ptr(i->second(content)); -} - - -DNSRecordContent* DNSRecordContent::mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t oc) { +std::shared_ptr DNSRecordContent::mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t oc) { // For opcode UPDATE and where the DNSRecord is an answer record, we don't care about content, because this is // not used within the prerequisite section of RFC2136, so - we can simply use unknownrecordcontent. // For section 3.2.3, we do need content so we need to get it properly. But only for the correct Qclasses. if (oc == Opcode::Update && dr.d_place == DNSResourceRecord::ANSWER && dr.d_class != 1) - return new UnknownRecordContent(dr, pr); + return std::make_shared(dr, pr); uint16_t searchclass = (dr.d_type == QType::OPT) ? 1 : dr.d_class; // class is invalid for OPT typemap_t::const_iterator i=getTypemap().find(make_pair(searchclass, dr.d_type)); if(i==getTypemap().end() || !i->second) { - return new UnknownRecordContent(dr, pr); + return std::make_shared(dr, pr); } return i->second(dr, pr); diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 03eca9fa1..9ee039b63 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -166,10 +166,9 @@ struct DNSRecord; class DNSRecordContent { public: - static DNSRecordContent* mastermake(const DNSRecord &dr, PacketReader& pr); - static DNSRecordContent* mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t opcode); - static DNSRecordContent* mastermake(uint16_t qtype, uint16_t qclass, const string& zone); - static std::unique_ptr makeunique(uint16_t qtype, uint16_t qclass, const string& content); + static std::shared_ptr mastermake(const DNSRecord &dr, PacketReader& pr); + static std::shared_ptr mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t opcode); + static std::shared_ptr mastermake(uint16_t qtype, uint16_t qclass, const string& zone); virtual std::string getZoneRepresentation(bool noDot=false) const = 0; virtual ~DNSRecordContent() {} @@ -198,8 +197,8 @@ public: void doRecordCheck(const struct DNSRecord&){} - typedef DNSRecordContent* makerfunc_t(const struct DNSRecord& dr, PacketReader& pr); - typedef DNSRecordContent* zmakerfunc_t(const string& str); + typedef std::shared_ptr makerfunc_t(const struct DNSRecord& dr, PacketReader& pr); + typedef std::shared_ptr zmakerfunc_t(const string& str); static void regist(uint16_t cl, uint16_t ty, makerfunc_t* f, zmakerfunc_t* z, const char* name) { diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 7c66209c1..5944d11f6 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -386,19 +386,19 @@ void EUI48RecordContent::report(void) { regist(1, QType::EUI48, &make, &make, "EUI48"); } -DNSRecordContent* EUI48RecordContent::make(const DNSRecord &dr, PacketReader& pr) +std::shared_ptr EUI48RecordContent::make(const DNSRecord &dr, PacketReader& pr) { if(dr.d_clen!=6) throw MOADNSException("Wrong size for EUI48 record"); - EUI48RecordContent* ret=new EUI48RecordContent(); + auto ret=std::make_shared(); pr.copyRecord((uint8_t*) &ret->d_eui48, 6); return ret; } -DNSRecordContent* EUI48RecordContent::make(const string& zone) +std::shared_ptr EUI48RecordContent::make(const string& zone) { // try to parse - EUI48RecordContent *ret=new EUI48RecordContent(); + auto ret=std::make_shared(); // format is 6 hex bytes and dashes if (sscanf(zone.c_str(), "%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx", ret->d_eui48, ret->d_eui48+1, ret->d_eui48+2, @@ -429,19 +429,19 @@ void EUI64RecordContent::report(void) { regist(1, QType::EUI64, &make, &make, "EUI64"); } -DNSRecordContent* EUI64RecordContent::make(const DNSRecord &dr, PacketReader& pr) +std::shared_ptr EUI64RecordContent::make(const DNSRecord &dr, PacketReader& pr) { if(dr.d_clen!=8) throw MOADNSException("Wrong size for EUI64 record"); - EUI64RecordContent* ret=new EUI64RecordContent(); + auto ret=std::make_shared(); pr.copyRecord((uint8_t*) &ret->d_eui64, 8); return ret; } -DNSRecordContent* EUI64RecordContent::make(const string& zone) +std::shared_ptr EUI64RecordContent::make(const string& zone) { // try to parse - EUI64RecordContent *ret=new EUI64RecordContent(); + auto ret=std::make_shared(); // format is 8 hex bytes and dashes if (sscanf(zone.c_str(), "%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx", ret->d_eui64, ret->d_eui64+1, ret->d_eui64+2, diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index 53284eccc..aff51ab1b 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -33,8 +33,8 @@ RNAME##RecordContent(const string& zoneData); \ static void report(void); \ static void unreport(void); \ - static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); \ - static DNSRecordContent* make(const string& zonedata); \ + static std::shared_ptr make(const DNSRecord &dr, PacketReader& pr); \ + static std::shared_ptr make(const string& zonedata); \ string getZoneRepresentation(bool noDot=false) const override; \ void toPacket(DNSPacketWriter& pw) override; \ uint16_t getType() const override { return QType::RNAME; } \ @@ -466,8 +466,8 @@ public: {} NSECRecordContent(const string& content, const string& zone=""); //FIXME400: DNSName& zone? - static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); - static DNSRecordContent* make(const string& content); + static std::shared_ptr make(const DNSRecord &dr, PacketReader& pr); + static std::shared_ptr make(const string& content); string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint16_t getType() const override @@ -487,8 +487,8 @@ public: {} NSEC3RecordContent(const string& content, const string& zone=""); //FIXME400: DNSName& zone? - static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); - static DNSRecordContent* make(const string& content); + static std::shared_ptr make(const DNSRecord &dr, PacketReader& pr); + static std::shared_ptr make(const string& content); string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; @@ -516,8 +516,8 @@ public: {} NSEC3PARAMRecordContent(const string& content, const string& zone=""); // FIXME400: DNSName& zone? - static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); - static DNSRecordContent* make(const string& content); + static std::shared_ptr make(const DNSRecord &dr, PacketReader& pr); + static std::shared_ptr make(const string& content); string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; @@ -541,8 +541,8 @@ public: {} LOCRecordContent(const string& content, const string& zone=""); - static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); - static DNSRecordContent* make(const string& content); + static std::shared_ptr make(const DNSRecord &dr, PacketReader& pr); + static std::shared_ptr make(const string& content); string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; @@ -565,8 +565,8 @@ public: {} WKSRecordContent(const string& content, const string& zone=""); // FIXME400: DNSName& zone? - static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); - static DNSRecordContent* make(const string& content); + static std::shared_ptr make(const DNSRecord &dr, PacketReader& pr); + static std::shared_ptr make(const string& content); string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; @@ -580,8 +580,8 @@ class EUI48RecordContent : public DNSRecordContent public: EUI48RecordContent() {}; static void report(void); - static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); - static DNSRecordContent* make(const string& zone); // FIXME400: DNSName& zone? + static std::shared_ptr make(const DNSRecord &dr, PacketReader& pr); + static std::shared_ptr make(const string& zone); // FIXME400: DNSName& zone? string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint16_t getType() const override { return QType::EUI48; } @@ -595,8 +595,8 @@ class EUI64RecordContent : public DNSRecordContent public: EUI64RecordContent() {}; static void report(void); - static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); - static DNSRecordContent* make(const string& zone); // FIXME400: DNSName& zone? + static std::shared_ptr make(const DNSRecord &dr, PacketReader& pr); + static std::shared_ptr make(const string& zone); // FIXME400: DNSName& zone? string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint16_t getType() const override { return QType::EUI64; } @@ -643,9 +643,9 @@ class CAARecordContent : public DNSRecordContent { }; #define boilerplate(RNAME, RTYPE) \ -RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const DNSRecord& dr, PacketReader& pr) \ +std::shared_ptr RNAME##RecordContent::make(const DNSRecord& dr, PacketReader& pr) \ { \ - return new RNAME##RecordContent(dr, pr); \ + return std::make_shared(dr, pr); \ } \ \ RNAME##RecordContent::RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr) \ @@ -654,9 +654,9 @@ RNAME##RecordContent::RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr xfrPacket(pr); \ } \ \ -RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const string& zonedata) \ +std::shared_ptr RNAME##RecordContent::make(const string& zonedata) \ { \ - return new RNAME##RecordContent(zonedata); \ + return std::make_shared(zonedata); \ } \ \ void RNAME##RecordContent::toPacket(DNSPacketWriter& pw) \ diff --git a/pdns/nsecrecords.cc b/pdns/nsecrecords.cc index 4796f4d40..875fc78ec 100644 --- a/pdns/nsecrecords.cc +++ b/pdns/nsecrecords.cc @@ -29,9 +29,9 @@ void NSECRecordContent::report(void) regist(1, 47, &make, &make, "NSEC"); } -DNSRecordContent* NSECRecordContent::make(const string& content) +std::shared_ptr NSECRecordContent::make(const string& content) { - return new NSECRecordContent(content); + return std::make_shared(content); } NSECRecordContent::NSECRecordContent(const string& content, const string& zone) @@ -81,9 +81,9 @@ void NSECRecordContent::toPacket(DNSPacketWriter& pw) pw.xfrBlob(tmp); } -NSECRecordContent::DNSRecordContent* NSECRecordContent::make(const DNSRecord &dr, PacketReader& pr) +std::shared_ptr NSECRecordContent::make(const DNSRecord &dr, PacketReader& pr) { - NSECRecordContent* ret=new NSECRecordContent(); + auto ret=std::make_shared(); pr.xfrName(ret->d_next); string bitmap; pr.xfrBlob(bitmap); @@ -136,9 +136,9 @@ void NSEC3RecordContent::report(void) regist(1, 50, &make, &make, "NSEC3"); } -DNSRecordContent* NSEC3RecordContent::make(const string& content) +std::shared_ptr NSEC3RecordContent::make(const string& content) { - return new NSEC3RecordContent(content); + return std::make_shared(content); } NSEC3RecordContent::NSEC3RecordContent(const string& content, const string& zone) @@ -203,9 +203,9 @@ void NSEC3RecordContent::toPacket(DNSPacketWriter& pw) } } -NSEC3RecordContent::DNSRecordContent* NSEC3RecordContent::make(const DNSRecord &dr, PacketReader& pr) +std::shared_ptr NSEC3RecordContent::make(const DNSRecord &dr, PacketReader& pr) { - NSEC3RecordContent* ret=new NSEC3RecordContent(); + auto ret=std::make_shared(); pr.xfr8BitInt(ret->d_algorithm); pr.xfr8BitInt(ret->d_flags); pr.xfr16BitInt(ret->d_iterations); @@ -273,9 +273,9 @@ void NSEC3PARAMRecordContent::report(void) regist(254, 51, &make, &make, "NSEC3PARAM"); } -DNSRecordContent* NSEC3PARAMRecordContent::make(const string& content) +std::shared_ptr NSEC3PARAMRecordContent::make(const string& content) { - return new NSEC3PARAMRecordContent(content); + return std::make_shared(content); } NSEC3PARAMRecordContent::NSEC3PARAMRecordContent(const string& content, const string& zone) @@ -297,9 +297,9 @@ void NSEC3PARAMRecordContent::toPacket(DNSPacketWriter& pw) pw.xfrBlob(d_salt); } -NSEC3PARAMRecordContent::DNSRecordContent* NSEC3PARAMRecordContent::make(const DNSRecord &dr, PacketReader& pr) +std::shared_ptr NSEC3PARAMRecordContent::make(const DNSRecord &dr, PacketReader& pr) { - NSEC3PARAMRecordContent* ret=new NSEC3PARAMRecordContent(); + auto ret=std::make_shared(); pr.xfr8BitInt(ret->d_algorithm); pr.xfr8BitInt(ret->d_flags); pr.xfr16BitInt(ret->d_iterations); diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index 47b2e400d..42844b5c4 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -1414,15 +1414,15 @@ void verifyCrypto(const string& zone) if(rr.qtype.getCode() == QType::DNSKEY) { cerr<<"got DNSKEY!"<(DNSRecordContent::mastermake(QType::DNSKEY, 1, rr.content)); + drc = *std::dynamic_pointer_cast(DNSRecordContent::mastermake(QType::DNSKEY, 1, rr.content)); } else if(rr.qtype.getCode() == QType::RRSIG) { cerr<<"got RRSIG"<(DNSRecordContent::mastermake(QType::RRSIG, 1, rr.content)); + rrc = *std::dynamic_pointer_cast(DNSRecordContent::mastermake(QType::RRSIG, 1, rr.content)); } else if(rr.qtype.getCode() == QType::DS) { cerr<<"got DS"<(DNSRecordContent::mastermake(QType::DS, 1, rr.content)); + dsrc = *std::dynamic_pointer_cast(DNSRecordContent::mastermake(QType::DS, 1, rr.content)); } else { qname = rr.qname; diff --git a/pdns/rec-lua-conf.cc b/pdns/rec-lua-conf.cc index f8001bf9f..6966ef791 100644 --- a/pdns/rec-lua-conf.cc +++ b/pdns/rec-lua-conf.cc @@ -35,7 +35,7 @@ GlobalStateHolder g_luaconfs; LuaConfigItems::LuaConfigItems() { for (const auto &dsRecord : rootDSs) { - auto ds=unique_ptr(dynamic_cast(DSRecordContent::make(dsRecord))); + auto ds=std::dynamic_pointer_cast(DSRecordContent::make(dsRecord)); dsAnchors[DNSName(".")].insert(*ds); } } @@ -234,7 +234,7 @@ void loadRecursorLuaConfig(const std::string& fname) Lua.writeFunction("addDS", [&lci](const std::string& who, const std::string& what) { DNSName zone(who); - auto ds = unique_ptr(dynamic_cast(DSRecordContent::make(what))); + auto ds=std::dynamic_pointer_cast(DSRecordContent::make(what)); lci.dsAnchors[zone].insert(*ds); }); diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index be3724b6b..e6efbaa64 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -490,7 +490,7 @@ string doAddTA(T begin, T end) try { L<(dynamic_cast(DSRecordContent::make(what))); + auto ds=std::dynamic_pointer_cast(DSRecordContent::make(what)); lci.dsAnchors[who].insert(*ds); }); broadcastAccFunction(boost::bind(pleaseWipePacketCache, who, true)); diff --git a/pdns/sillyrecords.cc b/pdns/sillyrecords.cc index 289cdb18c..d4030ef26 100644 --- a/pdns/sillyrecords.cc +++ b/pdns/sillyrecords.cc @@ -159,9 +159,9 @@ void LOCRecordContent::report(void) regist(254, QType::LOC, &make, &make, "LOC"); } -DNSRecordContent* LOCRecordContent::make(const string& content) +std::shared_ptr LOCRecordContent::make(const string& content) { - return new LOCRecordContent(content); + return std::make_shared(content); } @@ -177,9 +177,9 @@ void LOCRecordContent::toPacket(DNSPacketWriter& pw) pw.xfr32BitInt(d_altitude); } -LOCRecordContent::DNSRecordContent* LOCRecordContent::make(const DNSRecord &dr, PacketReader& pr) +std::shared_ptr LOCRecordContent::make(const DNSRecord &dr, PacketReader& pr) { - LOCRecordContent* ret=new LOCRecordContent(); + auto ret=std::make_shared(); pr.xfr8BitInt(ret->d_version); pr.xfr8BitInt(ret->d_size); pr.xfr8BitInt(ret->d_horizpre); diff --git a/pdns/speedtest.cc b/pdns/speedtest.cc index 8e4021251..07c8aa9fd 100644 --- a/pdns/speedtest.cc +++ b/pdns/speedtest.cc @@ -207,9 +207,8 @@ struct MakeARecordTestMM void operator()() const { - DNSRecordContent*drc = DNSRecordContent::mastermake(QType::A, 1, - "1.2.3.4"); - delete drc; + auto drc = DNSRecordContent::mastermake(QType::A, 1, + "1.2.3.4"); } }; @@ -281,8 +280,8 @@ struct GenericRecordTest DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), d_type); for(int records = 0; records < d_records; records++) { pw.startRecord(DNSName("outpost.ds9a.nl"), d_type); - DNSRecordContent*drc = DNSRecordContent::mastermake(d_type, 1, - d_content); + auto drc = DNSRecordContent::mastermake(d_type, 1, + d_content); drc->toPacket(pw); delete drc; } @@ -309,7 +308,7 @@ struct AAAARecordTest DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::AAAA); for(int records = 0; records < d_records; records++) { pw.startRecord(DNSName("outpost.ds9a.nl"), QType::AAAA); - DNSRecordContent*drc = DNSRecordContent::mastermake(QType::AAAA, 1, "fe80::21d:92ff:fe6d:8441"); + auto drc = DNSRecordContent::mastermake(QType::AAAA, 1, "fe80::21d:92ff:fe6d:8441"); drc->toPacket(pw); delete drc; } @@ -334,7 +333,7 @@ struct SOARecordTest for(int records = 0; records < d_records; records++) { pw.startRecord(DNSName("outpost.ds9a.nl"), QType::SOA); - DNSRecordContent*drc = DNSRecordContent::mastermake(QType::SOA, 1, "a0.org.afilias-nst.info. noc.afilias-nst.info. 2008758137 1800 900 604800 86400"); + auto drc = DNSRecordContent::mastermake(QType::SOA, 1, "a0.org.afilias-nst.info. noc.afilias-nst.info. 2008758137 1800 900 604800 86400"); drc->toPacket(pw); delete drc; } @@ -356,7 +355,7 @@ vector makeTypicalReferral() DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::A); pw.startRecord(DNSName("ds9a.nl"), QType::NS, 3600, 1, DNSResourceRecord::AUTHORITY); - DNSRecordContent* drc = DNSRecordContent::mastermake(QType::NS, 1, "ns1.ds9a.nl"); + auto drc = DNSRecordContent::mastermake(QType::NS, 1, "ns1.ds9a.nl"); drc->toPacket(pw); delete drc; diff --git a/pdns/test-dnsrecords_cc.cc b/pdns/test-dnsrecords_cc.cc index f9a23d5c9..fe445b241 100644 --- a/pdns/test-dnsrecords_cc.cc +++ b/pdns/test-dnsrecords_cc.cc @@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(test_record_types) { try { std::string recData; if (q.getCode() != QType::TSIG) { - boost::scoped_ptr rec(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); + auto rec = DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>()); BOOST_CHECK_MESSAGE(rec != NULL, "mastermake( " << q.getCode() << ", 1, " << val.get<1>() << ") returned NULL"); if (rec == NULL) continue; // now verify the record (note that this will be same as *zone* value (except for certain QTypes) @@ -268,10 +268,10 @@ BOOST_AUTO_TEST_CASE(test_record_types_bad_values) { if (val.get<2>()) { bool success=true; - BOOST_WARN_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); success=false; }, std::exception, test_dnsrecords_cc_predicate ); + BOOST_WARN_EXCEPTION( { std::shared_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); success=false; }, std::exception, test_dnsrecords_cc_predicate ); if (success==false) REC_FAIL_XSUCCESS2(q.getName() << " test #" << n << " has unexpectedly passed"); // a bad record was detected when it was supposed not to be detected } else { - BOOST_CHECK_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); }, std::exception, test_dnsrecords_cc_predicate ); + BOOST_CHECK_EXCEPTION( { std::shared_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); }, std::exception, test_dnsrecords_cc_predicate ); } }; } diff --git a/pdns/test-signers.cc b/pdns/test-signers.cc index 043b1ab70..1d5724bb4 100644 --- a/pdns/test-signers.cc +++ b/pdns/test-signers.cc @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(test_ed25519_signer) { reportBasicTypes(); - rrs.push_back(DNSRecordContent::makeunique(QType::MX, 1, "10 mail.example.com.")); + rrs.push_back(DNSRecordContent::mastermake(QType::MX, 1, "10 mail.example.com.")); RRSIGRecordContent rrc; rrc.d_originalttl = 3600; @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(test_ed448_signer) { reportBasicTypes(); - rrs.push_back(DNSRecordContent::makeunique(QType::MX, 1, "10 mail.example.com.")); + rrs.push_back(DNSRecordContent::mastermake(QType::MX, 1, "10 mail.example.com.")); RRSIGRecordContent rrc; rrc.d_originalttl = 3600; diff --git a/pdns/toysdig.cc b/pdns/toysdig.cc index eca198f87..685c6acd1 100644 --- a/pdns/toysdig.cc +++ b/pdns/toysdig.cc @@ -102,7 +102,7 @@ GlobalStateHolder g_luaconfs; LuaConfigItems::LuaConfigItems() { for (const auto &dsRecord : rootDSs) { - auto ds=unique_ptr(dynamic_cast(DSRecordContent::make(dsRecord))); + auto ds=std::dynamic_pointer_cast(DSRecordContent::make(dsRecord)); dsAnchors[DNSName(".")].insert(*ds); } } diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 2380206ce..24e776149 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -291,7 +291,7 @@ void AuthWebServer::indexfunction(HttpRequest* req, HttpResponse* resp) /** Helper to build a record content as needed. */ static inline string makeRecordContent(const QType& qtype, const string& content, bool noDot) { // noDot: for backend storage, pass true. for API users, pass false. - std::unique_ptr drc(DNSRecordContent::mastermake(qtype.getCode(), 1, content)); + auto drc = DNSRecordContent::mastermake(qtype.getCode(), QClass::IN, content); return drc->getZoneRepresentation(noDot); } -- 2.40.0