]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/qtype.hh
Merge pull request #6688 from rgacogne/dnsdist-const-ds-remote
[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 typedef pair<string,uint16_t> namenum;
135 static vector<namenum> names;
136
137 inline bool operator==(const QType &comp) const {
138 return(comp.code==code);
139 }
140
141 inline bool operator!=(const QType &comp) const {
142 return(comp.code!=code);
143 }
144
145 inline bool operator==(QType::typeenum comp) const {
146 return(comp==code);
147 }
148
149 inline bool operator!=(QType::typeenum comp) const {
150 return(comp!=code);
151 }
152
153 inline bool operator==(uint16_t comp) const {
154 return(comp==code);
155 }
156
157 inline bool operator!=(uint16_t comp) const {
158 return(comp!=code);
159 }
160
161 private:
162 static class init {
163 public:
164 void qtype_insert(const char* a, uint16_t num)
165 {
166 names.push_back(make_pair(string(a), num));
167 }
168
169 init()
170 {
171 qtype_insert("A", 1);
172 qtype_insert("NS", 2);
173 qtype_insert("CNAME", 5);
174 qtype_insert("SOA", 6);
175 qtype_insert("MB", 7);
176 qtype_insert("MG", 8);
177 qtype_insert("MR", 9);
178 qtype_insert("WKS", 11);
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);
185 qtype_insert("AFSDB", 18);
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);
193 qtype_insert("CERT", 37);
194 qtype_insert("A6", 38);
195 qtype_insert("DNAME", 39);
196 qtype_insert("OPT", 41);
197 qtype_insert("DS", 43);
198 qtype_insert("SSHFP", 44);
199 qtype_insert("IPSECKEY", 45);
200 qtype_insert("RRSIG", 46);
201 qtype_insert("NSEC", 47);
202 qtype_insert("DNSKEY", 48);
203 qtype_insert("DHCID", 49);
204 qtype_insert("NSEC3", 50);
205 qtype_insert("NSEC3PARAM", 51);
206 qtype_insert("TLSA", 52);
207 qtype_insert("SMIMEA", 53);
208 qtype_insert("RKEY", 57);
209 qtype_insert("CDS", 59);
210 qtype_insert("CDNSKEY", 60);
211 qtype_insert("OPENPGPKEY", 61);
212 qtype_insert("SPF", 99);
213 qtype_insert("EUI48", 108);
214 qtype_insert("EUI64", 109);
215 qtype_insert("TKEY", 249);
216 // qtype_insert("TSIG", 250);
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);
222 qtype_insert("URI", 256);
223 qtype_insert("CAA", 257);
224 qtype_insert("DLV", 32769);
225 qtype_insert("ADDR", 65400);
226 qtype_insert("ALIAS", 65401);
227 qtype_insert("LUA", 65402);
228 }
229 } initializer;
230
231 uint16_t code;
232 };
233
234 struct QClass
235 {
236 enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255};
237 };
238 #endif