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