]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd.h
fc0f2a04e03fa0635e2f1fe08fcd361d57afe380
[user/henk/code/inspircd.git] / include / inspircd.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __INSPIRCD_H__
15 #define __INSPIRCD_H__
16
17 #ifndef WIN32
18 #define DllExport
19 #define CoreExport
20 #define printf_c printf
21 #else
22 #include "inspircd_win32wrapper.h"
23 /** Windows defines these already */
24 #undef DELETE
25 #undef ERROR
26 #endif
27
28 #ifdef __GNUC__
29 #define CUSTOM_PRINTF(STRING, FIRST) __attribute__((format(printf, STRING, FIRST)))
30 #else
31 #define CUSTOM_PRINTF(STRING, FIRST)
32 #endif
33
34 // Required system headers.
35 #include <ctime>
36 #include <cstdarg>
37 #include <algorithm>
38 #include <cmath>
39 #include <cstring>
40 #include <climits>
41
42 #include <sstream>
43 #include <string>
44 #include <vector>
45 #include <deque>
46 #include <map>
47 #include <bitset>
48
49
50 /** A list of failed port bindings, used for informational purposes on startup */
51 typedef std::vector<std::pair<std::string, std::string> > FailedPortList;
52
53 /** A cached text file stored with its contents as lines
54  */
55 typedef std::deque< std::string > file_cache;
56
57 /** A configuration key and value pair
58  */
59 typedef std::pair< std::string, std::string > KeyVal;
60
61 /** A list of related configuration keys and values
62  */
63 typedef std::vector< KeyVal > KeyValList;
64
65 /** An entire config file, built up of KeyValLists
66  */
67 typedef std::multimap< std::string, KeyValList > ConfigDataHash;
68
69
70 #include "inspircd_config.h"
71 #include "numerics.h"
72 #include "uid.h"
73 #include "users.h"
74 #include "channels.h"
75 #include "timer.h"
76 #include "hashcomp.h"
77 #include "typedefs.h"
78 #include "logger.h"
79 #include "usermanager.h"
80 #include "socket.h"
81 #include "ctables.h"
82 #include "command_parse.h"
83 #include "mode.h"
84 #include "socketengine.h"
85 #include "snomasks.h"
86 #include "cull_list.h"
87 #include "filelogger.h"
88 #include "caller.h"
89 #include "modules.h"
90 #include "configreader.h"
91 #include "inspstring.h"
92 #include "protocol.h"
93
94 #ifndef PATH_MAX
95 #warning Potentially broken system, PATH_MAX undefined
96 #define PATH_MAX 4096
97 #endif
98
99 /**
100  * Used to define the maximum number of parameters a command may have.
101  */
102 #define MAXPARAMETERS 127
103
104 /** Returned by some functions to indicate failure.
105  */
106 #define ERROR -1
107
108 /** Support for librodent -
109  * see http://www.chatspike.net/index.php?z=64
110  */
111 #define ETIREDHAMSTERS EAGAIN
112
113 /** Template function to convert any input type to std::string
114  */
115 template<typename T> inline std::string ConvNumeric(const T &in)
116 {
117         if (in == 0) return "0";
118         char res[MAXBUF];
119         char* out = res;
120         T quotient = in;
121         while (quotient) {
122                 *out = "0123456789"[ std::abs( (long)quotient % 10 ) ];
123                 ++out;
124                 quotient /= 10;
125         }
126         if (in < 0)
127                 *out++ = '-';
128         *out = 0;
129         std::reverse(res,out);
130         return res;
131 }
132
133 /** Template function to convert any input type to std::string
134  */
135 inline std::string ConvToStr(const int in)
136 {
137         return ConvNumeric(in);
138 }
139
140 /** Template function to convert any input type to std::string
141  */
142 inline std::string ConvToStr(const long in)
143 {
144         return ConvNumeric(in);
145 }
146
147 /** Template function to convert any input type to std::string
148  */
149 inline std::string ConvToStr(const char* in)
150 {
151         return in;
152 }
153
154 /** Template function to convert any input type to std::string
155  */
156 inline std::string ConvToStr(const bool in)
157 {
158         return (in ? "1" : "0");
159 }
160
161 /** Template function to convert any input type to std::string
162  */
163 inline std::string ConvToStr(char in)
164 {
165         return std::string(in,1);
166 }
167
168 /** Template function to convert any input type to std::string
169  */
170 template <class T> inline std::string ConvToStr(const T &in)
171 {
172         std::stringstream tmp;
173         if (!(tmp << in)) return std::string();
174         return tmp.str();
175 }
176
177 /** Template function to convert any input type to any other type
178  * (usually an integer or numeric type)
179  */
180 template<typename T> inline long ConvToInt(const T &in)
181 {
182         std::stringstream tmp;
183         if (!(tmp << in)) return 0;
184         return atoi(tmp.str().c_str());
185 }
186
187 /** Template function to convert integer to char, storing result in *res and
188  * also returning the pointer to res. Based on Stuart Lowe's C/C++ Pages.
189  * @param T input value
190  * @param V result value
191  * @param R base to convert to
192  */
193 template<typename T, typename V, typename R> inline char* itoa(const T &in, V *res, R base)
194 {
195         if (base < 2 || base > 16) { *res = 0; return res; }
196         char* out = res;
197         int quotient = in;
198         while (quotient) {
199                 *out = "0123456789abcdef"[ std::abs( quotient % base ) ];
200                 ++out;
201                 quotient /= base;
202         }
203         if ( in < 0 && base == 10) *out++ = '-';
204         std::reverse( res, out );
205         *out = 0;
206         return res;
207 }
208
209 /** This class contains various STATS counters
210  * It is used by the InspIRCd class, which internally
211  * has an instance of it.
212  */
213 class serverstats : public classbase
214 {
215   public:
216         /** Number of accepted connections
217          */
218         unsigned long statsAccept;
219         /** Number of failed accepts
220          */
221         unsigned long statsRefused;
222         /** Number of unknown commands seen
223          */
224         unsigned long statsUnknown;
225         /** Number of nickname collisions handled
226          */
227         unsigned long statsCollisions;
228         /** Number of DNS queries sent out
229          */
230         unsigned long statsDns;
231         /** Number of good DNS replies received
232          * NOTE: This may not tally to the number sent out,
233          * due to timeouts and other latency issues.
234          */
235         unsigned long statsDnsGood;
236         /** Number of bad (negative) DNS replies received
237          * NOTE: This may not tally to the number sent out,
238          * due to timeouts and other latency issues.
239          */
240         unsigned long statsDnsBad;
241         /** Number of inbound connections seen
242          */
243         unsigned long statsConnects;
244         /** Total bytes of data transmitted
245          */
246         double statsSent;
247         /** Total bytes of data received
248          */
249         double statsRecv;
250         /** Cpu usage at last sample
251          */
252         timeval LastCPU;
253         /** Time last sample was read
254          */
255         timeval LastSampled;
256         /** The constructor initializes all the counts to zero
257          */
258         serverstats()
259                 : statsAccept(0), statsRefused(0), statsUnknown(0), statsCollisions(0), statsDns(0),
260                 statsDnsGood(0), statsDnsBad(0), statsConnects(0), statsSent(0.0), statsRecv(0.0)
261         {
262         }
263 };
264
265 class InspIRCd;
266
267 DEFINE_HANDLER1(ProcessUserHandler, void, User*);
268 DEFINE_HANDLER2(IsNickHandler, bool, const char*, size_t);
269 DEFINE_HANDLER1(IsIdentHandler, bool, const char*);
270 DEFINE_HANDLER1(FindDescriptorHandler, User*, int);
271 DEFINE_HANDLER1(FloodQuitUserHandler, void, User*);
272 DEFINE_HANDLER2(IsChannelHandler, bool, const char*, size_t);
273 DEFINE_HANDLER1(IsSIDHandler, bool, const std::string&);
274 DEFINE_HANDLER1(RehashHandler, void, const std::string&);
275
276 /* Forward declaration - required */
277 class XLineManager;
278 class BanCacheManager;
279
280 class CoreExport ConfigReaderThread : public Thread
281 {
282         InspIRCd* ServerInstance;
283         bool do_bail;
284         User* TheUser;
285  public:
286         ConfigReaderThread(InspIRCd* Instance, bool bail, User* user) : Thread(), ServerInstance(Instance), do_bail(bail), TheUser(user)
287         {
288         }
289
290         virtual ~ConfigReaderThread()
291         {
292         }
293
294         void Run();
295 };
296
297 /** The main class of the irc server.
298  * This class contains instances of all the other classes
299  * in this software, with the exception of the base class,
300  * classbase. Amongst other things, it contains a ModeParser,
301  * a DNS object, a CommandParser object, and a list of active
302  * Module objects, and facilities for Module objects to
303  * interact with the core system it implements.
304  */
305 class CoreExport InspIRCd : public classbase
306 {
307  private:
308         /** Holds the current UID. Used to generate the next one.
309          */
310         char current_uid[UUID_LENGTH];
311
312         /** Set up the signal handlers
313          */
314         void SetSignals();
315
316         /** Daemonize the ircd and close standard input/output streams
317          * @return True if the program daemonized succesfully
318          */
319         bool DaemonSeed();
320
321         /** Iterate the list of BufferedSocket objects, removing ones which have timed out
322          * @param TIME the current time
323          */
324         void DoSocketTimeouts(time_t TIME);
325
326         /** Increments the current UID by one.
327          */
328         void IncrementUID(int pos);
329
330         /** Perform background user events such as PING checks
331          */
332         void DoBackgroundUserStuff();
333
334         /** Returns true when all modules have done pre-registration checks on a user
335          * @param user The user to verify
336          * @return True if all modules have finished checking this user
337          */
338         bool AllModulesReportReady(User* user);
339
340         /** Logfile pathname specified on the commandline, or empty string
341          */
342         char LogFileName[MAXBUF];
343
344         /** The current time, updated in the mainloop
345          */
346         time_t TIME;
347
348         /** The time that was recorded last time around the mainloop
349          */
350         time_t OLDTIME;
351
352         /** A 64k buffer used to read client lines into
353          */
354         char ReadBuffer[65535];
355
356         /** Used when connecting clients
357          */
358         irc::sockets::insp_sockaddr client, server;
359
360         /** Used when connecting clients
361          */
362         socklen_t length;
363
364 #ifdef WIN32
365         IPC* WindowsIPC;
366 #endif
367
368  public:
369
370         /** Global cull list, will be processed on next iteration
371          */
372         CullList GlobalCulls;
373
374         /**** Functors ****/
375
376         ProcessUserHandler HandleProcessUser;
377         IsNickHandler HandleIsNick;
378         IsIdentHandler HandleIsIdent;
379         FindDescriptorHandler HandleFindDescriptor;
380         FloodQuitUserHandler HandleFloodQuitUser;
381         IsChannelHandler HandleIsChannel;
382         IsSIDHandler HandleIsSID;
383         RehashHandler HandleRehash;
384
385         /** BufferedSocket classes pending deletion after being closed.
386          * We don't delete these immediately as this may cause a segmentation fault.
387          */
388         std::map<BufferedSocket*,BufferedSocket*> SocketCull;
389
390         /** Globally accessible fake user record. This is used to force mode changes etc across s2s, etc.. bit ugly, but.. better than how this was done in 1.1
391          * Reason for it:
392          * kludge alert!
393          * SendMode expects a User* to send the numeric replies
394          * back to, so we create it a fake user that isnt in the user
395          * hash and set its descriptor to FD_MAGIC_NUMBER so the data
396          * falls into the abyss :p
397          */
398         User *FakeClient;
399
400         /** Returns the next available UID for this server.
401          */
402         std::string GetUID();
403
404         /** Find a user in the UUID hash
405          * @param nick The nickname to find
406          * @return A pointer to the user, or NULL if the user does not exist
407          */
408         User *FindUUID(const std::string &);
409
410         /** Find a user in the UUID hash
411          * @param nick The nickname to find
412          * @return A pointer to the user, or NULL if the user does not exist
413          */
414         User *FindUUID(const char *);
415
416         /** Build the ISUPPORT string by triggering all modules On005Numeric events
417          */
418         void BuildISupport();
419
420         /** List of server names we've seen.
421          */
422         servernamelist servernames;
423
424         /** Time this ircd was booted
425          */
426         time_t startup_time;
427
428         /** Config file pathname specified on the commandline or via ./configure
429          */
430         char ConfigFileName[MAXBUF];
431
432         /** Mode handler, handles mode setting and removal
433          */
434         ModeParser* Modes;
435
436         /** Command parser, handles client to server commands
437          */
438         CommandParser* Parser;
439
440         /** Socket engine, handles socket activity events
441          */
442         SocketEngine* SE;
443
444         /** Thread engine, Handles threading where required
445          */
446         ThreadEngine* Threads;
447
448         /** The thread/class used to read config files in REHASH and on startup
449          */
450         ConfigReaderThread* ConfigThread;
451
452         /** LogManager handles logging.
453          */
454         LogManager *Logs;
455
456         /** ModuleManager contains everything related to loading/unloading
457          * modules.
458          */
459         ModuleManager* Modules;
460
461         /** BanCacheManager is used to speed up checking of restrictions on connection
462          * to the IRCd.
463          */
464         BanCacheManager *BanCache;
465
466         /** Stats class, holds miscellaneous stats counters
467          */
468         serverstats* stats;
469
470         /**  Server Config class, holds configuration file data
471          */
472         ServerConfig* Config;
473
474         /** Snomask manager - handles routing of snomask messages
475          * to opers.
476          */
477         SnomaskManager* SNO;
478
479         /** DNS class, provides resolver facilities to the core and modules
480          */
481         DNS* Res;
482
483         /** Timer manager class, triggers Timer timer events
484          */
485         TimerManager* Timers;
486
487         /** X-Line manager. Handles G/K/Q/E line setting, removal and matching
488          */
489         XLineManager* XLines;
490
491         /** User manager. Various methods and data associated with users.
492          */
493         UserManager *Users;
494
495         /** Channel list, a hash_map containing all channels XXX move to channel manager class
496          */
497         chan_hash* chanlist;
498
499         /** Set to the current signal recieved
500          */
501         int s_signal;
502
503         /** Protocol interface, overridden by server protocol modules
504          */
505         ProtocolInterface* PI;
506
507         /** Get the current time
508          * Because this only calls time() once every time around the mainloop,
509          * it is much faster than calling time() directly.
510          * @return The current time as an epoch value (time_t)
511          */
512         time_t Time();
513
514         /** Process a user whos socket has been flagged as active
515          * @param cu The user to process
516          * @return There is no actual return value, however upon exit, the user 'cu' may have been
517          * marked for deletion in the global CullList.
518          */
519         caller1<void, User*> ProcessUser;
520
521         /** Bind all ports specified in the configuration file.
522          * @param bail True if the function should bail back to the shell on failure
523          * @param found_ports The actual number of ports found in the config, as opposed to the number actually bound
524          * @return The number of ports actually bound without error
525          */
526         int BindPorts(bool bail, int &found_ports, FailedPortList &failed_ports);
527
528         /** Binds a socket on an already open file descriptor
529          * @param sockfd A valid file descriptor of an open socket
530          * @param port The port number to bind to
531          * @param addr The address to bind to (IP only)
532          * @return True if the port was bound successfully
533          */
534         bool BindSocket(int sockfd, int port, const char* addr, bool dolisten = true);
535
536         /** Adds a server name to the list of servers we've seen
537          * @param The servername to add
538          */
539         void AddServerName(const std::string &servername);
540
541         /** Finds a cached char* pointer of a server name,
542          * This is used to optimize User by storing only the pointer to the name
543          * @param The servername to find
544          * @return A pointer to this name, gauranteed to never become invalid
545          */
546         const char* FindServerNamePtr(const std::string &servername);
547
548         /** Returns true if we've seen the given server name before
549          * @param The servername to find
550          * @return True if we've seen this server name before
551          */
552         bool FindServerName(const std::string &servername);
553
554         /** Gets the GECOS (description) field of the given server.
555          * If the servername is not that of the local server, the name
556          * is passed to handling modules which will attempt to determine
557          * the GECOS that bleongs to the given servername.
558          * @param servername The servername to find the description of
559          * @return The description of this server, or of the local server
560          */
561         std::string GetServerDescription(const char* servername);
562
563         /** Find a user in the nick hash.
564          * If the user cant be found in the nick hash check the uuid hash
565          * @param nick The nickname to find
566          * @return A pointer to the user, or NULL if the user does not exist
567          */
568         User* FindNick(const std::string &nick);
569
570         /** Find a user in the nick hash.
571          * If the user cant be found in the nick hash check the uuid hash
572          * @param nick The nickname to find
573          * @return A pointer to the user, or NULL if the user does not exist
574          */
575         User* FindNick(const char* nick);
576
577         /** Find a user in the nick hash ONLY
578          */
579         User* FindNickOnly(const char* nick);
580
581         /** Find a user in the nick hash ONLY
582          */
583         User* FindNickOnly(const std::string &nick);
584
585         /** Find a channel in the channels hash
586          * @param chan The channel to find
587          * @return A pointer to the channel, or NULL if the channel does not exist
588          */
589         Channel* FindChan(const std::string &chan);
590
591         /** Find a channel in the channels hash
592          * @param chan The channel to find
593          * @return A pointer to the channel, or NULL if the channel does not exist
594          */
595         Channel* FindChan(const char* chan);
596
597         /** Check for a 'die' tag in the config file, and abort if found
598          * @return Depending on the configuration, this function may never return
599          */
600         void CheckDie();
601
602         /** Check we aren't running as root, and exit if we are
603          * @return Depending on the configuration, this function may never return
604          */
605         void CheckRoot();
606
607         /** Determine the right path for, and open, the logfile
608          * @param argv The argv passed to main() initially, used to calculate program path
609          * @param argc The argc passed to main() initially, used to calculate program path
610          * @return True if the log could be opened, false if otherwise
611          */
612         bool OpenLog(char** argv, int argc);
613
614         /** Return true if a channel name is valid
615          * @param chname A channel name to verify
616          * @return True if the name is valid
617          */
618         caller2<bool, const char*, size_t> IsChannel;
619
620         /** Return true if str looks like a server ID
621          * @param string to check against
622          */
623         caller1<bool, const std::string&> IsSID;
624
625         /** Rehash the local server
626          */
627         caller1<void, const std::string&> Rehash;
628
629         /** Handles incoming signals after being set
630          * @param signal the signal recieved
631          */
632         void SignalHandler(int signal);
633
634         /** Sets the signal recieved
635          * @param signal the signal recieved
636          */
637         static void SetSignal(int signal);
638
639         /** Causes the server to exit after unloading modules and
640          * closing all open file descriptors.
641          *
642          * @param The exit code to give to the operating system
643          * (See the ExitStatus enum for valid values)
644          */
645         void Exit(int status);
646
647         /** Causes the server to exit immediately with exit code 0.
648          * The status code is required for signal handlers, and ignored.
649          */
650         static void QuickExit(int status);
651
652         /** Return a count of channels on the network
653          * @return The number of channels
654          */
655         long ChannelCount();
656
657         /** Send an error notice to all local users, opered and unopered
658          * @param s The error string to send
659          */
660         void SendError(const std::string &s);
661
662         /** Return true if a nickname is valid
663          * @param n A nickname to verify
664          * @return True if the nick is valid
665          */
666         caller2<bool, const char*, size_t> IsNick;
667
668         /** Return true if an ident is valid
669          * @param An ident to verify
670          * @return True if the ident is valid
671          */
672         caller1<bool, const char*> IsIdent;
673
674         /** Find a username by their file descriptor.
675          * It is preferred to use this over directly accessing the fd_ref_table array.
676          * @param socket The file descriptor of a user
677          * @return A pointer to the user if the user exists locally on this descriptor
678          */
679         caller1<User*, int> FindDescriptor;
680
681         /** Add a dns Resolver class to this server's active set
682          * @param r The resolver to add
683          * @param cached If this value is true, then the cache will
684          * be searched for the DNS result, immediately. If the value is
685          * false, then a request will be sent to the nameserver, and the
686          * result will not be immediately available. You should usually
687          * use the boolean value which you passed to the Resolver
688          * constructor, which Resolver will set appropriately depending
689          * on if cached results are available and haven't expired. It is
690          * however safe to force this value to false, forcing a remote DNS
691          * lookup, but not an update of the cache.
692          * @return True if the operation completed successfully. Note that
693          * if this method returns true, you should not attempt to access
694          * the resolver class you pass it after this call, as depending upon
695          * the request given, the object may be deleted!
696          */
697         bool AddResolver(Resolver* r, bool cached);
698
699         /** Add a command to this server's command parser
700          * @param f A Command command handler object to add
701          * @throw ModuleException Will throw ModuleExcption if the command already exists
702          */
703         void AddCommand(Command *f);
704
705         /** Send a modechange.
706          * The parameters provided are identical to that sent to the
707          * handler for class cmd_mode.
708          * @param parameters The mode parameters
709          * @param pcnt The number of items you have given in the first parameter
710          * @param user The user to send error messages to
711          */
712         void SendMode(const std::vector<std::string>& parameters, User *user);
713
714         /** Match two strings using pattern matching.
715          * This operates identically to the global function match(),
716          * except for that it takes std::string arguments rather than
717          * const char* ones.
718          * @param sliteral The literal string to match against
719          * @param spattern The pattern to match against. CIDR and globs are supported.
720          */
721         bool MatchText(const std::string &sliteral, const std::string &spattern);
722
723         /** Call the handler for a given command.
724          * @param commandname The command whos handler you wish to call
725          * @param parameters The mode parameters
726          * @param pcnt The number of items you have given in the first parameter
727          * @param user The user to execute the command as
728          * @return True if the command handler was called successfully
729          */
730         CmdResult CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user);
731
732         /** Return true if the command is a module-implemented command and the given parameters are valid for it
733          * @param parameters The mode parameters
734          * @param pcnt The number of items you have given in the first parameter
735          * @param user The user to test-execute the command as
736          * @return True if the command handler is a module command, and there are enough parameters and the user has permission to the command
737          */
738         bool IsValidModuleCommand(const std::string &commandname, int pcnt, User* user);
739
740         /** Return true if the given parameter is a valid nick!user\@host mask
741          * @param mask A nick!user\@host masak to match against
742          * @return True i the mask is valid
743          */
744         bool IsValidMask(const std::string &mask);
745
746         /** Rehash the local server
747          */
748         void RehashServer();
749
750         /** Return the channel whos index number matches that provided
751          * @param The index number of the channel to fetch
752          * @return A channel record, or NUll if index < 0 or index >= InspIRCd::ChannelCount()
753          */
754         Channel* GetChannelIndex(long index);
755
756         /** Dump text to a user target, splitting it appropriately to fit
757          * @param User the user to dump the text to
758          * @param LinePrefix text to prefix each complete line with
759          * @param TextStream the text to send to the user
760          */
761         void DumpText(User* User, const std::string &LinePrefix, std::stringstream &TextStream);
762
763         /** Check if the given nickmask matches too many users, send errors to the given user
764          * @param nick A nickmask to match against
765          * @param user A user to send error text to
766          * @return True if the nick matches too many users
767          */
768         bool NickMatchesEveryone(const std::string &nick, User* user);
769
770         /** Check if the given IP mask matches too many users, send errors to the given user
771          * @param ip An ipmask to match against
772          * @param user A user to send error text to
773          * @return True if the ip matches too many users
774          */
775         bool IPMatchesEveryone(const std::string &ip, User* user);
776
777         /** Check if the given hostmask matches too many users, send errors to the given user
778          * @param mask A hostmask to match against
779          * @param user A user to send error text to
780          * @return True if the host matches too many users
781          */
782         bool HostMatchesEveryone(const std::string &mask, User* user);
783
784         /** Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
785          * @param str A string containing a time in the form 1y2w3d4h6m5s
786          * (one year, two weeks, three days, four hours, six minutes and five seconds)
787          * @return The total number of seconds
788          */
789         long Duration(const std::string &str);
790
791         /** Attempt to compare a password to a string from the config file.
792          * This will be passed to handling modules which will compare the data
793          * against possible hashed equivalents in the input string.
794          * @param ex The object (user, server, whatever) causing the comparison.
795          * @param data The data from the config file
796          * @param input The data input by the oper
797          * @param hashtype The hash from the config file
798          * @return 0 if the strings match, 1 or -1 if they do not
799          */
800         int PassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype);
801
802         /** Check if a given server is a uline.
803          * An empty string returns true, this is by design.
804          * @param server The server to check for uline status
805          * @return True if the server is a uline OR the string is empty
806          */
807         bool ULine(const char* server);
808
809         /** Returns true if the uline is 'silent' (doesnt generate
810          * remote connect notices etc).
811          */
812         bool SilentULine(const char* server);
813
814         /** Returns the subversion revision ID of this ircd
815          * @return The revision ID or an empty string
816          */
817         std::string GetRevision();
818
819         /** Returns the full version string of this ircd
820          * @return The version string
821          */
822         std::string GetVersionString();
823
824         /** Attempt to write the process id to a given file
825          * @param filename The PID file to attempt to write to
826          * @return This function may bail if the file cannot be written
827          */
828         void WritePID(const std::string &filename);
829
830         /** This constructor initialises all the subsystems and reads the config file.
831          * @param argc The argument count passed to main()
832          * @param argv The argument list passed to main()
833          * @throw <anything> If anything is thrown from here and makes it to
834          * you, you should probably just give up and go home. Yes, really.
835          * It's that bad. Higher level classes should catch any non-fatal exceptions.
836          */
837         InspIRCd(int argc, char** argv);
838
839         /** Send a line of WHOIS data to a user.
840          * @param user user to send the line to
841          * @param dest user being WHOISed
842          * @param numeric Numeric to send
843          * @param text Text of the numeric
844          */
845         void SendWhoisLine(User* user, User* dest, int numeric, const std::string &text);
846
847         /** Send a line of WHOIS data to a user.
848          * @param user user to send the line to
849          * @param dest user being WHOISed
850          * @param numeric Numeric to send
851          * @param format Format string for the numeric
852          * @param ... Parameters for the format string
853          */
854         void SendWhoisLine(User* user, User* dest, int numeric, const char* format, ...) CUSTOM_PRINTF(5, 6);
855
856         /** Quit a user for excess flood, and if they are not
857          * fully registered yet, temporarily zline their IP.
858          * @param current user to quit
859          */
860         caller1<void, User*> FloodQuitUser;
861
862         /** Restart the server.
863          * This function will not return. If an error occurs,
864          * it will throw an instance of CoreException.
865          * @param reason The restart reason to show to all clients
866          * @throw CoreException An instance of CoreException indicating the error from execv().
867          */
868         void Restart(const std::string &reason);
869
870         /** Prepare the ircd for restart or shutdown.
871          * This function unloads all modules which can be unloaded,
872          * closes all open sockets, and closes the logfile.
873          */
874         void Cleanup();
875
876         /** This copies the user and channel hash_maps into new hash maps.
877          * This frees memory used by the hash_map allocator (which it neglects
878          * to free, most of the time, using tons of ram)
879          */
880         void RehashUsersAndChans();
881
882         /** Resets the cached max bans value on all channels.
883          * Called by rehash.
884          */
885         void ResetMaxBans();
886
887         /** Return a time_t as a human-readable string.
888          */
889         std::string TimeString(time_t curtime);
890
891         /** Begin execution of the server.
892          * NOTE: this function NEVER returns. Internally,
893          * it will repeatedly loop.
894          * @return The return value for this function is undefined.
895          */
896         int Run();
897
898         /** Force all BufferedSockets to be removed which are due to
899          * be culled.
900          */
901         void BufferedSocketCull();
902
903         /** Adds an extban char to the 005 token.
904          */
905         void AddExtBanChar(char c);
906
907         char* GetReadBuffer()
908         {
909                 return this->ReadBuffer;
910         }
911 };
912
913 #endif