spf_99.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <stdint.h>
  15. #include <string.h>
  16. #include <string>
  17. #include <vector>
  18. #include <util/buffer.h>
  19. #include <dns/exceptions.h>
  20. #include <dns/messagerenderer.h>
  21. #include <dns/rdata.h>
  22. #include <dns/rdataclass.h>
  23. /// This class implements the basic interfaces inherited from the abstract
  24. /// \c rdata::Rdata class. The semantics of the class is provided by
  25. /// a copy of instantiated TXTLikeImpl class common to both TXT and SPF.
  26. #include <dns/rdata/generic/detail/txt_like.h>
  27. using namespace std;
  28. using namespace isc::util;
  29. // BEGIN_ISC_NAMESPACE
  30. // BEGIN_RDATA_NAMESPACE
  31. /// \brief The assignment operator
  32. ///
  33. /// It internally allocates a resource, and if it fails a corresponding
  34. /// standard exception will be thrown.
  35. /// This method never throws an exception otherwise.
  36. SPF&
  37. SPF::operator=(const SPF& source) {
  38. if (impl_ == source.impl_) {
  39. return (*this);
  40. }
  41. SPFImpl* newimpl = new SPFImpl(*source.impl_);
  42. delete impl_;
  43. impl_ = newimpl;
  44. return (*this);
  45. }
  46. /// \brief The destructor
  47. SPF::~SPF() {
  48. delete impl_;
  49. }
  50. /// \brief Constructor from wire-format data.
  51. ///
  52. /// It internally allocates a resource, and if it fails a corresponding
  53. /// standard exception will be thrown.
  54. SPF::SPF(InputBuffer& buffer, size_t rdata_len) :
  55. impl_(new SPFImpl(buffer, rdata_len))
  56. {}
  57. /// \brief Constructor using the master lexer.
  58. ///
  59. /// This implementation only uses the \c lexer parameters; others are
  60. /// ignored.
  61. ///
  62. /// \throw CharStringTooLong the parameter string length exceeds maximum.
  63. /// \throw InvalidRdataText the method cannot process the parameter data
  64. ///
  65. /// \param lexer A \c MasterLexer object parsing a master file for this
  66. /// RDATA.
  67. SPF::SPF(MasterLexer& lexer, const Name*, MasterLoader::Options,
  68. MasterLoaderCallbacks&) :
  69. impl_(new SPFImpl(lexer))
  70. {}
  71. /// \brief Constructor from string.
  72. ///
  73. /// It internally allocates a resource, and if it fails a corresponding
  74. /// standard exception will be thrown.
  75. SPF::SPF(const std::string& txtstr) :
  76. impl_(new SPFImpl(txtstr))
  77. {}
  78. /// \brief Copy constructor
  79. ///
  80. /// It internally allocates a resource, and if it fails a corresponding
  81. /// standard exception will be thrown.
  82. SPF::SPF(const SPF& other) :
  83. Rdata(), impl_(new SPFImpl(*other.impl_))
  84. {}
  85. /// \brief Render the \c SPF in the wire format to a OutputBuffer object
  86. ///
  87. /// \return is the return of the corresponding implementation method.
  88. void
  89. SPF::toWire(OutputBuffer& buffer) const {
  90. impl_->toWire(buffer);
  91. }
  92. /// \brief Render the \c SPF in the wire format to an AbstractMessageRenderer
  93. /// object
  94. ///
  95. /// \return is the return of the corresponding implementation method.
  96. void
  97. SPF::toWire(AbstractMessageRenderer& renderer) const {
  98. impl_->toWire(renderer);
  99. }
  100. /// \brief Convert the \c SPF to a string.
  101. ///
  102. /// \return is the return of the corresponding implementation method.
  103. string
  104. SPF::toText() const {
  105. return (impl_->toText());
  106. }
  107. /// \brief Compare two instances of \c SPF RDATA.
  108. ///
  109. /// This method compares \c this and the \c other \c SPF objects.
  110. ///
  111. /// This method is expected to be used in a polymorphic way, and the
  112. /// parameter to compare against is therefore of the abstract \c Rdata class.
  113. /// However, comparing two \c Rdata objects of different RR types
  114. /// is meaningless, and \c other must point to a \c SPF object;
  115. /// otherwise, the standard \c bad_cast exception will be thrown.
  116. ///
  117. /// \param other the right-hand operand to compare against.
  118. /// \return is the return of the corresponding implementation method.
  119. int
  120. SPF::compare(const Rdata& other) const {
  121. const SPF& other_txt = dynamic_cast<const SPF&>(other);
  122. return (impl_->compare(*other_txt.impl_));
  123. }
  124. // END_RDATA_NAMESPACE
  125. // END_ISC_NAMESPACE