[svn] commit: r3810 - in /branches/trac422/src/lib/datasrc: memory_datasrc.cc memory_datasrc.h tests/memory_datasrc_unittest.cc tests/zonetable_unittest.cc zonetable.cc zonetable.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Dec 13 08:15:18 UTC 2010
Author: chenzhengzhang
Date: Mon Dec 13 08:15:18 2010
New Revision: 3810
Log:
revise MemoryDataSrc code and unittest according to review comments
Modified:
branches/trac422/src/lib/datasrc/memory_datasrc.cc
branches/trac422/src/lib/datasrc/memory_datasrc.h
branches/trac422/src/lib/datasrc/tests/memory_datasrc_unittest.cc
branches/trac422/src/lib/datasrc/tests/zonetable_unittest.cc
branches/trac422/src/lib/datasrc/zonetable.cc
branches/trac422/src/lib/datasrc/zonetable.h
Modified: branches/trac422/src/lib/datasrc/memory_datasrc.cc
==============================================================================
--- branches/trac422/src/lib/datasrc/memory_datasrc.cc (original)
+++ branches/trac422/src/lib/datasrc/memory_datasrc.cc Mon Dec 13 08:15:18 2010
@@ -13,33 +13,41 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <dns/name.h>
+#include <datasrc/memory_datasrc.h>
-#include <datasrc/zonetable.h>
-#include <datasrc/memory_datasrc.h>
using namespace std;
using namespace isc::dns;
namespace isc {
namespace datasrc {
-MemoryDataSrc::MemoryDataSrc()
+struct MemoryDataSrc::MemoryDataSrcImpl {
+ /// For now, \c MemoryDataSrc only contains a \c ZoneTable object, which
+ /// consists of (pointers to) \c MemoryZone objects, we may add more
+ /// member variables later for new features.
+ ZoneTable zone_table;
+};
+
+MemoryDataSrc::MemoryDataSrc() : impl_(new MemoryDataSrcImpl)
{}
-MemoryDataSrc::~MemoryDataSrc()
-{}
+MemoryDataSrc::~MemoryDataSrc() {
+ delete impl_;
+}
-MemoryDataSrc::Result
-MemoryDataSrc::add(ZonePtr zone) {
+isc::datasrc::result::Result
+MemoryDataSrc::addZone(ZonePtr zone) {
if (!zone) {
isc_throw(InvalidParameter,
- "Null pointer is passed to MemoryDataSrc::add()");
+ "Null pointer is passed to MemoryDataSrc::addZone()");
}
- return (zone_table_.add(zone));
+ return (impl_->zone_table.addZone(zone));
}
MemoryDataSrc::FindResult
-MemoryDataSrc::find(const isc::dns::Name& name) const {
- return (zone_table_.find(name));
+MemoryDataSrc::findZone(const isc::dns::Name& name) const {
+ return (FindResult(impl_->zone_table.findZone(name).code,
+ impl_->zone_table.findZone(name).zone));
}
} // end of namespace datasrc
} // end of namespace dns
Modified: branches/trac422/src/lib/datasrc/memory_datasrc.h
==============================================================================
--- branches/trac422/src/lib/datasrc/memory_datasrc.h (original)
+++ branches/trac422/src/lib/datasrc/memory_datasrc.h Mon Dec 13 08:15:18 2010
@@ -17,24 +17,30 @@
#include <boost/shared_ptr.hpp>
+#include <datasrc/zonetable.h>
+
namespace isc {
namespace dns {
class Name;
};
namespace datasrc {
+namespace result {
+enum Result;
+};
-/// \brief A set of authoritative zones.
+/// \brief A data source that uses in memory dedicated backend.
///
-/// The \c MemoryDataSrc class represents a set of zones of the same RR class
-/// and provides a basic interface to help DNS lookup processing.
-/// For a given domain name, its \c find() method searches the set for a zone
+/// The \c MemoryDataSrc class represents a data source and provides a
+/// basic interface to help DNS lookup processing. For a given domain
+/// name, its \c find() method searches the in memory dedicated backend
/// that gives a longest match against that name.
///
-/// The set of zones are assumed to be of the same RR class, but the
-/// \c MemoryDataSrc class does not enforce the assumption through its interface.
-/// For example, the \c add() method does not check if the new zone
-/// is of the same RR class as that of the others already in the table.
+/// The in memory dedicated backend are assumed to be of the same RR class,
+/// but the \c MemoryDataSrc class does not enforce the assumption through
+/// its interface.
+/// For example, the \c addZone() method does not check if the new zone is of
+/// the same RR class as that of the others already in the dedicated backend.
/// It is caller's responsibility to ensure this assumption.
///
/// <b>Notes to developer:</b>
@@ -43,12 +49,12 @@
/// interface is so different (we'll eventually consider this as part of the
/// generalization work).
///
-/// The add() method takes a (Boost) shared pointer because it would be
+/// The addZone() method takes a (Boost) shared pointer because it would be
/// inconvenient to require the caller to maintain the ownership of zones,
-/// while it wouldn't be safe to delete unnecessary zones inside the zone
-/// table.
+/// while it wouldn't be safe to delete unnecessary zones inside the dedicated
+/// backend.
///
-/// The find() method takes a domain name and returns the best matching \c
+/// The findZone() method takes a domain name and returns the best matching \c
/// MemoryZone in the form of (Boost) shared pointer, so that it can provide
/// the general interface for all data sources.
///
@@ -57,11 +63,6 @@
/// we may want to allow configuration update on an existing zone.
class MemoryDataSrc {
public:
- /// Result codes of various public methods of \c MemoryDataSrc.
- ///
- /// The detailed semantics may differ in different methods.
- /// See the description of specific methods for more details.
- typedef ZoneTable::Result Result;
/// \brief A helper structure to represent the search result of
/// <code>MemoryDataSrc::find()</code>.
///
@@ -77,7 +78,15 @@
///
/// See the description of \c find() for the semantics of the member
/// variables.
- typedef ZoneTable::FindResult FindResult;
+ struct FindResult {
+ FindResult(isc::datasrc::result::Result param_code,
+ const ConstZonePtr param_zone) :
+ code(param_code), zone(param_zone)
+ {}
+ const isc::datasrc::result::Result code;
+ const ConstZonePtr zone;
+ };
+
///
/// \name Constructors and Destructor.
///
@@ -110,10 +119,11 @@
/// This method never throws an exception otherwise.
///
/// \param zone A \c Zone object to be added.
- /// \return \c ZoneTable::SUCCESS If the zone is successfully added to the memory data source.
- /// \return \c ZoneTable::EXIST The memory data source already stores a zone that has the
- /// same origin.
- Result add(ZonePtr zone);
+ /// \return \c isc::datasrc::result::SUCCESS If the zone is successfully
+ /// added to the memory data source.
+ /// \return \c isc::datasrc::result::EXIST The memory data source already
+ /// stores a zone that has the same origin.
+ isc::datasrc::result::Result addZone(ZonePtr zone);
/// Find a \c Zone that best matches the given name in the \c MemoryDataSrc.
///
@@ -121,22 +131,23 @@
/// longest match against \c name, and returns the result in the
/// form of a \c FindResult object as follows:
/// - \c code: The result code of the operation.
- /// - \c ZoneTable::SUCCESS: A zone that gives an exact match is found
- /// - \c ZoneTable::PARTIALMATCH: A zone whose origin is a super domain of
- /// \c name is found (but there is no exact match)
- /// - \c ZoneTable::NOTFOUND: For all other cases.
- /// - \c zone: A <Boost> shared pointer to the found \c Zone object if one is
- /// found; otherwise \c NULL.
+ /// - \c isc::datasrc::result::SUCCESS: A zone that gives an exact match
+ // is found
+ /// - \c isc::datasrc::result::PARTIALMATCH: A zone whose origin is a
+ // super domain of \c name is found (but there is no exact match)
+ /// - \c isc::datasrc::result::NOTFOUND: For all other cases.
+ /// - \c zone: A <Boost> shared pointer to the found \c Zone object if one
+ // is found; otherwise \c NULL.
///
/// This method never throws an exception.
///
/// \param name A domain name for which the search is performed.
- /// \return A \c ZoneTable::FindResult object enclosing the search result (see above).
- FindResult find(const isc::dns::Name& name) const;
+ /// \return A \c FindResult object enclosing the search result (see above).
+ FindResult findZone(const isc::dns::Name& name) const;
+
private:
- /// \c MemoryDataSrc contains a \c ZoneTable object, which consists of (pointers
- /// to) \c MemoryZone objects.
- ZoneTable zone_table_;
+ struct MemoryDataSrcImpl;
+ MemoryDataSrcImpl* impl_;
};
}
}
Modified: branches/trac422/src/lib/datasrc/tests/memory_datasrc_unittest.cc
==============================================================================
--- branches/trac422/src/lib/datasrc/tests/memory_datasrc_unittest.cc (original)
+++ branches/trac422/src/lib/datasrc/tests/memory_datasrc_unittest.cc Mon Dec 13 08:15:18 2010
@@ -29,63 +29,90 @@
class MemoryDataSrcTest : public ::testing::Test {
protected:
- MemoryDataSrcTest() : zone1(new MemoryZone(RRClass::IN(),
- Name("example.com"))),
- zone2(new MemoryZone(RRClass::IN(),
- Name("example.net"))),
- zone3(new MemoryZone(RRClass::IN(), Name("example")))
+ MemoryDataSrcTest()
{}
MemoryDataSrc memory_datasrc;
- ZonePtr zone1, zone2, zone3;
};
-TEST_F(MemoryDataSrcTest, add) {
- EXPECT_EQ(ZoneTable::SUCCESS, memory_datasrc.add(zone1));
- EXPECT_EQ(ZoneTable::EXIST, memory_datasrc.add(zone1));
+TEST_F(MemoryDataSrcTest, add_find_Zone) {
+ // test add zone
+ // Bogus zone (NULL)
+ EXPECT_THROW(memory_datasrc.addZone(ZonePtr()), isc::InvalidParameter);
+
+ // add zones with different names one by one
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::IN(), Name("a")))));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::CH(), Name("b")))));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::IN(), Name("c")))));
+ // add zones with the same name suffix
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::CH(),
+ Name("x.d.e.f")))));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::CH(),
+ Name("o.w.y.d.e.f")))));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::CH(),
+ Name("p.w.y.d.e.f")))));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::IN(),
+ Name("q.w.y.d.e.f")))));
+ // add super zone and its subzone
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::CH(), Name("g.h")))));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::IN(), Name("i.g.h")))));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::IN(),
+ Name("z.d.e.f")))));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::IN(),
+ Name("j.z.d.e.f")))));
+
+ // different zone class isn't allowed.
+ EXPECT_EQ(isc::datasrc::result::EXIST, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::CH(),
+ Name("q.w.y.d.e.f")))));
+
// names are compared in a case insensitive manner.
- EXPECT_EQ(ZoneTable::EXIST, memory_datasrc.add(
- ZonePtr(new MemoryZone(RRClass::IN(), Name("EXAMPLE.COM")))));
+ EXPECT_EQ(isc::datasrc::result::EXIST, memory_datasrc.addZone(
+ ZonePtr(new MemoryZone(RRClass::IN(),
+ Name("Q.W.Y.d.E.f")))));
- EXPECT_EQ(ZoneTable::SUCCESS, memory_datasrc.add(zone2));
- EXPECT_EQ(ZoneTable::SUCCESS, memory_datasrc.add(zone3));
+ // test find zone
+ EXPECT_EQ(isc::datasrc::result::SUCCESS,
+ memory_datasrc.findZone(Name("a")).code);
+ EXPECT_EQ(Name("a"),
+ memory_datasrc.findZone(Name("a")).zone->getOrigin());
- // MemoryDataSrc is indexed only by name. Duplicate origin name with
- // different zone class isn't allowed.
- EXPECT_EQ(ZoneTable::EXIST, memory_datasrc.add(
- ZonePtr(new MemoryZone(RRClass::CH(),
- Name("example.com")))));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS,
+ memory_datasrc.findZone(Name("j.z.d.e.f")).code);
+ EXPECT_EQ(Name("j.z.d.e.f"),
+ memory_datasrc.findZone(Name("j.z.d.e.f")).zone->getOrigin());
- /// Bogus zone (NULL)
- EXPECT_THROW(memory_datasrc.add(ZonePtr()), isc::InvalidParameter);
-}
+ // NOTFOUND
+ EXPECT_EQ(isc::datasrc::result::NOTFOUND,
+ memory_datasrc.findZone(Name("d.e.f")).code);
+ EXPECT_EQ(ConstZonePtr(),
+ memory_datasrc.findZone(Name("d.e.f")).zone);
-TEST_F(MemoryDataSrcTest, find) {
- EXPECT_EQ(ZoneTable::SUCCESS, memory_datasrc.add(zone1));
- EXPECT_EQ(ZoneTable::SUCCESS, memory_datasrc.add(zone2));
- EXPECT_EQ(ZoneTable::SUCCESS, memory_datasrc.add(zone3));
-
- memory_datasrc.find(Name("example.com"));
- EXPECT_EQ(ZoneTable::SUCCESS, memory_datasrc.find(Name("example.com")).code);
- EXPECT_EQ(Name("example.com"),
- memory_datasrc.find(Name("example.com")).zone->getOrigin());
-
- EXPECT_EQ(ZoneTable::NOTFOUND,
- memory_datasrc.find(Name("example.org")).code);
- EXPECT_EQ(ConstZonePtr(static_cast<const Zone*>(NULL)),
- memory_datasrc.find(Name("example.org")).zone);
+ EXPECT_EQ(isc::datasrc::result::NOTFOUND,
+ memory_datasrc.findZone(Name("w.y.d.e.f")).code);
+ EXPECT_EQ(ConstZonePtr(),
+ memory_datasrc.findZone(Name("w.y.d.e.f")).zone);
// there's no exact match. the result should be the longest match,
// and the code should be PARTIALMATCH.
- EXPECT_EQ(ZoneTable::PARTIALMATCH,
- memory_datasrc.find(Name("www.example.com")).code);
- EXPECT_EQ(Name("example.com"),
- memory_datasrc.find(Name("www.example.com")).zone->getOrigin());
+ EXPECT_EQ(isc::datasrc::result::PARTIALMATCH,
+ memory_datasrc.findZone(Name("j.g.h")).code);
+ EXPECT_EQ(Name("g.h"),
+ memory_datasrc.findZone(Name("g.h")).zone->getOrigin());
- // make sure the partial match is indeed the longest match by adding
- // a zone with a shorter origin and query again.
- ZonePtr zone_com(new MemoryZone(RRClass::IN(), Name("com")));
- EXPECT_EQ(ZoneTable::SUCCESS, memory_datasrc.add(zone_com));
- EXPECT_EQ(Name("example.com"),
- memory_datasrc.find(Name("www.example.com")).zone->getOrigin());
+ EXPECT_EQ(isc::datasrc::result::PARTIALMATCH,
+ memory_datasrc.findZone(Name("z.i.g.h")).code);
+ EXPECT_EQ(Name("i.g.h"),
+ memory_datasrc.findZone(Name("z.i.g.h")).zone->getOrigin());
}
}
Modified: branches/trac422/src/lib/datasrc/tests/zonetable_unittest.cc
==============================================================================
--- branches/trac422/src/lib/datasrc/tests/zonetable_unittest.cc (original)
+++ branches/trac422/src/lib/datasrc/tests/zonetable_unittest.cc Mon Dec 13 08:15:18 2010
@@ -53,61 +53,61 @@
ZonePtr zone1, zone2, zone3;
};
-TEST_F(ZoneTableTest, add) {
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone1));
- EXPECT_EQ(ZoneTable::EXIST, zone_table.add(zone1));
+TEST_F(ZoneTableTest, addZone) {
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone1));
+ EXPECT_EQ(isc::datasrc::result::EXIST, zone_table.addZone(zone1));
// names are compared in a case insensitive manner.
- EXPECT_EQ(ZoneTable::EXIST, zone_table.add(
+ EXPECT_EQ(isc::datasrc::result::EXIST, zone_table.addZone(
ZonePtr(new MemoryZone(RRClass::IN(), Name("EXAMPLE.COM")))));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone2));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone3));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone2));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone3));
// Zone table is indexed only by name. Duplicate origin name with
// different zone class isn't allowed.
- EXPECT_EQ(ZoneTable::EXIST, zone_table.add(
+ EXPECT_EQ(isc::datasrc::result::EXIST, zone_table.addZone(
ZonePtr(new MemoryZone(RRClass::CH(),
Name("example.com")))));
/// Bogus zone (NULL)
- EXPECT_THROW(zone_table.add(ZonePtr()), isc::InvalidParameter);
+ EXPECT_THROW(zone_table.addZone(ZonePtr()), isc::InvalidParameter);
}
-TEST_F(ZoneTableTest, remove) {
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone1));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone2));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone3));
+TEST_F(ZoneTableTest, removeZone) {
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone1));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone2));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone3));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.remove(Name("example.net")));
- EXPECT_EQ(ZoneTable::NOTFOUND, zone_table.remove(Name("example.net")));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.removeZone(Name("example.net")));
+ EXPECT_EQ(isc::datasrc::result::NOTFOUND, zone_table.removeZone(Name("example.net")));
}
-TEST_F(ZoneTableTest, find) {
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone1));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone2));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone3));
+TEST_F(ZoneTableTest, findZone) {
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone1));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone2));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone3));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.find(Name("example.com")).code);
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.findZone(Name("example.com")).code);
EXPECT_EQ(Name("example.com"),
- zone_table.find(Name("example.com")).zone->getOrigin());
+ zone_table.findZone(Name("example.com")).zone->getOrigin());
- EXPECT_EQ(ZoneTable::NOTFOUND,
- zone_table.find(Name("example.org")).code);
- EXPECT_EQ(ConstZonePtr(static_cast<const Zone*>(NULL)),
- zone_table.find(Name("example.org")).zone);
+ EXPECT_EQ(isc::datasrc::result::NOTFOUND,
+ zone_table.findZone(Name("example.org")).code);
+ EXPECT_EQ(ConstZonePtr(),
+ zone_table.findZone(Name("example.org")).zone);
// there's no exact match. the result should be the longest match,
// and the code should be PARTIALMATCH.
- EXPECT_EQ(ZoneTable::PARTIALMATCH,
- zone_table.find(Name("www.example.com")).code);
+ EXPECT_EQ(isc::datasrc::result::PARTIALMATCH,
+ zone_table.findZone(Name("www.example.com")).code);
EXPECT_EQ(Name("example.com"),
- zone_table.find(Name("www.example.com")).zone->getOrigin());
+ zone_table.findZone(Name("www.example.com")).zone->getOrigin());
// make sure the partial match is indeed the longest match by adding
// a zone with a shorter origin and query again.
ZonePtr zone_com(new MemoryZone(RRClass::IN(), Name("com")));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone_com));
+ EXPECT_EQ(isc::datasrc::result::SUCCESS, zone_table.addZone(zone_com));
EXPECT_EQ(Name("example.com"),
- zone_table.find(Name("www.example.com")).zone->getOrigin());
+ zone_table.findZone(Name("www.example.com")).zone->getOrigin());
}
}
Modified: branches/trac422/src/lib/datasrc/zonetable.cc
==============================================================================
--- branches/trac422/src/lib/datasrc/zonetable.cc (original)
+++ branches/trac422/src/lib/datasrc/zonetable.cc Mon Dec 13 08:15:18 2010
@@ -77,29 +77,30 @@
delete impl_;
}
-ZoneTable::Result
-ZoneTable::add(ZonePtr zone) {
+isc::datasrc::result::Result
+ZoneTable::addZone(ZonePtr zone) {
if (!zone) {
isc_throw(InvalidParameter,
- "Null pointer is passed to ZoneTable::add()");
+ "Null pointer is passed to ZoneTable::addZone()");
}
if (impl_->zones.insert(
ZoneTableImpl::NameAndZone(zone->getOrigin(), zone)).second
== true) {
- return (SUCCESS);
+ return (isc::datasrc::result::SUCCESS);
} else {
- return (EXIST);
+ return (isc::datasrc::result::EXIST);
}
}
-ZoneTable::Result
-ZoneTable::remove(const Name& origin) {
- return (impl_->zones.erase(origin) == 1 ? SUCCESS : NOTFOUND);
+isc::datasrc::result::Result
+ZoneTable::removeZone(const Name& origin) {
+ return (impl_->zones.erase(origin) == 1 ? isc::datasrc::result::SUCCESS :
+ isc::datasrc::result::NOTFOUND);
}
ZoneTable::FindResult
-ZoneTable::find(const Name& name) const {
+ZoneTable::findZone(const Name& name) const {
// Inefficient internal loop to find a longest match.
// This will be replaced with a single call to more intelligent backend.
for (int i = 0; i < name.getLabelCount(); ++i) {
@@ -107,11 +108,11 @@
ZoneTableImpl::ZoneMap::const_iterator found =
impl_->zones.find(matchname);
if (found != impl_->zones.end()) {
- return (FindResult(i == 0 ? SUCCESS : PARTIALMATCH,
- (*found).second));
+ return (FindResult(i == 0 ? isc::datasrc::result::SUCCESS :
+ result::PARTIALMATCH, (*found).second));
}
}
- return (FindResult(NOTFOUND, ConstZonePtr(static_cast<const Zone*>(NULL))));
+ return (FindResult(isc::datasrc::result::NOTFOUND, ConstZonePtr()));
}
} // end of namespace datasrc
} // end of namespace isc
Modified: branches/trac422/src/lib/datasrc/zonetable.h
==============================================================================
--- branches/trac422/src/lib/datasrc/zonetable.h (original)
+++ branches/trac422/src/lib/datasrc/zonetable.h Mon Dec 13 08:15:18 2010
@@ -26,6 +26,18 @@
};
namespace datasrc {
+namespace result {
+ /// Result codes of various public methods of in memory data source
+ ///
+ /// The detailed semantics may differ in different methods.
+ /// See the description of specific methods for more details.
+ enum Result {
+ SUCCESS, ///< The operation is successful.
+ EXIST, ///< The zone is already stored in data source.
+ NOTFOUND, ///< The specified zone is not found in data source.
+ PARTIALMATCH ///< \c Only a partial match is found in \c find().
+ };
+}
/// \brief The base class for a single authoritative zone
///
@@ -223,77 +235,23 @@
/// \brief A set of authoritative zones.
///
-/// The \c ZoneTable class represents a set of zones of the same RR class
-/// and provides a basic interface to help DNS lookup processing.
-/// For a given domain name, its \c find() method searches the set for a zone
-/// that gives a longest match against that name.
-///
-/// The set of zones are assumed to be of the same RR class, but the
-/// \c ZoneTable class does not enforce the assumption through its interface.
-/// For example, the \c add() method does not check if the new zone
-/// is of the same RR class as that of the others already in the table.
-/// It is caller's responsibility to ensure this assumption.
-///
-/// <b>Notes to developer:</b>
-///
-/// The add() method takes a (Boost) shared pointer because it would be
-/// inconvenient to require the caller to maintain the ownership of zones,
-/// while it wouldn't be safe to delete unnecessary zones inside the zone
-/// table.
-///
-/// The find() method returns a (Boost) shared pointer, so that the higher
-/// level \c MemoryDataSrc can provide the genenral interface for all data
-/// sources.
-///
-/// Currently, \c FindResult::zone is immutable for safety.
-/// In future versions we may want to make it changeable. For example,
-/// we may want to allow configuration update on an existing zone.
-///
-/// In BIND 9's "zt" module, the equivalent of \c find() has an "option"
-/// parameter. The only defined option is the one to specify the "no exact"
-/// mode, and the only purpose of that mode is to prefer a second longest match
-/// even if there is an exact match in order to deal with type DS query.
-/// This trick may help enhance performance, but it also seems to make the
-/// implementation complicated for a very limited, minor case. So, for now,
-/// we don't introduce the special mode, and, since it was the only reason to
-/// have search options in BIND 9, our initial implementation doesn't provide
-/// a switch for options.
+/// \c ZoneTable class is primarily intended to be used as a backend for the
+/// \c MemoryDataSrc class, but is exposed as a separate class in case some
+/// application wants to use it directly (e.g. for a customized data source
+/// implementation).
+///
+/// For more descriptions about its struct and interfaces, please refer to the
+/// corresponding struct and interfaces of \c MemoryDataSrc.
class ZoneTable {
public:
- /// Result codes of various public methods of \c ZoneTable.
- ///
- /// The detailed semantics may differ in different methods.
- /// See the description of specific methods for more details.
- enum Result {
- SUCCESS, ///< The operation is successful.
- EXIST, ///< A zone is already stored in \c ZoneTable.
- NOTFOUND, ///< The specified zone is not found in \c ZoneTable.
- PARTIALMATCH ///< \c Only a partial match is found in \c find().
- };
-
- /// \brief A helper structure to represent the search result of
- /// <code>ZoneTable::find()</code>.
- ///
- /// This is a straightforward pair of the result code and a (Boost) shared
- /// pointer to the found zone to represent the result of \c find().
- /// We use this in order to avoid overloading the return value for both
- /// the result code ("success" or "not found") and the found object,
- /// i.e., avoid using \c NULL to mean "not found", etc.
- ///
- /// This is a simple value class with no internal state, so for
- /// convenience we allow the applications to refer to the members
- /// directly.
- ///
- /// See the description of \c find() for the semantics of the member
- /// variables.
struct FindResult {
- FindResult(Result param_code, const ConstZonePtr param_zone) :
+ FindResult(isc::datasrc::result::Result param_code,
+ const ConstZonePtr param_zone) :
code(param_code), zone(param_zone)
{}
- const Result code;
+ const isc::datasrc::result::Result code;
const ConstZonePtr zone;
};
-
///
/// \name Constructors and Destructor.
///
@@ -318,48 +276,25 @@
//@}
/// Add a \c Zone to the \c ZoneTable.
- ///
- /// \c zone must not be associated with a NULL pointer; otherwise
- /// an exception of class \c InvalidParameter will be thrown.
- /// If internal resource allocation fails, a corresponding standard
- /// exception will be thrown.
- /// This method never throws an exception otherwise.
- ///
- /// \param zone A \c Zone object to be added.
- /// \return \c SUCCESS If the zone is successfully added to the zone table.
- /// \return \c EXIST The zone table already stores a zone that has the
- /// same origin.
- Result add(ZonePtr zone);
+ /// See the description of <code>MemoryDataSrc::addZone()</code> for more
+ /// details.
+ isc::datasrc::result::Result addZone(ZonePtr zone);
/// Remove a \c Zone of the given origin name from the \c ZoneTable.
///
/// This method never throws an exception.
///
/// \param origin The origin name of the zone to be removed.
- /// \return \c SUCCESS If the zone is successfully removed from the
- /// zone table.
- /// \return \c NOTFOUND The zone table does not store the zone that matches
- /// \c origin.
- Result remove(const isc::dns::Name& origin);
+ /// \return \c isc::datasrc::result::SUCCESS If the zone is successfully
+ /// removed from the zone table.
+ /// \return \c isc::datasrc::result::NOTFOUND The zone table does not
+ /// store the zone that matches \c origin.
+ isc::datasrc::result::Result removeZone(const isc::dns::Name& origin);
/// Find a \c Zone that best matches the given name in the \c ZoneTable.
- ///
- /// It searches the internal storage for a \c Zone that gives the
- /// longest match against \c name, and returns the result in the
- /// form of a \c FindResult object as follows:
- /// - \c code: The result code of the operation.
- /// - \c SUCCESS: A zone that gives an exact match is found
- /// - \c PARTIALMATCH: A zone whose origin is a super domain of
- /// \c name is found (but there is no exact match)
- /// - \c NOTFOUND: For all other cases.
- /// - \c zone: A (Boost) shared pointer to the found \c Zone object if one
- /// is found; otherwise \c NULL.
- ///
- /// This method never throws an exception.
- ///
- /// \param name A domain name for which the search is performed.
- /// \return A \c FindResult object enclosing the search result (see above).
- FindResult find(const isc::dns::Name& name) const;
+ /// See the description of <code>MemoryDataSrc::findZone()</code> for more
+ /// details.
+ FindResult findZone(const isc::dns::Name& name) const;
private:
struct ZoneTableImpl;
More information about the bind10-changes
mailing list