ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config-parser.y
Revision: 5351
Committed: Sun Jan 11 13:24:19 2015 UTC (11 years, 6 months ago) by michael
File size: 13800 byte(s)
Log Message:
- Update license headers

File Contents

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

Properties

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