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>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #ifndef __INSPIRCD_IO_H__
18 #define __INSPIRCD_IO_H__
27 /** Flags for use with log()
35 typedef bool (*Validator)(const char*, const char*, void*);
36 typedef bool (*MultiValidator)(const char*, char**, void**, int*);
37 typedef bool (*MultiNotify)(const char*);
39 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
41 struct InitialConfig {
45 ConfigDataType datatype;
46 Validator validation_function;
53 MultiNotify init_function;
54 MultiValidator validation_function;
55 MultiNotify finish_function;
58 /** This class holds the bulk of the runtime configuration for the ircd.
59 * It allows for reading new config values, accessing configuration files,
60 * and storage of the configuration data needed to run the ircd, such as
61 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
63 class ServerConfig : public classbase
66 /** This variable holds the names of all
67 * files included from the main one. This
68 * is used to make sure that no files are
69 * recursively included.
71 std::vector<std::string> include_stack;
73 /** Used by the config file subsystem to
74 * safely read a C-style string without
75 * dependency upon any certain style of
76 * linefeed, e.g. it can read both windows
77 * and UNIX style linefeeds transparently.
79 int fgets_safe(char* buffer, size_t maxsize, FILE* &file);
81 /** This private method processes one line of
82 * configutation, appending errors to errorstream
83 * and setting error if an error has occured.
85 std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errorstream, bool &error, std::string filename);
87 /** Check that there is only one of each configuration item
89 bool CheckOnce(char* tag, bool bail, userrec* user);
93 /** Holds the server name of the local server
94 * as defined by the administrator.
96 char ServerName[MAXBUF];
98 /* Holds the network name the local server
99 * belongs to. This is an arbitary field defined
100 * by the administrator.
102 char Network[MAXBUF];
104 /** Holds the description of the local server
105 * as defined by the administrator.
107 char ServerDesc[MAXBUF];
109 /** Holds the admin's name, for output in
110 * the /ADMIN command.
112 char AdminName[MAXBUF];
114 /** Holds the email address of the admin,
115 * for output in the /ADMIN command.
117 char AdminEmail[MAXBUF];
119 /** Holds the admin's nickname, for output
120 * in the /ADMIN command
122 char AdminNick[MAXBUF];
124 /** The admin-configured /DIE password
126 char diepass[MAXBUF];
128 /** The admin-configured /RESTART password
130 char restartpass[MAXBUF];
132 /** The pathname and filename of the message of the
133 * day file, as defined by the administrator.
137 /** The pathname and filename of the rules file,
138 * as defined by the administrator.
142 /** The quit prefix in use, or an empty string
144 char PrefixQuit[MAXBUF];
146 /** The last string found within a <die> tag, or
149 char DieValue[MAXBUF];
151 /** The DNS server to use for DNS queries
153 char DNSServer[MAXBUF];
155 /** This variable contains a space-seperated list
156 * of commands which are disabled by the
157 * administrator of the server for non-opers.
159 char DisabledCommands[MAXBUF];
161 /** The full path to the modules directory.
162 * This is either set at compile time, or
163 * overridden in the configuration file via
168 /** The temporary directory where modules are copied
172 /** The full pathname to the executable, as
173 * given in argv[0] when the program starts.
175 char MyExecutable[1024];
177 /** The file handle of the logfile. If this
178 * value is NULL, the log file is not open,
179 * probably due to a permissions error on
180 * startup (this should not happen in normal
185 /** If this value is true, the owner of the
186 * server specified -nofork on the command
187 * line, causing the daemon to stay in the
192 /** If this value is true, halfops have been
193 * enabled in the configuration file.
197 /** The number of seconds the DNS subsystem
198 * will wait before timing out any request.
202 /** The size of the read() buffer in the user
203 * handling code, used to read data into a user's
208 /** The value to be used for listen() backlogs
213 /** The soft limit value assigned to the irc server.
214 * The IRC server will not allow more than this
215 * number of local users.
217 unsigned int SoftLimit;
219 /** Maximum number of targets for a multi target command
220 * such as PRIVMSG or KICK
222 unsigned int MaxTargets;
224 /** The maximum number of /WHO results allowed
225 * in any single /WHO command.
229 /** True if the DEBUG loglevel is selected.
233 /** The loglevel in use by the IRC server
237 /** How many seconds to wait before exiting
238 * the program when /DIE is correctly issued.
242 /** True if we're going to hide netsplits as *.net *.split for non-opers
246 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
251 /** If this is enabled then operators will
252 * see invisible (+i) channels in /whois.
256 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
258 char HideWhoisServer[MAXBUF];
260 /** A list of IP addresses the server is listening
263 char addrs[MAXBUF][255];
265 /** The MOTD file, cached in a file_cache type.
269 /** The RULES file, cached in a file_cache type.
273 /** The full pathname and filename of the PID
274 * file as defined in the configuration.
278 /** The parsed configuration file as a stringstream.
279 * You should pass this to any configuration methods
280 * of this class, and not access it directly. It is
281 * recommended that modules use ConfigReader instead
282 * which provides a simpler abstraction of configuration
285 std::stringstream config_f;
287 /** The connect classes in use by the IRC server.
291 /** A list of module names (names only, no paths)
292 * which are currently loaded by the server.
294 std::vector<std::string> module_names;
296 /** A list of ports which the server is listening on
300 /** Boolean sets of which modules implement which functions
302 char implement_lists[255][255];
304 /** Global implementation list
306 char global_implementation[255];
308 /** A list of ports claimed by IO Modules
310 std::map<int,Module*> IOHookModule;
312 /** The 005 tokens of this server (ISUPPORT)
313 * populated/repopulated upon loading or unloading
318 /** STATS characters in this list are available
321 char OperOnlyStats[MAXBUF];
323 /** The path and filename of the ircd.log file
327 /** Custom version string, which if defined can replace the system info in VERSION.
329 char CustomVersion[MAXBUF];
331 /** List of u-lined servers
333 std::vector<irc::string> ulines;
335 /** Max banlist sizes for channels (the std::string is a glob)
337 std::map<std::string,int> maxbans;
341 /** Clears the include stack in preperation for
346 /** Read the entire configuration into memory
347 * and initialize this class. All other methods
348 * should be used only by the core.
350 void Read(bool bail, userrec* user);
352 bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
353 int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
354 int ConfValueInteger(char* tag, char* var, int index, std::stringstream *config);
355 int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
356 int ConfValueEnum(char* tag,std::stringstream *config);
357 int EnumConf(std::stringstream *config_f,const char* tag);
358 int EnumValues(std::stringstream *config, const char* tag, int index);
359 Module* GetIOHook(int port);
360 bool AddIOHook(int port, Module* iomod);
361 bool DelIOHook(int port);
365 void Exit(int status);
369 bool FileExists(const char* file);
371 bool BindSocket(int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
372 void WritePID(const std::string &filename);
373 int BindPorts(bool bail);
374 char* CleanFilename(char* name);