1 /* This code is in the public domain.
2 * $Nightmare: nightmare/src/main/parser.y,v 1.2.2.1.2.1 2002/07/02 03:42:10 ejb Exp $
9 #include <netinet/in.h>
15 #define WE_ARE_MEMORY_C
19 #include "ircd_defs.h"
28 void yyerror(const char *);
31 static time_t conf_find_time(char*);
38 {"second", "seconds", 1},
39 {"minute", "minutes", 60},
40 {"hour", "hours", 60 * 60},
41 {"day", "days", 60 * 60 * 24},
42 {"week", "weeks", 60 * 60 * 24 * 7},
43 {"fortnight", "fortnights", 60 * 60 * 24 * 14},
44 {"month", "months", 60 * 60 * 24 * 7 * 4},
45 {"year", "years", 60 * 60 * 24 * 365},
46 /* ok-- we now do sizes here too. they aren't times, but
50 {"kbyte", "kbytes", 1024},
51 {"kilobyte", "kilebytes", 1024},
52 {"mb", NULL, 1024 * 1024},
53 {"mbyte", "mbytes", 1024 * 1024},
54 {"megabyte", "megabytes", 1024 * 1024},
58 time_t conf_find_time(char *name)
62 for (i = 0; ircd_times[i].name; i++)
64 if (strcasecmp(ircd_times[i].name, name) == 0 ||
65 (ircd_times[i].plural && strcasecmp(ircd_times[i].plural, name) == 0))
66 return ircd_times[i].val;
86 static int conf_get_yesno_value(char *str)
90 for (i = 0; yesno[i].word; i++)
92 if (strcasecmp(str, yesno[i].word) == 0)
94 return yesno[i].yesno;
101 static void free_cur_list(conf_parm_t* list)
103 if (list->type == CF_STRING || list->type == CF_QSTRING) {
104 rb_free(list->v.string);
105 } else if (list->type == CF_FLIST) {
106 /* Even though CF_FLIST is a flag, comparing with == is valid
107 * because conf_parm_t.type must be either a type or one flag.
109 free_cur_list(list->v.list);
113 free_cur_list(list->next);
120 conf_parm_t * cur_list = NULL;
122 static void add_cur_list_cpt(conf_parm_t *new)
124 if (cur_list == NULL)
126 cur_list = rb_malloc(sizeof(conf_parm_t));
127 cur_list->type = CF_FLIST;
128 cur_list->v.list = new;
132 new->next = cur_list->v.list;
133 cur_list->v.list = new;
137 static void add_cur_list(int type, char *str, int number)
141 new = rb_malloc(sizeof(conf_parm_t));
150 new->v.number = number;
154 new->v.string = rb_strdup(str);
158 add_cur_list_cpt(new);
166 char string[IRCD_BUFSIZE + 1];
167 conf_parm_t * conf_parm;
170 %token LOADMODULE TWODOTS
172 %token <string> QSTRING STRING
173 %token <number> NUMBER
175 %type <string> qstring string
176 %type <number> number timespec
177 %type <conf_parm> oneitem single itemlist
194 conf_start_block($1, NULL);
196 '{' block_items '}' ';'
199 conf_end_block(conf_cur_block);
203 conf_start_block($1, $2);
205 '{' block_items '}' ';'
208 conf_end_block(conf_cur_block);
212 block_items: block_items block_item
216 block_item: string '=' itemlist ';'
218 conf_call_set(conf_cur_block, $1, cur_list);
219 free_cur_list(cur_list);
224 itemlist: itemlist ',' single
230 add_cur_list_cpt($1);
232 | oneitem TWODOTS oneitem
234 /* "1 .. 5" meaning 1,2,3,4,5 - only valid for integers */
235 if ($1->type != CF_INT || $3->type != CF_INT)
237 conf_report_error("Both arguments in '..' notation must be integers.");
244 for (i = $1->v.number; i <= $3->v.number; i++)
246 add_cur_list(CF_INT, 0, i);
254 $$ = rb_malloc(sizeof(conf_parm_t));
255 $$->type = CF_QSTRING;
256 $$->v.string = rb_strdup($1);
260 $$ = rb_malloc(sizeof(conf_parm_t));
266 $$ = rb_malloc(sizeof(conf_parm_t));
272 /* a 'string' could also be a yes/no value ..
273 so pass it as that, if so */
274 int val = conf_get_yesno_value($1);
276 $$ = rb_malloc(sizeof(conf_parm_t));
285 $$->type = CF_STRING;
286 $$->v.string = rb_strdup($1);
295 m_bn = rb_basename((char *) $2);
297 if (findmodule_byname(m_bn) == -1)
299 load_one_module($2, MAPI_ORIGIN_EXTENSION, 0);
307 qstring: QSTRING { strcpy($$, $1); } ;
308 string: STRING { strcpy($$, $1); } ;
309 number: NUMBER { $$ = $1; } ;
311 timespec: number string
315 if ((t = conf_find_time($2)) == 0)
317 conf_report_error("Unrecognised time type/size '%s'", $2);