1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
PowerDNS Versatile Database Driven Nameserver
Copyright (C) 2002 - 2007 PowerDNS.COM BV
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation
Additionally, the license of this program contains a special
exception which allows to distribute the program in binary form when
it is linked against OpenSSL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dns.hh"
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <sstream>
#include "qtype.hh"
#include "misc.hh"
static_assert(sizeof(QType) == 2, "QType is not 2 bytes in size, something is wrong!");
vector<QType::namenum> QType::names;
// XXX FIXME we need to do something with initializer order here!
QType::init QType::initializer;
QType::QType()
{
code = 0;
}
bool QType::isSupportedType() {
for(vector<namenum>::iterator pos=names.begin();pos<names.end();++pos)
if(pos->second==code)
return true;
return false;
}
bool QType::isMetadataType() {
if (code == QType::AXFR ||
code == QType::MAILA ||
code == QType::MAILB ||
code == QType::TSIG ||
code == QType::IXFR)
return true;
return false;
}
uint16_t QType::getCode() const
{
return code;
}
const string QType::getName() const
{
vector<namenum>::iterator pos;
for(pos=names.begin();pos<names.end();++pos)
if(pos->second==code)
return pos->first;
return "TYPE"+itoa(code);
}
QType &QType::operator=(uint16_t n)
{
code=n;
return *this;
}
int QType::chartocode(const char *p)
{
string P = toUpper(p);
vector<namenum>::iterator pos;
for(pos=names.begin(); pos < names.end(); ++pos)
if(pos->first == P)
return pos->second;
if(*p=='#') {
return atoi(p+1);
}
if(boost::starts_with(P, "TYPE"))
return atoi(p+4);
return 0;
}
QType &QType::operator=(const char *p)
{
code=chartocode(p);
return *this;
}
QType &QType::operator=(const string &s)
{
code=chartocode(s.c_str());
return *this;
}
QType::QType(uint16_t n)
{
QType();
code=n;
}
|