]>
Commit | Line | Data |
---|---|---|
4192ca66 | 1 | /* |
12471842 PL |
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 | */ | |
4192ca66 BH |
22 | #ifndef PDNS_RCPGENERATOR_HH |
23 | #define PDNS_RCPGENERATOR_HH | |
2b808f13 | 24 | #include <inttypes.h> |
4192ca66 BH |
25 | #include <string> |
26 | #include <stdexcept> | |
27 | ||
10f4eea8 | 28 | #include "namespaces.hh" |
4a51ff72 | 29 | #include "dnsname.hh" |
f4352636 | 30 | #include "iputils.hh" |
4192ca66 BH |
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: | |
3716f081 | 42 | RecordTextReader(const string& str, const DNSName& zone=DNSName("")); |
341930bb BH |
43 | void xfr64BitInt(uint64_t& val); |
44 | void xfr48BitInt(uint64_t& val); | |
cbf0e7f3 BH |
45 | void xfr32BitInt(uint32_t& val); |
46 | void xfr16BitInt(uint16_t& val); | |
8c1c9170 | 47 | void xfr8BitInt(uint8_t& val); |
cbf0e7f3 | 48 | |
20133c59 | 49 | void xfrType(uint16_t& val); |
cbf0e7f3 | 50 | void xfrIP(uint32_t& val); |
b9b28916 | 51 | void xfrIP6(std::string& val); |
f4352636 PD |
52 | void xfrCAWithoutPort(uint8_t version, ComboAddress &val); |
53 | void xfrCAPort(ComboAddress &val); | |
8bf26468 BH |
54 | void xfrTime(uint32_t& val); |
55 | ||
f21fc0aa | 56 | void xfrName(DNSName& val, bool compress=false, bool noDot=false); |
84e1142d | 57 | void xfrText(string& val, bool multi=false, bool lenField=true); |
948a927f | 58 | void xfrUnquotedText(string& val, bool lenField=true); |
e4090157 | 59 | void xfrHexBlob(string& val, bool keepReading=false); |
8b606f6e | 60 | void xfrBase32HexBlob(string& val); |
1c4d88c5 | 61 | |
2fe9d6f7 | 62 | void xfrBlobNoSpaces(string& val, int len=-1); |
06ffdc52 | 63 | void xfrBlob(string& val, int len=-1); |
4192ca66 | 64 | |
ddb79bca AT |
65 | const string getRemaining() const { |
66 | return d_string.substr(d_pos); | |
67 | } | |
68 | ||
20133c59 | 69 | bool eof(); |
4192ca66 BH |
70 | private: |
71 | string d_string; | |
3716f081 | 72 | DNSName d_zone; |
4192ca66 BH |
73 | string::size_type d_pos; |
74 | string::size_type d_end; | |
75 | void skipSpaces(); | |
76 | }; | |
77 | ||
78 | class RecordTextWriter | |
79 | { | |
80 | public: | |
f21fc0aa | 81 | RecordTextWriter(string& str, bool noDot=false); |
341930bb | 82 | void xfr48BitInt(const uint64_t& val); |
cbf0e7f3 BH |
83 | void xfr32BitInt(const uint32_t& val); |
84 | void xfr16BitInt(const uint16_t& val); | |
8c1c9170 | 85 | void xfr8BitInt(const uint8_t& val); |
cbf0e7f3 | 86 | void xfrIP(const uint32_t& val); |
b9b28916 | 87 | void xfrIP6(const std::string& val); |
f4352636 PD |
88 | void xfrCAWithoutPort(uint8_t version, ComboAddress &val); |
89 | void xfrCAPort(ComboAddress &val); | |
8bf26468 | 90 | void xfrTime(const uint32_t& val); |
1c4d88c5 | 91 | void xfrBase32HexBlob(const string& val); |
20133c59 BH |
92 | |
93 | void xfrType(const uint16_t& val); | |
f21fc0aa | 94 | void xfrName(const DNSName& val, bool compress=false, bool noDot=false); |
84e1142d | 95 | void xfrText(const string& val, bool multi=false, bool lenField=true); |
948a927f | 96 | void xfrUnquotedText(const string& val, bool lenField=true); |
2fe9d6f7 | 97 | void xfrBlobNoSpaces(const string& val, int len=-1); |
06ffdc52 | 98 | void xfrBlob(const string& val, int len=-1); |
e4090157 | 99 | void xfrHexBlob(const string& val, bool keepReading=false); |
d476d7fb | 100 | bool eof() { return true; }; |
ddb79bca AT |
101 | |
102 | const string getRemaining() const { | |
103 | return ""; | |
104 | } | |
4192ca66 BH |
105 | private: |
106 | string& d_string; | |
f21fc0aa | 107 | bool d_nodot; |
4192ca66 | 108 | }; |
4192ca66 | 109 | #endif |