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 <cfloat>
29 #include <climits>
30 #include <cmath>
31 #include <csignal>
32 #include <cstdarg>
33 #include <cstdio>
34 #include <cstring>
35 #include <ctime>
36 #include <stdint.h>
37 
38 #include <algorithm>
39 #include <bitset>
40 #include <deque>
41 #include <list>
42 #include <map>
43 #include <set>
44 #include <sstream>
45 #include <string>
46 #include <vector>
47 
48 #include "intrusive_list.h"
49 #include "flat_map.h"
50 #include "compat.h"
51 #include "aligned_storage.h"
52 #include "typedefs.h"
53 #include "stdalgo.h"
54 
55 CoreExport extern InspIRCd* ServerInstance;
56 
59 template <typename T>
60 struct fakederef
61 {
62  T* operator->()
63  {
64  return static_cast<T*>(this);
65  }
66 };
67 
68 #include "config.h"
69 #include "convto.h"
70 #include "dynref.h"
71 #include "consolecolors.h"
72 #include "cull_list.h"
73 #include "extensible.h"
74 #include "fileutils.h"
75 #include "numerics.h"
76 #include "numeric.h"
77 #include "uid.h"
78 #include "server.h"
79 #include "users.h"
80 #include "channels.h"
81 #include "timer.h"
82 #include "hashcomp.h"
83 #include "logger.h"
84 #include "usermanager.h"
85 #include "socket.h"
86 #include "ctables.h"
87 #include "command_parse.h"
88 #include "mode.h"
89 #include "socketengine.h"
90 #include "snomasks.h"
91 #include "filelogger.h"
92 #include "message.h"
93 #include "modules.h"
94 #include "threadengine.h"
95 #include "configreader.h"
96 #include "inspstring.h"
97 #include "protocol.h"
98 #include "bancache.h"
99 #include "isupportmanager.h"
100 
106 {
107  public:
110  unsigned long Accept;
113  unsigned long Refused;
116  unsigned long Unknown;
119  unsigned long Collisions;
122  unsigned long Dns;
127  unsigned long DnsGood;
132  unsigned long DnsBad;
135  unsigned long Connects;
138  unsigned long Sent;
141  unsigned long Recv;
142 #ifdef _WIN32
143 
145  FILETIME LastCPU;
148  LARGE_INTEGER LastSampled;
151  LARGE_INTEGER QPFrequency;
152 #else
153 
155  timeval LastCPU;
158  timespec LastSampled;
159 #endif
160 
163  : Accept(0), Refused(0), Unknown(0), Collisions(0), Dns(0),
164  DnsGood(0), DnsBad(0), Connects(0), Sent(0), Recv(0)
165  {
166  }
167 };
168 
175 class CoreExport InspIRCd
176 {
177  private:
180  void SetSignals();
181 
185  bool DaemonSeed();
186 
189  struct timespec TIME;
190 
194  char ReadBuffer[65535];
195 
199  void CheckRoot();
200 
201  public:
202 
203  UIDGenerator UIDGen;
204 
210 
220 
225  User* FindUUID(const std::string &uid);
226 
229  time_t startup_time;
230 
233  std::string ConfigFileName;
234 
235  ExtensionManager Extensions;
236 
240 
244 
248 
252 
256 
261 
266 
270 
274 
279 
283 
287 
291 
294  chan_hash chanlist;
295 
298  std::vector<ListenSocket*> ports;
299 
302  static sig_atomic_t s_signal;
303 
307 
311 
314 
320  inline time_t Time() { return TIME.tv_sec; }
322  inline long Time_ns() { return TIME.tv_nsec; }
324  void UpdateTime();
325 
331  std::string GenRandomStr(unsigned int length, bool printable = true);
335  unsigned long GenRandomInt(unsigned long max);
336 
338  TR1NS::function<void(char*, size_t)> GenRandom;
339 
345  static void DefaultGenRandom(char* output, size_t max);
346 
350  int BindPorts(FailedPortList &failed_ports);
351 
357  User* FindNick(const std::string &nick);
358 
361  User* FindNickOnly(const std::string &nick);
362 
367  Channel* FindChan(const std::string &chan);
368 
372  chan_hash& GetChans() { return chanlist; }
373 
375  TR1NS::function<bool(const std::string&)> IsChannel;
376 
382  static bool DefaultIsChannel(const std::string& channel);
383 
388  static bool IsHost(const std::string& host);
389 
393  static bool IsSID(const std::string& sid);
394 
398  void SignalHandler(int signal);
399 
403  static void SetSignal(int signal);
404 
411  void Exit(int status);
412 
418  static std::string Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2);
419  static std::string Format(va_list& vaList, const char* formatString) CUSTOM_PRINTF(2, 0);
420 
422  TR1NS::function<bool(const std::string&)> IsNick;
423 
429  static bool DefaultIsNick(const std::string& nick);
430 
432  TR1NS::function<bool(const std::string&)> IsIdent;
433 
439  static bool DefaultIsIdent(const std::string& ident);
440 
447  static bool Match(const std::string& str, const std::string& mask, unsigned const char* map = NULL);
448  static bool Match(const char* str, const char* mask, unsigned const char* map = NULL);
449 
457  static bool MatchCIDR(const std::string& str, const std::string& mask, unsigned const char* map = NULL);
458  static bool MatchCIDR(const char* str, const char* mask, unsigned const char* map = NULL);
459 
465  static bool MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr);
466 
471  static bool IsValidMask(const std::string& mask);
472 
476  static void StripColor(std::string &sentence);
477 
481  static void ProcessColors(file_cache& input);
482 
486  void Rehash(const std::string& uuid = "");
487 
493  static unsigned long Duration(const std::string& str);
494 
504  bool PassCompare(Extensible* ex, const std::string& data, const std::string& input, const std::string& hashtype);
505 
509  std::string GetVersionString(bool getFullVersion = false);
510 
516  void WritePID(const std::string& filename, bool exitonfail = true);
517 
525  InspIRCd(int argc, char** argv);
526 
531  void Cleanup();
532 
540  static std::string TimeString(time_t curtime, const char* format = NULL, bool utc = false);
541 
549  static bool TimingSafeCompare(const std::string& one, const std::string& two);
550 
555  void Run();
556 
557  char* GetReadBuffer()
558  {
559  return this->ReadBuffer;
560  }
561 };
562 
563 ENTRYPOINT;
564 
565 template<class Cmd>
566 class CommandModule : public Module
567 {
568  Cmd cmd;
569  public:
570  CommandModule() : cmd(this)
571  {
572  }
573 
574  Version GetVersion() CXX11_OVERRIDE
575  {
576  return Version(cmd.name, VF_VENDOR|VF_CORE);
577  }
578 };
579 
580 inline void stdalgo::culldeleter::operator()(classbase* item)
581 {
582  if (item)
583  ServerInstance->GlobalCulls.AddItem(item);
584 }
585 
586 #include "numericbuilder.h"
Definition: threadengine_pthread.h:36
unsigned long DnsGood
Definition: inspircd.h:127
Definition: modules.h:178
std::tr1 ::function< void(char *, size_t)> GenRandom
Definition: inspircd.h:338
ServerConfig * Config
Definition: inspircd.h:273
ConfigReaderThread * ConfigThread
Definition: inspircd.h:251
ModuleManager Modules
Definition: inspircd.h:260
unsigned long Unknown
Definition: inspircd.h:116
Definition: inspircd.h:175
unsigned long Connects
Definition: inspircd.h:135
Definition: extensible.h:90
Definition: isupportmanager.h:23
time_t Time()
Definition: inspircd.h:320
long Time_ns()
Definition: inspircd.h:322
Definition: cull_list.h:54
Definition: logger.h:121
STL namespace.
Definition: users.h:224
unsigned long Recv
Definition: inspircd.h:141
Definition: command_parse.h:30
unsigned long Refused
Definition: inspircd.h:113
unsigned long Sent
Definition: inspircd.h:138
FakeUser * FakeClient
Definition: inspircd.h:219
LogManager Logs
Definition: inspircd.h:255
ProtocolInterface * PI
Definition: inspircd.h:306
ProtocolInterface DefaultProtocolInterface
Definition: inspircd.h:310
Definition: configreader.h:506
Definition: base.h:41
Definition: cull_list.h:30
UserManager Users
Definition: inspircd.h:290
unsigned long Collisions
Definition: inspircd.h:119
TimerManager Timers
Definition: inspircd.h:282
timespec LastSampled
Definition: inspircd.h:158
Version GetVersion()
Definition: inspircd.h:574
Definition: modules.h:973
Definition: bancache.h:50
Definition: mode.h:538
CommandParser Parser
Definition: inspircd.h:243
XLineManager * XLines
Definition: inspircd.h:286
Definition: inspircd.h:105
Definition: modules.h:239
unsigned long Dns
Definition: inspircd.h:122
Definition: usermanager.h:24
timeval LastCPU
Definition: inspircd.h:155
ActionList AtomicActions
Definition: inspircd.h:209
Definition: users.h:903
Definition: inspircd.h:60
Definition: snomasks.h:75
Definition: inspircd.h:566
time_t startup_time
Definition: inspircd.h:229
Definition: xline.h:398
serverstats stats
Definition: inspircd.h:269
chan_hash & GetChans()
Definition: inspircd.h:372
std::vector< ListenSocket * > ports
Definition: inspircd.h:298
CullList GlobalCulls
Definition: inspircd.h:207
std::tr1 ::function< bool(const std::string &)> IsChannel
Definition: inspircd.h:375
static sig_atomic_t s_signal
Definition: inspircd.h:302
unsigned long DnsBad
Definition: inspircd.h:132
std::string ConfigFileName
Definition: inspircd.h:233
ThreadEngine Threads
Definition: inspircd.h:247
Definition: extensible.h:124
SnomaskManager SNO
Definition: inspircd.h:278
unsigned long Accept
Definition: inspircd.h:110
ModeParser Modes
Definition: inspircd.h:239
ISupportManager ISupport
Definition: inspircd.h:313
Definition: uid.h:23
Definition: protocol.h:39
serverstats()
Definition: inspircd.h:162
chan_hash chanlist
Definition: inspircd.h:294
void AddItem(classbase *item)
Definition: cull_list.h:38
Definition: configreader.h:208
BanCacheManager BanCache
Definition: inspircd.h:265
Definition: timer.h:118
Definition: channels.h:37