]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd_io.h
Added support for <options customversion> to customize the second part of VERSION
[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   public:
65
66         /** Holds the server name of the local server
67          * as defined by the administrator.
68          */
69         char ServerName[MAXBUF];
70         
71         /* Holds the network name the local server
72          * belongs to. This is an arbitary field defined
73          * by the administrator.
74          */
75         char Network[MAXBUF];
76
77         /** Holds the description of the local server
78          * as defined by the administrator.
79          */
80         char ServerDesc[MAXBUF];
81
82         /** Holds the admin's name, for output in
83          * the /ADMIN command.
84          */
85         char AdminName[MAXBUF];
86
87         /** Holds the email address of the admin,
88          * for output in the /ADMIN command.
89          */
90         char AdminEmail[MAXBUF];
91
92         /** Holds the admin's nickname, for output
93          * in the /ADMIN command
94          */
95         char AdminNick[MAXBUF];
96
97         /** The admin-configured /DIE password
98          */
99         char diepass[MAXBUF];
100
101         /** The admin-configured /RESTART password
102          */
103         char restartpass[MAXBUF];
104
105         /** The pathname and filename of the message of the
106          * day file, as defined by the administrator.
107          */
108         char motd[MAXBUF];
109
110         /** The pathname and filename of the rules file,
111          * as defined by the administrator.
112          */
113         char rules[MAXBUF];
114
115         /** The quit prefix in use, or an empty string
116          */
117         char PrefixQuit[MAXBUF];
118
119         /** The last string found within a <die> tag, or
120          * an empty string.
121          */
122         char DieValue[MAXBUF];
123
124         /** The DNS server to use for DNS queries
125          */
126         char DNSServer[MAXBUF];
127
128         /** This variable contains a space-seperated list
129          * of commands which are disabled by the
130          * administrator of the server for non-opers.
131          */
132         char DisabledCommands[MAXBUF];
133
134         /** The full path to the modules directory.
135          * This is either set at compile time, or
136          * overridden in the configuration file via
137          * the <options> tag.
138          */
139         char ModPath[1024];
140
141         /** The full pathname to the executable, as
142          * given in argv[0] when the program starts.
143          */
144         char MyExecutable[1024];
145
146         /** The file handle of the logfile. If this
147          * value is NULL, the log file is not open,
148          * probably due to a permissions error on
149          * startup (this should not happen in normal
150          * operation!).
151          */
152         FILE *log_file;
153
154         /** If this value is true, the owner of the
155          * server specified -nofork on the command
156          * line, causing the daemon to stay in the
157          * foreground.
158          */
159         bool nofork;
160
161         /** If this value is true, the owner of the
162          * server has chosen to unlimit the coredump
163          * size to as large a value as his account
164          * settings will allow. This is often used
165          * when debugging.
166          */
167         bool unlimitcore;
168
169         /** If this value is true, halfops have been
170          * enabled in the configuration file.
171          */
172         bool AllowHalfop;
173
174         /** The number of seconds the DNS subsystem
175          * will wait before timing out any request.
176          */
177         int dns_timeout;
178
179         /** The size of the read() buffer in the user
180          * handling code, used to read data into a user's
181          * recvQ.
182          */
183         int NetBufferSize;
184
185         /** The value to be used for listen() backlogs
186          * as default.
187          */
188         int MaxConn;
189
190         /** The soft limit value assigned to the irc server.
191          * The IRC server will not allow more than this
192          * number of local users.
193          */
194         unsigned int SoftLimit;
195
196         /** The maximum number of /WHO results allowed
197          * in any single /WHO command.
198          */
199         int MaxWhoResults;
200
201         /** True if the DEBUG loglevel is selected.
202          */
203         int debugging;
204
205         /** The loglevel in use by the IRC server
206          */
207         int LogLevel;
208
209         /** How many seconds to wait before exiting
210          * the program when /DIE is correctly issued.
211          */
212         int DieDelay;
213
214         /** A list of IP addresses the server is listening
215          * on.
216          */
217         char addrs[MAXBUF][255];
218
219         /** The MOTD file, cached in a file_cache type.
220          */
221         file_cache MOTD;
222
223         /** The RULES file, cached in a file_cache type.
224          */
225         file_cache RULES;
226
227         /** The full pathname and filename of the PID
228          * file as defined in the configuration.
229          */
230         char PID[1024];
231
232         /** The parsed configuration file as a stringstream.
233          * You should pass this to any configuration methods
234          * of this class, and not access it directly. It is
235          * recommended that modules use ConfigReader instead
236          * which provides a simpler abstraction of configuration
237          * files.
238          */
239         std::stringstream config_f;
240
241         /** The connect classes in use by the IRC server.
242          */
243         ClassVector Classes;
244
245         /** A list of module names (names only, no paths)
246          * which are currently loaded by the server.
247          */
248         std::vector<std::string> module_names;
249
250         /** A list of ports which the server is listening on
251          */
252         int ports[255];
253
254         /** Boolean sets of which modules implement which functions
255          */
256         char implement_lists[255][255];
257
258         /** Global implementation list
259          */
260         char global_implementation[255];
261
262         /** A list of ports claimed by IO Modules
263          */
264         std::map<int,Module*> IOHookModule;
265
266         /** The 005 tokens of this server (ISUPPORT)
267          * populated/repopulated upon loading or unloading
268          * modules.
269          */
270         std::string data005;
271
272         /** STATS characters in this list are available
273          * only to operators.
274          */
275         char OperOnlyStats[MAXBUF];
276
277         /** The path and filename of the ircd.log file
278          */
279         std::string logpath;
280
281         /** Custom version string, which if defined can replace the system info in VERSION.
282          */
283         char CustomVersion[MAXBUF];
284
285         ServerConfig();
286
287         /** Clears the include stack in preperation for
288          * a Read() call.
289          */
290         void ClearStack();
291
292         /** Read the entire configuration into memory
293          * and initialize this class. All other methods
294          * should be used only by the core.
295          */
296         void Read(bool bail, userrec* user);
297
298         bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
299         int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
300         int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
301         int ConfValueEnum(char* tag,std::stringstream *config);
302         int EnumConf(std::stringstream *config_f,const char* tag);
303         int EnumValues(std::stringstream *config, const char* tag, int index);
304         Module* GetIOHook(int port);
305         bool AddIOHook(int port, Module* iomod);
306         bool DelIOHook(int port);
307 };
308
309
310 void Exit (int); 
311 void Start (void); 
312 void SetSignals();
313 int DaemonSeed (void); 
314 bool FileExists (const char* file);
315 int OpenTCPSocket (void); 
316 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
317 void WritePID(std::string filename);
318 int BindPorts();
319
320 #endif