dname_39.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #include <config.h>
  15. #include <string>
  16. #include <util/buffer.h>
  17. #include <dns/name.h>
  18. #include <dns/messagerenderer.h>
  19. #include <dns/rdata.h>
  20. #include <dns/rdataclass.h>
  21. #include <dns/rdata/generic/detail/lexer_util.h>
  22. using namespace std;
  23. using namespace isc::util;
  24. using isc::dns::rdata::generic::detail::createNameFromLexer;
  25. // BEGIN_ISC_NAMESPACE
  26. // BEGIN_RDATA_NAMESPACE
  27. DNAME::DNAME(const std::string& namestr) :
  28. // Fill in dummy name and replace it soon below.
  29. dname_(Name::ROOT_NAME())
  30. {
  31. try {
  32. std::istringstream ss(namestr);
  33. MasterLexer lexer;
  34. lexer.pushSource(ss);
  35. dname_ = createNameFromLexer(lexer, NULL);
  36. if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
  37. isc_throw(InvalidRdataText, "extra input text for DNAME: "
  38. << namestr);
  39. }
  40. } catch (const MasterLexer::LexerError& ex) {
  41. isc_throw(InvalidRdataText, "Failed to construct DNAME from '" <<
  42. namestr << "': " << ex.what());
  43. }
  44. }
  45. DNAME::DNAME(InputBuffer& buffer, size_t) :
  46. dname_(buffer)
  47. {
  48. // we don't need rdata_len for parsing. if necessary, the caller will
  49. // check consistency.
  50. }
  51. DNAME::DNAME(MasterLexer& lexer, const Name* origin,
  52. MasterLoader::Options, MasterLoaderCallbacks&) :
  53. dname_(createNameFromLexer(lexer, origin))
  54. {}
  55. DNAME::DNAME(const DNAME& other) :
  56. Rdata(), dname_(other.dname_)
  57. {}
  58. DNAME::DNAME(const Name& dname) :
  59. dname_(dname)
  60. {}
  61. void
  62. DNAME::toWire(OutputBuffer& buffer) const {
  63. dname_.toWire(buffer);
  64. }
  65. void
  66. DNAME::toWire(AbstractMessageRenderer& renderer) const {
  67. // Type DNAME is not "well-known", and name compression must be disabled
  68. // per RFC3597.
  69. renderer.writeName(dname_, false);
  70. }
  71. string
  72. DNAME::toText() const {
  73. return (dname_.toText());
  74. }
  75. int
  76. DNAME::compare(const Rdata& other) const {
  77. const DNAME& other_dname = dynamic_cast<const DNAME&>(other);
  78. return (compareNames(dname_, other_dname.dname_));
  79. }
  80. const Name&
  81. DNAME::getDname() const {
  82. return (dname_);
  83. }
  84. // END_RDATA_NAMESPACE
  85. // END_ISC_NAMESPACE