2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 PowerDNS.COM BV
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
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.
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.
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
24 /* (C) 2002 POWERDNS.COM BV */
28 #include "namespaces.hh"
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:
37 cout<<t.getCode()<<endl; // prints '5'
39 cout<<t.getName()<<endl; // prints 'SOA'
49 QType(); //!< Naked constructor
50 explicit QType(uint16_t); //!< convert from an integer to a QType
51 QType(const QType& orig) : code(orig.code)
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
63 bool operator<(const QType& rhs) const
65 return code < rhs.code;
68 template<class Archive>
69 void serialize(Archive &ar, const unsigned int version)
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();
79 static int chartocode(const char *p); //!< convert a character string to a code
80 enum typeenum : uint16_t {
136 typedef pair<string,uint16_t> namenum;
137 static vector<namenum> names;
139 inline bool operator==(const QType &comp) const {
140 return(comp.code==code);
143 inline bool operator!=(const QType &comp) const {
144 return(comp.code!=code);
147 inline bool operator==(QType::typeenum comp) const {
151 inline bool operator!=(QType::typeenum comp) const {
155 inline bool operator==(uint16_t comp) const {
159 inline bool operator!=(uint16_t comp) const {
166 void qtype_insert(const char* a, uint16_t num)
168 names.push_back(make_pair(string(a), num));
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);
233 enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255};