rbnode_rrset.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 modify the associated RRSIGs of the RRset are allowed (even
  41. /// though the pointer is to a "const" object). The reason here is because
  42. /// RRSIGs are added to the in-memory data source after the RBNodeRRset
  43. /// objects have been created. Thus there has to be the capability of
  44. /// 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 boost::noncopyable
  57. // 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. RBNodeRRset(const isc::dns::ConstRRsetPtr& rrset) : rrset_(rrset) {}
  67. /// \brief Destructor
  68. virtual ~RBNodeRRset() {}
  69. // Getter and Setter Methods
  70. //
  71. // The getter methods pass the call through to the underlying RRset. The
  72. // setter methods thrown an exception - this specialisation of the RRset
  73. // object does not expect the underlying RRset to be modified.
  74. virtual unsigned int getRdataCount() const {
  75. return (rrset_->getRdataCount());
  76. }
  77. virtual const isc::dns::Name& getName() const {
  78. return (rrset_->getName());
  79. }
  80. virtual const isc::dns::RRClass& getClass() const {
  81. return (rrset_->getClass());
  82. }
  83. virtual const isc::dns::RRType& getType() const {
  84. return (rrset_->getType());
  85. }
  86. virtual const isc::dns::RRTTL& getTTL() const {
  87. return (rrset_->getTTL());
  88. }
  89. virtual void setName(const isc::dns::Name&) {
  90. isc_throw(isc::NotImplemented, "RBNodeRRset::setName() not supported");
  91. }
  92. virtual void setTTL(const isc::dns::RRTTL&) {
  93. isc_throw(isc::NotImplemented, "RBNodeRRset::setTTL() not supported");
  94. }
  95. virtual std::string toText() const {
  96. return (rrset_->toText());
  97. }
  98. virtual unsigned int toWire(
  99. isc::dns::AbstractMessageRenderer& renderer) const {
  100. return (rrset_->toWire(renderer));
  101. }
  102. virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const {
  103. return (rrset_->toWire(buffer));
  104. }
  105. virtual void addRdata(isc::dns::rdata::ConstRdataPtr) {
  106. isc_throw(isc::NotImplemented,
  107. "RBNodeRRset::addRdata() not supported");
  108. }
  109. virtual void addRdata(const isc::dns::rdata::Rdata&) {
  110. isc_throw(isc::NotImplemented,
  111. "RBNodeRRset::addRdata() not supported");
  112. }
  113. virtual isc::dns::RdataIteratorPtr getRdataIterator() const {
  114. return (rrset_->getRdataIterator());
  115. }
  116. virtual isc::dns::RRsetPtr getRRsig() const {
  117. return (rrset_->getRRsig());
  118. }
  119. // With all the RRsig methods, we have the problem that we store the
  120. // underlying RRset using a ConstRRsetPtr - a pointer to a "const" RRset -
  121. // but we need to modify it by adding or removing an RRSIG. We overcome
  122. // this by temporarily violating the "const" nature of the RRset to add the
  123. // data.
  124. virtual void addRRsig(const isc::dns::rdata::ConstRdataPtr& rdata) {
  125. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  126. p->addRRsig(rdata);
  127. }
  128. virtual void addRRsig(const isc::dns::rdata::RdataPtr& rdata) {
  129. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  130. p->addRRsig(rdata);
  131. }
  132. virtual void addRRsig(const AbstractRRset& sigs) {
  133. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  134. p->addRRsig(sigs);
  135. }
  136. virtual void addRRsig(const isc::dns::ConstRRsetPtr& sigs) {
  137. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  138. p->addRRsig(sigs);
  139. }
  140. virtual void addRRsig(const isc::dns::RRsetPtr& sigs) {
  141. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  142. p->addRRsig(sigs);
  143. }
  144. virtual void removeRRsig() {
  145. AbstractRRset* p = const_cast<AbstractRRset*>(rrset_.get());
  146. p->removeRRsig();
  147. }
  148. /// \brief Return underlying RRset pointer
  149. ///
  150. /// ... mainly for testing.
  151. virtual isc::dns::ConstRRsetPtr getUnderlyingRRset() const {
  152. return (rrset_);
  153. }
  154. private:
  155. isc::dns::ConstRRsetPtr rrset_; ///< Underlying RRset
  156. };
  157. } // namespace internal
  158. } // namespace datasrc
  159. } // namespace isc
  160. #endif // __RBNODE_RRSET_H