The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

modules.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *          the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #ifndef __MODULES_H
00015 #define __MODULES_H
00016 
00017 #include "dynamic.h"
00018 #include "base.h"
00019 #include "ctables.h"
00020 #include "inspsocket.h"
00021 #include <string>
00022 #include <deque>
00023 #include <sstream>
00024 #include "timer.h"
00025 #include "mode.h"
00026 #include "dns.h"
00027 
00028 class XLine;
00029 
00032 enum AccessControlType {
00033         ACR_DEFAULT,            // Do default action (act as if the module isnt even loaded)
00034         ACR_DENY,               // deny the action
00035         ACR_ALLOW,              // allow the action
00036         AC_KICK,                // a user is being kicked
00037         AC_DEOP,                // a user is being deopped
00038         AC_OP,                  // a user is being opped
00039         AC_VOICE,               // a user is being voiced
00040         AC_DEVOICE,             // a user is being devoiced
00041         AC_HALFOP,              // a user is being halfopped
00042         AC_DEHALFOP,            // a user is being dehalfopped
00043         AC_INVITE,              // a user is being invited
00044         AC_GENERAL_MODE         // a channel mode is being changed
00045 };
00046 
00049 enum ModuleFlags {
00050         VF_STATIC = 1,          // module is static, cannot be /unloadmodule'd
00051         VF_VENDOR = 2,          // module is a vendor module (came in the original tarball, not 3rd party)
00052         VF_SERVICEPROVIDER = 4, // module provides a service to other modules (can be a dependency)
00053         VF_COMMON = 8           // module needs to be common on all servers in a network to link
00054 };
00055 
00058 enum WriteModeFlags {
00059         WM_AND = 1,
00060         WM_OR = 2
00061 };
00062 
00065 enum TargetTypeFlags {
00066         TYPE_USER = 1,
00067         TYPE_CHANNEL,
00068         TYPE_SERVER,
00069         TYPE_OTHER
00070 };
00071 
00074 enum MessageType {
00075         MSG_PRIVMSG = 0,
00076         MSG_NOTICE = 1
00077 };
00078 
00085 #define NATIVE_API_VERSION 12000
00086 #ifdef IPV6
00087 #define API_VERSION (NATIVE_API_VERSION * 10)
00088 #else
00089 #define API_VERSION (NATIVE_API_VERSION * 1)
00090 #endif
00091 
00092 class ServerConfig;
00093 
00094 /* Forward-delacare module for ModuleMessage etc
00095  */
00096 class Module;
00097 class InspIRCd;
00098 
00102 typedef std::deque<std::string> file_cache;
00103 
00106 typedef file_cache string_list;
00107 
00110 typedef std::map<std::string,Module*> featurelist;
00111 
00114 typedef std::deque<Module*> modulelist;
00115 
00118 typedef std::map<std::string, std::pair<int, modulelist> > interfacelist;
00119 
00125 #define FOREACH_MOD(y,x) do { \
00126         EventHandlerIter safei; \
00127         for (EventHandlerIter _i = ServerInstance->Modules->EventHandlers[y].begin(); _i != ServerInstance->Modules->EventHandlers[y].end(); ) \
00128         { \
00129                 safei = _i; \
00130                 ++safei; \
00131                 try \
00132                 { \
00133                         (*_i)->x ; \
00134                 } \
00135                 catch (CoreException& modexcept) \
00136                 { \
00137                         ServerInstance->Logs->Log("MODULE",DEFAULT,"Exception caught: %s",modexcept.GetReason()); \
00138                 } \
00139                 _i = safei; \
00140         } \
00141 } while (0);
00142 
00149 #define FOREACH_MOD_I(z,y,x) do { \
00150         EventHandlerIter safei; \
00151         for (EventHandlerIter _i = z->Modules->EventHandlers[y].begin(); _i != z->Modules->EventHandlers[y].end(); ) \
00152         { \
00153                 safei = _i; \
00154                 ++safei; \
00155                 try \
00156                 { \
00157                         (*_i)->x ; \
00158                 } \
00159                 catch (CoreException& modexcept) \
00160                 { \
00161                         z->Logs->Log("MODULE",DEFAULT,"Exception caught: %s",modexcept.GetReason()); \
00162                 } \
00163                 _i = safei; \
00164         } \
00165 } while (0);
00166 
00172 #define FOREACH_RESULT(y,x) \
00173 do { \
00174         EventHandlerIter safei; \
00175         MOD_RESULT = 0; \
00176         for (EventHandlerIter _i = ServerInstance->Modules->EventHandlers[y].begin(); _i != ServerInstance->Modules->EventHandlers[y].end(); ) \
00177         { \
00178                 safei = _i; \
00179                 ++safei; \
00180                 try \
00181                 { \
00182                         int res = (*_i)->x ; \
00183                         if (res != 0) { \
00184                                 MOD_RESULT = res; \
00185                                 break; \
00186                         } \
00187                 } \
00188                 catch (CoreException& modexcept) \
00189                 { \
00190                         ServerInstance->Logs->Log("MODULE",DEFAULT,"Exception caught: %s",modexcept.GetReason()); \
00191                 } \
00192                 _i = safei; \
00193         } \
00194 } while(0);
00195 
00196 
00202 #define FOREACH_RESULT_I(z,y,x) \
00203 do { \
00204         EventHandlerIter safei; \
00205         MOD_RESULT = 0; \
00206         for (EventHandlerIter _i = z->Modules->EventHandlers[y].begin(); _i != z->Modules->EventHandlers[y].end(); ) \
00207         { \
00208                 safei = _i; \
00209                 ++safei; \
00210                 try \
00211                 { \
00212                         int res = (*_i)->x ; \
00213                         if (res != 0) { \
00214                                 MOD_RESULT = res; \
00215                                 break; \
00216                         } \
00217                 } \
00218                 catch (CoreException& modexcept) \
00219                 { \
00220                         z->Logs->Log("MODULE",DEBUG,"Exception caught: %s",modexcept.GetReason()); \
00221                 } \
00222                 _i = safei; \
00223         } \
00224 } while (0);
00225 
00229 #define FD_MAGIC_NUMBER -42
00230 
00231 /* Useful macros */
00232 
00234 #define IS_LOCAL(x) ((x->GetFd() > -1))
00235 
00236 #define IS_REMOTE(x) (x->GetFd() < 0)
00237 
00238 #define IS_MODULE_CREATED(x) (x->GetFd() == FD_MAGIC_NUMBER)
00239 
00240 #define IS_OPER(x) (!x->oper.empty())
00241 
00242 #define IS_AWAY(x) (!x->awaymsg.empty())
00243 
00251 class CoreExport Version : public classbase
00252 {
00253  public:
00256         std::string version;
00257 
00260         const int Flags, API;
00261 
00264         Version(const std::string &sversion, int flags, int api_ver);
00265 };
00266 
00271 class CoreExport ModuleMessage : public Extensible
00272 {
00273  public:
00276         virtual ~ModuleMessage() {};
00277 };
00278 
00284 class CoreExport Request : public ModuleMessage
00285 {
00286  protected:
00289         char* data;
00294         const char* id;
00298         Module* source;
00301         Module* dest;
00302  public:
00308         Request(char* anydata, Module* src, Module* dst);
00319         Request(Module* src, Module* dst, const char* idstr);
00322         char* GetData();
00325         const char* GetId();
00328         Module* GetSource();
00331         Module* GetDest();
00337         const char* Send();
00338 };
00339 
00340 
00346 class CoreExport Event : public ModuleMessage
00347 {
00348  protected:
00351         char* data;
00355         Module* source;
00360         std::string id;
00361  public:
00364         Event(char* anydata, Module* src, const std::string &eventid);
00367         char* GetData();
00370         Module* GetSource();
00374         std::string GetEventID();
00379         char* Send(InspIRCd* ServerInstance);
00380 };
00381 
00384 enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER };
00385 
00388 enum Implementation
00389 {
00390         I_BEGIN,
00391         I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnRehash, I_OnServerRaw, I_OnSendSnotice,
00392         I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnWhois, I_OnUserPreInvite,
00393         I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreNick, I_OnUserMessage, I_OnUserNotice, I_OnMode,
00394         I_OnGetServerDescription, I_OnSyncUser, I_OnSyncChannel, I_OnSyncChannelMetaData, I_OnSyncUserMetaData,
00395         I_OnDecodeMetaData, I_ProtoSendMode, I_ProtoSendMetaData, I_OnWallops, I_OnChangeHost, I_OnChangeName, I_OnAddLine,
00396         I_OnDelLine, I_OnExpireLine, I_OnCleanup, I_OnUserPostNick, I_OnAccessCheck, I_On005Numeric, I_OnKill, I_OnRemoteKill, I_OnLoadModule, I_OnUnloadModule,
00397         I_OnBackgroundTimer, I_OnPreCommand, I_OnCheckReady, I_OnCheckInvite, I_OnRawMode,
00398         I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnCheckExtBan, I_OnCheckStringExtBan, I_OnStats, I_OnChangeLocalUserHost, I_OnChangeLocalUserGecos, 
00399         I_OnLocalTopicChange, I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan, I_OnDelBan,
00400         I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
00401         I_OnChannelPreDelete, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnUserList,
00402         I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect, I_OnBufferFlushed,
00403         I_OnText, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric, I_OnHookUserIO, I_OnHostCycle,
00404         I_END
00405 };
00406 
00407 class ConfigReader;
00408 
00414 class CoreExport Module : public Extensible
00415 {
00416  protected:
00419         InspIRCd* ServerInstance;
00420  public:
00421 
00427         Module(InspIRCd* Me);
00428 
00432         virtual ~Module();
00433 
00434         virtual void Prioritize()
00435         {
00436         }
00437 
00442         virtual Version GetVersion();
00443 
00448         virtual void OnUserConnect(User* user);
00449 
00458         virtual void OnUserQuit(User* user, const std::string &message, const std::string &oper_message);
00459 
00466         virtual void OnUserDisconnect(User* user);
00467 
00472         virtual int OnChannelPreDelete(Channel *chan);
00473 
00477         virtual void OnChannelDelete(Channel* chan);
00478 
00489         virtual void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent);
00490 
00497         virtual void OnPostJoin(User* user, Channel* channel);
00498 
00508         virtual void OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent);
00509 
00519         virtual void OnRehash(User* user, const std::string &parameter);
00520 
00532         virtual void OnServerRaw(std::string &raw, bool inbound, User* user);
00533 
00541         virtual int OnSendSnotice(char &snomask, std::string &type, const std::string &message);
00542 
00563         virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven);
00564         
00575         virtual int OnUserPreKick(User* source, User* user, Channel* chan, const std::string &reason);
00576 
00587         virtual void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent);
00588 
00595         virtual void OnOper(User* user, const std::string &opertype);
00596 
00605         virtual void OnPostOper(User* user, const std::string &opername, const std::string &opertype);
00606         
00617         virtual void OnInfo(User* user);
00618         
00625         virtual void OnWhois(User* source, User* dest);
00626         
00637         virtual int OnUserPreInvite(User* source,User* dest,Channel* channel, time_t timeout);
00638         
00647         virtual void OnUserInvite(User* source,User* dest,Channel* channel, time_t timeout);
00648         
00665         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list);
00666 
00686         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list);
00687 
00697         virtual void OnBuildExemptList(MessageType message_type, Channel* chan, User* sender, char status, CUList &exempt_list, const std::string &text);
00698         
00709         virtual int OnUserPreNick(User* user, const std::string &newnick);
00710 
00720         virtual void OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list);
00721 
00731         virtual void OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list);
00732 
00745         virtual void OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list);
00746 
00756         virtual void OnMode(User* user, void* dest, int target_type, const std::string &text);
00757 
00766         virtual void OnGetServerDescription(const std::string &servername,std::string &description);
00767 
00780         virtual void OnSyncUser(User* user, Module* proto, void* opaque);
00781 
00797         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque);
00798 
00799         /* Allows modules to syncronize metadata related to channels over the network during a netburst.
00800          * Whenever the linking module wants to send out data, but doesnt know what the data
00801          * represents (e.g. it is Extensible metadata, added to a User or Channel by a module) then
00802          * this method is called.You should use the ProtoSendMetaData function after you've
00803          * correctly decided how the data should be represented, to send the metadata on its way if it belongs
00804          * to your module. For a good example of how to use this method, see src/modules/m_swhois.cpp.
00805          * @param chan The channel whos metadata is being syncronized
00806          * @param proto A pointer to the module handling network protocol
00807          * @param opaque An opaque pointer set by the protocol module, should not be modified!
00808          * @param extname The extensions name which is being searched for
00809          * @param displayable If this value is true, the data is going to be displayed to a user,
00810          * and not sent across the network. Use this to determine wether or not to show sensitive data.
00811          */
00812         virtual void OnSyncChannelMetaData(Channel* chan, Module* proto,void* opaque, const std::string &extname, bool displayable = false);
00813 
00814         /* Allows modules to syncronize metadata related to users over the network during a netburst.
00815          * Whenever the linking module wants to send out data, but doesnt know what the data
00816          * represents (e.g. it is Extensible metadata, added to a User or Channel by a module) then
00817          * this method is called. You should use the ProtoSendMetaData function after you've
00818          * correctly decided how the data should be represented, to send the metadata on its way if
00819          * if it belongs to your module.
00820          * @param user The user whos metadata is being syncronized
00821          * @param proto A pointer to the module handling network protocol
00822          * @param opaque An opaque pointer set by the protocol module, should not be modified!
00823          * @param extname The extensions name which is being searched for
00824          * @param displayable If this value is true, the data is going to be displayed to a user,
00825          * and not sent across the network. Use this to determine wether or not to show sensitive data.
00826          */
00827         virtual void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable = false);
00828 
00829         /* Allows modules to syncronize metadata not related to users or channels, over the network during a netburst.
00830          * Whenever the linking module wants to send out data, but doesnt know what the data
00831          * represents (e.g. it is Extensible metadata, added to a User or Channel by a module) then
00832          * this method is called. You should use the ProtoSendMetaData function after you've
00833          * correctly decided how the data should be represented, to send the metadata on its way if
00834          * if it belongs to your module.
00835          * @param proto A pointer to the module handling network protocol
00836          * @param opaque An opaque pointer set by the protocol module, should not be modified!
00837          * @param displayable If this value is true, the data is going to be displayed to a user,
00838          * and not sent across the network. Use this to determine wether or not to show sensitive data.
00839          */
00840         virtual void OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable = false);
00841 
00849         virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata);
00850 
00864         virtual void ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline);
00865 
00880         virtual void ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata);
00881         
00886         virtual void OnWallops(User* user, const std::string &text);
00887 
00893         virtual void OnChangeHost(User* user, const std::string &newhost);
00894 
00900         virtual void OnChangeName(User* user, const std::string &gecos);
00901 
00907         virtual void OnAddLine(User* source, XLine* line);
00908 
00914         virtual void OnDelLine(User* source, XLine* line);
00915 
00920         virtual void OnExpireLine(XLine *line);
00921 
00931         virtual void OnCleanup(int target_type, void* item);
00932 
00942         virtual void OnUserPostNick(User* user, const std::string &oldnick);
00943 
00969         virtual int OnAccessCheck(User* source,User* dest,Channel* channel,int access_type);
00970 
00975         virtual void On005Numeric(std::string &output);
00976 
00990         virtual int OnKill(User* source, User* dest, const std::string &reason);
00991 
00997         virtual void OnRemoteKill(User* source, User* dest, const std::string &reason, const std::string &operreason);
00998 
01011         virtual void OnLoadModule(Module* mod,const std::string &name);
01012 
01025         virtual void OnUnloadModule(Module* mod,const std::string &name);
01026 
01033         virtual void OnBackgroundTimer(time_t curtime);
01034 
01053         virtual int OnPreCommand(std::string &command, std::vector<std::string>& parameters, User *user, bool validated, const std::string &original_line);
01054 
01067         virtual void OnPostCommand(const std::string &command, const std::vector<std::string>& parameters, User *user, CmdResult result, const std::string &original_line);
01068 
01079         virtual bool OnCheckReady(User* user);
01080 
01090         virtual int OnUserRegister(User* user);
01091 
01100         virtual int OnCheckInvite(User* user, Channel* chan);
01101 
01114         virtual int OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt, bool servermode = true);
01115 
01125         virtual int OnCheckKey(User* user, Channel* chan, const std::string &keygiven);
01126 
01135         virtual int OnCheckLimit(User* user, Channel* chan);
01136 
01146         virtual int OnCheckBan(User* user, Channel* chan);
01147 
01148         /* Called whenever checking whether or not a user is matched by an applicable extended bantype.
01149          * NOTE: may also trigger extra OnCheckStringExtBan events!
01150          * @param u The user to check
01151          * @param c The channel the user is on
01152          * @param type The type of extended ban to check for.
01153          */
01154         virtual int OnCheckExtBan(User *u, Channel *c, char type);
01155 
01159         virtual int OnCheckStringExtBan(const std::string &s, Channel *c, char type);
01160 
01170         virtual int OnStats(char symbol, User* user, string_list &results);
01171 
01178         virtual int OnChangeLocalUserHost(User* user, const std::string &newhost);
01179 
01186         virtual int OnChangeLocalUserGECOS(User* user, const std::string &newhost); 
01187 
01195         virtual int OnLocalTopicChange(User* user, Channel* chan, const std::string &topic);
01196 
01203         virtual void OnPostLocalTopicChange(User* user, Channel* chan, const std::string &topic);
01204 
01211         virtual void OnEvent(Event* event);
01212 
01220         virtual const char* OnRequest(Request* request);
01221 
01232         virtual int OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype);
01233 
01240         virtual void OnGlobalOper(User* user);
01241 
01248         virtual void OnPostConnect(User* user);
01249 
01257         virtual int OnAddBan(User* source, Channel* channel,const std::string &banmask);
01258 
01266         virtual int OnDelBan(User* source, Channel* channel,const std::string &banmask);
01267 
01268         virtual void OnHookUserIO(User* user, const std::string &targetip);
01269 
01279         virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport);
01280 
01291         virtual int OnRawSocketWrite(int fd, const char* buffer, int count);
01292 
01297         virtual void OnRawSocketClose(int fd);
01298 
01303         virtual void OnRawSocketConnect(int fd);
01304 
01320         virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult);
01321 
01330         virtual int OnSetAway(User* user, const std::string &awaymsg);
01331 
01345         virtual int OnUserList(User* user, Channel* Ptr, CUList* &userlist);
01346 
01358         virtual int OnWhoisLine(User* user, User* dest, int &numeric, std::string &text);
01359 
01365         virtual void OnGarbageCollect();
01366 
01374         virtual void OnBufferFlushed(User* user);
01375 
01379         virtual void OnRunTestSuite();
01380 
01385         virtual void OnNamesListItem(User* issuer, User* user, Channel* channel, std::string &prefixes, std::string &nick);
01386 
01387         virtual int OnNumeric(User* user, unsigned int numeric, const std::string &text);
01388 
01393         virtual bool OnHostCycle(User* user);
01394 };
01395 
01396 
01397 #define CONF_NO_ERROR           0x000000
01398 #define CONF_NOT_A_NUMBER       0x000010
01399 #define CONF_INT_NEGATIVE       0x000080
01400 #define CONF_VALUE_NOT_FOUND    0x000100
01401 #define CONF_FILE_NOT_FOUND     0x000200
01402 
01403 
01410 class CoreExport ConfigReader : public classbase
01411 {
01412   protected:
01413         InspIRCd* ServerInstance;
01419         ConfigDataHash* data;
01422         std::ostringstream* errorlog;
01425         bool privatehash;
01428         bool readerror;
01431         long error;
01432         
01433   public:
01438         ConfigReader(InspIRCd* Instance);
01442         ConfigReader(InspIRCd* Instance, const std::string &filename);
01446         ~ConfigReader();
01447 
01452         std::string ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds = false);
01458         std::string ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds = false);
01459 
01465         bool ReadFlag(const std::string &tag, const std::string &name, int index);
01472         bool ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index);
01473 
01483         int ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive);
01492         int ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive);
01493 
01498         long GetError();
01505         int Enumerate(const std::string &tag);
01510         bool Verify();
01517         void DumpErrors(bool bail,User* user);
01518 
01524         int EnumerateValues(const std::string &tag, int index);
01525 };
01526 
01527 
01528 
01534 class CoreExport FileReader : public classbase
01535 {
01536         InspIRCd* ServerInstance;
01539         file_cache fc;
01540 
01543         unsigned long contentsize;
01544 
01547         void CalcSize();
01548 
01549  public:
01554         FileReader(InspIRCd* Instance);
01555 
01561         FileReader(InspIRCd* Instance, const std::string &filename);
01562 
01566         ~FileReader();
01567 
01573         void LoadFile(const std::string &filename);
01574 
01577         std::string Contents();
01578 
01581         unsigned long ContentSize();
01582 
01586         bool Exists();
01587  
01592         std::string GetLine(int x);
01593 
01599         int FileSize();
01600 };
01601 
01608 typedef DLLFactory<Module> ircd_module;
01609 
01612 typedef std::vector<Module*> IntModuleList;
01613 
01616 typedef IntModuleList::iterator EventHandlerIter;
01617 
01620 enum PriorityState
01621 {
01622         PRIO_DONTCARE,
01623         PRIO_FIRST,
01624         PRIO_LAST,
01625         PRIO_AFTER,
01626         PRIO_BEFORE
01627 };
01628 
01632 class CoreExport ModuleManager : public classbase
01633 {
01634  private:
01637         std::string LastModuleError;
01638  
01641         featurelist Features;
01642 
01645         interfacelist Interfaces;
01646  
01649         int ModCount; 
01650         
01653         InspIRCd* Instance;
01654 
01658         std::map<std::string, std::pair<ircd_module*, Module*> > Modules;
01659 
01660  public:
01661 
01665         IntModuleList EventHandlers[I_END];
01666 
01669         ModuleManager(InspIRCd* Ins);
01670 
01673         ~ModuleManager(); 
01674 
01696         bool SetPriority(Module* mod, Implementation i, PriorityState s, Module** modules = NULL, size_t sz = 1);
01697 
01706         bool SetPriority(Module* mod, PriorityState s);
01707 
01715         bool Attach(Implementation i, Module* mod);
01716 
01724         bool Detach(Implementation i, Module* mod);
01725 
01730         void Attach(Implementation* i, Module* mod, size_t sz);
01731 
01735         void DetachAll(Module* mod);
01736  
01740         std::string& LastError();
01741 
01746         bool Load(const char* filename);
01747 
01752         bool Unload(const char* filename);
01753         
01756         void LoadAll();
01757         
01761         int GetCount()
01762         {
01763                 return this->ModCount;
01764         }
01765         
01771         Module* Find(const std::string &name);
01772  
01787         bool PublishFeature(const std::string &FeatureName, Module* Mod);
01788 
01803         bool PublishInterface(const std::string &InterfaceName, Module* Mod);
01804 
01811         std::pair<int,std::string> GetInterfaceInstanceCount(Module* m);
01812 
01820         void UseInterface(const std::string &InterfaceName);
01821 
01828         void DoneWithInterface(const std::string &InterfaceName);
01829 
01835         bool UnpublishFeature(const std::string &FeatureName);
01836 
01845         bool UnpublishInterface(const std::string &InterfaceName, Module* Mod);
01846 
01859         Module* FindFeature(const std::string &FeatureName);
01860 
01868         modulelist* FindInterface(const std::string &InterfaceName);
01869 
01876         bool ModuleHasInterface(Module* mod, const std::string& InterfaceName);
01877 
01882         const std::string& GetModuleName(Module* m);
01883 
01890         const std::vector<std::string> GetAllModuleNames(int filter);
01891 };
01892 
01897 #ifdef WINDOWS
01898 
01899 #define MODULE_INIT(y) \
01900         extern "C" DllExport Module * init_module(InspIRCd* Me) \
01901         { \
01902                 return new y(Me); \
01903         } \
01904         BOOLEAN WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) \
01905         { \
01906                 switch ( nReason ) \
01907                 { \
01908                         case DLL_PROCESS_ATTACH: \
01909                         case DLL_PROCESS_DETACH: \
01910                                 break; \
01911                 } \
01912                 return TRUE; \
01913         }
01914 
01915 #else
01916 
01917 #define MODULE_INIT(y) \
01918         extern "C" DllExport Module * init_module(InspIRCd* Me) \
01919         { \
01920                 return new y(Me); \
01921         }
01922 #endif
01923 
01924 #endif