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 "convto.h"
54 #include "stdalgo.h"
55 
56 CoreExport extern InspIRCd* ServerInstance;
57 
60 template <typename T>
61 struct fakederef
62 {
63  T* operator->()
64  {
65  return static_cast<T*>(this);
66  }
67 };
68 
69 #include "config.h"
70 #include "dynref.h"
71 #include "consolecolors.h"
72 #include "cull_list.h"
73 #include "extensible.h"
74 #include "fileutils.h"
75 #include "ctables.h"
76 #include "numerics.h"
77 #include "numeric.h"
78 #include "uid.h"
79 #include "server.h"
80 #include "users.h"
81 #include "channels.h"
82 #include "timer.h"
83 #include "hashcomp.h"
84 #include "logger.h"
85 #include "usermanager.h"
86 #include "socket.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 "clientprotocol.h"
95 #include "threadengine.h"
96 #include "configreader.h"
97 #include "inspstring.h"
98 #include "protocol.h"
99 #include "bancache.h"
100 #include "isupportmanager.h"
101 
107 {
108  public:
111  unsigned long Accept;
114  unsigned long Refused;
117  unsigned long Unknown;
120  unsigned long Collisions;
123  unsigned long Dns;
128  unsigned long DnsGood;
133  unsigned long DnsBad;
136  unsigned long Connects;
139  unsigned long Sent;
142  unsigned long Recv;
143 #ifdef _WIN32
144 
146  FILETIME LastCPU;
149  LARGE_INTEGER LastSampled;
152  LARGE_INTEGER QPFrequency;
153 #else
154 
156  timeval LastCPU;
159  timespec LastSampled;
160 #endif
161 
164  : Accept(0), Refused(0), Unknown(0), Collisions(0), Dns(0),
165  DnsGood(0), DnsBad(0), Connects(0), Sent(0), Recv(0)
166  {
167  }
168 };
169 
176 class CoreExport InspIRCd
177 {
178  private:
181  void SetSignals();
182 
186  bool DaemonSeed();
187 
190  struct timespec TIME;
191 
195  char ReadBuffer[65535];
196 
197  ClientProtocol::RFCEvents rfcevents;
198 
202  void CheckRoot();
203 
204  public:
205 
206  UIDGenerator UIDGen;
207 
213 
223 
228  User* FindUUID(const std::string &uid);
229 
232  time_t startup_time;
233 
236  std::string ConfigFileName;
237 
238  ExtensionManager Extensions;
239 
243 
247 
251 
255 
259 
264 
269 
273 
277 
282 
286 
290 
294 
297  chan_hash chanlist;
298 
301  std::vector<ListenSocket*> ports;
302 
305  static sig_atomic_t s_signal;
306 
310 
314 
317 
323  inline time_t Time() { return TIME.tv_sec; }
325  inline long Time_ns() { return TIME.tv_nsec; }
327  void UpdateTime();
328 
334  std::string GenRandomStr(unsigned int length, bool printable = true);
338  unsigned long GenRandomInt(unsigned long max);
339 
341  TR1NS::function<void(char*, size_t)> GenRandom;
342 
348  static void DefaultGenRandom(char* output, size_t max);
349 
355  bool BindPort(ConfigTag* tag, const irc::sockets::sockaddrs& sa, std::vector<ListenSocket*>& old_ports);
356 
360  int BindPorts(FailedPortList &failed_ports);
361 
367  User* FindNick(const std::string &nick);
368 
371  User* FindNickOnly(const std::string &nick);
372 
377  Channel* FindChan(const std::string &chan);
378 
382  chan_hash& GetChans() { return chanlist; }
383 
385  TR1NS::function<bool(const std::string&)> IsChannel;
386 
392  static bool DefaultIsChannel(const std::string& channel);
393 
398  static bool IsHost(const std::string& host);
399 
403  static bool IsSID(const std::string& sid);
404 
408  void SignalHandler(int signal);
409 
413  static void SetSignal(int signal);
414 
421  void Exit(int status);
422 
428  static std::string Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2);
429  static std::string Format(va_list& vaList, const char* formatString) CUSTOM_PRINTF(2, 0);
430 
432  TR1NS::function<bool(const std::string&)> IsNick;
433 
439  static bool DefaultIsNick(const std::string& nick);
440 
442  TR1NS::function<bool(const std::string&)> IsIdent;
443 
449  static bool DefaultIsIdent(const std::string& ident);
450 
457  static bool Match(const std::string& str, const std::string& mask, unsigned const char* map = NULL);
458  static bool Match(const char* str, const char* mask, unsigned const char* map = NULL);
459 
467  static bool MatchCIDR(const std::string& str, const std::string& mask, unsigned const char* map = NULL);
468  static bool MatchCIDR(const char* str, const char* mask, unsigned const char* map = NULL);
469 
475  static bool MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr);
476 
481  static bool IsValidMask(const std::string& mask);
482 
486  static void StripColor(std::string &sentence);
487 
491  static void ProcessColors(file_cache& input);
492 
496  void Rehash(const std::string& uuid = "");
497 
503  static unsigned long Duration(const std::string& str);
504 
511  static bool Duration(const std::string& str, unsigned long& duration);
512 
517  static bool IsValidDuration(const std::string& str);
518 
528  bool PassCompare(Extensible* ex, const std::string& data, const std::string& input, const std::string& hashtype);
529 
533  std::string GetVersionString(bool getFullVersion = false);
534 
540  void WritePID(const std::string& filename, bool exitonfail = true);
541 
549  InspIRCd(int argc, char** argv);
550 
555  void Cleanup();
556 
564  static std::string TimeString(time_t curtime, const char* format = NULL, bool utc = false);
565 
573  static bool TimingSafeCompare(const std::string& one, const std::string& two);
574 
579  void Run();
580 
581  char* GetReadBuffer()
582  {
583  return this->ReadBuffer;
584  }
585 
586  ClientProtocol::RFCEvents& GetRFCEvents() { return rfcevents; }
587 };
588 
589 ENTRYPOINT;
590 
591 inline void stdalgo::culldeleter::operator()(classbase* item)
592 {
593  if (item)
594  ServerInstance->GlobalCulls.AddItem(item);
595 }
596 
597 inline void Channel::Write(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg, char status, const CUList& except_list)
598 {
599  ClientProtocol::Event event(protoevprov, msg);
600  Write(event, status, except_list);
601 }
602 
603 inline void LocalUser::Send(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg)
604 {
605  ClientProtocol::Event event(protoevprov, msg);
606  Send(event);
607 }
608 
609 #include "numericbuilder.h"
610 #include "clientprotocolmsg.h"
611 #include "clientprotocolevent.h"
Definition: threadengine_pthread.h:36
unsigned long DnsGood
Definition: inspircd.h:128
std::tr1 ::function< void(char *, size_t)> GenRandom
Definition: inspircd.h:341
ServerConfig * Config
Definition: inspircd.h:276
ConfigReaderThread * ConfigThread
Definition: inspircd.h:254
ModuleManager Modules
Definition: inspircd.h:263
unsigned long Unknown
Definition: inspircd.h:117
Definition: configreader.h:37
Definition: inspircd.h:176
unsigned long Connects
Definition: inspircd.h:136
Definition: extensible.h:90
Definition: isupportmanager.h:23
time_t Time()
Definition: inspircd.h:323
long Time_ns()
Definition: inspircd.h:325
Definition: cull_list.h:54
Definition: logger.h:121
STL namespace.
Definition: users.h:224
unsigned long Recv
Definition: inspircd.h:142
Definition: command_parse.h:30
unsigned long Refused
Definition: inspircd.h:114
unsigned long Sent
Definition: inspircd.h:139
FakeUser * FakeClient
Definition: inspircd.h:222
LogManager Logs
Definition: inspircd.h:258
ProtocolInterface * PI
Definition: inspircd.h:309
ProtocolInterface DefaultProtocolInterface
Definition: inspircd.h:313
Definition: socket.h:58
Definition: configreader.h:471
Definition: base.h:41
Definition: cull_list.h:30
UserManager Users
Definition: inspircd.h:293
unsigned long Collisions
Definition: inspircd.h:120
TimerManager Timers
Definition: inspircd.h:285
Definition: clientprotocol.h:461
timespec LastSampled
Definition: inspircd.h:159
Definition: modules.h:935
Definition: bancache.h:50
Definition: mode.h:538
CommandParser Parser
Definition: inspircd.h:246
Definition: clientprotocol.h:180
XLineManager * XLines
Definition: inspircd.h:289
Definition: inspircd.h:106
unsigned long Dns
Definition: inspircd.h:123
Definition: usermanager.h:24
timeval LastCPU
Definition: inspircd.h:156
ActionList AtomicActions
Definition: inspircd.h:212
Definition: users.h:888
Definition: inspircd.h:61
Definition: snomasks.h:75
time_t startup_time
Definition: inspircd.h:232
Definition: xline.h:406
serverstats stats
Definition: inspircd.h:272
chan_hash & GetChans()
Definition: inspircd.h:382
std::vector< ListenSocket * > ports
Definition: inspircd.h:301
CullList GlobalCulls
Definition: inspircd.h:210
std::tr1 ::function< bool(const std::string &)> IsChannel
Definition: inspircd.h:385
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:305
unsigned long DnsBad
Definition: inspircd.h:133
Definition: clientprotocol.h:631
std::string ConfigFileName
Definition: inspircd.h:236
ThreadEngine Threads
Definition: inspircd.h:250
Definition: extensible.h:124
SnomaskManager SNO
Definition: inspircd.h:281
unsigned long Accept
Definition: inspircd.h:111
ModeParser Modes
Definition: inspircd.h:242
Definition: clientprotocol.h:614
ISupportManager ISupport
Definition: inspircd.h:316
Definition: uid.h:21
Definition: protocol.h:37
serverstats()
Definition: inspircd.h:163
chan_hash chanlist
Definition: inspircd.h:297
void AddItem(classbase *item)
Definition: cull_list.h:38
Definition: configreader.h:208
BanCacheManager BanCache
Definition: inspircd.h:268
Definition: timer.h:118
Definition: channels.h:37