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 // If the system has a pre-C11 stdint header this must be defined in
29 // order to use the numeric limit macros.
30 #define __STDC_LIMIT_MACROS
31 
32 #include <cfloat>
33 #include <climits>
34 #include <cmath>
35 #include <csignal>
36 #include <cstdarg>
37 #include <cstdio>
38 #include <cstring>
39 #include <ctime>
40 #include <stdint.h>
41 
42 #include <algorithm>
43 #include <bitset>
44 #include <deque>
45 #include <list>
46 #include <map>
47 #include <set>
48 #include <sstream>
49 #include <string>
50 #include <vector>
51 
52 #include "intrusive_list.h"
53 #include "flat_map.h"
54 #include "compat.h"
55 #include "aligned_storage.h"
56 #include "typedefs.h"
57 #include "convto.h"
58 #include "stdalgo.h"
59 
60 CoreExport extern InspIRCd* ServerInstance;
61 
64 template <typename T>
65 struct fakederef
66 {
67  T* operator->()
68  {
69  return static_cast<T*>(this);
70  }
71 };
72 
73 #include "config.h"
74 #include "dynref.h"
75 #include "consolecolors.h"
76 #include "cull_list.h"
77 #include "extensible.h"
78 #include "fileutils.h"
79 #include "ctables.h"
80 #include "numerics.h"
81 #include "numeric.h"
82 #include "uid.h"
83 #include "server.h"
84 #include "users.h"
85 #include "channels.h"
86 #include "timer.h"
87 #include "hashcomp.h"
88 #include "logger.h"
89 #include "usermanager.h"
90 #include "socket.h"
91 #include "command_parse.h"
92 #include "mode.h"
93 #include "socketengine.h"
94 #include "snomasks.h"
95 #include "filelogger.h"
96 #include "message.h"
97 #include "modules.h"
98 #include "clientprotocol.h"
99 #include "threadengine.h"
100 #include "configreader.h"
101 #include "inspstring.h"
102 #include "protocol.h"
103 #include "bancache.h"
104 #include "isupportmanager.h"
105 
111 {
112  public:
115  unsigned long Accept;
118  unsigned long Refused;
121  unsigned long Unknown;
124  unsigned long Collisions;
127  unsigned long Dns;
132  unsigned long DnsGood;
137  unsigned long DnsBad;
140  unsigned long Connects;
143  unsigned long Sent;
146  unsigned long Recv;
147 #ifdef _WIN32
148 
150  FILETIME LastCPU;
153  LARGE_INTEGER LastSampled;
156  LARGE_INTEGER QPFrequency;
157 #else
158 
160  timeval LastCPU;
163  timespec LastSampled;
164 #endif
165 
168  : Accept(0), Refused(0), Unknown(0), Collisions(0), Dns(0),
169  DnsGood(0), DnsBad(0), Connects(0), Sent(0), Recv(0)
170  {
171  }
172 };
173 
180 class CoreExport InspIRCd
181 {
182  private:
185  void SetSignals();
186 
190  bool DaemonSeed();
191 
194  struct timespec TIME;
195 
199  char ReadBuffer[65535];
200 
201  ClientProtocol::RFCEvents rfcevents;
202 
206  void CheckRoot();
207 
208  public:
209 
210  UIDGenerator UIDGen;
211 
217 
227 
232  User* FindUUID(const std::string &uid);
233 
236  time_t startup_time;
237 
240  std::string ConfigFileName;
241 
242  ExtensionManager Extensions;
243 
247 
251 
255 
259 
263 
268 
273 
277 
281 
286 
290 
294 
298 
301  chan_hash chanlist;
302 
305  std::vector<ListenSocket*> ports;
306 
309  static sig_atomic_t s_signal;
310 
314 
318 
321 
327  inline time_t Time() { return TIME.tv_sec; }
329  inline long Time_ns() { return TIME.tv_nsec; }
331  void UpdateTime();
332 
338  std::string GenRandomStr(unsigned int length, bool printable = true);
342  unsigned long GenRandomInt(unsigned long max);
343 
345  TR1NS::function<void(char*, size_t)> GenRandom;
346 
352  static void DefaultGenRandom(char* output, size_t max);
353 
359  bool BindPort(ConfigTag* tag, const irc::sockets::sockaddrs& sa, std::vector<ListenSocket*>& old_ports);
360 
364  int BindPorts(FailedPortList &failed_ports);
365 
371  User* FindNick(const std::string &nick);
372 
375  User* FindNickOnly(const std::string &nick);
376 
381  Channel* FindChan(const std::string &chan);
382 
386  chan_hash& GetChans() { return chanlist; }
387 
389  TR1NS::function<bool(const std::string&)> IsChannel;
390 
396  static bool DefaultIsChannel(const std::string& channel);
397 
402  static bool IsHost(const std::string& host);
403 
407  static bool IsSID(const std::string& sid);
408 
412  void SignalHandler(int signal);
413 
417  static void SetSignal(int signal);
418 
425  void Exit(int status);
426 
432  static std::string Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2);
433  static std::string Format(va_list& vaList, const char* formatString) CUSTOM_PRINTF(2, 0);
434 
436  TR1NS::function<bool(const std::string&)> IsNick;
437 
443  static bool DefaultIsNick(const std::string& nick);
444 
446  TR1NS::function<bool(const std::string&)> IsIdent;
447 
453  static bool DefaultIsIdent(const std::string& ident);
454 
461  static bool Match(const std::string& str, const std::string& mask, unsigned const char* map = NULL);
462  static bool Match(const char* str, const char* mask, unsigned const char* map = NULL);
463 
471  static bool MatchCIDR(const std::string& str, const std::string& mask, unsigned const char* map = NULL);
472  static bool MatchCIDR(const char* str, const char* mask, unsigned const char* map = NULL);
473 
479  static bool MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr);
480 
485  static bool IsValidMask(const std::string& mask);
486 
490  static void StripColor(std::string &sentence);
491 
495  static void ProcessColors(file_cache& input);
496 
500  void Rehash(const std::string& uuid = "");
501 
507  static unsigned long Duration(const std::string& str);
508 
515  static bool Duration(const std::string& str, unsigned long& duration);
516 
521  static bool IsValidDuration(const std::string& str);
522 
527  static std::string DurationString(time_t duration);
528 
538  bool PassCompare(Extensible* ex, const std::string& data, const std::string& input, const std::string& hashtype);
539 
543  std::string GetVersionString(bool getFullVersion = false);
544 
550  void WritePID(const std::string& filename, bool exitonfail = true);
551 
559  InspIRCd(int argc, char** argv);
560 
565  void Cleanup();
566 
574  static std::string TimeString(time_t curtime, const char* format = NULL, bool utc = false);
575 
583  static bool TimingSafeCompare(const std::string& one, const std::string& two);
584 
589  void Run();
590 
591  char* GetReadBuffer()
592  {
593  return this->ReadBuffer;
594  }
595 
596  ClientProtocol::RFCEvents& GetRFCEvents() { return rfcevents; }
597 };
598 
599 ENTRYPOINT;
600 
601 inline void stdalgo::culldeleter::operator()(classbase* item)
602 {
603  if (item)
604  ServerInstance->GlobalCulls.AddItem(item);
605 }
606 
607 inline void Channel::Write(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg, char status, const CUList& except_list)
608 {
609  ClientProtocol::Event event(protoevprov, msg);
610  Write(event, status, except_list);
611 }
612 
613 inline void LocalUser::Send(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg)
614 {
615  ClientProtocol::Event event(protoevprov, msg);
616  Send(event);
617 }
618 
619 #include "numericbuilder.h"
620 #include "clientprotocolmsg.h"
621 #include "clientprotocolevent.h"
Definition: threadengine_pthread.h:36
unsigned long DnsGood
Definition: inspircd.h:132
std::tr1 ::function< void(char *, size_t)> GenRandom
Definition: inspircd.h:345
ServerConfig * Config
Definition: inspircd.h:280
ConfigReaderThread * ConfigThread
Definition: inspircd.h:258
ModuleManager Modules
Definition: inspircd.h:267
unsigned long Unknown
Definition: inspircd.h:121
Definition: configreader.h:37
Definition: inspircd.h:180
unsigned long Connects
Definition: inspircd.h:140
Definition: extensible.h:90
Definition: isupportmanager.h:23
time_t Time()
Definition: inspircd.h:327
long Time_ns()
Definition: inspircd.h:329
Definition: cull_list.h:54
Definition: logger.h:121
Definition: users.h:224
unsigned long Recv
Definition: inspircd.h:146
Definition: command_parse.h:30
unsigned long Refused
Definition: inspircd.h:118
unsigned long Sent
Definition: inspircd.h:143
FakeUser * FakeClient
Definition: inspircd.h:226
LogManager Logs
Definition: inspircd.h:262
ProtocolInterface * PI
Definition: inspircd.h:313
ProtocolInterface DefaultProtocolInterface
Definition: inspircd.h:317
Definition: socket.h:58
Definition: configreader.h:471
Definition: base.h:41
Definition: cull_list.h:30
UserManager Users
Definition: inspircd.h:297
unsigned long Collisions
Definition: inspircd.h:124
TimerManager Timers
Definition: inspircd.h:289
Definition: clientprotocol.h:461
timespec LastSampled
Definition: inspircd.h:163
Definition: modules.h:938
Definition: bancache.h:50
Definition: mode.h:538
CommandParser Parser
Definition: inspircd.h:250
Definition: clientprotocol.h:180
XLineManager * XLines
Definition: inspircd.h:293
Definition: inspircd.h:110
unsigned long Dns
Definition: inspircd.h:127
Definition: usermanager.h:24
timeval LastCPU
Definition: inspircd.h:160
ActionList AtomicActions
Definition: inspircd.h:216
Definition: users.h:880
Definition: inspircd.h:65
Definition: snomasks.h:75
time_t startup_time
Definition: inspircd.h:236
Definition: xline.h:406
serverstats stats
Definition: inspircd.h:276
chan_hash & GetChans()
Definition: inspircd.h:386
std::vector< ListenSocket * > ports
Definition: inspircd.h:305
CullList GlobalCulls
Definition: inspircd.h:214
std::tr1 ::function< bool(const std::string &)> IsChannel
Definition: inspircd.h:389
void Write(ClientProtocol::Event &protoev, char status=0, const CUList &except_list=CUList())
Definition: channels.cpp:416
static sig_atomic_t s_signal
Definition: inspircd.h:309
unsigned long DnsBad
Definition: inspircd.h:137
Definition: clientprotocol.h:631
std::string ConfigFileName
Definition: inspircd.h:240
ThreadEngine Threads
Definition: inspircd.h:254
Definition: extensible.h:124
SnomaskManager SNO
Definition: inspircd.h:285
unsigned long Accept
Definition: inspircd.h:115
ModeParser Modes
Definition: inspircd.h:246
Definition: clientprotocol.h:614
ISupportManager ISupport
Definition: inspircd.h:320
Definition: uid.h:21
Definition: protocol.h:37
serverstats()
Definition: inspircd.h:167
chan_hash chanlist
Definition: inspircd.h:301
void AddItem(classbase *item)
Definition: cull_list.h:38
Definition: configreader.h:208
BanCacheManager BanCache
Definition: inspircd.h:272
Definition: timer.h:118
Definition: channels.h:37