File: qtype.hh

package info (click to toggle)
pdns-recursor 4.0.4-1+deb9u3~bpo8+1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 5,484 kB
  • sloc: cpp: 36,380; sh: 11,771; makefile: 305; xml: 37
file content (234 lines) | stat: -rw-r--r-- 5,678 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 * This file is part of PowerDNS or dnsdist.
 * Copyright -- PowerDNS.COM B.V. and its contributors
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * In addition, for the avoidance of any doubt, permission is granted to
 * link this program with OpenSSL and to (re)distribute the binaries
 * produced as the result of such linking.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
#ifndef QTYPE_HH
#define QTYPE_HH
// $Id$
#include <string>
#include <vector>
#include "namespaces.hh"

/** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS',
 *  'CNAME' etcetera. These types have both a name and a number. This class can seamlessly move between
 *   them. Use it like this:

\code
   QType t;
   t="CNAME";
   cout<<t.getCode()<<endl; // prints '5'
   t=6;
   cout<<t.getName()<<endl; // prints 'SOA'
\endcode

*/



class QType
{
public:
  QType(); //!< Naked constructor
  explicit QType(uint16_t); //!< convert from an integer to a QType
  QType(const QType& orig) : code(orig.code)
  {
  }
  QType &operator=(uint16_t);  //!< Assigns integers to us
  QType &operator=(const char *); //!< Assings strings to us
  QType &operator=(const string &); //!< Assings strings to us
  QType &operator=(const QType&rhs)  //!< Assings strings to us
  {
    code=rhs.code;
    return *this;
  }

  bool operator<(const QType& rhs) const 
  {
    return code < rhs.code;
  }

  template<class Archive>
  void serialize(Archive &ar, const unsigned int version)
  {
    ar & code;
  }

  const string getName() const; //!< Get a string representation of this type
  uint16_t getCode() const; //!< Get the integer representation of this type
  bool isSupportedType();
  bool isMetadataType();

  static int chartocode(const char *p); //!< convert a character string to a code
  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,
    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,
    TLSA=52,
    RKEY=57,
    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,
    URI=256,
    CAA=257,
    DLV=32769,
    ADDR=65400,
    ALIAS=65401
  };

  typedef pair<string,uint16_t> namenum;
  static vector<namenum> names;

  inline bool operator==(const QType &comp) const {
    return(comp.code==code);
  }

  inline bool operator!=(const QType &comp) const {
    return(comp.code!=code);
  }

  inline bool operator==(QType::typeenum comp) const {
    return(comp==code);
  }

  inline bool operator!=(QType::typeenum comp) const {
    return(comp!=code);
  }

  inline bool operator==(uint16_t comp) const {
    return(comp==code);
  }

  inline bool operator!=(uint16_t comp) const {
    return(comp!=code);
  }

private:
  static class init {
    public:
    void qtype_insert(const char* a, uint16_t num) 
    {
      names.push_back(make_pair(string(a), num));
    }

    init()
    {
      qtype_insert("A", 1);
      qtype_insert("NS", 2);
      qtype_insert("CNAME", 5);
      qtype_insert("SOA", 6);
      qtype_insert("MR", 9);
      qtype_insert("PTR", 12);
      qtype_insert("HINFO", 13);
      qtype_insert("MINFO", 14);
      qtype_insert("MX", 15);
      qtype_insert("TXT", 16);
      qtype_insert("RP", 17);
      qtype_insert("AFSDB", 18);
      qtype_insert("SIG", 24);
      qtype_insert("KEY", 25);
      qtype_insert("AAAA", 28);
      qtype_insert("LOC", 29);
      qtype_insert("SRV", 33);
      qtype_insert("NAPTR", 35);
      qtype_insert("KX", 36);
      qtype_insert("CERT", 37);
      qtype_insert("A6", 38);
      qtype_insert("DNAME", 39);
      qtype_insert("OPT", 41);
      qtype_insert("DS", 43);
      qtype_insert("SSHFP", 44);
      qtype_insert("IPSECKEY", 45);
      qtype_insert("RRSIG", 46);
      qtype_insert("NSEC", 47);
      qtype_insert("DNSKEY", 48);
      qtype_insert("DHCID", 49);
      qtype_insert("NSEC3", 50);
      qtype_insert("NSEC3PARAM", 51);
      qtype_insert("TLSA", 52);
      qtype_insert("RKEY", 57);
      qtype_insert("CDS", 59);
      qtype_insert("CDNSKEY", 60);
      qtype_insert("OPENPGPKEY", 61);
      qtype_insert("SPF", 99);
      qtype_insert("EUI48", 108);
      qtype_insert("EUI64", 109);
      qtype_insert("TKEY", 249);
//      qtype_insert("TSIG", 250);
      qtype_insert("IXFR", 251);
      qtype_insert("AXFR", 252);
      qtype_insert("MAILB", 253);
      qtype_insert("MAILA", 254);
      qtype_insert("ANY", 255);
      qtype_insert("URI", 256);
      qtype_insert("CAA", 257);
      qtype_insert("DLV", 32769);
      qtype_insert("ADDR", 65400);
      qtype_insert("ALIAS", 65401);
    }
  } initializer;

  uint16_t code;
};

struct QClass
{
  enum QClassEnum {IN=1, CHAOS=3, NONE=254, ANY=255};
};
#endif