Kea  1.9.9-git
rrcollator.cc
Go to the documentation of this file.
1 // Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
10 
11 // include this first to check the header is self-contained.
12 #include <dns/rrcollator.h>
13 
14 #include <dns/name.h>
15 #include <dns/rdataclass.h>
16 #include <dns/rrclass.h>
17 #include <dns/rrtype.h>
18 #include <dns/rrttl.h>
19 #include <dns/rdata.h>
20 #include <dns/rrset.h>
21 
22 #include <algorithm>
23 #include <functional>
24 
25 using namespace isc::dns::rdata;
26 namespace ph = std::placeholders;
27 
28 namespace isc {
29 namespace dns {
30 
32 public:
33  Impl(const AddRRsetCallback& callback) : callback_(callback) {}
34 
35  void addRR(const Name& name, const RRClass& rrclass,
36  const RRType& rrtype, const RRTTL& rrttl,
37  const RdataPtr& rdata);
38 
41 };
42 
43 namespace {
44 inline bool
45 isSameType(RRType type1, const ConstRdataPtr& rdata1,
46  const ConstRRsetPtr& rrset)
47 {
48  if (type1 != rrset->getType()) {
49  return (false);
50  }
51  if (type1 == RRType::RRSIG()) {
52  RdataIteratorPtr rit = rrset->getRdataIterator();
53  return (dynamic_cast<const generic::RRSIG&>(*rdata1).typeCovered()
54  == dynamic_cast<const generic::RRSIG&>(
55  rit->getCurrent()).typeCovered());
56  }
57  return (true);
58 }
59 }
60 
61 void
62 RRCollator::Impl::addRR(const Name& name, const RRClass& rrclass,
63  const RRType& rrtype, const RRTTL& rrttl,
64  const RdataPtr& rdata)
65 {
66  if (current_rrset_ && (!isSameType(rrtype, rdata, current_rrset_) ||
67  current_rrset_->getClass() != rrclass ||
68  current_rrset_->getName() != name)) {
69  callback_(current_rrset_);
70  current_rrset_.reset();
71  }
72 
73  if (!current_rrset_) {
74  current_rrset_ = RRsetPtr(new RRset(name, rrclass, rrtype, rrttl));
75  } else if (current_rrset_->getTTL() != rrttl) {
76  // RRs with different TTLs are given. Smaller TTL should win.
77  current_rrset_->setTTL(std::min(current_rrset_->getTTL(), rrttl));
78  }
79  current_rrset_->addRdata(rdata);
80 }
81 
83  impl_(new Impl(callback))
84 {}
85 
87  delete impl_;
88 }
89 
92  return (std::bind(&RRCollator::Impl::addRR, this->impl_,
93  ph::_1, ph::_2, ph::_3, ph::_4, ph::_5));
94 }
95 
96 void
98  if (impl_->current_rrset_) {
99  impl_->callback_(impl_->current_rrset_);
100  impl_->current_rrset_.reset();
101  }
102 }
103 
104 } // end namespace dns
105 } // end namespace isc
The Name class encapsulates DNS names.
Definition: name.h:223
rdata::RRSIG class represents the RRSIG RDATA as defined in RFC4034.
Definition: rdataclass.h:1784
std::function< void(const RRsetPtr &rrset)> AddRRsetCallback
Callback functor type for RRCollator.
Definition: rrcollator.h:54
std::function< void()> callback_
The callback function.
Definition: io_service.cc:38
const AddRRsetCallback callback_
Definition: rrcollator.cc:40
boost::shared_ptr< const Rdata > ConstRdataPtr
Definition: rdata.h:72
RRCollator(const AddRRsetCallback &callback)
Constructor.
Definition: rrcollator.cc:82
static const RRType & RRSIG()
Definition: rrtype.h:455
~RRCollator()
Destructor.
Definition: rrcollator.cc:86
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
void addRR(const Name &name, const RRClass &rrclass, const RRType &rrtype, const RRTTL &rrttl, const RdataPtr &rdata)
Definition: rrcollator.cc:62
AddRRCallback getCallback()
Return MasterLoader compatible callback.
Definition: rrcollator.cc:91
The RRTTL class encapsulates TTLs used in DNS resource records.
Definition: rrttl.h:55
Defines the logger used by the top-level component of kea-dhcp-ddns.
Impl(const AddRRsetCallback &callback)
Definition: rrcollator.cc:33
The RRset class is a concrete derived class of BasicRRset which contains a pointer to an additional R...
Definition: rrset.h:847
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
boost::shared_ptr< RdataIterator > RdataIteratorPtr
A pointer-like type point to an RdataIterator object.
Definition: rrset.h:63
boost::shared_ptr< const AbstractRRset > ConstRRsetPtr
A pointer-like type pointing to an (immutable) RRset object.
Definition: rrset.h:60
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:47
void flush()
Call the callback on the remaining RRset, if any.
Definition: rrcollator.cc:97
std::function< void(const Name &name, const RRClass &rrclass, const RRType &rrtype, const RRTTL &rrttl, const rdata::RdataPtr &rdata)> AddRRCallback
Type of callback to add a RR.
boost::shared_ptr< Rdata > RdataPtr
The RdataPtr type is a pointer-like type, pointing to an object of some concrete derived class of Rda...