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