#include <algorithm> // for std::max
#include <vector>
#include <boost/foreach.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
#include <dns/message.h>
#include <dns/rcode.h>
// 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,
// 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<RRset>(aaaa_result.rrset),
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());
// 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) {
// 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) {
boost::const_pointer_cast<RRset>(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) {
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 " <<
response_.setRcode(Rcode::NOERROR());
while (keep_doing) {
keep_doing = false;
- std::auto_ptr<RRsetList> target(qtype_is_any ? new RRsetList : NULL);
- const ZoneFinder::FindResult db_result(
- zfinder.find(qname_, qtype_, target.get(), dnssec_opt_));
+ std::vector<ConstRRsetPtr> target;
+ boost::function0<ZoneFinder::FindResult> 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
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>(rrset), dnssec_);
// Handle additional for answer section
addAdditional(*result.zone_finder, *rrset.get());
}
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<ConstRRsetPtr>& target,
+ const FindOptions options = FIND_DEFAULT);
// If false is passed, it makes the zone broken as if it didn't have the
// SOA.
return (rrset);
}
+ZoneFinder::FindResult
+MockZoneFinder::findAll(const Name& name, std::vector<ConstRRsetPtr>& 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).
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<RRset>(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()) {