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 #include "token_list.h"
35 
37 class CoreExport ConfigTag : public refcountbase
38 {
39  ConfigItems items;
40  public:
41  const std::string tag;
42  const std::string src_name;
43  const int src_line;
44 
46  std::string getString(const std::string& key, const std::string& def, const TR1NS::function<bool(const std::string&)>& validator);
48  std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX);
50  long getInt(const std::string& key, long def, long min = LONG_MIN, long max = LONG_MAX);
52  unsigned long getUInt(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX);
54  double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX);
56  bool getBool(const std::string& key, bool def = false);
57 
66  unsigned long getDuration(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX);
67 
74  bool readString(const std::string& key, std::string& value, bool allow_newline = false);
75 
76  std::string getTagLocation();
77 
78  inline const ConfigItems& getItems() const { return items; }
79 
81  static ConfigTag* create(const std::string& Tag, const std::string& file, int line, ConfigItems*& Items);
82  private:
83  ConfigTag(const std::string& Tag, const std::string& file, int line);
84 };
85 
90 {
91  public:
93  size_t NickMax;
95  size_t ChanMax;
97  size_t MaxModes;
99  size_t IdentMax;
101  size_t MaxQuit;
103  size_t MaxTopic;
105  size_t MaxKick;
107  size_t MaxReal;
109  size_t MaxAway;
111  size_t MaxLine;
113  size_t MaxHost;
114 
118  ServerLimits(ConfigTag* tag);
119 
121  size_t GetMaxMask() const { return NickMax + 1 + IdentMax + 1 + MaxHost; }
122 };
123 
125 {
131  bool nofork;
132 
140 
149  bool writelog;
150 
161  bool writepid;
162 
165  int argc;
166 
169  char** argv;
170 };
171 
172 class CoreExport OperInfo : public refcountbase
173 {
174  public:
175  TokenList AllowedOperCommands;
176  TokenList AllowedPrivs;
177 
179  std::bitset<64> AllowedUserModes;
180 
182  std::bitset<64> AllowedChanModes;
183 
189  std::vector<reference<ConfigTag> > class_blocks;
191  std::string name;
192 
196  OperInfo(const std::string& Name);
197 
199  std::string getConfig(const std::string& key);
200  void init();
201 };
202 
208 class CoreExport ServerConfig
209 {
210  private:
211  void CrossCheckOperClassType();
212  void CrossCheckConnectBlocks(ServerConfig* current);
213 
214  public:
217  {
220 
223 
225  BUT_RESTRICT_NOTIFY
226  };
227 
229  {
230  public:
232  std::string Config;
233 
235  std::string Data;
236 
238  std::string Log;
239 
241  std::string Module;
242 
243  ServerPaths(ConfigTag* tag);
244 
245  std::string PrependConfig(const std::string& fn) const { return FileSystem::ExpandPath(Config, fn); }
246  std::string PrependData(const std::string& fn) const { return FileSystem::ExpandPath(Data, fn); }
247  std::string PrependLog(const std::string& fn) const { return FileSystem::ExpandPath(Log, fn); }
248  std::string PrependModule(const std::string& fn) const { return FileSystem::ExpandPath(Module, fn); }
249  };
250 
253  typedef std::vector<reference<ConnectClass> > ClassVector;
254 
258 
263  ConfigTag* ConfValue(const std::string& tag);
264 
269  ConfigTagList ConfTags(const std::string& tag);
270 
273 
276  std::stringstream errstr;
277 
279  bool valid;
280 
283 
287  ConfigDataHash config_data;
288 
292  ConfigFileCache Files;
293 
297 
300 
304 
308  unsigned char c_ipv4_range;
309 
313  unsigned char c_ipv6_range;
314 
318  std::string ServerName;
319 
322  std::string XLineMessage;
323 
324  /* Holds the network name the local server
325  * belongs to. This is an arbitary field defined
326  * by the administrator.
327  */
328  std::string Network;
329 
333  std::string ServerDesc;
334 
337 
343 
347  int MaxConn;
348 
355 
360  unsigned int SoftLimit;
361 
365  unsigned int MaxTargets;
366 
368  time_t TimeSkipWarn;
369 
373  bool HideBans;
374 
376  bool RawLog;
377 
379  std::string HideServer;
380 
384  std::string PID;
385 
389 
392  std::string DefaultModes;
393 
396  std::string CustomVersion;
397 
401 
404  std::string CaseMapping;
405 
410 
414 
418 
421  unsigned int MaxChans;
422 
425  unsigned int OperMaxChans;
426 
432  std::string sid;
433 
436  ServerConfig();
437 
438  ~ServerConfig();
439 
442  const std::string& GetSID() const { return sid; }
443 
448  void Read();
449 
452  void Apply(ServerConfig* old, const std::string &useruid);
453  void ApplyModules(User* user);
454 
455  void Fill();
456 
461  static std::string Escape(const std::string& str, bool xml = true);
462 
466 };
467 
471 class CoreExport ConfigReaderThread : public Thread
472 {
473  ServerConfig* Config;
474  volatile bool done;
475  public:
476  const std::string TheUserUID;
477  ConfigReaderThread(const std::string &useruid)
478  : Config(new ServerConfig), done(false), TheUserUID(useruid)
479  {
480  }
481 
482  virtual ~ConfigReaderThread()
483  {
484  delete Config;
485  }
486 
487  void Run() CXX11_OVERRIDE;
489  void Finish();
490  bool IsDone() { return done; }
491 };
492 
494 class CoreExport ConfigStatus
495 {
496  public:
498  bool const initial;
499 
501  User* const srcuser;
502 
507  ConfigStatus(User* user = NULL, bool isinitial = false)
508  : initial(isinitial)
509  , srcuser(user)
510  {
511  }
512 };
OperInfo
Definition: configreader.h:172
ServerConfig::BUT_RESTRICT_SILENT
Definition: configreader.h:222
ServerConfig::MaxTargets
unsigned int MaxTargets
Definition: configreader.h:365
ServerConfig::cmdline
CommandLineConf cmdline
Definition: configreader.h:303
ServerConfig::ServerDesc
std::string ServerDesc
Definition: configreader.h:333
ServerConfig::c_ipv4_range
unsigned char c_ipv4_range
Definition: configreader.h:308
ServerConfig::OperIndex
insp::flat_map< std::string, reference< OperInfo > > OperIndex
Definition: configreader.h:257
ServerConfig::Limits
ServerLimits Limits
Definition: configreader.h:296
ServerConfig::valid
bool valid
Definition: configreader.h:279
ServerConfig::errstr
std::stringstream errstr
Definition: configreader.h:276
ConfigReaderThread
Definition: configreader.h:471
CommandLineConf
Definition: configreader.h:124
ServerConfig::MaxConn
int MaxConn
Definition: configreader.h:347
insp::flat_map< std::string, std::string, irc::insensitive_swo >
ServerConfig::OperTypes
OperIndex OperTypes
Definition: configreader.h:417
ServerLimits::ServerLimits
ServerLimits(ConfigTag *tag)
Definition: configreader.cpp:32
OperInfo::oper_block
reference< ConfigTag > oper_block
Definition: configreader.h:185
ServerConfig::DefaultModes
std::string DefaultModes
Definition: configreader.h:392
ConfigStatus::ConfigStatus
ConfigStatus(User *user=NULL, bool isinitial=false)
Definition: configreader.h:507
ServerConfig::CCOnConnect
bool CCOnConnect
Definition: configreader.h:354
reference< ConfigTag >
Thread
Definition: threadengine.h:33
ServerLimits::IdentMax
size_t IdentMax
Definition: configreader.h:99
refcountbase
Definition: base.h:85
ServerConfig::CaseMapping
std::string CaseMapping
Definition: configreader.h:404
ServerConfig::ServerPaths::Data
std::string Data
Definition: configreader.h:235
ServerConfig::FullHostInTopic
bool FullHostInTopic
Definition: configreader.h:409
ServerConfig::ServerPaths
Definition: configreader.h:228
ServerLimits
Definition: configreader.h:89
ServerConfig::RestrictBannedUsers
BannedUserTreatment RestrictBannedUsers
Definition: configreader.h:336
ServerConfig::NoSnoticeStack
bool NoSnoticeStack
Definition: configreader.h:465
ServerLimits::MaxReal
size_t MaxReal
Definition: configreader.h:107
ServerConfig::RawLog
bool RawLog
Definition: configreader.h:376
ServerConfig::TimeSkipWarn
time_t TimeSkipWarn
Definition: configreader.h:368
ServerConfig::ServerPaths::Config
std::string Config
Definition: configreader.h:232
ServerConfig::PID
std::string PID
Definition: configreader.h:384
ServerConfig::config_data
ConfigDataHash config_data
Definition: configreader.h:287
OperInfo::type_block
reference< ConfigTag > type_block
Definition: configreader.h:187
ServerConfig::ServerName
std::string ServerName
Definition: configreader.h:318
ServerConfig
Definition: configreader.h:208
ConfigStatus::initial
const bool initial
Definition: configreader.h:498
ServerConfig::c_ipv6_range
unsigned char c_ipv6_range
Definition: configreader.h:313
ServerConfig::ServerPaths::Log
std::string Log
Definition: configreader.h:238
ServerConfig::sid
std::string sid
Definition: configreader.h:432
ServerConfig::Classes
ClassVector Classes
Definition: configreader.h:388
OperInfo::class_blocks
std::vector< reference< ConfigTag > > class_blocks
Definition: configreader.h:189
ServerConfig::SoftLimit
unsigned int SoftLimit
Definition: configreader.h:360
ServerLimits::MaxKick
size_t MaxKick
Definition: configreader.h:105
ServerConfig::GetSID
const std::string & GetSID() const
Definition: configreader.h:442
CommandLineConf::forcedebug
bool forcedebug
Definition: configreader.h:139
ServerConfig::BannedUserTreatment
BannedUserTreatment
Definition: configreader.h:216
ServerConfig::HideBans
bool HideBans
Definition: configreader.h:373
OperInfo::AllowedChanModes
std::bitset< 64 > AllowedChanModes
Definition: configreader.h:182
ConfigTag
Definition: configreader.h:37
ServerConfig::ClassVector
std::vector< reference< ConnectClass > > ClassVector
Definition: configreader.h:253
ServerConfig::Files
ConfigFileCache Files
Definition: configreader.h:292
ServerConfig::NetBufferSize
int NetBufferSize
Definition: configreader.h:342
CommandLineConf::writepid
bool writepid
Definition: configreader.h:161
ServerLimits::MaxLine
size_t MaxLine
Definition: configreader.h:111
ServerConfig::EmptyTag
ConfigTag * EmptyTag
Definition: configreader.h:272
ServerLimits::MaxAway
size_t MaxAway
Definition: configreader.h:109
Thread::Run
virtual void Run()=0
OperInfo::name
std::string name
Definition: configreader.h:191
ConfigStatus::srcuser
User *const srcuser
Definition: configreader.h:501
ServerConfig::MaxChans
unsigned int MaxChans
Definition: configreader.h:421
ServerConfig::WildcardIPv6
bool WildcardIPv6
Definition: configreader.h:282
Module
Definition: modules.h:242
ServerLimits::MaxHost
size_t MaxHost
Definition: configreader.h:113
User
Definition: users.h:224
ServerConfig::SyntaxHints
bool SyntaxHints
Definition: configreader.h:400
OperInfo::AllowedUserModes
std::bitset< 64 > AllowedUserModes
Definition: configreader.h:179
ServerLimits::GetMaxMask
size_t GetMaxMask() const
Definition: configreader.h:121
ServerLimits::MaxModes
size_t MaxModes
Definition: configreader.h:97
CommandLineConf::nofork
bool nofork
Definition: configreader.h:131
ServerConfig::Paths
ServerPaths Paths
Definition: configreader.h:299
ServerConfig::BUT_NORMAL
Definition: configreader.h:219
CommandLineConf::argv
char ** argv
Definition: configreader.h:169
CommandLineConf::writelog
bool writelog
Definition: configreader.h:149
ServerLimits::MaxQuit
size_t MaxQuit
Definition: configreader.h:101
ServerLimits::MaxTopic
size_t MaxTopic
Definition: configreader.h:103
ServerLimits::ChanMax
size_t ChanMax
Definition: configreader.h:95
FileSystem::ExpandPath
static std::string ExpandPath(const std::string &base, const std::string &fragment)
Definition: fileutils.cpp:72
ServerConfig::ServerPaths::Module
std::string Module
Definition: configreader.h:241
ConfigStatus
Definition: configreader.h:494
CommandLineConf::argc
int argc
Definition: configreader.h:165
TokenList
Definition: token_list.h:24
ServerConfig::oper_blocks
OperIndex oper_blocks
Definition: configreader.h:413
ServerConfig::HideServer
std::string HideServer
Definition: configreader.h:379
ServerConfig::XLineMessage
std::string XLineMessage
Definition: configreader.h:322
ServerConfig::OperMaxChans
unsigned int OperMaxChans
Definition: configreader.h:425
ServerConfig::CustomVersion
std::string CustomVersion
Definition: configreader.h:396
ServerLimits::NickMax
size_t NickMax
Definition: configreader.h:93