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
32 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, void*);
33 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, void**, int*);
34 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
36 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
43 ConfigDataType datatype;
44 Validator validation_function;
52 MultiNotify init_function;
53 MultiValidator validation_function;
54 MultiNotify finish_function;
57 /** This class holds the bulk of the runtime configuration for the ircd.
58 * It allows for reading new config values, accessing configuration files,
59 * and storage of the configuration data needed to run the ircd, such as
60 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
62 class ServerConfig : public Extensible
65 InspIRCd* ServerInstance;
67 /** This variable holds the names of all
68 * files included from the main one. This
69 * is used to make sure that no files are
70 * recursively included.
72 std::vector<std::string> include_stack;
74 /** This private method processes one line of
75 * configutation, appending errors to errorstream
76 * and setting error if an error has occured.
78 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
80 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
82 /** Check that there is only one of each configuration item
84 bool CheckOnce(char* tag, bool bail, userrec* user);
88 /** This holds all the information in the config file,
89 * it's indexed by tag name to a vector of key/values.
91 ConfigDataHash config_data;
93 /** Holds the server name of the local server
94 * as defined by the administrator.
96 char ServerName[MAXBUF];
98 /* Holds the network name the local server
99 * belongs to. This is an arbitary field defined
100 * by the administrator.
102 char Network[MAXBUF];
104 /** Holds the description of the local server
105 * as defined by the administrator.
107 char ServerDesc[MAXBUF];
109 /** Holds the admin's name, for output in
110 * the /ADMIN command.
112 char AdminName[MAXBUF];
114 /** Holds the email address of the admin,
115 * for output in the /ADMIN command.
117 char AdminEmail[MAXBUF];
119 /** Holds the admin's nickname, for output
120 * in the /ADMIN command
122 char AdminNick[MAXBUF];
124 /** The admin-configured /DIE password
126 char diepass[MAXBUF];
128 /** The admin-configured /RESTART password
130 char restartpass[MAXBUF];
132 /** The pathname and filename of the message of the
133 * day file, as defined by the administrator.
137 /** The pathname and filename of the rules file,
138 * as defined by the administrator.
142 /** The quit prefix in use, or an empty string
144 char PrefixQuit[MAXBUF];
146 /** The last string found within a <die> tag, or
149 char DieValue[MAXBUF];
151 /** The DNS server to use for DNS queries
153 char DNSServer[MAXBUF];
155 /** This variable contains a space-seperated list
156 * of commands which are disabled by the
157 * administrator of the server for non-opers.
159 char DisabledCommands[MAXBUF];
161 /** The full path to the modules directory.
162 * This is either set at compile time, or
163 * overridden in the configuration file via
168 /** The temporary directory where modules are copied
172 /** The full pathname to the executable, as
173 * given in argv[0] when the program starts.
175 char MyExecutable[1024];
177 /** The file handle of the logfile. If this
178 * value is NULL, the log file is not open,
179 * probably due to a permissions error on
180 * startup (this should not happen in normal
185 /** If this value is true, the owner of the
186 * server specified -nofork on the command
187 * line, causing the daemon to stay in the
192 /** If this value if true then all log
193 * messages will be output, regardless of
194 * the level given in the config file.
195 * This is set with the -debug commandline
200 /** If this is true then log output will be
201 * written to the logfile. This is the default.
202 * If you put -nolog on the commandline then
203 * the logfile will not be written.
204 * This is meant to be used in conjunction with
205 * -debug for debugging without filling up the
210 /** If this value is true, halfops have been
211 * enabled in the configuration file.
215 /** The number of seconds the DNS subsystem
216 * will wait before timing out any request.
220 /** The size of the read() buffer in the user
221 * handling code, used to read data into a user's
226 /** The value to be used for listen() backlogs
231 /** The soft limit value assigned to the irc server.
232 * The IRC server will not allow more than this
233 * number of local users.
235 unsigned int SoftLimit;
237 /** Maximum number of targets for a multi target command
238 * such as PRIVMSG or KICK
240 unsigned int MaxTargets;
242 /** The maximum number of /WHO results allowed
243 * in any single /WHO command.
247 /** True if the DEBUG loglevel is selected.
251 /** The loglevel in use by the IRC server
255 /** How many seconds to wait before exiting
256 * the program when /DIE is correctly issued.
260 /** True if we're going to hide netsplits as *.net *.split for non-opers
264 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
269 /** If this is enabled then operators will
270 * see invisible (+i) channels in /whois.
274 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
276 char HideWhoisServer[MAXBUF];
278 /** A list of IP addresses the server is listening
281 char addrs[MAXBUF][255];
283 /** The MOTD file, cached in a file_cache type.
287 /** The RULES file, cached in a file_cache type.
291 /** The full pathname and filename of the PID
292 * file as defined in the configuration.
296 /** The connect classes in use by the IRC server.
300 /** A list of module names (names only, no paths)
301 * which are currently loaded by the server.
303 std::vector<std::string> module_names;
305 /** A list of ports which the server is listening on
309 /** A list of the file descriptors for the listening client ports
311 int openSockfd[MAX_DESCRIPTORS];
313 /** Boolean sets of which modules implement which functions
315 char implement_lists[255][255];
317 /** Global implementation list
319 char global_implementation[255];
321 /** A list of ports claimed by IO Modules
323 std::map<int,Module*> IOHookModule;
325 /** The 005 tokens of this server (ISUPPORT)
326 * populated/repopulated upon loading or unloading
331 /** STATS characters in this list are available
334 char OperOnlyStats[MAXBUF];
336 /** The path and filename of the ircd.log file
340 /** Custom version string, which if defined can replace the system info in VERSION.
342 char CustomVersion[MAXBUF];
344 /** List of u-lined servers
346 std::vector<irc::string> ulines;
348 /** Max banlist sizes for channels (the std::string is a glob)
350 std::map<std::string,int> maxbans;
352 /** If set to true, no user DNS lookups are to be performed
356 /** If set to true, provide syntax hints for unknown commands
360 ServerConfig(InspIRCd* Instance);
362 /** Clears the include stack in preperation for
367 /** Read the entire configuration into memory
368 * and initialize this class. All other methods
369 * should be used only by the core.
371 void Read(bool bail, userrec* user);
373 /** Read a file into a file_cache object
375 bool ReadFile(file_cache &F, const char* fname);
377 /** Load 'filename' into 'target', with the new config parser everything is parsed into
378 * tag/key/value at load-time rather than at read-value time.
380 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
381 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
383 /* Both these return true if the value existed or false otherwise */
385 /* Writes 'length' chars into 'result' as a string */
386 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
387 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
389 /* Tries to convert the value to an integer and write it to 'result' */
390 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
391 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
393 /* Returns true if the value exists and has a true value, false otherwise */
394 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
395 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
397 /* Returns the number of occurences of tag in the config file */
398 int ConfValueEnum(ConfigDataHash &target, const char* tag);
399 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
401 /* Returns the numbers of vars inside the index'th 'tag in the config file */
402 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
403 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
405 Module* GetIOHook(int port);
406 bool AddIOHook(int port, Module* iomod);
407 bool DelIOHook(int port);
410 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);