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 };
56 ValueItem(char* value)
66 void Set(const char* value)
80 return atoi(v.c_str());
85 return (char*)v.c_str();
90 return (GetInteger() || v == "yes" || v == "true");
94 class ValueContainerBase
101 virtual ~ValueContainerBase()
106 template<typename T> class ValueContainer : public ValueContainerBase
117 ValueContainer(T Val)
122 void Set(T newval, size_t s)
124 memcpy(val, newval, s);
128 typedef ValueContainer<bool*> ValueContainerBool;
129 typedef ValueContainer<unsigned int*> ValueContainerUInt;
130 typedef ValueContainer<char*> ValueContainerChar;
131 typedef ValueContainer<int*> ValueContainerInt;
133 typedef std::deque<ValueItem> ValueList;
135 /** A callback for validating a single value
137 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, ValueItem&);
138 /** A callback for validating multiple value entries
140 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, ValueList&, int*);
141 /** A callback indicating the end of a group of entries
143 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
146 /** Holds a core configuration item and its callbacks
152 ValueContainerBase* val;
153 ConfigDataType datatype;
154 Validator validation_function;
157 /** Holds a core configuration item and its callbacks
158 * where there may be more than one item
165 MultiNotify init_function;
166 MultiValidator validation_function;
167 MultiNotify finish_function;
170 /** A set of oper types
172 typedef std::map<irc::string,char*> opertype_t;
174 /** A Set of oper classes
176 typedef std::map<irc::string,char*> operclass_t;
179 /** This class holds the bulk of the runtime configuration for the ircd.
180 * It allows for reading new config values, accessing configuration files,
181 * and storage of the configuration data needed to run the ircd, such as
182 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
184 class ServerConfig : public Extensible
189 InspIRCd* ServerInstance;
191 /** This variable holds the names of all
192 * files included from the main one. This
193 * is used to make sure that no files are
194 * recursively included.
196 std::vector<std::string> include_stack;
198 /** This private method processes one line of
199 * configutation, appending errors to errorstream
200 * and setting error if an error has occured.
202 bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream);
204 /** Process an include directive
206 bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
208 /** Check that there is only one of each configuration item
210 bool CheckOnce(char* tag, bool bail, userrec* user);
214 InspIRCd* GetInstance();
216 /** This holds all the information in the config file,
217 * it's indexed by tag name to a vector of key/values.
219 ConfigDataHash config_data;
221 /** Max number of WhoWas entries per user.
225 /** Max number of cumulative user-entries in WhoWas.
226 * When max reached and added to, push out oldest entry FIFO style.
230 /** Max seconds a user is kept in WhoWas before being pruned.
234 /** Holds the server name of the local server
235 * as defined by the administrator.
237 char ServerName[MAXBUF];
239 /* Holds the network name the local server
240 * belongs to. This is an arbitary field defined
241 * by the administrator.
243 char Network[MAXBUF];
245 /** Holds the description of the local server
246 * as defined by the administrator.
248 char ServerDesc[MAXBUF];
250 /** Holds the admin's name, for output in
251 * the /ADMIN command.
253 char AdminName[MAXBUF];
255 /** Holds the email address of the admin,
256 * for output in the /ADMIN command.
258 char AdminEmail[MAXBUF];
260 /** Holds the admin's nickname, for output
261 * in the /ADMIN command
263 char AdminNick[MAXBUF];
265 /** The admin-configured /DIE password
267 char diepass[MAXBUF];
269 /** The admin-configured /RESTART password
271 char restartpass[MAXBUF];
273 /** The pathname and filename of the message of the
274 * day file, as defined by the administrator.
278 /** The pathname and filename of the rules file,
279 * as defined by the administrator.
283 /** The quit prefix in use, or an empty string
285 char PrefixQuit[MAXBUF];
287 /** The last string found within a <die> tag, or
290 char DieValue[MAXBUF];
292 /** The DNS server to use for DNS queries
294 char DNSServer[MAXBUF];
296 /** This variable contains a space-seperated list
297 * of commands which are disabled by the
298 * administrator of the server for non-opers.
300 char DisabledCommands[MAXBUF];
302 /** The full path to the modules directory.
303 * This is either set at compile time, or
304 * overridden in the configuration file via
309 /** The temporary directory where modules are copied
313 /** The full pathname to the executable, as
314 * given in argv[0] when the program starts.
316 char MyExecutable[1024];
318 /** The file handle of the logfile. If this
319 * value is NULL, the log file is not open,
320 * probably due to a permissions error on
321 * startup (this should not happen in normal
326 /** If this value is true, the owner of the
327 * server specified -nofork on the command
328 * line, causing the daemon to stay in the
333 /** If this value if true then all log
334 * messages will be output, regardless of
335 * the level given in the config file.
336 * This is set with the -debug commandline
341 /** If this is true then log output will be
342 * written to the logfile. This is the default.
343 * If you put -nolog on the commandline then
344 * the logfile will not be written.
345 * This is meant to be used in conjunction with
346 * -debug for debugging without filling up the
351 /** If this value is true, halfops have been
352 * enabled in the configuration file.
356 /** The number of seconds the DNS subsystem
357 * will wait before timing out any request.
361 /** The size of the read() buffer in the user
362 * handling code, used to read data into a user's
367 /** The value to be used for listen() backlogs
372 /** The soft limit value assigned to the irc server.
373 * The IRC server will not allow more than this
374 * number of local users.
376 unsigned int SoftLimit;
378 /** Maximum number of targets for a multi target command
379 * such as PRIVMSG or KICK
381 unsigned int MaxTargets;
383 /** The maximum number of /WHO results allowed
384 * in any single /WHO command.
388 /** True if the DEBUG loglevel is selected.
392 /** The loglevel in use by the IRC server
396 /** How many seconds to wait before exiting
397 * the program when /DIE is correctly issued.
401 /** True if we're going to hide netsplits as *.net *.split for non-opers
405 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
410 /** If this is enabled then operators will
411 * see invisible (+i) channels in /whois.
415 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
417 char HideWhoisServer[MAXBUF];
419 /** A list of IP addresses the server is listening
422 char addrs[MAXBUF][255];
424 /** The MOTD file, cached in a file_cache type.
428 /** The RULES file, cached in a file_cache type.
432 /** The full pathname and filename of the PID
433 * file as defined in the configuration.
437 /** The connect classes in use by the IRC server.
441 /** A list of module names (names only, no paths)
442 * which are currently loaded by the server.
444 std::vector<std::string> module_names;
446 /** A list of ports which the server is listening on
450 /** A list of the file descriptors for the listening client ports
452 ListenSocket* openSockfd[255];
454 /** Boolean sets of which modules implement which functions
456 char implement_lists[255][255];
458 /** Global implementation list
460 char global_implementation[255];
462 /** A list of ports claimed by IO Modules
464 std::map<int,Module*> IOHookModule;
466 /** The 005 tokens of this server (ISUPPORT)
467 * populated/repopulated upon loading or unloading
472 /** STATS characters in this list are available
475 char UserStats[MAXBUF];
477 /** The path and filename of the ircd.log file
481 /** Custom version string, which if defined can replace the system info in VERSION.
483 char CustomVersion[MAXBUF];
485 /** List of u-lined servers
487 std::vector<irc::string> ulines;
489 /** Max banlist sizes for channels (the std::string is a glob)
491 std::map<std::string,int> maxbans;
493 /** If set to true, no user DNS lookups are to be performed
497 /** If set to true, provide syntax hints for unknown commands
501 /** If set to true, users appear to quit then rejoin when their hosts change.
502 * This keeps clients synchronized properly.
506 /** All oper type definitions from the config file
508 opertype_t opertypes;
510 /** All oper class definitions from the config file
512 operclass_t operclass;
514 /** Construct a new ServerConfig
516 ServerConfig(InspIRCd* Instance);
518 /** Clears the include stack in preperation for a Read() call.
522 /** Read the entire configuration into memory
523 * and initialize this class. All other methods
524 * should be used only by the core.
526 void Read(bool bail, userrec* user);
528 /** Read a file into a file_cache object
530 bool ReadFile(file_cache &F, const char* fname);
532 /** Load 'filename' into 'target', with the new config parser everything is parsed into
533 * tag/key/value at load-time rather than at read-value time.
535 bool LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream);
536 /** Load 'filename' into 'target', with the new config parser everything is parsed into
537 * tag/key/value at load-time rather than at read-value time.
539 bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream);
541 /* Both these return true if the value existed or false otherwise */
543 /** Writes 'length' chars into 'result' as a string
545 bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length);
546 /** Writes 'length' chars into 'result' as a string
548 bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result);
550 /** Tries to convert the value to an integer and write it to 'result'
552 bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
553 /** Tries to convert the value to an integer and write it to 'result'
555 bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
557 /** Returns true if the value exists and has a true value, false otherwise
559 bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
560 /** Returns true if the value exists and has a true value, false otherwise
562 bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
564 /** Returns the number of occurences of tag in the config file
566 int ConfValueEnum(ConfigDataHash &target, const char* tag);
567 /** Returns the number of occurences of tag in the config file
569 int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
571 /** Returns the numbers of vars inside the index'th 'tag in the config file
573 int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
574 /** Returns the numbers of vars inside the index'th 'tag in the config file
576 int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
578 Module* GetIOHook(int port);
579 bool AddIOHook(int port, Module* iomod);
580 bool DelIOHook(int port);
582 static std::string GetFullProgDir(char** argv, int argc);
583 static bool DirValid(const char* dirandfile);
584 static char* CleanFilename(char* name);
585 static bool FileExists(const char* file);
589 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);
591 bool InitTypes(ServerConfig* conf, const char* tag);
592 bool InitClasses(ServerConfig* conf, const char* tag);
593 bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
594 bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
595 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag);