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 MaxGecos;
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 
262  ConfigTag* ConfValue(const std::string& tag);
263 
264  ConfigTagList ConfTags(const std::string& tag);
265 
268 
271  std::stringstream errstr;
272 
274  bool valid;
275 
278 
282  ConfigDataHash config_data;
283 
287  ConfigFileCache Files;
288 
292 
295 
299 
303  unsigned char c_ipv4_range;
304 
308  unsigned char c_ipv6_range;
309 
313  std::string ServerName;
314 
317  std::string XLineMessage;
318 
319  /* Holds the network name the local server
320  * belongs to. This is an arbitary field defined
321  * by the administrator.
322  */
323  std::string Network;
324 
328  std::string ServerDesc;
329 
333 
336  std::bitset<64> DisabledUModes;
337 
340  std::bitset<64> DisabledCModes;
341 
347 
350 
356 
360  int MaxConn;
361 
368 
373  unsigned int SoftLimit;
374 
378  unsigned int MaxTargets;
379 
383 
387  bool HideBans;
388 
390  bool RawLog;
391 
393  std::string HideServer;
394 
397  std::string HideKillsServer;
398 
402 
406  std::string PID;
407 
411 
415  std::string UserStats;
416 
419  std::string DefaultModes;
420 
423  std::string CustomVersion;
424 
428 
431  std::string CaseMapping;
432 
437 
442 
446 
450 
453  unsigned int MaxChans;
454 
457  unsigned int OperMaxChans;
458 
464  std::string sid;
465 
468  ServerConfig();
469 
470  ~ServerConfig();
471 
474  const std::string& GetSID() const { return sid; }
475 
480  void Read();
481 
484  void Apply(ServerConfig* old, const std::string &useruid);
485  void ApplyModules(User* user);
486 
487  void Fill();
488 
490  bool ApplyDisabledCommands();
491 
496  static std::string Escape(const std::string& str, bool xml = true);
497 
501 };
502 
506 class CoreExport ConfigReaderThread : public Thread
507 {
508  ServerConfig* Config;
509  volatile bool done;
510  public:
511  const std::string TheUserUID;
512  ConfigReaderThread(const std::string &useruid)
513  : Config(new ServerConfig), done(false), TheUserUID(useruid)
514  {
515  }
516 
517  virtual ~ConfigReaderThread()
518  {
519  delete Config;
520  }
521 
522  void Run() CXX11_OVERRIDE;
524  void Finish();
525  bool IsDone() { return done; }
526 };
527 
528 class CoreExport ConfigStatus
529 {
530  public:
531  User* const srcuser;
532 
533  ConfigStatus(User* user = NULL)
534  : srcuser(user)
535  {
536  }
537 };
bool SyntaxHints
Definition: configreader.h:427
static std::string ExpandPath(const std::string &base, const std::string &fragment)
Definition: fileutils.cpp:68
CommandLineConf cmdline
Definition: configreader.h:298
std::string sid
Definition: configreader.h:464
ClassVector Classes
Definition: configreader.h:410
std::string DefaultModes
Definition: configreader.h:419
virtual void Run()=0
size_t MaxQuit
Definition: configreader.h:101
std::string Data
Definition: configreader.h:235
BannedUserTreatment RestrictBannedUsers
Definition: configreader.h:349
std::string HideServer
Definition: configreader.h:393
std::string XLineMessage
Definition: configreader.h:317
Definition: configreader.h:37
int argc
Definition: configreader.h:165
size_t MaxLine
Definition: configreader.h:111
bool HideBans
Definition: configreader.h:387
Definition: configreader.h:172
std::string HideKillsServer
Definition: configreader.h:397
bool forcedebug
Definition: configreader.h:139
std::stringstream errstr
Definition: configreader.h:271
unsigned int OperMaxChans
Definition: configreader.h:457
unsigned int MaxChans
Definition: configreader.h:453
std::bitset< 64 > DisabledUModes
Definition: configreader.h:336
Definition: users.h:224
reference< ConfigTag > oper_block
Definition: configreader.h:185
std::string CustomVersion
Definition: configreader.h:423
std::string PID
Definition: configreader.h:406
bool CycleHostsFromUser
Definition: configreader.h:436
Definition: configreader.h:228
size_t MaxGecos
Definition: configreader.h:107
BannedUserTreatment
Definition: configreader.h:216
Definition: configreader.h:506
unsigned int MaxTargets
Definition: configreader.h:378
size_t MaxTopic
Definition: configreader.h:103
std::string ServerDesc
Definition: configreader.h:328
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:500
OperIndex oper_blocks
Definition: configreader.h:445
char ** argv
Definition: configreader.h:169
ConfigDataHash config_data
Definition: configreader.h:282
ConfigTag * EmptyTag
Definition: configreader.h:267
bool WildcardIPv6
Definition: configreader.h:277
std::string name
Definition: configreader.h:191
ServerLimits Limits
Definition: configreader.h:291
size_t MaxHost
Definition: configreader.h:113
Definition: base.h:85
Definition: configreader.h:89
unsigned char c_ipv6_range
Definition: configreader.h:308
bool HideULineKills
Definition: configreader.h:401
int MaxConn
Definition: configreader.h:360
size_t GetMaxMask() const
Definition: configreader.h:121
bool DisabledDontExist
Definition: configreader.h:332
bool FullHostInTopic
Definition: configreader.h:441
size_t IdentMax
Definition: configreader.h:99
Definition: modules.h:239
reference< ConfigTag > type_block
Definition: configreader.h:187
OperIndex OperTypes
Definition: configreader.h:449
unsigned char c_ipv4_range
Definition: configreader.h:303
unsigned int SoftLimit
Definition: configreader.h:373
size_t NickMax
Definition: configreader.h:93
int NetBufferSize
Definition: configreader.h:355
std::string Module
Definition: configreader.h:241
bool writepid
Definition: configreader.h:161
const std::string & GetSID() const
Definition: configreader.h:474
insp::flat_map< std::string, reference< OperInfo > > OperIndex
Definition: configreader.h:257
std::string UserStats
Definition: configreader.h:415
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:431
std::bitset< 64 > DisabledCModes
Definition: configreader.h:340
std::vector< reference< ConnectClass > > ClassVector
Definition: configreader.h:253
bool RawLog
Definition: configreader.h:390
Definition: token_list.h:24
bool valid
Definition: configreader.h:274
std::string Log
Definition: configreader.h:238
std::string ServerName
Definition: configreader.h:313
Definition: configreader.h:528
size_t ChanMax
Definition: configreader.h:95
Definition: configreader.h:222
Definition: configreader.h:219
bool GenericOper
Definition: configreader.h:346
Definition: configreader.h:208
bool CCOnConnect
Definition: configreader.h:367
ConfigFileCache Files
Definition: configreader.h:287
size_t MaxModes
Definition: configreader.h:97
bool writelog
Definition: configreader.h:149
ServerPaths Paths
Definition: configreader.h:294
bool HideSplits
Definition: configreader.h:382
bool nofork
Definition: configreader.h:131