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