BIND 10 trac1177, updated. 38d80ef7186ac2b18ed234a825894f5f78fc90b1 [1177] Concatenate on strings

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Sep 19 13:50:29 UTC 2011


The branch, trac1177 has been updated
       via  38d80ef7186ac2b18ed234a825894f5f78fc90b1 (commit)
       via  88bee2515653d3b5481608bc92a1956c7ea7cf48 (commit)
       via  e9286ce511be095f2b16b1b7bc503b1e4377593d (commit)
       via  723a6d1f333f1d513d5e4fe26a8ee7611767c9fc (commit)
       via  88fe1bafce118f40d256097c2bfbdf9e53553784 (commit)
      from  51c4b53945599a72d550d7380c7107e11b467d5c (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 38d80ef7186ac2b18ed234a825894f5f78fc90b1
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Sep 19 15:14:45 2011 +0200

    [1177] Concatenate on strings

commit 88bee2515653d3b5481608bc92a1956c7ea7cf48
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Sep 19 14:34:23 2011 +0200

    [1177] Remove unneeded static variable

commit e9286ce511be095f2b16b1b7bc503b1e4377593d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Sep 19 14:22:57 2011 +0200

    [1177] Allow NSEC and DS together with NS

commit 723a6d1f333f1d513d5e4fe26a8ee7611767c9fc
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Sep 19 14:16:17 2011 +0200

    [1177] Cleanup: removed exception variable names

commit 88fe1bafce118f40d256097c2bfbdf9e53553784
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Sep 19 14:16:03 2011 +0200

    [1177] Added missing documentation

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

Summary of changes:
 src/lib/datasrc/database.cc |   70 +++++++++++++++++++++++++------------------
 src/lib/datasrc/database.h  |   33 ++++++++++++++++++--
 2 files changed, 71 insertions(+), 32 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/database.cc b/src/lib/datasrc/database.cc
index 8cc7092..bb5be93 100644
--- a/src/lib/datasrc/database.cc
+++ b/src/lib/datasrc/database.cc
@@ -175,8 +175,8 @@ private:
 }
 
 DatabaseClient::Finder::FoundRRsets
-DatabaseClient::Finder::getRRsets(const Name& name, const WantedTypes& types,
-                                  bool check_ns, const Name* construct_name)
+DatabaseClient::Finder::getRRsets(const string& name, const WantedTypes& types,
+                                  bool check_ns, const string* construct_name)
 {
     RRsigStore sig_store;
     bool records_found = false;
@@ -184,11 +184,10 @@ DatabaseClient::Finder::getRRsets(const Name& name, const WantedTypes& types,
 
     // Request the context
     DatabaseAccessor::IteratorContextPtr
-        context(accessor_->getRecords(name.toText(), zone_id_));
+        context(accessor_->getRecords(name, zone_id_));
     // It must not return NULL, that's a bug of the implementation
     if (!context) {
-        isc_throw(isc::Unexpected, "Iterator context null at " +
-                  name.toText());
+        isc_throw(isc::Unexpected, "Iterator context null at " + name);
     }
 
     std::string columns[DatabaseAccessor::COLUMN_COUNT];
@@ -196,7 +195,10 @@ DatabaseClient::Finder::getRRsets(const Name& name, const WantedTypes& types,
         construct_name = &name;
     }
 
+    const Name construct_name_object(*construct_name);
+
     bool seen_cname(false);
+    bool seen_ds(false);
     bool seen_other(false);
     bool seen_ns(false);
 
@@ -233,8 +235,8 @@ DatabaseClient::Finder::getRRsets(const Name& name, const WantedTypes& types,
                 // contains an rrtype that is different from the actual value
                 // of the 'type covered' field in the RRSIG Rdata).
                 //cur_sigtype(columns[SIGTYPE_COLUMN]);
-                addOrCreate(result[cur_type], *construct_name, getClass(),
-                            cur_type, cur_ttl,
+                addOrCreate(result[cur_type], construct_name_object,
+                            getClass(), cur_type, cur_ttl,
                             columns[DatabaseAccessor::RDATA_COLUMN],
                             *accessor_);
             }
@@ -243,25 +245,31 @@ DatabaseClient::Finder::getRRsets(const Name& name, const WantedTypes& types,
                 seen_cname = true;
             } else if (cur_type == RRType::NS()) {
                 seen_ns = true;
-            } else if (cur_type != RRType::RRSIG()) {//RRSIG can live anywhere
-                // FIXME: Is something else allowed in the delegation point? DS?
+            } else if (cur_type == RRType::DS()) {
+                seen_ds = true;
+            } else if (cur_type != RRType::RRSIG() &&
+                       cur_type != RRType::NSEC3() &&
+                       cur_type != RRType::NSEC()) {
+                // NSEC and RRSIG can coexist with anything, otherwise
+                // we've seen something that can't live together with potential
+                // CNAME or NS
                 seen_other = true;
             }
-        } catch (const InvalidRRType& irt) {
+        } catch (const InvalidRRType&) {
             isc_throw(DataSourceError, "Invalid RRType in database for " <<
                       name << ": " << columns[DatabaseAccessor::
                       TYPE_COLUMN]);
-        } catch (const InvalidRRTTL& irttl) {
+        } catch (const InvalidRRTTL&) {
             isc_throw(DataSourceError, "Invalid TTL in database for " <<
                       name << ": " << columns[DatabaseAccessor::
                       TTL_COLUMN]);
-        } catch (const rdata::InvalidRdataText& ird) {
+        } catch (const rdata::InvalidRdataText&) {
             isc_throw(DataSourceError, "Invalid rdata in database for " <<
                       name << ": " << columns[DatabaseAccessor::
                       RDATA_COLUMN]);
         }
     }
-    if (seen_cname && (seen_other || seen_ns)) {
+    if (seen_cname && (seen_other || seen_ns || seen_ds)) {
         isc_throw(DataSourceError, "CNAME shares domain " << name <<
                   " with something else");
     }
@@ -295,11 +303,17 @@ DatabaseClient::Finder::hasSubdomains(const std::string& name) {
 // Some manipulation with RRType sets
 namespace {
 
-const std::set<RRType> empty_types;
-
 // To conveniently put the RRTypes into the sets. This is not really clean
 // design, but it is hidden inside this file and makes the calls much more
 // convenient.
+//
+// While this is not straightforward use of the + operator, some mathematical
+// conventions do allow summing sets with elements (usually in communitative
+// way, we define only one order of the operator parameters, as the other
+// isn't used).
+//
+// This arguably produces more readable code than having bunch of proxy
+// functions and set.insert calls scattered through the code.
 std::set<RRType> operator +(std::set<RRType> set, const RRType& type) {
     set.insert(type);
     return (set);
@@ -328,7 +342,7 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
     // we can't do it under NS, so we store it here to check
     isc::dns::RRsetPtr first_ns;
     // This is used at multiple places
-    static const WantedTypes nsec_types(empty_types + RRType::NSEC());
+    static const WantedTypes nsec_types(WantedTypes() + RRType::NSEC());
 
     // First, do we have any kind of delegation (NS/DNAME) here?
     const Name origin(getOrigin());
@@ -346,10 +360,11 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
     for (int i(remove_labels); i > 0; --i) {
         Name superdomain(name.split(i));
         // Look if there's NS or DNAME (but ignore the NS in origin)
-        static const WantedTypes delegation_types(empty_types +
+        static const WantedTypes delegation_types(WantedTypes() +
                                                   RRType::DNAME() +
                                                   RRType::NS());
-        found = getRRsets(superdomain, delegation_types, i != remove_labels);
+        found = getRRsets(superdomain.toText(), delegation_types,
+                          i != remove_labels);
         if (found.first) {
             // It contains some RRs, so it exists.
             last_known = superdomain.getLabelCount();
@@ -394,9 +409,9 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
         // It is special if there's a CNAME or NS, DNAME is ignored here
         // And we don't consider the NS in origin
 
-        static const WantedTypes final_types(empty_types + RRType::CNAME() +
+        static const WantedTypes final_types(WantedTypes() + RRType::CNAME() +
                                              RRType::NS() + RRType::NSEC());
-        found = getRRsets(name, final_types + type, name != origin);
+        found = getRRsets(name.toText(), final_types + type, name != origin);
         records_found = found.first;
 
         // NS records, CNAME record and Wanted Type records
@@ -439,21 +454,18 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
                 // Go up to first non-empty domain.
 
                 remove_labels = current_label_count - last_known;
-                const Name star("*");
                 for (size_t i(1); i <= remove_labels; ++ i) {
                     // Construct the name with *
-                    // TODO: Once the underlying DatabaseAccessor takes
-                    // string, do the concatenation on strings, not
-                    // Names
                     const Name superdomain(name.split(i));
-                    const Name wildcard(star.concatenate(superdomain));
+                    const string wildcard("*." + superdomain.toText());
+                    const string construct_name(name.toText());
                     // TODO What do we do about DNAME here?
-                    static const WantedTypes wildcard_types(empty_types +
+                    static const WantedTypes wildcard_types(WantedTypes() +
                                                             RRType::CNAME() +
                                                             RRType::NS() +
                                                             RRType::NSEC());
                     found = getRRsets(wildcard, wildcard_types + type, true,
-                                      &name);
+                                      &construct_name);
                     if (found.first) {
                         if (first_ns) {
                             // In case we are under NS, we don't
@@ -521,7 +533,7 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
                                 arg(name).arg(superdomain);
                         }
                         break;
-                    } else if (hasSubdomains(wildcard.toText())) {
+                    } else if (hasSubdomains(wildcard)) {
                         // Empty non-terminal asterisk
                         records_found = true;
                         get_cover = dnssec_data;
@@ -558,7 +570,7 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
                     // Which one should contain the NSEC record?
                     const Name coverName(findPreviousName(name));
                     // Get the record and copy it out
-                    found = getRRsets(coverName, nsec_types, true);
+                    found = getRRsets(coverName.toText(), nsec_types, true);
                     const FoundIterator
                         nci(found.second.find(RRType::NSEC()));
                     if (nci != found.second.end()) {
diff --git a/src/lib/datasrc/database.h b/src/lib/datasrc/database.h
index c9c2bc5..7d36508 100644
--- a/src/lib/datasrc/database.h
+++ b/src/lib/datasrc/database.h
@@ -640,9 +640,36 @@ public:
             FoundRRsets;
         /// \brief Just shortcut for set of types
         typedef std::set<dns::RRType> WantedTypes;
-        FoundRRsets getRRsets(const dns::Name& name, const WantedTypes& types,
-                              bool check_ns,
-                              const dns::Name* construct_name = NULL);
+        /**
+         * \brief Searches database for RRsets of one domain.
+         *
+         * This method scans RRs of single domain specified by name and
+         * extracts any RRsets found and requested by parameters.
+         *
+         * It is used internally by find(), because it is called multiple
+         * times (usually with different domains).
+         *
+         * \param name Which domain name should be scanned.
+         * \param types List of types the caller is interested in.
+         * \param check_ns If this is set to true, it checks nothing lives
+         *     together with NS record (with few little exceptions, like RRSET
+         *     or NSEC). This check is meant for non-apex NS records.
+         * \param construct_name If this is NULL, the resulting RRsets have
+         *     their name set to name. If it is not NULL, it overrides the name
+         *     and uses this one (this can be used for wildcard synthesized
+         *     records).
+         * \return A pair, where the first element indicates if the domain
+         *     contains any RRs at all (not only the requested, it may happen
+         *     this is set to true, but the second part is empty). The second
+         *     part is map from RRtypes to RRsets of the corresponding types.
+         *     If the RRset is not present in DB, the RRtype is not there at
+         *     all (so you'll not find NULL pointer in the result).
+         * \throw DataSourceError If there's a low-level error with the
+         *     database or the database contains bad data.
+         */
+        FoundRRsets getRRsets(const std::string& name,
+                              const WantedTypes& types, bool check_ns,
+                              const std::string* construct_name = NULL);
         /**
          * \brief Checks if something lives below this domain.
          *




More information about the bind10-changes mailing list