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