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 = "", size_t minlen = 0, size_t maxlen = UINT32_MAX);
48  long getInt(const std::string& key, long def, long min = LONG_MIN, long max = LONG_MAX);
50  unsigned long getUInt(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX);
52  double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX);
54  bool getBool(const std::string& key, bool def = false);
55 
64  unsigned long getDuration(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX);
65 
72  bool readString(const std::string& key, std::string& value, bool allow_newline = false);
73 
74  std::string getTagLocation();
75 
76  inline const ConfigItems& getItems() const { return items; }
77 
79  static ConfigTag* create(const std::string& Tag, const std::string& file, int line, ConfigItems*& Items);
80  private:
81  ConfigTag(const std::string& Tag, const std::string& file, int line);
82 };
83 
88 {
89  public:
91  size_t NickMax;
93  size_t ChanMax;
95  size_t MaxModes;
97  size_t IdentMax;
99  size_t MaxQuit;
101  size_t MaxTopic;
103  size_t MaxKick;
105  size_t MaxGecos;
107  size_t MaxAway;
109  size_t MaxLine;
111  size_t MaxHost;
112 
116  ServerLimits(ConfigTag* tag);
117 
119  size_t GetMaxMask() const { return NickMax + 1 + IdentMax + 1 + MaxHost; }
120 };
121 
123 {
129  bool nofork;
130 
138 
147  bool writelog;
148 
151  int argc;
152 
155  char** argv;
156 };
157 
158 class CoreExport OperInfo : public refcountbase
159 {
160  public:
161  TokenList AllowedOperCommands;
162  TokenList AllowedPrivs;
163 
165  std::bitset<64> AllowedUserModes;
166 
168  std::bitset<64> AllowedChanModes;
169 
175  std::vector<reference<ConfigTag> > class_blocks;
177  std::string name;
178 
182  OperInfo(const std::string& Name);
183 
185  std::string getConfig(const std::string& key);
186  void init();
187 };
188 
194 class CoreExport ServerConfig
195 {
196  private:
197  void CrossCheckOperClassType();
198  void CrossCheckConnectBlocks(ServerConfig* current);
199 
200  public:
202  {
203  public:
205  std::string Config;
206 
208  std::string Data;
209 
211  std::string Log;
212 
214  std::string Module;
215 
216  ServerPaths(ConfigTag* tag);
217 
218  std::string PrependConfig(const std::string& fn) const { return FileSystem::ExpandPath(Config, fn); }
219  std::string PrependData(const std::string& fn) const { return FileSystem::ExpandPath(Data, fn); }
220  std::string PrependLog(const std::string& fn) const { return FileSystem::ExpandPath(Log, fn); }
221  std::string PrependModule(const std::string& fn) const { return FileSystem::ExpandPath(Module, fn); }
222  };
223 
226  typedef std::vector<reference<ConnectClass> > ClassVector;
227 
231 
235  ConfigTag* ConfValue(const std::string& tag);
236 
237  ConfigTagList ConfTags(const std::string& tag);
238 
241 
244  std::stringstream errstr;
245 
247  bool valid;
248 
251 
255  ConfigDataHash config_data;
256 
260  ConfigFileCache Files;
261 
265 
268 
272 
276  unsigned char c_ipv4_range;
277 
281  unsigned char c_ipv6_range;
282 
286  std::string ServerName;
287 
290  std::string XLineMessage;
291 
292  /* Holds the network name the local server
293  * belongs to. This is an arbitary field defined
294  * by the administrator.
295  */
296  std::string Network;
297 
301  std::string ServerDesc;
302 
306 
309  std::bitset<64> DisabledUModes;
310 
313  std::bitset<64> DisabledCModes;
314 
320 
325 
331 
335  int MaxConn;
336 
343 
348  unsigned int SoftLimit;
349 
353  unsigned int MaxTargets;
354 
358 
362  bool HideBans;
363 
365  bool RawLog;
366 
368  std::string HideServer;
369 
372  std::string HideKillsServer;
373 
377 
381  std::string PID;
382 
386 
390  std::string UserStats;
391 
394  std::string DefaultModes;
395 
398  std::string CustomVersion;
399 
403 
406  std::string CaseMapping;
407 
412 
417 
421 
425 
428  unsigned int MaxChans;
429 
432  unsigned int OperMaxChans;
433 
439  std::string sid;
440 
443  ServerConfig();
444 
445  ~ServerConfig();
446 
449  const std::string& GetSID() const { return sid; }
450 
455  void Read();
456 
459  void Apply(ServerConfig* old, const std::string &useruid);
460  void ApplyModules(User* user);
461 
462  void Fill();
463 
465  bool ApplyDisabledCommands();
466 
471  static std::string Escape(const std::string& str, bool xml = true);
472 
476 };
477 
481 class CoreExport ConfigReaderThread : public Thread
482 {
483  ServerConfig* Config;
484  volatile bool done;
485  public:
486  const std::string TheUserUID;
487  ConfigReaderThread(const std::string &useruid)
488  : Config(new ServerConfig), done(false), TheUserUID(useruid)
489  {
490  }
491 
492  virtual ~ConfigReaderThread()
493  {
494  delete Config;
495  }
496 
497  void Run() CXX11_OVERRIDE;
499  void Finish();
500  bool IsDone() { return done; }
501 };
502 
503 class CoreExport ConfigStatus
504 {
505  public:
506  User* const srcuser;
507 
508  ConfigStatus(User* user = NULL)
509  : srcuser(user)
510  {
511  }
512 };
bool SyntaxHints
Definition: configreader.h:402
static std::string ExpandPath(const std::string &base, const std::string &fragment)
Definition: fileutils.cpp:68
CommandLineConf cmdline
Definition: configreader.h:271
std::string sid
Definition: configreader.h:439
ClassVector Classes
Definition: configreader.h:385
std::string DefaultModes
Definition: configreader.h:394
virtual void Run()=0
size_t MaxQuit
Definition: configreader.h:99
std::string Data
Definition: configreader.h:208
std::string HideServer
Definition: configreader.h:368
std::string XLineMessage
Definition: configreader.h:290
Definition: configreader.h:37
int argc
Definition: configreader.h:151
size_t MaxLine
Definition: configreader.h:109
bool HideBans
Definition: configreader.h:362
Definition: configreader.h:158
std::string HideKillsServer
Definition: configreader.h:372
bool forcedebug
Definition: configreader.h:137
std::stringstream errstr
Definition: configreader.h:244
unsigned int OperMaxChans
Definition: configreader.h:432
unsigned int MaxChans
Definition: configreader.h:428
std::bitset< 64 > DisabledUModes
Definition: configreader.h:309
Definition: users.h:224
reference< ConfigTag > oper_block
Definition: configreader.h:171
std::string CustomVersion
Definition: configreader.h:398
std::string PID
Definition: configreader.h:381
bool CycleHostsFromUser
Definition: configreader.h:411
Definition: configreader.h:201
size_t MaxGecos
Definition: configreader.h:105
Definition: configreader.h:481
unsigned int MaxTargets
Definition: configreader.h:353
size_t MaxTopic
Definition: configreader.h:101
std::string ServerDesc
Definition: configreader.h:301
Definition: threadengine.h:33
std::vector< reference< ConfigTag > > class_blocks
Definition: configreader.h:175
std::bitset< 64 > AllowedChanModes
Definition: configreader.h:168
bool NoSnoticeStack
Definition: configreader.h:475
OperIndex oper_blocks
Definition: configreader.h:420
char ** argv
Definition: configreader.h:155
ConfigDataHash config_data
Definition: configreader.h:255
ConfigTag * EmptyTag
Definition: configreader.h:240
bool WildcardIPv6
Definition: configreader.h:250
bool RestrictBannedUsers
Definition: configreader.h:324
std::string name
Definition: configreader.h:177
ServerLimits Limits
Definition: configreader.h:264
size_t MaxHost
Definition: configreader.h:111
Definition: base.h:85
Definition: configreader.h:87
unsigned char c_ipv6_range
Definition: configreader.h:281
bool HideULineKills
Definition: configreader.h:376
int MaxConn
Definition: configreader.h:335
size_t GetMaxMask() const
Definition: configreader.h:119
bool DisabledDontExist
Definition: configreader.h:305
bool FullHostInTopic
Definition: configreader.h:416
size_t IdentMax
Definition: configreader.h:97
Definition: modules.h:239
reference< ConfigTag > type_block
Definition: configreader.h:173
OperIndex OperTypes
Definition: configreader.h:424
unsigned char c_ipv4_range
Definition: configreader.h:276
unsigned int SoftLimit
Definition: configreader.h:348
size_t NickMax
Definition: configreader.h:91
int NetBufferSize
Definition: configreader.h:330
std::string Module
Definition: configreader.h:214
const std::string & GetSID() const
Definition: configreader.h:449
insp::flat_map< std::string, reference< OperInfo > > OperIndex
Definition: configreader.h:230
std::string UserStats
Definition: configreader.h:390
Definition: configreader.h:122
ServerLimits(ConfigTag *tag)
Definition: configreader.cpp:32
size_t MaxAway
Definition: configreader.h:107
std::bitset< 64 > AllowedUserModes
Definition: configreader.h:165
size_t MaxKick
Definition: configreader.h:103
std::string Config
Definition: configreader.h:205
std::string CaseMapping
Definition: configreader.h:406
std::bitset< 64 > DisabledCModes
Definition: configreader.h:313
std::vector< reference< ConnectClass > > ClassVector
Definition: configreader.h:226
bool RawLog
Definition: configreader.h:365
Definition: token_list.h:24
bool valid
Definition: configreader.h:247
std::string Log
Definition: configreader.h:211
std::string ServerName
Definition: configreader.h:286
Definition: configreader.h:503
size_t ChanMax
Definition: configreader.h:93
bool GenericOper
Definition: configreader.h:319
Definition: configreader.h:194
bool CCOnConnect
Definition: configreader.h:342
ConfigFileCache Files
Definition: configreader.h:260
size_t MaxModes
Definition: configreader.h:95
bool writelog
Definition: configreader.h:147
ServerPaths Paths
Definition: configreader.h:267
bool HideSplits
Definition: configreader.h:357
bool nofork
Definition: configreader.h:129