2007-01-25 07:40:21 +01:00
|
|
|
/* This code is in the public domain.
|
|
|
|
* $Nightmare: nightmare/src/main/parser.y,v 1.2.2.1.2.1 2002/07/02 03:42:10 ejb Exp $
|
|
|
|
*/
|
|
|
|
|
|
|
|
%{
|
2016-07-16 23:40:52 +02:00
|
|
|
#define YY_NO_UNPUT
|
|
|
|
|
|
|
|
int yylex();
|
2016-08-13 05:05:54 +02:00
|
|
|
|
|
|
|
namespace ircd {
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
static time_t conf_find_time(char*);
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const char * name;
|
|
|
|
const char * plural;
|
2014-02-28 15:51:52 +01:00
|
|
|
time_t val;
|
2007-01-25 07:40:21 +01:00
|
|
|
} ircd_times[] = {
|
|
|
|
{"second", "seconds", 1},
|
|
|
|
{"minute", "minutes", 60},
|
|
|
|
{"hour", "hours", 60 * 60},
|
|
|
|
{"day", "days", 60 * 60 * 24},
|
|
|
|
{"week", "weeks", 60 * 60 * 24 * 7},
|
|
|
|
{"fortnight", "fortnights", 60 * 60 * 24 * 14},
|
|
|
|
{"month", "months", 60 * 60 * 24 * 7 * 4},
|
|
|
|
{"year", "years", 60 * 60 * 24 * 365},
|
2014-02-28 15:51:52 +01:00
|
|
|
/* ok-- we now do sizes here too. they aren't times, but
|
2007-01-25 07:40:21 +01:00
|
|
|
it's close enough */
|
|
|
|
{"byte", "bytes", 1},
|
|
|
|
{"kb", NULL, 1024},
|
|
|
|
{"kbyte", "kbytes", 1024},
|
|
|
|
{"kilobyte", "kilebytes", 1024},
|
|
|
|
{"mb", NULL, 1024 * 1024},
|
|
|
|
{"mbyte", "mbytes", 1024 * 1024},
|
|
|
|
{"megabyte", "megabytes", 1024 * 1024},
|
|
|
|
{NULL, NULL, 0},
|
|
|
|
};
|
|
|
|
|
|
|
|
time_t conf_find_time(char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; ircd_times[i].name; i++)
|
|
|
|
{
|
2016-04-05 12:39:59 +02:00
|
|
|
if (rb_strcasecmp(ircd_times[i].name, name) == 0 ||
|
|
|
|
(ircd_times[i].plural && rb_strcasecmp(ircd_times[i].plural, name) == 0))
|
2007-01-25 07:40:21 +01:00
|
|
|
return ircd_times[i].val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const char *word;
|
|
|
|
int yesno;
|
|
|
|
} yesno[] = {
|
|
|
|
{"yes", 1},
|
|
|
|
{"no", 0},
|
|
|
|
{"true", 1},
|
|
|
|
{"false", 0},
|
|
|
|
{"on", 1},
|
|
|
|
{"off", 0},
|
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int conf_get_yesno_value(char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; yesno[i].word; i++)
|
|
|
|
{
|
2016-04-05 12:39:59 +02:00
|
|
|
if (rb_strcasecmp(str, yesno[i].word) == 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
return yesno[i].yesno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_cur_list(conf_parm_t* list)
|
|
|
|
{
|
2014-02-28 08:02:49 +01:00
|
|
|
if (list->type == CF_STRING || list->type == CF_QSTRING) {
|
|
|
|
rb_free(list->v.string);
|
|
|
|
} else if (list->type == CF_FLIST) {
|
|
|
|
/* Even though CF_FLIST is a flag, comparing with == is valid
|
|
|
|
* because conf_parm_t.type must be either a type or one flag.
|
|
|
|
*/
|
|
|
|
free_cur_list(list->v.list);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2014-02-28 08:02:49 +01:00
|
|
|
if (list->next) {
|
2007-01-25 07:40:21 +01:00
|
|
|
free_cur_list(list->next);
|
2014-02-28 08:02:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rb_free(list);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2014-02-28 15:51:52 +01:00
|
|
|
|
2016-07-16 23:40:52 +02:00
|
|
|
conf_parm_t * cur_list;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-07-16 23:40:52 +02:00
|
|
|
static void add_cur_list_cpt(conf_parm_t *new_)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if (cur_list == NULL)
|
|
|
|
{
|
2016-07-16 23:40:52 +02:00
|
|
|
cur_list = (conf_parm_t *)rb_malloc(sizeof(conf_parm_t));
|
2014-02-28 08:02:49 +01:00
|
|
|
cur_list->type = CF_FLIST;
|
2016-07-16 23:40:52 +02:00
|
|
|
cur_list->v.list = new_;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-16 23:40:52 +02:00
|
|
|
new_->next = cur_list->v.list;
|
|
|
|
cur_list->v.list = new_;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_cur_list(int type, char *str, int number)
|
|
|
|
{
|
2016-07-16 23:40:52 +02:00
|
|
|
conf_parm_t *new_;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-07-16 23:40:52 +02:00
|
|
|
new_ = (conf_parm_t *)rb_malloc(sizeof(conf_parm_t));
|
|
|
|
new_->next = NULL;
|
|
|
|
new_->type = type;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case CF_INT:
|
|
|
|
case CF_TIME:
|
|
|
|
case CF_YESNO:
|
2016-07-16 23:40:52 +02:00
|
|
|
new_->v.number = number;
|
2007-01-25 07:40:21 +01:00
|
|
|
break;
|
|
|
|
case CF_STRING:
|
|
|
|
case CF_QSTRING:
|
2016-07-16 23:40:52 +02:00
|
|
|
new_->v.string = rb_strdup(str);
|
2007-01-25 07:40:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-07-16 23:40:52 +02:00
|
|
|
add_cur_list_cpt(new_);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
} // namespace ircd
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%union {
|
2014-02-28 15:51:52 +01:00
|
|
|
int number;
|
2016-05-15 02:57:16 +02:00
|
|
|
char string[1024];
|
2016-08-13 05:05:54 +02:00
|
|
|
ircd::conf_parm_t * conf_parm;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
%token LOADMODULE TWODOTS
|
|
|
|
|
|
|
|
%token <string> QSTRING STRING
|
|
|
|
%token <number> NUMBER
|
|
|
|
|
|
|
|
%type <string> qstring string
|
2014-02-28 15:51:52 +01:00
|
|
|
%type <number> number timespec
|
2007-01-25 07:40:21 +01:00
|
|
|
%type <conf_parm> oneitem single itemlist
|
|
|
|
|
|
|
|
%start conf
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2014-02-28 15:51:52 +01:00
|
|
|
conf:
|
|
|
|
| conf conf_item
|
2007-01-25 07:40:21 +01:00
|
|
|
| error
|
|
|
|
;
|
|
|
|
|
|
|
|
conf_item: block
|
|
|
|
| loadmodule
|
|
|
|
;
|
|
|
|
|
2014-02-28 15:51:52 +01:00
|
|
|
block: string
|
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
ircd::conf_start_block($1, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2014-02-28 15:51:52 +01:00
|
|
|
'{' block_items '}' ';'
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
if (ircd::conf_cur_block)
|
|
|
|
ircd::conf_end_block(ircd::conf_cur_block);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2014-02-28 15:51:52 +01:00
|
|
|
| string qstring
|
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
ircd::conf_start_block($1, $2);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
'{' block_items '}' ';'
|
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
if (ircd::conf_cur_block)
|
|
|
|
ircd::conf_end_block(ircd::conf_cur_block);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-28 15:51:52 +01:00
|
|
|
block_items: block_items block_item
|
|
|
|
| block_item
|
2007-01-25 07:40:21 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
block_item: string '=' itemlist ';'
|
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
ircd::conf_call_set(ircd::conf_cur_block, $1, ircd::cur_list);
|
|
|
|
ircd::free_cur_list(ircd::cur_list);
|
|
|
|
ircd::cur_list = NULL;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
itemlist: itemlist ',' single
|
|
|
|
| single
|
|
|
|
;
|
|
|
|
|
|
|
|
single: oneitem
|
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
ircd::add_cur_list_cpt($1);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
| oneitem TWODOTS oneitem
|
|
|
|
{
|
|
|
|
/* "1 .. 5" meaning 1,2,3,4,5 - only valid for integers */
|
2014-02-28 08:02:49 +01:00
|
|
|
if ($1->type != CF_INT || $3->type != CF_INT)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
ircd::conf_report_error("Both arguments in '..' notation must be integers.");
|
2007-01-25 07:40:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = $1->v.number; i <= $3->v.number; i++)
|
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
ircd::add_cur_list(CF_INT, 0, i);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
oneitem: qstring
|
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
$$ = (ircd::conf_parm_t *)rb_malloc(sizeof(ircd::conf_parm_t));
|
2007-01-25 07:40:21 +01:00
|
|
|
$$->type = CF_QSTRING;
|
2008-04-02 01:26:34 +02:00
|
|
|
$$->v.string = rb_strdup($1);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
| timespec
|
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
$$ = (ircd::conf_parm_t *)rb_malloc(sizeof(ircd::conf_parm_t));
|
2007-01-25 07:40:21 +01:00
|
|
|
$$->type = CF_TIME;
|
|
|
|
$$->v.number = $1;
|
|
|
|
}
|
|
|
|
| number
|
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
$$ = (ircd::conf_parm_t *)rb_malloc(sizeof(ircd::conf_parm_t));
|
2007-01-25 07:40:21 +01:00
|
|
|
$$->type = CF_INT;
|
|
|
|
$$->v.number = $1;
|
|
|
|
}
|
|
|
|
| string
|
|
|
|
{
|
2014-02-28 15:51:52 +01:00
|
|
|
/* a 'string' could also be a yes/no value ..
|
2007-01-25 07:40:21 +01:00
|
|
|
so pass it as that, if so */
|
2016-08-13 05:05:54 +02:00
|
|
|
int val = ircd::conf_get_yesno_value($1);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
$$ = (ircd::conf_parm_t *)rb_malloc(sizeof(ircd::conf_parm_t));
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if (val != -1)
|
|
|
|
{
|
|
|
|
$$->type = CF_YESNO;
|
|
|
|
$$->v.number = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$$->type = CF_STRING;
|
2008-04-02 01:26:34 +02:00
|
|
|
$$->v.string = rb_strdup($1);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
loadmodule:
|
|
|
|
LOADMODULE QSTRING
|
|
|
|
{
|
2016-03-07 01:56:45 +01:00
|
|
|
char *m_bn;
|
|
|
|
m_bn = rb_basename((char *) $2);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
if (ircd::findmodule_byname(m_bn) == NULL)
|
2016-03-07 01:56:45 +01:00
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
ircd::load_one_module($2, MAPI_ORIGIN_EXTENSION, 0);
|
2016-03-07 01:56:45 +01:00
|
|
|
}
|
2014-03-02 23:05:30 +01:00
|
|
|
|
2016-03-07 01:56:45 +01:00
|
|
|
rb_free(m_bn);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
';'
|
|
|
|
;
|
|
|
|
|
|
|
|
qstring: QSTRING { strcpy($$, $1); } ;
|
|
|
|
string: STRING { strcpy($$, $1); } ;
|
|
|
|
number: NUMBER { $$ = $1; } ;
|
|
|
|
|
|
|
|
timespec: number string
|
2014-02-28 15:51:52 +01:00
|
|
|
{
|
2007-01-25 07:40:21 +01:00
|
|
|
time_t t;
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
if ((t = ircd::conf_find_time($2)) == 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-13 05:05:54 +02:00
|
|
|
ircd::conf_report_error("Unrecognised time type/size '%s'", $2);
|
2007-01-25 07:40:21 +01:00
|
|
|
t = 1;
|
|
|
|
}
|
2014-02-28 15:51:52 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
$$ = $1 * t;
|
|
|
|
}
|
|
|
|
| timespec timespec
|
|
|
|
{
|
|
|
|
$$ = $1 + $2;
|
|
|
|
}
|
|
|
|
| timespec number
|
|
|
|
{
|
|
|
|
$$ = $1 + $2;
|
|
|
|
}
|
|
|
|
;
|