Browse Source

Add nameserver manipulation to zone entry

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac408@3512 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
8f823b9fa0
2 changed files with 46 additions and 1 deletions
  1. 18 0
      src/lib/nsas/tests/zone_entry_unittest.cc
  2. 28 1
      src/lib/nsas/zone_entry.h

+ 18 - 0
src/lib/nsas/tests/zone_entry_unittest.cc

@@ -21,6 +21,7 @@
 
 #include "../asiolink.h"
 #include "../zone_entry.h"
+#include "../nameserver_entry.h"
 #include "../address_request_callback.h"
 
 #include "nsas_test.h"
@@ -77,5 +78,22 @@ TEST_F(ZoneEntryTest, Callbacks) {
     EXPECT_FALSE(zone.hasCallbacks());
 }
 
+TEST_F(ZoneEntryTest, Nameserver_iterators) {
+    ZoneEntry zone(EXAMPLE_CO_UK, RRClass::IN().getCode());
+    shared_ptr<NameserverEntry> nse(new NameserverEntry(EXAMPLE_CO_UK,
+        RRClass::IN().getCode()));
+    // The iterator can't be printed, so we can't use EQ
+    const ZoneEntry& zone_const(zone);
+    EXPECT_TRUE(zone.begin() == zone.end());
+    EXPECT_TRUE(zone_const.begin() == zone_const.end());
+    zone.nameserver_add(nse);
+    EXPECT_FALSE(zone.begin() == zone.end());
+    EXPECT_FALSE(zone_const.begin() == zone_const.end());
+    EXPECT_TRUE(*zone.begin() == nse);
+    EXPECT_TRUE(*zone_const.begin() == nse);
+    EXPECT_TRUE(zone.begin() + 1 == zone.end());
+    EXPECT_TRUE(zone_const.begin() + 1 == zone_const.end());
+}
+
 }   // namespace nsas
 }   // namespace isc

+ 28 - 1
src/lib/nsas/zone_entry.h

@@ -89,11 +89,38 @@ public:
     /// \short Remove a callback from queue and return it
     boost::shared_ptr<AddressRequestCallback> popCallback();
 
+    /// \short Nameserver entry pointer
+    typedef boost::shared_ptr<NameserverEntry> NameserverPtr;
+    /// \short Vector of nameservers
+    typedef std::vector<NameserverPtr> NameserverVector;
+    /// \short Iterators to the nameservers
+    typedef NameserverVector::iterator iterator;
+    typedef NameserverVector::const_iterator const_iterator;
+
+    /**
+     * \short Add a nameserver pointer to this zone.
+     *
+     * This does not lock, as it should be called while it is being created.
+     * No new nameservers should be added later (it should timeout first and
+     * be rebuild). Calling this after addition to the NameserverAddressStore
+     * is undefined (it is not thread safe).
+     */
+    void nameserver_add(NameserverPtr ns) { nameservers_.push_back(ns); }
+    /**
+     * \short Iterators for the nameservers.
+     *
+     * They do not lock, as the nameservers should be read only during
+     * the life of the zone.
+     */
+    iterator begin() { return (nameservers_.begin()); }
+    iterator end() { return (nameservers_.end()); }
+    const_iterator begin() const { return (nameservers_.begin()); }
+    const_iterator end() const { return (nameservers_.end()); }
 private:
     mutable boost::mutex    mutex_;     ///< Mutex protecting this zone entry
     std::string     name_;      ///< Canonical zone name
     uint16_t        classCode_; ///< Class code
-    std::vector<boost::shared_ptr<NameserverEntry> > nameservers_; ///< Nameservers
+    NameserverVector nameservers_; ///< Nameservers
     time_t          expiry_;    ///< Expiry time of this entry
     std::list<boost::shared_ptr<AddressRequestCallback> > callbacks_;
 };