]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/qtype.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
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.
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.
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.
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.
31 static_assert(sizeof(QType
) == 2, "QType is not 2 bytes in size, something is wrong!");
33 const map
<const string
, uint16_t> QType::names
= {
97 #if !defined(RECURSOR)
103 static map
<uint16_t, const string
> swapElements(const map
<const string
, uint16_t>& names
) {
104 map
<uint16_t, const string
> ret
;
106 for (const auto& n
: names
) {
107 ret
.emplace(n
.second
, n
.first
);
112 const map
<uint16_t, const string
> QType::numbers
= swapElements(names
);
115 bool QType::isSupportedType() const
117 return numbers
.count(code
) == 1;
120 bool QType::isMetadataType() const
122 // rfc6895 section 3.1, note ANY is 255 and falls outside the range
123 if (code
== QType::OPT
|| (code
>= rfc6895MetaLowerBound
&& code
<= rfc6895MetaUpperBound
)) {
129 const string
QType::toString() const
131 const auto& name
= numbers
.find(code
);
132 if (name
!= numbers
.cend()) {
135 return "TYPE" + std::to_string(code
);
138 uint16_t QType::chartocode(const char *p
)
140 string P
= toUpper(p
);
142 const auto& num
= names
.find(P
);
143 if (num
!= names
.cend()) {
147 return static_cast<uint16_t>(atoi(p
+ 1));
150 if (boost::starts_with(P
, "TYPE")) {
151 return static_cast<uint16_t>(atoi(p
+ 4));
157 QType
&QType::operator=(const char *p
)
159 code
= chartocode(p
);
163 QType
&QType::operator=(const string
&s
)
165 code
= chartocode(s
.c_str());
169 const std::string
QClass::toString() const
181 return "CLASS" + std::to_string(qclass
);