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 };
40 ConfigDataType datatype;
41 Validator validation_function;
49 MultiNotify init_function;
50 MultiValidator validation_function;
51 MultiNotify finish_function;
54 /** This class holds the bulk of the runtime configuration for the ircd.
55 * It allows for reading new config values, accessing configuration files,
56 * and storage of the configuration data needed to run the ircd, such as
57 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
59 class ServerConfig : public Extensible
62 /** This variable holds the names of all
63 * files included from the main one. This
64 * is used to make sure that no files are
65 * recursively included.
67 std::vector<std::string> include_stack;
69 /** This private method processes one line of
70 * configutation, appending errors to errorstream
71 * and setting error if an error has occured.
73 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
75 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
77 /** Check that there is only one of each configuration item
79 bool CheckOnce(char* tag, bool bail, userrec* user);
83 /** This holds all the information in the config file,
84 * it's indexed by tag name to a vector of key/values.
86 ConfigDataHash config_data;
88 /** Holds the server name of the local server
89 * as defined by the administrator.
91 char ServerName[MAXBUF];
93 /* Holds the network name the local server
94 * belongs to. This is an arbitary field defined
95 * by the administrator.
99 /** Holds the description of the local server
100 * as defined by the administrator.
102 char ServerDesc[MAXBUF];
104 /** Holds the admin's name, for output in
105 * the /ADMIN command.
107 char AdminName[MAXBUF];
109 /** Holds the email address of the admin,
110 * for output in the /ADMIN command.
112 char AdminEmail[MAXBUF];
114 /** Holds the admin's nickname, for output
115 * in the /ADMIN command
117 char AdminNick[MAXBUF];
119 /** The admin-configured /DIE password
121 char diepass[MAXBUF];
123 /** The admin-configured /RESTART password
125 char restartpass[MAXBUF];
127 /** The pathname and filename of the message of the
128 * day file, as defined by the administrator.
132 /** The pathname and filename of the rules file,
133 * as defined by the administrator.
137 /** The quit prefix in use, or an empty string
139 char PrefixQuit[MAXBUF];
141 /** The last string found within a <die> tag, or
144 char DieValue[MAXBUF];
146 /** The DNS server to use for DNS queries
148 char DNSServer[MAXBUF];
150 /** This variable contains a space-seperated list
151 * of commands which are disabled by the
152 * administrator of the server for non-opers.
154 char DisabledCommands[MAXBUF];
156 /** The full path to the modules directory.
157 * This is either set at compile time, or
158 * overridden in the configuration file via
163 /** The temporary directory where modules are copied
167 /** The full pathname to the executable, as
168 * given in argv[0] when the program starts.
170 char MyExecutable[1024];
172 /** The file handle of the logfile. If this
173 * value is NULL, the log file is not open,
174 * probably due to a permissions error on
175 * startup (this should not happen in normal
180 /** If this value is true, the owner of the
181 * server specified -nofork on the command
182 * line, causing the daemon to stay in the
187 /** If this value if true then all log
188 * messages will be output, regardless of
189 * the level given in the config file.
190 * This is set with the -debug commandline
195 /** If this is true then log output will be
196 * written to the logfile. This is the default.
197 * If you put -nolog on the commandline then
198 * the logfile will not be written.
199 * This is meant to be used in conjunction with
200 * -debug for debugging without filling up the
205 /** If this value is true, halfops have been
206 * enabled in the configuration file.
210 /** The number of seconds the DNS subsystem
211 * will wait before timing out any request.
215 /** The size of the read() buffer in the user
216 * handling code, used to read data into a user's
221 /** The value to be used for listen() backlogs
226 /** The soft limit value assigned to the irc server.
227 * The IRC server will not allow more than this
228 * number of local users.
230 unsigned int SoftLimit;
232 /** Maximum number of targets for a multi target command
233 * such as PRIVMSG or KICK
235 unsigned int MaxTargets;
237 /** The maximum number of /WHO results allowed
238 * in any single /WHO command.
242 /** True if the DEBUG loglevel is selected.
246 /** The loglevel in use by the IRC server
250 /** How many seconds to wait before exiting
251 * the program when /DIE is correctly issued.
255 /** True if we're going to hide netsplits as *.net *.split for non-opers
259 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
264 /** If this is enabled then operators will
265 * see invisible (+i) channels in /whois.
269 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
271 char HideWhoisServer[MAXBUF];
273 /** A list of IP addresses the server is listening
276 char addrs[MAXBUF][255];
278 /** The MOTD file, cached in a file_cache type.
282 /** The RULES file, cached in a file_cache type.
286 /** The full pathname and filename of the PID
287 * file as defined in the configuration.
291 /** The connect classes in use by the IRC server.
295 /** A list of module names (names only, no paths)
296 * which are currently loaded by the server.
298 std::vector<std::string> module_names;
300 /** A list of ports which the server is listening on
304 /** A list of the file descriptors for the listening client ports
306 int openSockfd[MAX_DESCRIPTORS];
308 /** Boolean sets of which modules implement which functions
310 char implement_lists[255][255];
312 /** Global implementation list
314 char global_implementation[255];
316 /** A list of ports claimed by IO Modules
318 std::map<int,Module*> IOHookModule;
320 /** The 005 tokens of this server (ISUPPORT)
321 * populated/repopulated upon loading or unloading
326 /** STATS characters in this list are available
329 char OperOnlyStats[MAXBUF];
331 /** The path and filename of the ircd.log file
335 /** Custom version string, which if defined can replace the system info in VERSION.
337 char CustomVersion[MAXBUF];
339 /** List of u-lined servers
341 std::vector<irc::string> ulines;
343 /** Max banlist sizes for channels (the std::string is a glob)
345 std::map<std::string,int> maxbans;
347 /** If set to true, no user DNS lookups are to be performed
353 /** Clears the include stack in preperation for
358 /** Read the entire configuration into memory
359 * and initialize this class. All other methods
360 * should be used only by the core.
362 void Read(bool bail, userrec* user);
364 /** Load 'filename' into 'target', with the new config parser everything is parsed into
365 * tag/key/value at load-time rather than at read-value time.
367 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
368 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
370 /* Both these return true if the value existed or false otherwise */
372 /* Writes 'length' chars into 'result' as a string */
373 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
374 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
376 /* Tries to convert the value to an integer and write it to 'result' */
377 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
378 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
380 /* Returns true if the value exists and has a true value, false otherwise */
381 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
382 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
384 /* Returns the number of occurences of tag in the config file */
385 int ConfValueEnum(ConfigDataHash &target, const char* tag);
386 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
388 /* Returns the numbers of vars inside the index'th 'tag in the config file */
389 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
390 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
392 Module* GetIOHook(int port);
393 bool AddIOHook(int port, Module* iomod);
394 bool DelIOHook(int port);