Kea 2.2.0
rrset_collection.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
11#include <dns/master_loader.h>
12#include <dns/rrcollator.h>
13
15
16#include <functional>
17
18using namespace isc;
19namespace ph = std::placeholders;
20
21namespace isc {
22namespace dns {
23
24void
25RRsetCollection::loaderCallback(const std::string&, size_t, const std::string&)
26{
27 // We just ignore callbacks for errors and warnings.
28}
29
30void
32 const CollectionKey key(rrset->getClass(), rrset->getType(),
33 rrset->getName());
34 CollectionMap::const_iterator it = rrsets_.find(key);
35 if (it != rrsets_.end()) {
37 "RRset for " << rrset->getName() << "/" << rrset->getClass()
38 << " with type " << rrset->getType() << " already exists");
39 }
40
41 rrsets_.insert(std::pair<CollectionKey, RRsetPtr>(key, rrset));
42}
43
44template<typename T>
45void
46RRsetCollection::constructHelper(T source, const isc::dns::Name& origin,
47 const isc::dns::RRClass& rrclass)
48{
49 RRCollator collator(std::bind(&RRsetCollection::addRRset, this, ph::_1));
50 MasterLoaderCallbacks callbacks
51 (std::bind(&RRsetCollection::loaderCallback, this, ph::_1, ph::_2, ph::_3),
52 std::bind(&RRsetCollection::loaderCallback, this, ph::_1, ph::_2, ph::_3));
53 MasterLoader loader(source, origin, rrclass, callbacks,
54 collator.getCallback(),
56 loader.load();
57 collator.flush();
58}
59
60RRsetCollection::RRsetCollection(const char* filename, const Name& origin,
61 const RRClass& rrclass)
62{
63 constructHelper(filename, origin, rrclass);
64}
65
66RRsetCollection::RRsetCollection(std::istream& input_stream, const Name& origin,
67 const RRClass& rrclass)
68{
69 constructHelper<std::istream&>(input_stream, origin, rrclass);
70}
71
73RRsetCollection::find(const Name& name, const RRClass& rrclass,
74 const RRType& rrtype) {
75 const CollectionKey key(rrclass, rrtype, name);
76 CollectionMap::iterator it = rrsets_.find(key);
77 if (it != rrsets_.end()) {
78 return (it->second);
79 }
80 return (RRsetPtr());
81}
82
84RRsetCollection::find(const Name& name, const RRClass& rrclass,
85 const RRType& rrtype) const
86{
87 const CollectionKey key(rrclass, rrtype, name);
88 CollectionMap::const_iterator it = rrsets_.find(key);
89 if (it != rrsets_.end()) {
90 return (it->second);
91 }
92 return (ConstRRsetPtr());
93}
94
95bool
96RRsetCollection::removeRRset(const Name& name, const RRClass& rrclass,
97 const RRType& rrtype)
98{
99 const CollectionKey key(rrclass, rrtype, name);
100
101 CollectionMap::iterator it = rrsets_.find(key);
102 if (it == rrsets_.end()) {
103 return (false);
104 }
105
106 rrsets_.erase(it);
107 return (true);
108}
109
112 CollectionMap::iterator it = rrsets_.begin();
113 return (RRsetCollectionBase::IterPtr(new DnsIter(it)));
114}
115
118 CollectionMap::iterator it = rrsets_.end();
119 return (RRsetCollectionBase::IterPtr(new DnsIter(it)));
120}
121
122} // end of namespace dns
123} // end of namespace isc
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
Set of issue callbacks for a loader.
A class able to load DNS master files.
Definition: master_loader.h:36
@ DEFAULT
Nothing special.
Definition: master_loader.h:40
The Name class encapsulates DNS names.
Definition: name.h:223
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
A converter from a stream of RRs to a stream of collated RRsets.
Definition: rrcollator.h:45
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
boost::shared_ptr< Iter > IterPtr
Wraps Iter with a reference count.
virtual RRsetCollectionBase::IterPtr getBeginning()
Returns an IterPtr wrapping an Iter pointing to the beginning of the collection.
virtual RRsetCollectionBase::IterPtr getEnd()
Returns an IterPtr wrapping an Iter pointing past the end of the collection.
virtual isc::dns::ConstRRsetPtr find(const isc::dns::Name &name, const isc::dns::RRClass &rrclass, const isc::dns::RRType &rrtype) const
Find a matching RRset in the collection.
void addRRset(isc::dns::RRsetPtr rrset)
Add an RRset to the collection.
bool removeRRset(const isc::dns::Name &name, const isc::dns::RRClass &rrclass, const isc::dns::RRType &rrtype)
Remove an RRset from the collection.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:47
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-lfc.