]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/bindparser.yy
Merge pull request #8223 from PowerDNS/omoerbeek-patch-1
[thirdparty/pdns.git] / pdns / bindparser.yy
CommitLineData
caa6eefa
BH
1%{
2
12c86877
BH
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"
5c409fa2 11#include "pdnsexception.hh"
9095085b 12#include "namespaces.hh"
d622042f 13#include "iputils.hh"
12c86877
BH
14#define YYDEBUG 1
15extern int yydebug;
7c0cb150 16#include "bindparserclasses.hh"
12c86877
BH
17
18#define YYSTYPE char *
19
20extern "C"
21{
22 int yyparse(void);
23 int yylex(void);
caa6eefa 24 void yyrestart(FILE *);
12c86877
BH
25 int yywrap()
26 {
27 return 1;
28 }
12c86877 29}
caa6eefa 30
12c86877
BH
31
32extern int yydebug;
33const char *bind_directory;
34extern int linenumber;
35static void yyerror(const char *str)
36{
37 extern char *current_filename;
c761bae7 38 throw PDNSException("Error in bind configuration '"+string(current_filename)+"' on line "+itoa(linenumber)+": "+str);
12c86877
BH
39}
40
41extern FILE *yyin;
42static BindParser *parent;
43BindDomainInfo s_di;
44
45void BindParser::parse(const string &fname)
46{
47 yydebug=0;
48 yyin=fopen(fname.c_str(),"r");
bd11bd1d 49 yyrestart(yyin);
12c86877 50 if(!yyin)
c761bae7 51 throw PDNSException("Unable to open '"+fname+"': "+strerror(errno));
12c86877
BH
52
53 linenumber=1;
54 parent=this;
55 extern char *current_filename;
56 extern char *original_filename;
57
58 current_filename=original_filename=(char*)fname.c_str();
59
60 yyparse();
61
62// cerr<<"Need to parse "<<d_zonedomains.size()<<" zone statements"<<endl;
63}
64
65void BindParser::setDirectory(const string &dir)
66{
67 d_dir=dir;
68 bind_directory=d_dir.c_str();
69}
70
27d94a79
BH
71void BindParser::addAlsoNotify(const string & host)
72{
73 alsoNotify.insert(host);
74}
75
12c86877
BH
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{
6808f3b5
PL
93 DI.hadFileDirective = (DI.filename != "");
94
12c86877
BH
95 if(DI.filename[0]!='/')
96 DI.filename=d_dir+"/"+DI.filename;
97
98 if(d_verbose)
efa2cfa0 99 cerr<<"Domain "<<DI.name.toStringNoDot()<<" lives in file '"<<DI.filename<<"'"<<endl;
12c86877
BH
100
101 d_zonedomains.push_back(DI);
102}
103
104%}
105
caa6eefa 106%token AWORD QUOTEDWORD OBRACE EBRACE SEMICOLON ZONETOK FILETOK OPTIONSTOK
27d94a79 107%token DIRECTORYTOK ACLTOK LOGGINGTOK CLASSTOK TYPETOK MASTERTOK ALSONOTIFYTOK
12c86877
BH
108
109%%
110
111root_commands:
112 |
113 root_commands root_command SEMICOLON
114 ;
115
df58857e 116root_command: command | acl_command | global_zone_command | global_options_command
12c86877
BH
117 ;
118
119commands:
120 |
121 commands command SEMICOLON
122 ;
123
124command:
125 terms
126 ;
127
df58857e 128global_zone_command:
12c86877
BH
129 ZONETOK quotedname zone_block
130 {
06452a67 131 s_di.name=DNSName($2);
ef96aca0 132 free($2);
12c86877
BH
133 parent->commit(s_di);
134 s_di.clear();
135 }
136 |
caa6eefa 137 ZONETOK quotedname AWORD zone_block
12c86877 138 {
06452a67 139 s_di.name=DNSName($2);
ef96aca0 140 free($2);
12c86877
BH
141 parent->commit(s_di);
142 s_di.clear();
143 }
144 ;
145
146
df58857e 147global_options_command:
12c86877
BH
148 OPTIONSTOK OBRACE options_commands EBRACE
149 |
150 LOGGINGTOK OBRACE options_commands EBRACE
151 ;
152
27d94a79 153
12c86877
BH
154acl_command:
155 ACLTOK quotedname acl_block | ACLTOK filename acl_block
156 ;
157
158acl_block: OBRACE acls EBRACE
159 ;
160
161acls:
162 |
163 acl SEMICOLON acls
164 ;
165
166acl:
caa6eefa 167 AWORD
12c86877
BH
168 ;
169
170options_commands:
171 |
172 options_command SEMICOLON options_commands
173 ;
174
df58857e
SB
175options_command: command | global_options_command
176 ;
177
178global_options_command: options_directory_command | also_notify_command
12c86877
BH
179 ;
180
181options_directory_command: DIRECTORYTOK quotedname
182 {
183 parent->setDirectory($2);
ef96aca0 184 free($2);
12c86877
BH
185 }
186 ;
187
27d94a79
BH
188also_notify_command: ALSONOTIFYTOK OBRACE also_notify_list EBRACE
189 ;
190
191also_notify_list:
192 |
193 also_notify SEMICOLON also_notify_list
194 ;
12c86877 195
27d94a79
BH
196also_notify: AWORD
197 {
198 parent->addAlsoNotify($1);
199 free($1);
200 }
201 ;
12c86877
BH
202terms: /* empty */
203 |
204 terms term
205 ;
206
caa6eefa 207term: AWORD | block | quotedname
12c86877
BH
208 ;
209block:
210 OBRACE commands EBRACE
211 ;
212
213zone_block:
214 OBRACE zone_commands EBRACE
215 ;
216
df58857e 217zone_commands:
12c86877
BH
218 |
219 zone_commands zone_command SEMICOLON
220 ;
221
df58857e
SB
222/* commands in zone
223 * in global scope also_notify_command is used instead of zone_also_notify_command
224 */
225zone_command: command | global_zone_command | zone_also_notify_command
226 ;
227
228/* zone commands that also are available at global scope */
229global_zone_command: zone_file_command | zone_type_command | zone_masters_command
12c86877
BH
230 ;
231
232zone_masters_command: MASTERTOK OBRACE masters EBRACE
233 ;
234
27d94a79
BH
235zone_also_notify_command: ALSONOTIFYTOK OBRACE zone_also_notify_list EBRACE
236 ;
237
238zone_also_notify_list:
239 |
240 zone_also_notify SEMICOLON zone_also_notify_list
241 ;
242
243zone_also_notify: AWORD
244 {
245 s_di.alsoNotify.insert($1);
246 free($1);
247 }
248 ;
249
12c86877
BH
250masters: /* empty */
251 |
252 masters master SEMICOLON
253 ;
254
caa6eefa 255master: AWORD
12c86877 256 {
d622042f 257 s_di.masters.push_back(ComboAddress($1, 53));
ef96aca0 258 free($1);
12c86877
BH
259 }
260 ;
261
262zone_file_command:
263 FILETOK quotedname
264 {
265 // printf("Found a filename: '%s'\n",$2);
266 s_di.filename=$2;
ef96aca0 267 free($2);
12c86877
BH
268 }
269 ;
270
271zone_type_command:
caa6eefa 272TYPETOK AWORD
12c86877 273 {
973ad2b5 274 s_di.type=$2;
ef96aca0 275 free($2);
12c86877
BH
276 }
277 ;
278
279
280quotedname:
281 QUOTEDWORD
282 {
283 $$=$1;
284 }
285 ;
286
caa6eefa 287filename: AWORD
27d94a79 288 ;