]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/qtype.hh
Merge branch 'master' of github.com:PowerDNS/pdns
[thirdparty/pdns.git] / pdns / qtype.hh
CommitLineData
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>
10f4eea8 28#include "namespaces.hh"
12c86877
BH
29
30/** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS',
abc1d928 31 * 'CNAME' etcetera. These types have both a name and a number. This class can seamlessly move between
12c86877
BH
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
46class QType
47{
48public:
49 QType(); //!< Naked constructor
0b55f2f5 50 explicit QType(uint16_t); //!< convert from an integer to a QType
d3a8e1df
BH
51 QType(const QType& orig) : code(orig.code)
52 {
53 }
0b55f2f5 54 QType &operator=(uint16_t); //!< Assigns integers to us
12c86877
BH
55 QType &operator=(const char *); //!< Assings strings to us
56 QType &operator=(const string &); //!< Assings strings to us
d3a8e1df
BH
57 QType &operator=(const QType&rhs) //!< Assings strings to us
58 {
59 code=rhs.code;
60 return *this;
61 }
1ac4e536
BH
62
63 bool operator<(const QType& rhs) const
64 {
65 return code < rhs.code;
66 }
67
cb433f9c
BH
68 template<class Archive>
69 void serialize(Archive &ar, const unsigned int version)
70 {
71 ar & code;
72 }
73
d6ed1eef 74 const string getName() const; //!< Get a string representation of this type
0b55f2f5 75 uint16_t getCode() const; //!< Get the integer representation of this type
e2b22865
RA
76 bool isSupportedType();
77 bool isMetadataType();
12c86877
BH
78
79 static int chartocode(const char *p); //!< convert a character string to a code
4bb0bca8 80// more solaris fun
914353ca 81#undef DS
792402a9 82 enum typeenum : uint16_t {A=1, NS=2, CNAME=5, SOA=6, MR=9, WKS=11, PTR=12, HINFO=13, MINFO=14, MX=15, TXT=16, RP=17, AFSDB=18, SIG=24, KEY=25, AAAA=28, LOC=29, SRV=33, NAPTR=35, KX=36,
8dee0750 83 CERT=37, A6=38, DNAME=39, OPT=41, DS=43, SSHFP=44, IPSECKEY=45, RRSIG=46, NSEC=47, DNSKEY=48, DHCID=49, NSEC3=50, NSEC3PARAM=51,
85b85b50 84 TLSA=52, CDS=59, CDNSKEY=60, OPENPGPKEY=61, SPF=99, EUI48=108, EUI64=109, TKEY=249, TSIG=250, IXFR=251, AXFR=252, MAILB=253, MAILA=254, ANY=255, ADDR=259,
882de365 85 ALIAS=260, DLV=32769};
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 113private:
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 143 qtype_insert("A6", 38);
8dee0750 144 qtype_insert("DNAME", 39);
9f44333a 145 qtype_insert("OPT", 41);
839973ac
BH
146 qtype_insert("DS", 43);
147 qtype_insert("SSHFP", 44);
622e2276 148 qtype_insert("IPSECKEY", 45);
839973ac
BH
149 qtype_insert("RRSIG", 46);
150 qtype_insert("NSEC", 47);
151 qtype_insert("DNSKEY", 48);
622e2276 152 qtype_insert("DHCID", 49);
839973ac
BH
153 qtype_insert("NSEC3", 50);
154 qtype_insert("NSEC3PARAM", 51);
9f44333a 155 qtype_insert("TLSA", 52);
882de365
PL
156 qtype_insert("CDS", 59);
157 qtype_insert("CDNSKEY", 60);
68066337 158 qtype_insert("OPENPGPKEY", 61);
9f44333a
RA
159 qtype_insert("SPF", 99);
160 qtype_insert("EUI48", 108);
161 qtype_insert("EUI64", 109);
b3ac6324 162 qtype_insert("TKEY", 249);
914353ca 163// qtype_insert("TSIG", 250);
9f44333a
RA
164 qtype_insert("IXFR", 251);
165 qtype_insert("AXFR", 252);
166 qtype_insert("MAILB", 253);
167 qtype_insert("MAILA", 254);
168 qtype_insert("ANY", 255);
9f44333a 169 qtype_insert("ADDR", 259);
d59b894d 170 qtype_insert("ALIAS", 260);
9f44333a 171 qtype_insert("DLV", 32769);
839973ac
BH
172 }
173 } initializer;
12c86877 174
839973ac 175 uint16_t code;
12c86877
BH
176};
177
adf13442
BH
178struct QClass
179{
9f44333a 180 enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255};
adf13442 181};
12c86877 182#endif