Commit 2afcb422 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2905] implemented the concept of "empty zone data"

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).
parent a41cac42
......@@ -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)
......
......@@ -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
......
......@@ -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());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment