Commit 0d8f1b7c authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2098] supported toText().

parent 4b07f9b7
......@@ -318,4 +318,30 @@ TEST_F(TreeNodeRRsetTest, getRdataIterator) {
TreeNodeRRset(rrclass_, origin_node_, ns_rdataset_,
false).getRdataIterator());
}
void
checkToText(const AbstractRRset& actual_rrset,
ConstRRsetPtr expected_rrset, ConstRRsetPtr expected_sig_rrset)
{
const string actual_text = actual_rrset.toText();
const string expected_text =
(expected_rrset ? expected_rrset->toText() : "") +
(expected_sig_rrset ? expected_sig_rrset->toText() : "");
EXPECT_EQ(expected_text, actual_text);
}
TEST_F(TreeNodeRRsetTest, toText) {
// Constructed with RRSIG, and it should be visible.
checkToText(TreeNodeRRset(rrclass_, www_node_, a_rdataset_, true),
a_rrset_, a_rrsig_rrset_);
// Constructed with RRSIG, and it should be invisible.
checkToText(TreeNodeRRset(rrclass_, www_node_, a_rdataset_, false),
a_rrset_, ConstRRsetPtr());
// Constructed without RRSIG, and it would be visible (but of course won't)
checkToText(TreeNodeRRset(rrclass_, origin_node_, ns_rdataset_, true),
ns_rrset_, ConstRRsetPtr());
// Constructed without RRSIG, and it should be visible
checkToText(TreeNodeRRset(rrclass_, origin_node_, ns_rdataset_, false),
ns_rrset_, ConstRRsetPtr());
}
}
......@@ -68,10 +68,46 @@ TreeNodeRRset::setTTL(const RRTTL&) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
// needed
std::string
TreeNodeRRset::toText() const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
// Create TTL from internal data
util::InputBuffer ttl_buffer(rdataset_->getTTLData(), sizeof(uint32_t));
const RRTTL ttl(ttl_buffer);
// Dump the main RRset, if not empty
std::string ret;
RRsetPtr tmp_rrset;
for (RdataIteratorPtr rit = getRdataIterator();
!rit->isLast();
rit->next())
{
if (!tmp_rrset) {
tmp_rrset = RRsetPtr(new RRset(getName(), rrclass_, getType(),
ttl));
}
tmp_rrset->addRdata(rit->getCurrent());
}
if (tmp_rrset) {
ret = tmp_rrset->toText();
}
// Dump any RRSIGs
tmp_rrset.reset();
for (RdataIteratorPtr rit = getSigRdataIterator();
!rit->isLast();
rit->next())
{
if (!tmp_rrset) {
tmp_rrset = RRsetPtr(new RRset(getName(), rrclass_,
RRType::RRSIG(), ttl));
}
tmp_rrset->addRdata(rit->getCurrent());
}
if (tmp_rrset) {
ret += tmp_rrset->toText();
}
return (ret);
}
namespace {
......@@ -214,7 +250,7 @@ renderDataToBuffer(const void* data, size_t data_len,
}
RdataIteratorPtr
TreeNodeRRset::getRdataIterator() const {
TreeNodeRRset::getRdataIteratorInternal(bool is_rrsig, size_t count) const {
util::OutputBuffer buffer(0);
RdataReader reader(rrclass_, rdataset_->type, rdataset_->getDataBuf(),
rdataset_->getRdataCount(), rrsig_count_,
......@@ -222,17 +258,29 @@ TreeNodeRRset::getRdataIterator() const {
boost::bind(renderDataToBuffer, _1, _2, &buffer));
std::vector<ConstRdataPtr> rdata_list;
for (size_t i = 0; i < rdataset_->getRdataCount(); ++i) {
for (size_t i = 0; i < count; ++i) {
buffer.clear();
const bool rendered = reader.iterateRdata();
const bool rendered = is_rrsig ? reader.iterateSingleSig() :
reader.iterateRdata();
assert(rendered == true);
util::InputBuffer ib(buffer.getData(), buffer.getLength());
rdata_list.push_back(createRdata(rdataset_->type, rrclass_,
ib, ib.getLength()));
rdata_list.push_back(
createRdata(is_rrsig ? RRType::RRSIG() : rdataset_->type, rrclass_,
ib, ib.getLength()));
}
return (RdataIteratorPtr(new TreeNodeRdataIterator(rdata_list)));
}
RdataIteratorPtr
TreeNodeRRset::getRdataIterator() const {
return (getRdataIteratorInternal(false, rdataset_->getRdataCount()));
}
RdataIteratorPtr
TreeNodeRRset::getSigRdataIterator() const {
return (getRdataIteratorInternal(true, dnssec_ok_ ? rrsig_count_ : 0));
}
RRsetPtr
TreeNodeRRset::getRRsig() const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
......
......@@ -113,6 +113,10 @@ public:
virtual bool isSameKind(const dns::AbstractRRset& other) const;
private:
dns::RdataIteratorPtr getSigRdataIterator() const;
dns::RdataIteratorPtr getRdataIteratorInternal(bool is_rrsig,
size_t count) const;
const ZoneNode* node_;
const RdataSet* rdataset_;
const size_t rrsig_count_;
......
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