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