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