]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/qtype.hh
Merge pull request #5413 from Habbie/rpm-missing-schema
[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 MR=9,
80 WKS=11,
81 PTR=12,
82 HINFO=13,
83 MINFO=14,
84 MX=15,
85 TXT=16,
86 RP=17,
87 AFSDB=18,
88 SIG=24,
89 KEY=25,
90 AAAA=28,
91 LOC=29,
92 SRV=33,
93 NAPTR=35,
94 KX=36,
95 CERT=37,
96 A6=38,
97 DNAME=39,
98 OPT=41,
99 DS=43,
100 SSHFP=44,
101 IPSECKEY=45,
102 RRSIG=46,
103 NSEC=47,
104 DNSKEY=48,
105 DHCID=49,
106 NSEC3=50,
107 NSEC3PARAM=51,
108 TLSA=52,
109 SMIMEA=53,
110 RKEY=57,
111 CDS=59,
112 CDNSKEY=60,
113 OPENPGPKEY=61,
114 SPF=99,
115 EUI48=108,
116 EUI64=109,
117 TKEY=249,
118 TSIG=250,
119 IXFR=251,
120 AXFR=252,
121 MAILB=253,
122 MAILA=254,
123 ANY=255,
124 URI=256,
125 CAA=257,
126 DLV=32769,
127 ADDR=65400,
128 ALIAS=65401
129 };
130
131 typedef pair<string,uint16_t> namenum;
132 static vector<namenum> names;
133
134 inline bool operator==(const QType &comp) const {
135 return(comp.code==code);
136 }
137
138 inline bool operator!=(const QType &comp) const {
139 return(comp.code!=code);
140 }
141
142 inline bool operator==(QType::typeenum comp) const {
143 return(comp==code);
144 }
145
146 inline bool operator!=(QType::typeenum comp) const {
147 return(comp!=code);
148 }
149
150 inline bool operator==(uint16_t comp) const {
151 return(comp==code);
152 }
153
154 inline bool operator!=(uint16_t comp) const {
155 return(comp!=code);
156 }
157
158 private:
159 static class init {
160 public:
161 void qtype_insert(const char* a, uint16_t num)
162 {
163 names.push_back(make_pair(string(a), num));
164 }
165
166 init()
167 {
168 qtype_insert("A", 1);
169 qtype_insert("NS", 2);
170 qtype_insert("CNAME", 5);
171 qtype_insert("SOA", 6);
172 qtype_insert("MR", 9);
173 qtype_insert("PTR", 12);
174 qtype_insert("HINFO", 13);
175 qtype_insert("MINFO", 14);
176 qtype_insert("MX", 15);
177 qtype_insert("TXT", 16);
178 qtype_insert("RP", 17);
179 qtype_insert("AFSDB", 18);
180 qtype_insert("SIG", 24);
181 qtype_insert("KEY", 25);
182 qtype_insert("AAAA", 28);
183 qtype_insert("LOC", 29);
184 qtype_insert("SRV", 33);
185 qtype_insert("NAPTR", 35);
186 qtype_insert("KX", 36);
187 qtype_insert("CERT", 37);
188 qtype_insert("A6", 38);
189 qtype_insert("DNAME", 39);
190 qtype_insert("OPT", 41);
191 qtype_insert("DS", 43);
192 qtype_insert("SSHFP", 44);
193 qtype_insert("IPSECKEY", 45);
194 qtype_insert("RRSIG", 46);
195 qtype_insert("NSEC", 47);
196 qtype_insert("DNSKEY", 48);
197 qtype_insert("DHCID", 49);
198 qtype_insert("NSEC3", 50);
199 qtype_insert("NSEC3PARAM", 51);
200 qtype_insert("TLSA", 52);
201 qtype_insert("RKEY", 57);
202 qtype_insert("CDS", 59);
203 qtype_insert("CDNSKEY", 60);
204 qtype_insert("OPENPGPKEY", 61);
205 qtype_insert("SPF", 99);
206 qtype_insert("EUI48", 108);
207 qtype_insert("EUI64", 109);
208 qtype_insert("TKEY", 249);
209 // qtype_insert("TSIG", 250);
210 qtype_insert("IXFR", 251);
211 qtype_insert("AXFR", 252);
212 qtype_insert("MAILB", 253);
213 qtype_insert("MAILA", 254);
214 qtype_insert("ANY", 255);
215 qtype_insert("URI", 256);
216 qtype_insert("CAA", 257);
217 qtype_insert("DLV", 32769);
218 qtype_insert("ADDR", 65400);
219 qtype_insert("ALIAS", 65401);
220 }
221 } initializer;
222
223 uint16_t code;
224 };
225
226 struct QClass
227 {
228 enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255};
229 };
230 #endif