ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config.c
Revision: 5335
Committed: Wed Jan 7 21:10:33 2015 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 3602 byte(s)
Log Message:
- Fix up header inclusion mess

File Contents

# User Rev Content
1 michael 5052 /*
2     * Copyright (C) 2002 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     #include "setup.h"
25    
26     #include <stdio.h>
27 michael 5254 #include <errno.h>
28 michael 5216 #include <string.h>
29 michael 5335 #include <stdlib.h>
30 michael 5052
31     #include "config.h"
32 michael 5270 #include "config-parser.h"
33 michael 5333 #include "memory.h"
34 michael 5052 #include "log.h"
35     #include "scan.h"
36     #include "irc.h"
37     #include "opercmd.h"
38     #include "stats.h"
39     #include "firedns.h"
40    
41     extern FILE *yyin;
42    
43     struct OptionsConf *OptionsItem = NULL;
44     struct IRCConf *IRCItem = NULL;
45     struct OpmConf *OpmItem = NULL;
46     struct ExemptConf *ExemptItem = NULL;
47     list_t *UserItemList = NULL;
48     list_t *ScannerItemList = NULL;
49    
50    
51     /* Malloc and initialize configuration data to NULL */
52 michael 5114 void
53     config_init(void)
54 michael 5052 {
55 michael 5114 /* Init IRC block */
56 michael 5274 IRCItem = xcalloc(sizeof *IRCItem);
57 michael 5114 IRCItem->channels = list_create();
58     IRCItem->performs = list_create();
59 michael 5052
60 michael 5114 /* Init Options block */
61 michael 5274 OptionsItem = xcalloc(sizeof *OptionsItem);
62 michael 5052
63 michael 5114 /* Init OPM block */
64 michael 5274 OpmItem = xcalloc(sizeof *OpmItem);
65 michael 5114 OpmItem->blacklists = list_create();
66 michael 5052
67 michael 5114 /* Init list of User blocks */
68     UserItemList = list_create();
69 michael 5052
70 michael 5114 /* Init list of Scanner blocks */
71     ScannerItemList = list_create();
72 michael 5052
73 michael 5114 /* Init list of Exempts */
74 michael 5274 ExemptItem = xcalloc(sizeof *ExemptItem);
75 michael 5114 ExemptItem->masks = list_create();
76 michael 5052 }
77    
78     /* Setup structs that hold configuration data and then reset default values */
79 michael 5114 void
80     config_setup(void)
81 michael 5052 {
82 michael 5114 /* Setup IRC Block Defaults */
83 michael 5148 IRCItem->mode = xstrdup("+c");
84 michael 5114 IRCItem->nick = xstrdup("hopm");
85     IRCItem->port = 6667;
86 michael 5198 IRCItem->readtimeout = 900;
87 michael 5114 IRCItem->oper = xstrdup("undefined");
88     IRCItem->username = xstrdup("hopm");
89     IRCItem->realname = xstrdup("Hybrid Open Proxy Monitor");
90     IRCItem->server = xstrdup("irc.example.org");
91     IRCItem->connregex = xstrdup("\\*\\*\\* Notice -- Client connecting: ([^ ]+) \\(([^@]+)@([^\\)]+)\\) \\[([0-9\\.]+)\\].*");
92     IRCItem->kline = xstrdup("KLINE %u@%h :Open Proxy found on your host.");
93 michael 5052
94 michael 5114 /* Setup options block defaults */
95     OptionsItem->negcache = 0; /* 0 disabled negcache */
96 michael 5332 OptionsItem->negcache_rebuild = 43200;
97 michael 5114 OptionsItem->pidfile = xstrdup("hopm.pid");
98     OptionsItem->dns_fdlimit = 50;
99     OptionsItem->scanlog = NULL;
100 michael 5052 }
101    
102 michael 5270 /* Rehash or load new configuration from filename, via flex/bison parser */
103 michael 5114 void
104 michael 5270 config_load(const char *filename)
105     {
106     config_init();
107     config_setup(); /* Setup/clear current configuration */
108    
109     log_printf("CONFIG -> Loading %s", filename);
110    
111     if ((yyin = fopen(filename, "r")) == NULL)
112     {
113     log_printf("CONFIG -> Error opening %s: %s", filename, strerror(errno));
114     exit(EXIT_FAILURE);
115     }
116    
117     yyparse();
118    
119     scan_init(); /* Initialize the scanners once we have the configuration */
120     command_init(); /* Initialize the command queue */
121     stats_init(); /* Initialize stats (UPTIME) */
122     firedns_init(); /* Initialize adns */
123    
124     fclose(yyin);
125     }
126    
127     void
128 michael 5114 yyerror(const char *str)
129 michael 5052 {
130 michael 5114 log_printf("CONFIG -> %s: line %d", str, linenum);
131     exit(EXIT_FAILURE);
132 michael 5052 }

Properties

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