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