]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/configreader.h
63836056a077aee5de56b77fba6fb46f8265885c
[user/henk/code/inspircd.git] / include / configreader.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *                <omster@gmail.com>
10  *     
11  * Written by Craig Edwards, Craig McLure, and others.
12  * This program is free but copyrighted software; see
13  *            the file COPYING for details.
14  *
15  * ---------------------------------------------------
16  */
17
18 #ifndef INSPIRCD_CONFIGREADER
19 #define INSPIRCD_CONFIGREADER
20
21 #include <sstream>
22 #include <string>
23 #include <vector>
24 #include <map>
25 #include "inspircd.h"
26 #include "globals.h"
27 #include "modules.h"
28
29 typedef bool (*Validator)(const char*, const char*, void*);
30 typedef bool (*MultiValidator)(const char*, char**, void**, int*);
31 typedef bool (*MultiNotify)(const char*);
32
33 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
34
35 struct InitialConfig {
36         char* tag;
37         char* value;
38         void* val;
39         ConfigDataType datatype;
40         Validator validation_function;
41 };
42
43 struct MultiConfig {
44         const char* tag;
45         char* items[12];
46         int datatype[12];
47         MultiNotify     init_function;
48         MultiValidator  validation_function;
49         MultiNotify     finish_function;
50 };
51
52 /** This class holds the bulk of the runtime configuration for the ircd.
53  * It allows for reading new config values, accessing configuration files,
54  * and storage of the configuration data needed to run the ircd, such as
55  * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
56  */
57 class ServerConfig : public classbase
58 {
59   private:
60         /** This variable holds the names of all
61          * files included from the main one. This
62          * is used to make sure that no files are
63          * recursively included.
64          */
65         std::vector<std::string> include_stack;
66
67         /** This private method processes one line of
68          * configutation, appending errors to errorstream
69          * and setting error if an error has occured.
70          */
71         bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
72   
73         bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
74
75         /** Check that there is only one of each configuration item
76          */
77         bool CheckOnce(char* tag, bool bail, userrec* user);
78   
79   public:
80           
81         /** This holds all the information in the config file,
82          * it's indexed by tag name to a vector of key/values.
83          */
84         ConfigDataHash config_data;
85
86         /** Holds the server name of the local server
87          * as defined by the administrator.
88          */
89         char ServerName[MAXBUF];
90         
91         /* Holds the network name the local server
92          * belongs to. This is an arbitary field defined
93          * by the administrator.
94          */
95         char Network[MAXBUF];
96
97         /** Holds the description of the local server
98          * as defined by the administrator.
99          */
100         char ServerDesc[MAXBUF];
101
102         /** Holds the admin's name, for output in
103          * the /ADMIN command.
104          */
105         char AdminName[MAXBUF];
106
107         /** Holds the email address of the admin,
108          * for output in the /ADMIN command.
109          */
110         char AdminEmail[MAXBUF];
111
112         /** Holds the admin's nickname, for output
113          * in the /ADMIN command
114          */
115         char AdminNick[MAXBUF];
116
117         /** The admin-configured /DIE password
118          */
119         char diepass[MAXBUF];
120
121         /** The admin-configured /RESTART password
122          */
123         char restartpass[MAXBUF];
124
125         /** The pathname and filename of the message of the
126          * day file, as defined by the administrator.
127          */
128         char motd[MAXBUF];
129
130         /** The pathname and filename of the rules file,
131          * as defined by the administrator.
132          */
133         char rules[MAXBUF];
134
135         /** The quit prefix in use, or an empty string
136          */
137         char PrefixQuit[MAXBUF];
138
139         /** The last string found within a <die> tag, or
140          * an empty string.
141          */
142         char DieValue[MAXBUF];
143
144         /** The DNS server to use for DNS queries
145          */
146         char DNSServer[MAXBUF];
147
148         /** This variable contains a space-seperated list
149          * of commands which are disabled by the
150          * administrator of the server for non-opers.
151          */
152         char DisabledCommands[MAXBUF];
153
154         /** The full path to the modules directory.
155          * This is either set at compile time, or
156          * overridden in the configuration file via
157          * the <options> tag.
158          */
159         char ModPath[1024];
160
161         /** The temporary directory where modules are copied
162          */
163         char TempDir[1024];
164
165         /** The full pathname to the executable, as
166          * given in argv[0] when the program starts.
167          */
168         char MyExecutable[1024];
169
170         /** The file handle of the logfile. If this
171          * value is NULL, the log file is not open,
172          * probably due to a permissions error on
173          * startup (this should not happen in normal
174          * operation!).
175          */
176         FILE *log_file;
177
178         /** If this value is true, the owner of the
179          * server specified -nofork on the command
180          * line, causing the daemon to stay in the
181          * foreground.
182          */
183         bool nofork;
184         
185         /** If this value if true then all log
186          * messages will be output, regardless of
187          * the level given in the config file.
188          * This is set with the -debug commandline
189          * option.
190          */
191         bool forcedebug;
192         
193         /** If this is true then log output will be
194          * written to the logfile. This is the default.
195          * If you put -nolog on the commandline then
196          * the logfile will not be written.
197          * This is meant to be used in conjunction with
198          * -debug for debugging without filling up the
199          * hard disk.
200          */
201         bool writelog;
202
203         /** If this value is true, halfops have been
204          * enabled in the configuration file.
205          */
206         bool AllowHalfop;
207
208         /** The number of seconds the DNS subsystem
209          * will wait before timing out any request.
210          */
211         int dns_timeout;
212
213         /** The size of the read() buffer in the user
214          * handling code, used to read data into a user's
215          * recvQ.
216          */
217         int NetBufferSize;
218
219         /** The value to be used for listen() backlogs
220          * as default.
221          */
222         int MaxConn;
223
224         /** The soft limit value assigned to the irc server.
225          * The IRC server will not allow more than this
226          * number of local users.
227          */
228         unsigned int SoftLimit;
229
230         /** Maximum number of targets for a multi target command
231          * such as PRIVMSG or KICK
232          */
233         unsigned int MaxTargets;
234
235         /** The maximum number of /WHO results allowed
236          * in any single /WHO command.
237          */
238         int MaxWhoResults;
239
240         /** True if the DEBUG loglevel is selected.
241          */
242         int debugging;
243
244         /** The loglevel in use by the IRC server
245          */
246         int LogLevel;
247
248         /** How many seconds to wait before exiting
249          * the program when /DIE is correctly issued.
250          */
251         int DieDelay;
252
253         /** True if we're going to hide netsplits as *.net *.split for non-opers
254          */
255         bool HideSplits;
256
257         /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
258          * K-Lines, Z-Lines)
259          */
260         bool HideBans;
261
262         /** If this is enabled then operators will
263          * see invisible (+i) channels in /whois.
264          */
265         bool OperSpyWhois;
266
267         /** Set to a non-empty string to obfuscate the server name of users in WHOIS
268          */
269         char HideWhoisServer[MAXBUF];
270
271         /** A list of IP addresses the server is listening
272          * on.
273          */
274         char addrs[MAXBUF][255];
275
276         /** The MOTD file, cached in a file_cache type.
277          */
278         file_cache MOTD;
279
280         /** The RULES file, cached in a file_cache type.
281          */
282         file_cache RULES;
283
284         /** The full pathname and filename of the PID
285          * file as defined in the configuration.
286          */
287         char PID[1024];
288
289         /** The connect classes in use by the IRC server.
290          */
291         ClassVector Classes;
292
293         /** A list of module names (names only, no paths)
294          * which are currently loaded by the server.
295          */
296         std::vector<std::string> module_names;
297
298         /** A list of ports which the server is listening on
299          */
300         int ports[255];
301
302         /** Boolean sets of which modules implement which functions
303          */
304         char implement_lists[255][255];
305
306         /** Global implementation list
307          */
308         char global_implementation[255];
309
310         /** A list of ports claimed by IO Modules
311          */
312         std::map<int,Module*> IOHookModule;
313
314         /** The 005 tokens of this server (ISUPPORT)
315          * populated/repopulated upon loading or unloading
316          * modules.
317          */
318         std::string data005;
319
320         /** STATS characters in this list are available
321          * only to operators.
322          */
323         char OperOnlyStats[MAXBUF];
324         
325         /** The path and filename of the ircd.log file
326          */
327         std::string logpath;
328
329         /** Custom version string, which if defined can replace the system info in VERSION.
330          */
331         char CustomVersion[MAXBUF];
332
333         /** List of u-lined servers
334          */
335         std::vector<irc::string> ulines;
336
337         /** Max banlist sizes for channels (the std::string is a glob)
338          */
339         std::map<std::string,int> maxbans;
340
341         ServerConfig();
342
343         /** Clears the include stack in preperation for
344          * a Read() call.
345          */
346         void ClearStack();
347
348         /** Read the entire configuration into memory
349          * and initialize this class. All other methods
350          * should be used only by the core.
351          */
352         void Read(bool bail, userrec* user);
353
354         /** Load 'filename' into 'target', with the new config parser everything is parsed into
355          * tag/key/value at load-time rather than at read-value time.
356          */
357         bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
358         bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
359         
360         /* Both these return true if the value existed or false otherwise */
361         
362         /* Writes 'length' chars into 'result' as a string */
363         bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
364         bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
365         
366         /* Tries to convert the value to an integer and write it to 'result' */
367         bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
368         bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
369         
370         /* Returns true if the value exists and has a true value, false otherwise */
371         bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
372         bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
373         
374         /* Returns the number of occurences of tag in the config file */
375         int ConfValueEnum(ConfigDataHash &target, const char* tag);
376         int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
377         
378         /* Returns the numbers of vars inside the index'th 'tag in the config file */
379         int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
380         int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
381         
382         Module* GetIOHook(int port);
383         bool AddIOHook(int port, Module* iomod);
384         bool DelIOHook(int port);
385 };
386
387 #endif