]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd_io.h
Optimisation of optimisation :P ty w00tie
[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 temporary directory where modules are copied
146          */
147         char TempDir[1024];
148
149         /** The full pathname to the executable, as
150          * given in argv[0] when the program starts.
151          */
152         char MyExecutable[1024];
153
154         /** The file handle of the logfile. If this
155          * value is NULL, the log file is not open,
156          * probably due to a permissions error on
157          * startup (this should not happen in normal
158          * operation!).
159          */
160         FILE *log_file;
161
162         /** If this value is true, the owner of the
163          * server specified -nofork on the command
164          * line, causing the daemon to stay in the
165          * foreground.
166          */
167         bool nofork;
168
169         /** If this value is true, the owner of the
170          * server has chosen to unlimit the coredump
171          * size to as large a value as his account
172          * settings will allow. This is often used
173          * when debugging.
174          */
175         bool unlimitcore;
176
177         /** If this value is true, halfops have been
178          * enabled in the configuration file.
179          */
180         bool AllowHalfop;
181
182         /** The number of seconds the DNS subsystem
183          * will wait before timing out any request.
184          */
185         int dns_timeout;
186
187         /** The size of the read() buffer in the user
188          * handling code, used to read data into a user's
189          * recvQ.
190          */
191         int NetBufferSize;
192
193         /** The value to be used for listen() backlogs
194          * as default.
195          */
196         int MaxConn;
197
198         /** The soft limit value assigned to the irc server.
199          * The IRC server will not allow more than this
200          * number of local users.
201          */
202         unsigned int SoftLimit;
203
204         /** Maximum number of targets for a multi target command
205          * such as PRIVMSG or KICK
206          */
207         unsigned int MaxTargets;
208
209         /** The maximum number of /WHO results allowed
210          * in any single /WHO command.
211          */
212         int MaxWhoResults;
213
214         /** True if the DEBUG loglevel is selected.
215          */
216         int debugging;
217
218         /** The loglevel in use by the IRC server
219          */
220         int LogLevel;
221
222         /** How many seconds to wait before exiting
223          * the program when /DIE is correctly issued.
224          */
225         int DieDelay;
226
227         /** True if we're going to hide netsplits as *.net *.split for non-opers
228          */
229         bool HideSplits;
230
231         /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
232          * K-Lines, Z-Lines)
233          */
234         bool HideBans;
235
236         /** Set to a non-empty string to obfuscate the server name of users in WHOIS
237          */
238         char HideWhoisServer[MAXBUF];
239
240         /** A list of IP addresses the server is listening
241          * on.
242          */
243         char addrs[MAXBUF][255];
244
245         /** The MOTD file, cached in a file_cache type.
246          */
247         file_cache MOTD;
248
249         /** The RULES file, cached in a file_cache type.
250          */
251         file_cache RULES;
252
253         /** The full pathname and filename of the PID
254          * file as defined in the configuration.
255          */
256         char PID[1024];
257
258         /** The parsed configuration file as a stringstream.
259          * You should pass this to any configuration methods
260          * of this class, and not access it directly. It is
261          * recommended that modules use ConfigReader instead
262          * which provides a simpler abstraction of configuration
263          * files.
264          */
265         std::stringstream config_f;
266
267         /** The connect classes in use by the IRC server.
268          */
269         ClassVector Classes;
270
271         /** A list of module names (names only, no paths)
272          * which are currently loaded by the server.
273          */
274         std::vector<std::string> module_names;
275
276         /** A list of ports which the server is listening on
277          */
278         int ports[255];
279
280         /** Boolean sets of which modules implement which functions
281          */
282         char implement_lists[255][255];
283
284         /** Global implementation list
285          */
286         char global_implementation[255];
287
288         /** A list of ports claimed by IO Modules
289          */
290         std::map<int,Module*> IOHookModule;
291
292         /** The 005 tokens of this server (ISUPPORT)
293          * populated/repopulated upon loading or unloading
294          * modules.
295          */
296         std::string data005;
297
298         /** STATS characters in this list are available
299          * only to operators.
300          */
301         char OperOnlyStats[MAXBUF];
302
303         /** The path and filename of the ircd.log file
304          */
305         std::string logpath;
306
307         /** Custom version string, which if defined can replace the system info in VERSION.
308          */
309         char CustomVersion[MAXBUF];
310
311         /** List of u-lined servers
312          */
313         std::vector<irc::string> ulines;
314
315         /** Max banlist sizes for channels (the std::string is a glob)
316          */
317         std::map<std::string,int> maxbans;
318
319         ServerConfig();
320
321         /** Clears the include stack in preperation for
322          * a Read() call.
323          */
324         void ClearStack();
325
326         /** Read the entire configuration into memory
327          * and initialize this class. All other methods
328          * should be used only by the core.
329          */
330         void Read(bool bail, userrec* user);
331
332         bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
333         int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
334         int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
335         int ConfValueEnum(char* tag,std::stringstream *config);
336         int EnumConf(std::stringstream *config_f,const char* tag);
337         int EnumValues(std::stringstream *config, const char* tag, int index);
338         Module* GetIOHook(int port);
339         bool AddIOHook(int port, Module* iomod);
340         bool DelIOHook(int port);
341 };
342
343
344 void Exit (int); 
345 void Start (void); 
346 void SetSignals();
347 int DaemonSeed (void); 
348 bool FileExists (const char* file);
349 int OpenTCPSocket (void); 
350 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
351 void WritePID(std::string filename);
352 int BindPorts();
353 char* CleanFilename(char* name);
354
355 #endif