]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Cleanup DNSResourceRecord 13618/head
authorFred Morcos <fred.morcos@open-xchange.com>
Wed, 13 Dec 2023 13:56:53 +0000 (14:56 +0100)
committerFred Morcos <fred.morcos@open-xchange.com>
Wed, 13 Dec 2023 14:18:00 +0000 (15:18 +0100)
pdns/dns.hh
pdns/dnsparser.cc

index 4f68df7b5c8b65ed8f44490aa19c58659e775a33..c95a62f1c52fdd49e9fc1c7b8b79e7f1bb7870f3 100644 (file)
@@ -56,9 +56,7 @@ public:
 class DNSResourceRecord
 {
 public:
-  DNSResourceRecord() :
-    last_modified(0), ttl(0), signttl(0), domain_id(-1), qclass(1), scopeMask(0), auth(1), disabled(0){};
-  static DNSResourceRecord fromWire(const DNSRecord& d);
+  static DNSResourceRecord fromWire(const DNSRecord& wire);
 
   enum Place : uint8_t
   {
@@ -69,7 +67,7 @@ public:
   }; //!< Type describing the positioning within, say, a DNSPacket
 
   void setContent(const string& content);
-  string getZoneRepresentation(bool noDot = false) const;
+  [[nodiscard]] string getZoneRepresentation(bool noDot = false) const;
 
   // data
   DNSName qname; //!< the name of this record, for example: www.powerdns.com
@@ -79,27 +77,29 @@ public:
 
   // Aligned on 8-byte boundaries on systems where time_t is 8 bytes and int
   // is 4 bytes, aka modern linux on x86_64
-  time_t last_modified; //!< For autocalculating SOA serial numbers - the backend needs to fill this in
+  time_t last_modified{}; //!< For autocalculating SOA serial numbers - the backend needs to fill this in
 
-  uint32_t ttl; //!< Time To Live of this record
-  uint32_t signttl; //!< If non-zero, use this TTL as original TTL in the RRSIG
+  uint32_t ttl{}; //!< Time To Live of this record
+  uint32_t signttl{}; //!< If non-zero, use this TTL as original TTL in the RRSIG
 
-  int domain_id; //!< If a backend implements this, the domain_id of the zone this record is in
+  int domain_id{-1}; //!< If a backend implements this, the domain_id of the zone this record is in
   QType qtype; //!< qtype of this record, ie A, CNAME, MX etc
-  uint16_t qclass; //!< class of this record
+  uint16_t qclass{1}; //!< class of this record
 
-  uint8_t scopeMask;
-  bool auth;
-  bool disabled;
+  uint8_t scopeMask{};
+  bool auth{true};
+  bool disabled{};
 
   bool operator==(const DNSResourceRecord& rhs);
 
-  bool operator<(const DNSResourceRecord& b) const
+  bool operator<(const DNSResourceRecord& other) const
   {
-    if (qname < b.qname)
+    if (qname < other.qname) {
       return true;
-    if (qname == b.qname)
-      return (content < b.content);
+    }
+    if (qname == other.qname) {
+      return (content < other.content);
+    }
     return false;
   }
 };
index ea1e6e8bfa7cec87195fc429484021ddd05f8b03..5a17fc36cb929b85bcfb12401a1891ba57704521 100644 (file)
@@ -212,15 +212,16 @@ DNSRecord::DNSRecord(const DNSResourceRecord& rr): d_name(rr.qname)
 }
 
 // If you call this and you are not parsing a packet coming from a socket, you are doing it wrong.
-DNSResourceRecord DNSResourceRecord::fromWire(const DNSRecord& d) {
-  DNSResourceRecord rr;
-  rr.qname = d.d_name;
-  rr.qtype = QType(d.d_type);
-  rr.ttl = d.d_ttl;
-  rr.content = d.getContent()->getZoneRepresentation(true);
-  rr.auth = false;
-  rr.qclass = d.d_class;
-  return rr;
+DNSResourceRecord DNSResourceRecord::fromWire(const DNSRecord& wire)
+{
+  DNSResourceRecord resourceRecord;
+  resourceRecord.qname = wire.d_name;
+  resourceRecord.qtype = QType(wire.d_type);
+  resourceRecord.ttl = wire.d_ttl;
+  resourceRecord.content = wire.getContent()->getZoneRepresentation(true);
+  resourceRecord.auth = false;
+  resourceRecord.qclass = wire.d_class;
+  return resourceRecord;
 }
 
 void MOADNSParser::init(bool query, const std::string_view& packet)