Kea 1.5.0
rrcollator.cc
Go to the documentation of this file.
1// Copyright (C) 2012-2015 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 <boost/bind.hpp>
23
24#include <algorithm>
25
26namespace isc {
27namespace dns {
28using namespace rdata;
29
31public:
32 Impl(const AddRRsetCallback& callback) : callback_(callback) {}
33
34 void addRR(const Name& name, const RRClass& rrclass,
35 const RRType& rrtype, const RRTTL& rrttl,
36 const RdataPtr& rdata);
37
40};
41
42namespace {
43inline bool
44isSameType(RRType type1, const ConstRdataPtr& rdata1,
45 const ConstRRsetPtr& rrset)
46{
47 if (type1 != rrset->getType()) {
48 return (false);
49 }
50 if (type1 == RRType::RRSIG()) {
51 RdataIteratorPtr rit = rrset->getRdataIterator();
52 return (dynamic_cast<const generic::RRSIG&>(*rdata1).typeCovered()
53 == dynamic_cast<const generic::RRSIG&>(
54 rit->getCurrent()).typeCovered());
55 }
56 return (true);
57}
58}
59
60void
61RRCollator::Impl::addRR(const Name& name, const RRClass& rrclass,
62 const RRType& rrtype, const RRTTL& rrttl,
63 const RdataPtr& rdata)
64{
65 if (current_rrset_ && (!isSameType(rrtype, rdata, current_rrset_) ||
66 current_rrset_->getClass() != rrclass ||
67 current_rrset_->getName() != name)) {
69 current_rrset_.reset();
70 }
71
72 if (!current_rrset_) {
73 current_rrset_ = RRsetPtr(new RRset(name, rrclass, rrtype, rrttl));
74 } else if (current_rrset_->getTTL() != rrttl) {
75 // RRs with different TTLs are given. Smaller TTL should win.
76 current_rrset_->setTTL(std::min(current_rrset_->getTTL(), rrttl));
77 }
78 current_rrset_->addRdata(rdata);
79}
80
82 impl_(new Impl(callback))
83{}
84
86 delete impl_;
87}
88
91 return (boost::bind(&RRCollator::Impl::addRR, this->impl_,
92 _1, _2, _3, _4, _5));
93}
94
95void
97 if (impl_->current_rrset_) {
98 impl_->callback_(impl_->current_rrset_);
99 impl_->current_rrset_.reset();
100 }
101}
102
103} // end namespace dns
104} // end namespace isc
The Name class encapsulates DNS names.
Definition: name.h:223
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:61
const AddRRsetCallback callback_
Definition: rrcollator.cc:39
Impl(const AddRRsetCallback &callback)
Definition: rrcollator.cc:32
~RRCollator()
Destructor.
Definition: rrcollator.cc:85
AddRRCallback getCallback()
Return MasterLoader compatible callback.
Definition: rrcollator.cc:90
boost::function< void(const RRsetPtr &rrset)> AddRRsetCallback
Callback functor type for RRCollator.
Definition: rrcollator.h:54
void flush()
Call the callback on the remaining RRset, if any.
Definition: rrcollator.cc:96
RRCollator(const AddRRsetCallback &callback)
Constructor.
Definition: rrcollator.cc:81
The RRTTL class encapsulates TTLs used in DNS resource records.
Definition: rrttl.h:55
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
static const RRType & RRSIG()
Definition: rrtype.h:611
The RRset class is a concrete derived class of BasicRRset which contains a pointer to an additional R...
Definition: rrset.h:847
rdata::RRSIG class represents the RRSIG RDATA as defined in RFC4034.
Definition: rdataclass.h:1784
const RRType & typeCovered() const
boost::shared_ptr< const Rdata > ConstRdataPtr
Definition: rdata.h:72
boost::shared_ptr< Rdata > RdataPtr
The RdataPtr type is a pointer-like type, pointing to an object of some concrete derived class of Rda...
boost::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< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:53
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
Defines the logger used by the top-level component of kea-dhcp-ddns.