]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/configreader.h
Remove VF_SERVICEPROVIDER, prevent heap allocation of ConfigReader
[user/henk/code/inspircd.git] / include / configreader.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef INSPIRCD_CONFIGREADER
15 #define INSPIRCD_CONFIGREADER
16
17 #include <sstream>
18 #include <string>
19 #include <vector>
20 #include <map>
21 #include "inspircd.h"
22 #include "modules.h"
23 #include "socketengine.h"
24 #include "socket.h"
25
26 /* Required forward definitions */
27 class ServerConfig;
28 class ServerLimits;
29 class InspIRCd;
30 class BufferedSocket;
31
32 /** A cached text file stored with its contents as lines
33  */
34 typedef std::vector<std::string> file_cache;
35
36 /** A configuration key and value pair
37  */
38 typedef std::pair<std::string, std::string> KeyVal;
39
40 struct CoreExport ConfigTag : public refcountbase
41 {
42         const std::string tag;
43         const std::string src_name;
44         const int src_line;
45         std::vector<KeyVal> items;
46
47         ConfigTag(const std::string& Tag, const std::string& file, int line)
48                 : tag(Tag), src_name(file), src_line(line) {}
49
50         std::string getString(const std::string& key, const std::string& def = "");
51         long getInt(const std::string& key, long def = 0);
52         double getFloat(const std::string& key, double def = 0);
53         bool getBool(const std::string& key, bool def = false);
54
55         bool readString(const std::string& key, std::string& value, bool allow_newline = false);
56
57         std::string getTagLocation();
58 };
59
60 /** An entire config file, built up of KeyValLists
61  */
62 typedef std::multimap<std::string, reference<ConfigTag> > ConfigDataHash;
63
64 typedef std::map<std::string, reference<ConfigTag> > TagIndex;
65
66 /** Defines the server's length limits on various length-limited
67  * items such as topics, nicknames, channel names etc.
68  */
69 class ServerLimits
70 {
71  public:
72         /** Maximum nickname length */
73         size_t NickMax;
74         /** Maximum channel length */
75         size_t ChanMax;
76         /** Maximum number of modes per line */
77         size_t MaxModes;
78         /** Maximum length of ident, not including ~ etc */
79         size_t IdentMax;
80         /** Maximum length of a quit message */
81         size_t MaxQuit;
82         /** Maximum topic length */
83         size_t MaxTopic;
84         /** Maximum kick message length */
85         size_t MaxKick;
86         /** Maximum GECOS (real name) length */
87         size_t MaxGecos;
88         /** Maximum away message length */
89         size_t MaxAway;
90
91         /** Creating the class initialises it to the defaults
92          * as in 1.1's ./configure script. Reading other values
93          * from the config will change these values.
94          */
95         ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
96         {
97         }
98
99         /** Finalises the settings by adding one. This allows for them to be used as-is
100          * without a 'value+1' when using the std::string assignment methods etc.
101          */
102         void Finalise()
103         {
104                 NickMax++;
105                 ChanMax++;
106                 IdentMax++;
107                 MaxQuit++;
108                 MaxTopic++;
109                 MaxKick++;
110                 MaxGecos++;
111                 MaxAway++;
112         }
113 };
114
115 /** This class holds the bulk of the runtime configuration for the ircd.
116  * It allows for reading new config values, accessing configuration files,
117  * and storage of the configuration data needed to run the ircd, such as
118  * the servername, connect classes, /ADMIN data, MOTDs and filenames etc.
119  */
120 class CoreExport ServerConfig
121 {
122   private:
123         void CrossCheckOperClassType();
124         void CrossCheckConnectBlocks(ServerConfig* current);
125
126  public:
127         /** Error stream, contains error output from any failed configuration parsing.
128          */
129         std::stringstream errstr;
130
131         /** True if this configuration is valid enough to run with */
132         bool valid;
133
134         /** Used to indicate who we announce invites to on a channel */
135         enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
136
137         /** Not used any more as it is named, can probably be removed or renamed.
138          */
139         int DoDownloads();
140
141         /** This holds all the information in the config file,
142          * it's indexed by tag name to a vector of key/values.
143          */
144         ConfigDataHash config_data;
145
146         /** Length limits, see definition of ServerLimits class
147          */
148         ServerLimits Limits;
149
150         /** Clones CIDR range for ipv4 (0-32)
151          * Defaults to 32 (checks clones on all IPs seperately)
152          */
153         int c_ipv4_range;
154
155         /** Clones CIDR range for ipv6 (0-128)
156          * Defaults to 128 (checks on all IPs seperately)
157          */
158         int c_ipv6_range;
159
160         /** Max number of WhoWas entries per user.
161          */
162         int WhoWasGroupSize;
163
164         /** Max number of cumulative user-entries in WhoWas.
165          *  When max reached and added to, push out oldest entry FIFO style.
166          */
167         int WhoWasMaxGroups;
168
169         /** Max seconds a user is kept in WhoWas before being pruned.
170          */
171         int WhoWasMaxKeep;
172
173         /** Both for set(g|u)id.
174          */
175         std::string SetUser;
176         std::string SetGroup;
177
178         /** Holds the server name of the local server
179          * as defined by the administrator.
180          */
181         std::string ServerName;
182
183         /** Notice to give to users when they are Xlined
184          */
185         std::string MoronBanner;
186
187         /* Holds the network name the local server
188          * belongs to. This is an arbitary field defined
189          * by the administrator.
190          */
191         std::string Network;
192
193         /** Holds the description of the local server
194          * as defined by the administrator.
195          */
196         std::string ServerDesc;
197
198         /** Holds the admin's name, for output in
199          * the /ADMIN command.
200          */
201         std::string AdminName;
202
203         /** Holds the email address of the admin,
204          * for output in the /ADMIN command.
205          */
206         std::string AdminEmail;
207
208         /** Holds the admin's nickname, for output
209          * in the /ADMIN command
210          */
211         std::string AdminNick;
212
213         /** The admin-configured /DIE password
214          */
215         std::string diepass;
216
217         /** The admin-configured /RESTART password
218          */
219         std::string restartpass;
220
221         /** The hash method for *BOTH* the die and restart passwords.
222          */
223         std::string powerhash;
224
225         /** The pathname and filename of the message of the
226          * day file, as defined by the administrator.
227          */
228         std::string motd;
229
230         /** The pathname and filename of the rules file,
231          * as defined by the administrator.
232          */
233         std::string rules;
234
235         /** The quit prefix in use, or an empty string
236          */
237         std::string PrefixQuit;
238
239         /** The quit suffix in use, or an empty string
240          */
241         std::string SuffixQuit;
242
243         /** The fixed quit message in use, or an empty string
244          */
245         std::string FixedQuit;
246
247         /** The part prefix in use, or an empty string
248          */
249         std::string PrefixPart;
250
251         /** The part suffix in use, or an empty string
252          */
253         std::string SuffixPart;
254
255         /** The fixed part message in use, or an empty string
256          */
257         std::string FixedPart;
258
259         /** The last string found within a <die> tag, or
260          * an empty string.
261          */
262         std::string DieValue;
263
264         /** The DNS server to use for DNS queries
265          */
266         std::string DNSServer;
267
268         /** Pretend disabled commands don't exist.
269          */
270         bool DisabledDontExist;
271
272         /** This variable contains a space-seperated list
273          * of commands which are disabled by the
274          * administrator of the server for non-opers.
275          */
276         std::string DisabledCommands;
277
278         /** This variable identifies which usermodes have been diabled.
279          */
280
281         char DisabledUModes[64];
282
283         /** This variable identifies which chanmodes have been disabled.
284          */
285         char DisabledCModes[64];
286
287         /** The full path to the modules directory.
288          * This is either set at compile time, or
289          * overridden in the configuration file via
290          * the <options> tag.
291          */
292         std::string ModPath;
293
294         /** The file handle of the logfile. If this
295          * value is NULL, the log file is not open,
296          * probably due to a permissions error on
297          * startup (this should not happen in normal
298          * operation!).
299          */
300         FILE *log_file;
301
302         /** If this value is true, the owner of the
303          * server specified -nofork on the command
304          * line, causing the daemon to stay in the
305          * foreground.
306          */
307         bool nofork;
308
309         /** If this value if true then all log
310          * messages will be output, regardless of
311          * the level given in the config file.
312          * This is set with the -debug commandline
313          * option.
314          */
315         bool forcedebug;
316
317         /** If this is true then log output will be
318          * written to the logfile. This is the default.
319          * If you put -nolog on the commandline then
320          * the logfile will not be written.
321          * This is meant to be used in conjunction with
322          * -debug for debugging without filling up the
323          * hard disk.
324          */
325         bool writelog;
326
327         /** If set to true, then all opers on this server are
328          * shown with a generic 'is an IRC operator' line rather
329          * than the oper type. Oper types are still used internally.
330          */
331         bool GenericOper;
332
333         /** If this value is true, banned users (+b, not extbans) will not be able to change nick
334          * if banned on any channel, nor to message them.
335          */
336         bool RestrictBannedUsers;
337
338         /** If this value is true, halfops have been
339          * enabled in the configuration file.
340          */
341         bool AllowHalfop;
342
343         /** If this is set to true, then mode lists (e.g
344          * MODE #chan b) are hidden from unprivileged
345          * users.
346          */
347         bool HideModeLists[256];
348
349         /** The number of seconds the DNS subsystem
350          * will wait before timing out any request.
351          */
352         int dns_timeout;
353
354         /** The size of the read() buffer in the user
355          * handling code, used to read data into a user's
356          * recvQ.
357          */
358         int NetBufferSize;
359
360         /** The value to be used for listen() backlogs
361          * as default.
362          */
363         int MaxConn;
364
365         /** The soft limit value assigned to the irc server.
366          * The IRC server will not allow more than this
367          * number of local users.
368          */
369         unsigned int SoftLimit;
370
371         /** Maximum number of targets for a multi target command
372          * such as PRIVMSG or KICK
373          */
374         unsigned int MaxTargets;
375
376         /** The maximum number of /WHO results allowed
377          * in any single /WHO command.
378          */
379         int MaxWhoResults;
380
381         /** True if the DEBUG loglevel is selected.
382          */
383         int debugging;
384
385         /** How many seconds to wait before exiting
386          * the program when /DIE is correctly issued.
387          */
388         int DieDelay;
389
390         /** True if we're going to hide netsplits as *.net *.split for non-opers
391          */
392         bool HideSplits;
393
394         /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines,
395          * K-Lines, Z-Lines)
396          */
397         bool HideBans;
398
399         /** Announce invites to the channel with a server notice
400          */
401         InviteAnnounceState AnnounceInvites;
402
403         /** If this is enabled then operators will
404          * see invisible (+i) channels in /whois.
405          */
406         bool OperSpyWhois;
407
408         /** Set to a non-empty string to obfuscate the server name of users in WHOIS
409          */
410         std::string HideWhoisServer;
411
412         /** Set to a non empty string to obfuscate nicknames prepended to a KILL.
413          */
414         std::string HideKillsServer;
415
416         /** The MOTD file, cached in a file_cache type.
417          */
418         file_cache MOTD;
419
420         /** The RULES file, cached in a file_cache type.
421          */
422         file_cache RULES;
423
424         /** The full pathname and filename of the PID
425          * file as defined in the configuration.
426          */
427         std::string PID;
428
429         /** The connect classes in use by the IRC server.
430          */
431         ClassVector Classes;
432
433         /** The 005 tokens of this server (ISUPPORT)
434          * populated/repopulated upon loading or unloading
435          * modules.
436          */
437         std::string data005;
438
439         /** isupport strings
440          */
441         std::vector<std::string> isupport;
442
443         /** STATS characters in this list are available
444          * only to operators.
445          */
446         std::string UserStats;
447
448         /** The path and filename of the ircd.log file
449          */
450         std::string logpath;
451
452         /** Default channel modes
453          */
454         std::string DefaultModes;
455
456         /** Custom version string, which if defined can replace the system info in VERSION.
457          */
458         std::string CustomVersion;
459
460         /** List of u-lined servers
461          */
462         std::map<irc::string, bool> ulines;
463
464         /** Max banlist sizes for channels (the std::string is a glob)
465          */
466         std::map<std::string, int> maxbans;
467
468         /** Directory where the inspircd binary resides
469          */
470         std::string MyDir;
471
472         /** If set to true, no user DNS lookups are to be performed
473          */
474         bool NoUserDns;
475
476         /** If set to true, provide syntax hints for unknown commands
477          */
478         bool SyntaxHints;
479
480         /** If set to true, users appear to quit then rejoin when their hosts change.
481          * This keeps clients synchronized properly.
482          */
483         bool CycleHosts;
484
485         /** If set to true, prefixed channel NOTICEs and PRIVMSGs will have the prefix
486          *  added to the outgoing text for undernet style msg prefixing.
487          */
488         bool UndernetMsgPrefix;
489
490         /** If set to true, the full nick!user@host will be shown in the TOPIC command
491          * for who set the topic last. If false, only the nick is shown.
492          */
493         bool FullHostInTopic;
494
495         /** All oper type definitions from the config file
496          */
497         TagIndex opertypes;
498
499         /** All oper class definitions from the config file
500          */
501         TagIndex operclass;
502
503         /** Saved argv from startup
504          */
505         char** argv;
506
507         /** Saved argc from startup
508          */
509         int argc;
510
511         /** Max channels per user
512          */
513         unsigned int MaxChans;
514
515         /** Oper max channels per user
516          */
517         unsigned int OperMaxChans;
518
519         /** TS6-like server ID.
520          * NOTE: 000...999 are usable for InspIRCd servers. This
521          * makes code simpler. 0AA, 1BB etc with letters are reserved
522          * for services use.
523          */
524         std::string sid;
525
526         /** True if we have been told to run the testsuite from the commandline,
527          * rather than entering the mainloop.
528          */
529         bool TestSuite;
530
531         /** Construct a new ServerConfig
532          */
533         ServerConfig();
534
535         /** Get server ID as string with required leading zeroes
536          */
537         std::string GetSID();
538
539         /** Update the 005 vector
540          */
541         void Update005();
542
543         /** Send the 005 numerics (ISUPPORT) to a user
544          */
545         void Send005(User* user);
546
547         /** Read the entire configuration into memory
548          * and initialize this class. All other methods
549          * should be used only by the core.
550          */
551         void Read();
552
553         /** Apply configuration changes from the old configuration.
554          */
555         void Apply(ServerConfig* old, const std::string &useruid);
556         void ApplyModules(User* user);
557
558         void Fill();
559
560         /** Read a file into a file_cache object
561          */
562         bool ReadFile(file_cache &F, const std::string& fname);
563
564         /* Returns true if the given string starts with a windows drive letter
565          */
566         bool StartsWithWindowsDriveLetter(const std::string &path);
567
568         /** Load 'filename' into 'target', with the new config parser everything is parsed into
569          * tag/key/value at load-time rather than at read-value time.
570          */
571         bool LoadConf(FILE* &conf, const char* filename, bool allowexeinc);
572
573         /** Load 'filename' into 'target', with the new config parser everything is parsed into
574          * tag/key/value at load-time rather than at read-value time.
575          */
576         bool LoadConf(FILE* &conf, const std::string &filename, bool allowexeinc);
577
578         ConfigTag* ConfValue(const std::string& tag, int offset = 0);
579
580         bool ApplyDisabledCommands(const std::string& data);
581
582         /** Clean a filename, stripping the directories (and drives) from string.
583          * @param name Directory to tidy
584          * @return The cleaned filename
585          */
586         static const char* CleanFilename(const char* name);
587
588         /** Check if a file exists.
589          * @param file The full path to a file
590          * @return True if the file exists and is readable.
591          */
592         static bool FileExists(const char* file);
593
594         /** If this value is true, invites will bypass more than just +i
595          */
596         bool InvBypassModes;
597
598 };
599 #endif