ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config-parser.y
Revision: 5650
Committed: Sun Mar 8 13:34:55 2015 UTC (10 years, 5 months ago) by michael
File size: 13791 byte(s)
Log Message:
- config-parser.y: style corrections

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
242 node = node_create(xstrdup($3));
243 list_add(IRCItem->performs, node);
244 };
245
246 irc_notice: NOTICE '=' STRING ';'
247 {
248 node_t *node;
249
250 node = node_create(xstrdup($3));
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 item->name = xstrdup("");
304 item->key = xstrdup("");
305 item->invite = xstrdup("");
306
307 node = node_create(item);
308
309 list_add(IRCItem->channels, node);
310 tmp = item;
311 }
312 CHANNEL '{' channel_items '}' ';';
313
314 channel_items: channel_items channel_item |
315 channel_item;
316
317 channel_item: channel_name |
318 channel_key |
319 channel_invite;
320
321 channel_name: NAME '=' STRING ';'
322 {
323 struct ChannelConf *item = tmp;
324
325 xfree(item->name);
326 item->name = xstrdup($3);
327 };
328
329 channel_key: KEY '=' STRING ';'
330 {
331 struct ChannelConf *item = tmp;
332
333 xfree(item->key);
334 item->key = xstrdup($3);
335 };
336
337 channel_invite: INVITE '=' STRING ';'
338 {
339 struct ChannelConf *item = tmp;
340
341 xfree(item->invite);
342 item->invite = xstrdup($3);
343 };
344
345 /*************************** USER BLOCK ***************************/
346
347 user_entry:
348 {
349 node_t *node;
350 struct UserConf *item;
351
352 item = xcalloc(sizeof *item);
353 item->masks = list_create();
354 item->scanners = list_create();
355
356 node = node_create(item);
357
358 list_add(UserItemList, node);
359 tmp = item;
360 }
361 USER '{' user_items '}' ';' ;
362
363 user_items: user_items user_item |
364 user_item;
365
366 user_item: user_mask |
367 user_scanner |
368 error;
369
370 user_mask: MASK '=' STRING ';'
371 {
372 struct UserConf *item = tmp;
373 node_t *node;
374
375 node = node_create(xstrdup($3));
376
377 list_add(item->masks, node);
378 };
379
380 user_scanner: SCANNER '=' STRING ';'
381 {
382 struct UserConf *item = tmp;
383 node_t *node;
384
385 node = node_create(xstrdup($3));
386
387 list_add(item->scanners, node);
388 };
389
390 /*************************** SCANNER BLOCK ***************************/
391
392 scanner_entry:
393 {
394 node_t *node;
395 struct ScannerConf *item, *olditem;
396
397 item = xcalloc(sizeof *item);
398
399 /* Setup ScannerConf defaults */
400 item->name = xstrdup("undefined");
401
402 if (LIST_SIZE(ScannerItemList) > 0)
403 {
404 olditem = ScannerItemList->tail->data;
405
406 item->vhost = xstrdup(olditem->vhost);
407 item->fd = olditem->fd;
408 item->target_ip = xstrdup(olditem->target_ip);
409 item->target_port = olditem->target_port;
410 item->timeout = olditem->timeout;
411 item->max_read = olditem->max_read;
412 item->target_string = olditem->target_string;
413 item->target_string_created = 0;
414 }
415 else
416 {
417 item->vhost = xstrdup("0.0.0.0");
418 item->fd = 512;
419 item->target_ip = xstrdup("127.0.0.1");
420 item->target_port = 6667;
421 item->timeout = 30;
422 item->max_read = 4096;
423 item->target_string = list_create();
424 item->target_string_created = 1;
425 }
426
427 item->protocols = list_create();
428
429 node = node_create(item);
430
431 list_add(ScannerItemList, node);
432 tmp = item;
433 }
434 SCANNER '{' scanner_items '}' ';' ;
435
436 scanner_items: scanner_items scanner_item |
437 scanner_item;
438
439 scanner_item: scanner_name |
440 scanner_vhost |
441 scanner_fd |
442 scanner_target_ip |
443 scanner_target_port |
444 scanner_target_string |
445 scanner_protocol |
446 scanner_timeout |
447 scanner_max_read |
448 error;
449
450 scanner_name: NAME '=' STRING ';'
451 {
452 struct ScannerConf *item = tmp;
453
454 xfree(item->name);
455 item->name = xstrdup($3);
456 };
457
458 scanner_vhost: VHOST '=' STRING ';'
459 {
460 struct ScannerConf *item = tmp;
461
462 xfree(item->vhost);
463 item->vhost = xstrdup($3);
464 };
465
466 scanner_target_ip: TARGET_IP '=' STRING ';'
467 {
468 struct ScannerConf *item = tmp;
469
470 xfree(item->target_ip);
471 item->target_ip = xstrdup($3);
472 };
473
474 scanner_target_string: TARGET_STRING '=' STRING ';'
475 {
476 struct ScannerConf *item = tmp;
477 node_t *node;
478
479 node = node_create($3);
480
481 if (item->target_string_created == 0)
482 {
483 item->target_string = list_create();
484 item->target_string_created = 1;
485 }
486
487 list_add(item->target_string, node);
488 };
489
490 scanner_fd: FD '=' NUMBER ';'
491 {
492 struct ScannerConf *item = tmp;
493
494 item->fd = $3;
495 };
496
497 scanner_target_port: TARGET_PORT '=' NUMBER ';'
498 {
499 struct ScannerConf *item = tmp;
500
501 item->target_port = $3;
502 };
503
504 scanner_timeout: TIMEOUT '=' timespec ';'
505 {
506 struct ScannerConf *item = tmp;
507
508 item->timeout = $3;
509 };
510
511 scanner_max_read: MAX_READ '=' sizespec ';'
512 {
513 struct ScannerConf *item = tmp;
514
515 item->max_read = $3;
516 };
517
518 scanner_protocol: PROTOCOL '=' PROTOCOLTYPE ':' NUMBER ';'
519 {
520 struct ProtocolConf *item;
521 struct ScannerConf *item2;
522
523 node_t *node;
524
525 item = xcalloc(sizeof *item);
526 item->type = $3;
527 item->port = $5;
528
529 item2 = tmp;
530
531 node = node_create(item);
532 list_add(item2->protocols, node);
533 };
534
535 /*************************** OPM BLOCK ***************************/
536
537 opm_entry: OPM '{' opm_items '}' ';' ;
538
539 opm_items: opm_items opm_item |
540 opm_item;
541
542 opm_item: opm_dnsbl_from |
543 opm_dnsbl_to |
544 opm_sendmail |
545 opm_blacklist_entry |
546 error;
547
548 opm_dnsbl_from: DNSBL_FROM '=' STRING ';'
549 {
550 xfree(OpmItem->dnsbl_from);
551 OpmItem->dnsbl_from = xstrdup($3);
552 };
553
554 opm_dnsbl_to: DNSBL_TO '=' STRING ';'
555 {
556 xfree(OpmItem->dnsbl_to);
557 OpmItem->dnsbl_to = xstrdup($3);
558 };
559
560 opm_sendmail: SENDMAIL '=' STRING ';'
561 {
562 xfree(OpmItem->sendmail);
563 OpmItem->sendmail = xstrdup($3);
564 };
565
566 /************************** BLACKLIST BLOCK *************************/
567
568 opm_blacklist_entry:
569 {
570 node_t *node;
571 struct BlacklistConf *item;
572
573 item = xcalloc(sizeof *item);
574
575 item->name = xstrdup("");
576 item->kline = xstrdup("");
577 item->ban_unknown = 0;
578 item->type = A_BITMASK;
579 item->reply = list_create();
580
581 node = node_create(item);
582 list_add(OpmItem->blacklists, node);
583
584 tmp = item;
585 }
586 BLACKLIST '{' blacklist_items '}' ';';
587
588 blacklist_items: blacklist_items blacklist_item |
589 blacklist_item;
590
591 blacklist_item: blacklist_name |
592 blacklist_type |
593 blacklist_kline |
594 blacklist_ban_unknown |
595 blacklist_reply |
596 error;
597
598 blacklist_name: NAME '=' STRING ';'
599 {
600 struct BlacklistConf *item = tmp;
601
602 xfree(item->name);
603 item->name = xstrdup($3);
604 };
605
606 blacklist_kline: KLINE '=' STRING ';'
607 {
608 struct BlacklistConf *item = tmp;
609
610 xfree(item->kline);
611 item->kline = xstrdup($3);
612 };
613
614 blacklist_type: TYPE '=' STRING ';'
615 {
616 struct BlacklistConf *item = tmp;
617
618 if (strcmp("A record bitmask", $3) == 0)
619 item->type = A_BITMASK;
620 else if (strcmp("A record reply", $3) == 0)
621 item->type = A_REPLY;
622 else
623 yyerror("Unknown blacklist type defined");
624 };
625
626 blacklist_ban_unknown: BAN_UNKNOWN '=' NUMBER ';'
627 {
628 struct BlacklistConf *item = tmp;
629
630 item->ban_unknown = $3;
631 };
632
633 blacklist_reply: REPLY '{' blacklist_reply_items '}' ';';
634
635 blacklist_reply_items: blacklist_reply_items blacklist_reply_item |
636 blacklist_reply_item;
637
638 blacklist_reply_item: NUMBER '=' STRING ';'
639 {
640 struct BlacklistReplyConf *item;
641 struct BlacklistConf *blacklist = tmp;
642 node_t *node;
643
644 item = xcalloc(sizeof *item);
645
646 item->number = $1;
647 item->type = xstrdup($3);
648
649 node = node_create(item);
650 list_add(blacklist->reply, node);
651 };
652
653 /*************************** EXEMPT BLOCK ***************************/
654
655
656 exempt_entry: EXEMPT '{' exempt_items '}' ';' ;
657
658 exempt_items: exempt_items exempt_item |
659 exempt_item;
660
661 exempt_item: exempt_mask |
662 error;
663
664 exempt_mask: MASK '=' STRING ';'
665 {
666 node_t *node;
667 node = node_create(xstrdup($3));
668
669 list_add(ExemptItem->masks, node);
670 };
671
672 %%

Properties

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