]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/qtype.cc
dnsdist: Refactoring to merge the UDP and TCP paths
[thirdparty/pdns.git] / pdns / qtype.cc
CommitLineData
12c86877 1/*
6edbf68a
PL
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
288f4aa9 22#include "dns.hh"
12c86877
BH
23#include <iostream>
24#include <string>
25#include <vector>
26#include <utility>
27#include <sstream>
28#include "qtype.hh"
29#include "misc.hh"
30
792402a9
PL
31static_assert(sizeof(QType) == 2, "QType is not 2 bytes in size, something is wrong!");
32
12c86877 33vector<QType::namenum> QType::names;
839973ac
BH
34// XXX FIXME we need to do something with initializer order here!
35QType::init QType::initializer;
12c86877
BH
36
37QType::QType()
38{
bf4da976 39 code = 0;
12c86877
BH
40}
41
e2b22865
RA
42bool QType::isSupportedType() {
43 for(vector<namenum>::iterator pos=names.begin();pos<names.end();++pos)
914353ca 44 if(pos->second==code)
e2b22865
RA
45 return true;
46 return false;
47}
48
49bool QType::isMetadataType() {
50 if (code == QType::AXFR ||
51 code == QType::MAILA ||
52 code == QType::MAILB ||
53 code == QType::TSIG ||
914353ca 54 code == QType::IXFR)
e2b22865
RA
55 return true;
56
57 return false;
58}
59
0b55f2f5 60uint16_t QType::getCode() const
12c86877
BH
61{
62 return code;
63}
64
d6ed1eef 65const string QType::getName() const
a9e2e5ef 66{
12c86877
BH
67 vector<namenum>::iterator pos;
68 for(pos=names.begin();pos<names.end();++pos)
69 if(pos->second==code)
70 return pos->first;
71
815caf66 72 return "TYPE"+itoa(code);
12c86877
BH
73}
74
0b55f2f5 75QType &QType::operator=(uint16_t n)
12c86877
BH
76{
77 code=n;
78 return *this;
79}
80
81int QType::chartocode(const char *p)
82{
8ce0dc75 83 string P = toUpper(p);
12c86877 84 vector<namenum>::iterator pos;
8ce0dc75 85
90e631d9 86 for(pos=names.begin(); pos < names.end(); ++pos)
8ce0dc75 87 if(pos->first == P)
12c86877 88 return pos->second;
8ce0dc75 89
e1de312a
BH
90 if(*p=='#') {
91 return atoi(p+1);
92 }
12c86877 93
8ce0dc75 94 if(boost::starts_with(P, "TYPE"))
e1de312a 95 return atoi(p+4);
8ce0dc75 96
12c86877
BH
97 return 0;
98}
99
100QType &QType::operator=(const char *p)
101{
102 code=chartocode(p);
103 return *this;
104}
105
12c86877
BH
106QType &QType::operator=(const string &s)
107{
108 code=chartocode(s.c_str());
109 return *this;
110}
111
112
d7c676a5 113QType::QType(uint16_t n): QType()
12c86877 114{
12c86877
BH
115 code=n;
116}