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