InspIRCd  3.0
configreader.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2007, 2009 Dennis Friis <[email protected]>
6  * Copyright (C) 2006-2008 Craig Edwards <[email protected]>
7  * Copyright (C) 2006-2008 Robin Burchell <[email protected]>
8  * Copyright (C) 2006 Oliver Lupton <[email protected]>
9  *
10  * This file is part of InspIRCd. InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 
24 #pragma once
25 
26 #include <sstream>
27 #include <string>
28 #include <vector>
29 #include <map>
30 #include "inspircd.h"
31 #include "modules.h"
32 #include "socketengine.h"
33 #include "socket.h"
34 
36 class CoreExport ConfigTag : public refcountbase
37 {
38  ConfigItems items;
39  public:
40  const std::string tag;
41  const std::string src_name;
42  const int src_line;
43 
45  std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX);
47  long getInt(const std::string& key, long def = 0, long min = LONG_MIN, long max = LONG_MAX);
49  double getFloat(const std::string& key, double def = 0);
51  bool getBool(const std::string& key, bool def = false);
52 
61  long getDuration(const std::string& key, long def = 0, long min = LONG_MIN, long max = LONG_MAX);
62 
69  bool readString(const std::string& key, std::string& value, bool allow_newline = false);
70 
79  void CheckRange(const std::string& key, long& res, long def, long min, long max);
80 
81  std::string getTagLocation();
82 
83  inline const ConfigItems& getItems() const { return items; }
84 
86  static ConfigTag* create(const std::string& Tag, const std::string& file, int line, ConfigItems*& Items);
87  private:
88  ConfigTag(const std::string& Tag, const std::string& file, int line);
89 };
90 
95 {
96  public:
98  size_t NickMax;
100  size_t ChanMax;
102  size_t MaxModes;
104  size_t IdentMax;
106  size_t MaxQuit;
108  size_t MaxTopic;
110  size_t MaxKick;
112  size_t MaxGecos;
114  size_t MaxAway;
116  size_t MaxLine;
118  size_t MaxHost;
119 
123  ServerLimits(ConfigTag* tag);
124 
126  size_t GetMaxMask() const { return NickMax + 1 + IdentMax + 1 + MaxHost; }
127 };
128 
130 {
136  bool nofork;
137 
145 
154  bool writelog;
155 
158  int argc;
159 
162  char** argv;
163 };
164 
165 class CoreExport OperInfo : public refcountbase
166 {
167  public:
169  PrivSet AllowedOperCommands;
170  PrivSet AllowedPrivs;
171 
173  std::bitset<64> AllowedUserModes;
174 
176  std::bitset<64> AllowedChanModes;
177 
183  std::vector<reference<ConfigTag> > class_blocks;
185  std::string name;
186 
188  std::string getConfig(const std::string& key);
189  void init();
190 };
191 
197 class CoreExport ServerConfig
198 {
199  private:
200  void CrossCheckOperClassType();
201  void CrossCheckConnectBlocks(ServerConfig* current);
202 
203  public:
205  {
206  public:
208  std::string Config;
209 
211  std::string Data;
212 
214  std::string Log;
215 
217  std::string Module;
218 
219  ServerPaths(ConfigTag* tag);
220 
221  std::string PrependConfig(const std::string& fn) const { return FileSystem::ExpandPath(Config, fn); }
222  std::string PrependData(const std::string& fn) const { return FileSystem::ExpandPath(Data, fn); }
223  std::string PrependLog(const std::string& fn) const { return FileSystem::ExpandPath(Log, fn); }
224  std::string PrependModule(const std::string& fn) const { return FileSystem::ExpandPath(Module, fn); }
225  };
226 
229  typedef std::vector<reference<ConnectClass> > ClassVector;
230 
234 
238  ConfigTag* ConfValue(const std::string& tag);
239 
240  ConfigTagList ConfTags(const std::string& tag);
241 
244 
247  std::stringstream errstr;
248 
250  bool valid;
251 
254 
256  enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
257  enum OperSpyWhoisState { SPYWHOIS_NONE, SPYWHOIS_SINGLEMSG, SPYWHOIS_SPLITMSG };
258 
262  ConfigDataHash config_data;
263 
267  ConfigFileCache Files;
268 
272 
275 
279 
284 
289 
293  std::string ServerName;
294 
297  std::string XLineMessage;
298 
299  /* Holds the network name the local server
300  * belongs to. This is an arbitary field defined
301  * by the administrator.
302  */
303  std::string Network;
304 
308  std::string ServerDesc;
309 
313 
318  std::string DisabledCommands;
319 
322  std::bitset<64> DisabledUModes;
323 
326  std::bitset<64> DisabledCModes;
327 
333 
338 
344 
348  int MaxConn;
349 
356 
361  unsigned int SoftLimit;
362 
366  unsigned int MaxTargets;
367 
371 
375  bool HideBans;
376 
380 
384  OperSpyWhoisState OperSpyWhois;
385 
387  bool RawLog;
388 
391  std::string HideWhoisServer;
392 
395  std::string HideKillsServer;
396 
400 
404  std::string PID;
405 
408  ClassVector Classes;
409 
413  std::string UserStats;
414 
417  std::string DefaultModes;
418 
421  std::string CustomVersion;
422 
426 
429  std::string CaseMapping;
430 
435 
440 
443  OperIndex oper_blocks;
444 
447  OperIndex OperTypes;
448 
451  unsigned int MaxChans;
452 
455  unsigned int OperMaxChans;
456 
462  std::string sid;
463 
466  ServerConfig();
467 
468  ~ServerConfig();
469 
472  const std::string& GetSID() const { return sid; }
473 
478  void Read();
479 
482  void Apply(ServerConfig* old, const std::string &useruid);
483  void ApplyModules(User* user);
484 
485  void Fill();
486 
487  bool ApplyDisabledCommands(const std::string& data);
488 
493  static std::string Escape(const std::string& str, bool xml = true);
494 
498 };
499 
503 class CoreExport ConfigReaderThread : public Thread
504 {
505  ServerConfig* Config;
506  volatile bool done;
507  public:
508  const std::string TheUserUID;
509  ConfigReaderThread(const std::string &useruid)
510  : Config(new ServerConfig), done(false), TheUserUID(useruid)
511  {
512  }
513 
514  virtual ~ConfigReaderThread()
515  {
516  delete Config;
517  }
518 
519  void Run();
521  void Finish();
522  bool IsDone() { return done; }
523 };
524 
525 class CoreExport ConfigStatus
526 {
527  public:
528  User* const srcuser;
529 
530  ConfigStatus(User* user = NULL)
531  : srcuser(user)
532  {
533  }
534 };
bool SyntaxHints
Definition: configreader.h:425
static std::string ExpandPath(const std::string &base, const std::string &fragment)
Definition: fileutils.cpp:68
CommandLineConf cmdline
Definition: configreader.h:278
std::string sid
Definition: configreader.h:462
ClassVector Classes
Definition: configreader.h:408
std::string DefaultModes
Definition: configreader.h:417
size_t MaxQuit
Definition: configreader.h:106
std::string Data
Definition: configreader.h:211
std::string XLineMessage
Definition: configreader.h:297
Definition: configreader.h:36
int argc
Definition: configreader.h:158
size_t MaxLine
Definition: configreader.h:116
bool HideBans
Definition: configreader.h:375
Definition: configreader.h:165
std::string HideKillsServer
Definition: configreader.h:395
bool forcedebug
Definition: configreader.h:144
std::stringstream errstr
Definition: configreader.h:247
unsigned int OperMaxChans
Definition: configreader.h:455
unsigned int MaxChans
Definition: configreader.h:451
std::bitset< 64 > DisabledUModes
Definition: configreader.h:322
std::string DisabledCommands
Definition: configreader.h:318
Definition: users.h:224
reference< ConfigTag > oper_block
Definition: configreader.h:179
std::string CustomVersion
Definition: configreader.h:421
std::string PID
Definition: configreader.h:404
bool CycleHostsFromUser
Definition: configreader.h:434
InviteAnnounceState
Definition: configreader.h:256
Definition: configreader.h:204
size_t MaxGecos
Definition: configreader.h:112
Definition: configreader.h:503
unsigned int MaxTargets
Definition: configreader.h:366
size_t MaxTopic
Definition: configreader.h:108
std::string ServerDesc
Definition: configreader.h:308
Definition: threadengine.h:33
std::vector< reference< ConfigTag > > class_blocks
Definition: configreader.h:183
std::bitset< 64 > AllowedChanModes
Definition: configreader.h:176
bool NoSnoticeStack
Definition: configreader.h:497
OperIndex oper_blocks
Definition: configreader.h:443
char ** argv
Definition: configreader.h:162
ConfigDataHash config_data
Definition: configreader.h:262
ConfigTag * EmptyTag
Definition: configreader.h:243
bool WildcardIPv6
Definition: configreader.h:253
bool RestrictBannedUsers
Definition: configreader.h:337
std::string name
Definition: configreader.h:185
ServerLimits Limits
Definition: configreader.h:271
size_t MaxHost
Definition: configreader.h:118
Definition: base.h:85
Definition: configreader.h:94
bool HideULineKills
Definition: configreader.h:399
int MaxConn
Definition: configreader.h:348
size_t GetMaxMask() const
Definition: configreader.h:126
bool DisabledDontExist
Definition: configreader.h:312
bool FullHostInTopic
Definition: configreader.h:439
size_t IdentMax
Definition: configreader.h:104
reference< ConfigTag > type_block
Definition: configreader.h:181
OperIndex OperTypes
Definition: configreader.h:447
unsigned int SoftLimit
Definition: configreader.h:361
size_t NickMax
Definition: configreader.h:98
int NetBufferSize
Definition: configreader.h:343
std::string Module
Definition: configreader.h:217
OperSpyWhoisState OperSpyWhois
Definition: configreader.h:384
const std::string & GetSID() const
Definition: configreader.h:472
insp::flat_map< std::string, reference< OperInfo > > OperIndex
Definition: configreader.h:233
std::string UserStats
Definition: configreader.h:413
int c_ipv4_range
Definition: configreader.h:283
Definition: configreader.h:129
size_t MaxAway
Definition: configreader.h:114
std::bitset< 64 > AllowedUserModes
Definition: configreader.h:173
std::string HideWhoisServer
Definition: configreader.h:391
size_t MaxKick
Definition: configreader.h:110
std::string Config
Definition: configreader.h:208
std::string CaseMapping
Definition: configreader.h:429
std::bitset< 64 > DisabledCModes
Definition: configreader.h:326
std::vector< reference< ConnectClass > > ClassVector
Definition: configreader.h:229
bool RawLog
Definition: configreader.h:387
int c_ipv6_range
Definition: configreader.h:288
bool valid
Definition: configreader.h:250
std::string Log
Definition: configreader.h:214
std::string ServerName
Definition: configreader.h:293
Definition: configreader.h:525
size_t ChanMax
Definition: configreader.h:100
bool GenericOper
Definition: configreader.h:332
Definition: configreader.h:197
bool CCOnConnect
Definition: configreader.h:355
ConfigFileCache Files
Definition: configreader.h:267
InviteAnnounceState AnnounceInvites
Definition: configreader.h:379
size_t MaxModes
Definition: configreader.h:102
bool writelog
Definition: configreader.h:154
ServerPaths Paths
Definition: configreader.h:274
bool HideSplits
Definition: configreader.h:370
bool nofork
Definition: configreader.h:136