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 $
3 * $Id: ircd_parser.y 871 2006-02-18 21:56:00Z nenolod $
10 #include <netinet/in.h>
16 #define WE_ARE_MEMORY_C
20 #include "ircd_defs.h"
29 void yyerror(const char *);
32 static time_t conf_find_time(char*);
39 {"second", "seconds", 1},
40 {"minute", "minutes", 60},
41 {"hour", "hours", 60 * 60},
42 {"day", "days", 60 * 60 * 24},
43 {"week", "weeks", 60 * 60 * 24 * 7},
44 {"fortnight", "fortnights", 60 * 60 * 24 * 14},
45 {"month", "months", 60 * 60 * 24 * 7 * 4},
46 {"year", "years", 60 * 60 * 24 * 365},
47 /* ok-- we now do sizes here too. they aren't times, but
51 {"kbyte", "kbytes", 1024},
52 {"kilobyte", "kilebytes", 1024},
53 {"mb", NULL, 1024 * 1024},
54 {"mbyte", "mbytes", 1024 * 1024},
55 {"megabyte", "megabytes", 1024 * 1024},
59 time_t conf_find_time(char *name)
63 for (i = 0; ircd_times[i].name; i++)
65 if (strcasecmp(ircd_times[i].name, name) == 0 ||
66 (ircd_times[i].plural && strcasecmp(ircd_times[i].plural, name) == 0))
67 return ircd_times[i].val;
87 static int conf_get_yesno_value(char *str)
91 for (i = 0; yesno[i].word; i++)
93 if (strcasecmp(str, yesno[i].word) == 0)
95 return yesno[i].yesno;
102 static void free_cur_list(conf_parm_t* list)
104 if (list->type == CF_STRING || list->type == CF_QSTRING) {
105 rb_free(list->v.string);
106 } else if (list->type == CF_FLIST) {
107 /* Even though CF_FLIST is a flag, comparing with == is valid
108 * because conf_parm_t.type must be either a type or one flag.
110 free_cur_list(list->v.list);
114 free_cur_list(list->next);
121 conf_parm_t * cur_list = NULL;
123 static void add_cur_list_cpt(conf_parm_t *new)
125 if (cur_list == NULL)
127 cur_list = rb_malloc(sizeof(conf_parm_t));
128 cur_list->type = CF_FLIST;
129 cur_list->v.list = new;
133 new->next = cur_list->v.list;
134 cur_list->v.list = new;
138 static void add_cur_list(int type, char *str, int number)
142 new = rb_malloc(sizeof(conf_parm_t));
151 new->v.number = number;
155 new->v.string = rb_strdup(str);
159 add_cur_list_cpt(new);
167 char string[IRCD_BUFSIZE + 1];
168 conf_parm_t * conf_parm;
171 %token LOADMODULE TWODOTS
173 %token <string> QSTRING STRING
174 %token <number> NUMBER
176 %type <string> qstring string
177 %type <number> number timespec
178 %type <conf_parm> oneitem single itemlist
195 conf_start_block($1, NULL);
197 '{' block_items '}' ';'
200 conf_end_block(conf_cur_block);
204 conf_start_block($1, $2);
206 '{' block_items '}' ';'
209 conf_end_block(conf_cur_block);
213 block_items: block_items block_item
217 block_item: string '=' itemlist ';'
219 conf_call_set(conf_cur_block, $1, cur_list);
220 free_cur_list(cur_list);
225 itemlist: itemlist ',' single
231 add_cur_list_cpt($1);
233 | oneitem TWODOTS oneitem
235 /* "1 .. 5" meaning 1,2,3,4,5 - only valid for integers */
236 if ($1->type != CF_INT || $3->type != CF_INT)
238 conf_report_error("Both arguments in '..' notation must be integers.");
245 for (i = $1->v.number; i <= $3->v.number; i++)
247 add_cur_list(CF_INT, 0, i);
255 $$ = rb_malloc(sizeof(conf_parm_t));
256 $$->type = CF_QSTRING;
257 $$->v.string = rb_strdup($1);
261 $$ = rb_malloc(sizeof(conf_parm_t));
267 $$ = rb_malloc(sizeof(conf_parm_t));
273 /* a 'string' could also be a yes/no value ..
274 so pass it as that, if so */
275 int val = conf_get_yesno_value($1);
277 $$ = rb_malloc(sizeof(conf_parm_t));
286 $$->type = CF_STRING;
287 $$->v.string = rb_strdup($1);
297 m_bn = rb_basename((char *) $2);
299 if (findmodule_byname(m_bn) == -1)
300 load_one_module($2, 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);