]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/qtype.hh
add OpenSSL exception to PowerDNS, Netherlabs, van Dijk and Hubert copyrights
[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 <utility>
29 #include "namespaces.hh"
30
31 /** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS',
32 * 'CNAME' etcetera. These types have both a name and a number. This class can seamlessly move between
33 * them. Use it like this:
34
35 \code
36 QType t;
37 t="CNAME";
38 cout<<t.getCode()<<endl; // prints '5'
39 t=6;
40 cout<<t.getName()<<endl; // prints 'SOA'
41 \endcode
42
43 */
44
45
46
47 class QType
48 {
49 public:
50 QType(); //!< Naked constructor
51 explicit QType(uint16_t); //!< convert from an integer to a QType
52 QType(const QType& orig) : code(orig.code)
53 {
54 }
55 QType &operator=(uint16_t); //!< Assigns integers to us
56 QType &operator=(const char *); //!< Assings strings to us
57 QType &operator=(const string &); //!< Assings strings to us
58 QType &operator=(const QType&rhs) //!< Assings strings to us
59 {
60 code=rhs.code;
61 return *this;
62 }
63
64 bool operator<(const QType& rhs) const
65 {
66 return code < rhs.code;
67 }
68
69 template<class Archive>
70 void serialize(Archive &ar, const unsigned int version)
71 {
72 ar & code;
73 }
74
75 const string getName() const; //!< Get a string representation of this type
76 uint16_t getCode() const; //!< Get the integer representation of this type
77 bool isSupportedType();
78 bool isMetadataType();
79
80 static int chartocode(const char *p); //!< convert a character string to a code
81 // more solaris fun
82 #undef DS
83 enum typeenum {A=1, NS=2, CNAME=5, SOA=6, MR=9, PTR=12, HINFO=13, MX=15, TXT=16, RP=17, AFSDB=18, SIG=24, KEY=25, AAAA=28, LOC=29, SRV=33, NAPTR=35, KX=36,
84 CERT=37, A6=38, OPT=41, DS=43, SSHFP=44, IPSECKEY=45, RRSIG=46, NSEC=47, DNSKEY=48, DHCID=49, NSEC3=50, NSEC3PARAM=51,
85 TLSA=52, SPF=99, EUI48=108, EUI64=109, TSIG=250, IXFR=251, AXFR=252, MAILB=253, MAILA=254, ANY=255, URL=256, MBOXFW=257, CURL=258, ADDR=259, DLV=32769} types;
86 typedef pair<string,uint16_t> namenum;
87 static vector<namenum> names;
88
89 inline bool operator==(const QType &comp) const {
90 return(comp.code==code);
91 }
92
93 inline bool operator!=(const QType &comp) const {
94 return(comp.code!=code);
95 }
96
97 inline bool operator==(QType::typeenum comp) const {
98 return(comp==code);
99 }
100
101 inline bool operator!=(QType::typeenum comp) const {
102 return(comp!=code);
103 }
104
105 inline bool operator==(uint16_t comp) const {
106 return(comp==code);
107 }
108
109 inline bool operator!=(uint16_t comp) const {
110 return(comp!=code);
111 }
112
113 private:
114 static class init {
115 public:
116 void qtype_insert(const char* a, uint16_t num)
117 {
118 names.push_back(make_pair(string(a), num));
119 }
120
121 init()
122 {
123 qtype_insert("A", 1);
124 qtype_insert("NS", 2);
125 qtype_insert("CNAME", 5);
126 qtype_insert("SOA", 6);
127 qtype_insert("MR", 9);
128 qtype_insert("PTR", 12);
129 qtype_insert("HINFO", 13);
130 qtype_insert("MINFO", 14);
131 qtype_insert("MX", 15);
132 qtype_insert("TXT", 16);
133 qtype_insert("RP", 17);
134 qtype_insert("AFSDB", 18);
135 qtype_insert("SIG", 24);
136 qtype_insert("KEY", 25);
137 qtype_insert("AAAA", 28);
138 qtype_insert("LOC", 29);
139 qtype_insert("SRV", 33);
140 qtype_insert("NAPTR", 35);
141 qtype_insert("KX", 36);
142 qtype_insert("CERT", 37);
143 qtype_insert("A6", 38);
144 qtype_insert("OPT", 41);
145 qtype_insert("DS", 43);
146 qtype_insert("SSHFP", 44);
147 qtype_insert("IPSECKEY", 45);
148 qtype_insert("RRSIG", 46);
149 qtype_insert("NSEC", 47);
150 qtype_insert("DNSKEY", 48);
151 qtype_insert("DHCID", 49);
152 qtype_insert("NSEC3", 50);
153 qtype_insert("NSEC3PARAM", 51);
154 qtype_insert("TLSA", 52);
155 qtype_insert("SPF", 99);
156 qtype_insert("EUI48", 108);
157 qtype_insert("EUI64", 109);
158 // qtype_insert("TSIG", 250);
159 qtype_insert("IXFR", 251);
160 qtype_insert("AXFR", 252);
161 qtype_insert("MAILB", 253);
162 qtype_insert("MAILA", 254);
163 qtype_insert("ANY", 255);
164 qtype_insert("URL", 256);
165 qtype_insert("MBOXFW", 257);
166 qtype_insert("CURL", 258);
167 qtype_insert("ADDR", 259);
168 qtype_insert("DLV", 32769);
169 }
170 } initializer;
171
172 uint16_t code;
173 };
174
175 struct QClass
176 {
177 enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255};
178 };
179 #endif