]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/bindparser.yy
Merge pull request #1896 from tuxis-ie/mysql-foreign-keys
[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 if(DI.filename[0]!='/')
93 DI.filename=d_dir+"/"+DI.filename;
94
95 if(d_verbose)
96 cerr<<"Domain "<<DI.name.toStringNoDot()<<" lives in file '"<<DI.filename<<"'"<<endl;
97
98 d_zonedomains.push_back(DI);
99 }
100
101 %}
102
103 %token AWORD QUOTEDWORD OBRACE EBRACE SEMICOLON ZONETOK FILETOK OPTIONSTOK
104 %token DIRECTORYTOK ACLTOK LOGGINGTOK CLASSTOK TYPETOK MASTERTOK ALSONOTIFYTOK
105
106 %%
107
108 root_commands:
109 |
110 root_commands root_command SEMICOLON
111 ;
112
113 root_command: command | acl_command | global_zone_command | global_options_command
114 ;
115
116 commands:
117 |
118 commands command SEMICOLON
119 ;
120
121 command:
122 terms
123 ;
124
125 global_zone_command:
126 ZONETOK quotedname zone_block
127 {
128 s_di.name=DNSName($2);
129 free($2);
130 parent->commit(s_di);
131 s_di.clear();
132 }
133 |
134 ZONETOK quotedname AWORD zone_block
135 {
136 s_di.name=DNSName($2);
137 free($2);
138 parent->commit(s_di);
139 s_di.clear();
140 }
141 ;
142
143
144 global_options_command:
145 OPTIONSTOK OBRACE options_commands EBRACE
146 |
147 LOGGINGTOK OBRACE options_commands EBRACE
148 ;
149
150
151 acl_command:
152 ACLTOK quotedname acl_block | ACLTOK filename acl_block
153 ;
154
155 acl_block: OBRACE acls EBRACE
156 ;
157
158 acls:
159 |
160 acl SEMICOLON acls
161 ;
162
163 acl:
164 AWORD
165 ;
166
167 options_commands:
168 |
169 options_command SEMICOLON options_commands
170 ;
171
172 options_command: command | global_options_command
173 ;
174
175 global_options_command: options_directory_command | also_notify_command
176 ;
177
178 options_directory_command: DIRECTORYTOK quotedname
179 {
180 parent->setDirectory($2);
181 free($2);
182 }
183 ;
184
185 also_notify_command: ALSONOTIFYTOK OBRACE also_notify_list EBRACE
186 ;
187
188 also_notify_list:
189 |
190 also_notify SEMICOLON also_notify_list
191 ;
192
193 also_notify: AWORD
194 {
195 parent->addAlsoNotify($1);
196 free($1);
197 }
198 ;
199 terms: /* empty */
200 |
201 terms term
202 ;
203
204 term: AWORD | block | quotedname
205 ;
206 block:
207 OBRACE commands EBRACE
208 ;
209
210 zone_block:
211 OBRACE zone_commands EBRACE
212 ;
213
214 zone_commands:
215 |
216 zone_commands zone_command SEMICOLON
217 ;
218
219 /* commands in zone
220 * in global scope also_notify_command is used instead of zone_also_notify_command
221 */
222 zone_command: command | global_zone_command | zone_also_notify_command
223 ;
224
225 /* zone commands that also are available at global scope */
226 global_zone_command: zone_file_command | zone_type_command | zone_masters_command
227 ;
228
229 zone_masters_command: MASTERTOK OBRACE masters EBRACE
230 ;
231
232 zone_also_notify_command: ALSONOTIFYTOK OBRACE zone_also_notify_list EBRACE
233 ;
234
235 zone_also_notify_list:
236 |
237 zone_also_notify SEMICOLON zone_also_notify_list
238 ;
239
240 zone_also_notify: AWORD
241 {
242 s_di.alsoNotify.insert($1);
243 free($1);
244 }
245 ;
246
247 masters: /* empty */
248 |
249 masters master SEMICOLON
250 ;
251
252 master: AWORD
253 {
254 s_di.masters.push_back($1);
255 free($1);
256 }
257 ;
258
259 zone_file_command:
260 FILETOK quotedname
261 {
262 // printf("Found a filename: '%s'\n",$2);
263 s_di.filename=$2;
264 free($2);
265 }
266 ;
267
268 zone_type_command:
269 TYPETOK AWORD
270 {
271 s_di.type=$2;
272 free($2);
273 }
274 ;
275
276
277 quotedname:
278 QUOTEDWORD
279 {
280 $$=$1;
281 }
282 ;
283
284 filename: AWORD
285 ;