1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2005 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);
66 /** Holds the server name of the local server
67 * as defined by the administrator.
69 char ServerName[MAXBUF];
71 /* Holds the network name the local server
72 * belongs to. This is an arbitary field defined
73 * by the administrator.
77 /** Holds the description of the local server
78 * as defined by the administrator.
80 char ServerDesc[MAXBUF];
82 /** Holds the admin's name, for output in
85 char AdminName[MAXBUF];
87 /** Holds the email address of the admin,
88 * for output in the /ADMIN command.
90 char AdminEmail[MAXBUF];
92 /** Holds the admin's nickname, for output
93 * in the /ADMIN command
95 char AdminNick[MAXBUF];
97 /** The admin-configured /DIE password
101 /** The admin-configured /RESTART password
103 char restartpass[MAXBUF];
105 /** The pathname and filename of the message of the
106 * day file, as defined by the administrator.
110 /** The pathname and filename of the rules file,
111 * as defined by the administrator.
115 /** The quit prefix in use, or an empty string
117 char PrefixQuit[MAXBUF];
119 /** The last string found within a <die> tag, or
122 char DieValue[MAXBUF];
124 /** The DNS server to use for DNS queries
126 char DNSServer[MAXBUF];
128 /** This variable contains a space-seperated list
129 * of commands which are disabled by the
130 * administrator of the server for non-opers.
132 char DisabledCommands[MAXBUF];
134 /** The full path to the modules directory.
135 * This is either set at compile time, or
136 * overridden in the configuration file via
141 /** The full pathname to the executable, as
142 * given in argv[0] when the program starts.
144 char MyExecutable[1024];
146 /** The file handle of the logfile. If this
147 * value is NULL, the log file is not open,
148 * probably due to a permissions error on
149 * startup (this should not happen in normal
154 /** If this value is true, the owner of the
155 * server specified -nofork on the command
156 * line, causing the daemon to stay in the
161 /** If this value is true, the owner of the
162 * server has chosen to unlimit the coredump
163 * size to as large a value as his account
164 * settings will allow. This is often used
169 /** If this value is true, halfops have been
170 * enabled in the configuration file.
174 /** The number of seconds the DNS subsystem
175 * will wait before timing out any request.
179 /** The size of the read() buffer in the user
180 * handling code, used to read data into a user's
185 /** The value to be used for listen() backlogs
190 /** The soft limit value assigned to the irc server.
191 * The IRC server will not allow more than this
192 * number of local users.
194 unsigned int SoftLimit;
196 /** The maximum number of /WHO results allowed
197 * in any single /WHO command.
201 /** True if the DEBUG loglevel is selected.
205 /** The loglevel in use by the IRC server
209 /** How many seconds to wait before exiting
210 * the program when /DIE is correctly issued.
214 /** A list of IP addresses the server is listening
217 char addrs[MAXBUF][255];
219 /** The MOTD file, cached in a file_cache type.
223 /** The RULES file, cached in a file_cache type.
227 /** The full pathname and filename of the PID
228 * file as defined in the configuration.
232 /** The parsed configuration file as a stringstream.
233 * You should pass this to any configuration methods
234 * of this class, and not access it directly. It is
235 * recommended that modules use ConfigReader instead
236 * which provides a simpler abstraction of configuration
239 std::stringstream config_f;
241 /** The connect classes in use by the IRC server.
245 /** A list of module names (names only, no paths)
246 * which are currently loaded by the server.
248 std::vector<std::string> module_names;
250 /** A list of ports which the server is listening on
254 /** Boolean sets of which modules implement which functions
256 char implement_lists[255][255];
258 /** Global implementation list
260 char global_implementation[255];
262 /** A list of ports claimed by IO Modules
264 std::map<int,Module*> IOHookModule;
268 /** Clears the include stack in preperation for
273 /** Read the entire configuration into memory
274 * and initialize this class. All other methods
275 * should be used only by the core.
277 void Read(bool bail, userrec* user);
279 bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
280 int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
281 int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
282 int ConfValueEnum(char* tag,std::stringstream *config);
283 int EnumConf(std::stringstream *config_f,const char* tag);
284 int EnumValues(std::stringstream *config, const char* tag, int index);
285 Module* GetIOHook(int port);
286 bool AddIOHook(int port, Module* iomod);
287 bool DelIOHook(int port);
293 int DaemonSeed (void);
294 bool FileExists (const char* file);
295 int OpenTCPSocket (void);
296 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
297 void WritePID(std::string filename);