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 /* 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
44 #define IS_SINGLE(x,y) ( (*x == y) && (*(x+1) == 0) )
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!"); }
48 template<typename T> inline std::string ConvToStr(const T &in)
50 std::stringstream tmp;
51 if (!(tmp << in)) return std::string();
55 class serverstats : public classbase
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;
68 unsigned long BoundPortCount;
72 statsAccept = statsRefused = statsUnknown = 0;
73 statsCollisions = statsDns = statsDnsGood = 0;
74 statsDnsBad = statsConnects = 0;
75 statsSent = statsRecv = 0.0;
81 class InspIRCd : public classbase
86 servernamelist servernames;
88 void EraseFactory(int j);
89 void EraseModule(int j);
91 void MoveTo(std::string modulename,int slot);
93 void SetSignals(bool SEGVHandler);
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);
101 void ProcessUser(userrec* cu);
102 void DoSocketTimeouts(time_t TIME);
103 void DoBackgroundUserStuff(time_t TIME);
105 bool AllModulesReportReady(userrec* user);
108 char LogFileName[MAXBUF];
110 featurelist Features;
117 ModeParser* ModeGrok;
118 CommandParser* Parser;
121 ServerConfig* Config;
122 std::vector<InspSocket*> module_sockets;
123 InspSocket* socket_ref[MAX_DESCRIPTORS]; /* XXX: This should probably be made private, with inline accessors */
124 userrec* fd_ref_table[MAX_DESCRIPTORS]; /* XXX: Ditto */
125 user_hash clientlist;
127 std::vector<userrec*> local_users;
128 std::vector<userrec*> all_opers;
130 TimerManager* Timers;
131 command_table cmdlist;
138 int GetModuleCount();
140 Module* FindModule(const std::string &name);
142 int BindPorts(bool bail);
143 bool HasPort(int port, char* addr);
144 bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
146 void AddServerName(const std::string &servername);
147 const char* FindServerNamePtr(const std::string &servername);
148 bool FindServerName(const std::string &servername);
150 std::string GetServerDescription(const char* servername);
152 void WriteOpers(const char* text, ...);
153 void WriteOpers(const std::string &text);
155 userrec* FindNick(const std::string &nick);
156 userrec* FindNick(const char* nick);
158 chanrec* FindChan(const std::string &chan);
159 chanrec* FindChan(const char* chan);
161 void LoadAllModules();
164 void OpenLog(char** argv, int argc);
166 bool UserToPseudo(userrec* user, const std::string &message);
167 bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
169 void ServerNoticeAll(char* text, ...);
170 void ServerPrivmsgAll(char* text, ...);
171 void WriteMode(const char* modes, int flags, const char* text, ...);
173 bool IsChannel(const char *chname);
175 static void Error(int status);
176 static void Rehash(int status);
177 static void Exit(int status);
180 int registered_usercount();
181 int usercount_invisible();
182 int usercount_opers();
183 int usercount_unknown();
187 void SendError(const char *s);
189 /** For use with Module::Prioritize().
190 * When the return value of this function is returned from
191 * Module::Prioritize(), this specifies that the module wishes
192 * to be ordered exactly BEFORE 'modulename'. For more information
193 * please see Module::Prioritize().
194 * @param modulename The module your module wants to be before in the call list
195 * @returns a priority ID which the core uses to relocate the module in the list
197 long PriorityBefore(const std::string &modulename);
199 /** For use with Module::Prioritize().
200 * When the return value of this function is returned from
201 * Module::Prioritize(), this specifies that the module wishes
202 * to be ordered exactly AFTER 'modulename'. For more information please
203 * see Module::Prioritize().
204 * @param modulename The module your module wants to be after in the call list
205 * @returns a priority ID which the core uses to relocate the module in the list
207 long PriorityAfter(const std::string &modulename);
209 /** Publish a 'feature'.
210 * There are two ways for a module to find another module it depends on.
211 * Either by name, using InspIRCd::FindModule, or by feature, using this
212 * function. A feature is an arbitary string which identifies something this
213 * module can do. For example, if your module provides SSL support, but other
214 * modules provide SSL support too, all the modules supporting SSL should
215 * publish an identical 'SSL' feature. This way, any module requiring use
216 * of SSL functions can just look up the 'SSL' feature using FindFeature,
217 * then use the module pointer they are given.
218 * @param FeatureName The case sensitive feature name to make available
219 * @param Mod a pointer to your module class
220 * @returns True on success, false if the feature is already published by
223 bool PublishFeature(const std::string &FeatureName, Module* Mod);
225 /** Unpublish a 'feature'.
226 * When your module exits, it must call this method for every feature it
227 * is providing so that the feature table is cleaned up.
228 * @param FeatureName the feature to remove
230 bool UnpublishFeature(const std::string &FeatureName);
232 /** Find a 'feature'.
233 * There are two ways for a module to find another module it depends on.
234 * Either by name, using InspIRCd::FindModule, or by feature, using the
235 * InspIRCd::PublishFeature method. A feature is an arbitary string which
236 * identifies something this module can do. For example, if your module
237 * provides SSL support, but other modules provide SSL support too, all
238 * the modules supporting SSL should publish an identical 'SSL' feature.
239 * To find a module capable of providing the feature you want, simply
240 * call this method with the feature name you are looking for.
241 * @param FeatureName The feature name you wish to obtain the module for
242 * @returns A pointer to a valid module class on success, NULL on failure.
244 Module* FindFeature(const std::string &FeatureName);
246 const std::string& GetModuleName(Module* m);
248 bool IsNick(const char* n);
249 bool IsIdent(const char* n);
251 userrec* FindDescriptor(int socket);
253 bool AddMode(ModeHandler* mh, const unsigned char modechar);
255 bool AddModeWatcher(ModeWatcher* mw);
257 bool DelModeWatcher(ModeWatcher* mw);
259 bool AddResolver(Resolver* r);
261 void AddCommand(command_t *f);
263 void SendMode(const char **parameters, int pcnt, userrec *user);
265 bool MatchText(const std::string &sliteral, const std::string &spattern);
267 bool CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user);
269 bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
271 bool IsUlined(const std::string &server);
273 void AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
275 void AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname);
277 void AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr);
279 void AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
281 void AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask);
283 bool DelGLine(const std::string &hostmask);
285 bool DelQLine(const std::string &nickname);
287 bool DelZLine(const std::string &ipaddr);
289 bool DelKLine(const std::string &hostmask);
291 bool DelELine(const std::string &hostmask);
293 long CalcDuration(const std::string &duration);
295 bool IsValidMask(const std::string &mask);
297 void AddSocket(InspSocket* sock);
299 void RemoveSocket(InspSocket* sock);
301 void DelSocket(InspSocket* sock);
305 chanrec* GetChannelIndex(long index);
307 void DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream);
309 std::string GetRevision();
310 std::string GetVersionString();
311 void WritePID(const std::string &filename);
313 bool LoadModule(const char* filename);
314 bool UnloadModule(const char* filename);
315 InspIRCd(int argc, char** argv);
316 void DoOneIteration(bool process_module_sockets);
317 static void Log(int level, const char* text, ...);
318 static void Log(int level, const std::string &text);