rrset.h 28 KB

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