ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config.c
(Generate patch)

Comparing hopm/trunk/src/config.c (file contents):
Revision 5726 by michael, Tue Mar 24 18:04:06 2015 UTC vs.
Revision 9478 by michael, Sat Jul 4 19:03:19 2020 UTC

# Line 1 | Line 1
1   /*
2   *  Copyright (c) 2002 Erik Fears
3 < *  Copyright (c) 2014-2015 ircd-hybrid development team
3 > *  Copyright (c) 2014-2020 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
# Line 27 | Line 27
27  
28   #include "config.h"
29   #include "config-parser.h"
30 + #include "compat.h"
31   #include "memory.h"
32   #include "log.h"
33   #include "scan.h"
# Line 34 | Line 35
35   #include "opercmd.h"
36   #include "stats.h"
37   #include "firedns.h"
38 + #include "misc.h"
39  
38 extern FILE *yyin;
40  
41 < struct OptionsConf *OptionsItem = NULL;
42 < struct IRCConf *IRCItem = NULL;
43 < struct OpmConf *OpmItem = NULL;
44 < struct ExemptConf *ExemptItem = NULL;
45 < list_t *UserItemList = NULL;
46 < list_t *ScannerItemList = NULL;
41 > FILE *conf_file;
42 > struct OptionsConf OptionsItem;
43 > struct IRCConf IRCItem;
44 > struct OpmConf OpmItem;
45 > struct ExemptConf ExemptItem;
46 > list_t UserItemList;
47 > list_t ScannerItemList;
48  
49  
48 /* Malloc and initialize configuration data to NULL */
49 static void
50 config_init(void)
51 {
52  /* Init IRC block */
53  IRCItem = xcalloc(sizeof *IRCItem);
54  IRCItem->channels = list_create();
55  IRCItem->performs = list_create();
56  IRCItem->notices  = list_create();
57
58  /* Init Options block */
59  OptionsItem = xcalloc(sizeof *OptionsItem);
60
61  /* Init OPM block */
62  OpmItem = xcalloc(sizeof *OpmItem);
63  OpmItem->blacklists = list_create();
64
65  /* Init list of User blocks */
66  UserItemList = list_create();
67
68  /* Init list of Scanner blocks */
69  ScannerItemList = list_create();
70
71  /* Init list of Exempts */
72  ExemptItem = xcalloc(sizeof *ExemptItem);
73  ExemptItem->masks = list_create();
74 }
75
50   /* Setup structs that hold configuration data and then reset default values */
51   static void
52   config_setup(void)
53   {
54 <  /* Setup IRC Block Defaults */
55 <  IRCItem->mode = xstrdup("+c");
56 <  IRCItem->nick = xstrdup("hopm");
57 <  IRCItem->port = 6667;
58 <  IRCItem->readtimeout = 900;
59 <  IRCItem->oper = xstrdup("undefined");
60 <  IRCItem->username = xstrdup("hopm");
61 <  IRCItem->realname = xstrdup("Hybrid Open Proxy Monitor");
62 <  IRCItem->server = xstrdup("irc.example.org");
63 <  IRCItem->connregex = xstrdup("\\*\\*\\* Notice -- Client connecting: ([^ ]+) \\(([^@]+)@([^\\)]+)\\) \\[([0-9\\.]+)\\].*");
64 <  IRCItem->kline = xstrdup("KLINE %u@%h :Open Proxy found on your host.");
65 <
66 <  /* Setup options block defaults */
67 <  OptionsItem->negcache = 0;   /* 0 disabled negcache */
68 <  OptionsItem->negcache_rebuild = 43200;
69 <  OptionsItem->pidfile = xstrdup("hopm.pid");
70 <  OptionsItem->dns_fdlimit = 50;
71 <  OptionsItem->scanlog = NULL;
54 >  /* Setup irc {} block defaults */
55 >  IRCItem.mode = xstrdup("+c");
56 >  IRCItem.nick = xstrdup("hopm");
57 >  IRCItem.port = 6667;
58 >  IRCItem.tls = 0;
59 >  IRCItem.readtimeout = 900;
60 >  IRCItem.reconnectinterval = 30;
61 >  IRCItem.oper = xstrdup("undefined");
62 >  IRCItem.username = xstrdup("hopm");
63 >  IRCItem.realname = xstrdup("Hybrid Open Proxy Monitor");
64 >  IRCItem.server = xstrdup("irc.example.org");
65 >  IRCItem.connregex = xstrdup("\\*\\*\\* Notice -- Client connecting: ([^ ]+) \\(([^@]+)@([^\\)]+)\\) \\[([0-9a-f\\.:]+)\\].*");
66 >  IRCItem.kline = xstrdup("KLINE %u@%h :Open Proxy found on your host.");
67 >
68 >  /* Setup options {} block defaults */
69 >  OptionsItem.command_queue_size = 64;
70 >  OptionsItem.command_interval = 10;
71 >  OptionsItem.command_timeout = 180;
72 >  OptionsItem.negcache = 0;  /* 0 disabled negcache */
73 >  OptionsItem.negcache_rebuild = 43200;
74 >  OptionsItem.pidfile = xstrdup("hopm.pid");
75 >  OptionsItem.dns_fdlimit = 50;
76 >  OptionsItem.dns_timeout = 5;
77   }
78  
79   /* Load configuration from filename, via flex/bison parser */
80   void
81   config_load(const char *filename)
82   {
104  config_init();
83    config_setup();  /* Setup/clear current configuration */
84  
85    log_printf("CONFIG -> Loading %s", filename);
86  
87 <  if ((yyin = fopen(filename, "r")) == NULL)
87 >  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
88 >
89 >  conf_file = fopen(filename, "r");
90 >  if (conf_file == NULL)
91    {
92      log_printf("CONFIG -> Error opening %s: %s", filename, strerror(errno));
93      exit(EXIT_FAILURE);
94    }
95  
96    yyparse();
97 +  fclose(conf_file);
98  
99    scan_init();     /* Initialize the scanners once we have the configuration */
118  command_init();  /* Initialize the command queue */
100    stats_init();    /* Initialize stats (UPTIME) */
101    firedns_init();  /* Initialize adns */
121
122  fclose(yyin);
102   }
103  
104   void
105   yyerror(const char *str)
106   {
107 <  log_printf("CONFIG -> %s: line %d", str, linenum);
107 >  log_printf("CONFIG -> \"%s\", line %u: %s: %s", conffilebuf, lineno, str, stripws(linebuf));
108    exit(EXIT_FAILURE);
109   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)