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
29 typedef bool (*Validator)(const char*, const char*, void*);
30 typedef bool (*MultiValidator)(const char*, char**, void**, int*);
31 typedef bool (*MultiNotify)(const char*);
33 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
35 struct InitialConfig {
39 ConfigDataType datatype;
40 Validator validation_function;
47 MultiNotify init_function;
48 MultiValidator validation_function;
49 MultiNotify finish_function;
52 /** This class holds the bulk of the runtime configuration for the ircd.
53 * It allows for reading new config values, accessing configuration files,
54 * and storage of the configuration data needed to run the ircd, such as
55 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
57 class ServerConfig : public classbase
60 /** This variable holds the names of all
61 * files included from the main one. This
62 * is used to make sure that no files are
63 * recursively included.
65 std::vector<std::string> include_stack;
67 /** This private method processes one line of
68 * configutation, appending errors to errorstream
69 * and setting error if an error has occured.
71 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
73 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
75 /** Check that there is only one of each configuration item
77 bool CheckOnce(char* tag, bool bail, userrec* user);
81 /** This holds all the information in the config file,
82 * it's indexed by tag name to a vector of key/values.
84 ConfigDataHash config_data;
86 /** Holds the server name of the local server
87 * as defined by the administrator.
89 char ServerName[MAXBUF];
91 /* Holds the network name the local server
92 * belongs to. This is an arbitary field defined
93 * by the administrator.
97 /** Holds the description of the local server
98 * as defined by the administrator.
100 char ServerDesc[MAXBUF];
102 /** Holds the admin's name, for output in
103 * the /ADMIN command.
105 char AdminName[MAXBUF];
107 /** Holds the email address of the admin,
108 * for output in the /ADMIN command.
110 char AdminEmail[MAXBUF];
112 /** Holds the admin's nickname, for output
113 * in the /ADMIN command
115 char AdminNick[MAXBUF];
117 /** The admin-configured /DIE password
119 char diepass[MAXBUF];
121 /** The admin-configured /RESTART password
123 char restartpass[MAXBUF];
125 /** The pathname and filename of the message of the
126 * day file, as defined by the administrator.
130 /** The pathname and filename of the rules file,
131 * as defined by the administrator.
135 /** The quit prefix in use, or an empty string
137 char PrefixQuit[MAXBUF];
139 /** The last string found within a <die> tag, or
142 char DieValue[MAXBUF];
144 /** The DNS server to use for DNS queries
146 char DNSServer[MAXBUF];
148 /** This variable contains a space-seperated list
149 * of commands which are disabled by the
150 * administrator of the server for non-opers.
152 char DisabledCommands[MAXBUF];
154 /** The full path to the modules directory.
155 * This is either set at compile time, or
156 * overridden in the configuration file via
161 /** The temporary directory where modules are copied
165 /** The full pathname to the executable, as
166 * given in argv[0] when the program starts.
168 char MyExecutable[1024];
170 /** The file handle of the logfile. If this
171 * value is NULL, the log file is not open,
172 * probably due to a permissions error on
173 * startup (this should not happen in normal
178 /** If this value is true, the owner of the
179 * server specified -nofork on the command
180 * line, causing the daemon to stay in the
185 /** If this value if true then all log
186 * messages will be output, regardless of
187 * the level given in the config file.
188 * This is set with the -debug commandline
193 /** If this is true then log output will be
194 * written to the logfile. This is the default.
195 * If you put -nolog on the commandline then
196 * the logfile will not be written.
197 * This is meant to be used in conjunction with
198 * -debug for debugging without filling up the
203 /** If this value is true, halfops have been
204 * enabled in the configuration file.
208 /** The number of seconds the DNS subsystem
209 * will wait before timing out any request.
213 /** The size of the read() buffer in the user
214 * handling code, used to read data into a user's
219 /** The value to be used for listen() backlogs
224 /** The soft limit value assigned to the irc server.
225 * The IRC server will not allow more than this
226 * number of local users.
228 unsigned int SoftLimit;
230 /** Maximum number of targets for a multi target command
231 * such as PRIVMSG or KICK
233 unsigned int MaxTargets;
235 /** The maximum number of /WHO results allowed
236 * in any single /WHO command.
240 /** True if the DEBUG loglevel is selected.
244 /** The loglevel in use by the IRC server
248 /** How many seconds to wait before exiting
249 * the program when /DIE is correctly issued.
253 /** True if we're going to hide netsplits as *.net *.split for non-opers
257 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
262 /** If this is enabled then operators will
263 * see invisible (+i) channels in /whois.
267 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
269 char HideWhoisServer[MAXBUF];
271 /** A list of IP addresses the server is listening
274 char addrs[MAXBUF][255];
276 /** The MOTD file, cached in a file_cache type.
280 /** The RULES file, cached in a file_cache type.
284 /** The full pathname and filename of the PID
285 * file as defined in the configuration.
289 /** The connect classes in use by the IRC server.
293 /** A list of module names (names only, no paths)
294 * which are currently loaded by the server.
296 std::vector<std::string> module_names;
298 /** A list of ports which the server is listening on
302 /** Boolean sets of which modules implement which functions
304 char implement_lists[255][255];
306 /** Global implementation list
308 char global_implementation[255];
310 /** A list of ports claimed by IO Modules
312 std::map<int,Module*> IOHookModule;
314 /** The 005 tokens of this server (ISUPPORT)
315 * populated/repopulated upon loading or unloading
320 /** STATS characters in this list are available
323 char OperOnlyStats[MAXBUF];
325 /** The path and filename of the ircd.log file
329 /** Custom version string, which if defined can replace the system info in VERSION.
331 char CustomVersion[MAXBUF];
333 /** List of u-lined servers
335 std::vector<irc::string> ulines;
337 /** Max banlist sizes for channels (the std::string is a glob)
339 std::map<std::string,int> maxbans;
343 /** Clears the include stack in preperation for
348 /** Read the entire configuration into memory
349 * and initialize this class. All other methods
350 * should be used only by the core.
352 void Read(bool bail, userrec* user);
354 /** Load 'filename' into 'target', with the new config parser everything is parsed into
355 * tag/key/value at load-time rather than at read-value time.
357 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
358 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
360 /* Both these return true if the value existed or false otherwise */
362 /* Writes 'length' chars into 'result' as a string */
363 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
364 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
366 /* Tries to convert the value to an integer and write it to 'result' */
367 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
368 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
370 /* Returns true if the value exists and has a true value, false otherwise */
371 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
372 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
374 /* Returns the number of occurences of tag in the config file */
375 int ConfValueEnum(ConfigDataHash &target, const char* tag);
376 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
378 /* Returns the numbers of vars inside the index'th 'tag in the config file */
379 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
380 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
382 Module* GetIOHook(int port);
383 bool AddIOHook(int port, Module* iomod);
384 bool DelIOHook(int port);