Kea 1.5.0
rrset_collection.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
11#include <dns/master_loader.h>
12#include <dns/rrcollator.h>
13
15
16#include <boost/bind.hpp>
17
18using namespace isc;
19
20namespace isc {
21namespace dns {
22
23void
24RRsetCollection::loaderCallback(const std::string&, size_t, const std::string&)
25{
26 // We just ignore callbacks for errors and warnings.
27}
28
29void
31 const CollectionKey key(rrset->getClass(), rrset->getType(),
32 rrset->getName());
33 CollectionMap::const_iterator it = rrsets_.find(key);
34 if (it != rrsets_.end()) {
36 "RRset for " << rrset->getName() << "/" << rrset->getClass()
37 << " with type " << rrset->getType() << " already exists");
38 }
39
40 rrsets_.insert(std::pair<CollectionKey, RRsetPtr>(key, rrset));
41}
42
43template<typename T>
44void
45RRsetCollection::constructHelper(T source, const isc::dns::Name& origin,
46 const isc::dns::RRClass& rrclass)
47{
48 RRCollator collator(boost::bind(&RRsetCollection::addRRset, this, _1));
49 MasterLoaderCallbacks callbacks
50 (boost::bind(&RRsetCollection::loaderCallback, this, _1, _2, _3),
51 boost::bind(&RRsetCollection::loaderCallback, this, _1, _2, _3));
52 MasterLoader loader(source, origin, rrclass, callbacks,
53 collator.getCallback(),
55 loader.load();
56 collator.flush();
57}
58
59RRsetCollection::RRsetCollection(const char* filename, const Name& origin,
60 const RRClass& rrclass)
61{
62 constructHelper(filename, origin, rrclass);
63}
64
65RRsetCollection::RRsetCollection(std::istream& input_stream, const Name& origin,
66 const RRClass& rrclass)
67{
68 constructHelper<std::istream&>(input_stream, origin, rrclass);
69}
70
72RRsetCollection::find(const Name& name, const RRClass& rrclass,
73 const RRType& rrtype) {
74 const CollectionKey key(rrclass, rrtype, name);
75 CollectionMap::iterator it = rrsets_.find(key);
76 if (it != rrsets_.end()) {
77 return (it->second);
78 }
79 return (RRsetPtr());
80}
81
83RRsetCollection::find(const Name& name, const RRClass& rrclass,
84 const RRType& rrtype) const
85{
86 const CollectionKey key(rrclass, rrtype, name);
87 CollectionMap::const_iterator it = rrsets_.find(key);
88 if (it != rrsets_.end()) {
89 return (it->second);
90 }
91 return (ConstRRsetPtr());
92}
93
94bool
95RRsetCollection::removeRRset(const Name& name, const RRClass& rrclass,
96 const RRType& rrtype)
97{
98 const CollectionKey key(rrclass, rrtype, name);
99
100 CollectionMap::iterator it = rrsets_.find(key);
101 if (it == rrsets_.end()) {
102 return (false);
103 }
104
105 rrsets_.erase(it);
106 return (true);
107}
108
111 CollectionMap::iterator it = rrsets_.begin();
112 return (RRsetCollectionBase::IterPtr(new DnsIter(it)));
113}
114
117 CollectionMap::iterator it = rrsets_.end();
118 return (RRsetCollectionBase::IterPtr(new DnsIter(it)));
119}
120
121} // end of namespace dns
122} // 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:53
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.