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 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, void*);
35 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, void**, int*);
36 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
38 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
45 ConfigDataType datatype;
46 Validator validation_function;
54 MultiNotify init_function;
55 MultiValidator validation_function;
56 MultiNotify finish_function;
59 /** This class holds the bulk of the runtime configuration for the ircd.
60 * It allows for reading new config values, accessing configuration files,
61 * and storage of the configuration data needed to run the ircd, such as
62 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
64 class ServerConfig : public Extensible
67 InspIRCd* ServerInstance;
69 /** This variable holds the names of all
70 * files included from the main one. This
71 * is used to make sure that no files are
72 * recursively included.
74 std::vector<std::string> include_stack;
76 /** This private method processes one line of
77 * configutation, appending errors to errorstream
78 * and setting error if an error has occured.
80 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
82 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
84 /** Check that there is only one of each configuration item
86 bool CheckOnce(char* tag, bool bail, userrec* user);
90 InspIRCd* GetInstance();
92 /** This holds all the information in the config file,
93 * it's indexed by tag name to a vector of key/values.
95 ConfigDataHash config_data;
97 /** Holds the server name of the local server
98 * as defined by the administrator.
100 char ServerName[MAXBUF];
102 /* Holds the network name the local server
103 * belongs to. This is an arbitary field defined
104 * by the administrator.
106 char Network[MAXBUF];
108 /** Holds the description of the local server
109 * as defined by the administrator.
111 char ServerDesc[MAXBUF];
113 /** Holds the admin's name, for output in
114 * the /ADMIN command.
116 char AdminName[MAXBUF];
118 /** Holds the email address of the admin,
119 * for output in the /ADMIN command.
121 char AdminEmail[MAXBUF];
123 /** Holds the admin's nickname, for output
124 * in the /ADMIN command
126 char AdminNick[MAXBUF];
128 /** The admin-configured /DIE password
130 char diepass[MAXBUF];
132 /** The admin-configured /RESTART password
134 char restartpass[MAXBUF];
136 /** The pathname and filename of the message of the
137 * day file, as defined by the administrator.
141 /** The pathname and filename of the rules file,
142 * as defined by the administrator.
146 /** The quit prefix in use, or an empty string
148 char PrefixQuit[MAXBUF];
150 /** The last string found within a <die> tag, or
153 char DieValue[MAXBUF];
155 /** The DNS server to use for DNS queries
157 char DNSServer[MAXBUF];
159 /** This variable contains a space-seperated list
160 * of commands which are disabled by the
161 * administrator of the server for non-opers.
163 char DisabledCommands[MAXBUF];
165 /** The full path to the modules directory.
166 * This is either set at compile time, or
167 * overridden in the configuration file via
172 /** The temporary directory where modules are copied
176 /** The full pathname to the executable, as
177 * given in argv[0] when the program starts.
179 char MyExecutable[1024];
181 /** The file handle of the logfile. If this
182 * value is NULL, the log file is not open,
183 * probably due to a permissions error on
184 * startup (this should not happen in normal
189 /** If this value is true, the owner of the
190 * server specified -nofork on the command
191 * line, causing the daemon to stay in the
196 /** If this value if true then all log
197 * messages will be output, regardless of
198 * the level given in the config file.
199 * This is set with the -debug commandline
204 /** If this is true then log output will be
205 * written to the logfile. This is the default.
206 * If you put -nolog on the commandline then
207 * the logfile will not be written.
208 * This is meant to be used in conjunction with
209 * -debug for debugging without filling up the
214 /** If this value is true, halfops have been
215 * enabled in the configuration file.
219 /** The number of seconds the DNS subsystem
220 * will wait before timing out any request.
224 /** The size of the read() buffer in the user
225 * handling code, used to read data into a user's
230 /** The value to be used for listen() backlogs
235 /** The soft limit value assigned to the irc server.
236 * The IRC server will not allow more than this
237 * number of local users.
239 unsigned int SoftLimit;
241 /** Maximum number of targets for a multi target command
242 * such as PRIVMSG or KICK
244 unsigned int MaxTargets;
246 /** The maximum number of /WHO results allowed
247 * in any single /WHO command.
251 /** True if the DEBUG loglevel is selected.
255 /** The loglevel in use by the IRC server
259 /** How many seconds to wait before exiting
260 * the program when /DIE is correctly issued.
264 /** True if we're going to hide netsplits as *.net *.split for non-opers
268 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
273 /** If this is enabled then operators will
274 * see invisible (+i) channels in /whois.
278 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
280 char HideWhoisServer[MAXBUF];
282 /** A list of IP addresses the server is listening
285 char addrs[MAXBUF][255];
287 /** The MOTD file, cached in a file_cache type.
291 /** The RULES file, cached in a file_cache type.
295 /** The full pathname and filename of the PID
296 * file as defined in the configuration.
300 /** The connect classes in use by the IRC server.
304 /** A list of module names (names only, no paths)
305 * which are currently loaded by the server.
307 std::vector<std::string> module_names;
309 /** A list of ports which the server is listening on
313 /** A list of the file descriptors for the listening client ports
315 ListenSocket* openSockfd[255];
317 /** Boolean sets of which modules implement which functions
319 char implement_lists[255][255];
321 /** Global implementation list
323 char global_implementation[255];
325 /** A list of ports claimed by IO Modules
327 std::map<int,Module*> IOHookModule;
329 /** The 005 tokens of this server (ISUPPORT)
330 * populated/repopulated upon loading or unloading
335 /** STATS characters in this list are available
338 char OperOnlyStats[MAXBUF];
340 /** The path and filename of the ircd.log file
344 /** Custom version string, which if defined can replace the system info in VERSION.
346 char CustomVersion[MAXBUF];
348 /** List of u-lined servers
350 std::vector<irc::string> ulines;
352 /** Max banlist sizes for channels (the std::string is a glob)
354 std::map<std::string,int> maxbans;
356 /** If set to true, no user DNS lookups are to be performed
360 /** If set to true, provide syntax hints for unknown commands
364 ServerConfig(InspIRCd* Instance);
366 /** Clears the include stack in preperation for
371 /** Read the entire configuration into memory
372 * and initialize this class. All other methods
373 * should be used only by the core.
375 void Read(bool bail, userrec* user);
377 /** Read a file into a file_cache object
379 bool ReadFile(file_cache &F, const char* fname);
381 /** Load 'filename' into 'target', with the new config parser everything is parsed into
382 * tag/key/value at load-time rather than at read-value time.
384 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
385 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
387 /* Both these return true if the value existed or false otherwise */
389 /* Writes 'length' chars into 'result' as a string */
390 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
391 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
393 /* Tries to convert the value to an integer and write it to 'result' */
394 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
395 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
397 /* Returns true if the value exists and has a true value, false otherwise */
398 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
399 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
401 /* Returns the number of occurences of tag in the config file */
402 int ConfValueEnum(ConfigDataHash &target, const char* tag);
403 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
405 /* Returns the numbers of vars inside the index'th 'tag in the config file */
406 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
407 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
409 Module* GetIOHook(int port);
410 bool AddIOHook(int port, Module* iomod);
411 bool DelIOHook(int port);
413 static std::string GetFullProgDir(char** argv, int argc);
414 static bool DirValid(const char* dirandfile);
415 static char* CleanFilename(char* name);
416 static bool FileExists(const char* file);
420 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);