]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Refactor serialize/wireFormatContent as suggested by @rgacogne
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 25 Oct 2024 09:33:17 +0000 (11:33 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 16 Dec 2024 10:28:53 +0000 (11:28 +0100)
pdns/Makefile.am
pdns/dnsparser.hh
pdns/dnswriter.cc
pdns/dnswriter.hh
pdns/shuffle.cc

index dcdfada5491a3bae3439ad08a189a5489aee61a9..a5e9cbfe706c295a3586b4364e288556bb2d04b8 100644 (file)
@@ -949,8 +949,8 @@ speedtest_SOURCES = \
        nsecrecords.cc \
        qtype.cc \
        rcpgenerator.cc rcpgenerator.hh \
-       sillyrecords.cc \
        shuffle.cc shuffle.hh \
+       sillyrecords.cc \
        speedtest.cc \
        statbag.cc \
        svc-records.cc svc-records.hh \
index 5d9889e20df23d3fccae421dd4c637db22e9de44..bc818b9100c52e984f18511a7c06aa600afc1b50 100644 (file)
@@ -201,26 +201,8 @@ public:
   virtual std::string getZoneRepresentation(bool noDot=false) const = 0;
   virtual ~DNSRecordContent() = default;
   virtual void toPacket(DNSPacketWriter& pw) const = 0;
-  // returns the wire format of the content, possibly including compressed pointers pointing to the owner name (unless canonic or lowerCase are set)
-  string serialize(const DNSName& qname, bool canonic=false, bool lowerCase=false) const
-  {
-    vector<uint8_t> packet;
-    DNSPacketWriter pw(packet, g_rootdnsname, 1);
-    if(canonic)
-      pw.setCanonic(true);
-
-    if(lowerCase)
-      pw.setLowercase(true);
-
-    pw.startRecord(qname, this->getType());
-    this->toPacket(pw);
-
-    string record;
-    pw.getRecordPayload(record); // needs to be called before commit()
-    return record;
-  }
-
-  [[nodiscard]] string wireFormatContent(const DNSName& qname, bool canonic = false, bool lowerCase = false) const
+  // returns the wire format of the content or the full record, possibly including compressed pointers pointing to the owner name (unless canonic or lowerCase are set)
+  [[nodiscard]] string serialize(const DNSName& qname, bool canonic = false, bool lowerCase = false, bool full = false) const
   {
     vector<uint8_t> packet;
     DNSPacketWriter packetWriter(packet, g_rootdnsname, QType::A);
@@ -236,7 +218,11 @@ public:
     toPacket(packetWriter);
 
     string record;
-    packetWriter.getContentWireFormat(record); // needs to be called before commit()
+    if (full) {
+      packetWriter.getWireFormatContent(record); // needs to be called before commit()
+    } else {
+      packetWriter.getRecordPayload(record); // needs to be called before commit()
+    }
     return record;
   }
 
index 1cdc5776beb248d3a0f435b81aa7d51027593090..96a66a1a8bbe5034c55ecc84424cf9281b8451d7 100644 (file)
@@ -458,9 +458,9 @@ template <typename Container> void GenericDNSPacketWriter<Container>::getRecordP
 }
 
 // call __before commit__
-template <typename Container> void GenericDNSPacketWriter<Container>::getContentWireFormat(string& records)
+template <typename Container> void GenericDNSPacketWriter<Container>::getWireFormatContent(string& record)
 {
-  records.assign(d_content.begin() + d_rollbackmarker, d_content.end());
+  record.assign(d_content.begin() + d_rollbackmarker, d_content.end());
 }
 
 template <typename Container> uint32_t GenericDNSPacketWriter<Container>::size() const
index c6ed4b3f04fd4215c81fd9b3cbe7446a9c493f0e..adccd8365b6ee8f4c4f2758e25bd7450e64a29b1 100644 (file)
@@ -138,7 +138,7 @@ public:
 
   dnsheader* getHeader();
   void getRecordPayload(string& records); // call __before commit__
-  void getContentWireFormat(string& records); // call __before commit__
+  void getWireFormatContent(string& record); // call __before commit__
 
   void setCanonic(bool val)
   {
index fae7a4a493ddd98c97bcd376e7c00e58587e7819..c9987b5633424d0cf07b864f03855c1bf16ae401 100644 (file)
@@ -159,7 +159,7 @@ unsigned int pdns::dedupRecords(vector<DNSRecord>& rrs)
 
   seen.reserve(rrs.size());
   for (const auto& rec : rrs) {
-    auto key = rec.getContent()->wireFormatContent(rec.d_name, true, true);
+    auto key = rec.getContent()->serialize(rec.d_name, true, true, true);
     // This ignores class, ttl and place by using constants for those
     if (!seen.emplace(std::move(key)).second) {
       dups[counter] = true;