You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

108 lines
3.3 KiB

  1. /*
  2. * This file is part of PowerDNS or dnsdist.
  3. * Copyright -- PowerDNS.COM B.V. and its contributors
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * In addition, for the avoidance of any doubt, permission is granted to
  10. * link this program with OpenSSL and to (re)distribute the binaries
  11. * produced as the result of such linking.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #pragma once
  23. #include <inttypes.h>
  24. #include <string>
  25. #include <stdexcept>
  26. #include "namespaces.hh"
  27. #include "dnsname.hh"
  28. #include "iputils.hh"
  29. class RecordTextException : public runtime_error
  30. {
  31. public:
  32. RecordTextException(const string& str) : runtime_error(str)
  33. {}
  34. };
  35. class RecordTextReader
  36. {
  37. public:
  38. RecordTextReader(const string& str, const DNSName& zone=DNSName(""));
  39. void xfr64BitInt(uint64_t& val);
  40. void xfr48BitInt(uint64_t& val);
  41. void xfr32BitInt(uint32_t& val);
  42. void xfr16BitInt(uint16_t& val);
  43. void xfr8BitInt(uint8_t& val);
  44. void xfrType(uint16_t& val);
  45. void xfrIP(uint32_t& val);
  46. void xfrIP6(std::string& val);
  47. void xfrCAWithoutPort(uint8_t version, ComboAddress &val);
  48. void xfrCAPort(ComboAddress &val);
  49. void xfrTime(uint32_t& val);
  50. void xfrName(DNSName& val, bool compress=false, bool noDot=false);
  51. void xfrText(string& val, bool multi=false, bool lenField=true);
  52. void xfrUnquotedText(string& val, bool lenField=true);
  53. void xfrHexBlob(string& val, bool keepReading=false);
  54. void xfrBase32HexBlob(string& val);
  55. void xfrBlobNoSpaces(string& val, int len=-1);
  56. void xfrBlob(string& val, int len=-1);
  57. const string getRemaining() const {
  58. return d_string.substr(d_pos);
  59. }
  60. bool eof();
  61. private:
  62. string d_string;
  63. DNSName d_zone;
  64. string::size_type d_pos;
  65. string::size_type d_end;
  66. void skipSpaces();
  67. };
  68. class RecordTextWriter
  69. {
  70. public:
  71. RecordTextWriter(string& str, bool noDot=false);
  72. void xfr48BitInt(const uint64_t& val);
  73. void xfr32BitInt(const uint32_t& val);
  74. void xfr16BitInt(const uint16_t& val);
  75. void xfr8BitInt(const uint8_t& val);
  76. void xfrIP(const uint32_t& val);
  77. void xfrIP6(const std::string& val);
  78. void xfrCAWithoutPort(uint8_t version, ComboAddress &val);
  79. void xfrCAPort(ComboAddress &val);
  80. void xfrTime(const uint32_t& val);
  81. void xfrBase32HexBlob(const string& val);
  82. void xfrType(const uint16_t& val);
  83. void xfrName(const DNSName& val, bool compress=false, bool noDot=false);
  84. void xfrText(const string& val, bool multi=false, bool lenField=true);
  85. void xfrUnquotedText(const string& val, bool lenField=true);
  86. void xfrBlobNoSpaces(const string& val, int len=-1);
  87. void xfrBlob(const string& val, int len=-1);
  88. void xfrHexBlob(const string& val, bool keepReading=false);
  89. bool eof() { return true; };
  90. const string getRemaining() const {
  91. return "";
  92. }
  93. private:
  94. string& d_string;
  95. bool d_nodot;
  96. };