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 };
40 /** Holds a core configuration item and its callbacks
47 ConfigDataType datatype;
48 Validator validation_function;
51 /** Holds a core configuration item and its callbacks
52 * where there may be more than one item
59 MultiNotify init_function;
60 MultiValidator validation_function;
61 MultiNotify finish_function;
64 /** This class holds the bulk of the runtime configuration for the ircd.
65 * It allows for reading new config values, accessing configuration files,
66 * and storage of the configuration data needed to run the ircd, such as
67 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
69 class ServerConfig : public Extensible
72 InspIRCd* ServerInstance;
74 /** This variable holds the names of all
75 * files included from the main one. This
76 * is used to make sure that no files are
77 * recursively included.
79 std::vector<std::string> include_stack;
81 /** This private method processes one line of
82 * configutation, appending errors to errorstream
83 * and setting error if an error has occured.
85 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
87 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
89 /** Check that there is only one of each configuration item
91 bool CheckOnce(char* tag, bool bail, userrec* user);
95 InspIRCd* GetInstance();
97 /** This holds all the information in the config file,
98 * it's indexed by tag name to a vector of key/values.
100 ConfigDataHash config_data;
102 /** Holds the server name of the local server
103 * as defined by the administrator.
105 char ServerName[MAXBUF];
107 /* Holds the network name the local server
108 * belongs to. This is an arbitary field defined
109 * by the administrator.
111 char Network[MAXBUF];
113 /** Holds the description of the local server
114 * as defined by the administrator.
116 char ServerDesc[MAXBUF];
118 /** Holds the admin's name, for output in
119 * the /ADMIN command.
121 char AdminName[MAXBUF];
123 /** Holds the email address of the admin,
124 * for output in the /ADMIN command.
126 char AdminEmail[MAXBUF];
128 /** Holds the admin's nickname, for output
129 * in the /ADMIN command
131 char AdminNick[MAXBUF];
133 /** The admin-configured /DIE password
135 char diepass[MAXBUF];
137 /** The admin-configured /RESTART password
139 char restartpass[MAXBUF];
141 /** The pathname and filename of the message of the
142 * day file, as defined by the administrator.
146 /** The pathname and filename of the rules file,
147 * as defined by the administrator.
151 /** The quit prefix in use, or an empty string
153 char PrefixQuit[MAXBUF];
155 /** The last string found within a <die> tag, or
158 char DieValue[MAXBUF];
160 /** The DNS server to use for DNS queries
162 char DNSServer[MAXBUF];
164 /** This variable contains a space-seperated list
165 * of commands which are disabled by the
166 * administrator of the server for non-opers.
168 char DisabledCommands[MAXBUF];
170 /** The full path to the modules directory.
171 * This is either set at compile time, or
172 * overridden in the configuration file via
177 /** The temporary directory where modules are copied
181 /** The full pathname to the executable, as
182 * given in argv[0] when the program starts.
184 char MyExecutable[1024];
186 /** The file handle of the logfile. If this
187 * value is NULL, the log file is not open,
188 * probably due to a permissions error on
189 * startup (this should not happen in normal
194 /** If this value is true, the owner of the
195 * server specified -nofork on the command
196 * line, causing the daemon to stay in the
201 /** If this value if true then all log
202 * messages will be output, regardless of
203 * the level given in the config file.
204 * This is set with the -debug commandline
209 /** If this is true then log output will be
210 * written to the logfile. This is the default.
211 * If you put -nolog on the commandline then
212 * the logfile will not be written.
213 * This is meant to be used in conjunction with
214 * -debug for debugging without filling up the
219 /** If this value is true, halfops have been
220 * enabled in the configuration file.
224 /** The number of seconds the DNS subsystem
225 * will wait before timing out any request.
229 /** The size of the read() buffer in the user
230 * handling code, used to read data into a user's
235 /** The value to be used for listen() backlogs
240 /** The soft limit value assigned to the irc server.
241 * The IRC server will not allow more than this
242 * number of local users.
244 unsigned int SoftLimit;
246 /** Maximum number of targets for a multi target command
247 * such as PRIVMSG or KICK
249 unsigned int MaxTargets;
251 /** The maximum number of /WHO results allowed
252 * in any single /WHO command.
256 /** True if the DEBUG loglevel is selected.
260 /** The loglevel in use by the IRC server
264 /** How many seconds to wait before exiting
265 * the program when /DIE is correctly issued.
269 /** True if we're going to hide netsplits as *.net *.split for non-opers
273 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
278 /** If this is enabled then operators will
279 * see invisible (+i) channels in /whois.
283 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
285 char HideWhoisServer[MAXBUF];
287 /** A list of IP addresses the server is listening
290 char addrs[MAXBUF][255];
292 /** The MOTD file, cached in a file_cache type.
296 /** The RULES file, cached in a file_cache type.
300 /** The full pathname and filename of the PID
301 * file as defined in the configuration.
305 /** The connect classes in use by the IRC server.
309 /** A list of module names (names only, no paths)
310 * which are currently loaded by the server.
312 std::vector<std::string> module_names;
314 /** A list of ports which the server is listening on
318 /** A list of the file descriptors for the listening client ports
320 ListenSocket* openSockfd[255];
322 /** Boolean sets of which modules implement which functions
324 char implement_lists[255][255];
326 /** Global implementation list
328 char global_implementation[255];
330 /** A list of ports claimed by IO Modules
332 std::map<int,Module*> IOHookModule;
334 /** The 005 tokens of this server (ISUPPORT)
335 * populated/repopulated upon loading or unloading
340 /** STATS characters in this list are available
343 char OperOnlyStats[MAXBUF];
345 /** The path and filename of the ircd.log file
349 /** Custom version string, which if defined can replace the system info in VERSION.
351 char CustomVersion[MAXBUF];
353 /** List of u-lined servers
355 std::vector<irc::string> ulines;
357 /** Max banlist sizes for channels (the std::string is a glob)
359 std::map<std::string,int> maxbans;
361 /** If set to true, no user DNS lookups are to be performed
365 /** If set to true, provide syntax hints for unknown commands
369 /** If set to true, users appear to quit then rejoin when their hosts change.
370 * This keeps clients synchronized properly.
374 ServerConfig(InspIRCd* Instance);
376 /** Clears the include stack in preperation for a Read() call.
380 /** Read the entire configuration into memory
381 * and initialize this class. All other methods
382 * should be used only by the core.
384 void Read(bool bail, userrec* user);
386 /** Read a file into a file_cache object
388 bool ReadFile(file_cache &F, const char* fname);
390 /** Load 'filename' into 'target', with the new config parser everything is parsed into
391 * tag/key/value at load-time rather than at read-value time.
393 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
394 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
396 /* Both these return true if the value existed or false otherwise */
398 /* Writes 'length' chars into 'result' as a string */
399 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
400 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
402 /* Tries to convert the value to an integer and write it to 'result' */
403 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
404 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
406 /* Returns true if the value exists and has a true value, false otherwise */
407 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
408 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
410 /* Returns the number of occurences of tag in the config file */
411 int ConfValueEnum(ConfigDataHash &target, const char* tag);
412 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
414 /* Returns the numbers of vars inside the index'th 'tag in the config file */
415 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
416 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
418 Module* GetIOHook(int port);
419 bool AddIOHook(int port, Module* iomod);
420 bool DelIOHook(int port);
422 static std::string GetFullProgDir(char** argv, int argc);
423 static bool DirValid(const char* dirandfile);
424 static char* CleanFilename(char* name);
425 static bool FileExists(const char* file);
429 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);