]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
SVCB: centralize param lookup
authorPieter Lexis <pieter.lexis@powerdns.com>
Mon, 22 Mar 2021 18:32:10 +0000 (19:32 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Mon, 29 Mar 2021 17:10:32 +0000 (19:10 +0200)
pdns/dnsrecords.cc
pdns/dnsrecords.hh

index 2a3560f3eb6f078df418e53de1ca4bdfab06f2f7..1dd2586175ab5e70752bebe169674f8d631cc0f4 100644 (file)
@@ -718,10 +718,7 @@ string APLRecordContent::getZoneRepresentation(bool noDot) const {
 
 /* SVCB start */
 bool SVCBBaseRecordContent::autoHint(const SvcParam::SvcParamKey &key) const {
-  auto p = std::find_if(d_params.begin(), d_params.end(),
-      [&key](const SvcParam &param) {
-        return param.getKey() == key;
-      });
+  auto p = getParamIt(key);
   if (p == d_params.end()) {
     return false;
   }
@@ -729,10 +726,7 @@ bool SVCBBaseRecordContent::autoHint(const SvcParam::SvcParamKey &key) const {
 }
 
 void SVCBBaseRecordContent::setHints(const SvcParam::SvcParamKey &key, const std::vector<ComboAddress> &addresses) {
-  auto p = std::find_if(d_params.begin(), d_params.end(),
-      [&key](const SvcParam &param) {
-        return param.getKey() == key;
-      });
+  auto p = getParamIt(key);
   if (p == d_params.end()) {
     return;
   }
@@ -750,10 +744,7 @@ void SVCBBaseRecordContent::setHints(const SvcParam::SvcParamKey &key, const std
 }
 
 void SVCBBaseRecordContent::removeParam(const SvcParam::SvcParamKey &key) {
-  auto p = std::find_if(d_params.begin(), d_params.end(),
-      [&key](const SvcParam &param) {
-        return param.getKey() == key;
-      });
+  auto p = getParamIt(key);
   if (p == d_params.end()) {
     return;
   }
@@ -765,24 +756,25 @@ bool SVCBBaseRecordContent::hasParams() const {
 }
 
 bool SVCBBaseRecordContent::hasParam(const SvcParam::SvcParamKey &key) const {
-  auto p = std::find_if(d_params.begin(), d_params.end(),
-      [&key](const SvcParam &param) {
-        return param.getKey() == key;
-      });
-  return p != d_params.end();
+  return getParamIt(key) != d_params.end();
 }
 
 SvcParam SVCBBaseRecordContent::getParam(const SvcParam::SvcParamKey &key) const {
-  auto p = std::find_if(d_params.begin(), d_params.end(),
-      [&key](const SvcParam &param) {
-        return param.getKey() == key;
-      });
+  auto p = getParamIt(key);
   if (p == d_params.end()) {
     throw std::out_of_range("No param with key " + SvcParam::keyToString(key));
   }
   return *p;
 }
 
+set<SvcParam>::const_iterator SVCBBaseRecordContent::getParamIt(const SvcParam::SvcParamKey &key) const {
+  auto p = std::find_if(d_params.begin(), d_params.end(),
+      [&key](const SvcParam &param) {
+        return param.getKey() == key;
+      });
+  return p;
+}
+
 /* SVCB end */
 
 boilerplate_conv(TKEY,
index 03936e161a9cbdc5bedb1c608c27462561a07a21..f454244974d1a1e8292070cc9d6f994c0e35e761 100644 (file)
@@ -508,7 +508,7 @@ class SVCBBaseRecordContent : public DNSRecordContent
     void setHints(const SvcParam::SvcParamKey &key, const std::vector<ComboAddress> &addresses);
     // Removes the parameter for |key| from d_params
     void removeParam(const SvcParam::SvcParamKey &key);
-    // Whether or not there are any param
+    // Whether or not there are any parameter
     bool hasParams() const;
     // Whether or not the param of |key| exists
     bool hasParam(const SvcParam::SvcParamKey &key) const;
@@ -519,6 +519,9 @@ class SVCBBaseRecordContent : public DNSRecordContent
     uint16_t d_priority;
     DNSName d_target;
     set<SvcParam> d_params;
+
+    // Get the iterator to parameter with |key|, return value can be d_params::end
+    set<SvcParam>::const_iterator getParamIt(const SvcParam::SvcParamKey &key) const;
 };
 
 class SVCBRecordContent : public SVCBBaseRecordContent