• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 19741624072

27 Nov 2025 03:45PM UTC coverage: 73.086% (+0.02%) from 73.065%
19741624072

Pull #16570

github

web-flow
Merge 08a2cdb1d into f94a3f63f
Pull Request #16570: rec: rewrite all unwrap calls in web.rs

38523 of 63408 branches covered (60.75%)

Branch coverage included in aggregate %.

128044 of 164496 relevant lines covered (77.84%)

6531485.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.72
/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
const map<const string, uint16_t> QType::names = {
34
  {"A", 1},
35
  {"NS", 2},
36
  {"CNAME", 5},
37
  {"SOA", 6},
38
  {"MB", 7},
39
  {"MG", 8},
40
  {"MR", 9},
41
  {"PTR", 12},
42
  {"HINFO", 13},
43
  {"MINFO", 14},
44
  {"MX", 15},
45
  {"TXT", 16},
46
  {"RP", 17},
47
  {"AFSDB", 18},
48
  {"SIG", 24},
49
  {"KEY", 25},
50
  {"AAAA", 28},
51
  {"LOC", 29},
52
  {"SRV", 33},
53
  {"NAPTR", 35},
54
  {"KX", 36},
55
  {"CERT", 37},
56
  {"A6", 38},
57
  {"DNAME", 39},
58
  {"OPT", 41},
59
  {"APL", 42},
60
  {"DS", 43},
61
  {"SSHFP", 44},
62
  {"IPSECKEY", 45},
63
  {"RRSIG", 46},
64
  {"NSEC", 47},
65
  {"DNSKEY", 48},
66
  {"DHCID", 49},
67
  {"NSEC3", 50},
68
  {"NSEC3PARAM", 51},
69
  {"TLSA", 52},
70
  {"SMIMEA", 53},
71
  {"RKEY", 57},
72
  {"CDS", 59},
73
  {"CDNSKEY", 60},
74
  {"OPENPGPKEY", 61},
75
  {"CSYNC", 62},
76
  {"ZONEMD", 63},
77
  {"SVCB", 64},
78
  {"HTTPS", 65},
79
  {"HHIT", 67},
80
  {"BRID", 68},
81
  {"SPF", 99},
82
  {"NID", 104},
83
  {"L32", 105},
84
  {"L64", 106},
85
  {"LP", 107},
86
  {"EUI48", 108},
87
  {"EUI64", 109},
88
  {"TKEY", 249},
89
  {"TSIG", 250},
90
  {"IXFR", 251},
91
  {"AXFR", 252},
92
  {"MAILB", 253},
93
  {"MAILA", 254},
94
  {"ANY", 255},
95
  {"URI", 256},
96
  {"CAA", 257},
97
  {"DLV", 32769},
98
  {"ADDR", 65400},
99
#if !defined(RECURSOR)
100
  {"ALIAS", 65401},
101
  {"LUA", 65402},
102
#endif
103
};
104

105
static map<uint16_t, const string> swapElements(const map<const string, uint16_t>& names) {
39,951✔
106
  map<uint16_t, const string> ret;
39,951✔
107

108
  for (const auto& n : names) {
2,674,895✔
109
    ret.emplace(n.second, n.first);
2,674,895✔
110
  }
2,674,895✔
111
  return ret;
39,951✔
112
}
39,951✔
113

114
const map<uint16_t, const string> QType::numbers = swapElements(names);
115

116

117
bool QType::isSupportedType() const
118
{
5,458✔
119
  return numbers.count(code) == 1;
5,458✔
120
}
5,458✔
121

122
bool QType::isMetadataType() const
123
{
5,458✔
124
  // rfc6895 section 3.1, note ANY is 255 and falls outside the range
125
  if (code == QType::OPT || (code >= rfc6895MetaLowerBound && code <= rfc6895MetaUpperBound)) {
5,458!
126
    return true;
×
127
  }
×
128
  return false;
5,458✔
129
}
5,458✔
130

131
const string QType::toString() const
132
{
1,873,171✔
133
  const auto& name = numbers.find(code);
1,873,171✔
134
  if (name != numbers.cend()) {
1,873,173✔
135
    return name->second;
1,871,903✔
136
  }
1,871,903✔
137
  return "TYPE" + std::to_string(code);
2,147,484,915✔
138
}
1,873,171✔
139

140
uint16_t QType::chartocode(const char *p)
141
{
1,214,317✔
142
  string P = toUpper(p);
1,214,317✔
143

144
  const auto& num = names.find(P);
1,214,317✔
145
  if (num != names.cend()) {
1,214,317✔
146
    return num->second;
1,205,764✔
147
  }
1,205,764✔
148
  if (*p == '#') {
8,553✔
149
    return static_cast<uint16_t>(atoi(p + 1));
2,665✔
150
  }
2,665✔
151

152
  if (boost::starts_with(P, "TYPE")) {
5,888✔
153
    return static_cast<uint16_t>(atoi(p + 4));
300✔
154
  }
300✔
155

156
  return 0;
5,588✔
157
}
5,888✔
158

159
QType &QType::operator=(const char *p)
160
{
2,834✔
161
  code = chartocode(p);
2,834✔
162
  return *this;
2,834✔
163
}
2,834✔
164

165
QType &QType::operator=(const string &s)
166
{
1,211,239✔
167
  code = chartocode(s.c_str());
1,211,239✔
168
  return *this;
1,211,239✔
169
}
1,211,239✔
170

171
static const std::map<const std::string, uint16_t> s_classMap = {
172
  {"IN", QClass::IN},
173
  {"CHAOS", QClass::CHAOS},
174
  {"NONE", QClass::NONE},
175
  {"ANY", QClass::ANY},
176
};
177

178
QClass::QClass(const std::string& code)
179
{
69✔
180
  auto mapIt = s_classMap.find(code);
69✔
181
  if (mapIt == s_classMap.end()) {
69!
182
    throw std::runtime_error("Invalid QClass '" + code + "'");
×
183
  }
×
184
  qclass = mapIt->second;
69✔
185
}
69✔
186

187
std::string QClass::toString() const
188
{
112,056✔
189
  switch (qclass) {
112,056✔
190
  case IN:
112,056!
191
    return "IN";
112,056✔
192
  case CHAOS:
×
193
    return "CHAOS";
×
194
  case NONE:
×
195
    return "NONE";
×
196
  case ANY:
×
197
    return "ANY";
×
198
  default :
×
199
    return "CLASS" + std::to_string(qclass);
×
200
  }
112,056✔
201
}
112,056✔
202

203
const std::set<uint16_t> QType::exclusiveEntryTypes = {
204
  QType::CNAME
205
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc