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