Browse Source

Merge branch 'trac2281'

Conflicts:
	src/lib/datasrc/memory/memory_messages.mes
	src/lib/datasrc/memory_datasrc.cc
Mukund Sivaraman 12 years ago
parent
commit
dd0f73adac
31 changed files with 292 additions and 9304 deletions
  1. 0 2
      src/bin/auth/auth_config.cc
  2. 0 1
      src/bin/auth/tests/auth_srv_unittest.cc
  3. 0 2
      src/bin/auth/tests/command_unittest.cc
  4. 0 1
      src/bin/auth/tests/config_unittest.cc
  5. 79 22
      src/bin/auth/tests/query_unittest.cc
  6. 3 11
      src/lib/datasrc/Makefile.am
  7. 0 171
      src/lib/datasrc/datasrc_messages.mes
  8. 0 1
      src/lib/datasrc/factory.cc
  9. 91 13
      src/lib/datasrc/memory/memory_messages.mes
  10. 18 18
      src/lib/datasrc/memory/zone_finder.cc
  11. 0 2045
      src/lib/datasrc/memory_datasrc.cc
  12. 0 366
      src/lib/datasrc/memory_datasrc.h
  13. 0 277
      src/lib/datasrc/memory_datasrc_link.cc
  14. 0 230
      src/lib/datasrc/rbnode_rrset.h
  15. 0 1993
      src/lib/datasrc/rbtree.h
  16. 50 0
      src/lib/datasrc/static_datasrc.h
  17. 14 8
      src/lib/datasrc/static_datasrc_link.cc
  18. 1 4
      src/lib/datasrc/tests/Makefile.am
  19. 3 78
      src/lib/datasrc/tests/factory_unittest.cc
  20. 0 2246
      src/lib/datasrc/tests/memory_datasrc_unittest.cc
  21. 0 276
      src/lib/datasrc/tests/rbnode_rrset_unittest.cc
  22. 0 1074
      src/lib/datasrc/tests/rbtree_unittest.cc
  23. 3 0
      src/lib/datasrc/tests/testdata/static-bad.zone
  24. 2 1
      src/lib/datasrc/tests/testdata/static.zone
  25. 0 128
      src/lib/datasrc/tests/zonetable_unittest.cc
  26. 0 160
      src/lib/datasrc/zonetable.cc
  27. 0 160
      src/lib/datasrc/zonetable.h
  28. 1 0
      src/lib/python/isc/datasrc/tests/Makefile.am
  29. 14 12
      src/lib/python/isc/datasrc/tests/datasrc_test.py
  30. 3 0
      src/lib/python/isc/datasrc/tests/testdata/static.zone
  31. 10 4
      src/lib/python/isc/datasrc/tests/zone_loader_test.py

+ 0 - 2
src/bin/auth/auth_config.cc

@@ -17,8 +17,6 @@
 
 
 #include <cc/data.h>
 #include <cc/data.h>
 
 
-#include <datasrc/memory_datasrc.h>
-#include <datasrc/zonetable.h>
 #include <datasrc/factory.h>
 #include <datasrc/factory.h>
 
 
 #include <auth/auth_srv.h>
 #include <auth/auth_srv.h>

+ 0 - 1
src/bin/auth/tests/auth_srv_unittest.cc

@@ -29,7 +29,6 @@
 #include <server_common/portconfig.h>
 #include <server_common/portconfig.h>
 #include <server_common/keyring.h>
 #include <server_common/keyring.h>
 
 
-#include <datasrc/memory_datasrc.h>
 #include <datasrc/client_list.h>
 #include <datasrc/client_list.h>
 #include <auth/auth_srv.h>
 #include <auth/auth_srv.h>
 #include <auth/command.h>
 #include <auth/command.h>

+ 0 - 2
src/bin/auth/tests/command_unittest.cc

@@ -29,8 +29,6 @@
 
 
 #include <config/ccsession.h>
 #include <config/ccsession.h>
 
 
-#include <datasrc/memory_datasrc.h>
-
 #include <asiolink/asiolink.h>
 #include <asiolink/asiolink.h>
 
 
 #include <util/unittests/mock_socketsession.h>
 #include <util/unittests/mock_socketsession.h>

+ 0 - 1
src/bin/auth/tests/config_unittest.cc

@@ -22,7 +22,6 @@
 #include <cc/data.h>
 #include <cc/data.h>
 
 
 #include <datasrc/data_source.h>
 #include <datasrc/data_source.h>
-#include <datasrc/memory_datasrc.h>
 
 
 #include <xfr/xfrout_client.h>
 #include <xfr/xfrout_client.h>
 
 

+ 79 - 22
src/bin/auth/tests/query_unittest.cc

@@ -30,7 +30,7 @@
 #include <dns/rrtype.h>
 #include <dns/rrtype.h>
 #include <dns/rdataclass.h>
 #include <dns/rdataclass.h>
 
 
-#include <datasrc/memory_datasrc.h>
+#include <datasrc/client.h>
 #include <datasrc/client_list.h>
 #include <datasrc/client_list.h>
 
 
 #include <auth/query.h>
 #include <auth/query.h>
@@ -831,6 +831,68 @@ createDataSrcClientList(DataSrcType type, DataSourceClient& client) {
     }
     }
 }
 }
 
 
+class MockClient : public DataSourceClient {
+public:
+    virtual FindResult findZone(const isc::dns::Name& origin) const {
+        const Name r_origin(origin.reverse());
+        std::map<Name, ZoneFinderPtr>::const_iterator it =
+            zone_finders_.lower_bound(r_origin);
+
+        if (it != zone_finders_.end()) {
+            const NameComparisonResult result =
+                origin.compare((it->first).reverse());
+            if (result.getRelation() == NameComparisonResult::EQUAL) {
+                return (FindResult(result::SUCCESS, it->second));
+            } else if (result.getRelation() == NameComparisonResult::SUBDOMAIN) {
+                return (FindResult(result::PARTIALMATCH, it->second));
+            }
+        }
+
+        // If it is at the beginning of the map, then the name was not
+        // found (we have already handled the element the iterator
+        // points to).
+        if (it == zone_finders_.begin()) {
+            return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
+        }
+
+        // Check if the previous element is a partial match.
+        --it;
+        const NameComparisonResult result =
+            origin.compare((it->first).reverse());
+        if (result.getRelation() == NameComparisonResult::SUBDOMAIN) {
+            return (FindResult(result::PARTIALMATCH, it->second));
+        }
+
+        return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
+    }
+
+    virtual ZoneUpdaterPtr getUpdater(const isc::dns::Name&, bool, bool) const {
+        isc_throw(isc::NotImplemented,
+                  "Updater isn't supported in the MockClient");
+    }
+
+    virtual std::pair<ZoneJournalReader::Result, ZoneJournalReaderPtr>
+    getJournalReader(const isc::dns::Name&, uint32_t, uint32_t) const {
+        isc_throw(isc::NotImplemented,
+                  "Journaling isn't supported in the MockClient");
+    }
+
+    result::Result addZone(ZoneFinderPtr finder) {
+        // Use the reverse of the name as the key, so we can quickly
+        // find partial matches in the map.
+        zone_finders_[finder->getOrigin().reverse()] = finder;
+        return (result::SUCCESS);
+    }
+
+private:
+    // Note that because we no longer have the old RBTree, and the new
+    // in-memory DomainTree is not useful as it returns const nodes, we
+    // use a std::map instead. In this map, the key is a name stored in
+    // reverse order of labels to aid in finding partial matches
+    // quickly.
+    std::map<Name, ZoneFinderPtr> zone_finders_;
+};
+
 class QueryTest : public ::testing::TestWithParam<DataSrcType> {
 class QueryTest : public ::testing::TestWithParam<DataSrcType> {
 protected:
 protected:
     QueryTest() :
     QueryTest() :
@@ -856,7 +918,7 @@ protected:
         response.setOpcode(Opcode::QUERY());
         response.setOpcode(Opcode::QUERY());
         // create and add a matching zone.
         // create and add a matching zone.
         mock_finder = new MockZoneFinder();
         mock_finder = new MockZoneFinder();
-        memory_client.addZone(ZoneFinderPtr(mock_finder));
+        mock_client.addZone(ZoneFinderPtr(mock_finder));
     }
     }
 
 
     virtual void SetUp() {
     virtual void SetUp() {
@@ -870,7 +932,7 @@ protected:
         // doesn't happen for derived test class.  This also ensures the
         // doesn't happen for derived test class.  This also ensures the
         // data source clients are configured after setting NSEC3 hash in case
         // data source clients are configured after setting NSEC3 hash in case
         // there's dependency.
         // there's dependency.
-        list_ = createDataSrcClientList(GetParam(), memory_client);
+        list_ = createDataSrcClientList(GetParam(), mock_client);
     }
     }
 
 
     virtual void TearDown() {
     virtual void TearDown() {
@@ -996,11 +1058,7 @@ private:
 
 
 protected:
 protected:
     MockZoneFinder* mock_finder;
     MockZoneFinder* mock_finder;
-    // We use InMemoryClient here. We could have some kind of mock client
-    // here, but historically, the Query supported only InMemoryClient
-    // (originally named MemoryDataSrc) and was tested with it, so we keep
-    // it like this for now.
-    InMemoryClient memory_client;
+    MockClient mock_client;
 
 
     boost::shared_ptr<ClientList> list_;
     boost::shared_ptr<ClientList> list_;
     const Name qname;
     const Name qname;
@@ -1040,7 +1098,7 @@ class QueryTestForMockOnly : public QueryTest {
 protected:
 protected:
     // Override SetUp() to avoid parameterized setup
     // Override SetUp() to avoid parameterized setup
     virtual void SetUp() {
     virtual void SetUp() {
-        list_ = createDataSrcClientList(MOCK, memory_client);
+        list_ = createDataSrcClientList(MOCK, mock_client);
     }
     }
 };
 };
 
 
@@ -1084,8 +1142,8 @@ responseCheck(Message& response, const isc::dns::Rcode& rcode,
 TEST_P(QueryTest, noZone) {
 TEST_P(QueryTest, noZone) {
     // There's no zone in the memory datasource.  So the response should have
     // There's no zone in the memory datasource.  So the response should have
     // REFUSED.
     // REFUSED.
-    InMemoryClient empty_memory_client;
-    SingletonList empty_list(empty_memory_client);
+    MockClient empty_mock_client;
+    SingletonList empty_list(empty_mock_client);
     EXPECT_NO_THROW(query.process(empty_list, qname, qtype,
     EXPECT_NO_THROW(query.process(empty_list, qname, qtype,
                                   response));
                                   response));
     EXPECT_EQ(Rcode::REFUSED(), response.getRcode());
     EXPECT_EQ(Rcode::REFUSED(), response.getRcode());
@@ -2258,8 +2316,8 @@ TEST_F(QueryTestForMockOnly, dsAboveDelegation) {
     // simple addition.  For now we test it for mock only.
     // simple addition.  For now we test it for mock only.
 
 
     // Pretending to have authority for the child zone, too.
     // Pretending to have authority for the child zone, too.
-    memory_client.addZone(ZoneFinderPtr(new AlternateZoneFinder(
-                                            Name("delegation.example.com"))));
+    mock_client.addZone(ZoneFinderPtr(new AlternateZoneFinder(
+                                           Name("delegation.example.com"))));
 
 
     // The following will succeed only if the search goes to the parent
     // The following will succeed only if the search goes to the parent
     // zone, not the child one we added above.
     // zone, not the child one we added above.
@@ -2281,8 +2339,8 @@ TEST_P(QueryTest, dsAboveDelegationNoData) {
     // Similar to the previous case, but the query is for an unsigned zone
     // Similar to the previous case, but the query is for an unsigned zone
     // (which doesn't have a DS at the parent).  The response should be a
     // (which doesn't have a DS at the parent).  The response should be a
     // "no data" error.  The query should still be handled at the parent.
     // "no data" error.  The query should still be handled at the parent.
-    memory_client.addZone(ZoneFinderPtr(
-                              new AlternateZoneFinder(
+    mock_client.addZone(ZoneFinderPtr(
+                             new AlternateZoneFinder(
                                   Name("unsigned-delegation.example.com"))));
                                   Name("unsigned-delegation.example.com"))));
 
 
     // The following will succeed only if the search goes to the parent
     // The following will succeed only if the search goes to the parent
@@ -2366,8 +2424,8 @@ TEST_F(QueryTestForMockOnly, dsAtGrandParentAndChild) {
 
 
     // Pretending to have authority for the child zone, too.
     // Pretending to have authority for the child zone, too.
     const Name childname("grand.delegation.example.com");
     const Name childname("grand.delegation.example.com");
-    memory_client.addZone(ZoneFinderPtr(
-                              new AlternateZoneFinder(childname)));
+    mock_client.addZone(ZoneFinderPtr(
+                             new AlternateZoneFinder(childname)));
     query.process(*list_, childname, RRType::DS(), response, true);
     query.process(*list_, childname, RRType::DS(), response, true);
     // Note that RR TTL of SOA and its RRSIG are set to SOA MINTTL, 0
     // Note that RR TTL of SOA and its RRSIG are set to SOA MINTTL, 0
     responseCheck(response, Rcode::NOERROR(), AA_FLAG, 0, 4, 0, NULL,
     responseCheck(response, Rcode::NOERROR(), AA_FLAG, 0, 4, 0, NULL,
@@ -2388,8 +2446,8 @@ TEST_F(QueryTestForMockOnly, dsAtRoot) {
     // won't be simple addition.  For now we test it for mock only.
     // won't be simple addition.  For now we test it for mock only.
 
 
     // Pretend to be a root server.
     // Pretend to be a root server.
-    memory_client.addZone(ZoneFinderPtr(
-                              new AlternateZoneFinder(Name::ROOT_NAME())));
+    mock_client.addZone(ZoneFinderPtr(
+                             new AlternateZoneFinder(Name::ROOT_NAME())));
     query.process(*list_, Name::ROOT_NAME(), RRType::DS(), response,
     query.process(*list_, Name::ROOT_NAME(), RRType::DS(), response,
                   true);
                   true);
     // Note that RR TTL of SOA and its RRSIG are set to SOA MINTTL, 0
     // Note that RR TTL of SOA and its RRSIG are set to SOA MINTTL, 0
@@ -2408,9 +2466,8 @@ TEST_F(QueryTestForMockOnly, dsAtRootWithDS) {
     // We could setup the additional zone for other data sources, but it
     // We could setup the additional zone for other data sources, but it
     // won't be simple addition.  For now we test it for mock only.
     // won't be simple addition.  For now we test it for mock only.
 
 
-    memory_client.addZone(ZoneFinderPtr(
-                              new AlternateZoneFinder(Name::ROOT_NAME(),
-                                                      true)));
+    mock_client.addZone(ZoneFinderPtr(
+                             new AlternateZoneFinder(Name::ROOT_NAME(), true)));
     query.process(*list_, Name::ROOT_NAME(), RRType::DS(), response,
     query.process(*list_, Name::ROOT_NAME(), RRType::DS(), response,
                   true);
                   true);
     responseCheck(response, Rcode::NOERROR(), AA_FLAG, 2, 2, 0,
     responseCheck(response, Rcode::NOERROR(), AA_FLAG, 2, 2, 0,

+ 3 - 11
src/lib/datasrc/Makefile.am

@@ -24,10 +24,7 @@ CLEANFILES += static.zone
 
 
 lib_LTLIBRARIES = libb10-datasrc.la
 lib_LTLIBRARIES = libb10-datasrc.la
 libb10_datasrc_la_SOURCES = data_source.h
 libb10_datasrc_la_SOURCES = data_source.h
-libb10_datasrc_la_SOURCES += rbnode_rrset.h
-libb10_datasrc_la_SOURCES += rbtree.h
 libb10_datasrc_la_SOURCES += exceptions.h
 libb10_datasrc_la_SOURCES += exceptions.h
-libb10_datasrc_la_SOURCES += zonetable.h zonetable.cc
 libb10_datasrc_la_SOURCES += zone.h zone_finder.h zone_finder.cc
 libb10_datasrc_la_SOURCES += zone.h zone_finder.h zone_finder.cc
 libb10_datasrc_la_SOURCES += zone_finder_context.cc
 libb10_datasrc_la_SOURCES += zone_finder_context.cc
 libb10_datasrc_la_SOURCES += zone_iterator.h
 libb10_datasrc_la_SOURCES += zone_iterator.h
@@ -37,7 +34,6 @@ libb10_datasrc_la_SOURCES += client.h client.cc
 libb10_datasrc_la_SOURCES += database.h database.cc
 libb10_datasrc_la_SOURCES += database.h database.cc
 libb10_datasrc_la_SOURCES += factory.h factory.cc
 libb10_datasrc_la_SOURCES += factory.h factory.cc
 libb10_datasrc_la_SOURCES += client_list.h client_list.cc
 libb10_datasrc_la_SOURCES += client_list.h client_list.cc
-libb10_datasrc_la_SOURCES += memory_datasrc.h memory_datasrc.cc
 libb10_datasrc_la_SOURCES += master_loader_callbacks.h
 libb10_datasrc_la_SOURCES += master_loader_callbacks.h
 libb10_datasrc_la_SOURCES += master_loader_callbacks.cc
 libb10_datasrc_la_SOURCES += master_loader_callbacks.cc
 libb10_datasrc_la_SOURCES += rrset_collection_base.h rrset_collection_base.cc
 libb10_datasrc_la_SOURCES += rrset_collection_base.h rrset_collection_base.cc
@@ -45,7 +41,7 @@ libb10_datasrc_la_SOURCES += zone_loader.h zone_loader.cc
 nodist_libb10_datasrc_la_SOURCES = datasrc_messages.h datasrc_messages.cc
 nodist_libb10_datasrc_la_SOURCES = datasrc_messages.h datasrc_messages.cc
 libb10_datasrc_la_LDFLAGS = -no-undefined -version-info 1:0:1
 libb10_datasrc_la_LDFLAGS = -no-undefined -version-info 1:0:1
 
 
-pkglib_LTLIBRARIES =  sqlite3_ds.la memory_ds.la static_ds.la
+pkglib_LTLIBRARIES = sqlite3_ds.la static_ds.la
 
 
 sqlite3_ds_la_SOURCES = sqlite3_accessor.h sqlite3_accessor.cc
 sqlite3_ds_la_SOURCES = sqlite3_accessor.h sqlite3_accessor.cc
 sqlite3_ds_la_SOURCES += sqlite3_accessor_link.cc
 sqlite3_ds_la_SOURCES += sqlite3_accessor_link.cc
@@ -55,12 +51,8 @@ sqlite3_ds_la_LIBADD = $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
 sqlite3_ds_la_LIBADD += libb10-datasrc.la
 sqlite3_ds_la_LIBADD += libb10-datasrc.la
 sqlite3_ds_la_LIBADD += $(SQLITE_LIBS)
 sqlite3_ds_la_LIBADD += $(SQLITE_LIBS)
 
 
-memory_ds_la_SOURCES = memory_datasrc_link.cc
-memory_ds_la_LDFLAGS = -module -avoid-version
-memory_ds_la_LIBADD = $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
-memory_ds_la_LIBADD += libb10-datasrc.la
-
 static_ds_la_SOURCES = static_datasrc_link.cc
 static_ds_la_SOURCES = static_datasrc_link.cc
+static_ds_la_SOURCES += static_datasrc.h
 static_ds_la_LDFLAGS = -module -avoid-version
 static_ds_la_LDFLAGS = -module -avoid-version
 static_ds_la_LIBADD = $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
 static_ds_la_LIBADD = $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
 static_ds_la_LIBADD += libb10-datasrc.la
 static_ds_la_LIBADD += libb10-datasrc.la
@@ -69,7 +61,7 @@ libb10_datasrc_la_LIBADD = $(top_builddir)/src/lib/exceptions/libb10-exceptions.
 libb10_datasrc_la_LIBADD += $(top_builddir)/src/lib/dns/libb10-dns++.la
 libb10_datasrc_la_LIBADD += $(top_builddir)/src/lib/dns/libb10-dns++.la
 libb10_datasrc_la_LIBADD += $(top_builddir)/src/lib/log/libb10-log.la
 libb10_datasrc_la_LIBADD += $(top_builddir)/src/lib/log/libb10-log.la
 libb10_datasrc_la_LIBADD += $(top_builddir)/src/lib/cc/libb10-cc.la
 libb10_datasrc_la_LIBADD += $(top_builddir)/src/lib/cc/libb10-cc.la
-libb10_datasrc_la_LIBADD += $(builddir)/memory/libdatasrc_memory.la
+libb10_datasrc_la_LIBADD += $(top_builddir)/src/lib/datasrc/memory/libdatasrc_memory.la
 libb10_datasrc_la_LIBADD += $(SQLITE_LIBS)
 libb10_datasrc_la_LIBADD += $(SQLITE_LIBS)
 
 
 BUILT_SOURCES = datasrc_config.h datasrc_messages.h datasrc_messages.cc
 BUILT_SOURCES = datasrc_config.h datasrc_messages.h datasrc_messages.cc

+ 0 - 171
src/lib/datasrc/datasrc_messages.mes

@@ -350,177 +350,6 @@ There's something suspicious in the master file. This is a warning only.
 It may be a problem or it may be harmless, but it should be checked.
 It may be a problem or it may be harmless, but it should be checked.
 This problem does not stop the zone from being loaded.
 This problem does not stop the zone from being loaded.
 
 
-% DATASRC_MEM_ADD_RRSET adding RRset '%1/%2' into zone '%3'
-Debug information. An RRset is being added to the in-memory data source.
-
-% DATASRC_MEM_ADD_WILDCARD adding wildcards for '%1'
-This is a debug message issued during the processing of a wildcard
-name. The internal domain name tree is scanned and some nodes are
-specially marked to allow the wildcard lookup to succeed.
-
-% DATASRC_MEM_ADD_ZONE adding zone '%1/%2'
-Debug information. A zone is being added into the in-memory data source.
-
-% DATASRC_MEM_ANY_SUCCESS ANY query for '%1' successful
-Debug information. The domain was found and an ANY type query is being answered
-by providing everything found inside the domain.
-
-% DATASRC_MEM_CNAME CNAME at the domain '%1'
-Debug information. The requested domain is an alias to a different domain,
-returning the CNAME instead.
-
-% DATASRC_MEM_CNAME_COEXIST can't add data to CNAME in domain '%1'
-This is the same problem as in MEM_CNAME_TO_NONEMPTY, but it happened the
-other way around -- adding some other data to CNAME.
-
-% DATASRC_MEM_CNAME_TO_NONEMPTY can't add CNAME to domain with other data in '%1'
-Someone or something tried to add a CNAME into a domain that already contains
-some other data. But the protocol forbids coexistence of CNAME with anything
-(RFC 1034, section 3.6.2). This indicates a problem with provided data.
-
-% DATASRC_MEM_CREATE creating zone '%1' in '%2' class
-Debug information. A representation of a zone for the in-memory data source is
-being created.
-
-% DATASRC_MEM_DELEG_FOUND delegation found at '%1'
-Debug information. A delegation point was found above the requested record.
-
-% DATASRC_MEM_DESTROY destroying zone '%1' in '%2' class
-Debug information. A zone from in-memory data source is being destroyed.
-
-% DATASRC_MEM_DNAME_ENCOUNTERED encountered a DNAME
-Debug information. While searching for the requested domain, a DNAME was
-encountered on the way.  This may lead to redirection to a different domain and
-stop the search.
-
-% DATASRC_MEM_DNAME_FOUND DNAME found at '%1'
-Debug information. A DNAME was found instead of the requested information.
-
-% DATASRC_MEM_DNAME_NS DNAME and NS can't coexist in non-apex domain '%1'
-A request was made for DNAME and NS records to be put into the same
-domain which is not the apex (the top of the zone). This is forbidden
-by RFC 2672 (section 3) and indicates a problem with provided data.
-
-% DATASRC_MEM_DOMAIN_EMPTY requested domain '%1' is empty
-Debug information. The requested domain exists in the tree of domains, but
-it is empty. Therefore it doesn't contain the requested resource type.
-
-% DATASRC_MEM_DUP_RRSET duplicate RRset '%1/%2'
-An RRset is being inserted into in-memory data source for a second time.  The
-original version must be removed first. Note that loading master files where an
-RRset is split into multiple locations is not supported yet.
-
-% DATASRC_MEM_EXACT_DELEGATION delegation at the exact domain '%1'
-Debug information. There's a NS record at the requested domain. This means
-this zone is not authoritative for the requested domain, but a delegation
-should be followed. The requested domain is an apex of some zone.
-
-% DATASRC_MEM_FIND find '%1/%2'
-Debug information. A search for the requested RRset is being started.
-
-% DATASRC_MEM_FINDNSEC3 finding NSEC3 for %1, mode %2
-Debug information. A search in an in-memory data source for NSEC3 that
-matches or covers the given name is being started.
-
-% DATASRC_MEM_FINDNSEC3_COVER found a covering NSEC3 for %1: %2
-Debug information. An NSEC3 that covers the given name is found and
-being returned.  The found NSEC3 RRset is also displayed.
-
-% DATASRC_MEM_FINDNSEC3_MATCH found a matching NSEC3 for %1 at label count %2: %3
-Debug information. An NSEC3 that matches (a possibly superdomain of)
-the given name is found and being returned.  When the shown label
-count is smaller than that of the given name, the matching NSEC3 is
-for a superdomain of the given name (see DATASRC_MEM_FINDNSEC3_TRYHASH).
-The found NSEC3 RRset is also displayed.
-
-% DATASRC_MEM_FINDNSEC3_TRYHASH looking for NSEC3 for %1 at label count %2 (hash %3)
-Debug information. In an attempt of finding an NSEC3 for the give name,
-(a possibly superdomain of) the name is hashed and searched for in the
-NSEC3 name space.  When the shown label count is smaller than that of the
-shown name, the search tries the superdomain name that share the shown
-(higher) label count of the shown name (e.g., for
-www.example.com. with shown label count of 3, example.com. is being
-tried).
-
-% DATASRC_MEM_FIND_TYPE_AT_ORIGIN origin query for type %1 in in-memory zone %2/%3 successful
-Debug information.  A specific type RRset is requested at a zone origin
-of an in-memory zone and it is found.
-
-% DATASRC_MEM_FIND_ZONE looking for zone '%1'
-Debug information. A zone object for this zone is being searched for in the
-in-memory data source.
-
-% DATASRC_MEM_LOAD loading zone '%1' from file '%2'
-Debug information. The content of master file is being loaded into the memory.
-
-% DATASRC_MEM_NOT_FOUND requested domain '%1' not found
-Debug information. The requested domain does not exist.
-
-% DATASRC_MEM_NO_NSEC3PARAM NSEC3PARAM is missing for NSEC3-signed zone %1/%2
-The in-memory data source has loaded a zone signed with NSEC3 RRs,
-but it doesn't have a NSEC3PARAM RR at the zone origin.  It's likely that
-the zone is somehow broken, but this RR is not necessarily needed for
-handling lookups with NSEC3 in this data source, so it accepts the given
-content of the zone.  Nevertheless the administrator should look into
-the integrity of the zone data.
-
-% DATASRC_MEM_NS_ENCOUNTERED encountered a NS
-Debug information. While searching for the requested domain, a NS was
-encountered on the way (a delegation). This may lead to stop of the search.
-
-% DATASRC_MEM_NXRRSET no such type '%1' at '%2'
-Debug information. The domain exists, but it doesn't hold any record of the
-requested type.
-
-% DATASRC_MEM_OUT_OF_ZONE domain '%1' doesn't belong to zone '%2'
-It was attempted to add the domain into a zone that shouldn't have it
-(eg. the domain is not subdomain of the zone origin). This indicates a
-problem with provided data.
-
-% DATASRC_MEM_RENAME renaming RRset from '%1' to '%2'
-Debug information. A RRset is being generated from a different RRset (most
-probably a wildcard). So it must be renamed to whatever the user asked for. In
-fact, it's impossible to rename RRsets with our libraries, so a new one is
-created and all resource records are copied over.
-
-% DATASRC_MEM_SINGLETON trying to add multiple RRs for domain '%1' and type '%2'
-Some resource types are singletons -- only one is allowed in a domain
-(for example CNAME or SOA). This indicates a problem with provided data.
-
-% DATASRC_MEM_SUCCESS query for '%1/%2' successful
-Debug information. The requested record was found.
-
-% DATASRC_MEM_SUPER_STOP stopped as '%1' is superdomain of a zone node, meaning it's empty
-Debug information. The search stopped because the requested domain was
-detected to be a superdomain of some existing node of zone (while there
-was no exact match).  This means that the domain is an empty nonterminal,
-therefore it is treated  as NXRRSET case (eg. the domain exists, but it
-doesn't have the requested record type).
-
-% DATASRC_MEM_SWAP swapping contents of two zone representations ('%1' and '%2')
-Debug information. The contents of two in-memory zones are being exchanged.
-This is usual practice to do some manipulation in exception-safe manner -- the
-new data are prepared in a different zone object and when it works, they are
-swapped. The old one contains the new data and the other one can be safely
-destroyed.
-
-% DATASRC_MEM_WILDCARD_CANCEL wildcard match canceled for '%1'
-Debug information. A domain above wildcard was reached, but there's something
-below the requested domain. Therefore the wildcard doesn't apply here.  This
-behaviour is specified by RFC 1034, section 4.3.3.
-
-% DATASRC_MEM_WILDCARD_DNAME DNAME record in wildcard domain '%1'
-The software refuses to load DNAME records into a wildcard domain.  It isn't
-explicitly forbidden, but the protocol is ambiguous about how this should
-behave and BIND 9 refuses that as well. Please describe your intention using
-different tools.
-
-% DATASRC_MEM_WILDCARD_NS NS record in wildcard domain '%1'
-The software refuses to load NS records into a wildcard domain.  It isn't
-explicitly forbidden, but the protocol is ambiguous about how this should
-behave and BIND 9 refuses that as well. Please describe your intention using
-different tools.
-
 % DATASRC_META_ADD adding a data source into meta data source
 % DATASRC_META_ADD adding a data source into meta data source
 This is a debug message issued during startup or reconfiguration.
 This is a debug message issued during startup or reconfiguration.
 Another data source is being added into the meta data source.
 Another data source is being added into the meta data source.

+ 0 - 1
src/lib/datasrc/factory.cc

@@ -17,7 +17,6 @@
 #include "data_source.h"
 #include "data_source.h"
 #include "database.h"
 #include "database.h"
 #include "sqlite3_accessor.h"
 #include "sqlite3_accessor.h"
-#include "memory_datasrc.h"
 
 
 #include "datasrc_config.h"
 #include "datasrc_config.h"
 
 

+ 91 - 13
src/lib/datasrc/memory/memory_messages.mes

@@ -23,19 +23,6 @@ It isn't explicitly forbidden, but no sane zone wouldn have such names
 for NSEC3.  BIND 9 also refuses NSEC3 at wildcard, so this behavior is
 for NSEC3.  BIND 9 also refuses NSEC3 at wildcard, so this behavior is
 compatible with BIND 9.
 compatible with BIND 9.
 
 
-% DATASRC_MEMORY_CHECK_ERROR post-load check of zone %1/%2 failed: %3
-The zone was loaded into the data source successfully, but the content fails
-basic sanity checks. See the message if you want to know what exactly is wrong
-with the data. The data can not be used and previous version, if any, will be
-preserved.
-
-% DATASRC_MEMORY_CHECK_WARNING %1/%2: %3
-The zone was loaded into the data source successfully, but there's some problem
-with the content. The problem does not stop the new version from being used
-(though there may be other problems that do, see DATASRC_MEMORY_CHECK_ERROR),
-but it should still be checked and fixed. See the message to know what exactly
-is wrong with the data.
-
 % DATASRC_MEMORY_MEM_ADD_RRSET adding RRset '%1/%2' into zone '%3'
 % DATASRC_MEMORY_MEM_ADD_RRSET adding RRset '%1/%2' into zone '%3'
 Debug information. An RRset is being added to the in-memory data source.
 Debug information. An RRset is being added to the in-memory data source.
 
 
@@ -101,3 +88,94 @@ The software refuses to load NS records into a wildcard domain.  It isn't
 explicitly forbidden, but the protocol is ambiguous about how this should
 explicitly forbidden, but the protocol is ambiguous about how this should
 behave and BIND 9 refuses that as well. Please describe your intention using
 behave and BIND 9 refuses that as well. Please describe your intention using
 different tools.
 different tools.
+
+% DATASRC_MEMORY_CHECK_ERROR post-load check of zone %1/%2 failed: %3
+The zone was loaded into the data source successfully, but the content fails
+basic sanity checks. See the message if you want to know what exactly is wrong
+with the data. The data can not be used and previous version, if any, will be
+preserved.
+
+% DATASRC_MEMORY_CHECK_WARNING %1/%2: %3
+The zone was loaded into the data source successfully, but there's some problem
+with the content. The problem does not stop the new version from being used
+(though there may be other problems that do, see DATASRC_MEMORY_CHECK_ERROR),
+but it should still be checked and fixed. See the message to know what exactly
+is wrong with the data.
+
+% DATASRC_MEMORY_DNAME_ENCOUNTERED encountered a DNAME
+Debug information. While searching for the requested domain, a DNAME was
+encountered on the way.  This may lead to redirection to a different domain and
+stop the search.
+
+% DATASRC_MEMORY_NS_ENCOUNTERED encountered a NS
+Debug information. While searching for the requested domain, a NS was
+encountered on the way (a delegation). This may lead to stop of the search.
+
+% DATASRC_MEMORY_DNAME_FOUND DNAME found at '%1'
+Debug information. A DNAME was found instead of the requested information.
+
+% DATASRC_MEMORY_DELEG_FOUND delegation found at '%1'
+Debug information. A delegation point was found above the requested record.
+
+% DATASRC_MEMORY_SUPER_STOP stopped as '%1' is superdomain of a zone node, meaning it's empty
+Debug information. The search stopped because the requested domain was
+detected to be a superdomain of some existing node of zone (while there
+was no exact match).  This means that the domain is an empty nonterminal,
+therefore it is treated  as NXRRSET case (eg. the domain exists, but it
+doesn't have the requested record type).
+
+% DATASRC_MEMORY_WILDCARD_CANCEL wildcard match canceled for '%1'
+Debug information. A domain above wildcard was reached, but there's something
+below the requested domain. Therefore the wildcard doesn't apply here.  This
+behaviour is specified by RFC 1034, section 4.3.3.
+
+% DATASRC_MEMORY_NOT_FOUND requested domain '%1' not found
+Debug information. The requested domain does not exist.
+
+% DATASRC_MEMORY_FIND_TYPE_AT_ORIGIN origin query for type %1 in in-memory zone %2/%3 successful
+Debug information.  A specific type RRset is requested at a zone origin
+of an in-memory zone and it is found.
+
+% DATASRC_MEMORY_DOMAIN_EMPTY requested domain '%1' is empty
+Debug information. The requested domain exists in the tree of domains, but
+it is empty. Therefore it doesn't contain the requested resource type.
+
+% DATASRC_MEMORY_EXACT_DELEGATION delegation at the exact domain '%1'
+Debug information. There's a NS record at the requested domain. This means
+this zone is not authoritative for the requested domain, but a delegation
+should be followed. The requested domain is an apex of some zone.
+
+% DATASRC_MEMORY_ANY_SUCCESS ANY query for '%1' successful
+Debug information. The domain was found and an ANY type query is being answered
+by providing everything found inside the domain.
+
+% DATASRC_MEMORY_SUCCESS query for '%1/%2' successful
+Debug information. The requested record was found.
+
+% DATASRC_MEMORY_CNAME CNAME at the domain '%1'
+Debug information. The requested domain is an alias to a different domain,
+returning the CNAME instead.
+
+% DATASRC_MEMORY_FINDNSEC3 finding NSEC3 for %1, mode %2
+Debug information. A search in an in-memory data source for NSEC3 that
+matches or covers the given name is being started.
+
+% DATASRC_MEMORY_FINDNSEC3_COVER found a covering NSEC3 for %1: %2
+Debug information. An NSEC3 that covers the given name is found and
+being returned.  The found NSEC3 RRset is also displayed.
+
+% DATASRC_MEMORY_FINDNSEC3_MATCH found a matching NSEC3 for %1 at label count %2: %3
+Debug information. An NSEC3 that matches (a possibly superdomain of)
+the given name is found and being returned.  When the shown label
+count is smaller than that of the given name, the matching NSEC3 is
+for a superdomain of the given name (see DATASRC_MEMORY_FINDNSEC3_TRYHASH).
+The found NSEC3 RRset is also displayed.
+
+% DATASRC_MEMORY_FINDNSEC3_TRYHASH looking for NSEC3 for %1 at label count %2 (hash %3)
+Debug information. In an attempt of finding an NSEC3 for the give name,
+(a possibly superdomain of) the name is hashed and searched for in the
+NSEC3 name space.  When the shown label count is smaller than that of the
+shown name, the search tries the superdomain name that share the shown
+(higher) label count of the shown name (e.g., for
+www.example.com. with shown label count of 3, example.com. is being
+tried).

+ 18 - 18
src/lib/datasrc/memory/zone_finder.cc

@@ -26,7 +26,7 @@
 #include <dns/rrttl.h>
 #include <dns/rrttl.h>
 #include <dns/nsec3hash.h>
 #include <dns/nsec3hash.h>
 
 
-#include <datasrc/logger.h>
+#include <datasrc/memory/logger.h>
 
 
 #include <util/buffer.h>
 #include <util/buffer.h>
 
 
@@ -168,7 +168,7 @@ bool cutCallback(const ZoneNode& node, FindState* state) {
                                                  RRType::DNAME());
                                                  RRType::DNAME());
 
 
     if (found_dname != NULL) {
     if (found_dname != NULL) {
-        LOG_DEBUG(logger, DBG_TRACE_DETAILED, DATASRC_MEM_DNAME_ENCOUNTERED);
+        LOG_DEBUG(logger, DBG_TRACE_DETAILED, DATASRC_MEMORY_DNAME_ENCOUNTERED);
         state->dname_node_ = &node;
         state->dname_node_ = &node;
         state->rdataset_ = found_dname;
         state->rdataset_ = found_dname;
         return (true);
         return (true);
@@ -183,7 +183,7 @@ bool cutCallback(const ZoneNode& node, FindState* state) {
             return (false);
             return (false);
         }
         }
 
 
-        LOG_DEBUG(logger, DBG_TRACE_DETAILED, DATASRC_MEM_NS_ENCOUNTERED);
+        LOG_DEBUG(logger, DBG_TRACE_DETAILED, DATASRC_MEMORY_NS_ENCOUNTERED);
 
 
         // BIND 9 checks if this node is not the origin.  That's probably
         // BIND 9 checks if this node is not the origin.  That's probably
         // because it can support multiple versions for dynamic updates
         // because it can support multiple versions for dynamic updates
@@ -483,13 +483,13 @@ FindNodeResult findNode(const ZoneData& zone_data,
     } else if (result == ZoneTree::PARTIALMATCH) {
     } else if (result == ZoneTree::PARTIALMATCH) {
         assert(node != NULL);
         assert(node != NULL);
         if (state.dname_node_ != NULL) { // DNAME
         if (state.dname_node_ != NULL) { // DNAME
-            LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_DNAME_FOUND).
+            LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEMORY_DNAME_FOUND).
                 arg(state.dname_node_->getName());
                 arg(state.dname_node_->getName());
             return (FindNodeResult(ZoneFinder::DNAME, state.dname_node_,
             return (FindNodeResult(ZoneFinder::DNAME, state.dname_node_,
                                    state.rdataset_));
                                    state.rdataset_));
         }
         }
         if (state.zonecut_node_ != NULL) { // DELEGATION due to NS
         if (state.zonecut_node_ != NULL) { // DELEGATION due to NS
-            LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_DELEG_FOUND).
+            LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEMORY_DELEG_FOUND).
                 arg(state.zonecut_node_->getName());
                 arg(state.zonecut_node_->getName());
             return (FindNodeResult(ZoneFinder::DELEGATION,
             return (FindNodeResult(ZoneFinder::DELEGATION,
                                    state.zonecut_node_,
                                    state.zonecut_node_,
@@ -498,7 +498,7 @@ FindNodeResult findNode(const ZoneData& zone_data,
         if (node_path.getLastComparisonResult().getRelation() ==
         if (node_path.getLastComparisonResult().getRelation() ==
             NameComparisonResult::SUPERDOMAIN) { // empty node, so NXRRSET
             NameComparisonResult::SUPERDOMAIN) { // empty node, so NXRRSET
             LOG_DEBUG(logger, DBG_TRACE_DATA,
             LOG_DEBUG(logger, DBG_TRACE_DATA,
-                      DATASRC_MEM_SUPER_STOP).arg(name_labels);
+                      DATASRC_MEMORY_SUPER_STOP).arg(name_labels);
             ConstNodeRRset nsec_rrset = getClosestNSEC(zone_data, node_path,
             ConstNodeRRset nsec_rrset = getClosestNSEC(zone_data, node_path,
                                                        options);
                                                        options);
             return (FindNodeResult(ZoneFinder::NXRRSET, nsec_rrset.first,
             return (FindNodeResult(ZoneFinder::NXRRSET, nsec_rrset.first,
@@ -516,7 +516,7 @@ FindNodeResult findNode(const ZoneData& zone_data,
                 // baz.foo.wild.example. The common ancestor, foo.wild.example,
                 // baz.foo.wild.example. The common ancestor, foo.wild.example,
                 // should cancel wildcard.  Treat it as NXDOMAIN.
                 // should cancel wildcard.  Treat it as NXDOMAIN.
                 LOG_DEBUG(logger, DBG_TRACE_DATA,
                 LOG_DEBUG(logger, DBG_TRACE_DATA,
-                          DATASRC_MEM_WILDCARD_CANCEL).arg(name_labels);
+                          DATASRC_MEMORY_WILDCARD_CANCEL).arg(name_labels);
                 ConstNodeRRset nsec_rrset = getClosestNSEC(zone_data,
                 ConstNodeRRset nsec_rrset = getClosestNSEC(zone_data,
                                                            node_path,
                                                            node_path,
                                                            options);
                                                            options);
@@ -546,7 +546,7 @@ FindNodeResult findNode(const ZoneData& zone_data,
                         FindNodeResult::FIND_WILDCARD | zonecut_flag));
                         FindNodeResult::FIND_WILDCARD | zonecut_flag));
         }
         }
 
 
-        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_NOT_FOUND).
+        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEMORY_NOT_FOUND).
             arg(name_labels);
             arg(name_labels);
         ConstNodeRRset nsec_rrset = getClosestNSEC(zone_data, node_path,
         ConstNodeRRset nsec_rrset = getClosestNSEC(zone_data, node_path,
                                                    options);
                                                    options);
@@ -785,7 +785,7 @@ InMemoryZoneFinder::findAtOrigin(const isc::dns::RRType& type,
     const RdataSet* const found = RdataSet::find(node->getData(), type);
     const RdataSet* const found = RdataSet::find(node->getData(), type);
 
 
     if (found != NULL) {
     if (found != NULL) {
-        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_FIND_TYPE_AT_ORIGIN).
+        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEMORY_FIND_TYPE_AT_ORIGIN).
             arg(type).arg(getOrigin()).arg(rrclass_);
             arg(type).arg(getOrigin()).arg(rrclass_);
         return (ZoneFinderContextPtr(
         return (ZoneFinderContextPtr(
                     new Context(*this, options, rrclass_,
                     new Context(*this, options, rrclass_,
@@ -831,7 +831,7 @@ InMemoryZoneFinder::findInternal(const isc::dns::Name& name,
     // If there is an exact match but the node is empty, it's equivalent
     // If there is an exact match but the node is empty, it's equivalent
     // to NXRRSET.
     // to NXRRSET.
     if (node->isEmpty()) {
     if (node->isEmpty()) {
-        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_DOMAIN_EMPTY).
+        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEMORY_DOMAIN_EMPTY).
             arg(name);
             arg(name);
         ConstNodeRRset nsec_rrset = getClosestNSEC(zone_data_, node_path,
         ConstNodeRRset nsec_rrset = getClosestNSEC(zone_data_, node_path,
                                                    options);
                                                    options);
@@ -854,7 +854,7 @@ InMemoryZoneFinder::findInternal(const isc::dns::Name& name,
         found = RdataSet::find(node->getData(), RRType::NS());
         found = RdataSet::find(node->getData(), RRType::NS());
         if (found != NULL) {
         if (found != NULL) {
             LOG_DEBUG(logger, DBG_TRACE_DATA,
             LOG_DEBUG(logger, DBG_TRACE_DATA,
-                      DATASRC_MEM_EXACT_DELEGATION).arg(name);
+                      DATASRC_MEMORY_EXACT_DELEGATION).arg(name);
             return (createFindResult(rrclass_, zone_data_, DELEGATION,
             return (createFindResult(rrclass_, zone_data_, DELEGATION,
                                      node, found, options, wild, &name));
                                      node, found, options, wild, &name));
         }
         }
@@ -870,7 +870,7 @@ InMemoryZoneFinder::findInternal(const isc::dns::Name& name,
                                                   wild ? &name : NULL));
                                                   wild ? &name : NULL));
             cur_rds = cur_rds->getNext();
             cur_rds = cur_rds->getNext();
         }
         }
-        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_ANY_SUCCESS).
+        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEMORY_ANY_SUCCESS).
             arg(name);
             arg(name);
         return (createFindResult(rrclass_, zone_data_, SUCCESS, node, NULL,
         return (createFindResult(rrclass_, zone_data_, SUCCESS, node, NULL,
                                  options, wild, &name));
                                  options, wild, &name));
@@ -879,7 +879,7 @@ InMemoryZoneFinder::findInternal(const isc::dns::Name& name,
     found = RdataSet::find(node->getData(), type);
     found = RdataSet::find(node->getData(), type);
     if (found != NULL) {
     if (found != NULL) {
         // Good, it is here
         // Good, it is here
-        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_SUCCESS).arg(name).
+        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEMORY_SUCCESS).arg(name).
             arg(type);
             arg(type);
         return (createFindResult(rrclass_, zone_data_, SUCCESS, node, found,
         return (createFindResult(rrclass_, zone_data_, SUCCESS, node, found,
                                  options, wild, &name));
                                  options, wild, &name));
@@ -888,7 +888,7 @@ InMemoryZoneFinder::findInternal(const isc::dns::Name& name,
         found = RdataSet::find(node->getData(), RRType::CNAME());
         found = RdataSet::find(node->getData(), RRType::CNAME());
         if (found != NULL) {
         if (found != NULL) {
 
 
-            LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_CNAME).arg(name);
+            LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEMORY_CNAME).arg(name);
             return (createFindResult(rrclass_, zone_data_, CNAME, node, found,
             return (createFindResult(rrclass_, zone_data_, CNAME, node, found,
                                      options, wild, &name));
                                      options, wild, &name));
         }
         }
@@ -905,7 +905,7 @@ InMemoryZoneFinder::findInternal(const isc::dns::Name& name,
 
 
 isc::datasrc::ZoneFinder::FindNSEC3Result
 isc::datasrc::ZoneFinder::FindNSEC3Result
 InMemoryZoneFinder::findNSEC3(const isc::dns::Name& name, bool recursive) {
 InMemoryZoneFinder::findNSEC3(const isc::dns::Name& name, bool recursive) {
-    LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_FINDNSEC3).arg(name).
+    LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_FINDNSEC3).arg(name).
         arg(recursive ? "recursive" : "non-recursive");
         arg(recursive ? "recursive" : "non-recursive");
 
 
     uint8_t labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];
     uint8_t labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];
@@ -972,7 +972,7 @@ InMemoryZoneFinder::findNSEC3(const isc::dns::Name& name, bool recursive) {
                              name : name.split(qlabels - labels, labels));
                              name : name.split(qlabels - labels, labels));
         const std::string hlabel = hash->calculate(hname);
         const std::string hlabel = hash->calculate(hname);
 
 
-        LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_FINDNSEC3_TRYHASH).
+        LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_FINDNSEC3_TRYHASH).
             arg(name).arg(labels).arg(hlabel);
             arg(name).arg(labels).arg(hlabel);
 
 
         node = NULL;
         node = NULL;
@@ -995,7 +995,7 @@ InMemoryZoneFinder::findNSEC3(const isc::dns::Name& name, bool recursive) {
             }
             }
 
 
             LOG_DEBUG(logger, DBG_TRACE_BASIC,
             LOG_DEBUG(logger, DBG_TRACE_BASIC,
-                      DATASRC_MEM_FINDNSEC3_MATCH).arg(name).arg(labels).
+                      DATASRC_MEMORY_FINDNSEC3_MATCH).arg(name).arg(labels).
                 arg(*closest);
                 arg(*closest);
 
 
             return (FindNSEC3Result(true, labels, closest, next));
             return (FindNSEC3Result(true, labels, closest, next));
@@ -1014,7 +1014,7 @@ InMemoryZoneFinder::findNSEC3(const isc::dns::Name& name, bool recursive) {
                     closest = createNSEC3RRset(covering_node, getClass());
                     closest = createNSEC3RRset(covering_node, getClass());
 
 
                     LOG_DEBUG(logger, DBG_TRACE_BASIC,
                     LOG_DEBUG(logger, DBG_TRACE_BASIC,
-                              DATASRC_MEM_FINDNSEC3_COVER).
+                              DATASRC_MEMORY_FINDNSEC3_COVER).
                         arg(name).arg(*closest);
                         arg(name).arg(*closest);
                 }
                 }
 
 

File diff suppressed because it is too large
+ 0 - 2045
src/lib/datasrc/memory_datasrc.cc


+ 0 - 366
src/lib/datasrc/memory_datasrc.h

@@ -1,366 +0,0 @@
-// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef MEMORY_DATA_SOURCE_H
-#define MEMORY_DATA_SOURCE_H 1
-
-#include <string>
-
-#include <boost/noncopyable.hpp>
-
-#include <datasrc/zonetable.h>
-#include <datasrc/client.h>
-
-#include <cc/data.h>
-
-namespace isc {
-namespace dns {
-class Name;
-class RRsetList;
-};
-
-namespace datasrc {
-
-/// A derived zone finder class intended to be used with the memory data source.
-///
-/// Conceptually this "finder" maintains a local in-memory copy of all RRs
-/// of a single zone from some kind of source (right now it's a textual
-/// master file, but it could also be another data source with a database
-/// backend).  This is why the class has methods like \c load() or \c add().
-///
-/// This class is non copyable.
-class InMemoryZoneFinder : boost::noncopyable, public ZoneFinder {
-    ///
-    /// \name Constructors and Destructor.
-public:
-    /// \brief Constructor from zone parameters.
-    ///
-    /// This constructor internally involves resource allocation, and if
-    /// it fails, a corresponding standard exception will be thrown.
-    /// It never throws an exception otherwise.
-    ///
-    /// \param rrclass The RR class of the zone.
-    /// \param origin The origin name of the zone.
-    InMemoryZoneFinder(const isc::dns::RRClass& rrclass,
-                       const isc::dns::Name& origin);
-
-    /// The destructor.
-    virtual ~InMemoryZoneFinder();
-    //@}
-
-    /// \brief Returns the origin of the zone.
-    virtual isc::dns::Name getOrigin() const;
-
-    /// \brief Returns the class of the zone.
-    virtual isc::dns::RRClass getClass() const;
-
-    /// \brief Find an RRset in the datasource
-    virtual ZoneFinderContextPtr find(const isc::dns::Name& name,
-                                      const isc::dns::RRType& type,
-                                      const FindOptions options =
-                                      FIND_DEFAULT);
-
-    /// \brief Version of find that returns all types at once
-    ///
-    /// It acts the same as find, just that when the correct node is found,
-    /// all the RRsets are filled into the target parameter instead of being
-    /// returned by the result.
-    virtual ZoneFinderContextPtr findAll(
-        const isc::dns::Name& name,
-        std::vector<isc::dns::ConstRRsetPtr>& target,
-        const FindOptions options = FIND_DEFAULT);
-
-    /// Look for NSEC3 for proving (non)existence of given name.
-    ///
-    /// See documentation in \c Zone.
-    virtual FindNSEC3Result
-    findNSEC3(const isc::dns::Name& name, bool recursive);
-
-    /// \brief Inserts an rrset into the zone.
-    ///
-    /// It puts another RRset into the zone.
-    ///
-    /// In the current implementation, this method doesn't allow an existing
-    /// RRset to be updated or overridden.  So the caller must make sure that
-    /// all RRs of the same type and name must be given in the form of a
-    /// single RRset.  The current implementation will also require that
-    /// when an RRSIG is added the RRset to be covered has already been
-    /// added.  These restrictions are probably too strict when this data
-    /// source accepts various forms of input, so they should be revisited
-    /// later.
-    ///
-    /// Except for NullRRset and OutOfZone, this method does not guarantee
-    /// strong exception safety (it is currently not needed, if it is needed
-    /// in future, it should be implemented).
-    ///
-    /// \throw NullRRset \c rrset is a NULL pointer.
-    /// \throw OutOfZone The owner name of \c rrset is outside of the
-    /// origin of the zone.
-    /// \throw AddError Other general errors.
-    /// \throw Others This method might throw standard allocation exceptions.
-    ///
-    /// \param rrset The set to add.
-    /// \return SUCCESS or EXIST (if an rrset for given name and type already
-    ///    exists).
-    result::Result add(const isc::dns::ConstRRsetPtr& rrset);
-
-    /// \brief RRset is NULL exception.
-    ///
-    /// This is thrown if the provided RRset parameter is NULL.
-    struct NullRRset : public InvalidParameter {
-        NullRRset(const char* file, size_t line, const char* what) :
-            InvalidParameter(file, line, what)
-        { }
-    };
-
-    /// \brief General failure exception for \c add().
-    ///
-    /// This is thrown against general error cases in adding an RRset
-    /// to the zone.
-    ///
-    /// Note: this exception would cover cases for \c OutOfZone or
-    /// \c NullRRset.  We'll need to clarify and unify the granularity
-    /// of exceptions eventually.  For now, exceptions are added as
-    /// developers see the need for it.
-    struct AddError : public InvalidParameter {
-        AddError(const char* file, size_t line, const char* what) :
-            InvalidParameter(file, line, what)
-        { }
-    };
-
-    /// Return the master file name of the zone
-    ///
-    /// This method returns the name of the zone's master file to be loaded.
-    /// The returned string will be an empty unless the zone finder has
-    /// successfully loaded a zone.
-    ///
-    /// This method should normally not throw an exception.  But the creation
-    /// of the return string may involve a resource allocation, and if it
-    /// fails, the corresponding standard exception will be thrown.
-    ///
-    /// \return The name of the zone file loaded in the zone finder, or an empty
-    /// string if the zone hasn't loaded any file.
-    const std::string getFileName() const;
-
-    /// \brief Load zone from masterfile.
-    ///
-    /// This loads data from masterfile specified by filename. It replaces
-    /// current content. The masterfile parsing ability is kind of limited,
-    /// see isc::dns::masterLoad.
-    ///
-    /// This throws isc::dns::MasterLoadError if there is problem with loading
-    /// (missing file, malformed, it contains different zone, etc - see
-    /// isc::dns::masterLoad for details).
-    ///
-    /// In case of internal problems, OutOfZone, NullRRset or AssertError could
-    /// be thrown, but they should not be expected. Exceptions caused by
-    /// allocation may be thrown as well.
-    ///
-    /// If anything is thrown, the previous content is preserved (so it can
-    /// be used to update the data, but if user makes a typo, the old one
-    /// is kept).
-    ///
-    /// \param filename The master file to load.
-    ///
-    /// \todo We may need to split it to some kind of build and commit/abort.
-    ///     This will probably be needed when a better implementation of
-    ///     configuration reloading is written.
-    void load(const std::string& filename);
-
-    /// \brief Load zone from another data source.
-    ///
-    /// This is similar to the other version, but zone's RRsets are provided
-    /// by an iterator of another data source.  On successful load, the
-    /// internal filename will be cleared.
-    ///
-    /// This implementation assumes the iterator produces combined RRsets,
-    /// that is, there should exactly one RRset for the same owner name and
-    /// RR type.  This means the caller is expected to create the iterator
-    /// with \c separate_rrs being \c false.  This implementation also assumes
-    /// RRsets of different names are not mixed; so if the iterator produces
-    /// an RRset of a different name than that of the previous RRset, that
-    /// previous name must never appear in the subsequent sequence of RRsets.
-    /// Note that the iterator API does not ensure this.  If the underlying
-    /// implementation does not follow it, load() will fail.  Note, however,
-    /// that this whole interface is tentative.  in-memory zone loading will
-    /// have to be revisited fundamentally, and at that point this restriction
-    /// probably won't matter.
-    void load(ZoneIterator& iterator);
-
-    /// Exchanges the content of \c this zone finder with that of the given
-    /// \c zone_finder.
-    ///
-    /// This method never throws an exception.
-    ///
-    /// \param zone_finder Another \c InMemoryZone object which is to
-    /// be swapped with \c this zone finder.
-    void swap(InMemoryZoneFinder& zone_finder);
-
-private:
-    /// \name Hidden private data
-    //@{
-    struct InMemoryZoneFinderImpl;
-    InMemoryZoneFinderImpl* impl_;
-    //@}
-    // The friend here is for InMemoryClient::getIterator. The iterator
-    // needs to access the data inside the zone, so the InMemoryClient
-    // extracts the pointer to data and puts it into the iterator.
-    // The access is read only.
-    friend class InMemoryClient;
-
-    /// \brief In-memory version of finder context.
-    ///
-    /// The implementation (and any specialized interface) is completely local
-    /// to the InMemoryZoneFinder class, so it's defined as private
-    class Context;
-};
-
-/// \brief A data source client that holds all necessary data in memory.
-///
-/// The \c InMemoryClient class provides an access to a conceptual data
-/// source that maintains all necessary data in a memory image, thereby
-/// allowing much faster lookups.  The in memory data is a copy of some
-/// real physical source - in the current implementation a list of zones
-/// are populated as a result of \c addZone() calls; zone data is given
-/// in a standard master file (but there's a plan to use database backends
-/// as a source of the in memory data).
-///
-/// Although every data source client is assumed to be of the same RR class,
-/// the \c InMemoryClient 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 memory.
-/// It is caller's responsibility to ensure this assumption.
-///
-/// <b>Notes to developer:</b>
-///
-/// 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 dedicated
-/// backend.
-///
-/// The findZone() method takes a domain name and returns the best matching
-/// \c InMemoryZoneFinder in the form of (Boost) shared pointer, so that it can
-/// provide the general interface for all data sources.
-class InMemoryClient : public DataSourceClient {
-public:
-    ///
-    /// \name Constructors and Destructor.
-    ///
-    //@{
-
-    /// Default constructor.
-    ///
-    /// This constructor internally involves resource allocation, and if
-    /// it fails, a corresponding standard exception will be thrown.
-    /// It never throws an exception otherwise.
-    InMemoryClient();
-
-    /// The destructor.
-    ~InMemoryClient();
-    //@}
-
-    /// Return the number of zones stored in the client.
-    ///
-    /// This method never throws an exception.
-    ///
-    /// \return The number of zones stored in the client.
-    virtual unsigned int getZoneCount() const;
-
-    /// Add a zone (in the form of \c ZoneFinder) to the \c InMemoryClient.
-    ///
-    /// \c zone_finder 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_finder A \c ZoneFinder object to be added.
-    /// \return \c result::SUCCESS If the zone_finder is successfully
-    /// added to the client.
-    /// \return \c result::EXIST The memory data source already
-    /// stores a zone that has the same origin.
-    result::Result addZone(ZoneFinderPtr zone_finder);
-
-    /// Returns a \c ZoneFinder for a zone_finder that best matches the given
-    /// name.
-    ///
-    /// This derived version of the method never throws an exception.
-    /// For other details see \c DataSourceClient::findZone().
-    virtual FindResult findZone(const isc::dns::Name& name) const;
-
-    /// \brief Implementation of the getIterator method
-    virtual ZoneIteratorPtr getIterator(const isc::dns::Name& name,
-                                        bool separate_rrs = false) const;
-
-    /// In-memory data source is read-only, so this derived method will
-    /// result in a NotImplemented exception.
-    ///
-    /// \note We plan to use a database-based data source as a backend
-    /// persistent storage for an in-memory data source.  When it's
-    /// implemented we may also want to allow the user of the in-memory client
-    /// to update via its updater (this may or may not be a good idea and
-    /// is subject to further discussions).
-    virtual ZoneUpdaterPtr getUpdater(const isc::dns::Name& name,
-                                      bool replace, bool journaling = false)
-        const;
-
-    virtual std::pair<ZoneJournalReader::Result, ZoneJournalReaderPtr>
-    getJournalReader(const isc::dns::Name& zone, uint32_t begin_serial,
-                     uint32_t end_serial) const;
-
-private:
-    // TODO: Do we still need the PImpl if nobody should manipulate this class
-    // directly any more (it should be handled through DataSourceClient)?
-    class InMemoryClientImpl;
-    InMemoryClientImpl* impl_;
-};
-
-/// \brief Creates an instance of the Memory datasource client
-///
-/// Currently the configuration passed here must be a MapElement, formed as
-/// follows:
-/// \code
-/// { "type": string ("memory"),
-///   "class": string ("IN"/"CH"/etc),
-///   "zones": list
-/// }
-/// Zones list is a list of maps:
-/// { "origin": string,
-///   "file": string
-/// }
-/// \endcode
-/// (i.e. the configuration that was used prior to the datasource refactor)
-///
-/// This configuration setup is currently under discussion and will change in
-/// the near future.
-///
-/// \param config The configuration for the datasource instance
-/// \param error This string will be set to an error message if an error occurs
-///              during initialization
-/// \return An instance of the memory datasource client, or NULL if there was
-///         an error
-extern "C" DataSourceClient* createInstance(isc::data::ConstElementPtr config,
-                                            std::string& error);
-
-/// \brief Destroy the instance created by createInstance()
-extern "C" void destroyInstance(DataSourceClient* instance);
-
-
-}
-}
-#endif  // MEMORY_DATA_SOURCE_H
-// Local Variables:
-// mode: c++
-// End:

+ 0 - 277
src/lib/datasrc/memory_datasrc_link.cc

@@ -1,277 +0,0 @@
-// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <cc/data.h>
-
-#include <dns/rrclass.h>
-
-#include <datasrc/client.h>
-#include <datasrc/factory.h>
-#include <datasrc/memory_datasrc.h>
-
-#include <exceptions/exceptions.h>
-
-#include <boost/foreach.hpp>
-#include <boost/scoped_ptr.hpp>
-
-#include <string>
-
-using namespace isc::dns;
-using namespace isc::data;
-
-namespace isc {
-namespace datasrc {
-
-/// This exception is raised if there is an error in the configuration
-/// that has been passed; missing information, duplicate values, etc.
-class InMemoryConfigError : public isc::Exception {
-public:
-    InMemoryConfigError(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
-};
-
-namespace {
-// convencience function to add an error message to a list of those
-// (TODO: move functions like these to some util lib?)
-void
-addError(ElementPtr errors, const std::string& error) {
-    if (errors != ElementPtr() && errors->getType() == Element::list) {
-        errors->add(Element::create(error));
-    }
-}
-
-/// Check if the given element exists in the map, and if it is a string
-bool
-checkConfigElementString(ConstElementPtr config, const std::string& name,
-                         ElementPtr errors)
-{
-    if (!config->contains(name)) {
-        addError(errors,
-                 "Config for memory backend does not contain a '"
-                 +name+
-                 "' value");
-        return (false);
-    } else if (!config->get(name) ||
-               config->get(name)->getType() != Element::string) {
-        addError(errors, "value of " + name +
-                 " in memory backend config is not a string");
-        return (false);
-    } else {
-        return (true);
-    }
-}
-
-bool
-checkZoneConfig(ConstElementPtr config, ElementPtr errors) {
-    bool result = true;
-    if (!config || config->getType() != Element::map) {
-        addError(errors, "Elements in memory backend's zone list must be maps");
-        result = false;
-    } else {
-        if (!checkConfigElementString(config, "origin", errors)) {
-            result = false;
-        }
-        if (!checkConfigElementString(config, "file", errors)) {
-            result = false;
-        }
-        // we could add some existence/readabilty/parsability checks here
-        // if we want
-    }
-    return result;
-}
-
-bool
-checkConfig(ConstElementPtr config, ElementPtr errors) {
-    /* Specific configuration is under discussion, right now this accepts
-     * the 'old' configuration, see [TODO]
-     * So for memory datasource, we get a structure like this:
-     * { "type": string ("memory"),
-     *   "class": string ("IN"/"CH"/etc),
-     *   "zones": list
-     * }
-     * Zones list is a list of maps:
-     * { "origin": string,
-     *     "file": string
-     * }
-     *
-     * At this moment we cannot be completely sure of the contents of the
-     * structure, so we have to do some more extensive tests than should
-     * strictly be necessary (e.g. existence and type of elements)
-     */
-    bool result = true;
-
-    if (!config || config->getType() != Element::map) {
-        addError(errors, "Base config for memory backend must be a map");
-        result = false;
-    } else {
-        if (!checkConfigElementString(config, "type", errors)) {
-            result = false;
-        } else {
-            if (config->get("type")->stringValue() != "memory") {
-                addError(errors,
-                         "Config for memory backend is not of type \"memory\"");
-                result = false;
-            }
-        }
-        if (config->contains("class")) {
-            if (!checkConfigElementString(config, "class", errors)) {
-                result = false;
-            } else {
-                try {
-                    RRClass(config->get("class")->stringValue());
-                } catch (const isc::Exception& rrce) {
-                    addError(errors,
-                             "Error parsing class config for memory backend: " +
-                             std::string(rrce.what()));
-                    result = false;
-                }
-            }
-        }
-        if (!config->contains("zones")) {
-            // Assume empty list of zones
-        } else if (!config->get("zones") ||
-                   config->get("zones")->getType() != Element::list) {
-            addError(errors,
-                     "'zones' element in memory backend config is not a list");
-            result = false;
-        } else {
-            BOOST_FOREACH(ConstElementPtr zone_config,
-                          config->get("zones")->listValue()) {
-                if (!checkZoneConfig(zone_config, errors)) {
-                    result = false;
-                }
-            }
-        }
-    }
-
-    return (result);
-}
-
-// Apply the given config to the just-initialized client
-// client must be freshly allocated, and config_value should have been
-// checked by the caller
-void
-applyConfig(isc::datasrc::InMemoryClient& client,
-            isc::data::ConstElementPtr config_value)
-{
-    // XXX: We have lost the context to get to the default values here,
-    // as a temporary workaround we hardcode the IN class here.
-    isc::dns::RRClass rrclass = RRClass::IN();
-    if (config_value->contains("class")) {
-        rrclass = RRClass(config_value->get("class")->stringValue());
-    }
-    ConstElementPtr zones_config = config_value->get("zones");
-    if (!zones_config) {
-        // XXX: Like the RR class, we cannot retrieve the default value here,
-        // so we assume an empty zone list in this case.
-        return;
-    }
-
-    BOOST_FOREACH(ConstElementPtr zone_config, zones_config->listValue()) {
-        ConstElementPtr origin = zone_config->get("origin");
-        const std::string origin_txt = origin ? origin->stringValue() : "";
-        if (origin_txt.empty()) {
-            isc_throw(InMemoryConfigError, "Missing zone origin");
-        }
-        ConstElementPtr file = zone_config->get("file");
-        const std::string file_txt = file ? file->stringValue() : "";
-        if (file_txt.empty()) {
-            isc_throw(InMemoryConfigError, "Missing zone file for zone: "
-                      << origin_txt);
-        }
-
-        // We support the traditional text type and SQLite3 backend.  For the
-        // latter we create a client for the underlying SQLite3 data source,
-        // and build the in-memory zone using an iterator of the underlying
-        // zone.
-        ConstElementPtr filetype = zone_config->get("filetype");
-        const std::string filetype_txt = filetype ? filetype->stringValue() :
-            "text";
-        boost::scoped_ptr<DataSourceClientContainer> container;
-        if (filetype_txt == "sqlite3") {
-            container.reset(new DataSourceClientContainer(
-                                "sqlite3",
-                                Element::fromJSON("{\"database_file\": \"" +
-                                                  file_txt + "\"}")));
-        } else if (filetype_txt != "text") {
-            isc_throw(InMemoryConfigError, "Invalid filetype for zone "
-                      << origin_txt << ": " << filetype_txt);
-        }
-
-        // Note: we don't want to have such small try-catch blocks for each
-        // specific error.  We may eventually want to introduce some unified
-        // error handling framework as we have more configuration parameters.
-        // See bug #1627 for the relevant discussion.
-        InMemoryZoneFinder* imzf = NULL;
-        try {
-            imzf = new InMemoryZoneFinder(rrclass, Name(origin_txt));
-        } catch (const isc::dns::NameParserException& ex) {
-            isc_throw(InMemoryConfigError, "unable to parse zone's origin: " <<
-                      ex.what());
-        }
-
-        boost::shared_ptr<InMemoryZoneFinder> zone_finder(imzf);
-        const result::Result result = client.addZone(zone_finder);
-        if (result == result::EXIST) {
-            isc_throw(InMemoryConfigError, "zone "<< origin->str()
-                      << " already exists");
-        }
-
-        /*
-         * TODO: Once we have better reloading of configuration (something
-         * else than throwing everything away and loading it again), we will
-         * need the load method to be split into some kind of build and
-         * commit/abort parts.
-         */
-        if (filetype_txt == "text") {
-            zone_finder->load(file_txt);
-        } else {
-            zone_finder->load(*container->getInstance().getIterator(
-                                  Name(origin_txt)));
-        }
-    }
-}
-
-} // end unnamed namespace
-
-DataSourceClient *
-createInstance(isc::data::ConstElementPtr config, std::string& error) {
-    ElementPtr errors(Element::createList());
-    if (!checkConfig(config, errors)) {
-        error = "Configuration error: " + errors->str();
-        return (NULL);
-    }
-    try {
-        std::auto_ptr<InMemoryClient> client(new isc::datasrc::InMemoryClient());
-        applyConfig(*client, config);
-        return (client.release());
-    } catch (const isc::Exception& isce) {
-        error = isce.what();
-        return (NULL);
-    } catch (const std::exception& exc) {
-        error = std::string("Error creating memory datasource: ") + exc.what();
-        return (NULL);
-    } catch (...) {
-        error = std::string("Error creating memory datasource, "
-                            "unknown exception");
-        return (NULL);
-    }
-}
-
-void destroyInstance(DataSourceClient* instance) {
-    delete instance;
-}
-
-} // end of namespace datasrc
-} // end of namespace isc

+ 0 - 230
src/lib/datasrc/rbnode_rrset.h

@@ -1,230 +0,0 @@
-// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef RBNODE_RRSET_H
-#define RBNODE_RRSET_H
-
-#include <dns/messagerenderer.h>
-#include <dns/name.h>
-#include <dns/rrclass.h>
-#include <dns/rrset.h>
-#include <dns/rrttl.h>
-#include <dns/rrtype.h>
-#include <util/buffer.h>
-
-#include <string>
-#include <vector>
-
-namespace isc {
-namespace datasrc {
-namespace internal {
-
-/// \brief The actual content of \c RBNodeRRset
-///
-///  This is defined in the namespace-scope (not hidden in the main class)
-/// so that the In-memory data source implementation can refer to it.
-struct RBNodeRRsetImpl;
-
-// Forward declaration of an opaque data type defined and used within the
-// implementation.  This is public only because it needs to be used within
-// the in-memory data source implementation, but conceptually this is a
-// private type for the in-memory data source implementation.
-// Note that the definition of the structure is still hidden within the
-// implementation, so, basically, a normal application should never be able
-// to use it directly even if it peeks into the "internal" namespace.
-struct AdditionalNodeInfo;
-
-/// \brief Special RRset for optimizing memory datasource requirement
-///
-/// To speed up the performance of the in-memory data source, at load time
-/// associate relevant "additional section" data with each RRset in the
-/// data source.
-///
-/// This class, derived from AbstractRRset, holds a "const" pointer to the
-/// underlying RRset object.  All calls to methods on the class are passed to
-/// the underlying object.  However, there are some restrictions:
-///
-/// - Calls to methods that change attributes of the underlying RRset (such as
-///   TTL or Name) cause an exception to be thrown.  The in-memory data source
-///   does not allow modification of these attributes.  In theory, it is a bad
-///   practice in that it doesn't preserve the assumed behavior of the base
-///   class.  In practice, however, it should be acceptable because this
-///   class is effectively hidden from applications and will only be given
-///   to them as a const pointer to the base class via find() variants.
-///   So the application cannot call non const methods anyway unless it
-///   intentionally breaks the constness.
-///
-/// - Calls that add the pointer to the associated RRSIG to the RRset are
-///   allowed (even though the pointer is to a "const" RRset).  The reason here
-///   is that RRSIGs are added to the in-memory data source after the
-///   RBNodeRRset objects have been created.  Thus there has to be the
-///   capability of modifying this information.
-///
-/// The class is not derived from RRset itself to simplify coding: part of the
-/// loading of the memory data source is handled in the BIND 10 "libdns++"
-/// code, which creates RRsets and passes them to the data source code.  This
-/// does not have to be altered if encapsulation, rather than inheritance, is
-/// used.
-///
-/// \note This class is exposed in this separate header file so that test code
-/// can refer to its definition, and only for that purpose.  Otherwise this is
-/// essentially a private class of the in-memory data source implementation,
-/// and an application shouldn't directly refer to this class.
-///
-// Note: non-Doxygen-documented methods are documented in the base class.
-
-class RBNodeRRset : public isc::dns::AbstractRRset {
-
-private:
-    // Note: The copy constructor and the assignment operator are intentionally
-    // defined as private as we would normally not duplicate a RBNodeRRset.
-    // (We use the "private" method instead of inheriting from
-    // boost::noncopyable so as to avoid multiple inheritance.)
-    RBNodeRRset(const RBNodeRRset& source);
-    RBNodeRRset& operator=(const RBNodeRRset& source);
-
-public:
-    /// \brief Usual Constructor
-    ///
-    /// Creates an RBNodeRRset from the pointer to the RRset passed to it.
-    ///
-    /// \param rrset Pointer to underlying RRset encapsulated by this object.
-    explicit RBNodeRRset(const isc::dns::ConstRRsetPtr& rrset);
-
-    /// \brief Destructor
-    virtual ~RBNodeRRset();
-
-    // Getter and Setter Methods
-    //
-    // The getter methods pass the call through to the underlying RRset.  The
-    // setter methods thrown an exception - this specialisation of the RRset
-    // object does not expect the underlying RRset to be modified.
-
-    virtual unsigned int getRdataCount() const;
-
-    virtual const isc::dns::Name& getName() const;
-
-    virtual const isc::dns::RRClass& getClass() const;
-
-    virtual const isc::dns::RRType& getType() const;
-
-    virtual const isc::dns::RRTTL& getTTL() const;
-
-    virtual void setName(const isc::dns::Name&);
-
-    virtual void setTTL(const isc::dns::RRTTL&);
-
-    virtual std::string toText() const;
-
-    virtual bool isSameKind(const AbstractRRset& other) const {
-        // This code is an optimisation for comparing
-        // RBNodeRRsets. However, in doing this optimisation,
-        // semantically the code is not "is same kind" but is instead
-        // "is identical object" in the case where RBNodeRRsets are compared.
-
-        const RBNodeRRset* rb = dynamic_cast<const RBNodeRRset*>(&other);
-        if (rb != NULL) {
-            return (this == rb);
-        } else {
-            return (AbstractRRset::isSameKind(other));
-        }
-    }
-
-    virtual unsigned int toWire(
-        isc::dns::AbstractMessageRenderer& renderer) const;
-
-    virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const;
-
-    virtual void addRdata(isc::dns::rdata::ConstRdataPtr);
-
-    virtual void addRdata(const isc::dns::rdata::Rdata&);
-
-    virtual isc::dns::RdataIteratorPtr getRdataIterator() const;
-
-    virtual isc::dns::RRsetPtr getRRsig() const;
-
-    virtual unsigned int getRRsigDataCount() const;
-
-    // With all the RRsig methods, we have the problem that we store the
-    // underlying RRset using a ConstRRsetPtr - a pointer to a "const" RRset -
-    // but we need to modify it by adding or removing an RRSIG.  We overcome
-    // this by temporarily violating the "const" nature of the RRset to add the
-    // data.
-
-    virtual void addRRsig(const isc::dns::rdata::ConstRdataPtr& rdata);
-
-    virtual void addRRsig(const isc::dns::rdata::RdataPtr& rdata);
-
-    virtual void addRRsig(const AbstractRRset& sigs);
-
-    virtual void addRRsig(const isc::dns::ConstRRsetPtr& sigs);
-
-    virtual void addRRsig(const isc::dns::RRsetPtr& sigs);
-
-    virtual void removeRRsig();
-
-    /// \brief Associate a link to an RB node of the additional record.
-    ///
-    /// This method adds a given opaque object that holds a link to an RB node
-    /// of the underlying in-memory data source that is corresponding to an
-    /// RDATA of this RRset.
-    ///
-    /// This method is exposed as public so it can be used within the in-memory
-    /// data source implementation, and only for that purpose.
-    ///
-    /// \param additional An opaque \c AdditionalNodeInfo object to be
-    /// associated with this RRset.
-    void addAdditionalNode(const AdditionalNodeInfo& additional);
-
-    /// \brief Return a pointer to the list (vector) of additional RB nodes.
-    ///
-    /// This method returns a pointer to a vector storing the opaque
-    /// \c AdditionalNodeInfo object that may be possibly set in this RRset.
-    /// Not all RRsets are associated with additional nodes; if no
-    /// such node is stored, this method returns NULL.
-    ///
-    /// Like \c addAdditionalNode(), this method is exposed as public only for
-    /// the in-memory data source implementation.
-    ///
-    /// \return A pointer to the associated vector of \c AdditionalNodeInfo;
-    /// NULL if no additional nodes are associated to this RRset.
-    const std::vector<AdditionalNodeInfo>* getAdditionalNodes() const;
-
-    /// \brief Copy the list of additional RB nodes to another RRset.
-    ///
-    /// This method copies the internal list (an STL vector in the actual
-    /// implementation) of additional RB nodes for this RRset to another
-    /// \c RBNodeRRset object.  The copy destination is generally expected to
-    /// be newly created and have an empty list, but this method does not
-    /// check the condition.  If the destination already has a non empty list,
-    /// the existing entries will be lost.
-    ///
-    /// \param dst The \c RBNodeRRset object to which the additional
-    /// RB node list is to be copied.
-    void copyAdditionalNodes(RBNodeRRset& dst) const;
-
-    /// \brief Return underlying RRset pointer
-    ///
-    /// ... mainly for testing.
-    isc::dns::ConstRRsetPtr getUnderlyingRRset() const;
-
-private:
-    RBNodeRRsetImpl* impl_;
-};
-
-}   // namespace internal
-}   // namespace datasrc
-}   // namespace isc
-
-#endif  // RBNODE_RRSET_H

File diff suppressed because it is too large
+ 0 - 1993
src/lib/datasrc/rbtree.h


+ 50 - 0
src/lib/datasrc/static_datasrc.h

@@ -0,0 +1,50 @@
+// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+
+#ifndef DATASRC_STATIC_H
+#define DATASRC_STATIC_H
+
+#include <datasrc/database.h>
+#include <cc/data.h>
+
+#include <string>
+
+namespace isc {
+namespace datasrc {
+
+/// \brief Creates an instance of the static datasource client
+///
+/// Currently the configuration passed here must be a StringElement,
+/// containing the path to a zone file for the BIND./CH zone.
+///
+/// \param config The configuration for the datasource instance (see above)
+/// \param error This string will be set to an error message if an error occurs
+///              during initialization
+/// \return An instance of the static datasource client, or NULL if there was
+///         an error
+extern "C" DataSourceClient* createInstance(isc::data::ConstElementPtr config,
+                                            std::string& error);
+
+/// \brief Destroy the instance created by createInstance()
+extern "C" void destroyInstance(DataSourceClient* instance);
+
+}
+}
+
+#endif  // DATASRC_STATIC_H
+
+// Local Variables:
+// mode: c++
+// End:

+ 14 - 8
src/lib/datasrc/static_datasrc_link.cc

@@ -13,7 +13,9 @@
 // PERFORMANCE OF THIS SOFTWARE.
 // PERFORMANCE OF THIS SOFTWARE.
 
 
 #include "client.h"
 #include "client.h"
-#include "memory_datasrc.h"
+#include "static_datasrc.h"
+#include <datasrc/memory/memory_client.h>
+#include <datasrc/memory/zone_table_segment.h>
 
 
 #include <cc/data.h>
 #include <cc/data.h>
 #include <dns/rrclass.h>
 #include <dns/rrclass.h>
@@ -32,16 +34,20 @@ namespace datasrc {
 DataSourceClient*
 DataSourceClient*
 createInstance(ConstElementPtr config, string& error) {
 createInstance(ConstElementPtr config, string& error) {
     try {
     try {
+        // FIXME: Fix the config that should be passed to
+        // ZoneTableSegment::create() when it actually uses the config
+        // to do something.
+        shared_ptr<memory::ZoneTableSegment> ztable_segment(
+            memory::ZoneTableSegment::create(isc::data::NullElement(),
+                                             RRClass::CH()));
         // Create the data source
         // Create the data source
-        auto_ptr<InMemoryClient> client(new InMemoryClient());
-        // Hardcode the origin and class
-        shared_ptr<InMemoryZoneFinder>
-            finder(new InMemoryZoneFinder(RRClass::CH(), Name("BIND")));
+        auto_ptr<memory::InMemoryClient> client
+            (new memory::InMemoryClient(ztable_segment, RRClass::CH()));
+
         // Fill it with data
         // Fill it with data
         const string path(config->stringValue());
         const string path(config->stringValue());
-        finder->load(path);
-        // And put the zone inside
-        client->addZone(finder);
+        client->load(Name("BIND"), path);
+
         return (client.release());
         return (client.release());
     }
     }
     catch (const std::exception& e) {
     catch (const std::exception& e) {

+ 1 - 4
src/lib/datasrc/tests/Makefile.am

@@ -48,14 +48,10 @@ common_ldadd += $(GTEST_LDADD) $(SQLITE_LIBS)
 run_unittests_SOURCES = $(common_sources)
 run_unittests_SOURCES = $(common_sources)
 
 
 run_unittests_SOURCES += test_client.h test_client.cc
 run_unittests_SOURCES += test_client.h test_client.cc
-run_unittests_SOURCES += rbtree_unittest.cc
 run_unittests_SOURCES += logger_unittest.cc
 run_unittests_SOURCES += logger_unittest.cc
 run_unittests_SOURCES += client_unittest.cc
 run_unittests_SOURCES += client_unittest.cc
 run_unittests_SOURCES += database_unittest.cc
 run_unittests_SOURCES += database_unittest.cc
 run_unittests_SOURCES += sqlite3_accessor_unittest.cc
 run_unittests_SOURCES += sqlite3_accessor_unittest.cc
-run_unittests_SOURCES += memory_datasrc_unittest.cc
-run_unittests_SOURCES += rbnode_rrset_unittest.cc
-run_unittests_SOURCES += zonetable_unittest.cc
 run_unittests_SOURCES += zone_finder_context_unittest.cc
 run_unittests_SOURCES += zone_finder_context_unittest.cc
 run_unittests_SOURCES += faked_nsec3.h faked_nsec3.cc
 run_unittests_SOURCES += faked_nsec3.h faked_nsec3.cc
 run_unittests_SOURCES += client_list_unittest.cc
 run_unittests_SOURCES += client_list_unittest.cc
@@ -118,5 +114,6 @@ EXTRA_DIST += testdata/new_minor_schema.sqlite3
 EXTRA_DIST += testdata/newschema.sqlite3
 EXTRA_DIST += testdata/newschema.sqlite3
 EXTRA_DIST += testdata/oldschema.sqlite3
 EXTRA_DIST += testdata/oldschema.sqlite3
 EXTRA_DIST += testdata/static.zone
 EXTRA_DIST += testdata/static.zone
+EXTRA_DIST += testdata/static-bad.zone
 EXTRA_DIST += testdata/novalidate.zone
 EXTRA_DIST += testdata/novalidate.zone
 EXTRA_DIST += testdata/checkwarn.zone
 EXTRA_DIST += testdata/checkwarn.zone

+ 3 - 78
src/lib/datasrc/tests/factory_unittest.cc

@@ -29,6 +29,7 @@ using namespace isc::data;
 
 
 std::string SQLITE_DBFILE_EXAMPLE_ORG = TEST_DATA_DIR "/example.org.sqlite3";
 std::string SQLITE_DBFILE_EXAMPLE_ORG = TEST_DATA_DIR "/example.org.sqlite3";
 const std::string STATIC_DS_FILE = TEST_DATA_DIR "/static.zone";
 const std::string STATIC_DS_FILE = TEST_DATA_DIR "/static.zone";
+const std::string STATIC_BAD_DS_FILE = TEST_DATA_DIR "/static-bad.zone";
 const std::string ROOT_ZONE_FILE = TEST_DATA_DIR "/root.zone";
 const std::string ROOT_ZONE_FILE = TEST_DATA_DIR "/root.zone";
 
 
 namespace {
 namespace {
@@ -160,78 +161,6 @@ TEST(FactoryTest, sqlite3ClientBadConfig) {
         isc::dns::Name("example.org."), false));
         isc::dns::Name("example.org."), false));
 }
 }
 
 
-TEST(FactoryTest, memoryClient) {
-    // We start out by building the configuration data bit by bit,
-    // testing each form of 'bad config', until we have a good one.
-    // Then we do some very basic operation on the client (detailed
-    // tests are left to the implementation-specific backends)
-    ElementPtr config;
-    ASSERT_THROW(DataSourceClientContainer client("memory", config),
-                 DataSourceError);
-
-    config = Element::create("asdf");
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config = Element::createMap();
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config->set("type", ElementPtr());
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config->set("type", Element::create(1));
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config->set("type", Element::create("FOO"));
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config->set("type", Element::create("memory"));
-    // no config at all should result in a default empty memory client
-    ASSERT_NO_THROW(DataSourceClientContainer("memory", config));
-
-    config->set("class", ElementPtr());
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config->set("class", Element::create(1));
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config->set("class", Element::create("FOO"));
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config->set("class", Element::create("IN"));
-    ASSERT_NO_THROW(DataSourceClientContainer("memory", config));
-
-    config->set("zones", ElementPtr());
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config->set("zones", Element::create(1));
-    ASSERT_THROW(DataSourceClientContainer("memory", config),
-                 DataSourceError);
-
-    config->set("zones", Element::createList());
-    DataSourceClientContainer dsc("memory", config);
-
-    // Once it is able to load some zones, we should add a few tests
-    // here to see that it does.
-    DataSourceClient::FindResult result(
-        dsc.getInstance().findZone(isc::dns::Name("no.such.zone.")));
-    ASSERT_EQ(result::NOTFOUND, result.code);
-
-    ASSERT_THROW(dsc.getInstance().getIterator(isc::dns::Name("example.org.")),
-                 DataSourceError);
-
-    ASSERT_THROW(dsc.getInstance().getUpdater(isc::dns::Name("no.such.zone."),
-                                              false), isc::NotImplemented);
-}
-
 TEST(FactoryTest, badType) {
 TEST(FactoryTest, badType) {
     ASSERT_THROW(DataSourceClientContainer("foo", ElementPtr()),
     ASSERT_THROW(DataSourceClientContainer("foo", ElementPtr()),
                                            DataSourceError);
                                            DataSourceError);
@@ -259,13 +188,9 @@ TEST(FactoryTest, staticDS) {
 }
 }
 
 
 // Check that file not containing BIND./CH is rejected
 // Check that file not containing BIND./CH is rejected
-//
-// FIXME: This test is disabled because the InMemoryZoneFinder::load does
-// not check if the data loaded correspond with the origin. The static
-// factory is not the place to fix that.
-TEST(FactoryTest, DISABLED_staticDSBadFile) {
+TEST(FactoryTest, staticDSBadFile) {
     // The only configuration is the file to load.
     // The only configuration is the file to load.
-    const ConstElementPtr config(new StringElement(STATIC_DS_FILE));
+    const ConstElementPtr config(new StringElement(STATIC_BAD_DS_FILE));
     // See it does not want the file
     // See it does not want the file
     EXPECT_THROW(DataSourceClientContainer("static", config), DataSourceError);
     EXPECT_THROW(DataSourceClientContainer("static", config), DataSourceError);
 }
 }

File diff suppressed because it is too large
+ 0 - 2246
src/lib/datasrc/tests/memory_datasrc_unittest.cc


+ 0 - 276
src/lib/datasrc/tests/rbnode_rrset_unittest.cc

@@ -1,276 +0,0 @@
-// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <exceptions/exceptions.h>
-#include <dns/rdataclass.h>
-#include <datasrc/rbnode_rrset.h>
-#include <testutils/dnsmessage_test.h>
-
-#include <dns/tests/unittest_util.h>
-
-#include <gtest/gtest.h>
-
-#include <sstream>
-#include <stdexcept>
-
-using isc::UnitTestUtil;
-
-using namespace isc;
-using namespace isc::datasrc;
-using namespace isc::datasrc::internal;
-using namespace isc::dns;
-using namespace isc::dns::rdata;
-using namespace isc::testutils;
-using namespace isc::util;
-using namespace std;
-
-// These tests are very similar to those for RRset - indeed, this file was
-// created from those tests.  However, the significant difference in behaviour
-// between RRset and RBNodeRRset - that the "set" methods in the latter mostly
-// result in exceptions being thrown - preclude use of full type
-// parameterisation of the tests.
-
-namespace {
-const char* const RRSIG_TXT =
-    "A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
-    "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
-    "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
-    "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
-    "f49t+sXKPzbipN9g+s1ZPiIyofc=";
-
-class RBNodeRRsetTest : public ::testing::Test {
-protected:
-    RBNodeRRsetTest() :
-        test_name("test.example.com"),
-        test_domain("example.com"),
-        test_nsname("ns.example.com"),
-        rrset_a(ConstRRsetPtr(new RRset(
-                test_name, RRClass::IN(), RRType::A(), RRTTL(3600)))),
-        rrset_a_empty(ConstRRsetPtr(new RRset(
-                      test_name, RRClass::IN(), RRType::A(), RRTTL(3600)))),
-        rrset_ns(ConstRRsetPtr(new RRset(
-                 test_domain, RRClass::IN(), RRType::NS(), RRTTL(86400)))),
-        rrset_ch_txt(ConstRRsetPtr(new RRset(
-                     test_domain, RRClass::CH(), RRType::TXT(), RRTTL(0)))),
-        rrset_siga(new RRset(test_name, RRClass::IN(), RRType::RRSIG(),
-                   RRTTL(3600)))
-
-    {
-        // Add a couple of Rdata elements to the A RRset.  The easiest way to
-        // do this is to override the "const" restrictions.  As this is a test,
-        // we don't feel too bad about doing so.
-        AbstractRRset* a_rrset =
-            const_cast<AbstractRRset*>(rrset_a.getUnderlyingRRset().get());
-        a_rrset->addRdata(in::A("192.0.2.1"));
-        a_rrset->addRdata(in::A("192.0.2.2"));
-
-        // Create the RRSIG corresponding to the rrset_a record.  The RDATA
-        // won't match the A record it covers, although it is internally
-        // self-consistent.
-        AbstractRRset* sig_rrset =
-            const_cast<AbstractRRset*>(rrset_siga.get());
-        sig_rrset->addRdata(generic::RRSIG(RRSIG_TXT));
-    }
-
-    const Name test_name;
-    const Name test_domain;
-    const Name test_nsname;
-
-    RBNodeRRset rrset_a;
-    RBNodeRRset rrset_a_empty;
-    const RBNodeRRset rrset_ns;
-    const RBNodeRRset rrset_ch_txt;
-
-    ConstRRsetPtr rrset_siga;
-};
-
-TEST_F(RBNodeRRsetTest, getRdataCount) {
-    EXPECT_EQ(0, rrset_a_empty.getRdataCount());
-    EXPECT_EQ(2, rrset_a.getRdataCount());
-}
-
-TEST_F(RBNodeRRsetTest, getName) {
-    EXPECT_EQ(test_name, rrset_a.getName());
-    EXPECT_EQ(test_domain, rrset_ns.getName());
-}
-
-TEST_F(RBNodeRRsetTest, getClass) {
-    EXPECT_EQ(RRClass("IN"), rrset_a.getClass());
-    EXPECT_EQ(RRClass("CH"), rrset_ch_txt.getClass());
-}
-
-TEST_F(RBNodeRRsetTest, getType) {
-    EXPECT_EQ(RRType("A"), rrset_a.getType());
-    EXPECT_EQ(RRType("NS"), rrset_ns.getType());
-    EXPECT_EQ(RRType("TXT"), rrset_ch_txt.getType());
-}
-
-TEST_F(RBNodeRRsetTest, getTTL) {
-    EXPECT_EQ(RRTTL(3600), rrset_a.getTTL());
-    EXPECT_EQ(RRTTL(86400), rrset_ns.getTTL());
-    EXPECT_EQ(RRTTL(0), rrset_ch_txt.getTTL());
-}
-
-TEST_F(RBNodeRRsetTest, setName) {
-    EXPECT_THROW(rrset_a.setName(test_nsname), NotImplemented);
-}
-
-TEST_F(RBNodeRRsetTest, setTTL) {
-    EXPECT_THROW(rrset_a.setTTL(RRTTL(86400)), NotImplemented);
-}
-
-TEST_F(RBNodeRRsetTest, toText) {
-    EXPECT_EQ("test.example.com. 3600 IN A 192.0.2.1\n"
-              "test.example.com. 3600 IN A 192.0.2.2\n",
-              rrset_a.toText());
-
-    // toText() cannot be performed for an empty RRset.
-    EXPECT_THROW(rrset_a_empty.toText(), EmptyRRset);
-}
-
-TEST_F(RBNodeRRsetTest, isSameKind) {
-    RBNodeRRset rrset_p(ConstRRsetPtr(new RRset(test_name, RRClass::IN(), RRType::A(), RRTTL(3600))));
-    RBNodeRRset rrset_q(ConstRRsetPtr(new RRset(test_name, RRClass::IN(), RRType::A(), RRTTL(3600))));
-    RRset rrset_w(test_name, RRClass::IN(), RRType::A(), RRTTL(3600));
-    RRset rrset_x(test_nsname, RRClass::IN(), RRType::A(), RRTTL(3600));
-    RRset rrset_y(test_name, RRClass::IN(), RRType::NS(), RRTTL(3600));
-    RRset rrset_z(test_name, RRClass::CH(), RRType::A(), RRTTL(3600));
-
-    EXPECT_TRUE(rrset_p.isSameKind(rrset_p));
-    EXPECT_FALSE(rrset_p.isSameKind(rrset_q));
-
-    EXPECT_TRUE(rrset_p.isSameKind(rrset_w));
-    EXPECT_FALSE(rrset_p.isSameKind(rrset_x));
-    EXPECT_FALSE(rrset_p.isSameKind(rrset_y));
-    EXPECT_FALSE(rrset_p.isSameKind(rrset_z));
-}
-
-// Note: although the next two tests are essentially the same and used common
-// test code, they use different test data: the MessageRenderer produces
-// compressed wire data whereas the OutputBuffer does not.
-
-template <typename T>
-void
-performToWireTest(T& dataHolder, const RBNodeRRset& rrset,
-                  const RBNodeRRset& rrset_empty, const char* testdata)
-{
-    rrset.toWire(dataHolder);
-
-    std::vector<unsigned char> wiredata;
-    UnitTestUtil::readWireData(testdata, wiredata);
-    EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, dataHolder.getData(),
-                        dataHolder.getLength(), &wiredata[0], wiredata.size());
-
-    // toWire() cannot be performed for an empty RRset.
-    dataHolder.clear();
-    EXPECT_THROW(rrset_empty.toWire(dataHolder), EmptyRRset);
-}
-
-TEST_F(RBNodeRRsetTest, toWireRenderer) {
-    MessageRenderer renderer;
-    performToWireTest(renderer, rrset_a, rrset_a_empty, "rrset_toWire2");
-}
-
-TEST_F(RBNodeRRsetTest, toWireBuffer) {
-    OutputBuffer buffer(0);
-    performToWireTest(buffer, rrset_a, rrset_a_empty, "rrset_toWire1");
-}
-
-TEST_F(RBNodeRRsetTest, addRdata) {
-    EXPECT_THROW(rrset_a.addRdata(in::A("192.0.2.3")), NotImplemented);
-
-    // Check the same goes for trying to add the wrong type of data
-    EXPECT_THROW(rrset_a.addRdata(generic::NS(test_nsname)), NotImplemented);
-}
-
-TEST_F(RBNodeRRsetTest, addRdataPtr) {
-    EXPECT_THROW(rrset_a_empty.addRdata(createRdata(rrset_a_empty.getType(),
-                                                    rrset_a_empty.getClass(),
-                                                    "192.0.2.1")),
-                 NotImplemented);
-}
-
-TEST_F(RBNodeRRsetTest, getRDataIterator) {
-    RdataIteratorPtr it = rrset_a.getRdataIterator();
-    for (int i = 0; i < 2; ++i) {
-        ASSERT_FALSE(it->isLast());
-        ASSERT_EQ(0, it->getCurrent().compare(in::A("192.0.2.1")));
-
-        it->next();
-        ASSERT_FALSE(it->isLast());
-        ASSERT_EQ(0, it->getCurrent().compare(in::A("192.0.2.2")));
-
-        it->next();
-        ASSERT_TRUE(it->isLast());
-
-        // Should be able repeat the iteration by calling first().
-        it->first();
-    }
-}
-
-// test operator<<.  We simply confirm it appends the result of toText().
-TEST_F(RBNodeRRsetTest, LeftShiftOperator) {
-    ostringstream oss;
-    oss << rrset_a;
-    EXPECT_EQ("test.example.com. 3600 IN A 192.0.2.1\n"
-              "test.example.com. 3600 IN A 192.0.2.2\n", oss.str());
-}
-
-// addRRSIG tests.
-TEST_F(RBNodeRRsetTest, addRRsigConstRdataPointer) {
-    EXPECT_FALSE(rrset_a.getRRsig());
-    ConstRdataPtr data = createRdata(rrset_siga->getType(),
-                                     rrset_siga->getClass(), RRSIG_TXT);
-    rrset_a.addRRsig(data);
-    rrsetCheck(rrset_siga, rrset_a.getRRsig());
-}
-
-TEST_F(RBNodeRRsetTest, addRRsigRdataPointer) {
-    EXPECT_FALSE(rrset_a.getRRsig());
-    RdataPtr data = createRdata(rrset_siga->getType(), rrset_siga->getClass(),
-                                RRSIG_TXT);
-    rrset_a.addRRsig(data);
-    rrsetCheck(rrset_siga, rrset_a.getRRsig());
-}
-
-TEST_F(RBNodeRRsetTest, addRRsigAbstractRRset) {
-    EXPECT_FALSE(rrset_a.getRRsig());
-    rrset_a.addRRsig(*(rrset_siga.get()));
-    rrsetCheck(rrset_siga, rrset_a.getRRsig());
-}
-
-TEST_F(RBNodeRRsetTest, addRRsigConstantRRsetPointer) {
-    EXPECT_FALSE(rrset_a.getRRsig());
-    rrset_a.addRRsig(rrset_siga);
-    rrsetCheck(rrset_siga, rrset_a.getRRsig());
-}
-
-TEST_F(RBNodeRRsetTest, addRRsigRRsetPointer) {
-    EXPECT_FALSE(rrset_a.getRRsig());
-    RRsetPtr rrsig(new RRset(test_name, RRClass::IN(), RRType::RRSIG(),
-                   RRTTL(3600)));
-    rrsig->addRdata(generic::RRSIG(RRSIG_TXT));
-    rrset_a.addRRsig(rrsig);
-    rrsetCheck(rrset_siga, rrset_a.getRRsig());
-}
-
-TEST_F(RBNodeRRsetTest, removeRRsig) {
-    EXPECT_FALSE(rrset_a.getRRsig());
-    rrset_a.addRRsig(*(rrset_siga.get()));
-    EXPECT_TRUE(rrset_a.getRRsig());
-    rrset_a.removeRRsig();
-    EXPECT_FALSE(rrset_a.getRRsig());
-}
-
-}   // Anonymous namespace

File diff suppressed because it is too large
+ 0 - 1074
src/lib/datasrc/tests/rbtree_unittest.cc


+ 3 - 0
src/lib/datasrc/tests/testdata/static-bad.zone

@@ -0,0 +1,3 @@
+NOTBIND.           3600    CH  SOA NOTBIND. NOTBIND. 4 3600 300 36000 3600
+NOTBIND.           3600    CH  NS  NOTBIND.
+VERSION.NOTBIND.   3600    CH  TXT "10"

+ 2 - 1
src/lib/datasrc/tests/testdata/static.zone

@@ -1,2 +1,3 @@
-BIND.           3600    CH  SOA BIND. BIND. 1 3600 300 36000 3600
+BIND.           3600    CH  SOA BIND. BIND. 3 3600 300 36000 3600
+BIND.           3600    CH  NS  BIND.
 VERSION.BIND.   3600    CH  TXT "10"
 VERSION.BIND.   3600    CH  TXT "10"

+ 0 - 128
src/lib/datasrc/tests/zonetable_unittest.cc

@@ -1,128 +0,0 @@
-// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <exceptions/exceptions.h>
-
-#include <util/memory_segment_local.h>
-
-#include <dns/name.h>
-#include <dns/rrclass.h>
-
-#include <datasrc/zonetable.h>
-// We use InMemoryZone to put something into the table
-#include <datasrc/memory_datasrc.h>
-
-#include <gtest/gtest.h>
-
-using namespace isc::dns;
-using namespace isc::datasrc;
-
-namespace {
-TEST(ZoneTest, init) {
-    InMemoryZoneFinder zone(RRClass::IN(), Name("example.com"));
-    EXPECT_EQ(Name("example.com"), zone.getOrigin());
-    EXPECT_EQ(RRClass::IN(), zone.getClass());
-
-    InMemoryZoneFinder ch_zone(RRClass::CH(), Name("example"));
-    EXPECT_EQ(Name("example"), ch_zone.getOrigin());
-    EXPECT_EQ(RRClass::CH(), ch_zone.getClass());
-}
-
-TEST(ZoneTest, find) {
-    InMemoryZoneFinder zone(RRClass::IN(), Name("example.com"));
-    EXPECT_EQ(ZoneFinder::NXDOMAIN,
-              zone.find(Name("www.example.com"), RRType::A())->code);
-}
-
-class ZoneTableTest : public ::testing::Test {
-protected:
-    ZoneTableTest() : zone1(new InMemoryZoneFinder(RRClass::IN(),
-                                                   Name("example.com"))),
-                      zone2(new InMemoryZoneFinder(RRClass::IN(),
-                                                   Name("example.net"))),
-                      zone3(new InMemoryZoneFinder(RRClass::IN(),
-                                                   Name("example"))),
-                      zone_table(ZoneTable::create(mem_sgmt_))
-    {}
-
-    ~ZoneTableTest() {
-        ZoneTable::destroy(mem_sgmt_, zone_table);
-    }
-    ZoneFinderPtr zone1, zone2, zone3;
-    isc::util::MemorySegmentLocal mem_sgmt_;
-    ZoneTable* zone_table;
-};
-
-TEST_F(ZoneTableTest, addZone) {
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone1));
-    EXPECT_EQ(result::EXIST, zone_table->addZone(mem_sgmt_, zone1));
-    // names are compared in a case insensitive manner.
-    EXPECT_EQ(result::EXIST, zone_table->addZone(
-                  mem_sgmt_,
-                  ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(),
-                                                       Name("EXAMPLE.COM")))));
-
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone2));
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone3));
-
-    // Zone table is indexed only by name.  Duplicate origin name with
-    // different zone class isn't allowed.
-    EXPECT_EQ(result::EXIST, zone_table->addZone(
-                  mem_sgmt_,
-                  ZoneFinderPtr(new InMemoryZoneFinder(RRClass::CH(),
-                                                       Name("example.com")))));
-
-    /// Bogus zone (NULL)
-    EXPECT_THROW(zone_table->addZone(mem_sgmt_, ZoneFinderPtr()),
-                 isc::InvalidParameter);
-}
-
-TEST_F(ZoneTableTest, DISABLED_removeZone) {
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone1));
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone2));
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone3));
-
-    EXPECT_EQ(result::SUCCESS, zone_table->removeZone(Name("example.net")));
-    EXPECT_EQ(result::NOTFOUND, zone_table->removeZone(Name("example.net")));
-}
-
-TEST_F(ZoneTableTest, findZone) {
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone1));
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone2));
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone3));
-
-    EXPECT_EQ(result::SUCCESS, zone_table->findZone(Name("example.com")).code);
-    EXPECT_EQ(Name("example.com"),
-              zone_table->findZone(Name("example.com")).zone->getOrigin());
-
-    EXPECT_EQ(result::NOTFOUND,
-              zone_table->findZone(Name("example.org")).code);
-    EXPECT_EQ(ConstZoneFinderPtr(),
-              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(result::PARTIALMATCH,
-              zone_table->findZone(Name("www.example.com")).code);
-    EXPECT_EQ(Name("example.com"),
-              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.
-    ZoneFinderPtr zone_com(new InMemoryZoneFinder(RRClass::IN(), Name("com")));
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zone_com));
-    EXPECT_EQ(Name("example.com"),
-              zone_table->findZone(Name("www.example.com")).zone->getOrigin());
-}
-}

+ 0 - 160
src/lib/datasrc/zonetable.cc

@@ -1,160 +0,0 @@
-// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <util/memory_segment.h>
-
-#include <dns/name.h>
-
-#include <datasrc/zonetable.h>
-#include <datasrc/rbtree.h>
-
-#include <cassert>
-
-using namespace std;
-using namespace isc::dns;
-
-namespace isc {
-namespace datasrc {
-
-/// \short Private data and implementation of ZoneTable
-struct ZoneTable::ZoneTableImpl {
-    // Type aliases to make it shorter
-    typedef RBTree<ZoneFinder> ZoneTree;
-    typedef RBNode<ZoneFinder> ZoneNode;
-
-    // The actual storage
-    ZoneTree* zones_;
-
-    // Constructor
-    ZoneTableImpl(util::MemorySegment& mem_sgmt) :
-        zones_(ZoneTree::create(mem_sgmt))
-    {}
-
-    /*
-     * The implementation methods are here and just wrap-called in the
-     * ZoneTable. We have variables locally (without impl_->), have
-     * type aliases, etc. And they will get inlined anyway.
-     */
-
-    // Implementation of ZoneTable::addZone
-    result::Result addZone(util::MemorySegment& mem_sgmt, ZoneFinderPtr zone) {
-        // Sanity check
-        if (!zone) {
-            isc_throw(InvalidParameter,
-                      "Null pointer is passed to ZoneTable::addZone()");
-        }
-
-        // Get the node where we put the zone
-        ZoneNode* node(NULL);
-        switch (zones_->insert(mem_sgmt, zone->getOrigin(), &node)) {
-            // This is OK
-            case ZoneTree::SUCCESS:
-            case ZoneTree::ALREADYEXISTS:
-                break;
-            // Can Not Happen
-            default:
-                assert(0);
-        }
-        // Can Not Happen
-        assert(node);
-
-        // Is it empty? We either just created it or it might be nonterminal
-        if (node->isEmpty()) {
-            node->setData(zone);
-            return (result::SUCCESS);
-        } else { // There's something there already
-            return (result::EXIST);
-        }
-    }
-
-    // Implementation of ZoneTable::findZone
-    ZoneTable::FindResult findZone(const Name& name) const {
-        ZoneNode *node(NULL);
-        result::Result my_result;
-
-        // Translate the return codes
-        switch (zones_->find(name, &node)) {
-            case ZoneTree::EXACTMATCH:
-                my_result = result::SUCCESS;
-                break;
-            case ZoneTree::PARTIALMATCH:
-                my_result = result::PARTIALMATCH;
-                break;
-            // We have no data there, so translate the pointer to NULL as well
-            case ZoneTree::NOTFOUND:
-                return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
-            // Can Not Happen
-            default:
-                assert(0);
-                // Because of warning
-                return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
-        }
-
-        // Can Not Happen (remember, NOTFOUND is handled)
-        assert(node);
-
-        return (FindResult(my_result, node->getData()));
-    }
-};
-
-ZoneTable::ZoneTable(util::MemorySegment& mem_sgmt) :
-    impl_(new ZoneTableImpl(mem_sgmt))
-{}
-
-ZoneTable::~ZoneTable() {
-    delete impl_;
-}
-
-ZoneTable*
-ZoneTable::create(util::MemorySegment& mem_sgmt) {
-    // The ZoneTable constructor can throw, so we need to prevent memory leak.
-    // This is ugly, but for now this seems to be the only place we need
-    // this, and since we'll substantially revise this code soon, so we don't
-    // work around it by this hack at the moment.
-    void* p = mem_sgmt.allocate(sizeof(ZoneTable));
-    try {
-        return (new(p) ZoneTable(mem_sgmt));
-    } catch (...) {
-        mem_sgmt.deallocate(p, sizeof(ZoneTable));
-        throw;
-    }
-}
-
-void
-ZoneTable::destroy(util::MemorySegment& mem_sgmt, ZoneTable* ztable) {
-    ZoneTableImpl::ZoneTree::destroy(mem_sgmt, ztable->impl_->zones_);
-    ztable->~ZoneTable();
-    mem_sgmt.deallocate(ztable, sizeof(ZoneTable));
-}
-
-result::Result
-ZoneTable::addZone(util::MemorySegment& mem_sgmt, ZoneFinderPtr zone) {
-    return (impl_->addZone(mem_sgmt, zone));
-}
-
-result::Result
-ZoneTable::removeZone(const Name&) {
-    // TODO Implement
-    assert(0);
-    // This should not ever be returned, the assert should kill us by now
-    return (result::SUCCESS);
-}
-
-ZoneTable::FindResult
-ZoneTable::findZone(const Name& name) const {
-    return (impl_->findZone(name));
-}
-
-} // end of namespace datasrc
-} // end of namespace isc

+ 0 - 160
src/lib/datasrc/zonetable.h

@@ -1,160 +0,0 @@
-// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef ZONETABLE_H
-#define ZONETABLE_H 1
-
-#include <util/memory_segment.h>
-
-#include <dns/rrset.h>
-
-#include <datasrc/zone_finder.h>
-
-#include <boost/shared_ptr.hpp>
-
-namespace isc {
-namespace dns {
-class Name;
-class RRClass;
-}
-
-namespace datasrc {
-
-/// \brief A set of authoritative zones.
-///
-/// \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:
-    struct FindResult {
-        FindResult(result::Result param_code, const ZoneFinderPtr param_zone) :
-            code(param_code), zone(param_zone)
-        {}
-        const result::Result code;
-        const ZoneFinderPtr zone;
-    };
-    ///
-    /// \name Constructors and Destructor.
-    ///
-    /// \b Note:
-    /// The copy constructor and the assignment operator are intentionally
-    /// defined as private, making this class non copyable.
-    //@{
-private:
-    ZoneTable(const ZoneTable& source);
-    ZoneTable& operator=(const ZoneTable& source);
-
-    /// Constructor.
-    ///
-    /// An object of this class is always expected to be created by the
-    /// allocator (\c create()), so the constructor is hidden as private.
-    ///
-    /// This constructor internally involves resource allocation, and if
-    /// it fails, a corresponding standard exception will be thrown.
-    /// It never throws an exception otherwise.
-    ZoneTable(util::MemorySegment& mem_sgmt);
-
-    /// The destructor.
-    ///
-    /// An object of this class is always expected to be destroyed explicitly
-    /// by \c destroy(), so the constructor is hidden as private.
-    ~ZoneTable();
-    //@}
-
-public:
-    /// \brief Allocate and construct \c ZoneTable
-    ///
-    /// This static method allocates memory for a new \c ZoneTable object
-    /// from the given memory segment, constructs the object, and returns
-    /// a pointer to it.
-    ///
-    /// \throw std::bad_alloc Memory allocation fails.
-    ///
-    /// \param mem_sgmt A \c MemorySegment from which memory for the new
-    /// \c ZoneTable is allocated.
-    static ZoneTable* create(util::MemorySegment& mem_sgmt);
-
-    /// \brief Destruct and deallocate \c ZoneTable
-    ///
-    /// \throw none
-    ///
-    /// \param mem_sgmt The \c MemorySegment that allocated memory for
-    /// \c ztable.
-    /// \param ztable A non NULL pointer to a valid \c ZoneTable object
-    /// that was originally created by the \c create() method (the behavior
-    /// is undefined if this condition isn't met).
-    static void destroy(util::MemorySegment& mem_sgmt, ZoneTable* ztable);
-
-    /// 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 result::SUCCESS If the zone is successfully
-    /// added to the zone table.
-    /// \return \c result::EXIST The zone table already contains
-    /// zone of the same origin.
-    result::Result addZone(util::MemorySegment& mem_sgmt, ZoneFinderPtr 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 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 result::SUCCESS: A zone that gives an exact match
-    ///    is found
-    ///   - \c result::PARTIALMATCH: A zone whose origin is a
-    ///    super domain of \c name is found (but there is no exact match)
-    ///   - \c 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 FindResult object enclosing the search result (see above).
-    FindResult findZone(const isc::dns::Name& name) const;
-
-private:
-    struct ZoneTableImpl;
-    ZoneTableImpl* impl_;
-};
-}
-}
-#endif  // ZONETABLE_H
-
-// Local Variables:
-// mode: c++
-// End:

+ 1 - 0
src/lib/python/isc/datasrc/tests/Makefile.am

@@ -11,6 +11,7 @@ EXTRA_DIST += testdata/oldschema.sqlite3
 EXTRA_DIST += testdata/new_minor_schema.sqlite3
 EXTRA_DIST += testdata/new_minor_schema.sqlite3
 EXTRA_DIST += testdata/example.com
 EXTRA_DIST += testdata/example.com
 EXTRA_DIST += testdata/example.com.ch
 EXTRA_DIST += testdata/example.com.ch
+EXTRA_DIST += testdata/static.zone
 CLEANFILES = $(abs_builddir)/rwtest.sqlite3.copied
 CLEANFILES = $(abs_builddir)/rwtest.sqlite3.copied
 CLEANFILES += $(abs_builddir)/zoneloadertest.sqlite3
 CLEANFILES += $(abs_builddir)/zoneloadertest.sqlite3
 
 

+ 14 - 12
src/lib/python/isc/datasrc/tests/datasrc_test.py

@@ -34,6 +34,8 @@ WRITE_ZONE_DB_FILE = TESTDATA_WRITE_PATH + "rwtest.sqlite3.copied"
 READ_ZONE_DB_CONFIG = "{ \"database_file\": \"" + READ_ZONE_DB_FILE + "\" }"
 READ_ZONE_DB_CONFIG = "{ \"database_file\": \"" + READ_ZONE_DB_FILE + "\" }"
 WRITE_ZONE_DB_CONFIG = "{ \"database_file\": \"" + WRITE_ZONE_DB_FILE + "\"}"
 WRITE_ZONE_DB_CONFIG = "{ \"database_file\": \"" + WRITE_ZONE_DB_FILE + "\"}"
 
 
+STATIC_ZONE_CONFIG = '"' + TESTDATA_PATH + "static.zone" + '"'
+
 def add_rrset(rrset_list, name, rrclass, rrtype, ttl, rdatas):
 def add_rrset(rrset_list, name, rrclass, rrtype, ttl, rdatas):
     rrset_to_add = isc.dns.RRset(name, rrclass, rrtype, ttl)
     rrset_to_add = isc.dns.RRset(name, rrclass, rrtype, ttl)
     if rdatas is not None:
     if rdatas is not None:
@@ -129,9 +131,6 @@ class DataSrcClient(unittest.TestCase):
         self.assertRaises(isc.datasrc.Error,
         self.assertRaises(isc.datasrc.Error,
                           isc.datasrc.DataSourceClient, "sqlite3",
                           isc.datasrc.DataSourceClient, "sqlite3",
                           "{ \"foo\": 1 }")
                           "{ \"foo\": 1 }")
-        self.assertRaises(isc.datasrc.Error,
-                          isc.datasrc.DataSourceClient, "memory",
-                          "{ \"foo\": 1 }")
 
 
     def test_iterate(self):
     def test_iterate(self):
         dsc = isc.datasrc.DataSourceClient("sqlite3", READ_ZONE_DB_CONFIG)
         dsc = isc.datasrc.DataSourceClient("sqlite3", READ_ZONE_DB_CONFIG)
@@ -564,14 +563,16 @@ class DataSrcUpdater(unittest.TestCase):
         self.assertEqual(updater_refs, sys.getrefcount(updater))
         self.assertEqual(updater_refs, sys.getrefcount(updater))
 
 
     def test_two_modules(self):
     def test_two_modules(self):
-        # load two modules, and check if they don't interfere
-        mem_cfg = { "type": "memory", "class": "IN", "zones": [] };
-        dsc_mem = isc.datasrc.DataSourceClient("memory", json.dumps(mem_cfg))
+        # load two modules, and check if they don't interfere; as the
+        # memory datasource module no longer exists, we check the static
+        # datasource instead (as that uses the memory datasource
+        # anyway).
+        dsc_static = isc.datasrc.DataSourceClient("static", STATIC_ZONE_CONFIG)
         dsc_sql = isc.datasrc.DataSourceClient("sqlite3", READ_ZONE_DB_CONFIG)
         dsc_sql = isc.datasrc.DataSourceClient("sqlite3", READ_ZONE_DB_CONFIG)
 
 
         # check if exceptions are working
         # check if exceptions are working
         self.assertRaises(isc.datasrc.Error, isc.datasrc.DataSourceClient,
         self.assertRaises(isc.datasrc.Error, isc.datasrc.DataSourceClient,
-                          "memory", "{}")
+                          "static", "\"\"")
         self.assertRaises(isc.datasrc.Error, isc.datasrc.DataSourceClient,
         self.assertRaises(isc.datasrc.Error, isc.datasrc.DataSourceClient,
                           "sqlite3", "{}")
                           "sqlite3", "{}")
 
 
@@ -587,11 +588,10 @@ class DataSrcUpdater(unittest.TestCase):
         self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
         self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
                          rrset.to_text())
                          rrset.to_text())
 
 
-        # see if a lookup fails in mem ds
-        result, finder = dsc_mem.find_zone(isc.dns.Name("example.com"))
+        # see if a lookup fails in static ds
+        result, finder = dsc_static.find_zone(isc.dns.Name("example"))
         self.assertEqual(finder.NXDOMAIN, result)
         self.assertEqual(finder.NXDOMAIN, result)
 
 
-
     def test_update_delete_abort(self):
     def test_update_delete_abort(self):
         # we don't do enything with this one, just making sure loading two
         # we don't do enything with this one, just making sure loading two
         # datasources
         # datasources
@@ -724,8 +724,10 @@ class DataSrcUpdater(unittest.TestCase):
         self.assertTrue(dsc.delete_zone(zone_name))
         self.assertTrue(dsc.delete_zone(zone_name))
 
 
     def test_create_zone_not_implemented(self):
     def test_create_zone_not_implemented(self):
-        mem_cfg = '{ "type": "memory", "class": "IN", "zones": [] }';
-        dsc = isc.datasrc.DataSourceClient("memory", mem_cfg)
+        # As the memory datasource module no longer exists, we check the
+        # static datasource instead (as that uses the memory datasource
+        # anyway).
+        dsc = isc.datasrc.DataSourceClient("static", STATIC_ZONE_CONFIG)
         self.assertRaises(isc.datasrc.NotImplemented, dsc.create_zone,
         self.assertRaises(isc.datasrc.NotImplemented, dsc.create_zone,
                           isc.dns.Name("example.com"))
                           isc.dns.Name("example.com"))
 
 

+ 3 - 0
src/lib/python/isc/datasrc/tests/testdata/static.zone

@@ -0,0 +1,3 @@
+BIND.           3600    CH  SOA BIND. BIND. 3 3600 300 36000 3600
+BIND.           3600    CH  NS  BIND.
+VERSION.BIND.   3600    CH  TXT "10"

+ 10 - 4
src/lib/python/isc/datasrc/tests/zone_loader_test.py

@@ -34,6 +34,7 @@ ORIG_DB_FILE = TESTDATA_PATH + '/example.com.sqlite3'
 DB_FILE = TESTDATA_WRITE_PATH + '/zoneloadertest.sqlite3'
 DB_FILE = TESTDATA_WRITE_PATH + '/zoneloadertest.sqlite3'
 DB_CLIENT_CONFIG = '{ "database_file": "' + DB_FILE + '" }'
 DB_CLIENT_CONFIG = '{ "database_file": "' + DB_FILE + '" }'
 DB_SOURCE_CLIENT_CONFIG = '{ "database_file": "' + SOURCE_DB_FILE + '" }'
 DB_SOURCE_CLIENT_CONFIG = '{ "database_file": "' + SOURCE_DB_FILE + '" }'
+STATIC_ZONE_CONFIG = '"' + TESTDATA_PATH + "/static.zone" + '"'
 
 
 ORIG_SOA_TXT = 'example.com. 3600 IN SOA master.example.com. ' +\
 ORIG_SOA_TXT = 'example.com. 3600 IN SOA master.example.com. ' +\
                'admin.example.com. 1234 3600 1800 2419200 7200\n'
                'admin.example.com. 1234 3600 1800 2419200 7200\n'
@@ -215,10 +216,15 @@ class ZoneLoaderTests(unittest.TestCase):
                           self.client, zone_name, self.source_client)
                           self.client, zone_name, self.source_client)
 
 
     def test_no_ds_load_support(self):
     def test_no_ds_load_support(self):
-        # This may change in the future, but atm, the in-mem ds does
-        # not support the API the zone loader uses (it has direct load calls)
-        inmem_client = isc.datasrc.DataSourceClient('memory',
-                                                    '{ "type": "memory" }');
+        # As the memory datasource module no longer exists, we check the
+        # static datasource instead (as that uses the memory datasource
+        # anyway).
+        #
+        # This may change in the future, but ATM, the static ds does not
+        # support the API the zone loader uses (it has direct load
+        # calls).
+        inmem_client = isc.datasrc.DataSourceClient('static',
+                                                    STATIC_ZONE_CONFIG);
         self.assertRaises(isc.datasrc.NotImplemented,
         self.assertRaises(isc.datasrc.NotImplemented,
                           isc.datasrc.ZoneLoader,
                           isc.datasrc.ZoneLoader,
                           inmem_client, self.test_name, self.test_file)
                           inmem_client, self.test_name, self.test_file)