]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Some final UeberBackend cleanups
authorFred Morcos <fred.morcos@open-xchange.com>
Sun, 29 Oct 2023 14:35:04 +0000 (15:35 +0100)
committerFred Morcos <fred.morcos@open-xchange.com>
Mon, 30 Oct 2023 11:52:42 +0000 (12:52 +0100)
pdns/ueberbackend.cc
pdns/ueberbackend.hh

index e1e5a013311e0df61b915bfb695eea14ab93957b..4b7d84c30b2dbd29fccfdde4cfb5cd8876135a8d 100644 (file)
@@ -288,8 +288,8 @@ void UeberBackend::updateZoneCache()
   for (auto& backend : backends) {
     vector<DomainInfo> zones;
     backend->getAllDomains(&zones, false, true);
-    for (auto& di : zones) {
-      zone_indices.emplace_back(std::move(di.zone), (int)di.id); // this cast should not be necessary
+    for (auto& domainInfo : zones) {
+      zone_indices.emplace_back(std::move(domainInfo.zone), (int)domainInfo.id); // this cast should not be necessary
     }
   }
   g_zoneCache.replace(zone_indices);
@@ -297,11 +297,11 @@ void UeberBackend::updateZoneCache()
 
 void UeberBackend::rediscover(string* status)
 {
-  for (auto i = backends.begin(); i != backends.end(); ++i) {
+  for (auto backend = backends.begin(); backend != backends.end(); ++backend) {
     string tmpstr;
-    (*i)->rediscover(&tmpstr);
+    (*backend)->rediscover(&tmpstr);
     if (status != nullptr) {
-      *status += tmpstr + (i != backends.begin() ? "\n" : "");
+      *status += tmpstr + (backend != backends.begin() ? "\n" : "");
     }
   }
 
@@ -607,18 +607,17 @@ bool UeberBackend::autoPrimariesList(std::vector<AutoPrimary>& primaries)
   return false;
 }
 
-bool UeberBackend::superMasterBackend(const string& ip, const DNSName& domain, const vector<DNSResourceRecord>& nsset, string* nameserver, string* account, DNSBackend** db)
+bool UeberBackend::superMasterBackend(const string& ip, const DNSName& domain, const vector<DNSResourceRecord>& nsset, string* nameserver, string* account, DNSBackend** dnsBackend)
 {
   for (auto* backend : backends) {
-    if (backend->superMasterBackend(ip, domain, nsset, nameserver, account, db)) {
+    if (backend->superMasterBackend(ip, domain, nsset, nameserver, account, dnsBackend)) {
       return true;
     }
   }
   return false;
 }
 
-UeberBackend::UeberBackend(const string& pname) :
-  d_negcached(false), d_cached(false)
+UeberBackend::UeberBackend(const string& pname)
 {
   {
     d_instances.lock()->push_back(this); // report to the static list of ourself
@@ -626,15 +625,13 @@ UeberBackend::UeberBackend(const string& pname) :
 
   d_cache_ttl = ::arg().asNum("query-cache-ttl");
   d_negcache_ttl = ::arg().asNum("negquery-cache-ttl");
-  d_qtype = 0;
-  d_stale = false;
 
   backends = BackendMakers().all(pname == "key-only");
 }
 
-static void del(DNSBackend* d)
+static void del(DNSBackend* backend)
 {
-  delete d;
+  delete backend;
 }
 
 void UeberBackend::cleanup()
@@ -671,17 +668,17 @@ enum UeberBackend::CacheResult UeberBackend::cacheHas(const Question& question,
   return CacheResult::Hit;
 }
 
-void UeberBackend::addNegCache(const Question& q) const
+void UeberBackend::addNegCache(const Question& question) const
 {
   extern AuthQueryCache QC;
   if (d_negcache_ttl == 0) {
     return;
   }
   // we should also not be storing negative answers if a pipebackend does scopeMask, but we can't pass a negative scopeMask in an empty set!
-  QC.insert(q.qname, q.qtype, vector<DNSZoneRecord>(), d_negcache_ttl, q.zoneId);
+  QC.insert(question.qname, question.qtype, vector<DNSZoneRecord>(), d_negcache_ttl, question.zoneId);
 }
 
-void UeberBackend::addCache(const Question& q, vector<DNSZoneRecord>&& rrs) const
+void UeberBackend::addCache(const Question& question, vector<DNSZoneRecord>&& rrs) const
 {
   extern AuthQueryCache QC;
 
@@ -689,13 +686,13 @@ void UeberBackend::addCache(const Question& q, vector<DNSZoneRecord>&& rrs) cons
     return;
   }
 
-  for (const auto& rr : rrs) {
-    if (rr.scopeMask) {
+  for (const auto& resourceRecord : rrs) {
+    if (resourceRecord.scopeMask != 0) {
       return;
     }
   }
 
-  QC.insert(q.qname, q.qtype, std::move(rrs), d_cache_ttl, q.zoneId);
+  QC.insert(question.qname, question.qtype, std::move(rrs), d_cache_ttl, question.zoneId);
 }
 
 void UeberBackend::alsoNotifies(const DNSName& domain, set<string>* ips)
@@ -776,7 +773,7 @@ void UeberBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, bo
   }
 }
 
-bool UeberBackend::get(DNSZoneRecord& rr)
+bool UeberBackend::get(DNSZoneRecord& resourceRecord)
 {
   // cout<<"UeberBackend::get(DNSZoneRecord) called"<<endl;
   if (d_negcached) {
@@ -785,18 +782,18 @@ bool UeberBackend::get(DNSZoneRecord& rr)
 
   if (d_cached) {
     while (d_cachehandleiter != d_answers.end()) {
-      rr = *d_cachehandleiter++;
-      if ((d_qtype == QType::ANY || rr.dr.d_type == d_qtype)) {
+      resourceRecord = *d_cachehandleiter++;
+      if ((d_qtype == QType::ANY || resourceRecord.dr.d_type == d_qtype)) {
         return true;
       }
     }
     return false;
   }
 
-  while (d_handle.get(rr)) {
-    rr.dr.d_place = DNSResourceRecord::ANSWER;
-    d_answers.push_back(rr);
-    if ((d_qtype == QType::ANY || rr.dr.d_type == d_qtype)) {
+  while (d_handle.get(resourceRecord)) {
+    resourceRecord.dr.d_place = DNSResourceRecord::ANSWER;
+    d_answers.push_back(resourceRecord);
+    if ((d_qtype == QType::ANY || resourceRecord.dr.d_type == d_qtype)) {
       return true;
     }
   }
@@ -865,24 +862,24 @@ bool UeberBackend::deleteTSIGKey(const DNSName& name)
 //
 bool UeberBackend::searchRecords(const string& pattern, int maxResults, vector<DNSResourceRecord>& result)
 {
-  bool rc = false;
+  bool ret = false;
   for (auto i = backends.begin(); result.size() < static_cast<vector<DNSResourceRecord>::size_type>(maxResults) && i != backends.end(); ++i) {
     if ((*i)->searchRecords(pattern, maxResults - result.size(), result)) {
-      rc = true;
+      ret = true;
     }
   }
-  return rc;
+  return ret;
 }
 
 bool UeberBackend::searchComments(const string& pattern, int maxResults, vector<Comment>& result)
 {
-  bool rc = false;
+  bool ret = false;
   for (auto i = backends.begin(); result.size() < static_cast<vector<Comment>::size_type>(maxResults) && i != backends.end(); ++i) {
     if ((*i)->searchComments(pattern, maxResults - result.size(), result)) {
-      rc = true;
+      ret = true;
     }
   }
-  return rc;
+  return ret;
 }
 
 AtomicCounter UeberBackend::handle::instances(0);
@@ -891,11 +888,6 @@ UeberBackend::handle::handle()
 {
   //  g_log<<Logger::Warning<<"Handle instances: "<<instances<<endl;
   ++instances;
-  parent = nullptr;
-  d_hinterBackend = nullptr;
-  pkt_p = nullptr;
-  i = 0;
-  zoneId = -1;
 }
 
 UeberBackend::handle::~handle()
@@ -903,11 +895,11 @@ UeberBackend::handle::~handle()
   --instances;
 }
 
-bool UeberBackend::handle::get(DNSZoneRecord& r)
+bool UeberBackend::handle::get(DNSZoneRecord& record)
 {
   DLOG(g_log << "Ueber get() was called for a " << qtype << " record" << endl);
   bool isMore = false;
-  while (d_hinterBackend && !(isMore = d_hinterBackend->get(r))) { // this backend out of answers
+  while (d_hinterBackend != nullptr && !(isMore = d_hinterBackend->get(record))) { // this backend out of answers
     if (i < parent->backends.size()) {
       DLOG(g_log << "Backend #" << i << " of " << parent->backends.size()
                  << " out of answers, taking next" << endl);
index 7aaeb78f6e36c9e0692daa56b586eb19d676b3f3..ada36f129b3fb6d5942438881078239c65006855 100644 (file)
@@ -47,7 +47,7 @@ public:
   UeberBackend(const string& pname = "default");
   ~UeberBackend();
 
-  bool superMasterBackend(const string& ip, const DNSName& domain, const vector<DNSResourceRecord>& nsset, string* nameserver, string* account, DNSBackend** db);
+  bool superMasterBackend(const string& ip, const DNSName& domain, const vector<DNSResourceRecord>& nsset, string* nameserver, string* account, DNSBackend** dnsBackend);
 
   bool superMasterAdd(const AutoPrimary& primary);
   bool autoPrimaryRemove(const struct AutoPrimary& primary);
@@ -61,7 +61,7 @@ public:
   static bool loadmodule(const string& name);
   static bool loadModules(const vector<string>& modules, const string& path);
 
-  static void go(void);
+  static void go();
 
   /** This contains all registered backends. The DynListener modifies this list for us when
       new modules are loaded */
@@ -73,23 +73,23 @@ public:
   class handle
   {
   public:
-    bool get(DNSZoneRecord& dr);
+    bool get(DNSZoneRecord& record);
     handle();
     ~handle();
 
     //! The UeberBackend class where this handle belongs to
-    UeberBackend* parent;
+    UeberBackend* parent{nullptr};
     //! The current real backend, which is answering questions
-    DNSBackend* d_hinterBackend;
+    DNSBackend* d_hinterBackend{nullptr};
 
     //! DNSPacket who asked this question
-    DNSPacket* pkt_p;
+    DNSPacket* pkt_p{nullptr};
     DNSName qname;
 
     //! Index of the current backend within the backends vector
-    unsigned int i;
+    unsigned int i{0};
     QType qtype;
-    int zoneId;
+    int zoneId{-1};
 
   private:
     static AtomicCounter instances;
@@ -101,7 +101,7 @@ public:
   bool getAuth(const DNSName& target, const QType& qtype, SOAData* soaData, bool cachedOk = true);
   /** Load SOA info from backends, ignoring the cache.*/
   bool getSOAUncached(const DNSName& domain, SOAData& soaData);
-  bool get(DNSZoneRecord& r);
+  bool get(DNSZoneRecord& resourceRecord);
   void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled);
 
   void getUnfreshSlaveInfos(vector<DomainInfo>* domains);
@@ -110,7 +110,7 @@ public:
   bool createDomain(const DNSName& domain, DomainInfo::DomainKind kind, const vector<ComboAddress>& masters, const string& account);
 
   bool doesDNSSEC();
-  bool addDomainKey(const DNSName& name, const DNSBackend::KeyData& key, int64_t& id);
+  bool addDomainKey(const DNSName& name, const DNSBackend::KeyData& key, int64_t& keyID);
   bool getDomainKeys(const DNSName& name, std::vector<DNSBackend::KeyData>& keys);
   bool getAllDomainMetadata(const DNSName& name, std::map<std::string, std::vector<std::string>>& meta);
   bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta);
@@ -118,14 +118,14 @@ public:
   bool setDomainMetadata(const DNSName& name, const std::string& kind, const std::vector<std::string>& meta);
   bool setDomainMetadata(const DNSName& name, const std::string& kind, const std::string& meta);
 
-  bool removeDomainKey(const DNSName& name, unsigned int id);
-  bool activateDomainKey(const DNSName& name, unsigned int id);
-  bool deactivateDomainKey(const DNSName& name, unsigned int id);
-  bool publishDomainKey(const DNSName& name, unsigned int id);
-  bool unpublishDomainKey(const DNSName& name, unsigned int id);
+  bool removeDomainKey(const DNSName& name, unsigned int keyID);
+  bool activateDomainKey(const DNSName& name, unsigned int keyID);
+  bool deactivateDomainKey(const DNSName& name, unsigned int keyID);
+  bool publishDomainKey(const DNSName& name, unsigned int keyID);
+  bool unpublishDomainKey(const DNSName& name, unsigned int keyID);
 
   void alsoNotifies(const DNSName& domain, set<string>* ips);
-  void rediscover(string* status = 0);
+  void rediscover(string* status = nullptr);
   void reload();
 
   bool setTSIGKey(const DNSName& name, const DNSName& algorithm, const string& content);
@@ -156,13 +156,13 @@ private:
   } d_question;
 
   unsigned int d_cache_ttl, d_negcache_ttl;
-  uint16_t d_qtype;
+  uint16_t d_qtype{0};
 
-  bool d_negcached;
-  bool d_cached;
+  bool d_negcached{false};
+  bool d_cached{false};
   static AtomicCounter* s_backendQueries;
   static bool d_go;
-  bool d_stale;
+  bool d_stale{false};
   static bool s_doANYLookupsOnly;
 
   enum CacheResult
@@ -173,8 +173,8 @@ private:
   };
 
   CacheResult cacheHas(const Question& question, vector<DNSZoneRecord>& resourceRecords) const;
-  void addNegCache(const Question& q) const;
-  void addCache(const Question& q, vector<DNSZoneRecord>&& rrs) const;
+  void addNegCache(const Question& question) const;
+  void addCache(const Question& question, vector<DNSZoneRecord>&& rrs) const;
 
   bool fillSOAFromZoneRecord(DNSName& shorter, int zoneId, SOAData* soaData);
   CacheResult fillSOAFromCache(SOAData* soaData, DNSName& shorter);