]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/qtype.cc
Merge pull request #2141 from zeha/out-of-tree-build
[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 "utility.hh"
23 #include "dns.hh"
24 #include <iostream>
25 #include <string>
26 #include <vector>
27 #include <utility>
28 #include <sstream>
29 #include "qtype.hh"
30 #include "misc.hh"
31 #include "lock.hh"
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 }
40
41 bool QType::isSupportedType() {
42 for(vector<namenum>::iterator pos=names.begin();pos<names.end();++pos)
43 if(pos->second==code)
44 return true;
45 return false;
46 }
47
48 bool QType::isMetadataType() {
49 if (code == QType::AXFR ||
50 code == QType::MAILA ||
51 code == QType::MAILB ||
52 code == QType::TSIG ||
53 code == QType::IXFR)
54 return true;
55
56 return false;
57 }
58
59 uint16_t QType::getCode() const
60 {
61 return code;
62 }
63
64 const string QType::getName() const
65 {
66 vector<namenum>::iterator pos;
67 for(pos=names.begin();pos<names.end();++pos)
68 if(pos->second==code)
69 return pos->first;
70
71 return "TYPE"+itoa(code);
72 }
73
74 QType &QType::operator=(uint16_t n)
75 {
76 code=n;
77 return *this;
78 }
79
80 int QType::chartocode(const char *p)
81 {
82 string P = toUpper(p);
83 vector<namenum>::iterator pos;
84
85 for(pos=names.begin(); pos < names.end(); ++pos)
86 if(pos->first == P)
87 return pos->second;
88
89 if(*p=='#') {
90 return atoi(p+1);
91 }
92
93 if(boost::starts_with(P, "TYPE"))
94 return atoi(p+4);
95
96 return 0;
97 }
98
99 QType &QType::operator=(const char *p)
100 {
101 code=chartocode(p);
102 return *this;
103 }
104
105 QType &QType::operator=(const string &s)
106 {
107 code=chartocode(s.c_str());
108 return *this;
109 }
110
111
112 QType::QType(uint16_t n)
113 {
114 QType();
115 code=n;
116 }