Restore stats_spy hook that was removed in commit 401f2454671ca233e35b0e6e4f3fa4c43cd...
[seven-1.x.git] / src / ircd_parser.y
blob788be741605f571619e862591931082aa5c9bbc8
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 */
5 %{
6 #include <sys/types.h>
7 #include <sys/stat.h>
9 #include <netinet/in.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
14 #include <stdio.h>
15 #define WE_ARE_MEMORY_C
16 #include "stdinc.h"
17 #include "setup.h"
18 #include "common.h"
19 #include "ircd_defs.h"
20 #include "config.h"
21 #include "client.h"
22 #include "modules.h"
23 #include "newconf.h"
25 #define YY_NO_UNPUT
27 int yyparse();
28 int yyerror(const char *);
29 int yylex();
31 static time_t conf_find_time(char*);
33 static struct {
34 const char * name;
35 const char * plural;
36 time_t val;
37 } ircd_times[] = {
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
47 it's close enough */
48 {"byte", "bytes", 1},
49 {"kb", NULL, 1024},
50 {"kbyte", "kbytes", 1024},
51 {"kilobyte", "kilebytes", 1024},
52 {"mb", NULL, 1024 * 1024},
53 {"mbyte", "mbytes", 1024 * 1024},
54 {"megabyte", "megabytes", 1024 * 1024},
55 {NULL, NULL, 0},
58 time_t conf_find_time(char *name)
60 int i;
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;
69 return 0;
72 static struct
74 const char *word;
75 int yesno;
76 } yesno[] = {
77 {"yes", 1},
78 {"no", 0},
79 {"true", 1},
80 {"false", 0},
81 {"on", 1},
82 {"off", 0},
83 {NULL, 0}
86 static int conf_get_yesno_value(char *str)
88 int i;
90 for (i = 0; yesno[i].word; i++)
92 if (strcasecmp(str, yesno[i].word) == 0)
94 return yesno[i].yesno;
98 return -1;
101 static void free_cur_list(conf_parm_t* list)
103 switch (list->type & CF_MTYPE)
105 case CF_STRING:
106 case CF_QSTRING:
107 MyFree(list->v.string);
108 break;
109 case CF_LIST:
110 free_cur_list(list->v.list);
111 break;
112 default: break;
115 if (list->next)
116 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 = MyMalloc(sizeof(conf_parm_t));
127 cur_list->type |= CF_FLIST;
128 cur_list->v.list = new;
130 else
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)
139 conf_parm_t *new;
141 new = MyMalloc(sizeof(conf_parm_t));
142 new->next = NULL;
143 new->type = type;
145 switch(type)
147 case CF_INT:
148 case CF_TIME:
149 case CF_YESNO:
150 new->v.number = number;
151 break;
152 case CF_STRING:
153 case CF_QSTRING:
154 DupString(new->v.string, str);
155 break;
158 add_cur_list_cpt(new);
164 %union {
165 int number;
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
179 %start conf
183 conf:
184 | conf conf_item
185 | error
188 conf_item: block
189 | loadmodule
192 block: string
194 conf_start_block($1, NULL);
196 '{' block_items '}' ';'
198 if (conf_cur_block)
199 conf_end_block(conf_cur_block);
201 | string qstring
203 conf_start_block($1, $2);
205 '{' block_items '}' ';'
207 if (conf_cur_block)
208 conf_end_block(conf_cur_block);
212 block_items: block_items block_item
213 | block_item
216 block_item: string '=' itemlist ';'
218 conf_call_set(conf_cur_block, $1, cur_list, CF_LIST);
219 free_cur_list(cur_list);
220 cur_list = NULL;
224 itemlist: itemlist ',' single
225 | single
228 single: oneitem
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_MTYPE) != CF_INT ||
236 ($3->type & CF_MTYPE) != CF_INT)
238 conf_report_error("Both arguments in '..' notation must be integers.");
239 break;
241 else
243 int i;
245 for (i = $1->v.number; i <= $3->v.number; i++)
247 add_cur_list(CF_INT, 0, i);
253 oneitem: qstring
255 $$ = MyMalloc(sizeof(conf_parm_t));
256 $$->type = CF_QSTRING;
257 DupString($$->v.string, $1);
259 | timespec
261 $$ = MyMalloc(sizeof(conf_parm_t));
262 $$->type = CF_TIME;
263 $$->v.number = $1;
265 | number
267 $$ = MyMalloc(sizeof(conf_parm_t));
268 $$->type = CF_INT;
269 $$->v.number = $1;
271 | string
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 $$ = MyMalloc(sizeof(conf_parm_t));
279 if (val != -1)
281 $$->type = CF_YESNO;
282 $$->v.number = val;
284 else
286 $$->type = CF_STRING;
287 DupString($$->v.string, $1);
292 loadmodule:
293 LOADMODULE QSTRING
295 #ifndef STATIC_MODULES
296 char *m_bn;
298 m_bn = irc_basename((char *) $2);
300 if (findmodule_byname(m_bn) == -1)
301 load_one_module($2, 0);
302 #endif
307 qstring: QSTRING { strcpy($$, $1); } ;
308 string: STRING { strcpy($$, $1); } ;
309 number: NUMBER { $$ = $1; } ;
311 timespec: number string
313 time_t t;
315 if ((t = conf_find_time($2)) == 0)
317 conf_report_error("Unrecognised time type/size '%s'", $2);
318 t = 1;
321 $$ = $1 * t;
323 | timespec timespec
325 $$ = $1 + $2;
327 | timespec number
329 $$ = $1 + $2;