Commit 25b7595f authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[1198] proposed further refactor 2: eliminated the need for 'records_found'

in findWildcardMatch().  as a result we can now use the common FindResult
struct as the return type of findWildcardMatch().
parent cf8596b5
......@@ -470,7 +470,7 @@ DatabaseClient::Finder::findDelegationPoint(const isc::dns::Name& name,
last_known));
}
DatabaseClient::Finder::WildcardSearchResult
ZoneFinder::FindResult
DatabaseClient::Finder::findWildcardMatch(
const isc::dns::Name& name, const isc::dns::RRType& type,
const FindOptions options, const isc::dns::ConstRRsetPtr& first_ns,
......@@ -478,13 +478,12 @@ DatabaseClient::Finder::findWildcardMatch(
{
// Result of search
isc::dns::ConstRRsetPtr result_rrset;
ZoneFinder::Result result_status = SUCCESS;
ZoneFinder::Result result_status = NXDOMAIN; // in case we don't find any
// Search options
const bool dnssec_data((options & FIND_DNSSEC) != 0);
// Other
bool records_found = false; // Distinguish between NXDOMAIN and NXRRSET
WantedTypes final_types(FINAL_TYPES());
final_types.insert(type);
......@@ -509,7 +508,6 @@ DatabaseClient::Finder::findWildcardMatch(
// delegation
result_rrset = first_ns;
result_status = DELEGATION;
records_found = true;
LOG_DEBUG(logger, DBG_TRACE_DETAILED,
DATASRC_DATABASE_WILDCARD_CANCEL_NS).
......@@ -522,7 +520,6 @@ DatabaseClient::Finder::findWildcardMatch(
// go up only to first existing domain, but it could be an empty
// non-terminal. In that case, we need to cancel the match.
records_found = true;
const FoundIterator cni(found.second.find(RRType::CNAME()));
const FoundIterator nsi(found.second.find(RRType::NS()));
const FoundIterator nci(found.second.find(RRType::NSEC()));
......@@ -561,14 +558,15 @@ DatabaseClient::Finder::findWildcardMatch(
DATASRC_DATABASE_WILDCARD_CANCEL_SUB).
arg(accessor_->getDBName()).arg(wildcard).
arg(name).arg(superdomain);
result_status = NXDOMAIN;
}
break;
} else if (hasSubdomains(wildcard)) {
// Empty non-terminal asterisk
records_found = true;
LOG_DEBUG(logger, DBG_TRACE_DETAILED,
DATASRC_DATABASE_WILDCARD_EMPTY).
arg(accessor_->getDBName()).arg(wildcard).arg(name);
result_status = NXRRSET;
if (dnssec_data) {
result_rrset = findNSECCover(Name(wildcard));
if (result_rrset) {
......@@ -578,7 +576,7 @@ DatabaseClient::Finder::findWildcardMatch(
break;
}
}
return (WildcardSearchResult(result_status, result_rrset, records_found));
return (ZoneFinder::FindResult(result_status, result_rrset));
}
ZoneFinder::FindResult
......@@ -656,18 +654,14 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
// It's not an empty non-terminal so check for wildcards.
// We remove labels one by one and look for the wildcard there.
// Go up to first non-empty domain.
const WildcardSearchResult wresult =
const ZoneFinder::FindResult wresult =
findWildcardMatch(name, type, options, first_ns, last_known);
if (!wresult.records_found) {
// This is the NXDOMAIN case (nothing found anywhere). If
// they want DNSSEC data, try getting the NSEC record
return (FindResult(NXDOMAIN,
dnssec_data ? findNSECCover(name) :
ConstRRsetPtr()));
} else {
return (FindResult(wresult.code == SUCCESS ? NXRRSET :
wresult.code, wresult.rrset));
if (wresult.code == NXDOMAIN && dnssec_data) {
// If the result is NXDOMAIN case and the caller wanted
// DNSSEC data, try getting the NSEC record.
return (FindResult(NXDOMAIN, findNSECCover(name)));
}
return (FindResult(wresult.code, wresult.rrset));
}
} else {
// This is the "usual" NXRRSET case. So in case they want DNSSEC,
......
......@@ -849,32 +849,6 @@ public:
const size_t last_known; ///< No. labels in last non-empty domain
};
/// \brief Search result of \c findWildcard().
///
/// This is a tuple combining the result of the search - a status code
/// and a pointer to the RRset found - together with additional
/// information needed for subsequent processing: if there is not a
/// match for the data sought, then whether there is no match for the
/// wildcard or where there is a match, but no RRs of the type
/// requested.
///
/// Note that the code and rrset elements are the same as that in
/// the \c ZoneFinder::FindResult struct: this structure could be
/// derived from that one, but as it is used just once in the code and
/// will never be treated as a \c FindResult, the obscurity involved in
/// deriving it from a parent class was deemed not worthwhile.
struct WildcardSearchResult {
WildcardSearchResult(const ZoneFinder::Result param_code,
const isc::dns::ConstRRsetPtr param_rrset,
const bool param_found) :
code(param_code), rrset(param_rrset),
records_found(param_found)
{}
const ZoneFinder::Result code; ///< Result code
const isc::dns::ConstRRsetPtr rrset; ///< Pointer to RRset found
const bool records_found; ///< true => NXRRSET
};
private:
boost::shared_ptr<DatabaseAccessor> accessor_;
const int zone_id_;
......@@ -997,8 +971,7 @@ public:
* is no match is an indication as to whether there was an
* NXDOMAIN or an NXRRSET.
*/
WildcardSearchResult
findWildcardMatch(
FindResult findWildcardMatch(
const isc::dns::Name& name,
const isc::dns::RRType& type, const FindOptions options,
const isc::dns::ConstRRsetPtr& first_ns, size_t last_known);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment