root/trunk/pdns/pdns/backends/bind/bindparser.yy @ 495

Revision 495, 3.5 KB (checked in by ahu, 8 years ago)

make bind configuration parser drop dots in zone names to save complaints about out of zone data
make out-of-zone check more case insensitive

  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1%{
2
3#include <stdio.h>
4#include <string.h>
5#include <stdlib.h>
6#include <string>
7#include <iostream>
8#include <utility>
9#include <errno.h>
10#include "misc.hh"
11#include "zoneparser.hh"
12#include "ahuexception.hh"
13using namespace std;
14#define YYDEBUG 1
15extern int yydebug;
16#include "bindparser.hh"
17
18#define YYSTYPE char *
19
20
21#ifndef WIN32
22extern "C"
23{
24#endif // WIN32
25        int yyparse(void);
26        int yylex(void);
27        void yyrestart(FILE *);
28        int yywrap()
29        {
30                return 1;
31        }
32#ifndef WIN32
33}
34#endif // WIN32
35
36
37extern int yydebug;
38const char *bind_directory;
39extern int linenumber;
40static void yyerror(const char *str)
41{
42  extern char *current_filename;       
43  throw AhuException("Error in bind configuration '"+string(current_filename)+"' on line "+itoa(linenumber)+": "+str);
44}
45
46extern FILE *yyin;
47static BindParser *parent;
48BindDomainInfo s_di;
49
50void BindParser::parse(const string &fname)
51{       
52        yydebug=0;
53        yyin=fopen(fname.c_str(),"r");
54        yyrestart(yyin);
55        if(!yyin)
56                throw AhuException("Unable to open '"+fname+"': "+strerror(errno));
57
58        linenumber=1;
59        parent=this;
60        extern char *current_filename;
61        extern char *original_filename;
62
63        current_filename=original_filename=(char*)fname.c_str();
64
65        yyparse();
66
67//      cerr<<"Need to parse "<<d_zonedomains.size()<<" zone statements"<<endl;
68}
69
70void BindParser::setDirectory(const string &dir)
71{
72        d_dir=dir;
73        bind_directory=d_dir.c_str();
74}
75
76const string &BindParser::getDirectory()
77{
78        return d_dir;
79}
80
81const vector<BindDomainInfo>& BindParser::getDomains()
82{
83        return d_zonedomains;
84}
85
86void BindParser::setVerbose(bool verbose)
87{
88  d_verbose=verbose;
89}
90
91void BindParser::commit(BindDomainInfo DI)
92{
93  if(DI.filename[0]!='/')
94    DI.filename=d_dir+"/"+DI.filename;
95
96  if(d_verbose)
97    cerr<<"Domain "<<DI.name<<" lives in file '"<<DI.filename<<"'"<<endl;
98
99  d_zonedomains.push_back(DI);
100}
101
102%}
103
104%token AWORD QUOTEDWORD OBRACE EBRACE SEMICOLON ZONETOK FILETOK OPTIONSTOK
105%token DIRECTORYTOK ACLTOK LOGGINGTOK CLASSTOK TYPETOK MASTERTOK
106
107%%
108
109root_commands:
110        |       
111        root_commands root_command SEMICOLON
112        ;
113
114root_command: command | acl_command | zone_command | options_command
115        ;
116
117commands:
118        |
119        commands command SEMICOLON
120        ;
121
122command:
123        terms
124        ;
125
126zone_command:
127        ZONETOK quotedname zone_block
128        {
129                s_di.name=ZoneParser::canonic($2);
130               
131                parent->commit(s_di);
132                s_di.clear();
133        }
134        |       
135        ZONETOK quotedname AWORD zone_block
136        {
137                s_di.name=$2;
138                parent->commit(s_di);
139                s_di.clear();
140        }
141        ;
142
143
144options_command:
145        OPTIONSTOK OBRACE options_commands EBRACE
146        |
147        LOGGINGTOK OBRACE options_commands EBRACE
148        ;
149
150acl_command:
151        ACLTOK quotedname acl_block |   ACLTOK filename acl_block
152        ;
153
154acl_block: OBRACE acls EBRACE
155        ;
156       
157acls:
158        |
159        acl SEMICOLON acls
160        ;
161
162acl:
163        AWORD
164        ;
165
166options_commands:
167        |
168        options_command SEMICOLON options_commands
169        ;
170
171options_command: command | options_directory_command
172        ;
173
174options_directory_command: DIRECTORYTOK quotedname
175        {
176                parent->setDirectory($2);
177        }
178        ;
179
180
181terms: /* empty */
182        |
183        terms term
184        ;
185
186term: AWORD | block | quotedname
187        ;
188block:
189        OBRACE commands EBRACE
190        ;
191
192zone_block:
193        OBRACE zone_commands EBRACE
194        ;
195
196zone_commands: 
197        |
198        zone_commands zone_command SEMICOLON
199        ;
200
201zone_command: command | zone_file_command | zone_type_command | zone_masters_command
202        ;
203
204zone_masters_command: MASTERTOK OBRACE masters EBRACE
205        ;
206
207masters: /* empty */
208        |
209        masters master SEMICOLON
210        ;
211
212master: AWORD
213        {
214                s_di.master=$1;
215        }
216        ;
217
218zone_file_command:
219        FILETOK quotedname
220        {
221          //            printf("Found a filename: '%s'\n",$2);
222                s_di.filename=$2;
223        }
224        ;
225
226zone_type_command:
227TYPETOK AWORD
228        {
229                s_di.type=$2;
230        }
231        ;
232
233
234quotedname:
235        QUOTEDWORD
236        {
237                $$=$1;
238        }
239        ;
240
241filename: AWORD
242        ;
Note: See TracBrowser for help on using the browser.