]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd_io.h
Typo in declaration
[user/henk/code/inspircd.git] / include / inspircd_io.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2005 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
26 /** Flags for use with log()
27  */
28 #define DEBUG 10
29 #define VERBOSE 20
30 #define DEFAULT 30
31 #define SPARSE 40
32 #define NONE 50
33
34 /** This class holds the bulk of the runtime configuration for the ircd.
35  * It allows for reading new config values, accessing configuration files,
36  * and storage of the configuration data needed to run the ircd, such as
37  * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
38  */
39 class ServerConfig : public classbase
40 {
41   private:
42         /** This variable holds the names of all
43          * files included from the main one. This
44          * is used to make sure that no files are
45          * recursively included.
46          */
47         std::vector<std::string> include_stack;
48
49         /** Used by the config file subsystem to
50          * safely read a C-style string without
51          * dependency upon any certain style of
52          * linefeed, e.g. it can read both windows
53          * and UNIX style linefeeds transparently.
54          */
55         int fgets_safe(char* buffer, size_t maxsize, FILE* &file);
56
57         /** This private method processes one line of
58          * configutation, appending errors to errorstream
59          * and setting error if an error has occured.
60          */
61         std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errorstream, bool &error, std::string filename);
62
63   public:
64
65         /** Holds the server name of the local server
66          * as defined by the administrator.
67          */
68         char ServerName[MAXBUF];
69         
70         /* Holds the network name the local server
71          * belongs to. This is an arbitary field defined
72          * by the administrator.
73          */
74         char Network[MAXBUF];
75
76         /** Holds the description of the local server
77          * as defined by the administrator.
78          */
79         char ServerDesc[MAXBUF];
80
81         /** Holds the admin's name, for output in
82          * the /ADMIN command.
83          */
84         char AdminName[MAXBUF];
85
86         /** Holds the email address of the admin,
87          * for output in the /ADMIN command.
88          */
89         char AdminEmail[MAXBUF];
90
91         /** Holds the admin's nickname, for output
92          * in the /ADMIN command
93          */
94         char AdminNick[MAXBUF];
95
96         /** The admin-configured /DIE password
97          */
98         char diepass[MAXBUF];
99
100         /** The admin-configured /RESTART password
101          */
102         char restartpass[MAXBUF];
103
104         /** The pathname and filename of the message of the
105          * day file, as defined by the administrator.
106          */
107         char motd[MAXBUF];
108
109         /** The pathname and filename of the rules file,
110          * as defined by the administrator.
111          */
112         char rules[MAXBUF];
113
114         /** The quit prefix in use, or an empty string
115          */
116         char PrefixQuit[MAXBUF];
117
118         /** The last string found within a <die> tag, or
119          * an empty string.
120          */
121         char DieValue[MAXBUF];
122
123         /** The DNS server to use for DNS queries
124          */
125         char DNSServer[MAXBUF];
126
127         /** This variable contains a space-seperated list
128          * of commands which are disabled by the
129          * administrator of the server for non-opers.
130          */
131         char DisabledCommands[MAXBUF];
132
133         /** The full path to the modules directory.
134          * This is either set at compile time, or
135          * overridden in the configuration file via
136          * the <options> tag.
137          */
138         char ModPath[1024];
139
140         /** The full pathname to the executable, as
141          * given in argv[0] when the program starts.
142          */
143         char MyExecutable[1024];
144
145         /** The file handle of the logfile. If this
146          * value is NULL, the log file is not open,
147          * probably due to a permissions error on
148          * startup (this should not happen in normal
149          * operation!).
150          */
151         FILE *log_file;
152
153         /** If this value is true, the owner of the
154          * server specified -nofork on the command
155          * line, causing the daemon to stay in the
156          * foreground.
157          */
158         bool nofork;
159
160         /** If this value is true, the owner of the
161          * server has chosen to unlimit the coredump
162          * size to as large a value as his account
163          * settings will allow. This is often used
164          * when debugging.
165          */
166         bool unlimitcore;
167
168         /** If this value is true, halfops have been
169          * enabled in the configuration file.
170          */
171         bool AllowHalfop;
172
173         /** The number of seconds the DNS subsystem
174          * will wait before timing out any request.
175          */
176         int dns_timeout;
177
178         /** The size of the read() buffer in the user
179          * handling code, used to read data into a user's
180          * recvQ.
181          */
182         int NetBufferSize;
183
184         /** The value to be used for listen() backlogs
185          * as default.
186          */
187         int MaxConn;
188
189         /** The soft limit value assigned to the irc server.
190          * The IRC server will not allow more than this
191          * number of local users.
192          */
193         unsigned int SoftLimit;
194
195         /** The maximum number of /WHO results allowed
196          * in any single /WHO command.
197          */
198         int MaxWhoResults;
199
200         /** True if the DEBUG loglevel is selected.
201          */
202         int debugging;
203
204         /** The loglevel in use by the IRC server
205          */
206         int LogLevel;
207
208         /** How many seconds to wait before exiting
209          * the program when /DIE is correctly issued.
210          */
211         int DieDelay;
212
213         /** A list of IP addresses the server is listening
214          * on.
215          */
216         char addrs[MAXBUF][255];
217
218         /** The MOTD file, cached in a file_cache type.
219          */
220         file_cache MOTD;
221
222         /** The RULES file, cached in a file_cache type.
223          */
224         file_cache RULES;
225
226         /** The full pathname and filename of the PID
227          * file as defined in the configuration.
228          */
229         char PID[1024];
230
231         /** The parsed configuration file as a stringstream.
232          * You should pass this to any configuration methods
233          * of this class, and not access it directly. It is
234          * recommended that modules use ConfigReader instead
235          * which provides a simpler abstraction of configuration
236          * files.
237          */
238         std::stringstream config_f;
239
240         /** The connect classes in use by the IRC server.
241          */
242         ClassVector Classes;
243
244         /** A list of module names (names only, no paths)
245          * which are currently loaded by the server.
246          */
247         std::vector<std::string> module_names;
248
249         /** A list of ports which the server is listening on
250          */
251         int ports[255];
252
253         ServerConfig();
254
255         /** Clears the include stack in preperation for
256          * a Read() call.
257          */
258         void ClearStack();
259
260         /** Read the entire configuration into memory
261          * and initialize this class. All other methods
262          * should be used only by the core.
263          */
264         void Read(bool bail, userrec* user);
265
266         bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream);
267         int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *config);
268         int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
269         int ConfValueEnum(char* tag,std::stringstream *config);
270         int EnumConf(std::stringstream *config_f,const char* tag);
271         int EnumValues(std::stringstream *config, const char* tag, int index);
272 };
273
274
275 void Exit (int); 
276 void Start (void); 
277 int DaemonSeed (void); 
278 bool FileExists (const char* file);
279 int OpenTCPSocket (void); 
280 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr);
281 void WritePID(std::string filename);
282 int BindPorts();
283
284 #endif