11 #include "pdnsexception.hh"
12 #include "namespaces.hh"
16 #include "bindparserclasses.hh"
18 #define YYSTYPE char *
24 void yyrestart(FILE *);
34 const char *bind_directory;
35 extern int linenumber;
36 static void yyerror(const char *str)
38 extern char *current_filename;
39 throw PDNSException("Error in bind configuration '"+string(current_filename)+"' on line "+std::to_string(linenumber)+": "+str);
43 static BindParser *parent;
46 void BindParser::parse(const string &fname)
49 yyin=fopen(fname.c_str(),"r");
52 throw PDNSException("Unable to open '"+fname+"': "+strerror(errno));
56 extern char *current_filename;
57 extern char *original_filename;
59 current_filename=original_filename=(char*)fname.c_str();
63 // cerr<<"Need to parse "<<d_zonedomains.size()<<" zone statements"<<endl;
66 void BindParser::setDirectory(const string &dir)
69 if (d_dir.back() == '/') {
72 bind_directory=d_dir.c_str();
75 void BindParser::addAlsoNotify(const string & host)
77 alsoNotify.insert(host);
80 const string &BindParser::getDirectory()
85 const vector<BindDomainInfo>& BindParser::getDomains()
90 void BindParser::setVerbose(bool verbose)
95 void BindParser::commit(BindDomainInfo DI)
97 DI.hadFileDirective = (DI.filename != "");
99 if(DI.filename[0]!='/')
100 DI.filename=d_dir+"/"+DI.filename;
103 cerr<<"Domain "<<DI.name.toStringNoDot()<<" lives in file '"<<DI.filename<<"'"<<endl;
105 d_zonedomains.push_back(DI);
110 %token AWORD QUOTEDWORD OBRACE EBRACE SEMICOLON ZONETOK FILETOK OPTIONSTOK
111 %token DIRECTORYTOK ACLTOK LOGGINGTOK CLASSTOK TYPETOK MASTERTOK ALSONOTIFYTOK
117 root_commands root_command SEMICOLON
120 root_command: command | acl_command | global_zone_command | global_options_command
125 commands command SEMICOLON
133 ZONETOK quotedname zone_block
135 s_di.name=DNSName($2);
137 parent->commit(s_di);
141 ZONETOK quotedname AWORD zone_block
143 s_di.name=DNSName($2);
145 parent->commit(s_di);
151 global_options_command:
152 OPTIONSTOK OBRACE options_commands EBRACE
154 LOGGINGTOK OBRACE options_commands EBRACE
159 ACLTOK quotedname acl_block | ACLTOK filename acl_block
162 acl_block: OBRACE acls EBRACE
176 options_command SEMICOLON options_commands
179 options_command: command | global_options_command
182 global_options_command: options_directory_command | also_notify_command
185 options_directory_command: DIRECTORYTOK quotedname
187 parent->setDirectory($2);
192 also_notify_command: ALSONOTIFYTOK OBRACE also_notify_list EBRACE
197 also_notify SEMICOLON also_notify_list
202 parent->addAlsoNotify($1);
211 term: AWORD | block | quotedname
214 OBRACE commands EBRACE
218 OBRACE zone_commands EBRACE
223 zone_commands zone_command SEMICOLON
227 * in global scope also_notify_command is used instead of zone_also_notify_command
229 zone_command: command | global_zone_command | zone_also_notify_command
232 /* zone commands that also are available at global scope */
233 global_zone_command: zone_file_command | zone_type_command | zone_masters_command
236 zone_masters_command: MASTERTOK OBRACE masters EBRACE
239 zone_also_notify_command: ALSONOTIFYTOK OBRACE zone_also_notify_list EBRACE
242 zone_also_notify_list:
244 zone_also_notify SEMICOLON zone_also_notify_list
247 zone_also_notify: AWORD
249 s_di.alsoNotify.insert($1);
256 masters master SEMICOLON
261 s_di.masters.push_back(ComboAddress($1, 53));
269 // printf("Found a filename: '%s'\n",$2);