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