]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd_io.h
Add checks for AddIOHook failing
[user/henk/code/inspircd.git] / include / inspircd_io.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __INSPIRCD_IO_H__
18 #define __INSPIRCD_IO_H__
19
20 #include <sstream>
21 #include <string>
22 #include <vector>
23 #include "inspircd.h"
24 #include "globals.h"
25 #include "modules.h"
26
27 /** Flags for use with log()
28  */
29 #define DEBUG 10
30 #define VERBOSE 20
31 #define DEFAULT 30
32 #define SPARSE 40
33 #define NONE 50
34
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.
39  */
40 class ServerConfig : public classbase
41 {
42   private:
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.
47          */
48         std::vector<std::string> include_stack;
49
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.
55          */
56         int fgets_safe(char* buffer, size_t maxsize, FILE* &file);
57
58         /** This private method processes one line of
59          * configutation, appending errors to errorstream
60          * and setting error if an error has occured.
61          */
62         std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errorstream, bool &error, std::string filename);
63
64         /** Check that there is only one of each configuration item
65          */
66         bool CheckOnce(char* tag, bool bail, userrec* user);
67
68   public:
69
70         /** Holds the server name of the local server
71          * as defined by the administrator.
72          */
73         char ServerName[MAXBUF];
74         
75         /* Holds the network name the local server
76          * belongs to. This is an arbitary field defined
77          * by the administrator.
78          */
79         char Network[MAXBUF];
80
81         /** Holds the description of the local server
82          * as defined by the administrator.
83          */
84         char ServerDesc[MAXBUF];
85
86         /** Holds the admin's name, for output in
87          * the /ADMIN command.
88          */
89         char AdminName[MAXBUF];
90
91         /** Holds the email address of the admin,
92          * for output in the /ADMIN command.
93          */
94         char AdminEmail[MAXBUF];
95
96         /** Holds the admin's nickname, for output
97          * in the /ADMIN command
98          */
99         char AdminNick[MAXBUF];
100
101         /** The admin-configured /DIE password
102          */
103         char diepass[MAXBUF];
104
105         /** The admin-configured /RESTART password
106          */
107         char restartpass[MAXBUF];
108
109         /** The pathname and filename of the message of the
110          * day file, as defined by the administrator.
111          */
112         char motd[MAXBUF];
113
114         /** The pathname and filename of the rules file,
115          * as defined by the administrator.
116          */
117         char rules[MAXBUF];
118
119         /** The quit prefix in use, or an empty string
120          */
121         char PrefixQuit[MAXBUF];
122
123         /** The last string found within a <die> tag, or
124          * an empty string.
125          */
126         char DieValue[MAXBUF];
127
128         /** The DNS server to use for DNS queries
129          */
130         char DNSServer[MAXBUF];
131
132         /** This variable contains a space-seperated list
133          * of commands which are disabled by the
134          * administrator of the server for non-opers.
135          */
136         char DisabledCommands[MAXBUF];
137
138         /** The full path to the modules directory.
139          * This is either set at compile time, or
140          * overridden in the configuration file via
141          * the <options> tag.
142          */
143         char ModPath[1024];
144
145         /** The full pathname to the executable, as
146          * given in argv[0] when the program starts.
147          */
148         char MyExecutable[1024];
149
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
154          * operation!).
155          */
156         FILE *log_file;
157
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
161          * foreground.
162          */
163         bool nofork;
164
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
169          * when debugging.
170          */
171         bool unlimitcore;
172
173         /** If this value is true, halfops have been
174          * enabled in the configuration file.
175          */
176         bool AllowHalfop;
177
178         /** The number of seconds the DNS subsystem
179          * will wait before timing out any request.
180          */
181         int dns_timeout;
182
183         /** The size of the read() buffer in the user
184          * handling code, used to read data into a user's
185          * recvQ.
186          */
187         int NetBufferSize;
188
189         /** The value to be used for listen() backlogs
190          * as default.
191          */
192         int MaxConn;
193
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.
197          */
198         unsigned int SoftLimit;
199
200         /** Maximum number of targets for a multi target command
201          * such as PRIVMSG or KICK
202          */
203         unsigned int MaxTargets;
204
205         /** The maximum number of /WHO results allowed
206          * in any single /WHO command.
207          */
208         int MaxWhoResults;
209
210         /** True if the DEBUG loglevel is selected.
211          */
212         int debugging;
213
214         /** The loglevel in use by the IRC server
215          */
216         int LogLevel;
217
218         /** How many seconds to wait before exiting
219          * the program when /DIE is correctly issued.
220          */
221         int DieDelay;
222
223         /** A list of IP addresses the server is listening
224          * on.
225          */
226         char addrs[MAXBUF][255];
227
228         /** The MOTD file, cached in a file_cache type.
229          */
230         file_cache MOTD;
231
232         /** The RULES file, cached in a file_cache type.
233          */
234         file_cache RULES;
235
236         /** The full pathname and filename of the PID
237          * file as defined in the configuration.
238          */
239         char PID[1024];
240
241         /** The parsed configuration file as a stringstream.
242          * You should pass this to any configuration methods
243          * of this class, and not access it directly. It is
244          * recommended that modules use ConfigReader instead
245          * which provides a simpler abstraction of configuration
246          * files.
247          */
248         std::stringstream config_f;
249
250         /** The connect classes in use by the IRC server.
251          */
252         ClassVector Classes;
253
254         /** A list of module names (names only, no paths)
255          * which are currently loaded by the server.
256          */
257         std::vector<std::string> module_names;
258
259         /** A list of ports which the server is listening on
260          */
261         int ports[255];
262
263         /** Boolean sets of which modules implement which functions
264          */
265         char implement_lists[255][255];
266
267         /** Global implementation list
268          */
269         char global_implementation[255];
270
271         /** A list of ports claimed by IO Modules
272          */
273         std::map<int,Module*> IOHookModule;
274
275         /** The 005 tokens of this server (ISUPPORT)
276          * populated/repopulated upon loading or unloading
277          * modules.
278          */
279         std::string data005;
280
281         /** STATS characters in this list are available
282          * only to operators.
283          */
284         char OperOnlyStats[MAXBUF];
285
286         /** The path and filename of the ircd.log file
287          */
288         std::string logpath;
289
290         /** Custom version string, which if defined can replace the system info in VERSION.
291          */
292         char CustomVersion[MAXBUF];
293
294         ServerConfig();
295
296         /** Clears the include stack in preperation for
297          * a Read() call.
298          */
299         void ClearStack();
300
301         /** Read the entire configuration into memory
302          * and initialize this class. All other methods
303          * should be used only by the core.
304          */
305         void Read(bool bail, userrec* user);
306
307         bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
308         int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
309         int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
310         int ConfValueEnum(char* tag,std::stringstream *config);
311         int EnumConf(std::stringstream *config_f,const char* tag);
312         int EnumValues(std::stringstream *config, const char* tag, int index);
313         Module* GetIOHook(int port);
314         bool AddIOHook(int port, Module* iomod);
315         bool DelIOHook(int port);
316 };
317
318
319 void Exit (int); 
320 void Start (void); 
321 void SetSignals();
322 int DaemonSeed (void); 
323 bool FileExists (const char* file);
324 int OpenTCPSocket (void); 
325 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
326 void WritePID(std::string filename);
327 int BindPorts();
328 char* CleanFilename(char* name);
329
330 #endif