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