[svn] commit: r750 - in /branches/each-datasrc: ./ src/lib/auth/cpp/data_source.cc src/lib/auth/cpp/data_source.h src/lib/auth/cpp/data_source_static.cc src/lib/auth/cpp/data_source_static.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Feb 8 18:14:26 UTC 2010
Author: each
Date: Mon Feb 8 18:14:25 2010
New Revision: 750
Log:
checkpoint: Added NameMatch class, added findAddrs() routine
Added:
branches/each-datasrc/
- copied from r740, trunk/
Modified:
branches/each-datasrc/src/lib/auth/cpp/data_source.cc
branches/each-datasrc/src/lib/auth/cpp/data_source.h
branches/each-datasrc/src/lib/auth/cpp/data_source_static.cc
branches/each-datasrc/src/lib/auth/cpp/data_source_static.h
Modified: branches/each-datasrc/src/lib/auth/cpp/data_source.cc
==============================================================================
--- branches/each-datasrc/src/lib/auth/cpp/data_source.cc (original)
+++ branches/each-datasrc/src/lib/auth/cpp/data_source.cc Mon Feb 8 18:14:25 2010
@@ -18,11 +18,12 @@
while (!q.tasks().empty()) {
RRsetList data, sigs;
- bool found = false;
QueryTaskPtr task = q.tasks().front();
q.tasks().pop();
- const DataSrc* ds = findClosestEnclosure(task->qname, container, found);
+ NameMatch match(task->qname);
+ findClosestEnclosure(match);
+ const DataSrc* ds = match.bestDataSrc();
if (ds == NULL) {
result = ZONE_NOT_FOUND;
Modified: branches/each-datasrc/src/lib/auth/cpp/data_source.h
==============================================================================
--- branches/each-datasrc/src/lib/auth/cpp/data_source.h (original)
+++ branches/each-datasrc/src/lib/auth/cpp/data_source.h Mon Feb 8 18:14:25 2010
@@ -36,6 +36,7 @@
};
class DataSrc;
+class NameMatch;
typedef std::vector<RRsetPtr> RRsetList;
@@ -60,17 +61,12 @@
const RRType& qtype,
RRsetList& target) const = 0;
- virtual const DataSrc* findClosestEnclosure(const Name& qname,
- Name& container,
- bool& found) const = 0;
+ virtual void findClosestEnclosure(NameMatch& match) const = 0;
// Optional 'low-level' methods. These will have stub implementations
// in the general DataSrc class but MAY be overwritten by subclasses
virtual DSResult init() = 0;
virtual DSResult close() = 0;
-
- //virtual const RRClass& getClass() const = 0;
- //virtual const RRClass& setClass() const = 0;
};
// Base class for a DNS Data Source
@@ -93,9 +89,30 @@
const RRType& qtype,
RRsetList& target) const = 0;
- virtual const DataSrc* findClosestEnclosure(const Name& qname,
- Name& container,
- bool& found) const = 0;
+ virtual DSResult findAddrs(const Name& qname,
+ const RRClass& qclass,
+ RRsetList& target,
+ RRsetList& sigs) const {
+ DSResult r;
+ r = findRRset(qname, qclass, RRType::A(), target, sigs);
+ if (r != SUCCESS)
+ return (r);
+ r = findRRset(qname, qclass, RRType::AAAA(), target, sigs);
+ return (r);
+ }
+
+ virtual DSResult findAddrs(const Name& qname,
+ const RRClass& qclass,
+ RRsetList& target) const {
+ DSResult r;
+ r = findRRset(qname, qclass, RRType::A(), target);
+ if (r != SUCCESS)
+ return (r);
+ r = findRRset(qname, qclass, RRType::AAAA(), target);
+ return (r);
+ }
+
+ virtual void findClosestEnclosure(NameMatch& match) const = 0;
const RRClass& getClass() const { return rrclass; }
void setClass(RRClass& c) { rrclass = c; }
@@ -119,31 +136,45 @@
}
data_sources.push_back(ds);
- };
+ }
- const DataSrc* findClosestEnclosure(const Name& qname,
- Name& container,
- bool& found) const
- {
- const DataSrc* best = NULL;
+ void findClosestEnclosure(NameMatch& match) const {
BOOST_FOREACH (DataSrc* ds, data_sources) {
- const DataSrc* source;
-
if (getClass() != RRClass::ANY() && ds->getClass() != getClass()) {
continue;
}
- source = ds->findClosestEnclosure(qname, container, found);
- if (source != NULL) {
- best = source;
- }
+ ds->findClosestEnclosure(match);
}
-
- return (best);
- };
+ }
private:
std::vector<DataSrc*> data_sources;
+};
+
+class NameMatch {
+public:
+ NameMatch(const Name& qname) :
+ closest_name_(NULL), best_source_(NULL), qname_(qname) {}
+
+ ~NameMatch() {}
+
+ void update(const DataSrc& new_source, const Name& container) {
+ if (closest_name_ == NULL ||
+ closest_name_->getLabelCount() < container.getLabelCount()) {
+ closest_name_ = &container;
+ best_source_ = &new_source;
+ }
+ }
+
+ const Name& qname() { return (qname_); }
+ const Name* closestName() { return (closest_name_); }
+ const DataSrc* bestDataSrc() { return (best_source_); }
+
+private:
+ const Name* closest_name_;
+ const DataSrc* best_source_;
+ const Name& qname_;
};
}
Modified: branches/each-datasrc/src/lib/auth/cpp/data_source_static.cc
==============================================================================
--- branches/each-datasrc/src/lib/auth/cpp/data_source_static.cc (original)
+++ branches/each-datasrc/src/lib/auth/cpp/data_source_static.cc Mon Feb 8 18:14:25 2010
@@ -47,25 +47,21 @@
version_ns->addRdata(generic::NS(version_name));
}
-const DataSrc*
-StaticDataSrc::findClosestEnclosure(const Name& qname, Name& container, bool& found) const {
+void
+StaticDataSrc::findClosestEnclosure(NameMatch& match) const {
+ const Name& qname = match.qname();
+
NameComparisonResult::NameRelation version_cmp =
qname.compare(version_name).getRelation();
if (version_cmp == NameComparisonResult::EQUAL ||
version_cmp == NameComparisonResult::SUBDOMAIN) {
NameComparisonResult::NameRelation sub_cmp =
- version_name.compare(container).getRelation();
+ version_name.compare(*match.closestName()).getRelation();
- if (sub_cmp == NameComparisonResult::SUBDOMAIN) {
- container = authors_name;
- found = true;
- return this;
- } else if (!found && sub_cmp == NameComparisonResult::EQUAL) {
- found = true;
- return this;
- } else {
- return NULL;
+ if (sub_cmp == NameComparisonResult::EQUAL ||
+ sub_cmp == NameComparisonResult::SUBDOMAIN) {
+ match.update(*this, version_name);
}
}
@@ -75,21 +71,13 @@
if (authors_cmp == NameComparisonResult::EQUAL ||
authors_cmp == NameComparisonResult::SUBDOMAIN) {
NameComparisonResult::NameRelation sub_cmp =
- authors_name.compare(container).getRelation();
+ authors_name.compare(*match.closestName()).getRelation();
- if (sub_cmp == NameComparisonResult::SUBDOMAIN) {
- container = authors_name;
- found = true;
- return this;
- } else if (!found && sub_cmp == NameComparisonResult::EQUAL) {
- found = true;
- return this;
- } else {
- return NULL;
+ if (sub_cmp == NameComparisonResult::EQUAL ||
+ sub_cmp == NameComparisonResult::SUBDOMAIN) {
+ match.update(*this, authors_name);
}
}
-
- return NULL;
}
DSResult
Modified: branches/each-datasrc/src/lib/auth/cpp/data_source_static.h
==============================================================================
--- branches/each-datasrc/src/lib/auth/cpp/data_source_static.h (original)
+++ branches/each-datasrc/src/lib/auth/cpp/data_source_static.h Mon Feb 8 18:14:25 2010
@@ -35,9 +35,7 @@
StaticDataSrc();
~StaticDataSrc() {};
- const DataSrc* findClosestEnclosure(const Name& qname,
- Name& container,
- bool& found) const;
+ void findClosestEnclosure(NameMatch& match) const;
DSResult findRRset(const Name& qname,
const RRClass& qclass,
More information about the bind10-changes
mailing list