freebsd-nq/usr.sbin/i4b/isdnd/rc_parse.y

540 lines
12 KiB
Plaintext
Raw Normal View History

/*
* Copyright (c) 1997 Joerg Wunsch. All rights reserved.
*
* Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*---------------------------------------------------------------------------
*
* i4b daemon - runtime configuration parser
* -----------------------------------------
*
1999-12-14 21:14:28 +00:00
* $FreeBSD$
*
* last edit-date: [Sun Aug 11 12:27:28 2002]
*
*---------------------------------------------------------------------------*/
%{
/* #define YYDEBUG 1 */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "monitor.h" /* monitor access rights bit definitions */
#include "isdnd.h"
#ifndef FALSE
# define FALSE 0
#endif
#ifndef TRUE
# define TRUE 1
#endif
extern void cfg_setval(int keyword);
1999-12-14 21:14:28 +00:00
extern void cfg_set_controller_default();
extern void reset_scanner(FILE *infile);
extern void yyerror(const char *msg);
extern int yylex();
extern int lineno;
extern char *yytext;
extern int nentries;
int saw_system = 0;
int entrycount = -1;
1999-12-14 21:14:28 +00:00
int controllercount = -1;
%}
%token ACCTALL
%token ACCTFILE
%token ADDPREFIX
%token ALERT
%token ALIASFNAME
1999-08-06 14:05:10 +00:00
%token ALIASING
%token ANSWERPROG
%token B1PROTOCOL
%token BEEPCONNECT
%token BCAP
2000-10-09 14:22:51 +00:00
%token BUDGETCALLOUTPERIOD
%token BUDGETCALLOUTNCALLS
%token BUDGETCALLOUTSFILE
%token BUDGETCALLOUTSFILEROTATE
%token BUDGETCALLBACKPERIOD
%token BUDGETCALLBACKNCALLS
%token BUDGETCALLBACKSFILE
%token BUDGETCALLBACKSFILEROTATE
%token CALLBACKWAIT
%token CALLEDBACKWAIT
1999-08-06 14:05:10 +00:00
%token CALLIN
%token CALLOUT
%token CHANNELSTATE
%token CLONE
%token CONNECTPROG
1999-12-14 21:14:28 +00:00
%token CONTROLLER
%token DIALOUTTYPE
1999-08-06 14:05:10 +00:00
%token DIALRANDINCR
%token DIALRETRIES
%token DIRECTION
%token DISCONNECTPROG
%token DOWNTIME
1999-08-06 14:05:10 +00:00
%token DOWNTRIES
%token EARLYHANGUP
%token ENTRY
2000-10-09 14:22:51 +00:00
%token EXTCALLATTR
%token FIRMWARE
1999-08-06 14:05:10 +00:00
%token FULLCMD
2000-10-09 14:22:51 +00:00
%token HOLIDAYFILE
%token IDLETIME_IN
%token IDLETIME_OUT
%token IDLE_ALG_OUT
%token ISDNCHANNEL
1999-08-06 14:05:10 +00:00
%token ISDNCONTROLLER
%token ISDNTIME
%token ISDNTXDELIN
%token ISDNTXDELOUT
%token LOCAL_PHONE_DIALOUT
%token LOCAL_SUBADDR_DIALOUT
%token LOCAL_PHONE_INCOMING
%token LOCAL_SUBADDR_INCOMING
1999-08-06 14:05:10 +00:00
%token LOGEVENTS
1999-12-14 21:14:28 +00:00
%token MAILER
%token MAILTO
%token MAXCONNECTTIME
%token MONITOR
%token MONITORACCESS
1999-08-06 14:05:10 +00:00
%token MONITORPORT
%token MONITORSW
%token NAME
%token NO
%token OFF
%token ON
2000-10-09 14:22:51 +00:00
%token PPP_AUTH_RECHALLENGE
%token PPP_AUTH_PARANOID
%token PPP_EXPECT_AUTH
%token PPP_EXPECT_NAME
%token PPP_EXPECT_PASSWORD
%token PPP_SEND_AUTH
%token PPP_SEND_NAME
%token PPP_SEND_PASSWORD
%token PREFIXNATIONAL
%token PREFIXINTERNATIONAL
1999-12-14 21:14:28 +00:00
%token PROTOCOL
%token RATESFILE
1999-08-06 14:05:10 +00:00
%token RATETYPE
%token REACTION
%token RECOVERYTIME
%token REGEXPR
%token REGPROG
1999-08-06 14:05:10 +00:00
%token REMOTE_NUMBERS_HANDLING
%token REMOTE_PHONE_DIALOUT
%token REMOTE_SUBADDR_DIALOUT
1999-08-06 14:05:10 +00:00
%token REMOTE_PHONE_INCOMING
%token REMOTE_SUBADDR_INCOMING
1999-08-06 14:05:10 +00:00
%token RESTRICTEDCMD
%token ROTATESUFFIX
%token RTPRIO
%token SYSTEM
%token TINAINITPROG
%token UNITLENGTH
%token UNITLENGTHSRC
%token USEACCTFILE
%token USESUBADDR
1999-08-06 14:05:10 +00:00
%token USEDOWN
%token USRDEVICENAME
%token USRDEVICEUNIT
2000-10-09 14:22:51 +00:00
%token VALID
%token YES
1999-08-06 14:05:10 +00:00
%token <str> NUMBERSTR
%token <str> STRING
%type <booln> boolean
%type <num> sysfilekeyword sysnumkeyword sysstrkeyword sysboolkeyword
2000-10-09 14:22:51 +00:00
%type <num> filekeyword numkeyword strkeyword boolkeyword monrights monright
%type <num> cstrkeyword cfilekeyword
%type <str> filename
%union {
int booln;
int num;
char *str;
}
%%
config: sections
;
sections: possible_nullentries
syssect
1999-12-14 21:14:28 +00:00
optcontrollersects
entrysects
;
possible_nullentries:
/* lambda */
| possible_nullentries error '\n'
| possible_nullentries nullentry
;
nullentry: '\n'
;
entrysects: entrysect
| entrysects entrysect
;
1999-12-14 21:14:28 +00:00
optcontrollersects:
controllersects
|
{
cfg_set_controller_default();
}
;
controllersects: controllersect
| controllersects controllersect
;
/* ============== */
/* system section */
/* ============== */
syssect: SYSTEM sysentries
;
sysentries: sysentry
{
saw_system = 1;
monitor_clear_rights();
}
| sysentries sysentry
;
sysentry: sysfileentry
| sysboolentry
| sysnumentry
| sysstrentry
| sysmonitorstart
| sysmonitorrights
| nullentry
| error '\n'
;
sysmonitorstart:
MONITOR '=' STRING '\n'
{
char *err = NULL;
switch (monitor_start_rights($3)) {
case I4BMAR_OK:
break;
case I4BMAR_LENGTH:
err = "local socket name too long: %s";
break;
case I4BMAR_DUP:
err = "duplicate entry: %s";
break;
case I4BMAR_CIDR:
err = "invalid CIDR specification: %s";
break;
case I4BMAR_NOIP:
err = "could not resolve host or net specification: %s";
break;
}
if (err) {
char msg[1024];
snprintf(msg, sizeof msg, err, $3);
yyerror(msg);
}
}
;
sysmonitorrights:
MONITORACCESS '=' monrights '\n'
{ monitor_add_rights($3); }
;
monrights: monrights ',' monright { $$ = $1 | $3; }
| monright { $$ = $1; }
;
monright: FULLCMD { $$ = I4B_CA_COMMAND_FULL; }
| RESTRICTEDCMD { $$ = I4B_CA_COMMAND_RESTRICTED; }
| CHANNELSTATE { $$ = I4B_CA_EVNT_CHANSTATE; }
| CALLIN { $$ = I4B_CA_EVNT_CALLIN; }
| CALLOUT { $$ = I4B_CA_EVNT_CALLOUT; }
| LOGEVENTS { $$ = I4B_CA_EVNT_I4B; }
;
sysfileentry: sysfilekeyword '=' filename '\n'
{
cfg_setval($1);
}
;
sysboolentry: sysboolkeyword '=' boolean '\n'
{
yylval.booln = $3;
cfg_setval($1);
}
;
sysnumentry: sysnumkeyword '=' NUMBERSTR '\n'
{
yylval.num = atoi($3);
cfg_setval($1);
}
;
sysstrentry: sysstrkeyword '=' STRING '\n'
{
cfg_setval($1);
}
| sysstrkeyword '=' NUMBERSTR '\n'
{
cfg_setval($1);
}
;
filename: STRING {
if ($1[0] != '/')
{
yyerror("filename doesn't start with a slash");
YYERROR;
}
$$ = $1;
}
;
boolean: NO { $$ = FALSE; }
| OFF { $$ = FALSE; }
| ON { $$ = TRUE; }
| YES { $$ = TRUE; }
;
sysfilekeyword: RATESFILE { $$ = RATESFILE; }
| ACCTFILE { $$ = ACCTFILE; }
| ALIASFNAME { $$ = ALIASFNAME; }
2000-10-09 14:22:51 +00:00
| HOLIDAYFILE { $$ = HOLIDAYFILE; }
| TINAINITPROG { $$ = TINAINITPROG; }
;
sysboolkeyword: USEACCTFILE { $$ = USEACCTFILE; }
| ALIASING { $$ = ALIASING; }
| ACCTALL { $$ = ACCTALL; }
| ADDPREFIX { $$ = ADDPREFIX; }
| BEEPCONNECT { $$ = BEEPCONNECT; }
2000-10-09 14:22:51 +00:00
| EXTCALLATTR { $$ = EXTCALLATTR; }
| ISDNTIME { $$ = ISDNTIME; }
| MONITORSW { $$ = MONITORSW; }
;
sysnumkeyword: MONITORPORT { $$ = MONITORPORT; }
| RTPRIO { $$ = RTPRIO; }
;
1999-12-14 21:14:28 +00:00
sysstrkeyword: MAILER { $$ = MAILER; }
| MAILTO { $$ = MAILTO; }
| PREFIXNATIONAL { $$ = PREFIXNATIONAL; }
| PREFIXINTERNATIONAL { $$ = PREFIXINTERNATIONAL; }
1999-12-14 21:14:28 +00:00
| ROTATESUFFIX { $$ = ROTATESUFFIX; }
1999-08-06 14:05:10 +00:00
| REGEXPR { $$ = REGEXPR; }
| REGPROG { $$ = REGPROG; }
;
1999-12-14 21:14:28 +00:00
/* ============= */
/* entry section */
/* ============= */
entrysect: ENTRY
{
entrycount++;
nentries++;
}
entries
;
entries: entry
| entries entry
;
2000-10-09 14:22:51 +00:00
entry: fileentry
| strentry
| numentry
| boolentry
| nullentry
| error '\n'
;
2000-10-09 14:22:51 +00:00
fileentry: filekeyword '=' filename '\n'
{
cfg_setval($1);
}
;
strentry: strkeyword '=' STRING '\n'
{
cfg_setval($1);
}
| strkeyword '=' NUMBERSTR '\n'
{
cfg_setval($1);
}
;
boolentry: boolkeyword '=' boolean '\n'
{
yylval.booln = $3;
cfg_setval($1);
}
;
numentry: numkeyword '=' NUMBERSTR '\n'
{
yylval.num = atoi($3);
cfg_setval($1);
}
;
2000-10-09 14:22:51 +00:00
filekeyword: BUDGETCALLBACKSFILE { $$ = BUDGETCALLBACKSFILE; }
| BUDGETCALLOUTSFILE { $$ = BUDGETCALLOUTSFILE; }
;
strkeyword: ANSWERPROG { $$ = ANSWERPROG; }
| B1PROTOCOL { $$ = B1PROTOCOL; }
| BCAP { $$ = BCAP; }
| CONNECTPROG { $$ = CONNECTPROG; }
| DIALOUTTYPE { $$ = DIALOUTTYPE; }
| DIRECTION { $$ = DIRECTION; }
| DISCONNECTPROG { $$ = DISCONNECTPROG; }
| IDLE_ALG_OUT { $$ = IDLE_ALG_OUT; }
| LOCAL_PHONE_INCOMING { $$ = LOCAL_PHONE_INCOMING; }
| LOCAL_SUBADDR_INCOMING { $$ = LOCAL_SUBADDR_INCOMING; }
| LOCAL_PHONE_DIALOUT { $$ = LOCAL_PHONE_DIALOUT; }
| LOCAL_SUBADDR_DIALOUT { $$ = LOCAL_SUBADDR_DIALOUT; }
| NAME { $$ = NAME; }
2000-10-09 14:22:51 +00:00
| PPP_EXPECT_AUTH { $$ = PPP_EXPECT_AUTH; }
| PPP_EXPECT_NAME { $$ = PPP_EXPECT_NAME; }
| PPP_EXPECT_PASSWORD { $$ = PPP_EXPECT_PASSWORD; }
| PPP_SEND_AUTH { $$ = PPP_SEND_AUTH; }
| PPP_SEND_NAME { $$ = PPP_SEND_NAME; }
| PPP_SEND_PASSWORD { $$ = PPP_SEND_PASSWORD; }
| REACTION { $$ = REACTION; }
| REMOTE_NUMBERS_HANDLING { $$ = REMOTE_NUMBERS_HANDLING; }
| REMOTE_PHONE_INCOMING { $$ = REMOTE_PHONE_INCOMING; }
| REMOTE_SUBADDR_INCOMING { $$ = REMOTE_SUBADDR_INCOMING; }
| REMOTE_PHONE_DIALOUT { $$ = REMOTE_PHONE_DIALOUT; }
| REMOTE_SUBADDR_DIALOUT { $$ = REMOTE_SUBADDR_DIALOUT; }
| UNITLENGTHSRC { $$ = UNITLENGTHSRC; }
| USRDEVICENAME { $$ = USRDEVICENAME; }
2000-10-09 14:22:51 +00:00
| VALID { $$ = VALID; }
| CLONE { $$ = CLONE; }
;
numkeyword: ALERT { $$ = ALERT; }
2000-10-09 14:22:51 +00:00
| BUDGETCALLBACKPERIOD { $$ = BUDGETCALLBACKPERIOD; }
| BUDGETCALLBACKNCALLS { $$ = BUDGETCALLBACKNCALLS; }
| BUDGETCALLOUTPERIOD { $$ = BUDGETCALLOUTPERIOD; }
| BUDGETCALLOUTNCALLS { $$ = BUDGETCALLOUTNCALLS; }
| CALLBACKWAIT { $$ = CALLBACKWAIT; }
| CALLEDBACKWAIT { $$ = CALLEDBACKWAIT; }
| DIALRETRIES { $$ = DIALRETRIES; }
| EARLYHANGUP { $$ = EARLYHANGUP; }
| IDLETIME_IN { $$ = IDLETIME_IN; }
| IDLETIME_OUT { $$ = IDLETIME_OUT; }
| ISDNCONTROLLER { $$ = ISDNCONTROLLER; }
| ISDNCHANNEL { $$ = ISDNCHANNEL; }
| ISDNTXDELIN { $$ = ISDNTXDELIN; }
| ISDNTXDELOUT { $$ = ISDNTXDELOUT; }
| RATETYPE { $$ = RATETYPE; }
| RECOVERYTIME { $$ = RECOVERYTIME; }
| UNITLENGTH { $$ = UNITLENGTH; }
| USRDEVICEUNIT { $$ = USRDEVICEUNIT; }
| DOWNTIME { $$ = DOWNTIME; }
| DOWNTRIES { $$ = DOWNTRIES; }
| MAXCONNECTTIME { $$ = MAXCONNECTTIME; }
;
2000-10-09 14:22:51 +00:00
boolkeyword: BUDGETCALLBACKSFILEROTATE { $$ = BUDGETCALLBACKSFILEROTATE; }
| BUDGETCALLOUTSFILEROTATE { $$ = BUDGETCALLOUTSFILEROTATE; }
| DIALRANDINCR { $$ = DIALRANDINCR; }
| PPP_AUTH_RECHALLENGE { $$ = PPP_AUTH_RECHALLENGE; }
| PPP_AUTH_PARANOID { $$ = PPP_AUTH_PARANOID; }
| USEDOWN { $$ = USEDOWN; }
| USESUBADDR { $$ = USESUBADDR; }
;
1999-12-14 21:14:28 +00:00
/* ================== */
/* controller section */
/* ================== */
controllersect: CONTROLLER
{
controllercount++;
}
controllers
;
controllers: controller
| controllers controller
;
controller: strcontroller
| nullentry
| error '\n'
;
strcontroller: cstrkeyword '=' STRING '\n'
{
cfg_setval($1);
}
| cstrkeyword '=' NUMBERSTR '\n'
{
cfg_setval($1);
}
| cfilekeyword '=' filename '\n'
{
cfg_setval($1);
}
1999-12-14 21:14:28 +00:00
;
cstrkeyword: PROTOCOL { $$ = PROTOCOL; }
;
cfilekeyword: FIRMWARE { $$ = FIRMWARE; }
;
1999-12-14 21:14:28 +00:00
%%