Browse Source

Update according to review comments

* Removed delegation code, as it is wrong and needs to be addressed in a
  more sophisticated way.
* Make MemoryZone::add strong exception safe at the interface level.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac447@3987 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
f369da7638
2 changed files with 19 additions and 22 deletions
  1. 17 11
      src/lib/datasrc/memory_datasrc.cc
  2. 2 11
      src/lib/datasrc/tests/memory_datasrc_unittest.cc

+ 17 - 11
src/lib/datasrc/memory_datasrc.cc

@@ -114,6 +114,13 @@ struct MemoryZone::MemoryZoneImpl {
         if (node->isEmpty()) {
             domain.reset(new Domain);
             node->setData(domain);
+            /*
+             * If something throws exception past this point, we did change
+             * the internal structure. But as an empty domain is taken as
+             * nonexistant one, it is strongly exception safe at the interface
+             * level even when the internal representation of the state
+             * changes.
+             */
         } else { // Get existing one
             domain = node->getData();
         }
@@ -133,16 +140,12 @@ struct MemoryZone::MemoryZoneImpl {
         try {
             // Get the relative name
             Name relative_name(getRelativeName(full_name));
-            // What we return when we succeed.
-            bool delegation(false);
             // Get the node
             DomainNode* node;
             switch (domains_.find(relative_name, &node)) {
                 case DomainTree::PARTIALMATCH:
-                    // We change to looking for a NS record in the node
-                    delegation = true;
-                    type = RRType::NS();
-                    break; // And handle it the usual way
+                    // Pretend it was not found for now
+                    // TODO: Implement real delegation
                 case DomainTree::NOTFOUND:
                     return (FindResult(NXDOMAIN, ConstRRsetPtr()));
                 case DomainTree::EXACTMATCH: // This one is OK, handle it
@@ -156,17 +159,20 @@ struct MemoryZone::MemoryZoneImpl {
             Domain::const_iterator found(node->getData()->find(type));
             if (found != node->getData()->end()) {
                 // Good, it is here
-                // Return either SUCCESS or DELEGATION
-                return (FindResult(delegation ? DELEGATION : SUCCESS,
-                    found->second));
+                return (FindResult(SUCCESS, found->second));
             } else {
                 /*
                  * TODO Look for CNAME and DNAME (it should be OK to do so when
                  * the value is not found, as CNAME/DNAME domain should be
                  * empty otherwise.)
                  */
-                if (delegation) {
-                    // If we were trying a delegation, then we have NXDOMAIN
+                if(node->getData()->empty()) {
+                    /*
+                     * In case the domain is empty, it is the same as if it
+                     * does not exist. It probably got here by unsuccessful
+                     * add, so just remove it, it is useless.
+                     */
+                    node->setData(DomainPtr());
                     return (FindResult(NXDOMAIN, ConstRRsetPtr()));
                 } else {
                     return (FindResult(NXRRSET, ConstRRsetPtr()));

+ 2 - 11
src/lib/datasrc/tests/memory_datasrc_unittest.cc

@@ -126,9 +126,7 @@ public:
         rr_ns_(new RRset(origin_, class_, RRType::NS(), RRTTL(300))),
         rr_ns_a_(new RRset(ns_name_, class_, RRType::A(), RRTTL(300))),
         rr_ns_aaaa_(new RRset(ns_name_, class_, RRType::AAAA(), RRTTL(300))),
-        rr_a_(new RRset(origin_, class_, RRType::A(), RRTTL(300))),
-        rr_delegation_(new RRset(Name("subdomain.example.org"), class_,
-            RRType::NS(), RRTTL(300)))
+        rr_a_(new RRset(origin_, class_, RRType::A(), RRTTL(300)))
     {
     }
     // Some data to test with
@@ -153,9 +151,7 @@ public:
         // AAAA of ns.example.org
         rr_ns_aaaa_,
         // A of example.org
-        rr_a_,
-        // A subdomain.example.org NS, for delegation
-        rr_delegation_;
+        rr_a_;
 
     /**
      * \brief Test one find query to the zone.
@@ -233,7 +229,6 @@ TEST_F(MemoryZoneTest, find) {
     EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_.add(rr_ns_a_)));
     EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_.add(rr_ns_aaaa_)));
     EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_.add(rr_a_)));
-    EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_.add(rr_delegation_)));
 
     // These two should be successful
     findTest(origin_, RRType::NS(), Zone::SUCCESS, rr_ns_);
@@ -246,10 +241,6 @@ TEST_F(MemoryZoneTest, find) {
     // These domains don't exist (and one is out of the zone)
     findTest(Name("nothere.example.org"), RRType::A(), Zone::NXDOMAIN);
     findTest(Name("example.net"), RRType::A(), Zone::NXDOMAIN);
-
-    // This should delegate
-    findTest(Name("a.subdomain.example.org"), RRType::MX(), Zone::DELEGATION,
-        rr_delegation_);
 }
 
 }