]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/qtype.cc
rec: ensure correct service user on debian
[thirdparty/pdns.git] / pdns / qtype.cc
1 /*
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 */
22 #include "dns.hh"
23 #include <iostream>
24 #include <string>
25 #include <vector>
26 #include <utility>
27 #include <sstream>
28 #include "qtype.hh"
29 #include "misc.hh"
30
31 static_assert(sizeof(QType) == 2, "QType is not 2 bytes in size, something is wrong!");
32
33 vector<QType::namenum> QType::names;
34 // XXX FIXME we need to do something with initializer order here!
35 QType::init QType::initializer;
36
37 QType::QType()
38 {
39 code = 0;
40 }
41
42 bool QType::isSupportedType() {
43 for(vector<namenum>::iterator pos=names.begin();pos<names.end();++pos)
44 if(pos->second==code)
45 return true;
46 return false;
47 }
48
49 bool QType::isMetadataType() {
50 if (code == QType::AXFR ||
51 code == QType::MAILA ||
52 code == QType::MAILB ||
53 code == QType::TSIG ||
54 code == QType::IXFR)
55 return true;
56
57 return false;
58 }
59
60 uint16_t QType::getCode() const
61 {
62 return code;
63 }
64
65 const string QType::getName() const
66 {
67 vector<namenum>::iterator pos;
68 for(pos=names.begin();pos<names.end();++pos)
69 if(pos->second==code)
70 return pos->first;
71
72 return "TYPE"+itoa(code);
73 }
74
75 QType &QType::operator=(uint16_t n)
76 {
77 code=n;
78 return *this;
79 }
80
81 int QType::chartocode(const char *p)
82 {
83 string P = toUpper(p);
84 vector<namenum>::iterator pos;
85
86 for(pos=names.begin(); pos < names.end(); ++pos)
87 if(pos->first == P)
88 return pos->second;
89
90 if(*p=='#') {
91 return atoi(p+1);
92 }
93
94 if(boost::starts_with(P, "TYPE"))
95 return atoi(p+4);
96
97 return 0;
98 }
99
100 QType &QType::operator=(const char *p)
101 {
102 code=chartocode(p);
103 return *this;
104 }
105
106 QType &QType::operator=(const string &s)
107 {
108 code=chartocode(s.c_str());
109 return *this;
110 }
111
112
113 QType::QType(uint16_t n): QType()
114 {
115 code=n;
116 }