rrset.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. // Copyright (C) 2010 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 __RRSET_H
  15. #define __RRSET_H 1
  16. #include <iostream>
  17. #include <string>
  18. #include <boost/shared_ptr.hpp>
  19. #include <exceptions/exceptions.h>
  20. #include <dns/rdata.h>
  21. #include <dns/rrtype.h>
  22. namespace isc {
  23. namespace util {
  24. class OututBuffer;
  25. }
  26. namespace dns {
  27. ///
  28. /// \brief A standard DNS module exception that is thrown if an RRset object
  29. /// does not contain any RDATA where required.
  30. ///
  31. class EmptyRRset : public Exception {
  32. public:
  33. EmptyRRset(const char* file, size_t line, const char* what) :
  34. isc::Exception(file, line, what) {}
  35. };
  36. // forward declarations
  37. class Name;
  38. class RRType;
  39. class RRClass;
  40. class RRTTL;
  41. class AbstractMessageRenderer;
  42. class AbstractRRset;
  43. class BasicRRset;
  44. class RdataIterator;
  45. class BasicRRsetImpl;
  46. class RRset;
  47. /// \brief A pointer-like type pointing to an \c RRset object.
  48. ///
  49. /// This type is commonly used as an argument of various functions defined
  50. /// in this library in order to handle RRsets in a polymorphic manner.
  51. typedef boost::shared_ptr<RRset> RRsetPtr;
  52. /// \brief A pointer-like type pointing to an (immutable) \c RRset
  53. /// object.
  54. ///
  55. /// This type is commonly used as an argument of various functions defined
  56. /// in this library in order to handle RRsets in a polymorphic manner.
  57. typedef boost::shared_ptr<const RRset> ConstRRsetPtr;
  58. /// \brief A pointer-like type point to an \c RdataIterator object.
  59. typedef boost::shared_ptr<RdataIterator> RdataIteratorPtr;
  60. /// \brief The \c AbstractRRset class is an abstract base class that
  61. /// models a DNS RRset.
  62. ///
  63. /// An object of (a specific derived class of) \c AbstractRRset
  64. /// models an RRset as described in the DNS standard:
  65. /// A set of DNS resource records (RRs) of the same type and class.
  66. /// The standard requires the TTL of all RRs in an RRset be the same;
  67. /// this class follows that requirement.
  68. /// Note about duplicate RDATA: RFC2181 states that it's meaningless that an
  69. /// RRset contains two identical RRs and that name servers should suppress
  70. /// such duplicates.
  71. /// This class is not responsible for ensuring this requirement: For example,
  72. /// \c addRdata() method doesn't check if there's already RDATA identical
  73. /// to the one being added.
  74. /// This is because such checks can be expensive, and it's often easy to
  75. /// ensure the uniqueness requirement at the %data preparation phase
  76. /// (e.g. when loading a zone).
  77. /// When parsing an incoming DNS message, the uniqueness may not be guaranteed,
  78. /// so the application needs to detect and ignore any duplicate RDATA
  79. /// (the \c Message class of this library should provide this responsibility).
  80. ///
  81. /// Another point to note is that \c AbstractRRset and its derived classes
  82. /// allow an object to have an empty set of RDATA.
  83. /// Even though there's no corresponding notion in the protocol specification,
  84. /// it would be more intuitive for a container-like %data structure
  85. /// to allow an empty set.
  86. ///
  87. /// Since \c AbstractRRset is an abstract class, it is generally used
  88. /// via a pointer (or pointer like object) or a reference.
  89. /// In particular, \c RRsetPtr, a pointer like type for \c AbstractRRset,
  90. /// is used for polymorphic RRset operations throughout this library.
  91. ///
  92. /// The \c AbstractRRset class is also intended to be a major customization
  93. /// point. For example, a high performance server implementation may want
  94. /// to define an optimized "pre-compiled" RRset and provide an optimized
  95. /// implementation of the \c toWire() method.
  96. ///
  97. /// Note about design choice: In BIND9, a set of RDATA with a common tuple
  98. /// of RR class, RR type, and TTL was represented in a structure named
  99. /// \c rdataset. Unlike the RRset classes, an \c rdataset did not contain
  100. /// the information of the owner name.
  101. /// This might be advantageous if we want to handle "RRsets", that is,
  102. /// a set of different types of RRset for the same owner name, because
  103. /// a single "name" structure can be used for multiple RRsets, minimizing
  104. /// %data copy and memory footprint.
  105. /// On the other hand, it's inconvenient for API users since in many cases
  106. /// a pair of name and an \c rdataset must be maintained. It's also counter
  107. /// intuitive in implementing protocol operations as an RRset is often used
  108. /// as an atomic entity in DNS protocols while an \c rdataset is a component
  109. /// of an RRset.
  110. ///
  111. /// We have therefore defined the notion of RRset explicitly in our initial
  112. /// API design. We believe memory footprint is not a big concern because
  113. /// RRsets are generally expected to be used as temporary objects, e.g.
  114. /// while parsing or constructing a DNS message, or searching a DNS %data
  115. /// source; for longer term purposes such as in-memory %data source entries,
  116. /// the corresponding %data would be represented in a different, memory
  117. /// optimized format. As for the concern about %data copy, we believe
  118. /// it can be mitigated by using copy-efficient implementation for the
  119. /// \c Name class implementation, such as reference counted objects.
  120. /// Later, We plan to perform benchmark tests later to see if this assumption
  121. /// is valid and to revisit the design if necessary.
  122. ///
  123. /// Note about terminology: there has been a discussion at the IETF
  124. /// namedroppers ML about RRset vs RRSet (case of "s")
  125. /// [http://ops.ietf.org/lists/namedroppers/namedroppers.2009/msg02737.html].
  126. /// While RFC2181 uses the latter, many other RFCs use the former,
  127. /// and most of the list members who showed their opinion seem to prefer
  128. /// "RRset". We follow that preference in this implementation.
  129. ///
  130. /// The current design of \c AbstractRRset is still in flux.
  131. /// There are many open questions in design details:
  132. /// - support more set-like operations, e.g, merge two RRsets of the same
  133. /// type?
  134. /// - more convenient methods or non member utility functions, e.g.
  135. /// "sort" and "search(find)" method?
  136. /// - what about comparing two RRsets of the same type? If we need this,
  137. /// should it compare rdata's as a set or as a list (i.e. compare
  138. /// each rdata one by one or as a whole)? c.f. NLnet Labs' ldns
  139. /// (http://www.nlnetlabs.nl/projects/ldns/doc/index.html)
  140. /// has \c ldns_rr_list_compare(), which takes the latter approach
  141. /// (seemingly assuming the caller sorts the lists beforehand).
  142. /// - BIND9 libdns has some special DNSSEC-related methods
  143. /// such as \c addnoqname() or \c addclosest(). Do we need these?
  144. /// (Probably not. We wouldn't want to make the class design too
  145. /// monolithic.)
  146. /// - Do we need to allow the user to remove specific Rdata?
  147. /// Probably not, according to the current usage of the BIND9 code.
  148. class AbstractRRset {
  149. ///
  150. /// \name Constructors and Destructor
  151. ///
  152. /// Note: The copy constructor and the assignment operator are intentionally
  153. /// defined as private to make it explicit that this is a pure base class.
  154. //@{
  155. private:
  156. AbstractRRset(const AbstractRRset& source);
  157. AbstractRRset& operator=(const AbstractRRset& source);
  158. protected:
  159. /// \brief The default constructor.
  160. ///
  161. /// This is intentionally defined as \c protected as this base class should
  162. /// never be instantiated (except as part of a derived class).
  163. AbstractRRset() {}
  164. public:
  165. /// The destructor.
  166. virtual ~AbstractRRset() {}
  167. //@}
  168. ///
  169. /// \name Getter and Setter Methods
  170. ///
  171. /// These methods are generally expected to be exception free, but it's
  172. /// not guaranteed at the interface level;
  173. /// for example, some performance optimized derived class may manage
  174. /// the information corresponding to the class "attributes" to get or set,
  175. /// and may require dynamic memory allocation to execute the method.
  176. /// Consult the derived class description to see if a specific derived
  177. /// \c RRset class may throw an exception from these methods.
  178. ///
  179. /// Note that setter methods are not provided for \c RRClass and
  180. /// \c RRType. This is intentional. Since the format and semantics of
  181. /// \c Rdata are dependent on the RR type (and RR class for some RR types),
  182. /// allowing dynamically modify these attributes can easily lead to a
  183. /// bug where the RDATA and type and/or class become inconsistent.
  184. /// We want to avoid that situation by restricting the access.
  185. //@{
  186. /// \brief Returns the number of \c Rdata objects contained in the \c RRset.
  187. ///
  188. /// Note that an \c RRset with an empty set of \c Rdata can exist, so
  189. /// this method may return 0.
  190. ///
  191. /// \return The number of \c Rdata objects contained.
  192. virtual unsigned int getRdataCount() const = 0;
  193. /// \brief Returns the owner name of the \c RRset.
  194. ///
  195. /// \return A reference to a \c Name class object corresponding to the
  196. /// \c RRset owner name.
  197. virtual const Name& getName() const = 0;
  198. /// \brief Returns the RR Class of the \c RRset.
  199. ///
  200. /// \return A reference to a \c RRClass class object corresponding to the
  201. /// RR class of the \c RRset.
  202. virtual const RRClass& getClass() const = 0;
  203. /// \brief Returns the RR Type of the \c RRset.
  204. ///
  205. /// \return A reference to a \c RRType class object corresponding to the
  206. /// RR type of the \c RRset.
  207. virtual const RRType& getType() const = 0;
  208. /// \brief Returns the TTL of the RRset.
  209. ///
  210. /// \return A reference to a \c RRTTL class object corresponding to the
  211. /// TTL of the \c RRset.
  212. virtual const RRTTL& getTTL() const = 0;
  213. /// \brief Updates the owner name of the \c RRset.
  214. ///
  215. /// \param name A reference to a \c Name class object to be copied as the
  216. /// new name.
  217. virtual void setName(const Name& name) = 0;
  218. /// \brief Updates the TTL of the \c RRset.
  219. ///
  220. /// \param ttl A reference to a \c RRTTL class object to be copied as the
  221. /// new TTL.
  222. virtual void setTTL(const RRTTL& ttl) = 0;
  223. //@}
  224. ///
  225. /// \name Converter Methods
  226. ///
  227. /// These methods have the default implementation that can be reused by
  228. /// derived classes.
  229. /// Since they are defined as pure virtual, derived classes
  230. /// that want to reuse the default implementation must explicitly
  231. /// invoke their base class version (see the description for
  232. /// <code>addRdata(const rdata::Rdata&)</code>).
  233. ///
  234. /// Design Note: the default implementations are defined only using
  235. /// other public methods of the \c AbstractRRset class, and could be
  236. /// implemented as non member functions (as some C++ textbooks suggest).
  237. /// However, since derived classes may want to provide customized versions
  238. /// (especially of the \c toWire() method for performance reasons)
  239. /// we chose to define them as virtual functions, and, as a result,
  240. /// member functions.
  241. //@{
  242. /// \brief Convert the RRset to a string.
  243. ///
  244. /// Unlike other similar methods of this library, this method terminates
  245. /// the resulting string with a trailing newline character.
  246. /// (following the BIND9 convention)
  247. ///
  248. /// The RRset must contain some RDATA; otherwise, an exception of class
  249. /// \c EmptyRRset will be thrown.
  250. /// If resource allocation fails, a corresponding standard exception
  251. /// will be thrown.
  252. /// The default implementation may throw other exceptions if the
  253. /// \c toText() method of the RDATA objects throws.
  254. /// If a derived class of \c AbstractRRset overrides the default
  255. /// implementation, the derived version may throw its own exceptions.
  256. ///
  257. /// Open issue: We may want to support multiple output formats as
  258. /// BIND9 does. For example, we might want to allow omitting the owner
  259. /// name when possible in the context of zone dump. This is a future
  260. /// TODO item.
  261. ///
  262. /// \return A string representation of the RRset.
  263. virtual std::string toText() const = 0;
  264. /// \brief Render the RRset in the wire format with name compression and
  265. /// truncation handling.
  266. ///
  267. /// This method compresses the owner name of the RRset and domain names
  268. /// used in RDATA that should be compressed.
  269. /// In addition, this method detects the case where rendering the entire
  270. /// RRset would cause truncation, and handles the case appropriately
  271. /// (this is a TODO item, and not implemented in this version).
  272. ///
  273. /// Note: perhaps we may want to add more arguments to convey optional
  274. /// information such as an "rrset-order" policy or how to handle truncation
  275. /// case. This is a TODO item.
  276. ///
  277. /// If resource allocation fails, a corresponding standard exception
  278. /// will be thrown.
  279. /// The RRset must contain some RDATA; otherwise, an exception of class
  280. /// \c EmptyRRset will be thrown.
  281. /// The default implementation may throw other exceptions if the
  282. /// \c toWire() method of the RDATA objects throws.
  283. /// If a derived class of \c AbstractRRset overrides the default
  284. /// implementation, the derived version may throw its own exceptions.
  285. ///
  286. /// \param renderer DNS message rendering context that encapsulates the
  287. /// output buffer and name compression information.
  288. /// \return The number of RRs rendered. If the truncation is necessary
  289. /// this value may be different from the number of RDATA objects contained
  290. /// in the RRset.
  291. virtual unsigned int toWire(AbstractMessageRenderer& renderer) const = 0;
  292. /// \brief Render the RRset in the wire format without any compression.
  293. ///
  294. /// See the other toWire() description about possible exceptions.
  295. ///
  296. /// \param buffer An output buffer to store the wire data.
  297. /// \return The number of RRs rendered.
  298. virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const = 0;
  299. //@}
  300. ///
  301. /// \name RDATA Manipulation Methods
  302. ///
  303. //@{
  304. /// \brief Add an RDATA to the RRset (pointer version).
  305. ///
  306. /// This method adds the given RDATA (as a pointer-like type to a
  307. /// derived class object of \c rdata::Rdata) to the \c RRset.
  308. ///
  309. /// \param rdata A pointer (like) type of \c rdata::RdataPtr to be added
  310. /// to the \c RRset.
  311. virtual void addRdata(rdata::ConstRdataPtr rdata) = 0;
  312. /// \brief Add an RDATA to the RRset (reference version).
  313. ///
  314. /// This method adds the given RDATA (as a reference to a
  315. /// derived class object of \c rdata::Rdata) to the \c RRset.
  316. ///
  317. /// This method has the default implementation that can be reused by
  318. /// derived classes.
  319. /// Since this method is defined as pure virtual, derived classes
  320. /// that want to reuse the default implementation must explicitly
  321. /// invoke this base class version.
  322. /// For example, if the class \c CustomizedRRset, a derived class of
  323. /// \c AbstractRRset, wants to reuse the default implementation of
  324. /// \c %addRdata() (reference version), it would be defined as follows:
  325. /// \code void
  326. /// CustomizedRRset::addRdata(const rdata::Rdata& rdata)
  327. /// {
  328. /// AbstractRRset::addRdata(rdata);
  329. /// }
  330. /// \endcode
  331. ///
  332. /// This method is more strictly typed than the pointer version:
  333. /// If \c rdata does not refer to the appropriate derived
  334. /// \c Rdata class
  335. /// for the \c RRType for this \c RRset, it throws an exception of class
  336. /// \c std::bad_cast.
  337. /// If resource allocation fails, a corresponding standard exception
  338. /// will be thrown.
  339. /// The RRset must contain some RDATA; otherwise, an exception of class
  340. /// \c EmptyRRset will be thrown.
  341. /// The default implementation may throw other exceptions if the
  342. /// \c toWire() method of the RDATA objects throws.
  343. /// If a derived class of \c AbstractRRset overrides the default
  344. /// implementation, the derived version may throw its own exceptions.
  345. ///
  346. /// The default implementation simply constructs an \c rdata::RdataPtr
  347. /// object from a newly allocated RDATA object copying from parameter
  348. /// \c rdata, and calls the other version of
  349. /// \c addRdata(const rdata::RdataPtr).
  350. /// So it is inherently less efficient than the other version.
  351. /// Still, this version would offer a more intuitive interface and is
  352. /// provided as such.
  353. ///
  354. /// \param rdata A reference to a \c rdata::RdataPtr (derived) class
  355. /// object, a copy of which is to be added to the \c RRset.
  356. virtual void addRdata(const rdata::Rdata& rdata) = 0;
  357. /// \brief Return an iterator to go through all RDATA stored in the
  358. /// \c RRset.
  359. ///
  360. /// The rdata cursor of the returned iterator will point to the first
  361. /// RDATA, that is, it effectively calls \c RdataIterator::first()
  362. /// internally.
  363. ///
  364. /// Using the design pattern terminology, \c getRdataIterator()
  365. /// is an example of a <em>factory method</em>.
  366. ///
  367. /// Whether this method throws an exception depends on the actual
  368. /// implementation of the derived \c AbstractRRset class, but in general
  369. /// it will involve resource allocation and can throw a standard exception
  370. /// if it fails.
  371. ///
  372. /// \return A pointer-like object pointing to the derived \c RdataIterator
  373. /// object.
  374. virtual RdataIteratorPtr getRdataIterator() const = 0;
  375. //@}
  376. };
  377. /// \brief The \c RdataIterator class is an abstract base class that
  378. /// provides an interface for accessing RDATA objects stored in an RRset.
  379. ///
  380. /// While different derived classes of \c AbstractRRset may maintain the RDATA
  381. /// objects in different ways, the \c RdataIterator class provides a
  382. /// unified interface to iterate over the RDATA objects in a polymorphic
  383. /// manner.
  384. ///
  385. /// Each derived class of \c AbstractRRset is expected to provide a concrete
  386. /// derived class of \c RdataIterator, and each derived \c RdataIterator
  387. /// class implements the unified interface in a way specific to the
  388. /// implementation of the corresponding derived \c AbstractRRset class.
  389. /// Using the design pattern terminology, this is a typical example of
  390. /// the \e Iterator pattern.
  391. ///
  392. /// The RDATA objects stored in the \c RRset are considered to form
  393. /// a unidirectional list from the \c RdataIterator point of view (while
  394. /// the actual implementation in the derived \c RRset may not use a list).
  395. /// We call this unidirectional list the <em>rdata list</em>.
  396. ///
  397. /// An \c RdataIterator object internally (and conceptually) holds a
  398. /// <em>rdata cursor</em>, which points to a specific item of the rdata list.
  399. ///
  400. /// Note about design choice: as is clear from the interface, \c RdataIterator
  401. /// is not compatible with the standard iterator classes.
  402. /// Although it would be useful (for example, we could then use STL algorithms)
  403. /// and is not necessarily impossible, it would make the iterator implementation
  404. /// much more complicated.
  405. /// For instance, any standard iterator must be assignable and
  406. /// copy-constructible.
  407. /// So we'd need to implement \c RdataIterator::operator=() in a polymorphic
  408. /// way. This will require non-trivial implementation tricks.
  409. /// We believe the simplified iterator interface as provided by the
  410. /// \c RdataIterator class is sufficient in practice:
  411. /// Most applications will simply go through the RDATA objects contained in
  412. /// an RRset, examining (and possibly using) each object, as one path
  413. /// operation.
  414. class RdataIterator {
  415. ///
  416. /// \name Constructors and Destructor
  417. ///
  418. /// Note: The copy constructor and the assignment operator are intentionally
  419. /// defined as private to make it explicit that this is a pure base class.
  420. //@{
  421. protected:
  422. /// \brief The default constructor.
  423. ///
  424. /// This is intentionally defined as \c protected as this base class should
  425. /// never be instantiated (except as part of a derived class).
  426. RdataIterator() {}
  427. public:
  428. /// \brief Destructor
  429. virtual ~RdataIterator() {}
  430. private:
  431. RdataIterator(const RdataIterator& source);
  432. RdataIterator& operator=(const RdataIterator& source);
  433. //@}
  434. public:
  435. /// \brief Move the rdata cursor to the first RDATA in the rdata list
  436. /// (if any).
  437. ///
  438. /// This method can safely be called multiple times, even after moving
  439. /// the rdata cursor forward by the \c next() method.
  440. ///
  441. /// This method should never throw an exception.
  442. virtual void first() = 0;
  443. /// \brief Move the rdata cursor to the next RDATA in the rdata list
  444. /// (if any).
  445. ///
  446. /// This method should never throw an exception.
  447. virtual void next() = 0;
  448. /// \brief Return the current \c Rdata corresponding to the rdata cursor.
  449. ///
  450. /// \return A reference to an \c rdata::Rdata object corresponding
  451. /// to the rdata cursor.
  452. virtual const rdata::Rdata& getCurrent() const = 0;
  453. /// \brief Return true iff the rdata cursor has reached the end of the
  454. /// rdata list.
  455. ///
  456. /// Once this method returns \c true, the behavior of any subsequent
  457. /// call to \c next() or \c getCurrent() is undefined.
  458. /// Likewise, the result of \c isLast() call followed by such undefined
  459. /// operations is also undefined.
  460. ///
  461. /// This method should never throw an exception.
  462. ///
  463. /// \return \c true if the rdata cursor has reached the end of the
  464. /// rdata list; otherwise \c false.
  465. virtual bool isLast() const = 0;
  466. };
  467. /// \brief The \c BasicRRset class is a concrete derived class of
  468. /// \c AbstractRRset that defines a straightforward RRset implementation.
  469. ///
  470. /// This class is designed to be as portable as possible, and so it adopts
  471. /// the Pimpl idiom to hide as many details as possible.
  472. /// Performance is a secondary concern for this class.
  473. ///
  474. /// This class is intended to be used by applications that only need
  475. /// moderate level of performance with full functionality provided by
  476. /// the \c AbstractRRset interfaces.
  477. /// Highly performance-sensitive applications, such as a large scale
  478. /// authoritative or caching name servers will implement and use a customized
  479. /// version of derived \c AbstractRRset class.
  480. class BasicRRset : public AbstractRRset {
  481. ///
  482. /// \name Constructors and Destructor
  483. ///
  484. /// Note: The copy constructor and the assignment operator are intentionally
  485. /// defined as private. The intended use case wouldn't require copies of
  486. /// a \c BasicRRset object; once created, it would normally be used
  487. /// as a \c const object (via references).
  488. //@{
  489. private:
  490. BasicRRset(const BasicRRset& source);
  491. BasicRRset& operator=(const BasicRRset& source);
  492. public:
  493. /// \brief Constructor from (mostly) fixed parameters of the RRset.
  494. ///
  495. /// This constructor is normally expected to be exception free, but
  496. /// copying the name may involve resource allocation, and if it fails
  497. /// the corresponding standard exception will be thrown.
  498. ///
  499. /// \param name The owner name of the RRset.
  500. /// \param rrclass The RR class of the RRset.
  501. /// \param rrtype The RR type of the RRset.
  502. /// \param ttl The TTL of the RRset.
  503. BasicRRset(const Name& name, const RRClass& rrclass,
  504. const RRType& rrtype, const RRTTL& ttl);
  505. /// \brief The destructor.
  506. virtual ~BasicRRset();
  507. //@}
  508. ///
  509. /// \name Getter and Setter Methods
  510. ///
  511. //@{
  512. /// \brief Returns the number of \c Rdata objects contained in the \c RRset.
  513. ///
  514. /// This method never throws an exception.
  515. ///
  516. /// \return The number of \c Rdata objects contained.
  517. virtual unsigned int getRdataCount() const;
  518. /// \brief Returns the owner name of the \c RRset.
  519. ///
  520. /// This method never throws an exception.
  521. ///
  522. /// \return A reference to a \c Name class object corresponding to the
  523. /// \c RRset owner name.
  524. virtual const Name& getName() const;
  525. /// \brief Returns the RR Class of the \c RRset.
  526. ///
  527. /// This method never throws an exception.
  528. ///
  529. /// \return A reference to a \c RRClass class object corresponding to the
  530. /// RR class of the \c RRset.
  531. virtual const RRClass& getClass() const;
  532. /// \brief Returns the RR Type of the \c RRset.
  533. ///
  534. /// This method never throws an exception.
  535. ///
  536. /// \return A reference to a \c RRType class object corresponding to the
  537. /// RR type of the \c RRset.
  538. virtual const RRType& getType() const;
  539. /// \brief Returns the TTL of the \c RRset.
  540. ///
  541. /// This method never throws an exception.
  542. ///
  543. /// \return A reference to a \c RRTTL class object corresponding to the
  544. /// TTL of the \c RRset.
  545. virtual const RRTTL& getTTL() const;
  546. /// \brief Updates the owner name of the \c RRset.
  547. ///
  548. /// This method normally does not throw an exception, but could throw
  549. /// some standard exception on resource allocation failure if the
  550. /// internal copy of the \c name involves resource allocation and it
  551. /// fails.
  552. ///
  553. /// \param name A reference to a \c Name class object to be copied as the
  554. /// new name.
  555. virtual void setName(const Name& name);
  556. /// \brief Updates the TTL of the \c RRset.
  557. ///
  558. /// This method never throws an exception.
  559. ///
  560. /// \param ttl A reference to a \c RRTTL class object to be copied as the
  561. /// new TTL.
  562. virtual void setTTL(const RRTTL& ttl);
  563. //@}
  564. ///
  565. /// \name Converter Methods
  566. ///
  567. //@{
  568. /// \brief Convert the RRset to a string.
  569. ///
  570. /// This method simply uses the default implementation.
  571. /// See \c AbstractRRset::toText().
  572. virtual std::string toText() const;
  573. /// \brief Render the RRset in the wire format with name compression and
  574. /// truncation handling.
  575. ///
  576. /// This method simply uses the default implementation.
  577. /// See \c AbstractRRset::toWire(MessageRenderer&)const.
  578. virtual unsigned int toWire(AbstractMessageRenderer& renderer) const;
  579. /// \brief Render the RRset in the wire format without any compression.
  580. ///
  581. /// This method simply uses the default implementation.
  582. /// See \c AbstractRRset::toWire(OutputBuffer&)const.
  583. virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const;
  584. //@}
  585. ///
  586. /// \name RDATA manipulation methods
  587. ///
  588. //@{
  589. /// \brief Add an RDATA to the RRset (pointer version).
  590. ///
  591. /// This method is normally expected to be exception free, but it may
  592. /// involve resource allocation, and if it fails the corresponding
  593. /// standard exception will be thrown.
  594. ///
  595. /// \param rdata A pointer (like) type of \c rdata::RdataPtr to be added
  596. /// to the \c BasicRRset.
  597. virtual void addRdata(rdata::ConstRdataPtr rdata);
  598. /// \brief Add an RDATA to the RRset (reference version).
  599. ///
  600. /// This method simply uses the default implementation.
  601. /// See \c AbstractRRset::addRdata(const rdata::Rdata&).
  602. virtual void addRdata(const rdata::Rdata& rdata);
  603. /// \brief Return an iterator to go through all RDATA stored in the
  604. /// \c BasicRRset.
  605. ///
  606. /// This is a concrete derived implementation of
  607. /// \c AbstractRRset::getRdataIterator().
  608. ///
  609. /// This method dynamically allocates resources. If it fails it will
  610. /// throw the corresponding standard exception.
  611. /// The iterator methods for the \c BasicRRset class are exception free.
  612. ///
  613. /// \return A pointer-like object pointing to the derived \c RdataIterator
  614. /// object for the \c BasicRRset class.
  615. virtual RdataIteratorPtr getRdataIterator() const;
  616. //@}
  617. private:
  618. BasicRRsetImpl* impl_;
  619. };
  620. /// \brief The \c RRset class is a concrete derived class of
  621. /// \c BasicRRset which contains a pointer to an additional RRset
  622. /// containing associated RRSIG records. This allows DNSSEC aware
  623. /// applications to treat data associated with a particular
  624. /// QNAME/QTYPE/QCLASS as a single object.
  625. class RRset : public BasicRRset {
  626. public:
  627. RRset(const Name& name, const RRClass& rrclass,
  628. const RRType& rrtype, const RRTTL& ttl);
  629. virtual ~RRset();
  630. /// \brief Updates the owner name of the \c RRset, including RRSIGs if any
  631. virtual void setName(const Name& n) {
  632. BasicRRset::setName(n);
  633. if (rrsig_) {
  634. rrsig_->setName(n);
  635. }
  636. }
  637. /// \brief Updates the owner name of the \c RRset, including RRSIGs if any
  638. virtual void setTTL(const RRTTL& ttl) {
  639. BasicRRset::setTTL(ttl);
  640. if (rrsig_) {
  641. rrsig_->setTTL(ttl);
  642. }
  643. }
  644. /// \brief Adds an RRSIG RR to this RRset's signatures
  645. virtual void addRRsig(const rdata::RdataPtr rdata) {
  646. if (!rrsig_) {
  647. rrsig_ = RRsetPtr(new RRset(getName(), getClass(),
  648. RRType::RRSIG(), getTTL()));
  649. }
  650. rrsig_->addRdata(rdata);
  651. }
  652. /// \brief Adds an RRSIG RRset to this RRset
  653. void addRRsig(AbstractRRset& sigs) {
  654. RdataIteratorPtr it = sigs.getRdataIterator();
  655. if (!rrsig_) {
  656. rrsig_ = RRsetPtr(new RRset(getName(), getClass(),
  657. RRType::RRSIG(), getTTL()));
  658. }
  659. for (it->first(); !it->isLast(); it->next()) {
  660. rrsig_->addRdata(it->getCurrent());
  661. }
  662. }
  663. void addRRsig(RRsetPtr sigs) { addRRsig(*sigs); }
  664. /// \brief Clear the RRSIGs for this RRset
  665. void removeRRsig() { rrsig_ = RRsetPtr(); }
  666. /// \brief Return a pointer to this RRset's RRSIG RRset
  667. RRsetPtr getRRsig() const { return (rrsig_); }
  668. private:
  669. RRsetPtr rrsig_;
  670. };
  671. /// \brief Insert the \c RRset as a string into stream.
  672. ///
  673. /// This method convert the \c rrset into a string and inserts it into the
  674. /// output stream \c os.
  675. ///
  676. /// This function overloads the global \c operator<< to behave as described in
  677. /// \c %ostream::%operator<< but applied to RRset objects.
  678. ///
  679. /// \param os A \c std::ostream object on which the insertion operation is
  680. /// performed.
  681. /// \param rrset A reference to a (derived class of) \c AbstractRRset object
  682. /// output by the operation.
  683. /// \return A reference to the same \c std::ostream object referenced by
  684. /// parameter \c os after the insertion operation.
  685. std::ostream& operator<<(std::ostream& os, const AbstractRRset& rrset);
  686. } // end of namespace dns
  687. } // end of namespace isc
  688. #endif // __RRSET_H
  689. // Local Variables:
  690. // mode: c++
  691. // End: