1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #ifndef __INSPIRCD_H__
18 #define __INSPIRCD_H__
23 #include "inspircd_config.h"
28 #include "helperfuncs.h"
29 #include "socketengine.h"
30 #include "command_parse.h"
32 /* Some misc defines */
37 #define ETIREDGERBILS EAGAIN
39 /** Debug levels for use with InspIRCd::Log()
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
55 #define IS_SINGLE(x,y) ( (*x == y) && (*(x+1) == 0) )
57 #define DELETE(x) {if (x) { delete x; x = NULL; }}
59 template<typename T> inline std::string ConvToStr(const T &in)
61 std::stringstream tmp;
62 if (!(tmp << in)) return std::string();
66 class serverstats : public classbase
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;
79 unsigned long BoundPortCount;
83 statsAccept = statsRefused = statsUnknown = 0;
84 statsCollisions = statsDns = statsDnsGood = 0;
85 statsDnsBad = statsConnects = 0;
86 statsSent = statsRecv = 0.0;
93 class InspIRCd : public classbase
98 servernamelist servernames;
100 void EraseFactory(int j);
101 void EraseModule(int j);
102 void BuildISupport();
103 void MoveTo(std::string modulename,int slot);
105 void SetSignals(bool SEGVHandler);
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);
113 void ProcessUser(userrec* cu);
114 void DoSocketTimeouts(time_t TIME);
115 void DoBackgroundUserStuff(time_t TIME);
117 bool AllModulesReportReady(userrec* user);
120 char LogFileName[MAXBUF];
122 featurelist Features;
127 char ReadBuffer[65535];
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;
138 CommandParser* Parser;
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;
147 std::vector<userrec*> local_users;
148 std::vector<userrec*> all_opers;
149 irc::whowas::whowas_users whowas;
151 TimerManager* Timers;
152 command_table cmdlist;
153 XLineManager* XLines;
160 int GetModuleCount();
162 Module* FindModule(const std::string &name);
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);
168 void AddServerName(const std::string &servername);
169 const char* FindServerNamePtr(const std::string &servername);
170 bool FindServerName(const std::string &servername);
172 std::string GetServerDescription(const char* servername);
174 void WriteOpers(const char* text, ...);
175 void WriteOpers(const std::string &text);
177 userrec* FindNick(const std::string &nick);
178 userrec* FindNick(const char* nick);
180 chanrec* FindChan(const std::string &chan);
181 chanrec* FindChan(const char* chan);
183 void LoadAllModules();
186 void OpenLog(char** argv, int argc);
188 bool UserToPseudo(userrec* user, const std::string &message);
189 bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
191 void ServerNoticeAll(char* text, ...);
192 void ServerPrivmsgAll(char* text, ...);
193 void WriteMode(const char* modes, int flags, const char* text, ...);
195 bool IsChannel(const char *chname);
197 static void Rehash(int status);
198 static void Exit(int status);
201 int RegisteredUserCount();
202 int InvisibleUserCount();
204 int UnregisteredUserCount();
206 long LocalUserCount();
208 void SendError(const char *s);
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
218 long PriorityBefore(const std::string &modulename);
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
228 long PriorityAfter(const std::string &modulename);
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
244 bool PublishFeature(const std::string &FeatureName, Module* Mod);
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
251 bool UnpublishFeature(const std::string &FeatureName);
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.
265 Module* FindFeature(const std::string &FeatureName);
267 const std::string& GetModuleName(Module* m);
269 bool IsNick(const char* n);
270 bool IsIdent(const char* n);
272 userrec* FindDescriptor(int socket);
274 bool AddMode(ModeHandler* mh, const unsigned char modechar);
276 bool AddModeWatcher(ModeWatcher* mw);
278 bool DelModeWatcher(ModeWatcher* mw);
280 bool AddResolver(Resolver* r);
282 void AddCommand(command_t *f);
284 void SendMode(const char **parameters, int pcnt, userrec *user);
286 bool MatchText(const std::string &sliteral, const std::string &spattern);
288 bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
290 bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
292 void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
294 void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
296 void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
298 void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
300 void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
302 bool DelGLine(const std::string &hostmask);
304 bool DelQLine(const std::string &nickname);
306 bool DelZLine(const std::string &ipaddr);
308 bool DelKLine(const std::string &hostmask);
310 bool DelELine(const std::string &hostmask);
312 bool IsValidMask(const std::string &mask);
314 void AddSocket(InspSocket* sock);
316 void RemoveSocket(InspSocket* sock);
318 void DelSocket(InspSocket* sock);
322 chanrec* GetChannelIndex(long index);
324 void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
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);
333 std::string GetRevision();
334 std::string GetVersionString();
335 void WritePID(const std::string &filename);
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);