From: Peter van Dijk Date: Thu, 28 Nov 2019 14:30:33 +0000 (+0100) Subject: dnsseckeeper: add getFromMetaOrDefault X-Git-Tag: auth-4.3.0-beta1~10^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fb19458665902997d293d76422c6976a0fc06c6;p=thirdparty%2Fpdns.git dnsseckeeper: add getFromMetaOrDefault --- diff --git a/pdns/dbdnsseckeeper.cc b/pdns/dbdnsseckeeper.cc index 1e9eb07d80..1324240cbb 100644 --- a/pdns/dbdnsseckeeper.cc +++ b/pdns/dbdnsseckeeper.cc @@ -191,10 +191,18 @@ bool DNSSECKeeper::activateKey(const DNSName& zname, unsigned int id) return d_keymetadb->activateDomainKey(zname, id); } +void DNSSECKeeper::getFromMetaOrDefault(const DNSName& zname, const std::string& key, std::string& value, const std::string& defaultvalue) +{ + if (getFromMeta(zname, key, value)) + return; + else + value = defaultvalue; +} -void DNSSECKeeper::getFromMeta(const DNSName& zname, const std::string& key, std::string& value) +bool DNSSECKeeper::getFromMeta(const DNSName& zname, const std::string& key, std::string& value) { static int ttl = ::arg().asNum("domain-metadata-cache-ttl"); + bool isset = false; value.clear(); unsigned int now = time(0); @@ -208,13 +216,15 @@ void DNSSECKeeper::getFromMeta(const DNSName& zname, const std::string& key, std metacache_t::const_iterator iter = s_metacache.find(tie(zname, key)); if(iter != s_metacache.end() && iter->d_ttd > now) { value = iter->d_value; - return; + return iter->d_isset; } } vector meta; d_keymetadb->getDomainMetadata(zname, key, meta); - if(!meta.empty()) + if(!meta.empty()) { value=*meta.begin(); + isset = true; + } if (ttl > 0) { METACacheEntry nce; @@ -222,11 +232,13 @@ void DNSSECKeeper::getFromMeta(const DNSName& zname, const std::string& key, std nce.d_ttd = now + ttl; nce.d_key= key; nce.d_value = value; + nce.d_isset = isset; { WriteLock l(&s_metacachelock); lruReplacingInsert(s_metacache, nce); } } + return isset; } void DNSSECKeeper::getSoaEdit(const DNSName& zname, std::string& value) diff --git a/pdns/dnsseckeeper.hh b/pdns/dnsseckeeper.hh index f280f4de98..848f5bcbdb 100644 --- a/pdns/dnsseckeeper.hh +++ b/pdns/dnsseckeeper.hh @@ -222,7 +222,8 @@ public: (*d_keymetadb->backends.begin())->commitTransaction(); } - void getFromMeta(const DNSName& zname, const std::string& key, std::string& value); + void getFromMetaOrDefault(const DNSName& zname, const std::string& key, std::string& value, const std::string& defaultvalue); + bool getFromMeta(const DNSName& zname, const std::string& key, std::string& value); void getSoaEdit(const DNSName& zname, std::string& value); bool unSecureZone(const DNSName& zone, std::string& error, std::string& info); bool rectifyZone(const DNSName& zone, std::string& error, std::string& info, bool doTransaction); @@ -252,6 +253,7 @@ private: DNSName d_domain; mutable std::string d_key, d_value; + mutable bool d_isset; unsigned int d_ttd; };