BIND 10 trac1065, updated. 59b545e90d30444a97c8e925569d240c819d42b4 [1065] Support for subdomain match

BIND 10 source code commits bind10-changes at lists.isc.org
Sat Aug 13 15:09:49 UTC 2011


The branch, trac1065 has been updated
       via  59b545e90d30444a97c8e925569d240c819d42b4 (commit)
      from  7e89c625c5d12b5816c857d0c0910922f8803f82 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 59b545e90d30444a97c8e925569d240c819d42b4
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Sat Aug 13 17:05:20 2011 +0200

    [1065] Support for subdomain match
    
    Only in the interface and test implementation for now. The SQLite
    version just ignores the parameter for now, will be done soon in this
    branch.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/database.h                 |    8 ++++++-
 src/lib/datasrc/sqlite3_accessor.cc        |    2 +-
 src/lib/datasrc/sqlite3_accessor.h         |    4 ++-
 src/lib/datasrc/tests/database_unittest.cc |   33 ++++++++++++++++++++++------
 4 files changed, 37 insertions(+), 10 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/database.h b/src/lib/datasrc/database.h
index 5253e60..187f5b1 100644
--- a/src/lib/datasrc/database.h
+++ b/src/lib/datasrc/database.h
@@ -84,8 +84,14 @@ public:
      *
      * \param zone_id The zone to search in, as returned by getZone()
      * \param name The name of the records to find
+     * \param subdomains If set to true, match subdomains of name instead
+     *     of name itself. It is used to find empty domains and match
+     *     wildcards.
+     * \todo Should we return the name as well? If we search for subdomains
+     *     it might be useful (and needed in case of wildcard).
      */
-    virtual void searchForRecords(int zone_id, const std::string& name) = 0;
+    virtual void searchForRecords(int zone_id, const std::string& name,
+                                  bool subdomains = false) = 0;
 
     /**
      * \brief Retrieves the next record from the search started with searchForRecords()
diff --git a/src/lib/datasrc/sqlite3_accessor.cc b/src/lib/datasrc/sqlite3_accessor.cc
index 817d530..e66aff4 100644
--- a/src/lib/datasrc/sqlite3_accessor.cc
+++ b/src/lib/datasrc/sqlite3_accessor.cc
@@ -323,7 +323,7 @@ SQLite3Database::getZone(const isc::dns::Name& name) const {
 }
 
 void
-SQLite3Database::searchForRecords(int zone_id, const std::string& name) {
+SQLite3Database::searchForRecords(int zone_id, const std::string& name, bool) {
     resetSearch();
     if (sqlite3_bind_int(dbparameters_->q_any_, 1, zone_id) != SQLITE_OK) {
         isc_throw(DataSourceError,
diff --git a/src/lib/datasrc/sqlite3_accessor.h b/src/lib/datasrc/sqlite3_accessor.h
index 4c2ec8b..a7f9bb6 100644
--- a/src/lib/datasrc/sqlite3_accessor.h
+++ b/src/lib/datasrc/sqlite3_accessor.h
@@ -100,8 +100,10 @@ public:
      *
      * \param zone_id The zone to seach in, as returned by getZone()
      * \param name The name to find records for
+     * \param subdomains Match subdomains instead of the name.
      */
-    virtual void searchForRecords(int zone_id, const std::string& name);
+    virtual void searchForRecords(int zone_id, const std::string& name,
+                                  bool subdomains = false);
 
     /**
      * \brief Retrieve the next record from the search started with
diff --git a/src/lib/datasrc/tests/database_unittest.cc b/src/lib/datasrc/tests/database_unittest.cc
index 0496081..e6a208e 100644
--- a/src/lib/datasrc/tests/database_unittest.cc
+++ b/src/lib/datasrc/tests/database_unittest.cc
@@ -54,7 +54,9 @@ public:
         }
     }
 
-    virtual void searchForRecords(int zone_id, const std::string& name) {
+    virtual void searchForRecords(int zone_id, const std::string& name,
+                                  bool subdomains)
+    {
         search_running_ = true;
 
         // 'hardcoded' name to trigger exceptions (for testing
@@ -69,14 +71,29 @@ public:
         }
         searched_name_ = name;
 
-        // we're not aiming for efficiency in this test, simply
-        // copy the relevant vector from records
         cur_record = 0;
         if (zone_id == 42) {
-            if (records.count(name) > 0) {
-                cur_name = records.find(name)->second;
-            } else {
+            if (subdomains) {
                 cur_name.clear();
+                // Just walk everything and check if it is a subdomain.
+                // If it is, just copy all data from there.
+                for (Domains::iterator i(records.begin()); i != records.end();
+                     ++ i) {
+                    Name local(i->first);
+                    if (local.compare(isc::dns::Name(name)).getRelation() ==
+                        isc::dns::NameComparisonResult::SUBDOMAIN) {
+                        cur_name.insert(cur_name.end(), i->second.begin(),
+                                        i->second.end());
+                    }
+                }
+            } else {
+                if (records.count(name) > 0) {
+                    // we're not aiming for efficiency in this test, simply
+                    // copy the relevant vector from records
+                    cur_name = records.find(name)->second;
+                } else {
+                    cur_name.clear();
+                }
             }
         } else {
             cur_name.clear();
@@ -119,7 +136,9 @@ public:
         return (database_name_);
     }
 private:
-    std::map<std::string, std::vector< std::vector<std::string> > > records;
+    typedef std::map<std::string, std::vector< std::vector<std::string> > >
+        Domains;
+    Domains records;
     // used as internal index for getNextRecord()
     size_t cur_record;
     // used as temporary storage after searchForRecord() and during




More information about the bind10-changes mailing list