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