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 /** Types of data in the core config
36 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
38 /** Holds a config value, either string, integer or boolean.
39 * Callback functions receive one or more of these, either on
40 * their own as a reference, or in a reference to a deque of them.
41 * The callback function can then alter the values of the ValueItem
42 * classes to validate the settings.
49 ValueItem(bool value);
50 ValueItem(char* value);
51 void Set(char* value);
52 void Set(const char* val);
59 /** The base class of the container 'ValueContainer'
60 * used internally by the core to hold core values.
62 class ValueContainerBase
65 ValueContainerBase() { }
66 virtual ~ValueContainerBase() { }
69 /** ValueContainer is used to contain pointers to different
70 * core values such as the server name, maximum number of
72 * It is specialized to hold a data type, then pointed at
73 * a value in the ServerConfig class. When the value has been
74 * read and validated, the Set method is called to write the
75 * value safely in a type-safe manner.
77 template<typename T> class ValueContainer : public ValueContainerBase
93 void Set(T newval, size_t s)
95 memcpy(val, newval, s);
99 /** A specialization of ValueContainer to hold a pointer to a bool
101 typedef ValueContainer<bool*> ValueContainerBool;
103 /** A specialization of ValueContainer to hold a pointer to
106 typedef ValueContainer<unsigned int*> ValueContainerUInt;
108 /** A specialization of ValueContainer to hold a pointer to
111 typedef ValueContainer<char*> ValueContainerChar;
113 /** A specialization of ValueContainer to hold a pointer to
116 typedef ValueContainer<int*> ValueContainerInt;
118 /** A set of ValueItems used by multi-value validator functions
120 typedef std::deque<ValueItem> ValueList;
122 /** A callback for validating a single value
124 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, ValueItem&);
125 /** A callback for validating multiple value entries
127 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, ValueList&, int*);
128 /** A callback indicating the end of a group of entries
130 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
132 /** Holds a core configuration item and its callbacks
138 ValueContainerBase* val;
139 ConfigDataType datatype;
140 Validator validation_function;
143 /** Holds a core configuration item and its callbacks
144 * where there may be more than one item
151 MultiNotify init_function;
152 MultiValidator validation_function;
153 MultiNotify finish_function;
156 /** A set of oper types
158 typedef std::map<irc::string,char*> opertype_t;
160 /** A Set of oper classes
162 typedef std::map<irc::string,char*> operclass_t;
165 /** This class holds the bulk of the runtime configuration for the ircd.
166 * It allows for reading new config values, accessing configuration files,
167 * and storage of the configuration data needed to run the ircd, such as
168 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
170 class ServerConfig : public Extensible
175 InspIRCd* ServerInstance;
177 /** This variable holds the names of all
178 * files included from the main one. This
179 * is used to make sure that no files are
180 * recursively included.
182 std::vector<std::string> include_stack;
184 /** This private method processes one line of
185 * configutation, appending errors to errorstream
186 * and setting error if an error has occured.
188 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
190 /** Process an include directive
192 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
194 /** Check that there is only one of each configuration item
196 bool CheckOnce(char* tag, bool bail, userrec* user);
200 InspIRCd* GetInstance();
202 /** This holds all the information in the config file,
203 * it's indexed by tag name to a vector of key/values.
205 ConfigDataHash config_data;
207 /** Max number of WhoWas entries per user.
211 /** Max number of cumulative user-entries in WhoWas.
212 * When max reached and added to, push out oldest entry FIFO style.
216 /** Max seconds a user is kept in WhoWas before being pruned.
220 /** Holds the server name of the local server
221 * as defined by the administrator.
223 char ServerName[MAXBUF];
225 /* Holds the network name the local server
226 * belongs to. This is an arbitary field defined
227 * by the administrator.
229 char Network[MAXBUF];
231 /** Holds the description of the local server
232 * as defined by the administrator.
234 char ServerDesc[MAXBUF];
236 /** Holds the admin's name, for output in
237 * the /ADMIN command.
239 char AdminName[MAXBUF];
241 /** Holds the email address of the admin,
242 * for output in the /ADMIN command.
244 char AdminEmail[MAXBUF];
246 /** Holds the admin's nickname, for output
247 * in the /ADMIN command
249 char AdminNick[MAXBUF];
251 /** The admin-configured /DIE password
253 char diepass[MAXBUF];
255 /** The admin-configured /RESTART password
257 char restartpass[MAXBUF];
259 /** The pathname and filename of the message of the
260 * day file, as defined by the administrator.
264 /** The pathname and filename of the rules file,
265 * as defined by the administrator.
269 /** The quit prefix in use, or an empty string
271 char PrefixQuit[MAXBUF];
273 /** The last string found within a <die> tag, or
276 char DieValue[MAXBUF];
278 /** The DNS server to use for DNS queries
280 char DNSServer[MAXBUF];
282 /** This variable contains a space-seperated list
283 * of commands which are disabled by the
284 * administrator of the server for non-opers.
286 char DisabledCommands[MAXBUF];
288 /** The full path to the modules directory.
289 * This is either set at compile time, or
290 * overridden in the configuration file via
295 /** The temporary directory where modules are copied
299 /** The full pathname to the executable, as
300 * given in argv[0] when the program starts.
302 char MyExecutable[1024];
304 /** The file handle of the logfile. If this
305 * value is NULL, the log file is not open,
306 * probably due to a permissions error on
307 * startup (this should not happen in normal
312 /** If this value is true, the owner of the
313 * server specified -nofork on the command
314 * line, causing the daemon to stay in the
319 /** If this value if true then all log
320 * messages will be output, regardless of
321 * the level given in the config file.
322 * This is set with the -debug commandline
327 /** If this is true then log output will be
328 * written to the logfile. This is the default.
329 * If you put -nolog on the commandline then
330 * the logfile will not be written.
331 * This is meant to be used in conjunction with
332 * -debug for debugging without filling up the
337 /** If this value is true, halfops have been
338 * enabled in the configuration file.
342 /** The number of seconds the DNS subsystem
343 * will wait before timing out any request.
347 /** The size of the read() buffer in the user
348 * handling code, used to read data into a user's
353 /** The value to be used for listen() backlogs
358 /** The soft limit value assigned to the irc server.
359 * The IRC server will not allow more than this
360 * number of local users.
362 unsigned int SoftLimit;
364 /** Maximum number of targets for a multi target command
365 * such as PRIVMSG or KICK
367 unsigned int MaxTargets;
369 /** The maximum number of /WHO results allowed
370 * in any single /WHO command.
374 /** True if the DEBUG loglevel is selected.
378 /** The loglevel in use by the IRC server
382 /** How many seconds to wait before exiting
383 * the program when /DIE is correctly issued.
387 /** True if we're going to hide netsplits as *.net *.split for non-opers
391 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
396 /** If this is enabled then operators will
397 * see invisible (+i) channels in /whois.
401 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
403 char HideWhoisServer[MAXBUF];
405 /** A list of IP addresses the server is listening
408 char addrs[MAXBUF][255];
410 /** The MOTD file, cached in a file_cache type.
414 /** The RULES file, cached in a file_cache type.
418 /** The full pathname and filename of the PID
419 * file as defined in the configuration.
423 /** The connect classes in use by the IRC server.
427 /** A list of module names (names only, no paths)
428 * which are currently loaded by the server.
430 std::vector<std::string> module_names;
432 /** A list of ports which the server is listening on
436 /** A list of the file descriptors for the listening client ports
438 ListenSocket* openSockfd[255];
440 /** Boolean sets of which modules implement which functions
442 char implement_lists[255][255];
444 /** Global implementation list
446 char global_implementation[255];
448 /** A list of ports claimed by IO Modules
450 std::map<int,Module*> IOHookModule;
452 /** The 005 tokens of this server (ISUPPORT)
453 * populated/repopulated upon loading or unloading
458 /** STATS characters in this list are available
461 char UserStats[MAXBUF];
463 /** The path and filename of the ircd.log file
467 /** Custom version string, which if defined can replace the system info in VERSION.
469 char CustomVersion[MAXBUF];
471 /** List of u-lined servers
473 std::vector<irc::string> ulines;
475 /** Max banlist sizes for channels (the std::string is a glob)
477 std::map<std::string,int> maxbans;
479 /** If set to true, no user DNS lookups are to be performed
483 /** If set to true, provide syntax hints for unknown commands
487 /** If set to true, users appear to quit then rejoin when their hosts change.
488 * This keeps clients synchronized properly.
492 /** All oper type definitions from the config file
494 opertype_t opertypes;
496 /** All oper class definitions from the config file
498 operclass_t operclass;
500 /** Construct a new ServerConfig
502 ServerConfig(InspIRCd* Instance);
504 /** Clears the include stack in preperation for a Read() call.
508 /** Read the entire configuration into memory
509 * and initialize this class. All other methods
510 * should be used only by the core.
512 void Read(bool bail, userrec* user);
514 /** Read a file into a file_cache object
516 bool ReadFile(file_cache &F, const char* fname);
518 /** Load 'filename' into 'target', with the new config parser everything is parsed into
519 * tag/key/value at load-time rather than at read-value time.
521 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
522 /** Load 'filename' into 'target', with the new config parser everything is parsed into
523 * tag/key/value at load-time rather than at read-value time.
525 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
527 /* Both these return true if the value existed or false otherwise */
529 /** Writes 'length' chars into 'result' as a string
531 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
532 /** Writes 'length' chars into 'result' as a string
534 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
536 /** Tries to convert the value to an integer and write it to 'result'
538 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
539 /** Tries to convert the value to an integer and write it to 'result'
541 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
543 /** Returns true if the value exists and has a true value, false otherwise
545 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
546 /** Returns true if the value exists and has a true value, false otherwise
548 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
550 /** Returns the number of occurences of tag in the config file
552 int ConfValueEnum(ConfigDataHash &target, const char* tag);
553 /** Returns the number of occurences of tag in the config file
555 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
557 /** Returns the numbers of vars inside the index'th 'tag in the config file
559 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
560 /** Returns the numbers of vars inside the index'th 'tag in the config file
562 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
564 Module* GetIOHook(int port);
565 bool AddIOHook(int port, Module* iomod);
566 bool DelIOHook(int port);
568 static std::string GetFullProgDir(char** argv, int argc);
569 static bool DirValid(const char* dirandfile);
570 static char* CleanFilename(char* name);
571 static bool FileExists(const char* file);
575 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);
577 bool InitTypes(ServerConfig* conf, const char* tag);
578 bool InitClasses(ServerConfig* conf, const char* tag);
579 bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
580 bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
581 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag);