Kea 2.5.5
rrset.h
Go to the documentation of this file.
1// Copyright (C) 2010-2021 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#ifndef RRSET_H
8#define RRSET_H 1
9
10#include <iostream>
11#include <string>
12
13#include <boost/shared_ptr.hpp>
14
15#include <dns/exceptions.h>
16
17#include <dns/rdata.h>
18#include <dns/rrtype.h>
19
20namespace isc {
21namespace util {
22class OututBuffer;
23}
24
25namespace dns {
26
32public:
33 EmptyRRset(const char* file, size_t line, const char* what) :
34 isc::dns::Exception(file, line, what) {}
35};
36
37// forward declarations
38class Name;
39class RRType;
40class RRClass;
41class RRTTL;
42class AbstractMessageRenderer;
43class AbstractRRset;
44class BasicRRset;
45class RdataIterator;
46class BasicRRsetImpl;
47class RRset;
48
53typedef boost::shared_ptr<AbstractRRset> RRsetPtr;
54
60typedef boost::shared_ptr<const AbstractRRset> ConstRRsetPtr;
61
63typedef boost::shared_ptr<RdataIterator> RdataIteratorPtr;
64
73
160
161private:
162 AbstractRRset(const AbstractRRset& source);
163 AbstractRRset& operator=(const AbstractRRset& source);
164protected:
170public:
172 virtual ~AbstractRRset() {}
174
192
193
199 virtual unsigned int getRdataCount() const = 0;
200
213 virtual uint16_t getLength() const = 0;
214
219 virtual const Name& getName() const = 0;
220
225 virtual const RRClass& getClass() const = 0;
226
231 virtual const RRType& getType() const = 0;
232
237 virtual const RRTTL& getTTL() const = 0;
238
243 virtual void setTTL(const RRTTL& ttl) = 0;
245
263
264
288 virtual std::string toText() const = 0;
289
319 virtual unsigned int toWire(AbstractMessageRenderer& renderer) const = 0;
320
327 virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const = 0;
329
333
334
341 virtual void addRdata(rdata::ConstRdataPtr rdata) = 0;
342
394 virtual void addRdata(const rdata::Rdata& rdata) = 0;
395
404 virtual void addRdata(const std::string& rdata_str) = 0;
405
425
440
441
444 virtual RRsetPtr getRRsig() const = 0;
445
453 virtual unsigned int getRRsigDataCount() const = 0;
454
461 virtual void addRRsig(const rdata::ConstRdataPtr& rdata) = 0;
462
472 virtual void addRRsig(const rdata::RdataPtr& rdata) = 0;
473
482 virtual void addRRsig(const AbstractRRset& sigs) = 0;
483
492 virtual void addRRsig(const ConstRRsetPtr& sigs) = 0;
493
505 virtual void addRRsig(const RRsetPtr& sigs) = 0;
506
508 virtual void removeRRsig() = 0;
509
516 virtual bool isSameKind(const AbstractRRset& other) const;
518
519};
520
564
565protected:
571public:
573 virtual ~RdataIterator() {}
574private:
575 RdataIterator(const RdataIterator& source);
576 RdataIterator& operator=(const RdataIterator& source);
578
579public:
587 virtual void first() = 0;
588
593 virtual void next() = 0;
594
599 virtual const rdata::Rdata& getCurrent() const = 0;
600
613 virtual bool isLast() const = 0;
614};
615
629class BasicRRset : public AbstractRRset {
637
638private:
639 BasicRRset(const BasicRRset& source);
640 BasicRRset& operator=(const BasicRRset& source);
641public:
652 BasicRRset(const Name& name, const RRClass& rrclass,
653 const RRType& rrtype, const RRTTL& ttl);
655 virtual ~BasicRRset();
657
661
662
667 virtual unsigned int getRdataCount() const;
668
674 virtual uint16_t getLength() const;
675
682 virtual const Name& getName() const;
683
690 virtual const RRClass& getClass() const;
691
698 virtual const RRType& getType() const;
699
706 virtual const RRTTL& getTTL() const;
707
714 virtual void setTTL(const RRTTL& ttl);
716
720
721
725 virtual std::string toText() const;
726
732 virtual unsigned int toWire(AbstractMessageRenderer& renderer) const;
733
738 virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const;
740
744
745
753 virtual void addRdata(rdata::ConstRdataPtr rdata);
754
759 virtual void addRdata(const rdata::Rdata& rdata);
760
766 virtual void addRdata(const std::string& rdata_str);
767
780 virtual RdataIteratorPtr getRdataIterator() const;
782
791
792
795 virtual RRsetPtr getRRsig() const {
796 return (RRsetPtr());
797 }
798
804 virtual unsigned int getRRsigDataCount() const {
805 return (0);
806 }
807
808 virtual void addRRsig(const rdata::ConstRdataPtr&) {
810 "BasicRRset does not implement the addRRsig() method");
811 }
812
813 virtual void addRRsig(const rdata::RdataPtr&) {
815 "BasicRRset does not implement the addRRsig() method");
816 }
817
818 virtual void addRRsig(const AbstractRRset&) {
820 "BasicRRset does not implement the addRRsig() method");
821 }
822
823 virtual void addRRsig(const ConstRRsetPtr&) {
825 "BasicRRset does not implement the addRRsig() method");
826 }
827
828 virtual void addRRsig(const RRsetPtr&) {
830 "BasicRRset does not implement the addRRsig() method");
831 }
832
833 virtual void removeRRsig() {
835 "BasicRRset does not implement the removeRRsig() method");
836 }
838private:
839 BasicRRsetImpl* impl_;
840};
841
847class RRset : public BasicRRset {
848public:
849 RRset(const Name& name, const RRClass& rrclass,
850 const RRType& rrtype, const RRTTL& ttl);
851
852 virtual ~RRset();
853
859 virtual uint16_t getLength() const;
860
865 virtual unsigned int toWire(AbstractMessageRenderer& renderer) const;
866
870 virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const;
871
873 virtual void setTTL(const RRTTL& ttl) {
875 if (rrsig_) {
876 rrsig_->setTTL(ttl);
877 }
878 }
879
881 virtual void addRRsig(const rdata::ConstRdataPtr& rdata) {
882 if (!rrsig_) {
883 rrsig_ = RRsetPtr(new RRset(getName(), getClass(),
884 RRType::RRSIG(), getTTL()));
885 }
886 rrsig_->addRdata(rdata);
887 }
888
889 // Workaround for older versions of boost: some don't support implicit
890 // conversion from shared_ptr<X> to shared_ptr<const X>. Note: we should
891 // revisit the interface of managing RRset signatures, at which point this
892 // problem may go away.
893 virtual void addRRsig(const rdata::RdataPtr& rdata) {
894 // Don't try to convert as a reference here. SunStudio will reject it.
895 addRRsig(static_cast<const rdata::ConstRdataPtr>(rdata));
896 }
897
899 virtual void addRRsig(const AbstractRRset& sigs) {
901
902 if (!rrsig_) {
903 rrsig_ = RRsetPtr(new RRset(getName(), getClass(),
904 RRType::RRSIG(), getTTL()));
905 }
906
907 for (it->first(); !it->isLast(); it->next()) {
908 rrsig_->addRdata(it->getCurrent());
909 }
910 }
911
912 virtual void addRRsig(const ConstRRsetPtr& sigs) { addRRsig(*sigs); }
913
914 // Another workaround for older boost (see above)
915 virtual void addRRsig(const RRsetPtr& sigs) { addRRsig(*sigs); }
916
918 virtual void removeRRsig() { rrsig_ = RRsetPtr(); }
919
921 virtual RRsetPtr getRRsig() const { return (rrsig_); }
922
930 virtual unsigned int getRRsigDataCount() const;
931
932private:
933 RRsetPtr rrsig_;
934};
935
936
951std::ostream& operator<<(std::ostream& os, const AbstractRRset& rrset);
952} // end of namespace dns
953} // end of namespace isc
954#endif // RRSET_H
955
956// Local Variables:
957// mode: c++
958// End:
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
The AbstractRRset class is an abstract base class that models a DNS RRset.
Definition: rrset.h:154
virtual unsigned int toWire(AbstractMessageRenderer &renderer) const =0
Render the RRset in the wire format with name compression and truncation handling.
Definition: rrset.cc:134
AbstractRRset()
The default constructor.
Definition: rrset.h:169
virtual const RRType & getType() const =0
Returns the RR Type of the RRset.
virtual std::string toText() const =0
Convert the RRset to a string.
Definition: rrset.cc:37
virtual void addRRsig(const ConstRRsetPtr &sigs)=0
Adds RRSIG RRset RRs to the associated RRSIG RRset.
virtual void addRRsig(const rdata::ConstRdataPtr &rdata)=0
Adds RRSIG RRset RRs to the associated RRSIG RRset.
virtual uint16_t getLength() const =0
Get the wire format length of the AbstractRRset.
virtual bool isSameKind(const AbstractRRset &other) const
Check whether two RRsets are of the same kind.
Definition: rrset.cc:144
virtual unsigned int getRdataCount() const =0
Returns the number of Rdata objects contained in the RRset.
virtual RRsetPtr getRRsig() const =0
Return pointer to this RRset's RRSIG RRset.
virtual void addRdata(const std::string &rdata_str)=0
Add an RDATA to the RRset (string version).
virtual void setTTL(const RRTTL &ttl)=0
Updates the TTL of the RRset.
virtual const Name & getName() const =0
Returns the owner name of the RRset.
virtual const RRTTL & getTTL() const =0
Returns the TTL of the RRset.
virtual RdataIteratorPtr getRdataIterator() const =0
Return an iterator to go through all RDATA stored in the RRset.
virtual void addRRsig(const rdata::RdataPtr &rdata)=0
Adds RRSIG RRset RRs to the associated RRSIG RRset.
virtual unsigned int getRRsigDataCount() const =0
Returns the number of RRSIG records associated with the RRset.
virtual ~AbstractRRset()
The destructor.
Definition: rrset.h:172
virtual void addRdata(rdata::ConstRdataPtr rdata)=0
Add an RDATA to the RRset (pointer version).
virtual const RRClass & getClass() const =0
Returns the RR Class of the RRset.
virtual void removeRRsig()=0
Clear the RRSIGs for this RRset.
virtual void addRRsig(const RRsetPtr &sigs)=0
Adds RRSIG RRset RRs to the associated RRSIG RRset.
virtual void addRRsig(const AbstractRRset &sigs)=0
Adds RRSIG RRset RRs to the associated RRSIG RRset.
This encapsulates the actual implementation of the BasicRRset class.
Definition: rrset.cc:161
The BasicRRset class is a concrete derived class of AbstractRRset that defines a straightforward RRse...
Definition: rrset.h:629
virtual void removeRRsig()
Clear the RRSIGs for this RRset.
Definition: rrset.h:833
virtual RdataIteratorPtr getRdataIterator() const
Return an iterator to go through all RDATA stored in the BasicRRset.
Definition: rrset.cc:461
virtual const RRTTL & getTTL() const
Returns the TTL of the RRset.
Definition: rrset.cc:277
virtual unsigned int getRdataCount() const
Returns the number of Rdata objects contained in the RRset.
Definition: rrset.cc:257
virtual void addRRsig(const ConstRRsetPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:823
virtual void addRRsig(const rdata::ConstRdataPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:808
virtual void addRRsig(const AbstractRRset &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:818
virtual void addRdata(rdata::ConstRdataPtr rdata)
Add an RDATA to the RRset (pointer version).
Definition: rrset.cc:242
virtual void addRRsig(const rdata::RdataPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:813
virtual unsigned int getRRsigDataCount() const
Returns the number of RRSIG records associated with the RRset.
Definition: rrset.h:804
virtual unsigned int toWire(AbstractMessageRenderer &renderer) const
Render the RRset in the wire format with name compression and truncation handling.
Definition: rrset.cc:341
virtual ~BasicRRset()
The destructor.
Definition: rrset.cc:237
virtual void addRRsig(const RRsetPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:828
virtual void setTTL(const RRTTL &ttl)
Updates the TTL of the RRset.
Definition: rrset.cc:282
virtual const RRType & getType() const
Returns the RR Type of the RRset.
Definition: rrset.cc:272
virtual uint16_t getLength() const
Get the wire format length of the BasicRRset.
Definition: rrset.cc:292
virtual const RRClass & getClass() const
Returns the RR Class of the RRset.
Definition: rrset.cc:267
virtual RRsetPtr getRRsig() const
Return pointer to this RRset's RRSIG RRset.
Definition: rrset.h:795
virtual const Name & getName() const
Returns the owner name of the RRset.
Definition: rrset.cc:262
virtual std::string toText() const
Convert the RRset to a string.
Definition: rrset.cc:287
A standard DNS module exception that is thrown if an RRset object does not contain any RDATA where re...
Definition: rrset.h:31
EmptyRRset(const char *file, size_t line, const char *what)
Definition: rrset.h:33
The Name class encapsulates DNS names.
Definition: name.h:223
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
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:455
The RRset class is a concrete derived class of BasicRRset which contains a pointer to an additional R...
Definition: rrset.h:847
virtual ~RRset()
Definition: rrset.cc:357
virtual uint16_t getLength() const
Get the wire format length of the RRset.
Definition: rrset.cc:369
virtual void addRRsig(const rdata::ConstRdataPtr &rdata)
Adds an RRSIG RR to this RRset's signatures.
Definition: rrset.h:881
virtual void setTTL(const RRTTL &ttl)
Updates the owner name of the RRset, including RRSIGs if any.
Definition: rrset.h:873
virtual unsigned int toWire(AbstractMessageRenderer &renderer) const
Render the RRset in the wire format with name compression and truncation handling.
Definition: rrset.cc:398
virtual RRsetPtr getRRsig() const
Return a pointer to this RRset's RRSIG RRset.
Definition: rrset.h:921
RRset(const Name &name, const RRClass &rrclass, const RRType &rrtype, const RRTTL &ttl)
Definition: rrset.cc:350
virtual void addRRsig(const ConstRRsetPtr &sigs)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:912
virtual void addRRsig(const RRsetPtr &sigs)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:915
virtual void removeRRsig()
Clear the RRSIGs for this RRset.
Definition: rrset.h:918
virtual void addRRsig(const rdata::RdataPtr &rdata)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:893
virtual void addRRsig(const AbstractRRset &sigs)
Adds an RRSIG RRset to this RRset.
Definition: rrset.h:899
virtual unsigned int getRRsigDataCount() const
Returns the number of RRSIG records associated with the RRset.
Definition: rrset.cc:360
The RdataIterator class is an abstract base class that provides an interface for accessing RDATA obje...
Definition: rrset.h:558
virtual const rdata::Rdata & getCurrent() const =0
Return the current Rdata corresponding to the rdata cursor.
virtual bool isLast() const =0
Return true iff the rdata cursor has reached the end of the rdata list.
virtual ~RdataIterator()
Destructor.
Definition: rrset.h:573
RdataIterator()
The default constructor.
Definition: rrset.h:570
virtual void first()=0
Move the rdata cursor to the first RDATA in the rdata list (if any).
virtual void next()=0
Move the rdata cursor to the next RDATA in the rdata list (if any).
The Rdata class is an abstract base class that provides a set of common interfaces to manipulate conc...
Definition: rdata.h:123
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
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::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:53
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
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-lfc.