~ubuntu-branches/ubuntu/maverick/pdns/maverick-updates

« back to all changes in this revision

Viewing changes to pdns/dnsparser.hh

  • Committer: Bazaar Package Importer
  • Author(s): Matthijs Mohlmann, Matthijs Mohlmann, Christoph Haas
  • Date: 2007-04-15 23:23:39 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070415232339-5x3scc8gx04e50um
Tags: 2.9.21-1
[ Matthijs Mohlmann ]
* New upstream release. (Closes: #420294)
* Remove meta pdns package.
* Added new sqlite3 backend package.
* Months and minutes where mixed up. (Closes: #406462)
* Case sensitivity in bind backend caused PowerDNS to not serve a certain
  zone. (Closes: #406461)
* Bind backend forgot about zones on a notify. (Closes: #398213)

[ Christoph Haas ]
* Documented incorporated backend bind. (Closes: #415471)

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
    You should have received a copy of the GNU General Public License
15
15
    along with this program; if not, write to the Free Software
16
 
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
*/
18
18
 
19
19
#ifndef DNSPARSER_HH
25
25
#include <iostream>
26
26
#include <vector>
27
27
#include <errno.h>
28
 
#include <netinet/in.h>
29
 
#include <arpa/nameser.h>
 
28
// #include <netinet/in.h>
30
29
#include "misc.hh"
31
30
#include <boost/shared_ptr.hpp>
32
31
#include <boost/lexical_cast.hpp>
33
32
#include <boost/tuple/tuple.hpp>
34
33
#include <boost/tuple/tuple_comparison.hpp>
 
34
#include "dns.hh"
35
35
#include "dnswriter.hh"
36
36
 
37
37
/** DNS records have three representations:
47
47
    And we might be able to reverse 2 -> 3 as well
48
48
*/
49
49
    
50
 
 
51
 
//namespace {
52
 
  typedef HEADER dnsheader;
53
 
//}
54
 
 
55
50
using namespace std;
56
51
using namespace boost;
57
 
typedef runtime_error MOADNSException;
58
52
 
59
 
struct dnsrecordheader
 
53
class MOADNSException : public runtime_error
60
54
{
61
 
  uint16_t d_type;
62
 
  uint16_t d_class;
63
 
  uint32_t d_ttl;
64
 
  uint16_t d_clen;
65
 
} __attribute__((packed));
 
55
public:
 
56
  MOADNSException(const string& str) : runtime_error(str)
 
57
  {}
 
58
};
66
59
 
67
60
 
68
61
class MOADNSParser;
116
109
    label=getLabel();
117
110
  }
118
111
 
119
 
  void xfrText(string &text)
 
112
  void xfrText(string &text, bool multi=false)
120
113
  {
121
 
    text=getText();
 
114
    text=getText(multi);
122
115
  }
123
116
 
124
117
  void xfrBlob(string& blob);
 
118
  void xfrHexBlob(string& blob);
125
119
 
126
120
  static uint16_t get16BitInt(const vector<unsigned char>&content, uint16_t& pos);
127
121
  static void getLabelFromContent(const vector<uint8_t>& content, uint16_t& frompos, string& ret, int recurs);
131
125
  void copyRecord(unsigned char* dest, uint16_t len);
132
126
 
133
127
  string getLabel(unsigned int recurs=0);
134
 
  string getText();
 
128
  string getText(bool multi);
135
129
 
136
130
  uint16_t d_pos;
137
131
 
179
173
  static void regist(uint16_t cl, uint16_t ty, makerfunc_t* f, zmakerfunc_t* z, const char* name)
180
174
  {
181
175
    if(f)
182
 
      typemap[make_pair(cl,ty)]=f;
 
176
      getTypemap()[make_pair(cl,ty)]=f;
183
177
    if(z)
184
 
      zmakermap[make_pair(cl,ty)]=z;
185
 
 
186
 
    namemap[make_pair(cl,ty)]=name;
 
178
      getZmakermap()[make_pair(cl,ty)]=z;
 
179
 
 
180
    getNamemap()[make_pair(cl,ty)]=name;
 
181
  }
 
182
 
 
183
  static void unregist(uint16_t cl, uint16_t ty) 
 
184
  {
 
185
    pair<uint16_t, uint16_t> key=make_pair(cl, ty);
 
186
    getTypemap().erase(key);
 
187
    getZmakermap().erase(key);
187
188
  }
188
189
 
189
190
  static uint16_t TypeToNumber(const string& name)
190
191
  {
191
 
    for(namemap_t::const_iterator i=namemap.begin(); i!=namemap.end();++i)
192
 
      if(!strcasecmp(i->second.c_str(), name.c_str()))
 
192
    for(namemap_t::const_iterator i=getNamemap().begin(); i!=getNamemap().end();++i)
 
193
      if(!Utility::strcasecmp(i->second.c_str(), name.c_str()))
193
194
        return i->first.second;
194
195
 
195
196
    throw runtime_error("Unknown DNS type '"+name+"'");
197
198
 
198
199
  static const string NumberToType(uint16_t num)
199
200
  {
200
 
    if(!namemap.count(make_pair(1,num)))
 
201
    if(!getNamemap().count(make_pair(1,num)))
201
202
      return "#" + lexical_cast<string>(num);
202
203
      //      throw runtime_error("Unknown DNS type with numerical id "+lexical_cast<string>(num));
203
 
    return namemap[make_pair(1,num)];
 
204
    return getNamemap()[make_pair(1,num)];
204
205
  }
205
206
 
206
207
  explicit DNSRecordContent(uint16_t type) : d_qtype(type)
209
210
 
210
211
protected:
211
212
  typedef std::map<std::pair<uint16_t, uint16_t>, makerfunc_t* > typemap_t;
212
 
  static typemap_t typemap;
213
 
 
214
213
  typedef std::map<std::pair<uint16_t, uint16_t>, zmakerfunc_t* > zmakermap_t;
215
 
  static zmakermap_t zmakermap;
216
 
 
217
214
  typedef std::map<std::pair<uint16_t, uint16_t>, string > namemap_t;
218
 
  static namemap_t namemap;
 
215
 
 
216
  static typemap_t& getTypemap();
 
217
  static namemap_t& getNamemap();
 
218
  static zmakermap_t& getZmakermap();
219
219
};
220
220
 
221
221
struct DNSRecord
268
268
  //! Parse from a string
269
269
  MOADNSParser(const string& buffer) 
270
270
  {
271
 
    init(buffer.c_str(), buffer.size());
 
271
    init(buffer.c_str(), (unsigned int)buffer.size());
272
272
  }
273
273
 
274
274
  //! Parse from a pointer and length
310
310
  vector<uint8_t> d_content;
311
311
};
312
312
 
313
 
 
 
313
string simpleCompress(const string& label);
 
314
void simpleExpandTo(const string& label, unsigned int frompos, string& ret);
314
315
 
315
316
#endif