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];
131 ModeParser* ModeGrok;
132 CommandParser* Parser;
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;
141 std::vector<userrec*> local_users;
142 std::vector<userrec*> all_opers;
143 irc::whowas::whowas_users whowas;
145 TimerManager* Timers;
146 command_table cmdlist;
147 XLineManager* XLines;
154 int GetModuleCount();
156 Module* FindModule(const std::string &name);
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);
162 void AddServerName(const std::string &servername);
163 const char* FindServerNamePtr(const std::string &servername);
164 bool FindServerName(const std::string &servername);
166 std::string GetServerDescription(const char* servername);
168 void WriteOpers(const char* text, ...);
169 void WriteOpers(const std::string &text);
171 userrec* FindNick(const std::string &nick);
172 userrec* FindNick(const char* nick);
174 chanrec* FindChan(const std::string &chan);
175 chanrec* FindChan(const char* chan);
177 void LoadAllModules();
180 void OpenLog(char** argv, int argc);
182 bool UserToPseudo(userrec* user, const std::string &message);
183 bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
185 void ServerNoticeAll(char* text, ...);
186 void ServerPrivmsgAll(char* text, ...);
187 void WriteMode(const char* modes, int flags, const char* text, ...);
189 bool IsChannel(const char *chname);
191 static void Rehash(int status);
192 static void Exit(int status);
195 int registered_usercount();
196 int usercount_invisible();
197 int usercount_opers();
198 int usercount_unknown();
202 void SendError(const char *s);
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
212 long PriorityBefore(const std::string &modulename);
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
222 long PriorityAfter(const std::string &modulename);
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
238 bool PublishFeature(const std::string &FeatureName, Module* Mod);
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
245 bool UnpublishFeature(const std::string &FeatureName);
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.
259 Module* FindFeature(const std::string &FeatureName);
261 const std::string& GetModuleName(Module* m);
263 bool IsNick(const char* n);
264 bool IsIdent(const char* n);
266 userrec* FindDescriptor(int socket);
268 bool AddMode(ModeHandler* mh, const unsigned char modechar);
270 bool AddModeWatcher(ModeWatcher* mw);
272 bool DelModeWatcher(ModeWatcher* mw);
274 bool AddResolver(Resolver* r);
276 void AddCommand(command_t *f);
278 void SendMode(const char **parameters, int pcnt, userrec *user);
280 bool MatchText(const std::string &sliteral, const std::string &spattern);
282 bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
284 bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
286 bool IsUlined(const std::string &server);
288 void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
290 void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
292 void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
294 void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
296 void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
298 bool DelGLine(const std::string &hostmask);
300 bool DelQLine(const std::string &nickname);
302 bool DelZLine(const std::string &ipaddr);
304 bool DelKLine(const std::string &hostmask);
306 bool DelELine(const std::string &hostmask);
308 long CalcDuration(const std::string &duration);
310 bool IsValidMask(const std::string &mask);
312 void AddSocket(InspSocket* sock);
314 void RemoveSocket(InspSocket* sock);
316 void DelSocket(InspSocket* sock);
320 chanrec* GetChannelIndex(long index);
322 void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
324 std::string GetRevision();
325 std::string GetVersionString();
326 void WritePID(const std::string &filename);
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);