From: Pieter Lexis Date: Mon, 22 Mar 2021 18:32:10 +0000 (+0100) Subject: SVCB: centralize param lookup X-Git-Tag: dnsdist-1.6.0-rc1~33^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a563ced8fc620bbca516000149943712cd32af4a;p=thirdparty%2Fpdns.git SVCB: centralize param lookup --- diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 2a3560f3eb..1dd2586175 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -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 ¶m) { - 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 &addresses) { - auto p = std::find_if(d_params.begin(), d_params.end(), - [&key](const SvcParam ¶m) { - 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 ¶m) { - 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 ¶m) { - 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 ¶m) { - 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::const_iterator SVCBBaseRecordContent::getParamIt(const SvcParam::SvcParamKey &key) const { + auto p = std::find_if(d_params.begin(), d_params.end(), + [&key](const SvcParam ¶m) { + return param.getKey() == key; + }); + return p; +} + /* SVCB end */ boilerplate_conv(TKEY, diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index 03936e161a..f454244974 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -508,7 +508,7 @@ class SVCBBaseRecordContent : public DNSRecordContent void setHints(const SvcParam::SvcParamKey &key, const std::vector &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 d_params; + + // Get the iterator to parameter with |key|, return value can be d_params::end + set::const_iterator getParamIt(const SvcParam::SvcParamKey &key) const; }; class SVCBRecordContent : public SVCBBaseRecordContent