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