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 /** This class holds the bulk of the runtime configuration for the ircd.
36 * It allows for reading new config values, accessing configuration files,
37 * and storage of the configuration data needed to run the ircd, such as
38 * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
40 class ServerConfig : public classbase
43 /** This variable holds the names of all
44 * files included from the main one. This
45 * is used to make sure that no files are
46 * recursively included.
48 std::vector<std::string> include_stack;
50 /** Used by the config file subsystem to
51 * safely read a C-style string without
52 * dependency upon any certain style of
53 * linefeed, e.g. it can read both windows
54 * and UNIX style linefeeds transparently.
56 int fgets_safe(char* buffer, size_t maxsize, FILE* &file);
58 /** This private method processes one line of
59 * configutation, appending errors to errorstream
60 * and setting error if an error has occured.
62 std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errorstream, bool &error, std::string filename);
64 /** Check that there is only one of each configuration item
66 bool CheckOnce(char* tag, bool bail, userrec* user);
70 /** Holds the server name of the local server
71 * as defined by the administrator.
73 char ServerName[MAXBUF];
75 /* Holds the network name the local server
76 * belongs to. This is an arbitary field defined
77 * by the administrator.
81 /** Holds the description of the local server
82 * as defined by the administrator.
84 char ServerDesc[MAXBUF];
86 /** Holds the admin's name, for output in
89 char AdminName[MAXBUF];
91 /** Holds the email address of the admin,
92 * for output in the /ADMIN command.
94 char AdminEmail[MAXBUF];
96 /** Holds the admin's nickname, for output
97 * in the /ADMIN command
99 char AdminNick[MAXBUF];
101 /** The admin-configured /DIE password
103 char diepass[MAXBUF];
105 /** The admin-configured /RESTART password
107 char restartpass[MAXBUF];
109 /** The pathname and filename of the message of the
110 * day file, as defined by the administrator.
114 /** The pathname and filename of the rules file,
115 * as defined by the administrator.
119 /** The quit prefix in use, or an empty string
121 char PrefixQuit[MAXBUF];
123 /** The last string found within a <die> tag, or
126 char DieValue[MAXBUF];
128 /** The DNS server to use for DNS queries
130 char DNSServer[MAXBUF];
132 /** This variable contains a space-seperated list
133 * of commands which are disabled by the
134 * administrator of the server for non-opers.
136 char DisabledCommands[MAXBUF];
138 /** The full path to the modules directory.
139 * This is either set at compile time, or
140 * overridden in the configuration file via
145 /** The full pathname to the executable, as
146 * given in argv[0] when the program starts.
148 char MyExecutable[1024];
150 /** The file handle of the logfile. If this
151 * value is NULL, the log file is not open,
152 * probably due to a permissions error on
153 * startup (this should not happen in normal
158 /** If this value is true, the owner of the
159 * server specified -nofork on the command
160 * line, causing the daemon to stay in the
165 /** If this value is true, the owner of the
166 * server has chosen to unlimit the coredump
167 * size to as large a value as his account
168 * settings will allow. This is often used
173 /** If this value is true, halfops have been
174 * enabled in the configuration file.
178 /** The number of seconds the DNS subsystem
179 * will wait before timing out any request.
183 /** The size of the read() buffer in the user
184 * handling code, used to read data into a user's
189 /** The value to be used for listen() backlogs
194 /** The soft limit value assigned to the irc server.
195 * The IRC server will not allow more than this
196 * number of local users.
198 unsigned int SoftLimit;
200 /** Maximum number of targets for a multi target command
201 * such as PRIVMSG or KICK
203 unsigned int MaxTargets;
205 /** The maximum number of /WHO results allowed
206 * in any single /WHO command.
210 /** True if the DEBUG loglevel is selected.
214 /** The loglevel in use by the IRC server
218 /** How many seconds to wait before exiting
219 * the program when /DIE is correctly issued.
223 /** True if we're going to hide netsplits as *.net *.split for non-opers
227 /** Set to a non-empty string to obfuscate the server name of users in WHOIS
229 char HideWhoisServer[MAXBUF];
231 /** A list of IP addresses the server is listening
234 char addrs[MAXBUF][255];
236 /** The MOTD file, cached in a file_cache type.
240 /** The RULES file, cached in a file_cache type.
244 /** The full pathname and filename of the PID
245 * file as defined in the configuration.
249 /** The parsed configuration file as a stringstream.
250 * You should pass this to any configuration methods
251 * of this class, and not access it directly. It is
252 * recommended that modules use ConfigReader instead
253 * which provides a simpler abstraction of configuration
256 std::stringstream config_f;
258 /** The connect classes in use by the IRC server.
262 /** A list of module names (names only, no paths)
263 * which are currently loaded by the server.
265 std::vector<std::string> module_names;
267 /** A list of ports which the server is listening on
271 /** Boolean sets of which modules implement which functions
273 char implement_lists[255][255];
275 /** Global implementation list
277 char global_implementation[255];
279 /** A list of ports claimed by IO Modules
281 std::map<int,Module*> IOHookModule;
283 /** The 005 tokens of this server (ISUPPORT)
284 * populated/repopulated upon loading or unloading
289 /** STATS characters in this list are available
292 char OperOnlyStats[MAXBUF];
294 /** The path and filename of the ircd.log file
298 /** Custom version string, which if defined can replace the system info in VERSION.
300 char CustomVersion[MAXBUF];
304 /** Clears the include stack in preperation for
309 /** Read the entire configuration into memory
310 * and initialize this class. All other methods
311 * should be used only by the core.
313 void Read(bool bail, userrec* user);
315 bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
316 int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
317 int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
318 int ConfValueEnum(char* tag,std::stringstream *config);
319 int EnumConf(std::stringstream *config_f,const char* tag);
320 int EnumValues(std::stringstream *config, const char* tag, int index);
321 Module* GetIOHook(int port);
322 bool AddIOHook(int port, Module* iomod);
323 bool DelIOHook(int port);
330 int DaemonSeed (void);
331 bool FileExists (const char* file);
332 int OpenTCPSocket (void);
333 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
334 void WritePID(std::string filename);
336 char* CleanFilename(char* name);