]>
Commit | Line | Data |
---|---|---|
12c86877 BH |
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 | |
22dc646a BH |
6 | it under the terms of the GNU General Public License version 2 |
7 | as published by the Free Software Foundation | |
f782fe38 MH |
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. | |
12c86877 BH |
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 | |
06bd9ccf | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
12c86877 BH |
21 | */ |
22 | #ifndef QTYPE_HH | |
23 | #define QTYPE_HH | |
24 | /* (C) 2002 POWERDNS.COM BV */ | |
d6ed1eef | 25 | // $Id$ |
12c86877 BH |
26 | #include <string> |
27 | #include <vector> | |
28 | #include <utility> | |
10f4eea8 | 29 | #include "namespaces.hh" |
12c86877 BH |
30 | |
31 | /** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS', | |
abc1d928 | 32 | * 'CNAME' etcetera. These types have both a name and a number. This class can seamlessly move between |
12c86877 BH |
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 | |
0b55f2f5 | 51 | explicit QType(uint16_t); //!< convert from an integer to a QType |
d3a8e1df BH |
52 | QType(const QType& orig) : code(orig.code) |
53 | { | |
54 | } | |
0b55f2f5 | 55 | QType &operator=(uint16_t); //!< Assigns integers to us |
12c86877 BH |
56 | QType &operator=(const char *); //!< Assings strings to us |
57 | QType &operator=(const string &); //!< Assings strings to us | |
d3a8e1df BH |
58 | QType &operator=(const QType&rhs) //!< Assings strings to us |
59 | { | |
60 | code=rhs.code; | |
61 | return *this; | |
62 | } | |
1ac4e536 BH |
63 | |
64 | bool operator<(const QType& rhs) const | |
65 | { | |
66 | return code < rhs.code; | |
67 | } | |
68 | ||
cb433f9c BH |
69 | template<class Archive> |
70 | void serialize(Archive &ar, const unsigned int version) | |
71 | { | |
72 | ar & code; | |
73 | } | |
74 | ||
d6ed1eef | 75 | const string getName() const; //!< Get a string representation of this type |
0b55f2f5 | 76 | uint16_t getCode() const; //!< Get the integer representation of this type |
e2b22865 RA |
77 | bool isSupportedType(); |
78 | bool isMetadataType(); | |
12c86877 BH |
79 | |
80 | static int chartocode(const char *p); //!< convert a character string to a code | |
4bb0bca8 | 81 | // more solaris fun |
914353ca KM |
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, | |
9f44333a RA |
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; | |
914353ca | 86 | typedef pair<string,uint16_t> namenum; |
e40635fe | 87 | static vector<namenum> names; |
839973ac | 88 | |
df9b53db | 89 | inline bool operator==(const QType &comp) const { |
9f44333a | 90 | return(comp.code==code); |
df9b53db PD |
91 | } |
92 | ||
93 | inline bool operator!=(const QType &comp) const { | |
9f44333a | 94 | return(comp.code!=code); |
df9b53db PD |
95 | } |
96 | ||
97 | inline bool operator==(QType::typeenum comp) const { | |
9f44333a | 98 | return(comp==code); |
df9b53db PD |
99 | } |
100 | ||
101 | inline bool operator!=(QType::typeenum comp) const { | |
9f44333a RA |
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); | |
df9b53db PD |
111 | } |
112 | ||
12c86877 | 113 | private: |
839973ac BH |
114 | static class init { |
115 | public: | |
116 | void qtype_insert(const char* a, uint16_t num) | |
117 | { | |
9f44333a | 118 | names.push_back(make_pair(string(a), num)); |
839973ac BH |
119 | } |
120 | ||
121 | init() | |
122 | { | |
914353ca KM |
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); | |
839973ac | 134 | qtype_insert("AFSDB", 18); |
9f44333a RA |
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); | |
839973ac | 142 | qtype_insert("CERT", 37); |
9f44333a RA |
143 | qtype_insert("A6", 38); |
144 | qtype_insert("OPT", 41); | |
839973ac BH |
145 | qtype_insert("DS", 43); |
146 | qtype_insert("SSHFP", 44); | |
622e2276 | 147 | qtype_insert("IPSECKEY", 45); |
839973ac BH |
148 | qtype_insert("RRSIG", 46); |
149 | qtype_insert("NSEC", 47); | |
150 | qtype_insert("DNSKEY", 48); | |
622e2276 | 151 | qtype_insert("DHCID", 49); |
839973ac BH |
152 | qtype_insert("NSEC3", 50); |
153 | qtype_insert("NSEC3PARAM", 51); | |
9f44333a RA |
154 | qtype_insert("TLSA", 52); |
155 | qtype_insert("SPF", 99); | |
156 | qtype_insert("EUI48", 108); | |
157 | qtype_insert("EUI64", 109); | |
914353ca | 158 | // qtype_insert("TSIG", 250); |
9f44333a RA |
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); | |
839973ac BH |
169 | } |
170 | } initializer; | |
12c86877 | 171 | |
839973ac | 172 | uint16_t code; |
12c86877 BH |
173 | }; |
174 | ||
adf13442 BH |
175 | struct QClass |
176 | { | |
9f44333a | 177 | enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255}; |
adf13442 | 178 | }; |
12c86877 | 179 | #endif |