]>
Commit | Line | Data |
---|---|---|
f814d7c8 BH |
1 | /* |
2 | PowerDNS Versatile Database Driven Nameserver | |
3 | Copyright (C) 2005 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 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
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 | |
17 | */ | |
18 | ||
19 | #include "dnsparser.hh" | |
20 | #include "sstuff.hh" | |
21 | #include "misc.hh" | |
22 | #include "dnswriter.hh" | |
23 | #include "dnsrecords.hh" | |
24 | #include "statbag.hh" | |
25 | #include "misc.hh" | |
26 | #include <fstream> | |
27 | #include "dns.hh" | |
28 | #include "zoneparser-tng.hh" | |
29 | ||
30 | ZoneParserTNG::ZoneParserTNG(const string& fname) | |
31 | { | |
32 | d_fp=fopen(fname.c_str(), "r"); | |
33 | if(!d_fp) | |
34 | throw runtime_error("Unable to open file '"+fname+"': "+stringerror()); | |
35 | } | |
36 | ||
37 | ZoneParserTNG::~ZoneParserTNG() | |
38 | { | |
39 | fclose(d_fp); | |
40 | } | |
41 | ||
42 | bool ZoneParserTNG::get(DNSResourceRecord& rr) | |
43 | { | |
44 | retry:; | |
45 | if(!getLine()) | |
46 | return false; | |
47 | string::size_type pos; | |
48 | vector<string> parts; | |
49 | ||
50 | if((pos=d_line.find(';'))!=string::npos) | |
51 | d_line.resize(pos); | |
52 | stripLine(d_line); | |
53 | if(d_line.empty()) | |
54 | goto retry; | |
55 | ||
56 | parts.clear(); | |
57 | stringtok(parts, d_line); | |
58 | if(parts.size()!=4 && parts.size()!=5) { | |
59 | cerr<<"Bad line: '"<<d_line<<"'\n"; | |
60 | return false; | |
61 | } | |
62 | ||
63 | rr.qname=toLowerCanonic(parts[0]); | |
64 | rr.ttl=atoi(parts[1].c_str()); | |
65 | string qclass("IN"); | |
66 | ||
67 | rr.qtype=parts[2 + (parts.size()==5)]; | |
68 | rr.content=parts[3 + (parts.size()==5)]; | |
69 | return true; | |
70 | } | |
71 | ||
72 | bool ZoneParserTNG::getLine() | |
73 | { | |
74 | char buffer[1024]; | |
75 | if(fgets(buffer, 1024, d_fp)) { | |
76 | d_line=buffer; | |
77 | return true; | |
78 | } | |
79 | return false; | |
80 | } | |
81 | ||
82 | ||
83 | #if 0 | |
84 | int main(int argc, char** argv) | |
85 | try | |
86 | { | |
87 | reportAllTypes(); | |
88 | ZoneParserTNG zpt(argv[1]); | |
89 | DNSResourceRecord rr; | |
90 | while(zpt.get(rr)) { | |
91 | } | |
92 | ||
93 | ||
94 | } | |
95 | catch(...) | |
96 | {} | |
97 | #endif |