1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
11 * Written by Craig Edwards, Craig McLure, and others.
12 * This program is free but copyrighted software; see
13 * the file COPYING for details.
15 * ---------------------------------------------------
18 #ifndef INSPIRCD_CONFIGREADER
19 #define INSPIRCD_CONFIGREADER
28 #include "socketengine.h"
34 /** A callback for validating a single value
36 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, void*);
37 /** A callback for validating multiple value entries
39 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, void**, int*);
40 /** A callback indicating the end of a group of entries
42 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
44 /** Types of data in the core config
46 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
48 /** Holds a core configuration item and its callbacks
55 ConfigDataType datatype;
56 Validator validation_function;
59 /** Holds a core configuration item and its callbacks
60 * where there may be more than one item
67 MultiNotify init_function;
68 MultiValidator validation_function;
69 MultiNotify finish_function;
72 /** A set of oper types
74 typedef std::map<irc::string,char*> opertype_t;
76 /** A Set of oper classes
78 typedef std::map<irc::string,char*> operclass_t;
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.
86 class ServerConfig : public Extensible
91 InspIRCd* ServerInstance;
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.
98 std::vector<std::string> include_stack;
100 /** This private method processes one line of
101 * configutation, appending errors to errorstream
102 * and setting error if an error has occured.
104 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
106 /** Process an include directive
108 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
110 /** Check that there is only one of each configuration item
112 bool CheckOnce(char* tag, bool bail, userrec* user);
116 InspIRCd* GetInstance();
118 /** This holds all the information in the config file,
119 * it's indexed by tag name to a vector of key/values.
121 ConfigDataHash config_data;
123 /** Max number of WhoWas entries per user.
127 /** Max number of cumulative user-entries in WhoWas.
128 * When max reached and added to, push out oldest entry FIFO style.
132 /** Max seconds a user is kept in WhoWas before being pruned.
136 /** Holds the server name of the local server
137 * as defined by the administrator.
139 char ServerName[MAXBUF];
141 /* Holds the network name the local server
142 * belongs to. This is an arbitary field defined
143 * by the administrator.
145 char Network[MAXBUF];
147 /** Holds the description of the local server
148 * as defined by the administrator.
150 char ServerDesc[MAXBUF];
152 /** Holds the admin's name, for output in
153 * the /ADMIN command.
155 char AdminName[MAXBUF];
157 /** Holds the email address of the admin,
158 * for output in the /ADMIN command.
160 char AdminEmail[MAXBUF];
162 /** Holds the admin's nickname, for output
163 * in the /ADMIN command
165 char AdminNick[MAXBUF];
167 /** The admin-configured /DIE password
169 char diepass[MAXBUF];
171 /** The admin-configured /RESTART password
173 char restartpass[MAXBUF];
175 /** The pathname and filename of the message of the
176 * day file, as defined by the administrator.
180 /** The pathname and filename of the rules file,
181 * as defined by the administrator.
185 /** The quit prefix in use, or an empty string
187 char PrefixQuit[MAXBUF];
189 /** The last string found within a <die> tag, or
192 char DieValue[MAXBUF];
194 /** The DNS server to use for DNS queries
196 char DNSServer[MAXBUF];
198 /** This variable contains a space-seperated list
199 * of commands which are disabled by the
200 * administrator of the server for non-opers.
202 char DisabledCommands[MAXBUF];
204 /** The full path to the modules directory.
205 * This is either set at compile time, or
206 * overridden in the configuration file via
211 /** The temporary directory where modules are copied
215 /** The full pathname to the executable, as
216 * given in argv[0] when the program starts.
218 char MyExecutable[1024];
220 /** The file handle of the logfile. If this
221 * value is NULL, the log file is not open,
222 * probably due to a permissions error on
223 * startup (this should not happen in normal
228 /** If this value is true, the owner of the
229 * server specified -nofork on the command
230 * line, causing the daemon to stay in the
235 /** If this value if true then all log
236 * messages will be output, regardless of
237 * the level given in the config file.
238 * This is set with the -debug commandline
243 /** If this is true then log output will be
244 * written to the logfile. This is the default.
245 * If you put -nolog on the commandline then
246 * the logfile will not be written.
247 * This is meant to be used in conjunction with
248 * -debug for debugging without filling up the
253 /** If this value is true, halfops have been
254 * enabled in the configuration file.
258 /** The number of seconds the DNS subsystem
259 * will wait before timing out any request.
263 /** The size of the read() buffer in the user
264 * handling code, used to read data into a user's
269 /** The value to be used for listen() backlogs
274 /** The soft limit value assigned to the irc server.
275 * The IRC server will not allow more than this
276 * number of local users.
278 unsigned int SoftLimit;
280 /** Maximum number of targets for a multi target command
281 * such as PRIVMSG or KICK
283 unsigned int MaxTargets;
285 /** The maximum number of /WHO results allowed
286 * in any single /WHO command.
290 /** True if the DEBUG loglevel is selected.
294 /** The loglevel in use by the IRC server
298 /** How many seconds to wait before exiting
299 * the program when /DIE is correctly issued.
303 /** True if we're going to hide netsplits as *.net *.split for non-opers
307 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
312 /** If this is enabled then operators will
313 * see invisible (+i) channels in /whois.
317 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
319 char HideWhoisServer[MAXBUF];
321 /** A list of IP addresses the server is listening
324 char addrs[MAXBUF][255];
326 /** The MOTD file, cached in a file_cache type.
330 /** The RULES file, cached in a file_cache type.
334 /** The full pathname and filename of the PID
335 * file as defined in the configuration.
339 /** The connect classes in use by the IRC server.
343 /** A list of module names (names only, no paths)
344 * which are currently loaded by the server.
346 std::vector<std::string> module_names;
348 /** A list of ports which the server is listening on
352 /** A list of the file descriptors for the listening client ports
354 ListenSocket* openSockfd[255];
356 /** Boolean sets of which modules implement which functions
358 char implement_lists[255][255];
360 /** Global implementation list
362 char global_implementation[255];
364 /** A list of ports claimed by IO Modules
366 std::map<int,Module*> IOHookModule;
368 /** The 005 tokens of this server (ISUPPORT)
369 * populated/repopulated upon loading or unloading
374 /** STATS characters in this list are available
377 char UserStats[MAXBUF];
379 /** The path and filename of the ircd.log file
383 /** Custom version string, which if defined can replace the system info in VERSION.
385 char CustomVersion[MAXBUF];
387 /** List of u-lined servers
389 std::vector<irc::string> ulines;
391 /** Max banlist sizes for channels (the std::string is a glob)
393 std::map<std::string,int> maxbans;
395 /** If set to true, no user DNS lookups are to be performed
399 /** If set to true, provide syntax hints for unknown commands
403 /** If set to true, users appear to quit then rejoin when their hosts change.
404 * This keeps clients synchronized properly.
409 #if __GNUC__ == 3 && __GNUC_MINOR__ == 3
410 /** if we're being compiled with GCC 3.3 add
411 * dummy opertype on heap to fix GCC 3.3 crash
413 opertype_t dummyopertype;
416 /** All oper type definitions from the config file
418 opertype_t opertypes;
420 /** All oper class definitions from the config file
422 operclass_t operclass;
424 /** Construct a new ServerConfig
426 ServerConfig(InspIRCd* Instance);
428 /** Clears the include stack in preperation for a Read() call.
432 /** Read the entire configuration into memory
433 * and initialize this class. All other methods
434 * should be used only by the core.
436 void Read(bool bail, userrec* user);
438 /** Read a file into a file_cache object
440 bool ReadFile(file_cache &F, const char* fname);
442 /** Load 'filename' into 'target', with the new config parser everything is parsed into
443 * tag/key/value at load-time rather than at read-value time.
445 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
446 /** Load 'filename' into 'target', with the new config parser everything is parsed into
447 * tag/key/value at load-time rather than at read-value time.
449 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
451 /* Both these return true if the value existed or false otherwise */
453 /** Writes 'length' chars into 'result' as a string
455 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
456 /** Writes 'length' chars into 'result' as a string
458 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
460 /** Tries to convert the value to an integer and write it to 'result'
462 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
463 /** Tries to convert the value to an integer and write it to 'result'
465 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
467 /** Returns true if the value exists and has a true value, false otherwise
469 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
470 /** Returns true if the value exists and has a true value, false otherwise
472 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
474 /** Returns the number of occurences of tag in the config file
476 int ConfValueEnum(ConfigDataHash &target, const char* tag);
477 /** Returns the number of occurences of tag in the config file
479 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
481 /** Returns the numbers of vars inside the index'th 'tag in the config file
483 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
484 /** Returns the numbers of vars inside the index'th 'tag in the config file
486 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
488 Module* GetIOHook(int port);
489 bool AddIOHook(int port, Module* iomod);
490 bool DelIOHook(int port);
492 static std::string GetFullProgDir(char** argv, int argc);
493 static bool DirValid(const char* dirandfile);
494 static char* CleanFilename(char* name);
495 static bool FileExists(const char* file);
499 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);