]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2905] implemented the concept of "empty zone data"
authorJINMEI Tatuya <jinmei@isc.org>
Fri, 17 May 2013 23:52:44 +0000 (16:52 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Fri, 17 May 2013 23:52:44 +0000 (16:52 -0700)
this will be used instead of NULL in later part of this branch.
(NULL won't work because it would create an unintended empty node).

src/lib/datasrc/memory/zone_data.cc
src/lib/datasrc/memory/zone_data.h
src/lib/datasrc/tests/memory/zone_data_unittest.cc

index bb626c1654bb10f9385c77598d2f904553b96c0b..a1d3430e923432037d5f6449d1d36fd6fc1bf124 100644 (file)
@@ -179,6 +179,13 @@ ZoneData::create(util::MemorySegment& mem_sgmt, const Name& zone_origin) {
     return (zone_data);
 }
 
+ZoneData*
+ZoneData::create(util::MemorySegment& mem_sgmt) {
+    ZoneData* zone_data = create(mem_sgmt, Name::ROOT_NAME());
+    zone_data->origin_node_->setFlag(EMPTY_ZONE);
+    return (zone_data);
+}
+
 void
 ZoneData::destroy(util::MemorySegment& mem_sgmt, ZoneData* zone_data,
                   RRClass zone_class)
index d511e472f515827f66e33278fbd538d28c79fd50..4d717714ab416a2dbb15a410fd3b7d17c55d7410 100644 (file)
@@ -384,11 +384,16 @@ private:
     // to indicate whether the zone is signed or not.  Internal use,
     // so defined as private.
     static const ZoneNode::Flags DNSSEC_SIGNED = ZoneNode::FLAG_USER1;
+
+    // Also set in the origin node, indicating this is a special "empty zone",
+    // that could be created only by the corresponding create() method to be
+    // used for some kind of sentinel data.
+    static const ZoneNode::Flags EMPTY_ZONE = ZoneNode::FLAG_USER2;
 public:
     /// \brief Node flag indicating it is at a "wildcard level"
     ///
     /// This means one of the node's immediate children is a wildcard.
-    static const ZoneNode::Flags WILDCARD_NODE = ZoneNode::FLAG_USER2;
+    static const ZoneNode::Flags WILDCARD_NODE = ZoneNode::FLAG_USER3;
 
 public:
     /// \brief Allocate and construct \c ZoneData.
@@ -410,6 +415,23 @@ public:
     static ZoneData* create(util::MemorySegment& mem_sgmt,
                             const dns::Name& zone_origin);
 
+    /// \brief Allocate and construct a special "empty" \c ZoneData.
+    ///
+    /// A ZoneData object created this way holds all internal integrity
+    /// that those created by the other \c create() method have, but is not
+    /// publicly associated with any actual zone data.  It's intended to be
+    /// used as a kind of sentinel data to representing the concept such as
+    /// "broken zone".
+    ///
+    /// Methods calls on empty \c ZoneData object except \c destroy() and
+    /// \c isEmpty() are meaningless, while they shouldn't cause disruption.
+    /// It's caller's responsibility to use empty zone data objects in the
+    /// intended way.
+    ///
+    /// \param mem_sgmt A \c MemorySegment from which memory for the new
+    /// \c ZoneData is allocated.
+    static ZoneData* create(util::MemorySegment& mem_sgmt);
+
     /// \brief Destruct and deallocate \c ZoneData.
     ///
     /// It releases all resource allocated in the internal storage NSEC3 for
@@ -482,6 +504,13 @@ public:
     /// \throw none
     bool isNSEC3Signed() const { return (nsec3_data_); }
 
+    /// \brief Return whether or not the zone data is "empty".
+    ///
+    /// See the description of \c create() for the concept of empty zone data.
+    ///
+    /// \throw None
+    bool isEmpty() const { return (origin_node_->getFlag(EMPTY_ZONE)); }
+
     /// \brief Return NSEC3Data of the zone.
     ///
     /// This method returns non-NULL valid pointer to \c NSEC3Data object
index 983e5882c651cf37d36a5749d227cbf58b486bd1..54a0fc49695e705672c6546b10a4f16f6413e80e 100644 (file)
@@ -277,4 +277,14 @@ TEST_F(ZoneDataTest, minTTL) {
     zone_data_->setMinTTL(1200);
     EXPECT_EQ(RRTTL(1200), createRRTTL(zone_data_->getMinTTLData()));
 }
+
+TEST_F(ZoneDataTest, emptyData) {
+    // normally create zone data are never "empty"
+    EXPECT_FALSE(zone_data_->isEmpty());
+
+    // zone data instance created by the special create() is made "empty".
+    ZoneData* empty_data = ZoneData::create(mem_sgmt_);
+    EXPECT_TRUE(empty_data->isEmpty());
+    ZoneData::destroy(mem_sgmt_, empty_data, RRClass::IN());
+}
 }