]> granicus.if.org Git - pdns/commitdiff
Make DNSRecordContent::mastermake() return a shared pointer
authorRemi Gacogne <remi.gacogne@powerdns.com>
Sun, 4 Jun 2017 16:48:21 +0000 (18:48 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 6 Jun 2017 07:55:10 +0000 (09:55 +0200)
We almost always wrapped it into one afterward, and had no good reason
not to anyway.

17 files changed:
modules/bindbackend/binddnssec.cc
modules/tinydnsbackend/tinydnsbackend.cc
pdns/dnsparser.cc
pdns/dnsparser.hh
pdns/lua-auth4.cc
pdns/lua-pdns.cc
pdns/lua-recursor4.cc
pdns/packethandler.cc
pdns/pdnsutil.cc
pdns/rec-lua-conf.cc
pdns/recursordist/test-negcache_cc.cc
pdns/recursordist/test-syncres_cc.cc
pdns/reczones.cc
pdns/speedtest.cc
pdns/syncres.cc
pdns/test-dnsrecords_cc.cc
pdns/ws-auth.cc

index fb125af2724059bae9ea6d2f291d61e68b95ae07..6f1981dd4aafdb50f0b4f0dafd09c506edd615ea 100644 (file)
@@ -168,9 +168,8 @@ bool Bind2Backend::getNSEC3PARAM(const DNSName& name, NSEC3PARAMRecordContent* n
 
   static int maxNSEC3Iterations=::arg().asNum("max-nsec3-iterations");
   if(ns3p) {
-    NSEC3PARAMRecordContent* tmp=dynamic_cast<NSEC3PARAMRecordContent*>(DNSRecordContent::mastermake(QType::NSEC3PARAM, 1, value));
+    std::shared_ptr<NSEC3PARAMRecordContent> tmp=std::dynamic_pointer_cast<NSEC3PARAMRecordContent>(DNSRecordContent::mastermake(QType::NSEC3PARAM, 1, value));
     *ns3p = *tmp;
-    delete tmp;
 
     if (ns3p->d_iterations > maxNSEC3Iterations) {
       ns3p->d_iterations = maxNSEC3Iterations;
index 8b3bed9f89e39d7abc104aca81fbf5be6e2e9f59..83b473d936f8ff909aca00a81390fd1829e09bfc 100644 (file)
@@ -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);
+        std::shared_ptr<DNSRecordContent> drc = DNSRecordContent::mastermake(dr, pr);
         rr.content = drc->getZoneRepresentation();
         DLOG(cerr<<"CONTENT: "<<rr.content<<endl);
-        delete drc;
       }
       catch (...) {
         if (d_ignorebogus) {
index 37493a0863f88c178c4564845024d9f48ad1100b..5b2faa8f63c054096cfcece4992b94cdecc61eb3 100644 (file)
@@ -121,28 +121,28 @@ shared_ptr<DNSRecordContent> DNSRecordContent::unserialize(const DNSName& qname,
   return ret;
 }
 
-DNSRecordContent* DNSRecordContent::mastermake(const DNSRecord &dr, 
+std::shared_ptr<DNSRecordContent> 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<UnknownRecordContent>(dr, pr);
   }
 
-  return i->second(dr, pr);
+  return std::shared_ptr<DNSRecordContent>(i->second(dr, pr));
 }
 
-DNSRecordContent* DNSRecordContent::mastermake(uint16_t qtype, uint16_t qclass,
+std::shared_ptr<DNSRecordContent> 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<UnknownRecordContent>(content);
   }
 
-  return i->second(content);
+  return std::shared_ptr<DNSRecordContent>(i->second(content));
 }
 
 std::unique_ptr<DNSRecordContent> DNSRecordContent::makeunique(uint16_t qtype, uint16_t qclass,
@@ -157,21 +157,21 @@ std::unique_ptr<DNSRecordContent> DNSRecordContent::makeunique(uint16_t qtype, u
 }
 
 
-DNSRecordContent* DNSRecordContent::mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t oc) {
+std::shared_ptr<DNSRecordContent> 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<UnknownRecordContent>(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<UnknownRecordContent>(dr, pr);
   }
 
-  return i->second(dr, pr);
+  return std::shared_ptr<DNSRecordContent>(i->second(dr, pr));
 }
 
 
@@ -207,7 +207,7 @@ DNSRecord::DNSRecord(const DNSResourceRecord& rr)
   d_class = rr.qclass;
   d_place = DNSResourceRecord::ANSWER;
   d_clen = 0;
-  d_content = std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(d_type, rr.qclass, rr.content));
+  d_content = DNSRecordContent::mastermake(d_type, rr.qclass, rr.content);
 }
 
 // If you call this and you are not parsing a packet coming from a socket, you are doing it wrong.
@@ -290,7 +290,7 @@ void MOADNSParser::init(bool query, const char *packet, unsigned int len)
       }
       else {
 //        cerr<<"parsing RR, query is "<<query<<", place is "<<dr.d_place<<", type is "<<dr.d_type<<", class is "<<dr.d_class<<endl;
-        dr.d_content=std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(dr, pr, d_header.opcode));
+        dr.d_content=DNSRecordContent::mastermake(dr, pr, d_header.opcode);
       }
 
       d_answers.push_back(make_pair(dr, pr.d_pos));
@@ -431,15 +431,12 @@ DNSName PacketReader::getName()
     d_pos+=consumed;
     return dn;
   }
-  catch(std::range_error& re)
-    {
-      throw std::out_of_range(string("dnsname issue: ")+re.what());
-    }
-
-  catch(...)
-    {
-      throw std::out_of_range("dnsname issue");
-    }
+  catch(const std::range_error& re) {
+    throw std::out_of_range(string("dnsname issue: ")+re.what());
+  }
+  catch(...) {
+    throw std::out_of_range("dnsname issue");
+  }
   throw PDNSException("PacketReader::getName(): name is empty");
 }
 
index 1f0ca6a5b925a4b92242316279d625ecd99e4a82..78a73f03bebc3b23b89d8fc7c72ab6f57e725232 100644 (file)
@@ -166,9 +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::shared_ptr<DNSRecordContent> mastermake(const DNSRecord &dr, PacketReader& pr);
+  static std::shared_ptr<DNSRecordContent> mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t opcode);
+  static std::shared_ptr<DNSRecordContent> mastermake(uint16_t qtype, uint16_t qclass, const string& zone);
   static std::unique_ptr<DNSRecordContent> makeunique(uint16_t qtype, uint16_t qclass, const string& content);
 
   virtual std::string getZoneRepresentation(bool noDot=false) const = 0;
index a14c12b3fbfd3d31a95dd251bee68b5910f32409..687da4bdd139cd28756c5caed2c2fa8797fb08d6 100644 (file)
@@ -142,7 +142,7 @@ AuthLua4::AuthLua4(const std::string& fname) {
     });
 
 
-  d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(dr.d_type, 1, newContent)); });
+  d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = DNSRecordContent::mastermake(dr.d_type, 1, newContent); });
 
   d_lw->writeFunction("pdnslog", [](const std::string& msg, boost::optional<int> loglevel) {
       theL() << (Logger::Urgency)loglevel.get_value_or(Logger::Warning) << msg<<endl;
index 59511d9a0630f4b8dc178d713013cae401a4421f..2d10551507dc7f47dd849314aba1b657b3fcfb2c 100644 (file)
@@ -255,7 +255,7 @@ void popResourceRecordsTable(lua_State *lua, const DNSName &query, vector<DNSRec
 
     string content;
     getFromTable(lua, "content", content);
-    rr.d_content=shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(rr.d_type, rr.d_class, content));
+    rr.d_content=DNSRecordContent::mastermake(rr.d_type, rr.d_class, content);
 
     if(!getFromTable(lua, "ttl", rr.d_ttl))
       rr.d_ttl=3600;
index e6ae516f42f6e1b2b3494d7dec0c757eb190f2d2..192eb2d18762926ec880fe0a0485357ae5644f48 100644 (file)
@@ -196,7 +196,7 @@ void RecursorLua4::DNSQuestion::addRecord(uint16_t type, const std::string& cont
   dr.d_ttl=ttl.get_value_or(3600);
   dr.d_type = type;
   dr.d_place = place;
-  dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(type, 1, content));
+  dr.d_content = DNSRecordContent::mastermake(type, 1, content);
   records.push_back(dr);
 }
 
@@ -372,7 +372,7 @@ RecursorLua4::RecursorLua4(const std::string& fname)
     },
     [](DNSFilterEngine::Policy& pol, const std::string& content) {
       // Only CNAMES for now, when we ever add a d_custom_type, there will be pain
-      pol.d_custom = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::CNAME, 1, content));
+      pol.d_custom = DNSRecordContent::mastermake(QType::CNAME, 1, content);
     }
   );
   d_lw->registerFunction("getDH", &DNSQuestion::getDH);
@@ -401,7 +401,7 @@ RecursorLua4::RecursorLua4(const std::string& fname)
     });
 
 
-  d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(dr.d_type, 1, newContent)); });
+  d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = DNSRecordContent::mastermake(dr.d_type, 1, newContent); });
   d_lw->registerFunction("addAnswer", &DNSQuestion::addAnswer);
   d_lw->registerFunction("addRecord", &DNSQuestion::addRecord);
   d_lw->registerFunction("getRecords", &DNSQuestion::getRecords);
index 3a9dc7a2510fa44ffcf76a1738296d2acf72bdff..cf083520f26b018df89b3299b3f9e6deb8a3d3c0 100644 (file)
@@ -265,7 +265,7 @@ int PacketHandler::doChaosRequest(DNSPacket *p, DNSPacket *r, DNSName &target)
       }
       else
         content=mode;
-      rr.dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::TXT, 1, "\""+content+"\""));
+      rr.dr.d_content = DNSRecordContent::mastermake(QType::TXT, 1, "\""+content+"\"");
     }
     else if (target==idserver) {
       // modes: disabled, hostname or custom
@@ -275,7 +275,7 @@ int PacketHandler::doChaosRequest(DNSPacket *p, DNSPacket *r, DNSName &target)
         r->setRcode(RCode::Refused);
         return 0;
       }
-      rr.dr.d_content=shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::TXT, 1, id));
+      rr.dr.d_content=DNSRecordContent::mastermake(QType::TXT, 1, id);
     }
     else {
       r->setRcode(RCode::Refused);
index 36214400605d5a25dcf58a4cf42a7849bbf884fa..4c57f763602491faf82c3b47faaca982fa66419c 100644 (file)
@@ -1,3 +1,4 @@
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -1465,23 +1466,23 @@ void verifyCrypto(const string& zone)
     if(rr.qtype.getCode() == QType::DNSKEY) {
       cerr<<"got DNSKEY!"<<endl;
       apex=rr.qname;
-      drc = *dynamic_cast<DNSKEYRecordContent*>(DNSRecordContent::mastermake(QType::DNSKEY, 1, rr.content));
+      drc = *std::dynamic_pointer_cast<DNSKEYRecordContent>(DNSRecordContent::mastermake(QType::DNSKEY, 1, rr.content));
     }
     else if(rr.qtype.getCode() == QType::RRSIG) {
       cerr<<"got RRSIG"<<endl;
-      rrc = *dynamic_cast<RRSIGRecordContent*>(DNSRecordContent::mastermake(QType::RRSIG, 1, rr.content));
+      rrc = *std::dynamic_pointer_cast<RRSIGRecordContent>(DNSRecordContent::mastermake(QType::RRSIG, 1, rr.content));
     }
     else if(rr.qtype.getCode() == QType::DS) {
       cerr<<"got DS"<<endl;
-      dsrc = *dynamic_cast<DSRecordContent*>(DNSRecordContent::mastermake(QType::DS, 1, rr.content));
+      dsrc = *std::dynamic_pointer_cast<DSRecordContent>(DNSRecordContent::mastermake(QType::DS, 1, rr.content));
     }
     else {
       qname = rr.qname;
-      toSign.push_back(shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, rr.content)));
+      toSign.push_back(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, rr.content));
     }
   }
   
-  string msg = getMessageForRRSET(qname, rrc, toSign);        
+  string msg = getMessageForRRSET(qname, rrc, toSign);
   cerr<<"Verify: "<<DNSCryptoKeyEngine::makeFromPublicKeyString(drc.d_algorithm, drc.d_key)->verify(msg, rrc.d_signature)<<endl;
   if(dsrc.d_digesttype) {
     cerr<<"Calculated DS: "<<apex.toString()<<" IN DS "<<makeDSFromDNSKey(apex, drc, dsrc.d_digesttype).getZoneRepresentation()<<endl;
index 6c5e7e171e5d16c290fec63e05547be2dfdcd3b2..9e0c8a469bc040dd5a117874aca8c19b83c7b1de 100644 (file)
@@ -62,11 +62,9 @@ static void parseRPZParameters(const std::unordered_map<string,boost::variant<ui
     defpol->d_name = std::make_shared<std::string>(polName);
     if(defpol->d_kind == DNSFilterEngine::PolicyKind::Custom) {
       defpol->d_custom=
-        shared_ptr<DNSRecordContent>(
           DNSRecordContent::mastermake(QType::CNAME, 1,
                                        boost::get<string>(constGet(have,"defcontent"))
-            )
-          );
+            );
 
       if(have.count("defttl"))
         defpol->d_ttl = static_cast<int32_t>(boost::get<uint32_t>(constGet(have, "defttl")));
index c0ee00e50679979478c92c2078a4b97dec732986..7340884700ce65f44f5d4704faab649a14ec144b 100644 (file)
@@ -14,7 +14,7 @@ static recordsAndSignatures genRecsAndSigs(const DNSName& name, const uint16_t q
   rec.d_type = qtype;
   rec.d_ttl = 600;
   rec.d_place = DNSResourceRecord::AUTHORITY;
-  rec.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(qtype, QClass::IN, content));
+  rec.d_content = DNSRecordContent::mastermake(qtype, QClass::IN, content);
 
   ret.records.push_back(rec);
 
index e2338783b243aa5367b5a648a351f4f2ada204d0..1f1bab402681f2d89505ab4a9737fa6d46b6bfd2 100644 (file)
@@ -195,7 +195,7 @@ static void addRecordToList(std::vector<DNSRecord>& records, const DNSName& name
     rec.d_content = std::make_shared<OPTRecordContent>();
   }
   else {
-    rec.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(type, QClass::IN, content));
+    rec.d_content = DNSRecordContent::mastermake(type, QClass::IN, content);
   }
 
   records.push_back(rec);
index 772decded2892066dcb2b94c1f6846f7bdfc2099..01e818d127815e9df62875e2613ffba1634494ff 100644 (file)
@@ -108,7 +108,7 @@ static void makeNameToIPZone(std::shared_ptr<SyncRes::domainmap_t> newMap, const
   dr.d_ttl=86400;
   dr.d_type=QType::SOA;
   dr.d_class = 1;
-  dr.d_content = std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::SOA, 1, "localhost. root 1 604800 86400 2419200 604800"));
+  dr.d_content = DNSRecordContent::mastermake(QType::SOA, 1, "localhost. root 1 604800 86400 2419200 604800");
   
   ad.d_records.insert(dr);
 
@@ -118,7 +118,7 @@ static void makeNameToIPZone(std::shared_ptr<SyncRes::domainmap_t> newMap, const
   ad.d_records.insert(dr);
   
   dr.d_type=QType::A;
-  dr.d_content= std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::A, 1, ip));
+  dr.d_content = DNSRecordContent::mastermake(QType::A, 1, ip);
   ad.d_records.insert(dr);
   
   if(newMap->count(dr.d_name)) {  
@@ -151,7 +151,7 @@ static void makeIPToNamesZone(std::shared_ptr<SyncRes::domainmap_t> newMap, cons
   dr.d_place=DNSResourceRecord::ANSWER;
   dr.d_ttl=86400;
   dr.d_type=QType::SOA;
-  dr.d_content=std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::SOA, 1, "localhost. root 1 604800 86400 2419200 604800"));
+  dr.d_content=DNSRecordContent::mastermake(QType::SOA, 1, "localhost. root 1 604800 86400 2419200 604800");
   
   ad.d_records.insert(dr);
 
@@ -163,7 +163,7 @@ static void makeIPToNamesZone(std::shared_ptr<SyncRes::domainmap_t> newMap, cons
 
   if(ipparts.size()==4)  // otherwise this is a partial zone
     for(unsigned int n=1; n < parts.size(); ++n) {
-      dr.d_content=std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::PTR, 1, DNSName(parts[n]).toString())); // XXX FIXME DNSNAME PAIN CAN THIS BE RIGHT?
+      dr.d_content=DNSRecordContent::mastermake(QType::PTR, 1, DNSName(parts[n]).toString()); // XXX FIXME DNSNAME PAIN CAN THIS BE RIGHT?
       ad.d_records.insert(dr);
     }
 
index d3a1fc15bd84b539cba55825aea9edc866f0d602..5c8e0677dadf83b8e51a52188e230ff4a8852a6e 100644 (file)
@@ -229,29 +229,25 @@ vector<uint8_t> makeBigReferral()
   for(char c='a'; c<= 'm';++c) {
     pw.startRecord(DNSName("com"), QType::NS, 3600, 1, DNSResourceRecord::AUTHORITY);
     gtld[0]=c;
-    DNSRecordContent* drc = DNSRecordContent::mastermake(QType::NS, 1, gtld);
+    std::unique_ptr<DNSRecordContent> drc = DNSRecordContent::makeunique(QType::NS, 1, gtld);
     drc->toPacket(pw);
-    delete drc;
   }
 
   for(char c='a'; c<= 'k';++c) {
     gtld[0]=c;
     pw.startRecord(DNSName(gtld), QType::A, 3600, 1, DNSResourceRecord::ADDITIONAL);
-    DNSRecordContent* drc = DNSRecordContent::mastermake(QType::A, 1, "1.2.3.4");
+    std::unique_ptr<DNSRecordContent> drc = DNSRecordContent::makeunique(QType::A, 1, "1.2.3.4");
     drc->toPacket(pw);
-    delete drc;
   }
 
 
   pw.startRecord(DNSName("a.gtld-servers.net"), QType::AAAA, 3600, 1, DNSResourceRecord::ADDITIONAL);
-  auto aaaarc = DNSRecordContent::mastermake(QType::AAAA, 1, "2001:503:a83e::2:30");
+  auto aaaarc = DNSRecordContent::makeunique(QType::AAAA, 1, "2001:503:a83e::2:30");
   aaaarc->toPacket(pw);
-  delete aaaarc;
 
   pw.startRecord(DNSName("b.gtld-servers.net"), QType::AAAA, 3600, 1, DNSResourceRecord::ADDITIONAL);
-  aaaarc = DNSRecordContent::mastermake(QType::AAAA, 1, "2001:503:231d::2:30");
+  aaaarc = DNSRecordContent::makeunique(QType::AAAA, 1, "2001:503:231d::2:30");
   aaaarc->toPacket(pw);
-  delete aaaarc;
 
 
   pw.commit();
@@ -297,9 +293,8 @@ vector<uint8_t> makeBigDNSPacketReferral()
   //  shuffle(records);
   for(const auto& rec : records) {
     pw.startRecord(rec.qname, rec.qtype.getCode(), rec.ttl, 1, DNSResourceRecord::ADDITIONAL);
-    auto drc = DNSRecordContent::mastermake(rec.qtype.getCode(), 1, rec.content);
+    auto drc = DNSRecordContent::makeunique(rec.qtype.getCode(), 1, rec.content);
     drc->toPacket(pw);
-    delete drc;
   }
 
   pw.commit();
@@ -317,9 +312,8 @@ struct MakeARecordTestMM
 
   void operator()() const
   {
-      DNSRecordContent*drc = DNSRecordContent::mastermake(QType::A, 1, 
-                                                          "1.2.3.4");
-      delete drc;
+      auto drc = DNSRecordContent::makeunique(QType::A, 1,
+                                              "1.2.3.4");
   }
 };
 
@@ -391,10 +385,9 @@ 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::makeunique(d_type, 1,
+                                              d_content);
       drc->toPacket(pw);
-      delete drc;
     }
     pw.commit();
   }
@@ -419,9 +412,8 @@ 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::makeunique(QType::AAAA, 1, "fe80::21d:92ff:fe6d:8441");
       drc->toPacket(pw);
-      delete drc;
     }
     pw.commit();
   }
@@ -444,9 +436,8 @@ 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::makeunique(QType::SOA, 1, "a0.org.afilias-nst.info. noc.afilias-nst.info. 2008758137 1800 900 604800 86400");
       drc->toPacket(pw);
-      delete drc;
     }
     pw.commit();
   }
@@ -466,25 +457,21 @@ vector<uint8_t> 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::makeunique(QType::NS, 1, "ns1.ds9a.nl");
   drc->toPacket(pw);
-  delete drc;
 
   pw.startRecord(DNSName("ds9a.nl"), QType::NS, 3600, 1, DNSResourceRecord::AUTHORITY);
-  drc = DNSRecordContent::mastermake(QType::NS, 1, "ns2.ds9a.nl");
+  drc = DNSRecordContent::makeunique(QType::NS, 1, "ns2.ds9a.nl");
   drc->toPacket(pw);
-  delete drc;
 
 
   pw.startRecord(DNSName("ns1.ds9a.nl"), QType::A, 3600, 1, DNSResourceRecord::ADDITIONAL);
-  drc = DNSRecordContent::mastermake(QType::A, 1, "1.2.3.4");
+  drc = DNSRecordContent::makeunique(QType::A, 1, "1.2.3.4");
   drc->toPacket(pw);
-  delete drc;
 
   pw.startRecord(DNSName("ns2.ds9a.nl"), QType::A, 3600, 1, DNSResourceRecord::ADDITIONAL);
-  drc = DNSRecordContent::mastermake(QType::A, 1, "4.3.2.1");
+  drc = DNSRecordContent::makeunique(QType::A, 1, "4.3.2.1");
   drc->toPacket(pw);
-  delete drc;
 
   pw.commit();
   return  packet;
index 4652fb1754f885f3032f6abd9e4728e85c42ebf2..206f4bfcda086c40b7de084151862f0aa30ed5c4 100644 (file)
@@ -190,7 +190,7 @@ bool SyncRes::doSpecialNamesResolve(const DNSName &qname, const QType &qtype, co
     dr.d_ttl = 86400;
     for (const auto& ans : answers) {
       dr.d_type = ans.first;
-      dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(ans.first, qclass, ans.second));
+      dr.d_content = DNSRecordContent::mastermake(ans.first, qclass, ans.second);
       ret.push_back(dr);
     }
   }
index 576c42d5d79b5a517dcdad6589c17f12b6896f82..bb68f90cf7fb75894163b295015d5bc473b73ba0 100644 (file)
@@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(test_record_types) {
    try {
       std::string recData;
       if (q.getCode() != QType::TSIG) {
-        boost::scoped_ptr<DNSRecordContent> 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<DNSRecordContent> 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( { auto 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<DNSRecordContent> 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( { auto 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 );
     }
   };
 }
index 2129964dc5919575f85445c094075391f396a984..5d3482fc1d7b3b448a776a3b6aa999b4d62a2d86 100644 (file)
@@ -287,7 +287,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<DNSRecordContent> drc(DNSRecordContent::mastermake(qtype.getCode(), 1, content));
+  std::unique_ptr<DNSRecordContent> drc(DNSRecordContent::makeunique(qtype.getCode(), QClass::IN, content));
   return drc->getZoneRepresentation(noDot);
 }