]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/qtype.cc
Merge remote-tracking branch 'origin/master' into dnsname
[thirdparty/pdns.git] / pdns / qtype.cc
1 /*
2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 - 2007 PowerDNS.COM BV
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2
7 as published by the Free Software Foundation
8
9 Additionally, the license of this program contains a special
10 exception which allows to distribute the program in binary form when
11 it is linked against OpenSSL.
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 St, 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 vector<QType::namenum> QType::names;
32 // XXX FIXME we need to do something with initializer order here!
33 QType::init QType::initializer;
34
35 QType::QType()
36 {
37 }
38
39 bool QType::isSupportedType() {
40 for(vector<namenum>::iterator pos=names.begin();pos<names.end();++pos)
41 if(pos->second==code)
42 return true;
43 return false;
44 }
45
46 bool QType::isMetadataType() {
47 if (code == QType::AXFR ||
48 code == QType::MAILA ||
49 code == QType::MAILB ||
50 code == QType::TSIG ||
51 code == QType::IXFR)
52 return true;
53
54 return false;
55 }
56
57 uint16_t QType::getCode() const
58 {
59 return code;
60 }
61
62 const string QType::getName() const
63 {
64 vector<namenum>::iterator pos;
65 for(pos=names.begin();pos<names.end();++pos)
66 if(pos->second==code)
67 return pos->first;
68
69 return "TYPE"+itoa(code);
70 }
71
72 QType &QType::operator=(uint16_t n)
73 {
74 code=n;
75 return *this;
76 }
77
78 int QType::chartocode(const char *p)
79 {
80 string P = toUpper(p);
81 vector<namenum>::iterator pos;
82
83 for(pos=names.begin(); pos < names.end(); ++pos)
84 if(pos->first == P)
85 return pos->second;
86
87 if(*p=='#') {
88 return atoi(p+1);
89 }
90
91 if(boost::starts_with(P, "TYPE"))
92 return atoi(p+4);
93
94 return 0;
95 }
96
97 QType &QType::operator=(const char *p)
98 {
99 code=chartocode(p);
100 return *this;
101 }
102
103 QType &QType::operator=(const string &s)
104 {
105 code=chartocode(s.c_str());
106 return *this;
107 }
108
109
110 QType::QType(uint16_t n)
111 {
112 QType();
113 code=n;
114 }