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 class InitialConfig : public classbase
41 ConfigDataType datatype;
42 Validator validation_function;
45 class MultiConfig : public classbase
51 MultiNotify init_function;
52 MultiValidator validation_function;
53 MultiNotify finish_function;
56 /** This class holds the bulk of the runtime configuration for the ircd.
57 * It allows for reading new config values, accessing configuration files,
58 * and storage of the configuration data needed to run the ircd, such as
59 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
61 class ServerConfig : public Extensible
64 /** This variable holds the names of all
65 * files included from the main one. This
66 * is used to make sure that no files are
67 * recursively included.
69 std::vector<std::string> include_stack;
71 /** This private method processes one line of
72 * configutation, appending errors to errorstream
73 * and setting error if an error has occured.
75 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
77 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
79 /** Check that there is only one of each configuration item
81 bool CheckOnce(char* tag, bool bail, userrec* user);
85 /** This holds all the information in the config file,
86 * it's indexed by tag name to a vector of key/values.
88 ConfigDataHash config_data;
90 /** Holds the server name of the local server
91 * as defined by the administrator.
93 char ServerName[MAXBUF];
95 /* Holds the network name the local server
96 * belongs to. This is an arbitary field defined
97 * by the administrator.
101 /** Holds the description of the local server
102 * as defined by the administrator.
104 char ServerDesc[MAXBUF];
106 /** Holds the admin's name, for output in
107 * the /ADMIN command.
109 char AdminName[MAXBUF];
111 /** Holds the email address of the admin,
112 * for output in the /ADMIN command.
114 char AdminEmail[MAXBUF];
116 /** Holds the admin's nickname, for output
117 * in the /ADMIN command
119 char AdminNick[MAXBUF];
121 /** The admin-configured /DIE password
123 char diepass[MAXBUF];
125 /** The admin-configured /RESTART password
127 char restartpass[MAXBUF];
129 /** The pathname and filename of the message of the
130 * day file, as defined by the administrator.
134 /** The pathname and filename of the rules file,
135 * as defined by the administrator.
139 /** The quit prefix in use, or an empty string
141 char PrefixQuit[MAXBUF];
143 /** The last string found within a <die> tag, or
146 char DieValue[MAXBUF];
148 /** The DNS server to use for DNS queries
150 char DNSServer[MAXBUF];
152 /** This variable contains a space-seperated list
153 * of commands which are disabled by the
154 * administrator of the server for non-opers.
156 char DisabledCommands[MAXBUF];
158 /** The full path to the modules directory.
159 * This is either set at compile time, or
160 * overridden in the configuration file via
165 /** The temporary directory where modules are copied
169 /** The full pathname to the executable, as
170 * given in argv[0] when the program starts.
172 char MyExecutable[1024];
174 /** The file handle of the logfile. If this
175 * value is NULL, the log file is not open,
176 * probably due to a permissions error on
177 * startup (this should not happen in normal
182 /** If this value is true, the owner of the
183 * server specified -nofork on the command
184 * line, causing the daemon to stay in the
189 /** If this value if true then all log
190 * messages will be output, regardless of
191 * the level given in the config file.
192 * This is set with the -debug commandline
197 /** If this is true then log output will be
198 * written to the logfile. This is the default.
199 * If you put -nolog on the commandline then
200 * the logfile will not be written.
201 * This is meant to be used in conjunction with
202 * -debug for debugging without filling up the
207 /** If this value is true, halfops have been
208 * enabled in the configuration file.
212 /** The number of seconds the DNS subsystem
213 * will wait before timing out any request.
217 /** The size of the read() buffer in the user
218 * handling code, used to read data into a user's
223 /** The value to be used for listen() backlogs
228 /** The soft limit value assigned to the irc server.
229 * The IRC server will not allow more than this
230 * number of local users.
232 unsigned int SoftLimit;
234 /** Maximum number of targets for a multi target command
235 * such as PRIVMSG or KICK
237 unsigned int MaxTargets;
239 /** The maximum number of /WHO results allowed
240 * in any single /WHO command.
244 /** True if the DEBUG loglevel is selected.
248 /** The loglevel in use by the IRC server
252 /** How many seconds to wait before exiting
253 * the program when /DIE is correctly issued.
257 /** True if we're going to hide netsplits as *.net *.split for non-opers
261 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
266 /** If this is enabled then operators will
267 * see invisible (+i) channels in /whois.
271 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
273 char HideWhoisServer[MAXBUF];
275 /** A list of IP addresses the server is listening
278 char addrs[MAXBUF][255];
280 /** The MOTD file, cached in a file_cache type.
284 /** The RULES file, cached in a file_cache type.
288 /** The full pathname and filename of the PID
289 * file as defined in the configuration.
293 /** The connect classes in use by the IRC server.
297 /** A list of module names (names only, no paths)
298 * which are currently loaded by the server.
300 std::vector<std::string> module_names;
302 /** A list of ports which the server is listening on
306 /** Boolean sets of which modules implement which functions
308 char implement_lists[255][255];
310 /** Global implementation list
312 char global_implementation[255];
314 /** A list of ports claimed by IO Modules
316 std::map<int,Module*> IOHookModule;
318 /** The 005 tokens of this server (ISUPPORT)
319 * populated/repopulated upon loading or unloading
324 /** STATS characters in this list are available
327 char OperOnlyStats[MAXBUF];
329 /** The path and filename of the ircd.log file
333 /** Custom version string, which if defined can replace the system info in VERSION.
335 char CustomVersion[MAXBUF];
337 /** List of u-lined servers
339 std::vector<irc::string> ulines;
341 /** Max banlist sizes for channels (the std::string is a glob)
343 std::map<std::string,int> maxbans;
347 /** Clears the include stack in preperation for
352 /** Read the entire configuration into memory
353 * and initialize this class. All other methods
354 * should be used only by the core.
356 void Read(bool bail, userrec* user);
358 /** Load 'filename' into 'target', with the new config parser everything is parsed into
359 * tag/key/value at load-time rather than at read-value time.
361 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
362 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
364 /* Both these return true if the value existed or false otherwise */
366 /* Writes 'length' chars into 'result' as a string */
367 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
368 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
370 /* Tries to convert the value to an integer and write it to 'result' */
371 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
372 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
374 /* Returns true if the value exists and has a true value, false otherwise */
375 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
376 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
378 /* Returns the number of occurences of tag in the config file */
379 int ConfValueEnum(ConfigDataHash &target, const char* tag);
380 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
382 /* Returns the numbers of vars inside the index'th 'tag in the config file */
383 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
384 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
386 Module* GetIOHook(int port);
387 bool AddIOHook(int port, Module* iomod);
388 bool DelIOHook(int port);