]>
Commit | Line | Data |
---|---|---|
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" |
12c86877 BH |
13 | #define YYDEBUG 1 |
14 | extern int yydebug; | |
7c0cb150 | 15 | #include "bindparserclasses.hh" |
12c86877 BH |
16 | |
17 | #define YYSTYPE char * | |
18 | ||
19 | extern "C" | |
20 | { | |
21 | int yyparse(void); | |
22 | int yylex(void); | |
caa6eefa | 23 | void yyrestart(FILE *); |
12c86877 BH |
24 | int yywrap() |
25 | { | |
26 | return 1; | |
27 | } | |
12c86877 | 28 | } |
caa6eefa | 29 | |
12c86877 BH |
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; | |
c761bae7 | 37 | throw PDNSException("Error in bind configuration '"+string(current_filename)+"' on line "+itoa(linenumber)+": "+str); |
12c86877 BH |
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"); | |
bd11bd1d | 48 | yyrestart(yyin); |
12c86877 | 49 | if(!yyin) |
c761bae7 | 50 | throw PDNSException("Unable to open '"+fname+"': "+strerror(errno)); |
12c86877 BH |
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 | ||
27d94a79 BH |
70 | void BindParser::addAlsoNotify(const string & host) |
71 | { | |
72 | alsoNotify.insert(host); | |
73 | } | |
74 | ||
12c86877 BH |
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 | { | |
6808f3b5 PL |
92 | DI.hadFileDirective = (DI.filename != ""); |
93 | ||
12c86877 BH |
94 | if(DI.filename[0]!='/') |
95 | DI.filename=d_dir+"/"+DI.filename; | |
96 | ||
97 | if(d_verbose) | |
efa2cfa0 | 98 | cerr<<"Domain "<<DI.name.toStringNoDot()<<" lives in file '"<<DI.filename<<"'"<<endl; |
12c86877 BH |
99 | |
100 | d_zonedomains.push_back(DI); | |
101 | } | |
102 | ||
103 | %} | |
104 | ||
caa6eefa | 105 | %token AWORD QUOTEDWORD OBRACE EBRACE SEMICOLON ZONETOK FILETOK OPTIONSTOK |
27d94a79 | 106 | %token DIRECTORYTOK ACLTOK LOGGINGTOK CLASSTOK TYPETOK MASTERTOK ALSONOTIFYTOK |
12c86877 BH |
107 | |
108 | %% | |
109 | ||
110 | root_commands: | |
111 | | | |
112 | root_commands root_command SEMICOLON | |
113 | ; | |
114 | ||
df58857e | 115 | root_command: command | acl_command | global_zone_command | global_options_command |
12c86877 BH |
116 | ; |
117 | ||
118 | commands: | |
119 | | | |
120 | commands command SEMICOLON | |
121 | ; | |
122 | ||
123 | command: | |
124 | terms | |
125 | ; | |
126 | ||
df58857e | 127 | global_zone_command: |
12c86877 BH |
128 | ZONETOK quotedname zone_block |
129 | { | |
06452a67 | 130 | s_di.name=DNSName($2); |
ef96aca0 | 131 | free($2); |
12c86877 BH |
132 | parent->commit(s_di); |
133 | s_di.clear(); | |
134 | } | |
135 | | | |
caa6eefa | 136 | ZONETOK quotedname AWORD zone_block |
12c86877 | 137 | { |
06452a67 | 138 | s_di.name=DNSName($2); |
ef96aca0 | 139 | free($2); |
12c86877 BH |
140 | parent->commit(s_di); |
141 | s_di.clear(); | |
142 | } | |
143 | ; | |
144 | ||
145 | ||
df58857e | 146 | global_options_command: |
12c86877 BH |
147 | OPTIONSTOK OBRACE options_commands EBRACE |
148 | | | |
149 | LOGGINGTOK OBRACE options_commands EBRACE | |
150 | ; | |
151 | ||
27d94a79 | 152 | |
12c86877 BH |
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: | |
caa6eefa | 166 | AWORD |
12c86877 BH |
167 | ; |
168 | ||
169 | options_commands: | |
170 | | | |
171 | options_command SEMICOLON options_commands | |
172 | ; | |
173 | ||
df58857e SB |
174 | options_command: command | global_options_command |
175 | ; | |
176 | ||
177 | global_options_command: options_directory_command | also_notify_command | |
12c86877 BH |
178 | ; |
179 | ||
180 | options_directory_command: DIRECTORYTOK quotedname | |
181 | { | |
182 | parent->setDirectory($2); | |
ef96aca0 | 183 | free($2); |
12c86877 BH |
184 | } |
185 | ; | |
186 | ||
27d94a79 BH |
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 | ; | |
12c86877 | 194 | |
27d94a79 BH |
195 | also_notify: AWORD |
196 | { | |
197 | parent->addAlsoNotify($1); | |
198 | free($1); | |
199 | } | |
200 | ; | |
12c86877 BH |
201 | terms: /* empty */ |
202 | | | |
203 | terms term | |
204 | ; | |
205 | ||
caa6eefa | 206 | term: AWORD | block | quotedname |
12c86877 BH |
207 | ; |
208 | block: | |
209 | OBRACE commands EBRACE | |
210 | ; | |
211 | ||
212 | zone_block: | |
213 | OBRACE zone_commands EBRACE | |
214 | ; | |
215 | ||
df58857e | 216 | zone_commands: |
12c86877 BH |
217 | | |
218 | zone_commands zone_command SEMICOLON | |
219 | ; | |
220 | ||
df58857e SB |
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 | |
12c86877 BH |
229 | ; |
230 | ||
231 | zone_masters_command: MASTERTOK OBRACE masters EBRACE | |
232 | ; | |
233 | ||
27d94a79 BH |
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 | ||
12c86877 BH |
249 | masters: /* empty */ |
250 | | | |
251 | masters master SEMICOLON | |
252 | ; | |
253 | ||
caa6eefa | 254 | master: AWORD |
12c86877 | 255 | { |
e5b11b2f | 256 | s_di.masters.push_back($1); |
ef96aca0 | 257 | free($1); |
12c86877 BH |
258 | } |
259 | ; | |
260 | ||
261 | zone_file_command: | |
262 | FILETOK quotedname | |
263 | { | |
264 | // printf("Found a filename: '%s'\n",$2); | |
265 | s_di.filename=$2; | |
ef96aca0 | 266 | free($2); |
12c86877 BH |
267 | } |
268 | ; | |
269 | ||
270 | zone_type_command: | |
caa6eefa | 271 | TYPETOK AWORD |
12c86877 | 272 | { |
973ad2b5 | 273 | s_di.type=$2; |
ef96aca0 | 274 | free($2); |
12c86877 BH |
275 | } |
276 | ; | |
277 | ||
278 | ||
279 | quotedname: | |
280 | QUOTEDWORD | |
281 | { | |
282 | $$=$1; | |
283 | } | |
284 | ; | |
285 | ||
caa6eefa | 286 | filename: AWORD |
27d94a79 | 287 | ; |