rdata.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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 RDATA_H
  15. #define RDATA_H 1
  16. #include <dns/master_lexer.h>
  17. #include <dns/master_loader.h>
  18. #include <dns/master_loader_callbacks.h>
  19. #include <exceptions/exceptions.h>
  20. #include <boost/shared_ptr.hpp>
  21. #include <stdint.h>
  22. namespace isc {
  23. namespace util {
  24. class InputBuffer;
  25. class OutputBuffer;
  26. }
  27. namespace dns {
  28. class AbstractMessageRenderer;
  29. class RRType;
  30. class RRClass;
  31. class Name;
  32. namespace rdata {
  33. ///
  34. /// \brief A standard DNS module exception that is thrown if RDATA parser
  35. /// encounters an invalid or inconsistent data length.
  36. ///
  37. class InvalidRdataLength : public Exception {
  38. public:
  39. InvalidRdataLength(const char* file, size_t line, const char* what) :
  40. isc::Exception(file, line, what) {}
  41. };
  42. ///
  43. /// \brief A standard DNS module exception that is thrown if RDATA parser
  44. /// fails to recognize a given textual representation.
  45. ///
  46. class InvalidRdataText : public Exception {
  47. public:
  48. InvalidRdataText(const char* file, size_t line, const char* what) :
  49. isc::Exception(file, line, what) {}
  50. };
  51. ///
  52. /// \brief A standard DNS module exception that is thrown if RDATA parser
  53. /// parser encounters a character-string (as defined in RFC1035) exceeding
  54. /// the maximum allowable length (\c MAX_CHARSTRING_LEN).
  55. ///
  56. class CharStringTooLong : public Exception {
  57. public:
  58. CharStringTooLong(const char* file, size_t line, const char* what) :
  59. isc::Exception(file, line, what) {}
  60. };
  61. // Forward declaration to define RdataPtr.
  62. class Rdata;
  63. ///
  64. /// The \c RdataPtr type is a pointer-like type, pointing to an
  65. /// object of some concrete derived class of \c Rdata.
  66. ///
  67. typedef boost::shared_ptr<Rdata> RdataPtr;
  68. typedef boost::shared_ptr<const Rdata> ConstRdataPtr;
  69. /// \brief Possible maximum length of RDATA, which is the maximum unsigned
  70. /// 16 bit value.
  71. const size_t MAX_RDLENGTH = 65535;
  72. /// \brief The maximum allowable length of character-string containing in
  73. /// RDATA as defined in RFC1035, not including the 1-byte length field.
  74. const unsigned int MAX_CHARSTRING_LEN = 255;
  75. /// \brief The \c Rdata class is an abstract base class that provides
  76. /// a set of common interfaces to manipulate concrete RDATA objects.
  77. ///
  78. /// Generally, a separate derived class directly inherited from the base
  79. /// \c Rdata class is defined for each well known RDATA.
  80. /// Each of such classes will define the common logic based on the
  81. /// corresponding protocol standard.
  82. ///
  83. /// Since some types of RRs are class specific and the corresponding RDATA
  84. /// may have different semantics (e.g. type A for class IN and type A for
  85. /// class CH have different representations and semantics), we separate
  86. /// \c Rdata derived classes for such RR types in different namespaces.
  87. /// The namespace of types specific to a class is named the lower-cased class
  88. /// name; for example, RDATA of class IN-specific types are defined in the
  89. /// \c in namespace, and RDATA of class CH-specific types are defined in
  90. /// the \c ch namespace, and so on.
  91. /// The derived classes are named using the RR type name (upper cased) such as
  92. /// \c A or \c AAAA.
  93. /// Thus RDATA of type A RR for class IN and CH are defined as \c in::A and
  94. /// \c ch::A, respectively.
  95. /// Many other RR types are class independent; the derived \c Rdata classes
  96. /// for such RR types are defined in the \c generic namespace. Examples are
  97. /// \c generic::NS and \c generic::SOA.
  98. ///
  99. /// If applications need to refer to these derived classes, it is generally
  100. /// recommended to prepend at least some part of the namespace because the
  101. /// same class name can be used in different namespaces.
  102. /// So, instead of doing
  103. /// \code using namespace isc::dns::rdata::in;
  104. /// A& rdata_type_a; \endcode
  105. /// it is advisable to prepend at least \c in from the namespace:
  106. /// \code using namespace isc::dns::rdata;
  107. /// in::A& rdata_type_a; \endcode
  108. ///
  109. /// In many cases, however, an application doesn't have to care about such
  110. /// derived classes.
  111. /// For instance, to parse an incoming DNS message an application wouldn't
  112. /// have to perform type specific operation unless the application is
  113. /// specifically concerned about a particular type.
  114. /// So, this API generally handles \c Rdata in a polymorphic way through
  115. /// a pointer or reference to this base abstract class.
  116. class Rdata {
  117. ///
  118. /// \name Constructors and Destructor
  119. ///
  120. /// Note: The copy constructor and the assignment operator are intentionally
  121. /// defined as private. Concrete classes should generally specialize their
  122. /// own versions of these methods.
  123. //@{
  124. protected:
  125. /// The default constructor.
  126. ///
  127. /// This is intentionally defined as \c protected as this base class should
  128. /// never be instantiated (except as part of a derived class). In many
  129. /// cases, the derived class wouldn't define a public default constructor
  130. /// either, because an \c Rdata object without concrete data isn't
  131. /// meaningful.
  132. Rdata() {}
  133. private:
  134. Rdata(const Rdata& source);
  135. void operator=(const Rdata& source);
  136. public:
  137. /// The destructor.
  138. virtual ~Rdata() {};
  139. //@}
  140. ///
  141. /// \name Converter methods
  142. ///
  143. //@{
  144. /// \brief Convert an \c Rdata to a string.
  145. ///
  146. /// This method returns a \c std::string object representing the \c Rdata.
  147. ///
  148. /// This is a pure virtual method without the definition; the actual
  149. /// representation is specific to each derived concrete class and
  150. /// should be explicitly defined in the derived class.
  151. ///
  152. /// \return A string representation of \c Rdata.
  153. virtual std::string toText() const = 0;
  154. /// \brief Render the \c Rdata in the wire format into a buffer.
  155. ///
  156. /// This is a pure virtual method without the definition; the actual
  157. /// conversion is specific to each derived concrete class and
  158. /// should be explicitly defined in the derived class.
  159. ///
  160. /// \param buffer An output buffer to store the wire data.
  161. virtual void toWire(isc::util::OutputBuffer& buffer) const = 0;
  162. /// \brief Render the \c Rdata in the wire format into a
  163. /// \c MessageRenderer object.
  164. ///
  165. /// This is a pure virtual method without the definition; the actual
  166. /// conversion is specific to each derived concrete class and
  167. /// should be explicitly defined in the derived class.
  168. ///
  169. /// \param renderer DNS message rendering context that encapsulates the
  170. /// output buffer in which the \c Rdata is to be stored.
  171. virtual void toWire(AbstractMessageRenderer& renderer) const = 0;
  172. //@}
  173. ///
  174. /// \name Comparison method
  175. ///
  176. //@{
  177. /// \brief Compare two instances of \c Rdata.
  178. ///
  179. /// This method compares \c this and the \c other Rdata objects
  180. /// in terms of the DNSSEC sorting order as defined in RFC4034, and returns
  181. /// the result as an integer.
  182. ///
  183. /// This is a pure virtual method without the definition; the actual
  184. /// comparison logic is specific to each derived concrete class and
  185. /// should be explicitly defined in the derived class.
  186. ///
  187. /// Specific implementations of this method must confirm that \c this
  188. /// and the \c other are objects of the same concrete derived class of
  189. /// \c Rdata. This is normally done by \c dynamic_cast in the
  190. /// implementation. It also means if the assumption isn't met
  191. /// an exception of class \c std::bad_cast will be thrown.
  192. ///
  193. /// Here is an implementation choice: instead of relying on
  194. /// \c dynamic_cast, we could first convert the data into wire-format
  195. /// and compare the pair as opaque data. This would be more polymorphic,
  196. /// but might involve significant overhead, especially for a large size
  197. /// of RDATA.
  198. ///
  199. /// \param other the right-hand operand to compare against.
  200. /// \return < 0 if \c this would be sorted before \c other.
  201. /// \return 0 if \c this is identical to \c other in terms of sorting order.
  202. /// \return > 0 if \c this would be sorted after \c other.
  203. virtual int compare(const Rdata& other) const = 0;
  204. //@}
  205. };
  206. namespace generic {
  207. /// \brief The \c GenericImpl class is the actual implementation of the
  208. /// \c generic::Generic class.
  209. ///
  210. /// The implementation is hidden from applications. This approach requires
  211. /// dynamic memory allocation on construction, copy, or assignment, but
  212. /// we believe it should be acceptable as "unknown" RDATA should be pretty
  213. /// rare.
  214. struct GenericImpl;
  215. /// \brief The \c generic::Generic class represents generic "unknown" RDATA.
  216. ///
  217. /// This class is used as a placeholder for all non well-known type of RDATA.
  218. /// By definition, the stored data is regarded as opaque binary without
  219. /// assuming any structure.
  220. class Generic : public Rdata {
  221. public:
  222. ///
  223. /// \name Constructors, Assignment Operator and Destructor.
  224. ///
  225. //@{
  226. /// \brief Constructor from a string.
  227. ///
  228. /// This method constructs a \c generic::Generic object from a textual
  229. /// representation as defined in RFC3597.
  230. ///
  231. /// If \c rdata_string isn't a valid textual representation of this type
  232. /// of RDATA, an exception of class \c InvalidRdataText or
  233. /// \c InvalidRdataLength will be thrown.
  234. /// If resource allocation to store the data fails, a corresponding standard
  235. /// exception will be thrown.
  236. ///
  237. /// \param rdata_string A string of textual representation of generic
  238. /// RDATA.
  239. explicit Generic(const std::string& rdata_string);
  240. ///
  241. /// \brief Constructor from wire-format data.
  242. ///
  243. /// The \c buffer parameter normally stores a complete DNS message
  244. /// containing the generic RDATA to be constructed.
  245. /// The current read position of the buffer points to the head of the
  246. /// data.
  247. ///
  248. /// This method reads \c rdata_len bytes from the \c buffer, and internally
  249. /// stores the data as an opaque byte sequence.
  250. ///
  251. /// \c rdata_len must not exceed \c MAX_RDLENGTH; otherwise, an exception
  252. /// of class \c InvalidRdataLength will be thrown.
  253. /// If resource allocation to hold the data fails, a corresponding standard
  254. /// exception will be thrown; if the \c buffer doesn't contain \c rdata_len
  255. /// bytes of unread data, an exception of class \c InvalidBufferPosition
  256. /// will be thrown.
  257. ///
  258. /// \param buffer A reference to an \c InputBuffer object storing the
  259. /// \c Rdata to parse.
  260. /// \param rdata_len The length in buffer of the \c Rdata. In bytes.
  261. Generic(isc::util::InputBuffer& buffer, size_t rdata_len);
  262. /// \brief Constructor from master lexer.
  263. ///
  264. Generic(MasterLexer& lexer, const Name* name,
  265. MasterLoader::Options options, MasterLoaderCallbacks& callbacks);
  266. ///
  267. /// \brief The destructor.
  268. virtual ~Generic();
  269. ///
  270. /// \brief The copy constructor.
  271. ///
  272. /// If resource allocation to copy the data fails, a corresponding standard
  273. /// exception will be thrown.
  274. ///
  275. /// \param source A reference to a \c generic::Generic object to copy from.
  276. Generic(const Generic& source);
  277. ///
  278. /// \brief The assignment operator.
  279. ///
  280. /// If resource allocation to copy the data fails, a corresponding standard
  281. /// exception will be thrown.
  282. ///
  283. /// \param source A reference to a \c generic::Generic object to copy from.
  284. Generic& operator=(const Generic& source);
  285. //@}
  286. ///
  287. /// \name Converter methods
  288. ///
  289. //@{
  290. /// \brief Convert an \c generic::Generic object to a string.
  291. ///
  292. /// This method converts a generic "unknown" RDATA object into a textual
  293. /// representation of such unknown data as defined in RFC3597.
  294. ///
  295. /// If resource allocation to copy the data fails, a corresponding standard
  296. /// exception will be thrown.
  297. ///
  298. /// \return A string representation of \c generic::Generic.
  299. virtual std::string toText() const;
  300. ///
  301. /// \brief Render the \c generic::Generic in the wire format into a buffer.
  302. ///
  303. /// This will require \c rdata_len bytes of remaining capacity in the
  304. /// \c buffer. If this is not the case and resource allocation for the
  305. /// necessary memory space fails, a corresponding standard exception will
  306. /// be thrown.
  307. ///
  308. /// \param buffer An output buffer to store the wire data.
  309. virtual void toWire(isc::util::OutputBuffer& buffer) const;
  310. /// \brief Render the \c generic::Generic in the wire format into a
  311. /// \c MessageRenderer object.
  312. ///
  313. /// This will require \c rdata_len bytes of remaining capacity in the
  314. /// \c buffer. If this is not the case and resource allocation for the
  315. /// necessary memory space fails, a corresponding standard exception will
  316. /// be thrown.
  317. ///
  318. /// \param renderer DNS message rendering context that encapsulates the
  319. /// output buffer in which the \c Generic object is to be stored.
  320. virtual void toWire(AbstractMessageRenderer& renderer) const;
  321. //@}
  322. ///
  323. /// \name Comparison method
  324. ///
  325. //@{
  326. /// \brief Compare two instances of \c generic::Generic objects.
  327. ///
  328. /// As defined in RFC4034, this method simply compares the wire-format
  329. /// representations of the two objects as left-justified unsigned octet
  330. /// sequences.
  331. ///
  332. /// The object referenced by \c other must have been instantiated as
  333. /// a c generic::Generic class object; otherwise, an exception of class
  334. /// \c std::bad_cast will be thrown.
  335. /// Note that the comparison is RR type/class agnostic: this method doesn't
  336. /// check whether the two \c Rdata objects to compare are of the comparable
  337. /// RR type/class. For example, \c this object may come from an \c RRset
  338. /// of \c RRType x, and the \c other may come from a different \c RRset
  339. /// of \c RRType y (where x != y). This situation would be considered a
  340. /// bug, but this method cannot detect this type of error.
  341. /// The caller must ensure this condition.
  342. ///
  343. /// \param other the right-hand operand to compare against.
  344. /// \return < 0 if \c this would be sorted before \c other.
  345. /// \return 0 if \c this is identical to \c other in terms of sorting order.
  346. /// \return > 0 if \c this would be sorted after \c other.
  347. virtual int compare(const Rdata& other) const;
  348. //@}
  349. private:
  350. void constructHelper(const std::string& rdata_string);
  351. GenericImpl* impl_;
  352. };
  353. ///
  354. /// \brief Insert the name as a string into stream.
  355. ///
  356. /// This method convert the \c rdata into a string and inserts it into the
  357. /// output stream \c os.
  358. ///
  359. /// This function overloads the global \c operator<< to behave as described in
  360. /// \c ostream::operator<< but applied to \c generic::Generic Rdata objects.
  361. ///
  362. /// \param os A \c std::ostream object on which the insertion operation is
  363. /// performed.
  364. /// \param rdata The \c Generic object output by the operation.
  365. /// \return A reference to the same \c std::ostream object referenced by
  366. /// parameter \c os after the insertion operation.
  367. std::ostream& operator<<(std::ostream& os, const Generic& rdata);
  368. } // end of namespace "generic"
  369. //
  370. // Non class-member functions related to Rdata
  371. //
  372. ///
  373. /// \name Parameterized Polymorphic RDATA Factories
  374. ///
  375. /// This set of global functions provide a unified interface to create an
  376. /// \c Rdata object in a parameterized polymorphic way,
  377. /// that is, these functions take a pair of \c RRType and \c RRClass
  378. /// objects and data specific to that pair, and create an object of
  379. /// the corresponding concrete derived class of \c Rdata.
  380. ///
  381. /// These will be useful when parsing/constructing a DNS message or
  382. /// parsing a master file, where information for a specific type of RDATA
  383. /// is given but the resulting object, once created, should better be used
  384. /// in a polymorphic way.
  385. ///
  386. /// For example, if a master file parser encounters an NS RR
  387. /// \verbatim example.com. 3600 IN NS ns.example.com.\endverbatim
  388. /// it stores the text fragments "IN", "NS", and "ns.example.com." in
  389. /// \c std::string objects \c class_txt, \c type_txt, and \c nsname_txt,
  390. /// respectively, then it would create a new \c RdataPtr object as follows:
  391. /// \code RdataPtr rdata = createRdata(RRType(type_txt), RRClass(class_txt),
  392. /// nsname_txt); \endcode
  393. /// On success, \c rdata will point to an object of the \c generic::NS class
  394. /// that internally holds a domain name of "ns.example.com."
  395. ///
  396. /// Internally, these functions uses the corresponding
  397. /// \c RRParamRegistry::createRdata methods of the \c RRParamRegistry.
  398. /// See also the description on these methods for related notes.
  399. //@{
  400. /// \brief Create RDATA of a given pair of RR type and class from a string.
  401. ///
  402. /// This method creates from a string an \c Rdata object of the given pair
  403. /// of RR type and class.
  404. ///
  405. /// \param rrtype An \c RRType object specifying the type/class pair.
  406. /// \param rrclass An \c RRClass object specifying the type/class pair.
  407. /// \param rdata_string A string of textual representation of the \c Rdata.
  408. /// \return An \c RdataPtr object pointing to the created \c Rdata
  409. /// object.
  410. RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
  411. const std::string& rdata_string);
  412. /// \brief Create RDATA of a given pair of RR type and class from
  413. /// wire-format data.
  414. ///
  415. /// This method creates from wire-format binary data an \c Rdata object
  416. /// of the given pair of RR type and class.
  417. ///
  418. /// \c len must not exceed the protocol defined maximum value, \c MAX_RDLENGTH;
  419. /// otherwise, an exception of class \c InvalidRdataLength will be thrown.
  420. ///
  421. /// In some cases, the length of the RDATA is determined without the
  422. /// information of \c len. For example, the RDATA length of an IN/A RR
  423. /// must always be 4. If \c len is not equal to the actual length in such
  424. /// cases, an exception of class InvalidRdataLength will be thrown.
  425. ///
  426. /// \param rrtype An \c RRType object specifying the type/class pair.
  427. /// \param rrclass An \c RRClass object specifying the type/class pair.
  428. /// \param buffer A reference to an \c InputBuffer object storing the
  429. /// \c Rdata to parse.
  430. /// \param len The length in buffer of the \c Rdata. In bytes.
  431. /// \return An \c RdataPtr object pointing to the created \c Rdata
  432. /// object.
  433. RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
  434. isc::util::InputBuffer& buffer, size_t len);
  435. /// \brief Create RDATA of a given pair of RR type and class, copying
  436. /// of another RDATA of same kind.
  437. ///
  438. /// This method creates an \c Rdata object of the given pair of
  439. /// RR type and class, copying the content of the given \c Rdata,
  440. /// \c source.
  441. ///
  442. /// \param rrtype An \c RRType object specifying the type/class pair.
  443. /// \param rrclass An \c RRClass object specifying the type/class pair.
  444. /// \param source A reference to an \c Rdata object whose content
  445. /// is to be copied to the created \c Rdata object.
  446. /// \return An \c RdataPtr object pointing to the created
  447. /// \c Rdata object.
  448. RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
  449. const Rdata& source);
  450. /// \brief Create RDATA of a given pair of RR type and class using the
  451. /// master lexer.
  452. ///
  453. /// This is a more generic form of factory from textual RDATA, and is mainly
  454. /// intended to be used internally by the master file parser (\c MasterLoader)
  455. /// of this library.
  456. ///
  457. /// The \c lexer is expected to be at the beginning of textual RDATA of the
  458. /// specified type and class. This function (and its underlying Rdata
  459. /// implementations) extracts necessary tokens from the lexer and constructs
  460. /// the RDATA from them.
  461. ///
  462. /// Due to the intended usage of this version, this function handles error
  463. /// cases quite differently from other versions. It internally catches
  464. /// most of syntax and semantics errors of the input (reported as exceptions),
  465. /// calls the corresponding callback specified by the \c callbacks parameters,
  466. /// and returns a NULL smart pointer. If the caller rather wants to get
  467. /// an exception in these cases, it can pass a callback that internally
  468. /// throws on error. Some critical exceptions such as \c std::bad_alloc are
  469. /// still propagated to the upper layer as it doesn't make sense to try
  470. /// recovery from such a situation within this function.
  471. ///
  472. /// Whether or not the creation succeeds, this function updates the lexer
  473. /// until it reaches either the end of line or file, starting from the end of
  474. /// the RDATA text (or the point of failure if the parsing fails in the
  475. /// middle of it). The caller can therefore assume it's ready for reading
  476. /// the next data (which is normally a subsequent RR in the zone file) on
  477. /// return, whether or not this function succeeds.
  478. ///
  479. /// \param rrtype An \c RRType object specifying the type/class pair.
  480. /// \param rrclass An \c RRClass object specifying the type/class pair.
  481. /// \param lexer A \c MasterLexer object parsing a master file for the
  482. /// RDATA to be created
  483. /// \param origin If non NULL, specifies the origin of any domain name fields
  484. /// of the RDATA that are non absolute.
  485. /// \param options Master loader options controlling how to deal with errors
  486. /// or non critical issues in the parsed RDATA.
  487. /// \param callbacks Callback to be called when an error or non critical issue
  488. /// is found.
  489. /// \return An \c RdataPtr object pointing to the created
  490. /// \c Rdata object. Will be NULL if parsing fails.
  491. RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
  492. MasterLexer& lexer, const Name* origin,
  493. MasterLoader::Options options,
  494. MasterLoaderCallbacks& callbacks);
  495. //@}
  496. ///
  497. /// \brief Gives relative ordering of two names in terms of DNSSEC RDATA
  498. /// ordering.
  499. ///
  500. /// This method compares two names as defined in Sections 6.2 and 6.3 of
  501. /// RFC4034: Comparing two names in their canonical form
  502. /// (i.e., converting upper case ASCII characters to lower ones) and
  503. /// as a left-justified unsigned octet sequence. Note that the ordering is
  504. /// different from that for owner names. For example, "a.example" should be
  505. /// sorted before "example" as RDATA, but the ordering is the opposite when
  506. /// compared as owner names.
  507. ///
  508. /// Normally, applications would not need this function directly.
  509. /// This is mostly an internal helper function for \c Rdata related classes
  510. /// to implement their \c compare() method.
  511. /// This function is publicly open, however, for the convenience of
  512. /// external developers who want to implement new or experimental RR types.
  513. ///
  514. /// This function never throws an exception as long as the given names are
  515. /// valid \c Name objects.
  516. ///
  517. /// Additional note about applicability: In fact, BIND9's similar function,
  518. /// \c dns_name_rdatacompare(), is only used in rdata implementations and
  519. /// for testing purposes.
  520. ///
  521. /// \param n1,n2 \c Name class objects to compare.
  522. /// \return -1 if \c n1 would be sorted before \c n2.
  523. /// \return 0 if \c n1 is identical to \c n2 in terms of sorting order.
  524. /// \return 1 if \c n1 would be sorted after \c n2.
  525. ///
  526. int compareNames(const Name& n1, const Name& n2);
  527. } // end of namespace "rdata"
  528. }
  529. }
  530. #endif // RDATA_H
  531. // Local Variables:
  532. // mode: c++
  533. // End: