]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd_io.h
Decide that it wasn't quite appropriate :(
[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         /** Set to a non-empty string to obfuscate the server name of users in WHOIS
232          */
233         char HideWhoisServer[MAXBUF];
234
235         /** A list of IP addresses the server is listening
236          * on.
237          */
238         char addrs[MAXBUF][255];
239
240         /** The MOTD file, cached in a file_cache type.
241          */
242         file_cache MOTD;
243
244         /** The RULES file, cached in a file_cache type.
245          */
246         file_cache RULES;
247
248         /** The full pathname and filename of the PID
249          * file as defined in the configuration.
250          */
251         char PID[1024];
252
253         /** The parsed configuration file as a stringstream.
254          * You should pass this to any configuration methods
255          * of this class, and not access it directly. It is
256          * recommended that modules use ConfigReader instead
257          * which provides a simpler abstraction of configuration
258          * files.
259          */
260         std::stringstream config_f;
261
262         /** The connect classes in use by the IRC server.
263          */
264         ClassVector Classes;
265
266         /** A list of module names (names only, no paths)
267          * which are currently loaded by the server.
268          */
269         std::vector<std::string> module_names;
270
271         /** A list of ports which the server is listening on
272          */
273         int ports[255];
274
275         /** Boolean sets of which modules implement which functions
276          */
277         char implement_lists[255][255];
278
279         /** Global implementation list
280          */
281         char global_implementation[255];
282
283         /** A list of ports claimed by IO Modules
284          */
285         std::map<int,Module*> IOHookModule;
286
287         /** The 005 tokens of this server (ISUPPORT)
288          * populated/repopulated upon loading or unloading
289          * modules.
290          */
291         std::string data005;
292
293         /** STATS characters in this list are available
294          * only to operators.
295          */
296         char OperOnlyStats[MAXBUF];
297
298         /** The path and filename of the ircd.log file
299          */
300         std::string logpath;
301
302         /** Custom version string, which if defined can replace the system info in VERSION.
303          */
304         char CustomVersion[MAXBUF];
305
306         ServerConfig();
307
308         /** Clears the include stack in preperation for
309          * a Read() call.
310          */
311         void ClearStack();
312
313         /** Read the entire configuration into memory
314          * and initialize this class. All other methods
315          * should be used only by the core.
316          */
317         void Read(bool bail, userrec* user);
318
319         bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
320         int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
321         int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
322         int ConfValueEnum(char* tag,std::stringstream *config);
323         int EnumConf(std::stringstream *config_f,const char* tag);
324         int EnumValues(std::stringstream *config, const char* tag, int index);
325         Module* GetIOHook(int port);
326         bool AddIOHook(int port, Module* iomod);
327         bool DelIOHook(int port);
328 };
329
330
331 void Exit (int); 
332 void Start (void); 
333 void SetSignals();
334 int DaemonSeed (void); 
335 bool FileExists (const char* file);
336 int OpenTCPSocket (void); 
337 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
338 void WritePID(std::string filename);
339 int BindPorts();
340 char* CleanFilename(char* name);
341
342 #endif