rdata_encoder.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright (C) 2012 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 DATASRC_MEMORY_RDATA_ENCODER_H
  15. #define DATASRC_MEMORY_RDATA_ENCODER_H 1
  16. #include <dns/labelsequence.h>
  17. #include <dns/rdata.h>
  18. #include <dns/rrclass.h>
  19. #include <dns/rrtype.h>
  20. #include <boost/function.hpp>
  21. #include <boost/noncopyable.hpp>
  22. #include <vector>
  23. namespace isc {
  24. namespace datasrc {
  25. namespace memory {
  26. /// \brief Attributes of domain name fields of encoded RDATA.
  27. ///
  28. /// The enum values define special traits of the name that can affect how
  29. /// it should be handled in rendering or query processing.
  30. enum RdataNameAttributes {
  31. NAMEATTR_COMPRESSIBLE = 1, ///< Name should be compressed when rendered
  32. NAMEATTR_ADDITIONAL = (NAMEATTR_COMPRESSIBLE << 1) ///< Name requires
  33. ///< Additional section
  34. ///< handling
  35. };
  36. /// \brief TBD
  37. ///
  38. /// Encoding, FYI:
  39. /// uint16_t n1_1: size of 1st variable len field (if any) of 1st RDATA
  40. /// uint16_t n1_2: size of 2nd variable len field of 1st RDATA
  41. /// ...
  42. /// uint16_t nN_M: size of last (Mth) variable len field of last (Nth) RDATA
  43. /// A sequence of packed data fields follow:
  44. /// uint8_t[]: data field value, length specified by nI_J (in case it's
  45. /// variable) or by the field spec (in case it's fixed-length).
  46. /// or
  47. /// opaque data, LabelSequence::getSerializedLength() bytes: data for a name
  48. /// (a possible 1-byte padding)
  49. /// uint16_t ns1: size of 1st RRSIG data
  50. /// ...
  51. /// uint16_t nsL: size of last (Lth) RRSIG data
  52. /// uint8_t[ns1]: 1st RRSIG data
  53. /// ...
  54. /// uint8_t[nsL]: last RRSIG data
  55. class RdataEncoder : boost::noncopyable {
  56. public:
  57. /// \brief Default constructor.
  58. RdataEncoder();
  59. /// \brief The destrcutor.
  60. ~RdataEncoder();
  61. void start(dns::RRClass rrclass, dns::RRType rrtype);
  62. void addRdata(const dns::rdata::Rdata& rdata);
  63. size_t getStorageLength() const;
  64. void encode(void* buf, size_t buf_len) const;
  65. private:
  66. struct RdataEncoderImpl;
  67. RdataEncoderImpl* impl_;
  68. };
  69. // We use the following quick-hack version of encoder and "foreach"
  70. // operator until we implement the complete versions. The plan is to
  71. // update the test cases that use these functions with the complete
  72. // functions/classes, and then remove the entire namespace.
  73. namespace testing {
  74. // Callbacks used in foreachRdataField.
  75. typedef boost::function<void(const dns::LabelSequence&,
  76. RdataNameAttributes)> NameCallback;
  77. typedef boost::function<void(const uint8_t*, size_t)> DataCallback;
  78. // Iterate over each field (in terms of the internal encoding) of each
  79. // RDATA stored in encoded_data, and call the given callback for each
  80. // data (for domain name fields, name_callback will be called; for
  81. // normal data fields data_callback will be called). rdata_count is
  82. // the number of RDATAs. If the encoded data contain variable-length
  83. // data fields, varlen_list should store a sequence of their lengths,
  84. // in the of the appearance.
  85. void foreachRdataField(dns::RRClass rrclass, dns::RRType rrtype,
  86. size_t rdata_count,
  87. const std::vector<uint8_t>& encoded_data,
  88. const std::vector<uint16_t>& varlen_list,
  89. NameCallback name_callback, DataCallback data_callback);
  90. }
  91. } // namespace memory
  92. } // namespace datasrc
  93. } // namespace isc
  94. #endif // DATASRC_MEMORY_RDATA_ENCODER_H
  95. // Local Variables:
  96. // mode: c++
  97. // End: