]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd.h
d0c8f4ca0187b5751d702c7acc1d37b51ef183dd
[user/henk/code/inspircd.git] / include / inspircd.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                     E-mail:
7  *              <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *          the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __INSPIRCD_H__
18 #define __INSPIRCD_H__
19
20 #include <time.h>
21 #include <string>
22 #include <sstream>
23 #include "inspircd_config.h"
24 #include "users.h"
25 #include "channels.h"
26 #include "socket.h"
27 #include "mode.h"
28 #include "helperfuncs.h"
29 #include "socketengine.h"
30 #include "command_parse.h"
31
32 /* Some misc defines */
33 #define ERROR -1
34 #define MAXCOMMAND 32
35
36 /* Crucial defines */
37 #define ETIREDGERBILS EAGAIN
38
39 /** Debug levels for use with InspIRCd::Log()
40  */
41 enum DebugLevel
42 {
43         DEBUG           =       10,
44         VERBOSE         =       20,
45         DEFAULT         =       30,
46         SPARSE          =       40,
47         NONE            =       50,
48 };
49
50 /* This define is used in place of strcmp when we 
51  * want to check if a char* string contains only one
52  * letter. Pretty fast, its just two compares and an
53  * addition.
54  */
55 #define IS_SINGLE(x,y) ( (*x == y) && (*(x+1) == 0) )
56
57 #define DELETE(x) {if (x) { delete x; x = NULL; }}
58
59 template<typename T> inline std::string ConvToStr(const T &in)
60 {
61         std::stringstream tmp;
62         if (!(tmp << in)) return std::string();
63         return tmp.str();
64 }
65
66 class serverstats : public classbase
67 {
68   public:
69         unsigned long statsAccept;
70         unsigned long statsRefused;
71         unsigned long statsUnknown;
72         unsigned long statsCollisions;
73         unsigned long statsDns;
74         unsigned long statsDnsGood;
75         unsigned long statsDnsBad;
76         unsigned long statsConnects;
77         double statsSent;
78         double statsRecv;
79         unsigned long BoundPortCount;
80
81         serverstats()
82         {
83                 statsAccept = statsRefused = statsUnknown = 0;
84                 statsCollisions = statsDns = statsDnsGood = 0;
85                 statsDnsBad = statsConnects = 0;
86                 statsSent = statsRecv = 0.0;
87                 BoundPortCount = 0;
88         }
89 };
90
91 class XLineManager;
92
93 class InspIRCd : public classbase
94 {
95  private:
96         char MODERR[MAXBUF];
97         bool expire_run;
98         servernamelist servernames;
99  
100         void EraseFactory(int j);
101         void EraseModule(int j);
102         void BuildISupport();
103         void MoveTo(std::string modulename,int slot);
104         void Start();
105         void SetSignals(bool SEGVHandler);
106         bool DaemonSeed();
107         void MakeLowerMap();
108         void MoveToLast(std::string modulename);
109         void MoveToFirst(std::string modulename);
110         void MoveAfter(std::string modulename, std::string after);
111         void MoveBefore(std::string modulename, std::string before);
112
113         void ProcessUser(userrec* cu);
114         void DoSocketTimeouts(time_t TIME);
115         void DoBackgroundUserStuff(time_t TIME);
116
117         bool AllModulesReportReady(userrec* user);
118
119         int ModCount;
120         char LogFileName[MAXBUF];
121
122         featurelist Features;
123
124         time_t TIME;
125         time_t OLDTIME;
126
127         char ReadBuffer[65535];
128
129         const long duration_m;
130         const long duration_h;
131         const long duration_d;
132         const long duration_w;
133         const long duration_y;
134
135  public:
136         time_t startup_time;
137         ModeParser* Modes;
138         CommandParser* Parser;
139         SocketEngine* SE;
140         serverstats* stats;
141         ServerConfig* Config;
142         std::vector<InspSocket*> module_sockets;
143         InspSocket* socket_ref[MAX_DESCRIPTORS];        /* XXX: This should probably be made private, with inline accessors */
144         userrec* fd_ref_table[MAX_DESCRIPTORS];         /* XXX: Ditto */
145         user_hash clientlist;
146         chan_hash chanlist;
147         std::vector<userrec*> local_users;
148         std::vector<userrec*> all_opers;
149         irc::whowas::whowas_users whowas;
150         DNS* Res;
151         TimerManager* Timers;
152         command_table cmdlist;
153         XLineManager* XLines;
154
155         ModuleList modules;
156         FactoryList factory;
157
158         time_t Time();
159
160         int GetModuleCount();
161
162         Module* FindModule(const std::string &name);
163
164         int BindPorts(bool bail);
165         bool HasPort(int port, char* addr);
166         bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
167
168         void AddServerName(const std::string &servername);
169         const char* FindServerNamePtr(const std::string &servername);
170         bool FindServerName(const std::string &servername);
171
172         std::string GetServerDescription(const char* servername);
173
174         void WriteOpers(const char* text, ...);
175         void WriteOpers(const std::string &text);
176         
177         userrec* FindNick(const std::string &nick);
178         userrec* FindNick(const char* nick);
179
180         chanrec* FindChan(const std::string &chan);
181         chanrec* FindChan(const char* chan);
182
183         void LoadAllModules();
184         void CheckDie();
185         void CheckRoot();
186         void OpenLog(char** argv, int argc);
187
188         bool UserToPseudo(userrec* user, const std::string &message);
189         bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
190
191         void ServerNoticeAll(char* text, ...);
192         void ServerPrivmsgAll(char* text, ...);
193         void WriteMode(const char* modes, int flags, const char* text, ...);
194
195         bool IsChannel(const char *chname);
196
197         static void Rehash(int status);
198         static void Exit(int status);
199
200         int UserCount();
201         int RegisteredUserCount();
202         int InvisibleUserCount();
203         int OperCount();
204         int UnregisteredUserCount();
205         long ChannelCount();
206         long LocalUserCount();
207
208         void SendError(const char *s);
209
210         /** For use with Module::Prioritize().
211          * When the return value of this function is returned from
212          * Module::Prioritize(), this specifies that the module wishes
213          * to be ordered exactly BEFORE 'modulename'. For more information
214          * please see Module::Prioritize().
215          * @param modulename The module your module wants to be before in the call list
216          * @returns a priority ID which the core uses to relocate the module in the list
217          */
218         long PriorityBefore(const std::string &modulename);
219
220         /** For use with Module::Prioritize().
221          * When the return value of this function is returned from
222          * Module::Prioritize(), this specifies that the module wishes
223          * to be ordered exactly AFTER 'modulename'. For more information please
224          * see Module::Prioritize().
225          * @param modulename The module your module wants to be after in the call list
226          * @returns a priority ID which the core uses to relocate the module in the list
227          */
228         long PriorityAfter(const std::string &modulename);
229
230         /** Publish a 'feature'.
231          * There are two ways for a module to find another module it depends on.
232          * Either by name, using InspIRCd::FindModule, or by feature, using this
233          * function. A feature is an arbitary string which identifies something this
234          * module can do. For example, if your module provides SSL support, but other
235          * modules provide SSL support too, all the modules supporting SSL should
236          * publish an identical 'SSL' feature. This way, any module requiring use
237          * of SSL functions can just look up the 'SSL' feature using FindFeature,
238          * then use the module pointer they are given.
239          * @param FeatureName The case sensitive feature name to make available
240          * @param Mod a pointer to your module class
241          * @returns True on success, false if the feature is already published by
242          * another module.
243          */
244         bool PublishFeature(const std::string &FeatureName, Module* Mod);
245
246         /** Unpublish a 'feature'.
247          * When your module exits, it must call this method for every feature it
248          * is providing so that the feature table is cleaned up.
249          * @param FeatureName the feature to remove
250          */
251         bool UnpublishFeature(const std::string &FeatureName);
252
253         /** Find a 'feature'.
254          * There are two ways for a module to find another module it depends on.
255          * Either by name, using InspIRCd::FindModule, or by feature, using the
256          * InspIRCd::PublishFeature method. A feature is an arbitary string which
257          * identifies something this module can do. For example, if your module
258          * provides SSL support, but other modules provide SSL support too, all
259          * the modules supporting SSL should publish an identical 'SSL' feature.
260          * To find a module capable of providing the feature you want, simply
261          * call this method with the feature name you are looking for.
262          * @param FeatureName The feature name you wish to obtain the module for
263          * @returns A pointer to a valid module class on success, NULL on failure.
264          */
265         Module* FindFeature(const std::string &FeatureName);
266
267         const std::string& GetModuleName(Module* m);
268
269         bool IsNick(const char* n);
270         bool IsIdent(const char* n);
271
272         userrec* FindDescriptor(int socket);
273
274         bool AddMode(ModeHandler* mh, const unsigned char modechar);
275
276         bool AddModeWatcher(ModeWatcher* mw);
277
278         bool DelModeWatcher(ModeWatcher* mw);
279
280         bool AddResolver(Resolver* r);
281
282         void AddCommand(command_t *f);
283
284         void SendMode(const char **parameters, int pcnt, userrec *user);
285
286         bool MatchText(const std::string &sliteral, const std::string &spattern);
287
288         bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
289
290         bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
291
292         void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
293
294         void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
295
296         void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
297
298         void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
299
300         void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
301
302         bool DelGLine(const std::string &hostmask);
303
304         bool DelQLine(const std::string &nickname);
305
306         bool DelZLine(const std::string &ipaddr);
307
308         bool DelKLine(const std::string &hostmask);
309
310         bool DelELine(const std::string &hostmask);
311
312         bool IsValidMask(const std::string &mask);
313
314         void AddSocket(InspSocket* sock);
315
316         void RemoveSocket(InspSocket* sock);
317
318         void DelSocket(InspSocket* sock);
319
320         void RehashServer();
321
322         chanrec* GetChannelIndex(long index);
323
324         void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
325
326         bool NickMatchesEveryone(const std::string &nick, userrec* user);
327         bool IPMatchesEveryone(const std::string &ip, userrec* user);
328         bool HostMatchesEveryone(const std::string &mask, userrec* user);
329         long Duration(const char* str);
330         int OperPassCompare(const char* data,const char* input);
331         bool ULine(const char* server);
332
333         std::string GetRevision();
334         std::string GetVersionString();
335         void WritePID(const std::string &filename);
336         char* ModuleError();
337         bool LoadModule(const char* filename);
338         bool UnloadModule(const char* filename);
339         InspIRCd(int argc, char** argv);
340         void DoOneIteration(bool process_module_sockets);
341         void Log(int level, const char* text, ...);
342         void Log(int level, const std::string &text);
343         int Run();
344 };
345
346 #endif