Kea  2.1.7-git
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 
20 namespace isc {
21 namespace util {
22 class OututBuffer;
23 }
24 
25 namespace dns {
26 
32 public:
33  EmptyRRset(const char* file, size_t line, const char* what) :
34  isc::dns::Exception(file, line, what) {}
35 };
36 
37 // forward declarations
38 class Name;
39 class RRType;
40 class RRClass;
41 class RRTTL;
43 class AbstractRRset;
44 class BasicRRset;
45 class RdataIterator;
46 class BasicRRsetImpl;
47 class RRset;
48 
53 typedef boost::shared_ptr<AbstractRRset> RRsetPtr;
54 
60 typedef boost::shared_ptr<const AbstractRRset> ConstRRsetPtr;
61 
63 typedef boost::shared_ptr<RdataIterator> RdataIteratorPtr;
64 
73 
160 
161 private:
162  AbstractRRset(const AbstractRRset& source);
163  AbstractRRset& operator=(const AbstractRRset& source);
164 protected:
170 public:
172  virtual ~AbstractRRset() {}
174 
192 
193  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  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  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 
423  virtual RdataIteratorPtr getRdataIterator() const = 0;
425 
440 
441  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 
565 protected:
571 public:
573  virtual ~RdataIterator() {}
574 private:
575  RdataIterator(const RdataIterator& source);
576  RdataIterator& operator=(const RdataIterator& source);
578 
579 public:
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 
629 class BasicRRset : public AbstractRRset {
637 
638 private:
639  BasicRRset(const BasicRRset& source);
640  BasicRRset& operator=(const BasicRRset& source);
641 public:
652  BasicRRset(const Name& name, const RRClass& rrclass,
653  const RRType& rrtype, const RRTTL& ttl);
655  virtual ~BasicRRset();
657 
661 
662  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  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  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  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  }
838 private:
839  BasicRRsetImpl* impl_;
840 };
841 
847 class RRset : public BasicRRset {
848 public:
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) {
874  BasicRRset::setTTL(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) {
900  RdataIteratorPtr it = sigs.getRdataIterator();
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 
932 private:
933  RRsetPtr rrsig_;
934 };
935 
936 
951 std::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:
The Name class encapsulates DNS names.
Definition: name.h:223
The BasicRRset class is a concrete derived class of AbstractRRset that defines a straightforward RRse...
Definition: rrset.h:629
virtual void addRRsig(const RRsetPtr &sigs)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:915
A generic exception that is thrown when a function is not implemented.
EmptyRRset(const char *file, size_t line, const char *what)
Definition: rrset.h:33
virtual void addRRsig(const rdata::ConstRdataPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:808
virtual void addRRsig(const RRsetPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:828
AbstractRRset()
The default constructor.
Definition: rrset.h:169
The RdataIterator class is an abstract base class that provides an interface for accessing RDATA obje...
Definition: rrset.h:558
This encapsulates the actual implementation of the BasicRRset class.
Definition: rrset.cc:161
RdataIterator()
The default constructor.
Definition: rrset.h:570
virtual void removeRRsig()
Clear the RRSIGs for this RRset.
Definition: rrset.h:918
boost::shared_ptr< const Rdata > ConstRdataPtr
Definition: rdata.h:72
The Rdata class is an abstract base class that provides a set of common interfaces to manipulate conc...
Definition: rdata.h:123
std::ostream & operator<<(std::ostream &os, const CSVRow &row)
Overrides standard output stream operator for CSVRow object.
Definition: csv_file.cc:100
virtual unsigned int getRRsigDataCount() const
Returns the number of RRSIG records associated with the RRset.
Definition: rrset.h:804
virtual void addRRsig(const ConstRRsetPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:823
virtual void addRRsig(const ConstRRsetPtr &sigs)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:912
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
virtual void addRRsig(const rdata::RdataPtr &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:813
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
virtual void setTTL(const RRTTL &ttl)
Updates the owner name of the RRset, including RRSIGs if any.
Definition: rrset.h:873
The RRTTL class encapsulates TTLs used in DNS resource records.
Definition: rrttl.h:55
virtual RdataIteratorPtr getRdataIterator() const =0
Return an iterator to go through all RDATA stored in the RRset.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
A standard DNS module exception that is thrown if an RRset object does not contain any RDATA where re...
Definition: rrset.h:31
virtual ~AbstractRRset()
The destructor.
Definition: rrset.h:172
Defines the logger used by the top-level component of kea-lfc.
The AbstractRRset class is an abstract base class that models a DNS RRset.
Definition: rrset.h:154
The RRset class is a concrete derived class of BasicRRset which contains a pointer to an additional R...
Definition: rrset.h:847
virtual void removeRRsig()
Clear the RRSIGs for this RRset.
Definition: rrset.h:833
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
virtual void addRRsig(const AbstractRRset &sigs)
Adds an RRSIG RRset to this RRset.
Definition: rrset.h:899
virtual void addRRsig(const rdata::ConstRdataPtr &rdata)
Adds an RRSIG RR to this RRset&#39;s signatures.
Definition: rrset.h:881
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
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:47
virtual ~RdataIterator()
Destructor.
Definition: rrset.h:573
virtual void addRRsig(const AbstractRRset &)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:818
boost::shared_ptr< Rdata > RdataPtr
The RdataPtr type is a pointer-like type, pointing to an object of some concrete derived class of Rda...
virtual RRsetPtr getRRsig() const
Return a pointer to this RRset&#39;s RRSIG RRset.
Definition: rrset.h:921
virtual void addRRsig(const rdata::RdataPtr &rdata)
Adds RRSIG RRset RRs to the associated RRSIG RRset.
Definition: rrset.h:893