ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/branches/1.0.x/src/config-parser.y
Revision: 5427
Committed: Wed Jan 28 13:51:01 2015 UTC (10 years, 6 months ago) by michael
File size: 13948 byte(s)
Log Message:
- memory.c:MyFree(): removed extraneous pointer test; renamed MyFree to xfree

File Contents

# Content
1 /*
2 * Copyright (c) 2002-2003 Erik Fears
3 * Copyright (c) 2014-2015 ircd-hybrid development team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 */
20
21 %{
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "memory.h"
26 #include "config.h"
27
28 int yylex(void);
29
30 int yydebug=0;
31 void *tmp; /* Variable to temporarily hold nodes before insertion to list */
32
33 %}
34
35 %token AWAY
36 %token BAN_UNKNOWN
37 %token BLACKLIST
38 %token BYTES KBYTES MBYTES
39 %token CHANNEL
40 %token CONNREGEX
41 %token DNS_FDLIMIT
42 %token DNSBL_FROM
43 %token DNSBL_TO
44 %token EXEMPT
45 %token FD
46 %token INVITE
47 %token IRC
48 %token KLINE
49 %token KEY
50 %token MASK
51 %token MAX_READ
52 %token MODE
53 %token NAME
54 %token NEGCACHE
55 %token NEGCACHE_REBUILD
56 %token NICK
57 %token NICKSERV
58 %token NOTICE
59 %token OPER
60 %token OPM
61 %token OPTIONS
62 %token PASSWORD
63 %token PERFORM
64 %token PIDFILE
65 %token PORT
66 %token PROTOCOL
67 %token READTIMEOUT
68 %token REALNAME
69 %token REPLY
70 %token SCANLOG
71 %token SCANNER
72 %token SECONDS MINUTES HOURS DAYS WEEKS MONTHS YEARS
73 %token SENDMAIL
74 %token SERVER
75 %token TARGET_IP
76 %token TARGET_PORT
77 %token TARGET_STRING
78 %token TIMEOUT
79 %token TYPE
80 %token USERNAME
81 %token USER
82 %token VHOST
83
84 %union
85 {
86 int number;
87 char *string;
88 }
89
90 %token <number> NUMBER
91 %token <string> STRING
92 %token <number> PROTOCOLTYPE
93 %type <number> timespec
94 %type <number> timespec_
95 %type <number> sizespec
96 %type <number> sizespec_
97
98 %%
99
100 config:
101 | config config_items
102 ;
103
104 config_items: irc_entry |
105 options_entry |
106 opm_entry |
107 user_entry |
108 scanner_entry |
109 exempt_entry;
110
111 timespec_: { $$ = 0; } | timespec;
112 timespec: NUMBER timespec_ { $$ = $1 + $2; } |
113 NUMBER SECONDS timespec_ { $$ = $1 + $3; } |
114 NUMBER MINUTES timespec_ { $$ = $1 * 60 + $3; } |
115 NUMBER HOURS timespec_ { $$ = $1 * 60 * 60 + $3; } |
116 NUMBER DAYS timespec_ { $$ = $1 * 60 * 60 * 24 + $3; } |
117 NUMBER WEEKS timespec_ { $$ = $1 * 60 * 60 * 24 * 7 + $3; } |
118 NUMBER MONTHS timespec_ { $$ = $1 * 60 * 60 * 24 * 7 * 4 + $3; } |
119 NUMBER YEARS timespec_ { $$ = $1 * 60 * 60 * 24 * 365 + $3; }
120 ;
121
122 sizespec_: { $$ = 0; } | sizespec;
123 sizespec: NUMBER sizespec_ { $$ = $1 + $2; } |
124 NUMBER BYTES sizespec_ { $$ = $1 + $3; } |
125 NUMBER KBYTES sizespec_ { $$ = $1 * 1024 + $3; } |
126 NUMBER MBYTES sizespec_ { $$ = $1 * 1024 * 1024 + $3; }
127 ;
128
129 /*************************** OPTIONS BLOCK ***********************/
130
131 options_entry: OPTIONS '{' options_items '}' ';';
132
133 options_items: options_items options_item |
134 options_item;
135
136 options_item: options_negcache |
137 options_negcache_rebuild |
138 options_pidfile |
139 options_dns_fdlimit |
140 options_scanlog |
141 error;
142
143 options_negcache: NEGCACHE '=' timespec ';'
144 {
145 OptionsItem->negcache = $3;
146 };
147
148 options_negcache_rebuild: NEGCACHE_REBUILD '=' timespec ';'
149 {
150 OptionsItem->negcache_rebuild = $3;
151 };
152
153 options_pidfile: PIDFILE '=' STRING ';'
154 {
155 xfree(OptionsItem->pidfile);
156 OptionsItem->pidfile = xstrdup($3);
157 };
158
159 options_dns_fdlimit: DNS_FDLIMIT '=' NUMBER ';'
160 {
161 OptionsItem->dns_fdlimit = $3;
162 };
163
164 options_scanlog: SCANLOG '=' STRING ';'
165 {
166 xfree(OptionsItem->scanlog);
167 OptionsItem->scanlog = xstrdup($3);
168 };
169
170 /*************************** IRC BLOCK ***************************/
171
172 irc_entry: IRC '{' irc_items '}' ';';
173
174 irc_items: irc_items irc_item |
175 irc_item;
176
177 irc_item: irc_away |
178 irc_connregex |
179 irc_kline |
180 irc_nick |
181 irc_nickserv |
182 irc_mode |
183 irc_oper |
184 irc_password |
185 irc_port |
186 irc_readtimeout |
187 irc_realname |
188 irc_server |
189 irc_username |
190 irc_vhost |
191 irc_perform |
192 irc_notice |
193 channel_entry |
194 error;
195
196 irc_away: AWAY '=' STRING ';'
197 {
198 xfree(IRCItem->away);
199 IRCItem->away = xstrdup($3);
200 };
201
202 irc_kline: KLINE '=' STRING ';'
203 {
204 xfree(IRCItem->kline);
205 IRCItem->kline = xstrdup($3);
206 };
207
208 irc_mode: MODE '=' STRING ';'
209 {
210 xfree(IRCItem->mode);
211 IRCItem->mode = xstrdup($3);
212 };
213
214 irc_nick: NICK '=' STRING ';'
215 {
216 xfree(IRCItem->nick);
217 IRCItem->nick = xstrdup($3);
218 };
219
220 irc_nickserv: NICKSERV '=' STRING ';'
221 {
222 xfree(IRCItem->nickserv);
223 IRCItem->nickserv = xstrdup($3);
224 };
225
226 irc_oper: OPER '=' STRING ';'
227 {
228 xfree(IRCItem->oper);
229 IRCItem->oper = xstrdup($3);
230 };
231
232 irc_password: PASSWORD '=' STRING ';'
233 {
234 xfree(IRCItem->password);
235 IRCItem->password = xstrdup($3);
236 };
237
238 irc_perform: PERFORM '=' STRING ';'
239 {
240 node_t *node;
241 node = node_create(xstrdup($3));
242
243 list_add(IRCItem->performs, node);
244 };
245
246 irc_notice: NOTICE '=' STRING ';'
247 {
248 node_t *node;
249 node = node_create(xstrdup($3));
250
251 list_add(IRCItem->notices, node);
252 };
253
254 irc_port: PORT '=' NUMBER ';'
255 {
256 IRCItem->port = $3;
257 };
258
259 irc_readtimeout: READTIMEOUT '=' timespec ';'
260 {
261 IRCItem->readtimeout = $3;
262 };
263
264 irc_realname: REALNAME '=' STRING ';'
265 {
266 xfree(IRCItem->realname);
267 IRCItem->realname = xstrdup($3);
268 };
269
270 irc_server: SERVER '=' STRING ';'
271 {
272 xfree(IRCItem->server);
273 IRCItem->server = xstrdup($3);
274 };
275
276 irc_username: USERNAME '=' STRING ';'
277 {
278 xfree(IRCItem->username);
279 IRCItem->username = xstrdup($3);
280 };
281
282 irc_vhost: VHOST '=' STRING ';'
283 {
284 xfree(IRCItem->vhost);
285 IRCItem->vhost = xstrdup($3);
286 };
287
288 irc_connregex: CONNREGEX '=' STRING ';'
289 {
290 xfree(IRCItem->connregex);
291 IRCItem->connregex = xstrdup($3);
292 };
293
294
295 /************************** CHANNEL BLOCK *************************/
296
297 channel_entry:
298 {
299 node_t *node;
300 struct ChannelConf *item;
301
302 item = xcalloc(sizeof *item);
303
304 item->name = xstrdup("");
305 item->key = xstrdup("");
306 item->invite = xstrdup("");
307
308 node = node_create(item);
309 list_add(IRCItem->channels, node);
310
311 tmp = item;
312 }
313 CHANNEL '{' channel_items '}' ';';
314
315 channel_items: channel_items channel_item |
316 channel_item;
317
318 channel_item: channel_name |
319 channel_key |
320 channel_invite;
321
322 channel_name: NAME '=' STRING ';'
323 {
324 struct ChannelConf *item = tmp;
325
326 xfree(item->name);
327 item->name = xstrdup($3);
328 };
329
330 channel_key: KEY '=' STRING ';'
331 {
332 struct ChannelConf *item = tmp;
333
334 xfree(item->key);
335 item->key = xstrdup($3);
336 };
337
338 channel_invite: INVITE '=' STRING ';'
339 {
340 struct ChannelConf *item = tmp;
341
342 xfree(item->invite);
343 item->invite = xstrdup($3);
344 };
345
346 /*************************** USER BLOCK ***************************/
347
348 user_entry:
349 {
350 node_t *node;
351 struct UserConf *item;
352
353 item = xcalloc(sizeof *item);
354
355 item->masks = list_create();
356 item->scanners = list_create();
357
358 node = node_create(item);
359 list_add(UserItemList, node);
360
361 tmp = item;
362 }
363 USER '{' user_items '}' ';' ;
364
365 user_items: user_items user_item |
366 user_item;
367
368 user_item: user_mask |
369 user_scanner |
370 error;
371
372 user_mask: MASK '=' STRING ';'
373 {
374 struct UserConf *item = tmp;
375 node_t *node;
376
377 node = node_create(xstrdup($3));
378
379 list_add(item->masks, node);
380 };
381
382 user_scanner: SCANNER '=' STRING ';'
383 {
384 struct UserConf *item = tmp;
385 node_t *node;
386
387 node = node_create(xstrdup($3));
388
389 list_add(item->scanners, node);
390 };
391
392 /*************************** SCANNER BLOCK ***************************/
393
394 scanner_entry:
395 {
396 node_t *node;
397 struct ScannerConf *item, *olditem;
398
399 item = xcalloc(sizeof *item);
400
401 /* Setup ScannerConf defaults */
402 item->name = xstrdup("undefined");
403
404 if(LIST_SIZE(ScannerItemList) > 0)
405 {
406 olditem = ScannerItemList->tail->data;
407
408 item->vhost = xstrdup(olditem->vhost);
409 item->fd = olditem->fd;
410 item->target_ip = xstrdup(olditem->target_ip);
411 item->target_port = olditem->target_port;
412 item->timeout = olditem->timeout;
413 item->max_read = olditem->max_read;
414
415 item->target_string = olditem->target_string;
416 item->target_string_created = 0;
417 }
418 else
419 {
420 item->vhost = xstrdup("0.0.0.0");
421 item->fd = 512;
422 item->target_ip = xstrdup("127.0.0.1");
423 item->target_port = 6667;
424 item->timeout = 30;
425 item->max_read = 4096;
426
427 item->target_string = list_create();
428 item->target_string_created = 1;
429 }
430
431 item->protocols = list_create();
432
433 node = node_create(item);
434
435 list_add(ScannerItemList, node);
436 tmp = item;
437 }
438 SCANNER '{' scanner_items '}' ';' ;
439
440 scanner_items: scanner_items scanner_item |
441 scanner_item;
442
443 scanner_item: scanner_name |
444 scanner_vhost |
445 scanner_fd |
446 scanner_target_ip |
447 scanner_target_port |
448 scanner_target_string |
449 scanner_protocol |
450 scanner_timeout |
451 scanner_max_read |
452 error;
453
454 scanner_name: NAME '=' STRING ';'
455 {
456 struct ScannerConf *item = tmp;
457 xfree(item->name);
458 item->name = xstrdup($3);
459 };
460
461 scanner_vhost: VHOST '=' STRING ';'
462 {
463 struct ScannerConf *item = tmp;
464 xfree(item->vhost);
465 item->vhost = xstrdup($3);
466 };
467
468 scanner_target_ip: TARGET_IP '=' STRING ';'
469 {
470 struct ScannerConf *item = tmp;
471 xfree(item->target_ip);
472 item->target_ip = xstrdup($3);
473 };
474
475 scanner_target_string: TARGET_STRING '=' STRING ';'
476 {
477 struct ScannerConf *item = tmp;
478
479 node_t *node;
480 node = node_create($3);
481
482 if(item->target_string_created == 0)
483 {
484 item->target_string = list_create();
485 item->target_string_created = 1;
486 }
487
488 list_add(item->target_string, node);
489 };
490
491 scanner_fd: FD '=' NUMBER ';'
492 {
493 struct ScannerConf *item = tmp;
494 item->fd = $3;
495 };
496
497 scanner_target_port: TARGET_PORT '=' NUMBER ';'
498 {
499 struct ScannerConf *item = tmp;
500 item->target_port = $3;
501 };
502
503 scanner_timeout: TIMEOUT '=' timespec ';'
504 {
505 struct ScannerConf *item = tmp;
506 item->timeout = $3;
507 };
508
509 scanner_max_read: MAX_READ '=' sizespec ';'
510 {
511 struct ScannerConf *item = tmp;
512 item->max_read = $3;
513 };
514
515 scanner_protocol: PROTOCOL '=' PROTOCOLTYPE ':' NUMBER ';'
516 {
517 struct ProtocolConf *item;
518 struct ScannerConf *item2;
519
520 node_t *node;
521
522 item = xcalloc(sizeof *item);
523 item->type = $3;
524 item->port = $5;
525
526 item2 = tmp;
527
528 node = node_create(item);
529 list_add(item2->protocols, node);
530 };
531
532 /*************************** OPM BLOCK ***************************/
533
534 opm_entry: OPM '{' opm_items '}' ';' ;
535
536 opm_items: opm_items opm_item |
537 opm_item;
538
539 opm_item: opm_dnsbl_from |
540 opm_dnsbl_to |
541 opm_sendmail |
542 opm_blacklist_entry |
543 error;
544
545 opm_dnsbl_from: DNSBL_FROM '=' STRING ';'
546 {
547 xfree(OpmItem->dnsbl_from);
548 OpmItem->dnsbl_from = xstrdup($3);
549 };
550
551 opm_dnsbl_to: DNSBL_TO '=' STRING ';'
552 {
553 xfree(OpmItem->dnsbl_to);
554 OpmItem->dnsbl_to = xstrdup($3);
555 };
556
557 opm_sendmail: SENDMAIL '=' STRING ';'
558 {
559 xfree(OpmItem->sendmail);
560 OpmItem->sendmail = xstrdup($3);
561 };
562
563 /************************** BLACKLIST BLOCK *************************/
564
565 opm_blacklist_entry:
566 {
567 node_t *node;
568 struct BlacklistConf *item;
569
570 item = xcalloc(sizeof *item);
571
572 item->name = xstrdup("");
573 item->kline = xstrdup("");
574 item->ban_unknown = 0;
575 item->type = A_BITMASK;
576 item->reply = list_create();
577
578 node = node_create(item);
579 list_add(OpmItem->blacklists, node);
580
581 tmp = item;
582 }
583 BLACKLIST '{' blacklist_items '}' ';';
584
585 blacklist_items: blacklist_items blacklist_item |
586 blacklist_item;
587
588 blacklist_item: blacklist_name |
589 blacklist_type |
590 blacklist_kline |
591 blacklist_ban_unknown |
592 blacklist_reply |
593 error;
594
595 blacklist_name: NAME '=' STRING ';' {
596 struct BlacklistConf *item = tmp;
597
598 xfree(item->name);
599 item->name = xstrdup($3);
600 };
601
602 blacklist_kline: KLINE '=' STRING ';' {
603 struct BlacklistConf *item = tmp;
604
605 xfree(item->kline);
606 item->kline = xstrdup($3);
607 };
608
609 blacklist_type: TYPE '=' STRING ';' {
610 struct BlacklistConf *item = tmp;
611
612 if(strcmp("A record bitmask", $3) == 0)
613 item->type = A_BITMASK;
614 else if(strcmp("A record reply", $3) == 0)
615 item->type = A_REPLY;
616 else
617 yyerror("Unknown blacklist type defined");
618 };
619
620 blacklist_ban_unknown: BAN_UNKNOWN '=' NUMBER ';' {
621 struct BlacklistConf *item = tmp;
622
623 item->ban_unknown = $3;
624 };
625
626 blacklist_reply: REPLY '{' blacklist_reply_items '}' ';';
627
628 blacklist_reply_items: blacklist_reply_items blacklist_reply_item |
629 blacklist_reply_item;
630
631 blacklist_reply_item: NUMBER '=' STRING ';'
632 {
633 struct BlacklistReplyConf *item;
634 struct BlacklistConf *blacklist = tmp;
635 node_t *node;
636
637 item = xcalloc(sizeof *item);
638
639 item->number = $1;
640 item->type = xstrdup($3);
641
642 node = node_create(item);
643 list_add(blacklist->reply, node);
644 };
645
646 /*************************** EXEMPT BLOCK ***************************/
647
648
649 exempt_entry: EXEMPT '{' exempt_items '}' ';' ;
650
651 exempt_items: exempt_items exempt_item |
652 exempt_item;
653
654 exempt_item: exempt_mask |
655 error;
656
657 exempt_mask: MASK '=' STRING ';'
658 {
659 node_t *node;
660 node = node_create(xstrdup($3));
661
662 list_add(ExemptItem->masks, node);
663 };
664
665 %%

Properties

Name Value
svn:eol-style native
svn:keywords Id