]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/rcpgenerator.hh
Merge pull request #14021 from Habbie/auth-lua-join-whitespace
[thirdparty/pdns.git] / pdns / rcpgenerator.hh
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 #ifndef PDNS_RCPGENERATOR_HH
23 #define PDNS_RCPGENERATOR_HH
24 #include <inttypes.h>
25 #include <string>
26 #include <stdexcept>
27
28 #include "namespaces.hh"
29 #include "dnsname.hh"
30 #include "iputils.hh"
31
32 class RecordTextException : public runtime_error
33 {
34 public:
35 RecordTextException(const string& str) : runtime_error(str)
36 {}
37 };
38
39 class RecordTextReader
40 {
41 public:
42 RecordTextReader(const string& str, const DNSName& zone=DNSName(""));
43 void xfr64BitInt(uint64_t& val);
44 void xfr48BitInt(uint64_t& val);
45 void xfr32BitInt(uint32_t& val);
46 void xfr16BitInt(uint16_t& val);
47 void xfr8BitInt(uint8_t& val);
48
49 void xfrType(uint16_t& val);
50 void xfrIP(uint32_t& val);
51 void xfrIP6(std::string& val);
52 void xfrCAWithoutPort(uint8_t version, ComboAddress &val);
53 void xfrCAPort(ComboAddress &val);
54 void xfrTime(uint32_t& val);
55
56 void xfrName(DNSName& val, bool compress=false, bool noDot=false);
57 void xfrText(string& val, bool multi=false, bool lenField=true);
58 void xfrUnquotedText(string& val, bool lenField=true);
59 void xfrHexBlob(string& val, bool keepReading=false);
60 void xfrBase32HexBlob(string& val);
61
62 void xfrBlobNoSpaces(string& val, int len=-1);
63 void xfrBlob(string& val, int len=-1);
64
65 const string getRemaining() const {
66 return d_string.substr(d_pos);
67 }
68
69 bool eof();
70 private:
71 string d_string;
72 DNSName d_zone;
73 string::size_type d_pos;
74 string::size_type d_end;
75 void skipSpaces();
76 };
77
78 class RecordTextWriter
79 {
80 public:
81 RecordTextWriter(string& str, bool noDot=false);
82 void xfr48BitInt(const uint64_t& val);
83 void xfr32BitInt(const uint32_t& val);
84 void xfr16BitInt(const uint16_t& val);
85 void xfr8BitInt(const uint8_t& val);
86 void xfrIP(const uint32_t& val);
87 void xfrIP6(const std::string& val);
88 void xfrCAWithoutPort(uint8_t version, ComboAddress &val);
89 void xfrCAPort(ComboAddress &val);
90 void xfrTime(const uint32_t& val);
91 void xfrBase32HexBlob(const string& val);
92
93 void xfrType(const uint16_t& val);
94 void xfrName(const DNSName& val, bool compress=false, bool noDot=false);
95 void xfrText(const string& val, bool multi=false, bool lenField=true);
96 void xfrUnquotedText(const string& val, bool lenField=true);
97 void xfrBlobNoSpaces(const string& val, int len=-1);
98 void xfrBlob(const string& val, int len=-1);
99 void xfrHexBlob(const string& val, bool keepReading=false);
100 bool eof() { return true; };
101
102 const string getRemaining() const {
103 return "";
104 }
105 private:
106 string& d_string;
107 bool d_nodot;
108 };
109 #endif