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