]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd.h
Fixed
[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  public:
130         time_t startup_time;
131         ModeParser* ModeGrok;
132         CommandParser* Parser;
133         SocketEngine* SE;
134         serverstats* stats;
135         ServerConfig* Config;
136         std::vector<InspSocket*> module_sockets;
137         InspSocket* socket_ref[MAX_DESCRIPTORS];        /* XXX: This should probably be made private, with inline accessors */
138         userrec* fd_ref_table[MAX_DESCRIPTORS];         /* XXX: Ditto */
139         user_hash clientlist;
140         chan_hash chanlist;
141         std::vector<userrec*> local_users;
142         std::vector<userrec*> all_opers;
143         irc::whowas::whowas_users whowas;
144         DNS* Res;
145         TimerManager* Timers;
146         command_table cmdlist;
147         XLineManager* XLines;
148
149         ModuleList modules;
150         FactoryList factory;
151
152         time_t Time();
153
154         int GetModuleCount();
155
156         Module* FindModule(const std::string &name);
157
158         int BindPorts(bool bail);
159         bool HasPort(int port, char* addr);
160         bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
161
162         void AddServerName(const std::string &servername);
163         const char* FindServerNamePtr(const std::string &servername);
164         bool FindServerName(const std::string &servername);
165
166         std::string GetServerDescription(const char* servername);
167
168         void WriteOpers(const char* text, ...);
169         void WriteOpers(const std::string &text);
170         
171         userrec* FindNick(const std::string &nick);
172         userrec* FindNick(const char* nick);
173
174         chanrec* FindChan(const std::string &chan);
175         chanrec* FindChan(const char* chan);
176
177         void LoadAllModules();
178         void CheckDie();
179         void CheckRoot();
180         void OpenLog(char** argv, int argc);
181
182         bool UserToPseudo(userrec* user, const std::string &message);
183         bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
184
185         void ServerNoticeAll(char* text, ...);
186         void ServerPrivmsgAll(char* text, ...);
187         void WriteMode(const char* modes, int flags, const char* text, ...);
188
189         bool IsChannel(const char *chname);
190
191         static void Rehash(int status);
192         static void Exit(int status);
193
194         int usercnt();
195         int registered_usercount();
196         int usercount_invisible();
197         int usercount_opers();
198         int usercount_unknown();
199         long chancount();
200         long local_count();
201
202         void SendError(const char *s);
203
204         /** For use with Module::Prioritize().
205          * When the return value of this function is returned from
206          * Module::Prioritize(), this specifies that the module wishes
207          * to be ordered exactly BEFORE 'modulename'. For more information
208          * please see Module::Prioritize().
209          * @param modulename The module your module wants to be before in the call list
210          * @returns a priority ID which the core uses to relocate the module in the list
211          */
212         long PriorityBefore(const std::string &modulename);
213
214         /** For use with Module::Prioritize().
215          * When the return value of this function is returned from
216          * Module::Prioritize(), this specifies that the module wishes
217          * to be ordered exactly AFTER 'modulename'. For more information please
218          * see Module::Prioritize().
219          * @param modulename The module your module wants to be after in the call list
220          * @returns a priority ID which the core uses to relocate the module in the list
221          */
222         long PriorityAfter(const std::string &modulename);
223
224         /** Publish a 'feature'.
225          * There are two ways for a module to find another module it depends on.
226          * Either by name, using InspIRCd::FindModule, or by feature, using this
227          * function. A feature is an arbitary string which identifies something this
228          * module can do. For example, if your module provides SSL support, but other
229          * modules provide SSL support too, all the modules supporting SSL should
230          * publish an identical 'SSL' feature. This way, any module requiring use
231          * of SSL functions can just look up the 'SSL' feature using FindFeature,
232          * then use the module pointer they are given.
233          * @param FeatureName The case sensitive feature name to make available
234          * @param Mod a pointer to your module class
235          * @returns True on success, false if the feature is already published by
236          * another module.
237          */
238         bool PublishFeature(const std::string &FeatureName, Module* Mod);
239
240         /** Unpublish a 'feature'.
241          * When your module exits, it must call this method for every feature it
242          * is providing so that the feature table is cleaned up.
243          * @param FeatureName the feature to remove
244          */
245         bool UnpublishFeature(const std::string &FeatureName);
246
247         /** Find a 'feature'.
248          * There are two ways for a module to find another module it depends on.
249          * Either by name, using InspIRCd::FindModule, or by feature, using the
250          * InspIRCd::PublishFeature method. A feature is an arbitary string which
251          * identifies something this module can do. For example, if your module
252          * provides SSL support, but other modules provide SSL support too, all
253          * the modules supporting SSL should publish an identical 'SSL' feature.
254          * To find a module capable of providing the feature you want, simply
255          * call this method with the feature name you are looking for.
256          * @param FeatureName The feature name you wish to obtain the module for
257          * @returns A pointer to a valid module class on success, NULL on failure.
258          */
259         Module* FindFeature(const std::string &FeatureName);
260
261         const std::string& GetModuleName(Module* m);
262
263         bool IsNick(const char* n);
264         bool IsIdent(const char* n);
265
266         userrec* FindDescriptor(int socket);
267
268         bool AddMode(ModeHandler* mh, const unsigned char modechar);
269
270         bool AddModeWatcher(ModeWatcher* mw);
271
272         bool DelModeWatcher(ModeWatcher* mw);
273
274         bool AddResolver(Resolver* r);
275
276         void AddCommand(command_t *f);
277
278         void SendMode(const char **parameters, int pcnt, userrec *user);
279
280         bool MatchText(const std::string &sliteral, const std::string &spattern);
281
282         bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
283
284         bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
285
286         bool IsUlined(const std::string &server);
287
288         void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
289
290         void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
291
292         void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
293
294         void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
295
296         void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
297
298         bool DelGLine(const std::string &hostmask);
299
300         bool DelQLine(const std::string &nickname);
301
302         bool DelZLine(const std::string &ipaddr);
303
304         bool DelKLine(const std::string &hostmask);
305
306         bool DelELine(const std::string &hostmask);
307
308         long CalcDuration(const std::string &duration);
309
310         bool IsValidMask(const std::string &mask);
311
312         void AddSocket(InspSocket* sock);
313
314         void RemoveSocket(InspSocket* sock);
315
316         void DelSocket(InspSocket* sock);
317
318         void RehashServer();
319
320         chanrec* GetChannelIndex(long index);
321
322         void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
323
324         std::string GetRevision();
325         std::string GetVersionString();
326         void WritePID(const std::string &filename);
327         char* ModuleError();
328         bool LoadModule(const char* filename);
329         bool UnloadModule(const char* filename);
330         InspIRCd(int argc, char** argv);
331         void DoOneIteration(bool process_module_sockets);
332         void Log(int level, const char* text, ...);
333         void Log(int level, const std::string &text);
334         int Run();
335 };
336
337 #endif