Kea 2.7.4
rrset.h
Go to the documentation of this file.
1// Copyright (C) 2010-2024 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
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#include <util/buffer.h>
20
21namespace isc {
22namespace dns {
23
29public:
30 EmptyRRset(const char* file, size_t line, const char* what) :
31 isc::dns::Exception(file, line, what) {}
32};
33
34// forward declarations
35class Name;
36class RRType;
37class RRClass;
38class RRTTL;
39class AbstractMessageRenderer;
40class AbstractRRset;
41class BasicRRset;
42class RdataIterator;
43class BasicRRsetImpl;
44class RRset;
45
50typedef boost::shared_ptr<AbstractRRset> RRsetPtr;
51
57typedef boost::shared_ptr<const AbstractRRset> ConstRRsetPtr;
58
60typedef boost::shared_ptr<RdataIterator> RdataIteratorPtr;
61
70
157
158private:
159 AbstractRRset(const AbstractRRset& source);
160 AbstractRRset& operator=(const AbstractRRset& source);
161protected:
167public:
169 virtual ~AbstractRRset() {}
171
189
190
196 virtual uint32_t getRdataCount() const = 0;
197
210 virtual uint16_t getLength() const = 0;
211
216 virtual const Name& getName() const = 0;
217
222 virtual const RRClass& getClass() const = 0;
223
228 virtual const RRType& getType() const = 0;
229
234 virtual const RRTTL& getTTL() const = 0;
235
240 virtual void setTTL(const RRTTL& ttl) = 0;
242
260
261
285 virtual std::string toText() const = 0;
286
316 virtual uint32_t toWire(AbstractMessageRenderer& renderer) const = 0;
317
324 virtual uint32_t toWire(isc::util::OutputBuffer& buffer) const = 0;
326
330
331
338 virtual void addRdata(rdata::ConstRdataPtr rdata) = 0;
339
391 virtual void addRdata(const rdata::Rdata& rdata) = 0;
392
401 virtual void addRdata(const std::string& rdata_str) = 0;
402
422
437
438
441 virtual RRsetPtr getRRsig() const = 0;
442
450 virtual uint32_t getRRsigDataCount() const = 0;
451
458 virtual void addRRsig(const rdata::ConstRdataPtr& rdata) = 0;
459
469 virtual void addRRsig(const rdata::RdataPtr& rdata) = 0;
470
479 virtual void addRRsig(const AbstractRRset& sigs) = 0;
480
489 virtual void addRRsig(const ConstRRsetPtr& sigs) = 0;
490
502 virtual void addRRsig(const RRsetPtr& sigs) = 0;
503
505 virtual void removeRRsig() = 0;
506
513 virtual bool isSameKind(const AbstractRRset& other) const;
515
516};
517
561
562protected:
568public:
570 virtual ~RdataIterator() {}
571private:
572 RdataIterator(const RdataIterator& source);
573 RdataIterator& operator=(const RdataIterator& source);
575
576public:
584 virtual void first() = 0;
585
590 virtual void next() = 0;
591
596 virtual const rdata::Rdata& getCurrent() const = 0;
597
610 virtual bool isLast() const = 0;
611};
612
626class BasicRRset : public AbstractRRset {
634
635private:
636 BasicRRset(const BasicRRset& source);
637 BasicRRset& operator=(const BasicRRset& source);
638public:
649 BasicRRset(const Name& name, const RRClass& rrclass,
650 const RRType& rrtype, const RRTTL& ttl);
652 virtual ~BasicRRset();
654
658
659
664 virtual uint32_t getRdataCount() const;
665
671 virtual uint16_t getLength() const;
672
679 virtual const Name& getName() const;
680
687 virtual const RRClass& getClass() const;
688
695 virtual const RRType& getType() const;
696
703 virtual const RRTTL& getTTL() const;
704
711 virtual void setTTL(const RRTTL& ttl);
713
717
718
722 virtual std::string toText() const;
723
729 virtual uint32_t toWire(AbstractMessageRenderer& renderer) const;
730
735 virtual uint32_t toWire(isc::util::OutputBuffer& buffer) const;
737
741
742
750 virtual void addRdata(rdata::ConstRdataPtr rdata);
751
756 virtual void addRdata(const rdata::Rdata& rdata);
757
763 virtual void addRdata(const std::string& rdata_str);
764
777 virtual RdataIteratorPtr getRdataIterator() const;
779
788
789
792 virtual RRsetPtr getRRsig() const {
793 return (RRsetPtr());
794 }
795
801 virtual uint32_t getRRsigDataCount() const {
802 return (0);
803 }
804
805 virtual void addRRsig(const rdata::ConstRdataPtr&) {
807 "BasicRRset does not implement the addRRsig() method");
808 }
809
810 virtual void addRRsig(const rdata::RdataPtr&) {
812 "BasicRRset does not implement the addRRsig() method");
813 }
814
815 virtual void addRRsig(const AbstractRRset&) {
817 "BasicRRset does not implement the addRRsig() method");
818 }
819
820 virtual void addRRsig(const ConstRRsetPtr&) {
822 "BasicRRset does not implement the addRRsig() method");
823 }
824
825 virtual void addRRsig(const RRsetPtr&) {
827 "BasicRRset does not implement the addRRsig() method");
828 }
829
830 virtual void removeRRsig() {
832 "BasicRRset does not implement the removeRRsig() method");
833 }
835private:
836 boost::shared_ptr<BasicRRsetImpl> impl_;
837};
838
844class RRset : public BasicRRset {
845public:
846 RRset(const Name& name, const RRClass& rrclass,
847 const RRType& rrtype, const RRTTL& ttl);
848
849 virtual ~RRset();
850
856 virtual uint16_t getLength() const;
857
862 virtual uint32_t toWire(AbstractMessageRenderer& renderer) const;
863
867 virtual uint32_t toWire(isc::util::OutputBuffer& buffer) const;
868
870 virtual void setTTL(const RRTTL& ttl) {
872 if (rrsig_) {
873 rrsig_->setTTL(ttl);
874 }
875 }
876
878 virtual void addRRsig(const rdata::ConstRdataPtr& rdata) {
879 if (!rrsig_) {
880 rrsig_ = RRsetPtr(new RRset(getName(), getClass(),
881 RRType::RRSIG(), getTTL()));
882 }
883 rrsig_->addRdata(rdata);
884 }
885
886 // Workaround for older versions of boost: some don't support implicit
887 // conversion from shared_ptr<X> to shared_ptr<const X>. Note: we should
888 // revisit the interface of managing RRset signatures, at which point this
889 // problem may go away.
890 virtual void addRRsig(const rdata::RdataPtr& rdata) {
891 // Don't try to convert as a reference here. SunStudio will reject it.
892 addRRsig(static_cast<const rdata::ConstRdataPtr>(rdata));
893 }
894
896 virtual void addRRsig(const AbstractRRset& sigs) {
897 RdataIteratorPtr it = sigs.getRdataIterator();
898
899 if (!rrsig_) {
900 rrsig_ = RRsetPtr(new RRset(getName(), getClass(),
901 RRType::RRSIG(), getTTL()));
902 }
903
904 for (it->first(); !it->isLast(); it->next()) {
905 rrsig_->addRdata(it->getCurrent());
906 }
907 }
908
909 virtual void addRRsig(const ConstRRsetPtr& sigs) { addRRsig(*sigs); }
910
911 // Another workaround for older boost (see above)
912 virtual void addRRsig(const RRsetPtr& sigs) { addRRsig(*sigs); }
913
915 virtual void removeRRsig() { rrsig_ = RRsetPtr(); }
916
918 virtual RRsetPtr getRRsig() const { return (rrsig_); }
919
927 virtual uint32_t getRRsigDataCount() const;
928
929private:
930 RRsetPtr rrsig_;
931};
932
933
948std::ostream& operator<<(std::ostream& os, const AbstractRRset& rrset);
949} // end of namespace dns
950} // end of namespace isc
951#endif // RRSET_H
952
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:151
AbstractRRset()
The default constructor.
Definition rrset.h:166
virtual uint32_t toWire(AbstractMessageRenderer &renderer) const =0
Render the RRset in the wire format with name compression and truncation handling.
Definition rrset.cc:134
virtual const RRType & getType() const =0
Returns the RR Type of the RRset.
virtual uint32_t getRdataCount() const =0
Returns the number of Rdata objects contained in 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 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 ~AbstractRRset()
The destructor.
Definition rrset.h:169
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 uint32_t getRRsigDataCount() const =0
Returns the number of RRSIG records associated with 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.
The BasicRRset class is a concrete derived class of AbstractRRset that defines a straightforward RRse...
Definition rrset.h:626
virtual void removeRRsig()
Clear the RRSIGs for this RRset.
Definition rrset.h:830
virtual RdataIteratorPtr getRdataIterator() const
Return an iterator to go through all RDATA stored in the BasicRRset.
Definition rrset.cc:460
virtual const RRTTL & getTTL() const
Returns the TTL of the RRset.
Definition rrset.cc:275
virtual void addRRsig(const ConstRRsetPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition rrset.h:820
virtual void addRRsig(const rdata::ConstRdataPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition rrset.h:805
virtual void addRRsig(const AbstractRRset &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition rrset.h:815
virtual uint32_t getRRsigDataCount() const
Returns the number of RRSIG records associated with the RRset.
Definition rrset.h:801
virtual void addRdata(rdata::ConstRdataPtr rdata)
Add an RDATA to the RRset (pointer version).
Definition rrset.cc:240
virtual void addRRsig(const rdata::RdataPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition rrset.h:810
virtual uint32_t getRdataCount() const
Returns the number of Rdata objects contained in the RRset.
Definition rrset.cc:255
virtual ~BasicRRset()
The destructor.
Definition rrset.cc:236
virtual void addRRsig(const RRsetPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition rrset.h:825
virtual void setTTL(const RRTTL &ttl)
Updates the TTL of the RRset.
Definition rrset.cc:280
virtual const RRType & getType() const
Returns the RR Type of the RRset.
Definition rrset.cc:270
virtual uint16_t getLength() const
Get the wire format length of the BasicRRset.
Definition rrset.cc:290
virtual const RRClass & getClass() const
Returns the RR Class of the RRset.
Definition rrset.cc:265
virtual RRsetPtr getRRsig() const
Return pointer to this RRset's RRSIG RRset.
Definition rrset.h:792
virtual const Name & getName() const
Returns the owner name of the RRset.
Definition rrset.cc:260
virtual uint32_t toWire(AbstractMessageRenderer &renderer) const
Render the RRset in the wire format with name compression and truncation handling.
Definition rrset.cc:339
virtual std::string toText() const
Convert the RRset to a string.
Definition rrset.cc:285
A standard DNS module exception that is thrown if an RRset object does not contain any RDATA where re...
Definition rrset.h:28
EmptyRRset(const char *file, size_t line, const char *what)
Definition rrset.h:30
The Name class encapsulates DNS names.
Definition name.h:219
The RRClass class encapsulates DNS resource record classes.
Definition rrclass.h:89
The RRTTL class encapsulates TTLs used in DNS resource records.
Definition rrttl.h:51
The RRType class encapsulates DNS resource record types.
Definition rrtype.h:96
static const RRType & RRSIG()
Definition rrtype.h:321
The RRset class is a concrete derived class of BasicRRset which contains a pointer to an additional R...
Definition rrset.h:844
virtual ~RRset()
Definition rrset.cc:353
virtual uint16_t getLength() const
Get the wire format length of the RRset.
Definition rrset.cc:366
virtual void addRRsig(const rdata::ConstRdataPtr &rdata)
Adds an RRSIG RR to this RRset's signatures.
Definition rrset.h:878
virtual void setTTL(const RRTTL &ttl)
Updates the owner name of the RRset, including RRSIGs if any.
Definition rrset.h:870
virtual RRsetPtr getRRsig() const
Return a pointer to this RRset's RRSIG RRset.
Definition rrset.h:918
RRset(const Name &name, const RRClass &rrclass, const RRType &rrtype, const RRTTL &ttl)
Definition rrset.cc:348
virtual void addRRsig(const ConstRRsetPtr &sigs)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition rrset.h:909
virtual uint32_t toWire(AbstractMessageRenderer &renderer) const
Render the RRset in the wire format with name compression and truncation handling.
Definition rrset.cc:395
virtual void addRRsig(const RRsetPtr &sigs)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition rrset.h:912
virtual void removeRRsig()
Clear the RRSIGs for this RRset.
Definition rrset.h:915
virtual void addRRsig(const rdata::RdataPtr &rdata)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition rrset.h:890
virtual void addRRsig(const AbstractRRset &sigs)
Adds an RRSIG RRset to this RRset.
Definition rrset.h:896
virtual uint32_t getRRsigDataCount() const
Returns the number of RRSIG records associated with the RRset.
Definition rrset.cc:357
The RdataIterator class is an abstract base class that provides an interface for accessing RDATA obje...
Definition rrset.h:555
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:570
RdataIterator()
The default constructor.
Definition rrset.h:567
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:120
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:343
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Rdata > ConstRdataPtr
Definition rdata.h:69
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:50
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition edns.cc:163
boost::shared_ptr< RdataIterator > RdataIteratorPtr
A pointer-like type point to an RdataIterator object.
Definition rrset.h:60
boost::shared_ptr< const AbstractRRset > ConstRRsetPtr
A pointer-like type pointing to an (immutable) RRset object.
Definition rrset.h:57
Defines the logger used by the top-level component of kea-lfc.