InspIRCd  3.0
inspircd.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2007-2008 Robin Burchell <[email protected]>
6  * Copyright (C) 2008 Pippijn van Steenhoven <[email protected]>
7  * Copyright (C) 2003-2008 Craig Edwards <[email protected]>
8  * Copyright (C) 2006-2007 Oliver Lupton <[email protected]>
9  * Copyright (C) 2007 Dennis Friis <[email protected]>
10  * Copyright (C) 2003 randomdan <[email protected]???>
11  *
12  * This file is part of InspIRCd. InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 
26 #pragma once
27 
28 #include <climits>
29 #include <cmath>
30 #include <csignal>
31 #include <cstdarg>
32 #include <cstdio>
33 #include <cstring>
34 #include <ctime>
35 #include <stdint.h>
36 
37 #include <algorithm>
38 #include <bitset>
39 #include <deque>
40 #include <list>
41 #include <map>
42 #include <set>
43 #include <sstream>
44 #include <string>
45 #include <vector>
46 
47 #include "intrusive_list.h"
48 #include "flat_map.h"
49 #include "compat.h"
50 #include "aligned_storage.h"
51 #include "typedefs.h"
52 #include "stdalgo.h"
53 
54 CoreExport extern InspIRCd* ServerInstance;
55 
58 template <typename T>
59 struct fakederef
60 {
61  T* operator->()
62  {
63  return static_cast<T*>(this);
64  }
65 };
66 
67 #include "config.h"
68 #include "convto.h"
69 #include "dynref.h"
70 #include "consolecolors.h"
71 #include "cull_list.h"
72 #include "extensible.h"
73 #include "fileutils.h"
74 #include "numerics.h"
75 #include "numeric.h"
76 #include "uid.h"
77 #include "server.h"
78 #include "users.h"
79 #include "channels.h"
80 #include "timer.h"
81 #include "hashcomp.h"
82 #include "logger.h"
83 #include "usermanager.h"
84 #include "socket.h"
85 #include "ctables.h"
86 #include "command_parse.h"
87 #include "mode.h"
88 #include "socketengine.h"
89 #include "snomasks.h"
90 #include "filelogger.h"
91 #include "message.h"
92 #include "modules.h"
93 #include "threadengine.h"
94 #include "configreader.h"
95 #include "inspstring.h"
96 #include "protocol.h"
97 #include "bancache.h"
98 #include "isupportmanager.h"
99 
105 {
106  public:
109  unsigned long Accept;
112  unsigned long Refused;
115  unsigned long Unknown;
118  unsigned long Collisions;
121  unsigned long Dns;
126  unsigned long DnsGood;
131  unsigned long DnsBad;
134  unsigned long Connects;
137  unsigned long Sent;
140  unsigned long Recv;
141 #ifdef _WIN32
142 
144  FILETIME LastCPU;
147  LARGE_INTEGER LastSampled;
150  LARGE_INTEGER QPFrequency;
151 #else
152 
154  timeval LastCPU;
157  timespec LastSampled;
158 #endif
159 
162  : Accept(0), Refused(0), Unknown(0), Collisions(0), Dns(0),
163  DnsGood(0), DnsBad(0), Connects(0), Sent(0), Recv(0)
164  {
165  }
166 };
167 
174 class CoreExport InspIRCd
175 {
176  private:
179  void SetSignals();
180 
184  bool DaemonSeed();
185 
188  struct timespec TIME;
189 
193  char ReadBuffer[65535];
194 
198  void CheckRoot();
199 
200  public:
201 
202  UIDGenerator UIDGen;
203 
209 
219 
224  User* FindUUID(const std::string &uid);
225 
228  time_t startup_time;
229 
232  std::string ConfigFileName;
233 
234  ExtensionManager Extensions;
235 
239 
243 
247 
251 
255 
260 
265 
269 
273 
278 
282 
286 
290 
293  chan_hash chanlist;
294 
297  std::vector<ListenSocket*> ports;
298 
301  static sig_atomic_t s_signal;
302 
306 
310 
313 
319  inline time_t Time() { return TIME.tv_sec; }
321  inline long Time_ns() { return TIME.tv_nsec; }
323  void UpdateTime();
324 
330  std::string GenRandomStr(unsigned int length, bool printable = true);
334  unsigned long GenRandomInt(unsigned long max);
335 
337  TR1NS::function<void(char*, size_t)> GenRandom;
338 
344  static void DefaultGenRandom(char* output, size_t max);
345 
349  int BindPorts(FailedPortList &failed_ports);
350 
356  User* FindNick(const std::string &nick);
357 
360  User* FindNickOnly(const std::string &nick);
361 
366  Channel* FindChan(const std::string &chan);
367 
371  chan_hash& GetChans() { return chanlist; }
372 
374  TR1NS::function<bool(const std::string&)> IsChannel;
375 
381  static bool DefaultIsChannel(const std::string& channel);
382 
386  static bool IsSID(const std::string& sid);
387 
391  void SignalHandler(int signal);
392 
396  static void SetSignal(int signal);
397 
404  void Exit(int status);
405 
411  static std::string Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2);
412  static std::string Format(va_list& vaList, const char* formatString) CUSTOM_PRINTF(2, 0);
413 
415  TR1NS::function<bool(const std::string&)> IsNick;
416 
422  static bool DefaultIsNick(const std::string& nick);
423 
425  TR1NS::function<bool(const std::string&)> IsIdent;
426 
432  static bool DefaultIsIdent(const std::string& ident);
433 
440  static bool Match(const std::string& str, const std::string& mask, unsigned const char* map = NULL);
441  static bool Match(const char* str, const char* mask, unsigned const char* map = NULL);
442 
450  static bool MatchCIDR(const std::string& str, const std::string& mask, unsigned const char* map = NULL);
451  static bool MatchCIDR(const char* str, const char* mask, unsigned const char* map = NULL);
452 
458  static bool MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr);
459 
464  static bool IsValidMask(const std::string& mask);
465 
469  static void StripColor(std::string &sentence);
470 
474  static void ProcessColors(file_cache& input);
475 
479  void Rehash(const std::string& uuid = "");
480 
486  static unsigned long Duration(const std::string& str);
487 
497  bool PassCompare(Extensible* ex, const std::string& data, const std::string& input, const std::string& hashtype);
498 
502  std::string GetVersionString(bool getFullVersion = false);
503 
509  void WritePID(const std::string& filename, bool exitonfail = true);
510 
518  InspIRCd(int argc, char** argv);
519 
524  void Cleanup();
525 
533  static std::string TimeString(time_t curtime, const char* format = NULL, bool utc = false);
534 
542  static bool TimingSafeCompare(const std::string& one, const std::string& two);
543 
548  void Run();
549 
550  char* GetReadBuffer()
551  {
552  return this->ReadBuffer;
553  }
554 };
555 
556 ENTRYPOINT;
557 
558 template<class Cmd>
559 class CommandModule : public Module
560 {
561  Cmd cmd;
562  public:
563  CommandModule() : cmd(this)
564  {
565  }
566 
567  Version GetVersion() CXX11_OVERRIDE
568  {
569  return Version(cmd.name, VF_VENDOR|VF_CORE);
570  }
571 };
572 
573 inline void stdalgo::culldeleter::operator()(classbase* item)
574 {
575  if (item)
576  ServerInstance->GlobalCulls.AddItem(item);
577 }
578 
579 #include "numericbuilder.h"
580 #include "modules/whois.h"
581 #include "modules/stats.h"
Definition: threadengine_pthread.h:36
unsigned long DnsGood
Definition: inspircd.h:126
Definition: modules.h:178
std::tr1 ::function< void(char *, size_t)> GenRandom
Definition: inspircd.h:337
ServerConfig * Config
Definition: inspircd.h:272
ConfigReaderThread * ConfigThread
Definition: inspircd.h:250
ModuleManager Modules
Definition: inspircd.h:259
unsigned long Unknown
Definition: inspircd.h:115
Definition: inspircd.h:174
unsigned long Connects
Definition: inspircd.h:134
Definition: extensible.h:90
Definition: isupportmanager.h:23
time_t Time()
Definition: inspircd.h:319
long Time_ns()
Definition: inspircd.h:321
Definition: cull_list.h:54
Definition: logger.h:121
STL namespace.
Definition: users.h:224
unsigned long Recv
Definition: inspircd.h:140
Definition: command_parse.h:30
unsigned long Refused
Definition: inspircd.h:112
unsigned long Sent
Definition: inspircd.h:137
FakeUser * FakeClient
Definition: inspircd.h:218
LogManager Logs
Definition: inspircd.h:254
ProtocolInterface * PI
Definition: inspircd.h:305
ProtocolInterface DefaultProtocolInterface
Definition: inspircd.h:309
Definition: configreader.h:502
Definition: base.h:41
Definition: cull_list.h:30
UserManager Users
Definition: inspircd.h:289
unsigned long Collisions
Definition: inspircd.h:118
TimerManager Timers
Definition: inspircd.h:281
timespec LastSampled
Definition: inspircd.h:157
Version GetVersion()
Definition: inspircd.h:567
Definition: modules.h:966
Definition: bancache.h:50
Definition: mode.h:538
CommandParser Parser
Definition: inspircd.h:242
XLineManager * XLines
Definition: inspircd.h:285
Definition: inspircd.h:104
Definition: modules.h:239
unsigned long Dns
Definition: inspircd.h:121
Definition: usermanager.h:24
timeval LastCPU
Definition: inspircd.h:154
ActionList AtomicActions
Definition: inspircd.h:208
Definition: users.h:903
Definition: inspircd.h:59
Definition: snomasks.h:75
Definition: inspircd.h:559
time_t startup_time
Definition: inspircd.h:228
Definition: xline.h:398
serverstats stats
Definition: inspircd.h:268
chan_hash & GetChans()
Definition: inspircd.h:371
std::vector< ListenSocket * > ports
Definition: inspircd.h:297
CullList GlobalCulls
Definition: inspircd.h:206
std::tr1 ::function< bool(const std::string &)> IsChannel
Definition: inspircd.h:374
static sig_atomic_t s_signal
Definition: inspircd.h:301
unsigned long DnsBad
Definition: inspircd.h:131
std::string ConfigFileName
Definition: inspircd.h:232
ThreadEngine Threads
Definition: inspircd.h:246
Definition: extensible.h:124
SnomaskManager SNO
Definition: inspircd.h:277
unsigned long Accept
Definition: inspircd.h:109
ModeParser Modes
Definition: inspircd.h:238
ISupportManager ISupport
Definition: inspircd.h:312
Definition: uid.h:23
Definition: protocol.h:39
serverstats()
Definition: inspircd.h:161
chan_hash chanlist
Definition: inspircd.h:293
void AddItem(classbase *item)
Definition: cull_list.h:38
Definition: configreader.h:202
BanCacheManager BanCache
Definition: inspircd.h:264
Definition: timer.h:118
Definition: channels.h:37