char_string.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 DNS_RDATA_CHARSTRING_H
  15. #define DNS_RDATA_CHARSTRING_H 1
  16. #include <dns/master_lexer.h>
  17. #include <string>
  18. #include <vector>
  19. #include <stdint.h>
  20. namespace isc {
  21. namespace dns {
  22. namespace rdata {
  23. namespace generic {
  24. namespace detail {
  25. /// \brief Type for DNS character string.
  26. ///
  27. /// A character string can contain any unsigned 8-bit value, so this cannot
  28. /// be the bare char basis.
  29. typedef std::vector<uint8_t> CharString;
  30. /// \brief Convert a DNS character-string into corresponding binary data.
  31. ///
  32. /// This helper function takes a string object that is expected to be a
  33. /// textual representation of a valid DNS character-string, and dumps
  34. /// the corresponding binary sequence in the given placeholder (passed
  35. /// via the \c result parameter). It handles escape notations of
  36. /// character-strings with a backslash ('\'), and checks the length
  37. /// restriction.
  38. ///
  39. /// \throw CharStringTooLong The resulting binary data are too large for a
  40. /// valid character-string.
  41. /// \throw InvalidRdataText Other syntax errors.
  42. ///
  43. /// \brief str_region A string that represents a character-string.
  44. /// \brief result A placeholder vector where the resulting data are to be
  45. /// stored. Expected to be empty, but it's not checked.
  46. void stringToCharString(const MasterToken::StringRegion& str_region,
  47. CharString& result);
  48. /// \brief Convert a CharString into a textual DNS character-string.
  49. ///
  50. /// This method converts a binary 8-bit representation of a DNS
  51. /// character string into a textual string representation, escaping any
  52. /// special characters in the process. For example, characters like
  53. /// double-quotes, semi-colon and backspace are prefixed with backspace
  54. /// character, and characters not in the printable range of [0x20, 0x7e]
  55. /// (inclusive) are converted to the \xxx 3-digit decimal
  56. /// representation.
  57. ///
  58. /// \param char_string The \c CharString to convert.
  59. /// \return A string representation of \c char_string.
  60. std::string charStringToString(const CharString& char_string);
  61. } // namespace detail
  62. } // namespace generic
  63. } // namespace rdata
  64. } // namespace dns
  65. } // namespace isc
  66. #endif // DNS_RDATA_CHARSTRING_H
  67. // Local Variables:
  68. // mode: c++
  69. // End: