[svn] commit: r3866 - in /trunk: ./ src/bin/auth/ src/bin/auth/tests/ src/bin/bind10/ src/lib/datasrc/ src/lib/datasrc/tests/ src/lib/nsas/ src/lib/nsas/tests/
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Dec 16 09:20:44 UTC 2010
Author: chenzhengzhang
Date: Thu Dec 16 09:20:44 2010
New Revision: 3866
Log:
merge trac422 : Implement memory Data Source Class
Added:
trunk/src/lib/datasrc/memory_datasrc.cc
- copied unchanged from r3862, branches/trac422/src/lib/datasrc/memory_datasrc.cc
trunk/src/lib/datasrc/memory_datasrc.h
- copied unchanged from r3862, branches/trac422/src/lib/datasrc/memory_datasrc.h
trunk/src/lib/datasrc/tests/memory_datasrc_unittest.cc
- copied unchanged from r3862, branches/trac422/src/lib/datasrc/tests/memory_datasrc_unittest.cc
Modified:
trunk/ (props changed)
trunk/ChangeLog
trunk/src/bin/auth/query.cc
trunk/src/bin/auth/tests/query_unittest.cc
trunk/src/bin/bind10/bind10.py.in (props changed)
trunk/src/lib/datasrc/Makefile.am
trunk/src/lib/datasrc/tests/Makefile.am
trunk/src/lib/datasrc/tests/zonetable_unittest.cc
trunk/src/lib/datasrc/zonetable.cc
trunk/src/lib/datasrc/zonetable.h
trunk/src/lib/nsas/ (props changed)
trunk/src/lib/nsas/tests/ (props changed)
Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog (original)
+++ trunk/ChangeLog Thu Dec 16 09:20:44 2010
@@ -1,3 +1,11 @@
+ 130. [func] jerry
+ src/lib/datasrc: Introduced a new class MemoryDataSrc to provide
+ the general interface for memory data source. For the initial
+ implementation, we don't make it a derived class of AbstractDataSrc
+ because the interface is so different(we'll eventually consider this
+ as part of the generalization work).
+ (Trac #422, svn r3566)
+
129. [func] jinmei
src/lib/dns: Added new functions masterLoad() for loading master
zone files. The initial implementation can only parse a limited
Modified: trunk/src/bin/auth/query.cc
==============================================================================
--- trunk/src/bin/auth/query.cc (original)
+++ trunk/src/bin/auth/query.cc Thu Dec 16 09:20:44 2010
@@ -26,10 +26,10 @@
namespace auth {
void
Query::process() const {
- const ZoneTable::FindResult result = zone_table_.find(qname_);
+ const ZoneTable::FindResult result = zone_table_.findZone(qname_);
- if (result.code != ZoneTable::SUCCESS &&
- result.code != ZoneTable::PARTIALMATCH) {
+ if (result.code != isc::datasrc::result::SUCCESS &&
+ result.code != isc::datasrc::result::PARTIALMATCH) {
response_.setRcode(Rcode::SERVFAIL());
return;
}
Modified: trunk/src/bin/auth/tests/query_unittest.cc
==============================================================================
--- trunk/src/bin/auth/tests/query_unittest.cc (original)
+++ trunk/src/bin/auth/tests/query_unittest.cc Thu Dec 16 09:20:44 2010
@@ -55,7 +55,7 @@
TEST_F(QueryTest, matchZone) {
// add a matching zone. since the zone is empty right now, the response
// should have NXDOMAIN.
- zone_table.add(ZonePtr(new MemoryZone(qclass, Name("example.com"))));
+ zone_table.addZone(ZonePtr(new MemoryZone(qclass, Name("example.com"))));
query.process();
EXPECT_EQ(Rcode::NXDOMAIN(), response.getRcode());
}
@@ -63,7 +63,7 @@
TEST_F(QueryTest, noMatchZone) {
// there's a zone in the table but it doesn't match the qname. should
// result in SERVFAIL.
- zone_table.add(ZonePtr(new MemoryZone(qclass, Name("example.org"))));
+ zone_table.addZone(ZonePtr(new MemoryZone(qclass, Name("example.org"))));
query.process();
EXPECT_EQ(Rcode::SERVFAIL(), response.getRcode());
}
Modified: trunk/src/lib/datasrc/Makefile.am
==============================================================================
--- trunk/src/lib/datasrc/Makefile.am (original)
+++ trunk/src/lib/datasrc/Makefile.am Thu Dec 16 09:20:44 2010
@@ -16,3 +16,4 @@
libdatasrc_la_SOURCES += query.h query.cc
libdatasrc_la_SOURCES += cache.h cache.cc
libdatasrc_la_SOURCES += zonetable.h zonetable.cc
+libdatasrc_la_SOURCES += memory_datasrc.h memory_datasrc.cc
Modified: trunk/src/lib/datasrc/tests/Makefile.am
==============================================================================
--- trunk/src/lib/datasrc/tests/Makefile.am (original)
+++ trunk/src/lib/datasrc/tests/Makefile.am Thu Dec 16 09:20:44 2010
@@ -25,11 +25,12 @@
run_unittests_SOURCES += cache_unittest.cc
run_unittests_SOURCES += test_datasrc.h test_datasrc.cc
run_unittests_SOURCES += zonetable_unittest.cc
+run_unittests_SOURCES += memory_datasrc_unittest.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
run_unittests_LDADD = $(GTEST_LDADD)
run_unittests_LDADD += $(SQLITE_LIBS)
-run_unittests_LDADD += $(top_builddir)/src/lib/datasrc/libdatasrc.la
+run_unittests_LDADD += $(top_builddir)/src/lib/datasrc/libdatasrc.la
run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
run_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
Modified: trunk/src/lib/datasrc/tests/zonetable_unittest.cc
==============================================================================
--- trunk/src/lib/datasrc/tests/zonetable_unittest.cc (original)
+++ trunk/src/lib/datasrc/tests/zonetable_unittest.cc Thu Dec 16 09:20:44 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(result::SUCCESS, zone_table.addZone(zone1));
+ EXPECT_EQ(result::EXIST, zone_table.addZone(zone1));
// names are compared in a case insensitive manner.
- EXPECT_EQ(ZoneTable::EXIST, zone_table.add(
+ EXPECT_EQ(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(result::SUCCESS, zone_table.addZone(zone2));
+ EXPECT_EQ(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(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(result::SUCCESS, zone_table.addZone(zone1));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone2));
+ EXPECT_EQ(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(result::SUCCESS, zone_table.removeZone(Name("example.net")));
+ EXPECT_EQ(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(result::SUCCESS, zone_table.addZone(zone1));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone2));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone3));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.find(Name("example.com")).code);
+ EXPECT_EQ(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(static_cast<const Zone*>(NULL),
- zone_table.find(Name("example.org")).zone);
+ EXPECT_EQ(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(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(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: trunk/src/lib/datasrc/zonetable.cc
==============================================================================
--- trunk/src/lib/datasrc/zonetable.cc (original)
+++ trunk/src/lib/datasrc/zonetable.cc Thu Dec 16 09:20:44 2010
@@ -77,29 +77,30 @@
delete impl_;
}
-ZoneTable::Result
-ZoneTable::add(ZonePtr zone) {
+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 (result::SUCCESS);
} else {
- return (EXIST);
+ return (result::EXIST);
}
}
-ZoneTable::Result
-ZoneTable::remove(const Name& origin) {
- return (impl_->zones.erase(origin) == 1 ? SUCCESS : NOTFOUND);
+result::Result
+ZoneTable::removeZone(const Name& origin) {
+ return (impl_->zones.erase(origin) == 1 ? result::SUCCESS :
+ 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.get()));
+ return (FindResult(i == 0 ? result::SUCCESS :
+ result::PARTIALMATCH, (*found).second));
}
}
- return (FindResult(NOTFOUND, NULL));
+ return (FindResult(result::NOTFOUND, ConstZonePtr()));
}
} // end of namespace datasrc
} // end of namespace isc
Modified: trunk/src/lib/datasrc/zonetable.h
==============================================================================
--- trunk/src/lib/datasrc/zonetable.h (original)
+++ trunk/src/lib/datasrc/zonetable.h Thu Dec 16 09:20:44 2010
@@ -26,6 +26,21 @@
};
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.
+///
+/// Note: this is intended to be used from other data sources eventually,
+/// but for now it's specific to in memory data source and its backend.
+enum Result {
+ SUCCESS, ///< The operation is successful.
+ EXIST, ///< The search key is already stored.
+ NOTFOUND, ///< The specified object is not found.
+ PARTIALMATCH ///< \c Only a partial match is found.
+};
+}
/// \brief The base class for a single authoritative zone
///
@@ -223,81 +238,22 @@
/// \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.
-///
-/// On the other hand, the find() method returns a bare pointer, rather than
-/// the shared pointer, in order to minimize the dependency on Boost
-/// definitions in our public interfaces. This means the caller can only
-/// refer to the returned object (via the pointer) for a short period.
-/// It should be okay for simple lookup purposes, but if we see the need
-/// for keeping a \c Zone object for a longer period of context, we may
-/// have to revisit this decision.
-///
-/// 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 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 Zone* param_zone) :
+ FindResult(result::Result param_code, const ConstZonePtr param_zone) :
code(param_code), zone(param_zone)
{}
- const Result code;
- const Zone* const zone;
+ const result::Result code;
+ const ConstZonePtr zone;
};
-
///
/// \name Constructors and Destructor.
///
@@ -322,53 +278,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.
+ 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 result::SUCCESS If the zone is successfully
+ /// removed from the zone table.
+ /// \return \c result::NOTFOUND The zone table does not
+ /// store the zone that matches \c origin.
+ 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 pointer to the found \c Zone object if one is found;
- /// otherwise \c NULL.
- ///
- /// The pointer returned in the \c FindResult object is only valid until
- /// the corresponding zone is removed from the zone table.
- /// The caller must ensure that the zone is held in the zone table while
- /// it needs to refer to it.
- ///
- /// 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