]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd_io.h
Removed unused check for valid channel name - if it's invalid, it won't exist in...
[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 typedef bool (*Validator)(const char*, const char*, void*);
36 typedef bool (*MultiValidator)(const char*, char**, void**, int*);
37 typedef bool (*MultiNotify)(const char*);
38
39 enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN };
40
41 struct InitialConfig {
42         char* tag;
43         char* value;
44         void* val;
45         ConfigDataType datatype;
46         Validator validation_function;
47 };
48
49 struct MultiConfig {
50         const char* tag;
51         char* items[12];
52         int datatype[12];
53         MultiNotify     init_function;
54         MultiValidator  validation_function;
55         MultiNotify     finish_function;
56 };
57
58 /** This class holds the bulk of the runtime configuration for the ircd.
59  * It allows for reading new config values, accessing configuration files,
60  * and storage of the configuration data needed to run the ircd, such as
61  * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
62  */
63 class ServerConfig : public classbase
64 {
65   private:
66         /** This variable holds the names of all
67          * files included from the main one. This
68          * is used to make sure that no files are
69          * recursively included.
70          */
71         std::vector<std::string> include_stack;
72
73         /** Used by the config file subsystem to
74          * safely read a C-style string without
75          * dependency upon any certain style of
76          * linefeed, e.g. it can read both windows
77          * and UNIX style linefeeds transparently.
78          */
79         int fgets_safe(char* buffer, size_t maxsize, FILE* &file);
80
81         /** This private method processes one line of
82          * configutation, appending errors to errorstream
83          * and setting error if an error has occured.
84          */
85         std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errorstream, bool &error, std::string filename);
86
87         /** Check that there is only one of each configuration item
88          */
89         bool CheckOnce(char* tag, bool bail, userrec* user);
90
91   public:
92
93         /** Holds the server name of the local server
94          * as defined by the administrator.
95          */
96         char ServerName[MAXBUF];
97         
98         /* Holds the network name the local server
99          * belongs to. This is an arbitary field defined
100          * by the administrator.
101          */
102         char Network[MAXBUF];
103
104         /** Holds the description of the local server
105          * as defined by the administrator.
106          */
107         char ServerDesc[MAXBUF];
108
109         /** Holds the admin's name, for output in
110          * the /ADMIN command.
111          */
112         char AdminName[MAXBUF];
113
114         /** Holds the email address of the admin,
115          * for output in the /ADMIN command.
116          */
117         char AdminEmail[MAXBUF];
118
119         /** Holds the admin's nickname, for output
120          * in the /ADMIN command
121          */
122         char AdminNick[MAXBUF];
123
124         /** The admin-configured /DIE password
125          */
126         char diepass[MAXBUF];
127
128         /** The admin-configured /RESTART password
129          */
130         char restartpass[MAXBUF];
131
132         /** The pathname and filename of the message of the
133          * day file, as defined by the administrator.
134          */
135         char motd[MAXBUF];
136
137         /** The pathname and filename of the rules file,
138          * as defined by the administrator.
139          */
140         char rules[MAXBUF];
141
142         /** The quit prefix in use, or an empty string
143          */
144         char PrefixQuit[MAXBUF];
145
146         /** The last string found within a <die> tag, or
147          * an empty string.
148          */
149         char DieValue[MAXBUF];
150
151         /** The DNS server to use for DNS queries
152          */
153         char DNSServer[MAXBUF];
154
155         /** This variable contains a space-seperated list
156          * of commands which are disabled by the
157          * administrator of the server for non-opers.
158          */
159         char DisabledCommands[MAXBUF];
160
161         /** The full path to the modules directory.
162          * This is either set at compile time, or
163          * overridden in the configuration file via
164          * the <options> tag.
165          */
166         char ModPath[1024];
167
168         /** The temporary directory where modules are copied
169          */
170         char TempDir[1024];
171
172         /** The full pathname to the executable, as
173          * given in argv[0] when the program starts.
174          */
175         char MyExecutable[1024];
176
177         /** The file handle of the logfile. If this
178          * value is NULL, the log file is not open,
179          * probably due to a permissions error on
180          * startup (this should not happen in normal
181          * operation!).
182          */
183         FILE *log_file;
184
185         /** If this value is true, the owner of the
186          * server specified -nofork on the command
187          * line, causing the daemon to stay in the
188          * foreground.
189          */
190         bool nofork;
191
192         /** If this value is true, the owner of the
193          * server has chosen to unlimit the coredump
194          * size to as large a value as his account
195          * settings will allow. This is often used
196          * when debugging.
197          */
198         bool unlimitcore;
199
200         /** If this value is true, halfops have been
201          * enabled in the configuration file.
202          */
203         bool AllowHalfop;
204
205         /** The number of seconds the DNS subsystem
206          * will wait before timing out any request.
207          */
208         int dns_timeout;
209
210         /** The size of the read() buffer in the user
211          * handling code, used to read data into a user's
212          * recvQ.
213          */
214         int NetBufferSize;
215
216         /** The value to be used for listen() backlogs
217          * as default.
218          */
219         int MaxConn;
220
221         /** The soft limit value assigned to the irc server.
222          * The IRC server will not allow more than this
223          * number of local users.
224          */
225         unsigned int SoftLimit;
226
227         /** Maximum number of targets for a multi target command
228          * such as PRIVMSG or KICK
229          */
230         unsigned int MaxTargets;
231
232         /** The maximum number of /WHO results allowed
233          * in any single /WHO command.
234          */
235         int MaxWhoResults;
236
237         /** True if the DEBUG loglevel is selected.
238          */
239         int debugging;
240
241         /** The loglevel in use by the IRC server
242          */
243         int LogLevel;
244
245         /** How many seconds to wait before exiting
246          * the program when /DIE is correctly issued.
247          */
248         int DieDelay;
249
250         /** True if we're going to hide netsplits as *.net *.split for non-opers
251          */
252         bool HideSplits;
253
254         /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
255          * K-Lines, Z-Lines)
256          */
257         bool HideBans;
258
259         /** Set to a non-empty string to obfuscate the server name of users in WHOIS
260          */
261         char HideWhoisServer[MAXBUF];
262
263         /** A list of IP addresses the server is listening
264          * on.
265          */
266         char addrs[MAXBUF][255];
267
268         /** The MOTD file, cached in a file_cache type.
269          */
270         file_cache MOTD;
271
272         /** The RULES file, cached in a file_cache type.
273          */
274         file_cache RULES;
275
276         /** The full pathname and filename of the PID
277          * file as defined in the configuration.
278          */
279         char PID[1024];
280
281         /** The parsed configuration file as a stringstream.
282          * You should pass this to any configuration methods
283          * of this class, and not access it directly. It is
284          * recommended that modules use ConfigReader instead
285          * which provides a simpler abstraction of configuration
286          * files.
287          */
288         std::stringstream config_f;
289
290         /** The connect classes in use by the IRC server.
291          */
292         ClassVector Classes;
293
294         /** A list of module names (names only, no paths)
295          * which are currently loaded by the server.
296          */
297         std::vector<std::string> module_names;
298
299         /** A list of ports which the server is listening on
300          */
301         int ports[255];
302
303         /** Boolean sets of which modules implement which functions
304          */
305         char implement_lists[255][255];
306
307         /** Global implementation list
308          */
309         char global_implementation[255];
310
311         /** A list of ports claimed by IO Modules
312          */
313         std::map<int,Module*> IOHookModule;
314
315         /** The 005 tokens of this server (ISUPPORT)
316          * populated/repopulated upon loading or unloading
317          * modules.
318          */
319         std::string data005;
320
321         /** STATS characters in this list are available
322          * only to operators.
323          */
324         char OperOnlyStats[MAXBUF];
325
326         /** The path and filename of the ircd.log file
327          */
328         std::string logpath;
329
330         /** Custom version string, which if defined can replace the system info in VERSION.
331          */
332         char CustomVersion[MAXBUF];
333
334         /** List of u-lined servers
335          */
336         std::vector<irc::string> ulines;
337
338         /** Max banlist sizes for channels (the std::string is a glob)
339          */
340         std::map<std::string,int> maxbans;
341
342         ServerConfig();
343
344         /** Clears the include stack in preperation for
345          * a Read() call.
346          */
347         void ClearStack();
348
349         /** Read the entire configuration into memory
350          * and initialize this class. All other methods
351          * should be used only by the core.
352          */
353         void Read(bool bail, userrec* user);
354
355         bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
356         int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
357         int ConfValueInteger(char* tag, char* var, int index, std::stringstream *config);
358         int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
359         int ConfValueEnum(char* tag,std::stringstream *config);
360         int EnumConf(std::stringstream *config_f,const char* tag);
361         int EnumValues(std::stringstream *config, const char* tag, int index);
362         Module* GetIOHook(int port);
363         bool AddIOHook(int port, Module* iomod);
364         bool DelIOHook(int port);
365 };
366
367
368 void Exit(int status); 
369 void Start(); 
370 void SetSignals();
371 bool DaemonSeed(); 
372 bool FileExists(const char* file);
373 int OpenTCPSocket(); 
374 bool BindSocket(int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
375 void WritePID(const std::string &filename);
376 int BindPorts(bool bail);
377 char* CleanFilename(char* name);
378
379 #endif