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 int 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 switch (list->type & CF_MTYPE)
108 MyFree(list->v.string);
111 free_cur_list(list->v.list);
117 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 = MyMalloc(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 = MyMalloc(sizeof(conf_parm_t));
151 new->v.number = number;
155 DupString(new->v.string, 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, CF_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_MTYPE) != CF_INT ||
237 ($3->type & CF_MTYPE) != CF_INT)
239 conf_report_error("Both arguments in '..' notation must be integers.");
246 for (i = $1->v.number; i <= $3->v.number; i++)
248 add_cur_list(CF_INT, 0, i);
256 $$ = MyMalloc(sizeof(conf_parm_t));
257 $$->type = CF_QSTRING;
258 DupString($$->v.string, $1);
262 $$ = MyMalloc(sizeof(conf_parm_t));
268 $$ = MyMalloc(sizeof(conf_parm_t));
274 /* a 'string' could also be a yes/no value ..
275 so pass it as that, if so */
276 int val = conf_get_yesno_value($1);
278 $$ = MyMalloc(sizeof(conf_parm_t));
287 $$->type = CF_STRING;
288 DupString($$->v.string, $1);
296 #ifndef STATIC_MODULES
299 m_bn = irc_basename((char *) $2);
301 if (findmodule_byname(m_bn) == -1)
302 load_one_module($2, 0);
308 qstring: QSTRING { strcpy($$, $1); } ;
309 string: STRING { strcpy($$, $1); } ;
310 number: NUMBER { $$ = $1; } ;
312 timespec: number string
316 if ((t = conf_find_time($2)) == 0)
318 conf_report_error("Unrecognised time type/size '%s'", $2);