]>
Commit | Line | Data |
---|---|---|
12c86877 BH |
1 | /* |
2 | PowerDNS Versatile Database Driven Nameserver | |
3 | Copyright (C) 2002 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 as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | */ | |
19 | #ifndef QTYPE_HH | |
20 | #define QTYPE_HH | |
21 | /* (C) 2002 POWERDNS.COM BV */ | |
22 | // $Id: qtype.hh,v 1.1 2002/11/27 15:18:32 ahu Exp $ | |
23 | #include <string> | |
24 | #include <vector> | |
25 | #include <utility> | |
26 | ||
27 | using namespace std; | |
28 | ||
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 seemlessly move between | |
31 | * them. Use it like this: | |
32 | ||
33 | \code | |
34 | QType t; | |
35 | t="CNAME"; | |
36 | cout<<t.getCode()<<endl; // prints '5' | |
37 | t=6; | |
38 | cout<<t.getName()<<endl; // prints 'SOA' | |
39 | \endcode | |
40 | ||
41 | */ | |
42 | ||
43 | ||
44 | ||
45 | class QType | |
46 | { | |
47 | public: | |
48 | QType(); //!< Naked constructor | |
49 | explicit QType(int); //!< convert from an integer to a QType | |
50 | QType(char *p); //!< convert from a char* to a QType\r | |
51 | ||
52 | QType &operator=(int); //!< Assigns integers to us | |
53 | QType &operator=(const char *); //!< Assings strings to us | |
54 | QType &operator=(const string &); //!< Assings strings to us | |
55 | bool operator==(const QType &) const; //!< equality operator | |
56 | ||
57 | string getName() const; //!< Get a string representation of this type | |
58 | int getCode() const; //!< Get the integer representation of this type | |
59 | ||
60 | static int chartocode(const char *p); //!< convert a character string to a code | |
61 | ||
62 | enum {A=1,NS=2,CNAME=5,SOA=6,PTR=12,MX=15,TXT=16,AAAA=28,NAPTR=35,AXFR=252, ANY=255} types; | |
63 | private: | |
64 | short int code; | |
65 | typedef pair<string,int> namenum; | |
66 | void insert(char *p, int n); | |
67 | ||
68 | static vector<namenum> names; | |
69 | static bool uninit; | |
70 | }; | |
71 | ||
72 | ||
73 | #endif |