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.
27 #include "namespaces.hh"
29 /** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS',
30 * 'CNAME' etcetera. These types have both a name and a number. This class can seamlessly move between
31 * them. Use it like this:
36 cout<<t.getCode()<<endl; // prints '5'
38 cout<<t.toString()<<endl; // prints 'SOA'
46 QType(uint16_t qtype = 0) : code(qtype) {}
47 QType &operator=(const char *);
48 QType &operator=(const string &);
50 operator uint16_t() const {
54 const string toString() const;
55 uint16_t getCode() const
61 * \brief Return whether we know the name of this type.
63 * This does not presume that we have an implemented a content representation for this type,
64 * for that please see DNSRecordContent::isRegisteredType().
66 bool isSupportedType() const;
68 * \brief Whether the type is either a QTYPE or Meta-Type as defined by rfc6895 section 3.1.
70 * Note that ANY is 255 and falls outside the range.
72 bool isMetadataType() const;
74 static uint16_t chartocode(const char* p);
76 enum typeenum : uint16_t {
141 #if !defined(RECURSOR)
147 const static uint16_t rfc6895MetaLowerBound = 128;
148 const static uint16_t rfc6895MetaUpperBound = 254; // Note 255: ANY is not included
149 const static uint16_t rfc6895Reserved = 65535;
151 const static map<const string, uint16_t> names;
152 const static map<uint16_t, const string> numbers;
159 // Define hash function on QType. See https://en.cppreference.com/w/cpp/utility/hash
161 template<> struct hash<QType> {
162 std::size_t operator()(QType qtype) const noexcept {
163 return std::hash<uint16_t>{}(qtype.getCode());
168 inline std::ostream& operator<<(std::ostream& stream, const QType& qtype)
170 return stream << qtype.toString();
173 // Used by e.g. boost multi-index
174 inline size_t hash_value(const QType qtype) {
175 return qtype.getCode();
180 constexpr QClass(uint16_t code = 0) : qclass(code) {}
182 constexpr operator uint16_t() const {
185 constexpr uint16_t getCode() const
189 const std::string toString() const;
191 static const QClass IN;
192 static const QClass CHAOS;
193 static const QClass NONE;
194 static const QClass ANY;
200 constexpr QClass QClass::IN(1);
201 constexpr QClass QClass::CHAOS(3);
202 constexpr QClass QClass::NONE(254);
203 constexpr QClass QClass::ANY(255);
205 inline std::ostream& operator<<(std::ostream& s, QClass qclass)
207 return s << qclass.toString();