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