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