1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #ifndef INSPIRCD_CONFIGREADER
15 #define INSPIRCD_CONFIGREADER
24 #include "socketengine.h"
31 /** Types of data in the core config
33 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
35 /** Holds a config value, either string, integer or boolean.
36 * Callback functions receive one or more of these, either on
37 * their own as a reference, or in a reference to a deque of them.
38 * The callback function can then alter the values of the ValueItem
39 * classes to validate the settings.
46 ValueItem(bool value);
47 ValueItem(char* value);
48 void Set(char* value);
49 void Set(const char* val);
56 /** The base class of the container 'ValueContainer'
57 * used internally by the core to hold core values.
59 class ValueContainerBase
62 ValueContainerBase() { }
63 virtual ~ValueContainerBase() { }
66 /** ValueContainer is used to contain pointers to different
67 * core values such as the server name, maximum number of
69 * It is specialized to hold a data type, then pointed at
70 * a value in the ServerConfig class. When the value has been
71 * read and validated, the Set method is called to write the
72 * value safely in a type-safe manner.
74 template<typename T> class ValueContainer : public ValueContainerBase
90 void Set(T newval, size_t s)
92 memcpy(val, newval, s);
96 /** A specialization of ValueContainer to hold a pointer to a bool
98 typedef ValueContainer<bool*> ValueContainerBool;
100 /** A specialization of ValueContainer to hold a pointer to
103 typedef ValueContainer<unsigned int*> ValueContainerUInt;
105 /** A specialization of ValueContainer to hold a pointer to
108 typedef ValueContainer<char*> ValueContainerChar;
110 /** A specialization of ValueContainer to hold a pointer to
113 typedef ValueContainer<int*> ValueContainerInt;
115 /** A set of ValueItems used by multi-value validator functions
117 typedef std::deque<ValueItem> ValueList;
119 /** A callback for validating a single value
121 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, ValueItem&);
122 /** A callback for validating multiple value entries
124 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, ValueList&, int*);
125 /** A callback indicating the end of a group of entries
127 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
129 /** Holds a core configuration item and its callbacks
135 ValueContainerBase* val;
136 ConfigDataType datatype;
137 Validator validation_function;
140 /** Holds a core configuration item and its callbacks
141 * where there may be more than one item
148 MultiNotify init_function;
149 MultiValidator validation_function;
150 MultiNotify finish_function;
153 /** A set of oper types
155 typedef std::map<irc::string,char*> opertype_t;
157 /** A Set of oper classes
159 typedef std::map<irc::string,char*> operclass_t;
162 /** This class holds the bulk of the runtime configuration for the ircd.
163 * It allows for reading new config values, accessing configuration files,
164 * and storage of the configuration data needed to run the ircd, such as
165 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
167 class ServerConfig : public Extensible
172 InspIRCd* ServerInstance;
174 /** This variable holds the names of all
175 * files included from the main one. This
176 * is used to make sure that no files are
177 * recursively included.
179 std::vector<std::string> include_stack;
181 /** This private method processes one line of
182 * configutation, appending errors to errorstream
183 * and setting error if an error has occured.
185 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
187 /** Process an include directive
189 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
191 /** Check that there is only one of each configuration item
193 bool CheckOnce(char* tag, bool bail, userrec* user);
197 InspIRCd* GetInstance();
199 /** This holds all the information in the config file,
200 * it's indexed by tag name to a vector of key/values.
202 ConfigDataHash config_data;
204 /** Max number of WhoWas entries per user.
208 /** Max number of cumulative user-entries in WhoWas.
209 * When max reached and added to, push out oldest entry FIFO style.
213 /** Max seconds a user is kept in WhoWas before being pruned.
217 /** Holds the server name of the local server
218 * as defined by the administrator.
220 char ServerName[MAXBUF];
222 /* Holds the network name the local server
223 * belongs to. This is an arbitary field defined
224 * by the administrator.
226 char Network[MAXBUF];
228 /** Holds the description of the local server
229 * as defined by the administrator.
231 char ServerDesc[MAXBUF];
233 /** Holds the admin's name, for output in
234 * the /ADMIN command.
236 char AdminName[MAXBUF];
238 /** Holds the email address of the admin,
239 * for output in the /ADMIN command.
241 char AdminEmail[MAXBUF];
243 /** Holds the admin's nickname, for output
244 * in the /ADMIN command
246 char AdminNick[MAXBUF];
248 /** The admin-configured /DIE password
250 char diepass[MAXBUF];
252 /** The admin-configured /RESTART password
254 char restartpass[MAXBUF];
256 /** The pathname and filename of the message of the
257 * day file, as defined by the administrator.
261 /** The pathname and filename of the rules file,
262 * as defined by the administrator.
266 /** The quit prefix in use, or an empty string
268 char PrefixQuit[MAXBUF];
270 /** The last string found within a <die> tag, or
273 char DieValue[MAXBUF];
275 /** The DNS server to use for DNS queries
277 char DNSServer[MAXBUF];
279 /** This variable contains a space-seperated list
280 * of commands which are disabled by the
281 * administrator of the server for non-opers.
283 char DisabledCommands[MAXBUF];
285 /** The full path to the modules directory.
286 * This is either set at compile time, or
287 * overridden in the configuration file via
292 /** The full pathname to the executable, as
293 * given in argv[0] when the program starts.
295 char MyExecutable[1024];
297 /** The file handle of the logfile. If this
298 * value is NULL, the log file is not open,
299 * probably due to a permissions error on
300 * startup (this should not happen in normal
305 /** If this value is true, the owner of the
306 * server specified -nofork on the command
307 * line, causing the daemon to stay in the
312 /** If this value if true then all log
313 * messages will be output, regardless of
314 * the level given in the config file.
315 * This is set with the -debug commandline
320 /** If this is true then log output will be
321 * written to the logfile. This is the default.
322 * If you put -nolog on the commandline then
323 * the logfile will not be written.
324 * This is meant to be used in conjunction with
325 * -debug for debugging without filling up the
330 /** If this value is true, halfops have been
331 * enabled in the configuration file.
335 /** The number of seconds the DNS subsystem
336 * will wait before timing out any request.
340 /** The size of the read() buffer in the user
341 * handling code, used to read data into a user's
346 /** The value to be used for listen() backlogs
351 /** The soft limit value assigned to the irc server.
352 * The IRC server will not allow more than this
353 * number of local users.
355 unsigned int SoftLimit;
357 /** Maximum number of targets for a multi target command
358 * such as PRIVMSG or KICK
360 unsigned int MaxTargets;
362 /** The maximum number of /WHO results allowed
363 * in any single /WHO command.
367 /** True if the DEBUG loglevel is selected.
371 /** The loglevel in use by the IRC server
375 /** How many seconds to wait before exiting
376 * the program when /DIE is correctly issued.
380 /** True if we're going to hide netsplits as *.net *.split for non-opers
384 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
389 /** If this is enabled then operators will
390 * see invisible (+i) channels in /whois.
394 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
396 char HideWhoisServer[MAXBUF];
398 /** A list of IP addresses the server is listening
401 char addrs[MAXBUF][255];
403 /** The MOTD file, cached in a file_cache type.
407 /** The RULES file, cached in a file_cache type.
411 /** The full pathname and filename of the PID
412 * file as defined in the configuration.
416 /** The connect classes in use by the IRC server.
420 /** A list of module names (names only, no paths)
421 * which are currently loaded by the server.
423 std::vector<std::string> module_names;
425 /** A list of ports which the server is listening on
429 /** A list of the file descriptors for the listening client ports
431 ListenSocket* openSockfd[255];
433 /** Boolean sets of which modules implement which functions
435 char implement_lists[255][255];
437 /** Global implementation list
439 char global_implementation[255];
441 /** A list of ports claimed by IO Modules
443 std::map<int,Module*> IOHookModule;
445 std::map<InspSocket*, Module*> SocketIOHookModule;
447 /** The 005 tokens of this server (ISUPPORT)
448 * populated/repopulated upon loading or unloading
452 std::vector<std::string> isupport;
454 /** STATS characters in this list are available
457 char UserStats[MAXBUF];
459 /** The path and filename of the ircd.log file
463 /** Custom version string, which if defined can replace the system info in VERSION.
465 char CustomVersion[MAXBUF];
467 /** List of u-lined servers
469 std::vector<irc::string> ulines;
471 /** Max banlist sizes for channels (the std::string is a glob)
473 std::map<std::string,int> maxbans;
475 /** If set to true, no user DNS lookups are to be performed
479 /** If set to true, provide syntax hints for unknown commands
483 /** If set to true, users appear to quit then rejoin when their hosts change.
484 * This keeps clients synchronized properly.
488 /** All oper type definitions from the config file
490 opertype_t opertypes;
492 /** All oper class definitions from the config file
494 operclass_t operclass;
496 /** Construct a new ServerConfig
498 ServerConfig(InspIRCd* Instance);
500 /** Clears the include stack in preperation for a Read() call.
504 /** Update the 005 vector
508 /** Send the 005 numerics (ISUPPORT) to a user
510 void Send005(userrec* user);
512 /** Read the entire configuration into memory
513 * and initialize this class. All other methods
514 * should be used only by the core.
516 void Read(bool bail, userrec* user);
518 /** Read a file into a file_cache object
520 bool ReadFile(file_cache &F, const char* fname);
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 char* filename, std::ostringstream &errorstream);
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 std::string &filename, std::ostringstream &errorstream);
531 /* Both these return true if the value existed or false otherwise */
533 /** Writes 'length' chars into 'result' as a string
535 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
536 /** Writes 'length' chars into 'result' as a string
538 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
540 /** Tries to convert the value to an integer and write it to 'result'
542 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
543 /** Tries to convert the value to an integer and write it to 'result'
545 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
547 /** Returns true if the value exists and has a true value, false otherwise
549 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
550 /** Returns true if the value exists and has a true value, false otherwise
552 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
554 /** Returns the number of occurences of tag in the config file
556 int ConfValueEnum(ConfigDataHash &target, const char* tag);
557 /** Returns the number of occurences of tag in the config file
559 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
561 /** Returns the numbers of vars inside the index'th 'tag in the config file
563 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
564 /** Returns the numbers of vars inside the index'th 'tag in the config file
566 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
568 Module* GetIOHook(int port);
569 bool AddIOHook(int port, Module* iomod);
570 bool DelIOHook(int port);
571 Module* GetIOHook(InspSocket* is);
572 bool AddIOHook(Module* iomod, InspSocket* is);
573 bool DelIOHook(InspSocket* is);
575 static std::string GetFullProgDir(char** argv, int argc);
576 static bool DirValid(const char* dirandfile);
577 static char* CleanFilename(char* name);
578 static bool FileExists(const char* file);
582 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);
584 bool InitTypes(ServerConfig* conf, const char* tag);
585 bool InitClasses(ServerConfig* conf, const char* tag);
586 bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
587 bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
588 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag);