No empty .Rs/.Re
[netbsd-mini2440.git] / usr.sbin / isdn / isdnd / rc_parse.y
blob14a8ec1772c2cbbc4df055a22ac562f875f3fb2c
1 /*
2 * Copyright (c) 1997 Joerg Wunsch. All rights reserved.
4 * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
28 *---------------------------------------------------------------------------
30 * i4b daemon - runtime configuration parser
31 * -----------------------------------------
33 * $Id: rc_parse.y,v 1.6 2009/04/16 05:56:32 lukem Exp $
35 * $FreeBSD$
37 * last edit-date: [Mon Oct 2 22:51:23 2000]
39 *---------------------------------------------------------------------------*/
43 /* #define YYDEBUG 1 */
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <ctype.h>
49 #include "monitor.h" /* monitor access rights bit definitions */
50 #include "isdnd.h"
52 #ifndef FALSE
53 # define FALSE 0
54 #endif
56 #ifndef TRUE
57 # define TRUE 1
58 #endif
60 extern void cfg_setval(int keyword);
61 extern void init_currrent_cfg_state(void);
62 extern void reset_scanner(FILE *infile);
63 extern void yyerror(const char *msg);
64 extern int yylex(void);
65 extern void flush_config(void);
67 extern int lineno;
68 extern char *yytext;
70 extern struct isdn_ctrl_state * cur_ctrl;
72 int saw_system = 0;
75 %token ACCTALL
76 %token ACCTFILE
77 %token ALERT
78 %token ALIASFNAME
79 %token ALIASING
80 %token ANSWERPROG
81 %token AUTOUPDOWN
82 %token B1PROTOCOL
83 %token BEEPCONNECT
84 %token BUDGETCALLOUTPERIOD
85 %token BUDGETCALLOUTNCALLS
86 %token BUDGETCALLOUTSFILE
87 %token BUDGETCALLOUTSFILEROTATE
88 %token BUDGETCALLBACKPERIOD
89 %token BUDGETCALLBACKNCALLS
90 %token BUDGETCALLBACKSFILE
91 %token BUDGETCALLBACKSFILEROTATE
92 %token CALLBACKWAIT
93 %token CALLEDBACKWAIT
94 %token CALLIN
95 %token CALLOUT
96 %token CHANNELSTATE
97 %token CONNECTPROG
98 %token CONTROLLER
99 %token DIALOUTTYPE
100 %token DIALRANDINCR
101 %token DIALRETRIES
102 %token DIRECTION
103 %token DISCONNECTPROG
104 %token DOWNTIME
105 %token DOWNTRIES
106 %token EARLYHANGUP
107 %token ENTRY
108 %token EXTCALLATTR
109 %token FIRMWARE
110 %token FULLCMD
111 %token HOLIDAYFILE
112 %token IDLETIME_IN
113 %token IDLETIME_OUT
114 %token IDLE_ALG_OUT
115 %token ISDNCHANNEL
116 %token ISDNCONTROLLER
117 %token ISDNTIME
118 %token ISDNTXDELIN
119 %token ISDNTXDELOUT
120 %token LOCAL_PHONE_DIALOUT
121 %token LOCAL_PHONE_INCOMING
122 %token LOGEVENTS
123 %token MAILER
124 %token MAILTO
125 %token MONITOR
126 %token MONITORACCESS
127 %token MONITORPORT
128 %token MONITORSW
129 %token NAME
130 %token NO
131 %token OFF
132 %token ON
133 %token PPP_AUTH_RECHALLENGE
134 %token PPP_AUTH_PARANOID
135 %token PPP_EXPECT_AUTH
136 %token PPP_EXPECT_NAME
137 %token PPP_EXPECT_PASSWORD
138 %token PPP_SEND_AUTH
139 %token PPP_SEND_NAME
140 %token PPP_SEND_PASSWORD
141 %token PROTOCOL
142 %token RATESFILE
143 %token RATETYPE
144 %token REACTION
145 %token RECOVERYTIME
146 %token REGEXPR
147 %token REGPROG
148 %token REMOTE_NUMBERS_HANDLING
149 %token REMOTE_PHONE_DIALOUT
150 %token REMOTE_PHONE_INCOMING
151 %token RESTRICTEDCMD
152 %token ROTATESUFFIX
153 %token RTPRIO
154 %token SYSTEM
155 %token TINAINITPROG
156 %token UNITLENGTH
157 %token UNITLENGTHSRC
158 %token USEACCTFILE
159 %token USEDOWN
160 %token USRDEVICENAME
161 %token USRDEVICEUNIT
162 %token VALID
163 %token YES
166 %token <str> NUMBERSTR
168 %token <str> STRING
170 %type <booln> boolean
172 %type <num> sysfilekeyword sysnumkeyword sysstrkeyword sysboolkeyword
173 %type <num> filekeyword numkeyword strkeyword boolkeyword monrights monright
174 %type <num> cstrkeyword cfilekeyword
175 %type <str> filename
177 %union {
178 int booln;
179 int num;
180 char *str;
185 config: sections
187 flush_config();
191 sections: possible_nullentries
192 syssect
193 optcontrollersects
194 optentrysects
197 possible_nullentries:
198 /* lambda */
199 | possible_nullentries error '\n'
200 | possible_nullentries nullentry
203 nullentry: '\n'
206 optentrysects: entrysects
210 entrysects: entrysect
211 | entrysects entrysect
214 optcontrollersects:
215 controllersects
219 controllersects: controllersect
220 | controllersects controllersect
223 /* ============== */
224 /* system section */
225 /* ============== */
227 syssect: SYSTEM sysentries
230 sysentries: sysentry
232 saw_system = 1;
233 monitor_clear_rights();
235 | sysentries sysentry
238 sysentry: sysfileentry
239 | sysboolentry
240 | sysnumentry
241 | sysstrentry
242 | sysmonitorstart
243 | sysmonitorrights
244 | nullentry
245 | error '\n'
249 sysmonitorstart:
250 MONITOR '=' STRING '\n'
252 const char *err = NULL;
253 switch (monitor_start_rights($3)) {
254 case I4BMAR_OK:
255 break;
256 case I4BMAR_LENGTH:
257 err = "local socket name too long: %s";
258 break;
259 case I4BMAR_DUP:
260 err = "duplicate entry: %s";
261 break;
262 case I4BMAR_CIDR:
263 err = "invalid CIDR specification: %s";
264 break;
265 case I4BMAR_NOIP:
266 err = "could not resolve host or net specification: %s";
267 break;
269 if (err) {
270 char msg[1024];
271 snprintf(msg, sizeof msg, err, $3);
272 yyerror(msg);
277 sysmonitorrights:
278 MONITORACCESS '=' monrights '\n'
279 { monitor_add_rights($3); }
282 monrights: monrights ',' monright { $$ = $1 | $3; }
283 | monright { $$ = $1; }
286 monright: FULLCMD { $$ = I4B_CA_COMMAND_FULL; }
287 | RESTRICTEDCMD { $$ = I4B_CA_COMMAND_RESTRICTED; }
288 | CHANNELSTATE { $$ = I4B_CA_EVNT_CHANSTATE; }
289 | CALLIN { $$ = I4B_CA_EVNT_CALLIN; }
290 | CALLOUT { $$ = I4B_CA_EVNT_CALLOUT; }
291 | LOGEVENTS { $$ = I4B_CA_EVNT_I4B; }
294 sysfileentry: sysfilekeyword '=' filename '\n'
296 cfg_setval($1);
300 sysboolentry: sysboolkeyword '=' boolean '\n'
302 yylval.booln = $3;
303 cfg_setval($1);
307 sysnumentry: sysnumkeyword '=' NUMBERSTR '\n'
309 yylval.num = atoi($3);
310 cfg_setval($1);
314 sysstrentry: sysstrkeyword '=' STRING '\n'
316 cfg_setval($1);
318 | sysstrkeyword '=' NUMBERSTR '\n'
320 cfg_setval($1);
324 filename: STRING {
325 if ($1[0] != '/')
327 yyerror("filename doesn't start with a slash");
328 YYERROR;
330 $$ = $1;
334 boolean: NO { $$ = FALSE; }
335 | OFF { $$ = FALSE; }
336 | ON { $$ = TRUE; }
337 | YES { $$ = TRUE; }
340 sysfilekeyword: RATESFILE { $$ = RATESFILE; }
341 | ACCTFILE { $$ = ACCTFILE; }
342 | ALIASFNAME { $$ = ALIASFNAME; }
343 | HOLIDAYFILE { $$ = HOLIDAYFILE; }
344 | TINAINITPROG { $$ = TINAINITPROG; }
347 sysboolkeyword: USEACCTFILE { $$ = USEACCTFILE; }
348 | ALIASING { $$ = ALIASING; }
349 | ACCTALL { $$ = ACCTALL; }
350 | BEEPCONNECT { $$ = BEEPCONNECT; }
351 | EXTCALLATTR { $$ = EXTCALLATTR; }
352 | ISDNTIME { $$ = ISDNTIME; }
353 | MONITORSW { $$ = MONITORSW; }
356 sysnumkeyword: MONITORPORT { $$ = MONITORPORT; }
357 | RTPRIO { $$ = RTPRIO; }
360 sysstrkeyword: MAILER { $$ = MAILER; }
361 | MAILTO { $$ = MAILTO; }
362 | ROTATESUFFIX { $$ = ROTATESUFFIX; }
363 | REGEXPR { $$ = REGEXPR; }
364 | REGPROG { $$ = REGPROG; }
367 /* ============= */
368 /* entry section */
369 /* ============= */
371 entrysect: ENTRY
373 init_currrent_cfg_state();
375 entries
378 entries: entry
379 | entries entry
382 entry: fileentry
383 | strentry
384 | numentry
385 | boolentry
386 | nullentry
387 | error '\n'
390 fileentry: filekeyword '=' filename '\n'
392 cfg_setval($1);
397 strentry: strkeyword '=' STRING '\n'
399 cfg_setval($1);
401 | strkeyword '=' NUMBERSTR '\n'
403 cfg_setval($1);
407 boolentry: boolkeyword '=' boolean '\n'
409 yylval.booln = $3;
410 cfg_setval($1);
414 numentry: numkeyword '=' NUMBERSTR '\n'
416 yylval.num = atoi($3);
417 cfg_setval($1);
421 filekeyword: BUDGETCALLBACKSFILE { $$ = BUDGETCALLBACKSFILE; }
422 | BUDGETCALLOUTSFILE { $$ = BUDGETCALLOUTSFILE; }
425 strkeyword: ANSWERPROG { $$ = ANSWERPROG; }
426 | B1PROTOCOL { $$ = B1PROTOCOL; }
427 | CONNECTPROG { $$ = CONNECTPROG; }
428 | DIALOUTTYPE { $$ = DIALOUTTYPE; }
429 | DIRECTION { $$ = DIRECTION; }
430 | DISCONNECTPROG { $$ = DISCONNECTPROG; }
431 | IDLE_ALG_OUT { $$ = IDLE_ALG_OUT; }
432 | LOCAL_PHONE_INCOMING { $$ = LOCAL_PHONE_INCOMING; }
433 | LOCAL_PHONE_DIALOUT { $$ = LOCAL_PHONE_DIALOUT; }
434 | NAME { $$ = NAME; }
435 | PPP_EXPECT_AUTH { $$ = PPP_EXPECT_AUTH; }
436 | PPP_EXPECT_NAME { $$ = PPP_EXPECT_NAME; }
437 | PPP_EXPECT_PASSWORD { $$ = PPP_EXPECT_PASSWORD; }
438 | PPP_SEND_AUTH { $$ = PPP_SEND_AUTH; }
439 | PPP_SEND_NAME { $$ = PPP_SEND_NAME; }
440 | PPP_SEND_PASSWORD { $$ = PPP_SEND_PASSWORD; }
441 | REACTION { $$ = REACTION; }
442 | REMOTE_NUMBERS_HANDLING { $$ = REMOTE_NUMBERS_HANDLING; }
443 | REMOTE_PHONE_INCOMING { $$ = REMOTE_PHONE_INCOMING; }
444 | REMOTE_PHONE_DIALOUT { $$ = REMOTE_PHONE_DIALOUT; }
445 | UNITLENGTHSRC { $$ = UNITLENGTHSRC; }
446 | USRDEVICENAME { $$ = USRDEVICENAME; }
447 | VALID { $$ = VALID; }
450 numkeyword: ALERT { $$ = ALERT; }
451 | BUDGETCALLBACKPERIOD { $$ = BUDGETCALLBACKPERIOD; }
452 | BUDGETCALLBACKNCALLS { $$ = BUDGETCALLBACKNCALLS; }
453 | BUDGETCALLOUTPERIOD { $$ = BUDGETCALLOUTPERIOD; }
454 | BUDGETCALLOUTNCALLS { $$ = BUDGETCALLOUTNCALLS; }
455 | CALLBACKWAIT { $$ = CALLBACKWAIT; }
456 | CALLEDBACKWAIT { $$ = CALLEDBACKWAIT; }
457 | DIALRETRIES { $$ = DIALRETRIES; }
458 | EARLYHANGUP { $$ = EARLYHANGUP; }
459 | IDLETIME_IN { $$ = IDLETIME_IN; }
460 | IDLETIME_OUT { $$ = IDLETIME_OUT; }
461 | ISDNCONTROLLER { $$ = ISDNCONTROLLER; }
462 | ISDNCHANNEL { $$ = ISDNCHANNEL; }
463 | ISDNTXDELIN { $$ = ISDNTXDELIN; }
464 | ISDNTXDELOUT { $$ = ISDNTXDELOUT; }
465 | RATETYPE { $$ = RATETYPE; }
466 | RECOVERYTIME { $$ = RECOVERYTIME; }
467 | UNITLENGTH { $$ = UNITLENGTH; }
468 | USRDEVICEUNIT { $$ = USRDEVICEUNIT; }
469 | DOWNTIME { $$ = DOWNTIME; }
470 | DOWNTRIES { $$ = DOWNTRIES; }
473 boolkeyword: AUTOUPDOWN { $$ = AUTOUPDOWN; }
474 | BUDGETCALLBACKSFILEROTATE { $$ = BUDGETCALLBACKSFILEROTATE; }
475 | BUDGETCALLOUTSFILEROTATE { $$ = BUDGETCALLOUTSFILEROTATE; }
476 | DIALRANDINCR { $$ = DIALRANDINCR; }
477 | PPP_AUTH_RECHALLENGE { $$ = PPP_AUTH_RECHALLENGE; }
478 | PPP_AUTH_PARANOID { $$ = PPP_AUTH_PARANOID; }
479 | USEDOWN { $$ = USEDOWN; }
482 /* ================== */
483 /* controller section */
484 /* ================== */
486 controllersect: CONTROLLER
488 cur_ctrl = NULL;
490 controllers
493 controllers: controller {
494 if (cur_ctrl)
495 cur_ctrl = NEXT_CTRL(cur_ctrl);
496 else
497 cur_ctrl = get_first_ctrl_state();
499 | controllers controller
502 controller: strcontroller
503 | nullentry
504 | error '\n'
507 strcontroller: cstrkeyword '=' STRING '\n'
509 cfg_setval($1);
511 | cstrkeyword '=' NUMBERSTR '\n'
513 cfg_setval($1);
515 | cfilekeyword '=' filename '\n'
517 cfg_setval($1);
521 cstrkeyword: PROTOCOL { $$ = PROTOCOL; }
524 cfilekeyword: FIRMWARE { $$ = FIRMWARE; }