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