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 
493 class CoreExport ConfigStatus
494 {
495  public:
496  User* const srcuser;
497 
498  ConfigStatus(User* user = NULL)
499  : srcuser(user)
500  {
501  }
502 };
bool SyntaxHints
Definition: configreader.h:400
static std::string ExpandPath(const std::string &base, const std::string &fragment)
Definition: fileutils.cpp:68
size_t MaxReal
Definition: configreader.h:107
CommandLineConf cmdline
Definition: configreader.h:303
std::string sid
Definition: configreader.h:432
ClassVector Classes
Definition: configreader.h:388
std::string DefaultModes
Definition: configreader.h:392
virtual void Run()=0
size_t MaxQuit
Definition: configreader.h:101
std::string Data
Definition: configreader.h:235
BannedUserTreatment RestrictBannedUsers
Definition: configreader.h:336
std::string HideServer
Definition: configreader.h:379
std::string XLineMessage
Definition: configreader.h:322
Definition: configreader.h:37
int argc
Definition: configreader.h:165
size_t MaxLine
Definition: configreader.h:111
bool HideBans
Definition: configreader.h:373
Definition: configreader.h:172
bool forcedebug
Definition: configreader.h:139
std::stringstream errstr
Definition: configreader.h:276
unsigned int OperMaxChans
Definition: configreader.h:425
unsigned int MaxChans
Definition: configreader.h:421
Definition: users.h:224
reference< ConfigTag > oper_block
Definition: configreader.h:185
std::string CustomVersion
Definition: configreader.h:396
std::string PID
Definition: configreader.h:384
Definition: configreader.h:228
BannedUserTreatment
Definition: configreader.h:216
Definition: configreader.h:471
unsigned int MaxTargets
Definition: configreader.h:365
size_t MaxTopic
Definition: configreader.h:103
std::string ServerDesc
Definition: configreader.h:333
time_t TimeSkipWarn
Definition: configreader.h:368
Definition: threadengine.h:33
std::vector< reference< ConfigTag > > class_blocks
Definition: configreader.h:189
std::bitset< 64 > AllowedChanModes
Definition: configreader.h:182
bool NoSnoticeStack
Definition: configreader.h:465
OperIndex oper_blocks
Definition: configreader.h:413
char ** argv
Definition: configreader.h:169
ConfigDataHash config_data
Definition: configreader.h:287
ConfigTag * EmptyTag
Definition: configreader.h:272
bool WildcardIPv6
Definition: configreader.h:282
std::string name
Definition: configreader.h:191
ServerLimits Limits
Definition: configreader.h:296
size_t MaxHost
Definition: configreader.h:113
Definition: base.h:85
Definition: configreader.h:89
unsigned char c_ipv6_range
Definition: configreader.h:313
int MaxConn
Definition: configreader.h:347
size_t GetMaxMask() const
Definition: configreader.h:121
bool FullHostInTopic
Definition: configreader.h:409
size_t IdentMax
Definition: configreader.h:99
Definition: modules.h:240
reference< ConfigTag > type_block
Definition: configreader.h:187
OperIndex OperTypes
Definition: configreader.h:417
unsigned char c_ipv4_range
Definition: configreader.h:308
unsigned int SoftLimit
Definition: configreader.h:360
size_t NickMax
Definition: configreader.h:93
int NetBufferSize
Definition: configreader.h:342
std::string Module
Definition: configreader.h:241
bool writepid
Definition: configreader.h:161
const std::string & GetSID() const
Definition: configreader.h:442
insp::flat_map< std::string, reference< OperInfo > > OperIndex
Definition: configreader.h:257
Definition: configreader.h:124
ServerLimits(ConfigTag *tag)
Definition: configreader.cpp:32
size_t MaxAway
Definition: configreader.h:109
std::bitset< 64 > AllowedUserModes
Definition: configreader.h:179
size_t MaxKick
Definition: configreader.h:105
std::string Config
Definition: configreader.h:232
std::string CaseMapping
Definition: configreader.h:404
std::vector< reference< ConnectClass > > ClassVector
Definition: configreader.h:253
bool RawLog
Definition: configreader.h:376
Definition: token_list.h:24
bool valid
Definition: configreader.h:279
std::string Log
Definition: configreader.h:238
std::string ServerName
Definition: configreader.h:318
Definition: configreader.h:493
size_t ChanMax
Definition: configreader.h:95
Definition: configreader.h:222
Definition: configreader.h:219
Definition: configreader.h:208
bool CCOnConnect
Definition: configreader.h:354
ConfigFileCache Files
Definition: configreader.h:292
size_t MaxModes
Definition: configreader.h:97
bool writelog
Definition: configreader.h:149
ServerPaths Paths
Definition: configreader.h:299
bool nofork
Definition: configreader.h:131