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