ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config-parser.y
Revision: 5333
Committed: Wed Jan 7 20:45:06 2015 UTC (11 years, 6 months ago) by michael
File size: 13759 byte(s)
Log Message:
- Move malloc.c to memory.c

File Contents

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

Properties

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