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*, const char**, void**, int**);
38 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
40 struct InitialConfig {
44 ConfigDataType datatype;
45 Validator validation_function;
52 ConfigDataType** datatype;
53 MultiValidator validation_function;
56 /** This class holds the bulk of the runtime configuration for the ircd.
57 * It allows for reading new config values, accessing configuration files,
58 * and storage of the configuration data needed to run the ircd, such as
59 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
61 class ServerConfig : public classbase
64 /** This variable holds the names of all
65 * files included from the main one. This
66 * is used to make sure that no files are
67 * recursively included.
69 std::vector<std::string> include_stack;
71 /** Used by the config file subsystem to
72 * safely read a C-style string without
73 * dependency upon any certain style of
74 * linefeed, e.g. it can read both windows
75 * and UNIX style linefeeds transparently.
77 int fgets_safe(char* buffer, size_t maxsize, FILE* &file);
79 /** This private method processes one line of
80 * configutation, appending errors to errorstream
81 * and setting error if an error has occured.
83 std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errorstream, bool &error, std::string filename);
85 /** Check that there is only one of each configuration item
87 bool CheckOnce(char* tag, bool bail, userrec* user);
91 /** Holds the server name of the local server
92 * as defined by the administrator.
94 char ServerName[MAXBUF];
96 /* Holds the network name the local server
97 * belongs to. This is an arbitary field defined
98 * by the administrator.
100 char Network[MAXBUF];
102 /** Holds the description of the local server
103 * as defined by the administrator.
105 char ServerDesc[MAXBUF];
107 /** Holds the admin's name, for output in
108 * the /ADMIN command.
110 char AdminName[MAXBUF];
112 /** Holds the email address of the admin,
113 * for output in the /ADMIN command.
115 char AdminEmail[MAXBUF];
117 /** Holds the admin's nickname, for output
118 * in the /ADMIN command
120 char AdminNick[MAXBUF];
122 /** The admin-configured /DIE password
124 char diepass[MAXBUF];
126 /** The admin-configured /RESTART password
128 char restartpass[MAXBUF];
130 /** The pathname and filename of the message of the
131 * day file, as defined by the administrator.
135 /** The pathname and filename of the rules file,
136 * as defined by the administrator.
140 /** The quit prefix in use, or an empty string
142 char PrefixQuit[MAXBUF];
144 /** The last string found within a <die> tag, or
147 char DieValue[MAXBUF];
149 /** The DNS server to use for DNS queries
151 char DNSServer[MAXBUF];
153 /** This variable contains a space-seperated list
154 * of commands which are disabled by the
155 * administrator of the server for non-opers.
157 char DisabledCommands[MAXBUF];
159 /** The full path to the modules directory.
160 * This is either set at compile time, or
161 * overridden in the configuration file via
166 /** The temporary directory where modules are copied
170 /** The full pathname to the executable, as
171 * given in argv[0] when the program starts.
173 char MyExecutable[1024];
175 /** The file handle of the logfile. If this
176 * value is NULL, the log file is not open,
177 * probably due to a permissions error on
178 * startup (this should not happen in normal
183 /** If this value is true, the owner of the
184 * server specified -nofork on the command
185 * line, causing the daemon to stay in the
190 /** If this value is true, the owner of the
191 * server has chosen to unlimit the coredump
192 * size to as large a value as his account
193 * settings will allow. This is often used
198 /** If this value is true, halfops have been
199 * enabled in the configuration file.
203 /** The number of seconds the DNS subsystem
204 * will wait before timing out any request.
208 /** The size of the read() buffer in the user
209 * handling code, used to read data into a user's
214 /** The value to be used for listen() backlogs
219 /** The soft limit value assigned to the irc server.
220 * The IRC server will not allow more than this
221 * number of local users.
223 unsigned int SoftLimit;
225 /** Maximum number of targets for a multi target command
226 * such as PRIVMSG or KICK
228 unsigned int MaxTargets;
230 /** The maximum number of /WHO results allowed
231 * in any single /WHO command.
235 /** True if the DEBUG loglevel is selected.
239 /** The loglevel in use by the IRC server
243 /** How many seconds to wait before exiting
244 * the program when /DIE is correctly issued.
248 /** True if we're going to hide netsplits as *.net *.split for non-opers
252 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
257 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
259 char HideWhoisServer[MAXBUF];
261 /** A list of IP addresses the server is listening
264 char addrs[MAXBUF][255];
266 /** The MOTD file, cached in a file_cache type.
270 /** The RULES file, cached in a file_cache type.
274 /** The full pathname and filename of the PID
275 * file as defined in the configuration.
279 /** The parsed configuration file as a stringstream.
280 * You should pass this to any configuration methods
281 * of this class, and not access it directly. It is
282 * recommended that modules use ConfigReader instead
283 * which provides a simpler abstraction of configuration
286 std::stringstream config_f;
288 /** The connect classes in use by the IRC server.
292 /** A list of module names (names only, no paths)
293 * which are currently loaded by the server.
295 std::vector<std::string> module_names;
297 /** A list of ports which the server is listening on
301 /** Boolean sets of which modules implement which functions
303 char implement_lists[255][255];
305 /** Global implementation list
307 char global_implementation[255];
309 /** A list of ports claimed by IO Modules
311 std::map<int,Module*> IOHookModule;
313 /** The 005 tokens of this server (ISUPPORT)
314 * populated/repopulated upon loading or unloading
319 /** STATS characters in this list are available
322 char OperOnlyStats[MAXBUF];
324 /** The path and filename of the ircd.log file
328 /** Custom version string, which if defined can replace the system info in VERSION.
330 char CustomVersion[MAXBUF];
332 /** List of u-lined servers
334 std::vector<irc::string> ulines;
336 /** Max banlist sizes for channels (the std::string is a glob)
338 std::map<std::string,int> maxbans;
342 /** Clears the include stack in preperation for
347 /** Read the entire configuration into memory
348 * and initialize this class. All other methods
349 * should be used only by the core.
351 void Read(bool bail, userrec* user);
353 bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
354 int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
355 int ConfValueInteger(char* tag, char* var, int index, std::stringstream *config);
356 int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
357 int ConfValueEnum(char* tag,std::stringstream *config);
358 int EnumConf(std::stringstream *config_f,const char* tag);
359 int EnumValues(std::stringstream *config, const char* tag, int index);
360 Module* GetIOHook(int port);
361 bool AddIOHook(int port, Module* iomod);
362 bool DelIOHook(int port);
369 int DaemonSeed (void);
370 bool FileExists (const char* file);
371 int OpenTCPSocket (void);
372 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
373 void WritePID(std::string filename);
375 char* CleanFilename(char* name);