]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/backends/bind/bindparser.yy
Initial revision
[thirdparty/pdns.git] / pdns / backends / bind / bindparser.yy
1 %{
2
3 #define DIRTY_HACK WORD
4 #undef WORD
5
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <string>
10 #include <iostream>
11 #include <utility>
12 #include <errno.h>
13 #include "misc.hh"
14 #include "ahuexception.hh"
15 using namespace std;
16 #define YYDEBUG 1
17 extern int yydebug;
18 #include "bindparser.hh"
19
20 #define WORD DIRTY_HACK
21
22 #define YYSTYPE char *
23
24 extern "C"
25 {
26 int yyparse(void);
27 int yylex(void);
28 int yywrap()
29 {
30 return 1;
31 }
32
33 }
34
35 extern int yydebug;
36 const char *bind_directory;
37 extern int linenumber;
38 static void yyerror(const char *str)
39 {
40 extern char *current_filename;
41 throw AhuException("Error in bind configuration '"+string(current_filename)+"' on line "+itoa(linenumber)+": "+str);
42 }
43
44 extern FILE *yyin;
45 static BindParser *parent;
46 BindDomainInfo s_di;
47
48 void BindParser::parse(const string &fname)
49 {
50 yydebug=0;
51 yyin=fopen(fname.c_str(),"r");
52
53 if(!yyin)
54 throw AhuException("Unable to open '"+fname+"': "+strerror(errno));
55
56 linenumber=1;
57 parent=this;
58 extern char *current_filename;
59 extern char *original_filename;
60
61 current_filename=original_filename=(char*)fname.c_str();
62
63 yyparse();
64
65 // cerr<<"Need to parse "<<d_zonedomains.size()<<" zone statements"<<endl;
66 }
67
68 void BindParser::setDirectory(const string &dir)
69 {
70 d_dir=dir;
71 bind_directory=d_dir.c_str();
72 }
73
74 const string &BindParser::getDirectory()
75 {
76 return d_dir;
77 }
78
79 const vector<BindDomainInfo>& BindParser::getDomains()
80 {
81 return d_zonedomains;
82 }
83
84 void BindParser::setVerbose(bool verbose)
85 {
86 d_verbose=verbose;
87 }
88
89 void BindParser::commit(BindDomainInfo DI)
90 {
91 if(DI.filename[0]!='/')
92 DI.filename=d_dir+"/"+DI.filename;
93
94 if(d_verbose)
95 cerr<<"Domain "<<DI.name<<" lives in file '"<<DI.filename<<"'"<<endl;
96
97 d_zonedomains.push_back(DI);
98 }
99
100 %}
101
102 %token WORD QUOTEDWORD OBRACE EBRACE SEMICOLON ZONETOK FILETOK OPTIONSTOK
103 %token DIRECTORYTOK ACLTOK LOGGINGTOK CLASSTOK TYPETOK MASTERTOK
104
105 %%
106
107 root_commands:
108 |
109 root_commands root_command SEMICOLON
110 ;
111
112 root_command: command | acl_command | zone_command | options_command
113 ;
114
115 commands:
116 |
117 commands command SEMICOLON
118 ;
119
120 command:
121 terms
122 ;
123
124 zone_command:
125 ZONETOK quotedname zone_block
126 {
127 s_di.name=$2;
128 parent->commit(s_di);
129 s_di.clear();
130 }
131 |
132 ZONETOK quotedname WORD zone_block
133 {
134 s_di.name=$2;
135 parent->commit(s_di);
136 s_di.clear();
137 }
138 ;
139
140
141 options_command:
142 OPTIONSTOK OBRACE options_commands EBRACE
143 |
144 LOGGINGTOK OBRACE options_commands EBRACE
145 ;
146
147 acl_command:
148 ACLTOK quotedname acl_block | ACLTOK filename acl_block
149 ;
150
151 acl_block: OBRACE acls EBRACE
152 ;
153
154 acls:
155 |
156 acl SEMICOLON acls
157 ;
158
159 acl:
160 WORD
161 ;
162
163 options_commands:
164 |
165 options_command SEMICOLON options_commands
166 ;
167
168 options_command: command | options_directory_command
169 ;
170
171 options_directory_command: DIRECTORYTOK quotedname
172 {
173 parent->setDirectory($2);
174 }
175 ;
176
177
178 terms: /* empty */
179 |
180 terms term
181 ;
182
183 term: WORD | block | quotedname
184 ;
185 block:
186 OBRACE commands EBRACE
187 ;
188
189 zone_block:
190 OBRACE zone_commands EBRACE
191 ;
192
193 zone_commands:
194 |
195 zone_commands zone_command SEMICOLON
196 ;
197
198 zone_command: command | zone_file_command | zone_type_command | zone_masters_command
199 ;
200
201 zone_masters_command: MASTERTOK OBRACE masters EBRACE
202 ;
203
204 masters: /* empty */
205 |
206 masters master SEMICOLON
207 ;
208
209 master: WORD
210 {
211 s_di.master=$1;
212 }
213 ;
214
215 zone_file_command:
216 FILETOK quotedname
217 {
218 // printf("Found a filename: '%s'\n",$2);
219 s_di.filename=$2;
220 }
221 ;
222
223 zone_type_command:
224 TYPETOK WORD
225 {
226 // printf("Found a filename: '%s'\n",$2);
227 // ztype=$2;
228 }
229 ;
230
231
232 quotedname:
233 QUOTEDWORD
234 {
235 $$=$1;
236 }
237 ;
238
239 filename: WORD
240 ;