]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/qtype.hh
Merge pull request #14021 from Habbie/auth-lua-join-whitespace
[thirdparty/pdns.git] / pdns / qtype.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 QTYPE_HH
23 #define QTYPE_HH
24 // $Id$
25 #include <string>
26 #include <vector>
27 #include "namespaces.hh"
28
29 /** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS',
30 * 'CNAME' etcetera. These types have both a name and a number. This class can seamlessly move between
31 * them. Use it like this:
32
33 \code
34 QType t;
35 t="CNAME";
36 cout<<t.getCode()<<endl; // prints '5'
37 t=6;
38 cout<<t.getName()<<endl; // prints 'SOA'
39 \endcode
40
41 */
42
43
44
45 class QType
46 {
47 public:
48 QType(); //!< Naked constructor
49 explicit QType(uint16_t); //!< convert from an integer to a QType
50 QType(const QType& orig) : code(orig.code)
51 {
52 }
53 QType &operator=(uint16_t); //!< Assigns integers to us
54 QType &operator=(const char *); //!< Assigns strings to us
55 QType &operator=(const string &); //!< Assigns strings to us
56 QType &operator=(const QType&rhs) //!< Assigns strings to us
57 {
58 code=rhs.code;
59 return *this;
60 }
61
62 bool operator<(const QType& rhs) const
63 {
64 return code < rhs.code;
65 }
66
67 const string getName() const; //!< Get a string representation of this type
68 uint16_t getCode() const; //!< Get the integer representation of this type
69 bool isSupportedType();
70 bool isMetadataType();
71
72 static int chartocode(const char *p); //!< convert a character string to a code
73 enum typeenum : uint16_t {
74 ENT=0,
75 A=1,
76 NS=2,
77 CNAME=5,
78 SOA=6,
79 MB=7,
80 MG=8,
81 MR=9,
82 WKS=11,
83 PTR=12,
84 HINFO=13,
85 MINFO=14,
86 MX=15,
87 TXT=16,
88 RP=17,
89 AFSDB=18,
90 SIG=24,
91 KEY=25,
92 AAAA=28,
93 LOC=29,
94 SRV=33,
95 NAPTR=35,
96 KX=36,
97 CERT=37,
98 A6=38,
99 DNAME=39,
100 OPT=41,
101 DS=43,
102 SSHFP=44,
103 IPSECKEY=45,
104 RRSIG=46,
105 NSEC=47,
106 DNSKEY=48,
107 DHCID=49,
108 NSEC3=50,
109 NSEC3PARAM=51,
110 TLSA=52,
111 SMIMEA=53,
112 RKEY=57,
113 CDS=59,
114 CDNSKEY=60,
115 OPENPGPKEY=61,
116 SPF=99,
117 EUI48=108,
118 EUI64=109,
119 TKEY=249,
120 TSIG=250,
121 IXFR=251,
122 AXFR=252,
123 MAILB=253,
124 MAILA=254,
125 ANY=255,
126 URI=256,
127 CAA=257,
128 DLV=32769,
129 ADDR=65400,
130 ALIAS=65401,
131 LUA=65402
132 };
133
134 QType(typeenum orig) : code(orig)
135 {
136 }
137
138 typedef pair<string,uint16_t> namenum;
139 static vector<namenum> names;
140
141 inline bool operator==(const QType &comp) const {
142 return(comp.code==code);
143 }
144
145 inline bool operator!=(const QType &comp) const {
146 return(comp.code!=code);
147 }
148
149 inline bool operator==(QType::typeenum comp) const {
150 return(comp==code);
151 }
152
153 inline bool operator!=(QType::typeenum comp) const {
154 return(comp!=code);
155 }
156
157 inline bool operator==(uint16_t comp) const {
158 return(comp==code);
159 }
160
161 inline bool operator!=(uint16_t comp) const {
162 return(comp!=code);
163 }
164
165 private:
166 static class init {
167 public:
168 void qtype_insert(const char* a, uint16_t num)
169 {
170 names.push_back(make_pair(string(a), num));
171 }
172
173 init()
174 {
175 qtype_insert("A", 1);
176 qtype_insert("NS", 2);
177 qtype_insert("CNAME", 5);
178 qtype_insert("SOA", 6);
179 qtype_insert("MB", 7);
180 qtype_insert("MG", 8);
181 qtype_insert("MR", 9);
182 qtype_insert("WKS", 11);
183 qtype_insert("PTR", 12);
184 qtype_insert("HINFO", 13);
185 qtype_insert("MINFO", 14);
186 qtype_insert("MX", 15);
187 qtype_insert("TXT", 16);
188 qtype_insert("RP", 17);
189 qtype_insert("AFSDB", 18);
190 qtype_insert("SIG", 24);
191 qtype_insert("KEY", 25);
192 qtype_insert("AAAA", 28);
193 qtype_insert("LOC", 29);
194 qtype_insert("SRV", 33);
195 qtype_insert("NAPTR", 35);
196 qtype_insert("KX", 36);
197 qtype_insert("CERT", 37);
198 qtype_insert("A6", 38);
199 qtype_insert("DNAME", 39);
200 qtype_insert("OPT", 41);
201 qtype_insert("DS", 43);
202 qtype_insert("SSHFP", 44);
203 qtype_insert("IPSECKEY", 45);
204 qtype_insert("RRSIG", 46);
205 qtype_insert("NSEC", 47);
206 qtype_insert("DNSKEY", 48);
207 qtype_insert("DHCID", 49);
208 qtype_insert("NSEC3", 50);
209 qtype_insert("NSEC3PARAM", 51);
210 qtype_insert("TLSA", 52);
211 qtype_insert("SMIMEA", 53);
212 qtype_insert("RKEY", 57);
213 qtype_insert("CDS", 59);
214 qtype_insert("CDNSKEY", 60);
215 qtype_insert("OPENPGPKEY", 61);
216 qtype_insert("SPF", 99);
217 qtype_insert("EUI48", 108);
218 qtype_insert("EUI64", 109);
219 qtype_insert("TKEY", 249);
220 // qtype_insert("TSIG", 250);
221 qtype_insert("IXFR", 251);
222 qtype_insert("AXFR", 252);
223 qtype_insert("MAILB", 253);
224 qtype_insert("MAILA", 254);
225 qtype_insert("ANY", 255);
226 qtype_insert("URI", 256);
227 qtype_insert("CAA", 257);
228 qtype_insert("DLV", 32769);
229 qtype_insert("ADDR", 65400);
230 qtype_insert("ALIAS", 65401);
231 qtype_insert("LUA", 65402);
232 }
233 } initializer;
234
235 uint16_t code;
236 };
237
238 struct QClass
239 {
240 enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255};
241 };
242 #endif