rbnode_rrset.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __RBNODE_RRSET_H
  15. #define __RBNODE_RRSET_H
  16. #include <dns/messagerenderer.h>
  17. #include <dns/name.h>
  18. #include <dns/rrclass.h>
  19. #include <dns/rrset.h>
  20. #include <dns/rrttl.h>
  21. #include <dns/rrtype.h>
  22. #include <util/buffer.h>
  23. #include <string>
  24. namespace isc {
  25. namespace datasrc {
  26. namespace internal {
  27. /// \brief Special RRset for optimizing memory datasource requirement
  28. ///
  29. /// To speed up the performance of the in-memory data source, at load time
  30. /// associate relevant "additional section" data with each RRset in the
  31. /// data source.
  32. ///
  33. /// This class, derived from AbstractRRset, holds a "const" pointer to the
  34. /// underlying RRset object. All calls to methods on the class are passed to
  35. /// the underlying object. However, there are some restrictions:
  36. ///
  37. /// - Calls to methods that change attributes of the underlying RRset (such as
  38. /// TTL or Name) cause an exception to be thrown. The in-memory data source
  39. /// does not allow modification of these attributes.
  40. /// - Calls that add the pointer to the associated RRSIG to the RRset are
  41. /// allowed (even though the pointer is to a "const" RRset). The reason here
  42. /// is that RRSIGs are added to the in-memory data source after the
  43. /// RBNodeRRset objects have been created. Thus there has to be the
  44. /// capability of modifying this information.
  45. ///
  46. /// The class is not derived from RRset itself to simplify coding: part of the
  47. /// loading of the memory data source is handled in the BIND 10 "libdns++"
  48. /// code, which creates RRsets and passes them to the data source code. This
  49. /// does not have to be altered if encapsulation, rather than inheritcance, is
  50. /// used.
  51. // Note: non-Doxygen-documented methods are documented in the base class.
  52. class RBNodeRRset : public isc::dns::AbstractRRset {
  53. private:
  54. // Note: The copy constructor and the assignment operator are intentionally
  55. // defined as private as we would normally not duplicate a RBNodeRRset.
  56. // (We use the "private" method instead of inheriting from
  57. // boost::noncopyable so as to avoid multiple inheritance.)
  58. RBNodeRRset(const RBNodeRRset& source);
  59. RBNodeRRset& operator=(const RBNodeRRset& source);
  60. public:
  61. /// \brief Usual Constructor
  62. ///
  63. /// Creates an RBNodeRRset from the pointer to the RRset passed to it.
  64. ///
  65. /// \param rrset Pointer to underlying RRset encapsulated by this object.
  66. explicit RBNodeRRset(const isc::dns::ConstRRsetPtr& rrset) : rrset_(rrset)
  67. {}
  68. /// \brief Destructor
  69. virtual ~RBNodeRRset() {}
  70. // Getter and Setter Methods
  71. //
  72. // The getter methods pass the call through to the underlying RRset. The
  73. // setter methods thrown an exception - this specialisation of the RRset
  74. // object does not expect the underlying RRset to be modified.
  75. virtual unsigned int getRdataCount() const {
  76. return (rrset_->getRdataCount());
  77. }
  78. virtual const isc::dns::Name& getName() const {
  79. return (rrset_->getName());
  80. }
  81. virtual const isc::dns::RRClass& getClass() const {
  82. return (rrset_->getClass());
  83. }
  84. virtual const isc::dns::RRType& getType() const {
  85. return (rrset_->getType());
  86. }
  87. virtual const isc::dns::RRTTL& getTTL() const {
  88. return (rrset_->getTTL());
  89. }
  90. virtual void setName(const isc::dns::Name&) {
  91. isc_throw(isc::NotImplemented, "RBNodeRRset::setName() not supported");
  92. }
  93. virtual void setTTL(const isc::dns::RRTTL&) {
  94. isc_throw(isc::NotImplemented, "RBNodeRRset::setTTL() not supported");
  95. }
  96. virtual std::string toText() const {
  97. return (rrset_->toText());
  98. }
  99. virtual unsigned int toWire(
  100. isc::dns::AbstractMessageRenderer& renderer) const {
  101. return (rrset_->toWire(renderer));
  102. }
  103. virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const {
  104. return (rrset_->toWire(buffer));
  105. }
  106. virtual void addRdata(isc::dns::rdata::ConstRdataPtr) {
  107. isc_throw(isc::NotImplemented,
  108. "RBNodeRRset::addRdata() not supported");
  109. }
  110. virtual void addRdata(const isc::dns::rdata::Rdata&) {
  111. isc_throw(isc::NotImplemented,
  112. "RBNodeRRset::addRdata() not supported");
  113. }
  114. virtual isc::dns::RdataIteratorPtr getRdataIterator() const {
  115. return (rrset_->getRdataIterator());
  116. }
  117. virtual isc::dns::RRsetPtr getRRsig() const {
  118. return (rrset_->getRRsig());
  119. }
  120. // With all the RRsig methods, we have the problem that we store the
  121. // underlying RRset using a ConstRRsetPtr - a pointer to a "const" RRset -
  122. // but we need to modify it by adding or removing an RRSIG. We overcome
  123. // this by temporarily violating the "const" nature of the RRset to add the
  124. // data.
  125. virtual void addRRsig(const isc::dns::rdata::ConstRdataPtr& rdata) {
  126. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  127. p->addRRsig(rdata);
  128. }
  129. virtual void addRRsig(const isc::dns::rdata::RdataPtr& rdata) {
  130. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  131. p->addRRsig(rdata);
  132. }
  133. virtual void addRRsig(const AbstractRRset& sigs) {
  134. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  135. p->addRRsig(sigs);
  136. }
  137. virtual void addRRsig(const isc::dns::ConstRRsetPtr& sigs) {
  138. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  139. p->addRRsig(sigs);
  140. }
  141. virtual void addRRsig(const isc::dns::RRsetPtr& sigs) {
  142. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  143. p->addRRsig(sigs);
  144. }
  145. virtual void removeRRsig() {
  146. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  147. p->removeRRsig();
  148. }
  149. /// \brief Return underlying RRset pointer
  150. ///
  151. /// ... mainly for testing.
  152. isc::dns::ConstRRsetPtr getUnderlyingRRset() const {
  153. return (rrset_);
  154. }
  155. private:
  156. isc::dns::ConstRRsetPtr rrset_; ///< Underlying RRset
  157. };
  158. } // namespace internal
  159. } // namespace datasrc
  160. } // namespace isc
  161. #endif // __RBNODE_RRSET_H