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*);
37 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
39 struct InitialConfig {
44 Validator validation_function;
47 /** This class holds the bulk of the runtime configuration for the ircd.
48 * It allows for reading new config values, accessing configuration files,
49 * and storage of the configuration data needed to run the ircd, such as
50 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
52 class ServerConfig : public classbase
55 /** This variable holds the names of all
56 * files included from the main one. This
57 * is used to make sure that no files are
58 * recursively included.
60 std::vector<std::string> include_stack;
62 /** Used by the config file subsystem to
63 * safely read a C-style string without
64 * dependency upon any certain style of
65 * linefeed, e.g. it can read both windows
66 * and UNIX style linefeeds transparently.
68 int fgets_safe(char* buffer, size_t maxsize, FILE* &file);
70 /** This private method processes one line of
71 * configutation, appending errors to errorstream
72 * and setting error if an error has occured.
74 std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errorstream, bool &error, std::string filename);
76 /** Check that there is only one of each configuration item
78 bool CheckOnce(char* tag, bool bail, userrec* user);
82 /** Holds the server name of the local server
83 * as defined by the administrator.
85 char ServerName[MAXBUF];
87 /* Holds the network name the local server
88 * belongs to. This is an arbitary field defined
89 * by the administrator.
93 /** Holds the description of the local server
94 * as defined by the administrator.
96 char ServerDesc[MAXBUF];
98 /** Holds the admin's name, for output in
101 char AdminName[MAXBUF];
103 /** Holds the email address of the admin,
104 * for output in the /ADMIN command.
106 char AdminEmail[MAXBUF];
108 /** Holds the admin's nickname, for output
109 * in the /ADMIN command
111 char AdminNick[MAXBUF];
113 /** The admin-configured /DIE password
115 char diepass[MAXBUF];
117 /** The admin-configured /RESTART password
119 char restartpass[MAXBUF];
121 /** The pathname and filename of the message of the
122 * day file, as defined by the administrator.
126 /** The pathname and filename of the rules file,
127 * as defined by the administrator.
131 /** The quit prefix in use, or an empty string
133 char PrefixQuit[MAXBUF];
135 /** The last string found within a <die> tag, or
138 char DieValue[MAXBUF];
140 /** The DNS server to use for DNS queries
142 char DNSServer[MAXBUF];
144 /** This variable contains a space-seperated list
145 * of commands which are disabled by the
146 * administrator of the server for non-opers.
148 char DisabledCommands[MAXBUF];
150 /** The full path to the modules directory.
151 * This is either set at compile time, or
152 * overridden in the configuration file via
157 /** The temporary directory where modules are copied
161 /** The full pathname to the executable, as
162 * given in argv[0] when the program starts.
164 char MyExecutable[1024];
166 /** The file handle of the logfile. If this
167 * value is NULL, the log file is not open,
168 * probably due to a permissions error on
169 * startup (this should not happen in normal
174 /** If this value is true, the owner of the
175 * server specified -nofork on the command
176 * line, causing the daemon to stay in the
181 /** If this value is true, the owner of the
182 * server has chosen to unlimit the coredump
183 * size to as large a value as his account
184 * settings will allow. This is often used
189 /** If this value is true, halfops have been
190 * enabled in the configuration file.
194 /** The number of seconds the DNS subsystem
195 * will wait before timing out any request.
199 /** The size of the read() buffer in the user
200 * handling code, used to read data into a user's
205 /** The value to be used for listen() backlogs
210 /** The soft limit value assigned to the irc server.
211 * The IRC server will not allow more than this
212 * number of local users.
214 unsigned int SoftLimit;
216 /** Maximum number of targets for a multi target command
217 * such as PRIVMSG or KICK
219 unsigned int MaxTargets;
221 /** The maximum number of /WHO results allowed
222 * in any single /WHO command.
226 /** True if the DEBUG loglevel is selected.
230 /** The loglevel in use by the IRC server
234 /** How many seconds to wait before exiting
235 * the program when /DIE is correctly issued.
239 /** True if we're going to hide netsplits as *.net *.split for non-opers
243 /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
248 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
250 char HideWhoisServer[MAXBUF];
252 /** A list of IP addresses the server is listening
255 char addrs[MAXBUF][255];
257 /** The MOTD file, cached in a file_cache type.
261 /** The RULES file, cached in a file_cache type.
265 /** The full pathname and filename of the PID
266 * file as defined in the configuration.
270 /** The parsed configuration file as a stringstream.
271 * You should pass this to any configuration methods
272 * of this class, and not access it directly. It is
273 * recommended that modules use ConfigReader instead
274 * which provides a simpler abstraction of configuration
277 std::stringstream config_f;
279 /** The connect classes in use by the IRC server.
283 /** A list of module names (names only, no paths)
284 * which are currently loaded by the server.
286 std::vector<std::string> module_names;
288 /** A list of ports which the server is listening on
292 /** Boolean sets of which modules implement which functions
294 char implement_lists[255][255];
296 /** Global implementation list
298 char global_implementation[255];
300 /** A list of ports claimed by IO Modules
302 std::map<int,Module*> IOHookModule;
304 /** The 005 tokens of this server (ISUPPORT)
305 * populated/repopulated upon loading or unloading
310 /** STATS characters in this list are available
313 char OperOnlyStats[MAXBUF];
315 /** The path and filename of the ircd.log file
319 /** Custom version string, which if defined can replace the system info in VERSION.
321 char CustomVersion[MAXBUF];
323 /** List of u-lined servers
325 std::vector<irc::string> ulines;
327 /** Max banlist sizes for channels (the std::string is a glob)
329 std::map<std::string,int> maxbans;
333 /** Clears the include stack in preperation for
338 /** Read the entire configuration into memory
339 * and initialize this class. All other methods
340 * should be used only by the core.
342 void Read(bool bail, userrec* user);
344 bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
345 int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
346 int ConfValueInteger(char* tag, char* var, int index, std::stringstream *config);
347 int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
348 int ConfValueEnum(char* tag,std::stringstream *config);
349 int EnumConf(std::stringstream *config_f,const char* tag);
350 int EnumValues(std::stringstream *config, const char* tag, int index);
351 Module* GetIOHook(int port);
352 bool AddIOHook(int port, Module* iomod);
353 bool DelIOHook(int port);
360 int DaemonSeed (void);
361 bool FileExists (const char* file);
362 int OpenTCPSocket (void);
363 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
364 void WritePID(std::string filename);
366 char* CleanFilename(char* name);