]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/qtype.cc
Merge pull request #825 from dev-zero/master
[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
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #include "utility.hh"
20 #include "dns.hh"
21 #include <iostream>
22 #include <string>
23 #include <vector>
24 #include <utility>
25 #include <sstream>
26 #include "qtype.hh"
27 #include "misc.hh"
28 #include "lock.hh"
29
30 vector<QType::namenum> QType::names;
31 // XXX FIXME we need to do something with initializer order here!
32 QType::init QType::initializer;
33
34 QType::QType()
35 {
36 }
37
38 bool QType::isSupportedType() {
39 for(vector<namenum>::iterator pos=names.begin();pos<names.end();++pos)
40 if(pos->second==code)
41 return true;
42 return false;
43 }
44
45 bool QType::isMetadataType() {
46 if (code == QType::AXFR ||
47 code == QType::MAILA ||
48 code == QType::MAILB ||
49 code == QType::TSIG ||
50 code == QType::IXFR)
51 return true;
52
53 return false;
54 }
55
56 uint16_t QType::getCode() const
57 {
58 return code;
59 }
60
61 const string QType::getName() const
62 {
63 vector<namenum>::iterator pos;
64 for(pos=names.begin();pos<names.end();++pos)
65 if(pos->second==code)
66 return pos->first;
67
68 return "TYPE"+itoa(code);
69 }
70
71 QType &QType::operator=(uint16_t n)
72 {
73 code=n;
74 return *this;
75 }
76
77 int QType::chartocode(const char *p)
78 {
79 static QType qt;
80 vector<namenum>::iterator pos;
81 for(pos=names.begin(); pos < names.end(); ++pos)
82 if(pos->first == p)
83 return pos->second;
84
85 if(*p=='#') {
86 return atoi(p+1);
87 }
88
89 if(boost::starts_with(p, "TYPE"))
90 return atoi(p+4);
91
92 return 0;
93 }
94
95 QType &QType::operator=(const char *p)
96 {
97 code=chartocode(p);
98 return *this;
99 }
100
101 QType &QType::operator=(const string &s)
102 {
103 code=chartocode(s.c_str());
104 return *this;
105 }
106
107
108 QType::QType(uint16_t n)
109 {
110 QType();
111 code=n;
112 }