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