From: Michal 'vorner' Vaner Date: Mon, 12 Dec 2011 12:20:32 +0000 (+0100) Subject: [1483] Port the rest to new interface X-Git-Tag: perftcpdns_before_epoll~5^2~7^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=90c77658e79a21c3a60da992f22eb2f2660db667;p=thirdparty%2Fkea.git [1483] Port the rest to new interface --- diff --git a/src/bin/auth/query.cc b/src/bin/auth/query.cc index f1592620ae..ef7653fb7e 100644 --- a/src/bin/auth/query.cc +++ b/src/bin/auth/query.cc @@ -15,6 +15,8 @@ #include // for std::max #include #include +#include +#include #include #include @@ -67,7 +69,7 @@ Query::addAdditionalAddrs(ZoneFinder& zone, const Name& qname, // Find A rrset if (qname_ != qname || qtype_ != RRType::A()) { - ZoneFinder::FindResult a_result = zone.find(qname, RRType::A(), NULL, + ZoneFinder::FindResult a_result = zone.find(qname, RRType::A(), options | dnssec_opt_); if (a_result.code == ZoneFinder::SUCCESS) { response_.addRRset(Message::SECTION_ADDITIONAL, @@ -78,7 +80,7 @@ Query::addAdditionalAddrs(ZoneFinder& zone, const Name& qname, // Find AAAA rrset if (qname_ != qname || qtype_ != RRType::AAAA()) { ZoneFinder::FindResult aaaa_result = - zone.find(qname, RRType::AAAA(), NULL, options | dnssec_opt_); + zone.find(qname, RRType::AAAA(), options | dnssec_opt_); if (aaaa_result.code == ZoneFinder::SUCCESS) { response_.addRRset(Message::SECTION_ADDITIONAL, boost::const_pointer_cast(aaaa_result.rrset), @@ -90,7 +92,7 @@ Query::addAdditionalAddrs(ZoneFinder& zone, const Name& qname, void Query::addSOA(ZoneFinder& finder) { ZoneFinder::FindResult soa_result(finder.find(finder.getOrigin(), - RRType::SOA(), NULL, dnssec_opt_)); + RRType::SOA(), dnssec_opt_)); if (soa_result.code != ZoneFinder::SUCCESS) { isc_throw(NoSOA, "There's no SOA record in zone " << finder.getOrigin().toText()); @@ -146,7 +148,7 @@ Query::addNXDOMAINProof(ZoneFinder& finder, ConstRRsetPtr nsec) { // otherwise we shouldn't have got NXDOMAIN for the original query in // the first place). const ZoneFinder::FindResult fresult = finder.find(wildname, - RRType::NSEC(), NULL, + RRType::NSEC(), dnssec_opt_); if (fresult.code != ZoneFinder::NXDOMAIN || !fresult.rrset || fresult.rrset->getRdataCount() == 0) { @@ -171,7 +173,7 @@ Query::addWildcardProof(ZoneFinder& finder) { // substitution. Confirm that by specifying NO_WILDCARD. It should result // in NXDOMAIN and an NSEC RR that proves it should be returned. const ZoneFinder::FindResult fresult = - finder.find(qname_, RRType::NSEC(), NULL, + finder.find(qname_, RRType::NSEC(), dnssec_opt_ | ZoneFinder::NO_WILDCARD); if (fresult.code != ZoneFinder::NXDOMAIN || !fresult.rrset || fresult.rrset->getRdataCount() == 0) { @@ -194,7 +196,7 @@ Query::addWildcardNXRRSETProof(ZoneFinder& finder, ConstRRsetPtr nsec) { boost::const_pointer_cast(nsec), dnssec_); const ZoneFinder::FindResult fresult = - finder.find(qname_, RRType::NSEC(), NULL, + finder.find(qname_, RRType::NSEC(), dnssec_opt_ | ZoneFinder::NO_WILDCARD); if (fresult.code != ZoneFinder::NXDOMAIN || !fresult.rrset || fresult.rrset->getRdataCount() == 0) { @@ -213,8 +215,7 @@ void Query::addAuthAdditional(ZoneFinder& finder) { // Fill in authority and addtional sections. ZoneFinder::FindResult ns_result = finder.find(finder.getOrigin(), - RRType::NS(), NULL, - dnssec_opt_); + RRType::NS(), dnssec_opt_); // zone origin name should have NS records if (ns_result.code != ZoneFinder::SUCCESS) { isc_throw(NoApexNS, "There's no apex NS records in zone " << @@ -253,9 +254,16 @@ Query::process() { response_.setRcode(Rcode::NOERROR()); while (keep_doing) { keep_doing = false; - std::auto_ptr target(qtype_is_any ? new RRsetList : NULL); - const ZoneFinder::FindResult db_result( - zfinder.find(qname_, qtype_, target.get(), dnssec_opt_)); + std::vector target; + boost::function0 find; + if (qtype_is_any) { + find = boost::bind(&ZoneFinder::findAll, &zfinder, qname_, + boost::ref(target), dnssec_opt_); + } else { + find = boost::bind(&ZoneFinder::find, &zfinder, qname_, qtype_, + dnssec_opt_); + } + ZoneFinder::FindResult db_result(find()); switch (db_result.code) { case ZoneFinder::DNAME: { // First, put the dname into the answer @@ -326,9 +334,9 @@ Query::process() { if (qtype_is_any) { // If quety type is ANY, insert all RRs under the domain // into answer section. - BOOST_FOREACH(RRsetPtr rrset, *target) { - response_.addRRset(Message::SECTION_ANSWER, rrset, - dnssec_); + BOOST_FOREACH(ConstRRsetPtr rrset, target) { + response_.addRRset(Message::SECTION_ANSWER, + boost::const_pointer_cast(rrset), dnssec_); // Handle additional for answer section addAdditional(*result.zone_finder, *rrset.get()); } diff --git a/src/bin/auth/tests/query_unittest.cc b/src/bin/auth/tests/query_unittest.cc index 14067abb7d..858759ef98 100644 --- a/src/bin/auth/tests/query_unittest.cc +++ b/src/bin/auth/tests/query_unittest.cc @@ -211,8 +211,10 @@ public: virtual isc::dns::RRClass getClass() const { return (rrclass_); } virtual FindResult find(const isc::dns::Name& name, const isc::dns::RRType& type, - RRsetList* target = NULL, const FindOptions options = FIND_DEFAULT); + virtual FindResult findAll(const isc::dns::Name& name, + std::vector& target, + const FindOptions options = FIND_DEFAULT); // If false is passed, it makes the zone broken as if it didn't have the // SOA. @@ -304,9 +306,30 @@ substituteWild(const RRset& wild_rrset, const Name& real_name) { return (rrset); } +ZoneFinder::FindResult +MockZoneFinder::findAll(const Name& name, std::vector& target, + const FindOptions options) +{ + ZoneFinder::FindResult result(find(name, RRType::ANY(), options)); + if (result.code == NXRRSET) { + const Domains::const_iterator found_domain = domains_.find(name); + if (!found_domain->second.empty()) { + for (RRsetStore::const_iterator found_rrset = + found_domain->second.begin(); + found_rrset != found_domain->second.end(); ++found_rrset) { + // Insert RRs under the domain name into target + target.push_back(found_rrset->second); + } + return (FindResult(SUCCESS, RRsetPtr())); + } + } + + return (result); +} + ZoneFinder::FindResult MockZoneFinder::find(const Name& name, const RRType& type, - RRsetList* target, const FindOptions options) + const FindOptions options) { // Emulating a broken zone: mandatory apex RRs are missing if specifically // configured so (which are rare cases). @@ -358,17 +381,6 @@ MockZoneFinder::find(const Name& name, const RRType& type, return (FindResult(SUCCESS, rrset)); } - // If not found but we have a target, fill it with all RRsets here - if (!found_domain->second.empty() && target != NULL) { - for (found_rrset = found_domain->second.begin(); - found_rrset != found_domain->second.end(); ++found_rrset) { - // Insert RRs under the domain name into target - target->addRRset( - boost::const_pointer_cast(found_rrset->second)); - } - return (FindResult(SUCCESS, found_domain->second.begin()->second)); - } - // Otherwise, if this domain name has CNAME, return it. found_rrset = found_domain->second.find(RRType::CNAME()); if (found_rrset != found_domain->second.end()) { diff --git a/src/lib/python/isc/datasrc/finder_python.cc b/src/lib/python/isc/datasrc/finder_python.cc index 7f74133d8d..5aa9c3eb9c 100644 --- a/src/lib/python/isc/datasrc/finder_python.cc +++ b/src/lib/python/isc/datasrc/finder_python.cc @@ -74,7 +74,7 @@ PyObject* ZoneFinder_helper(ZoneFinder* finder, PyObject* args) { static_cast(options_int); const ZoneFinder::FindResult find_result( finder->find(PyName_ToName(name), PyRRType_ToRRType(rrtype), - NULL, options)); + options)); const ZoneFinder::Result r = find_result.code; isc::dns::ConstRRsetPtr rrsp = find_result.rrset; if (rrsp) {