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"
35 /** Types of data in the core config
37 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
39 /** Holds a config value, either string, integer or boolean.
40 * Callback functions receive one or more of these, either on
41 * their own as a reference, or in a reference to a deque of them.
42 * The callback function can then alter the values of the ValueItem
43 * classes to validate the settings.
50 ValueItem(bool value);
51 ValueItem(char* value);
52 void Set(char* value);
53 void Set(const char* val);
60 /** The base class of the container 'ValueContainer'
61 * used internally by the core to hold core values.
63 class ValueContainerBase
66 ValueContainerBase() { }
67 virtual ~ValueContainerBase() { }
70 /** ValueContainer is used to contain pointers to different
71 * core values such as the server name, maximum number of
73 * It is specialized to hold a data type, then pointed at
74 * a value in the ServerConfig class. When the value has been
75 * read and validated, the Set method is called to write the
76 * value safely in a type-safe manner.
78 template<typename T> class ValueContainer : public ValueContainerBase
94 void Set(T newval, size_t s)
96 memcpy(val, newval, s);
100 /** A specialization of ValueContainer to hold a pointer to a bool
102 typedef ValueContainer<bool*> ValueContainerBool;
104 /** A specialization of ValueContainer to hold a pointer to
107 typedef ValueContainer<unsigned int*> ValueContainerUInt;
109 /** A specialization of ValueContainer to hold a pointer to
112 typedef ValueContainer<char*> ValueContainerChar;
114 /** A specialization of ValueContainer to hold a pointer to
117 typedef ValueContainer<int*> ValueContainerInt;
119 /** A set of ValueItems used by multi-value validator functions
121 typedef std::deque<ValueItem> ValueList;
123 /** A callback for validating a single value
125 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, ValueItem&);
126 /** A callback for validating multiple value entries
128 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, ValueList&, int*);
129 /** A callback indicating the end of a group of entries
131 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
133 /** Holds a core configuration item and its callbacks
139 ValueContainerBase* val;
140 ConfigDataType datatype;
141 Validator validation_function;
144 /** Holds a core configuration item and its callbacks
145 * where there may be more than one item
152 MultiNotify init_function;
153 MultiValidator validation_function;
154 MultiNotify finish_function;
157 /** A set of oper types
159 typedef std::map<irc::string,char*> opertype_t;
161 /** A Set of oper classes
163 typedef std::map<irc::string,char*> operclass_t;
166 /** This class holds the bulk of the runtime configuration for the ircd.
167 * It allows for reading new config values, accessing configuration files,
168 * and storage of the configuration data needed to run the ircd, such as
169 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
171 class ServerConfig : public Extensible
176 InspIRCd* ServerInstance;
178 /** This variable holds the names of all
179 * files included from the main one. This
180 * is used to make sure that no files are
181 * recursively included.
183 std::vector<std::string> include_stack;
185 /** This private method processes one line of
186 * configutation, appending errors to errorstream
187 * and setting error if an error has occured.
189 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
191 /** Process an include directive
193 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
195 /** Check that there is only one of each configuration item
197 bool CheckOnce(char* tag, bool bail, userrec* user);
201 InspIRCd* GetInstance();
203 /** This holds all the information in the config file,
204 * it's indexed by tag name to a vector of key/values.
206 ConfigDataHash config_data;
208 /** Max number of WhoWas entries per user.
212 /** Max number of cumulative user-entries in WhoWas.
213 * When max reached and added to, push out oldest entry FIFO style.
217 /** Max seconds a user is kept in WhoWas before being pruned.
221 /** Holds the server name of the local server
222 * as defined by the administrator.
224 char ServerName[MAXBUF];
226 /* Holds the network name the local server
227 * belongs to. This is an arbitary field defined
228 * by the administrator.
230 char Network[MAXBUF];
232 /** Holds the description of the local server
233 * as defined by the administrator.
235 char ServerDesc[MAXBUF];
237 /** Holds the admin's name, for output in
238 * the /ADMIN command.
240 char AdminName[MAXBUF];
242 /** Holds the email address of the admin,
243 * for output in the /ADMIN command.
245 char AdminEmail[MAXBUF];
247 /** Holds the admin's nickname, for output
248 * in the /ADMIN command
250 char AdminNick[MAXBUF];
252 /** The admin-configured /DIE password
254 char diepass[MAXBUF];
256 /** The admin-configured /RESTART password
258 char restartpass[MAXBUF];
260 /** The pathname and filename of the message of the
261 * day file, as defined by the administrator.
265 /** The pathname and filename of the rules file,
266 * as defined by the administrator.
270 /** The quit prefix in use, or an empty string
272 char PrefixQuit[MAXBUF];
274 /** The last string found within a <die> tag, or
277 char DieValue[MAXBUF];
279 /** The DNS server to use for DNS queries
281 char DNSServer[MAXBUF];
283 /** This variable contains a space-seperated list
284 * of commands which are disabled by the
285 * administrator of the server for non-opers.
287 char DisabledCommands[MAXBUF];
289 /** The full path to the modules directory.
290 * This is either set at compile time, or
291 * overridden in the configuration file via
296 /** The full pathname to the executable, as
297 * given in argv[0] when the program starts.
299 char MyExecutable[1024];
301 /** The file handle of the logfile. If this
302 * value is NULL, the log file is not open,
303 * probably due to a permissions error on
304 * startup (this should not happen in normal
309 /** If this value is true, the owner of the
310 * server specified -nofork on the command
311 * line, causing the daemon to stay in the
316 /** If this value if true then all log
317 * messages will be output, regardless of
318 * the level given in the config file.
319 * This is set with the -debug commandline
324 /** If this is true then log output will be
325 * written to the logfile. This is the default.
326 * If you put -nolog on the commandline then
327 * the logfile will not be written.
328 * This is meant to be used in conjunction with
329 * -debug for debugging without filling up the
334 /** If this value is true, halfops have been
335 * enabled in the configuration file.
339 /** The number of seconds the DNS subsystem
340 * will wait before timing out any request.
344 /** The size of the read() buffer in the user
345 * handling code, used to read data into a user's
350 /** The value to be used for listen() backlogs
355 /** The soft limit value assigned to the irc server.
356 * The IRC server will not allow more than this
357 * number of local users.
359 unsigned int SoftLimit;
361 /** Maximum number of targets for a multi target command
362 * such as PRIVMSG or KICK
364 unsigned int MaxTargets;
366 /** The maximum number of /WHO results allowed
367 * in any single /WHO command.
371 /** True if the DEBUG loglevel is selected.
375 /** The loglevel in use by the IRC server
379 /** How many seconds to wait before exiting
380 * the program when /DIE is correctly issued.
384 /** True if we're going to hide netsplits as *.net *.split for non-opers
388 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
393 /** If this is enabled then operators will
394 * see invisible (+i) channels in /whois.
398 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
400 char HideWhoisServer[MAXBUF];
402 /** A list of IP addresses the server is listening
405 char addrs[MAXBUF][255];
407 /** The MOTD file, cached in a file_cache type.
411 /** The RULES file, cached in a file_cache type.
415 /** The full pathname and filename of the PID
416 * file as defined in the configuration.
420 /** The connect classes in use by the IRC server.
424 /** A list of module names (names only, no paths)
425 * which are currently loaded by the server.
427 std::vector<std::string> module_names;
429 /** A list of ports which the server is listening on
433 /** A list of the file descriptors for the listening client ports
435 ListenSocket* openSockfd[255];
437 /** Boolean sets of which modules implement which functions
439 char implement_lists[255][255];
441 /** Global implementation list
443 char global_implementation[255];
445 /** A list of ports claimed by IO Modules
447 std::map<int,Module*> IOHookModule;
449 std::map<InspSocket*, Module*> SocketIOHookModule;
451 /** The 005 tokens of this server (ISUPPORT)
452 * populated/repopulated upon loading or unloading
456 std::vector<std::string> isupport;
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 /** Update the 005 vector
512 /** Send the 005 numerics (ISUPPORT) to a user
514 void Send005(userrec* user);
516 /** Read the entire configuration into memory
517 * and initialize this class. All other methods
518 * should be used only by the core.
520 void Read(bool bail, userrec* user);
522 /** Read a file into a file_cache object
524 bool ReadFile(file_cache &F, const char* fname);
526 /** Load 'filename' into 'target', with the new config parser everything is parsed into
527 * tag/key/value at load-time rather than at read-value time.
529 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
530 /** Load 'filename' into 'target', with the new config parser everything is parsed into
531 * tag/key/value at load-time rather than at read-value time.
533 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
535 /* Both these return true if the value existed or false otherwise */
537 /** Writes 'length' chars into 'result' as a string
539 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
540 /** Writes 'length' chars into 'result' as a string
542 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
544 /** Tries to convert the value to an integer and write it to 'result'
546 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
547 /** Tries to convert the value to an integer and write it to 'result'
549 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
551 /** Returns true if the value exists and has a true value, false otherwise
553 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
554 /** Returns true if the value exists and has a true value, false otherwise
556 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
558 /** Returns the number of occurences of tag in the config file
560 int ConfValueEnum(ConfigDataHash &target, const char* tag);
561 /** Returns the number of occurences of tag in the config file
563 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
565 /** Returns the numbers of vars inside the index'th 'tag in the config file
567 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
568 /** Returns the numbers of vars inside the index'th 'tag in the config file
570 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
572 Module* GetIOHook(int port);
573 bool AddIOHook(int port, Module* iomod);
574 bool DelIOHook(int port);
575 Module* GetIOHook(InspSocket* is);
576 bool AddIOHook(Module* iomod, InspSocket* is);
577 bool DelIOHook(InspSocket* is);
579 static std::string GetFullProgDir(char** argv, int argc);
580 static bool DirValid(const char* dirandfile);
581 static char* CleanFilename(char* name);
582 static bool FileExists(const char* file);
586 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);
588 bool InitTypes(ServerConfig* conf, const char* tag);
589 bool InitClasses(ServerConfig* conf, const char* tag);
590 bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
591 bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
592 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag);