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  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
00006  *                       E-mail:
00007  *                <brain@chatspike.net>
00008  *                <Craig@chatspike.net>
00009  *     
00010  * Written by Craig Edwards, Craig McLure, and others.
00011  * This program is free but copyrighted software; see
00012  *            the file COPYING for details.
00013  *
00014  * ---------------------------------------------------
00015  */
00016 
00017 
00018 #ifndef __PLUGIN_H
00019 #define __PLUGIN_H
00020 
00023 #define DEBUG 10
00024 #define VERBOSE 20
00025 #define DEFAULT 30
00026 #define SPARSE 40
00027 #define NONE 50
00028 
00031 #define MT_CHANNEL 1
00032 #define MT_CLIENT 2
00033 #define MT_SERVER 3
00034 
00037 #define ACR_DEFAULT 0           // Do default action (act as if the module isnt even loaded)
00038 #define ACR_DENY 1              // deny the action
00039 #define ACR_ALLOW 2             // allow the action
00040 #define AC_KICK 0               // a user is being kicked
00041 #define AC_DEOP 1               // a user is being deopped
00042 #define AC_OP 2                 // a user is being opped
00043 #define AC_VOICE 3              // a user is being voiced
00044 #define AC_DEVOICE 4            // a user is being devoiced
00045 #define AC_HALFOP 5             // a user is being halfopped
00046 #define AC_DEHALFOP 6           // a user is being dehalfopped
00047 #define AC_INVITE 7             // a user is being invited
00048 #define AC_GENERAL_MODE 8       // a user channel mode is being changed
00049 
00052 #define VF_STATIC               1       // module is static, cannot be /unloadmodule'd
00053 #define VF_VENDOR               2       // module is a vendor module (came in the original tarball, not 3rd party)
00054 #define VF_SERVICEPROVIDER      4       // module provides a service to other modules (can be a dependency)
00055 #define VF_COMMON               8       // module needs to be common on all servers in a mesh to link
00056 
00057 #include "dynamic.h"
00058 #include "base.h"
00059 #include "ctables.h"
00060 #include "socket.h"
00061 #include <string>
00062 #include <deque>
00063 #include <sstream>
00064 
00065 class Server;
00066 
00069 typedef std::deque<std::string> file_cache;
00070 typedef file_cache string_list;
00071 
00074 typedef std::deque<userrec*> chanuserlist;
00075 
00076 
00077 // This #define allows us to call a method in all
00078 // loaded modules in a readable simple way, e.g.:
00079 // 'FOREACH_MOD OnConnect(user);'
00080 
00081 #define FOREACH_MOD for (int _i = 0; _i <= MODCOUNT; _i++) modules[_i]->
00082 
00083 // This define is similar to the one above but returns a result in MOD_RESULT.
00084 // The first module to return a nonzero result is the value to be accepted,
00085 // and any modules after are ignored.
00086 
00087 // *********************************************************************************************
00088 
00089 #define FOREACH_RESULT(x) { MOD_RESULT = 0; \
00090                         for (int _i = 0; _i <= MODCOUNT; _i++) { \
00091                         int res = modules[_i]->x ; \
00092                         if (res != 0) { \
00093                                 MOD_RESULT = res; \
00094                                 break; \
00095                         } \
00096                 } \
00097         } 
00098    
00099 // *********************************************************************************************
00100 
00101 #define FD_MAGIC_NUMBER -42
00102 
00103 extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
00104 extern void server_mode(char **parameters, int pcnt, userrec *user);
00105 
00106 // class Version holds the version information of a Module, returned
00107 // by Module::GetVersion (thanks RD)
00108 
00113 class Version : public classbase
00114 {
00115  public:
00116          const int Major, Minor, Revision, Build, Flags;
00117          Version(int major, int minor, int revision, int build, int flags);
00118 };
00119 
00125 class Admin : public classbase
00126 {
00127  public:
00128          const std::string Name, Email, Nick;
00129          Admin(std::string name, std::string email, std::string nick);
00130 };
00131 
00132 
00133 // Forward-delacare module for ModuleMessage etc
00134 class Module;
00135 
00136 // Thanks to Rob (from anope) for the idea of this message passing API
00137 // (its been done before, but this seemed a very neat and tidy way...
00138 
00143 class ModuleMessage : public classbase
00144 {
00145  public:
00148         virtual char* Send() = 0;
00149         virtual ~ModuleMessage() {};
00150 };
00151 
00157 class Request : public ModuleMessage
00158 {
00159  protected:
00162         char* data;
00166         Module* source;
00169         Module* dest;
00170  public:
00173         Request(char* anydata, Module* src, Module* dst);
00176         char* GetData();
00179         Module* GetSource();
00182         Module* GetDest();
00188         char* Send();
00189 };
00190 
00191 
00197 class Event : public ModuleMessage
00198 {
00199  protected:
00202         char* data;
00206         Module* source;
00211         std::string id;
00212  public:
00215         Event(char* anydata, Module* src, std::string eventid);
00218         char* GetData();
00221         Module* GetSource();
00225         std::string GetEventID();
00230         char* Send();
00231 };
00232 
00236 class ExtMode : public classbase
00237 {
00238  public:
00239         char modechar;
00240         int type;
00241         bool needsoper;
00242         int params_when_on;
00243         int params_when_off;
00244         bool list;
00245         ExtMode(char mc, int ty, bool oper, int p_on, int p_off) : modechar(mc), type(ty), needsoper(oper), params_when_on(p_on), params_when_off(p_off) { };
00246 };
00247 
00248 
00254 class Module : public classbase
00255 {
00256  public:
00257 
00262         Module(Server* Me);
00263 
00267         virtual ~Module();
00268 
00273         virtual Version GetVersion();
00274 
00279         virtual void OnUserConnect(userrec* user);
00280 
00288         virtual void OnUserQuit(userrec* user, std::string message);
00289 
00296         virtual void OnUserDisconnect(userrec* user);
00297 
00304         virtual void OnUserJoin(userrec* user, chanrec* channel);
00305 
00312         virtual void OnUserPart(userrec* user, chanrec* channel);
00313 
00321         virtual void OnRehash(std::string parameter);
00322 
00334         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user);
00335 
00351         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params);
00352         
00369         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
00370         
00381         virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason);
00382 
00391         virtual void OnUserKick(userrec* source, userrec* user, chanrec* chan, std::string reason);
00392 
00399         virtual void OnOper(userrec* user, std::string opertype);
00400         
00411         virtual void OnInfo(userrec* user);
00412         
00419         virtual void OnWhois(userrec* source, userrec* dest);
00420         
00430         virtual int OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel);
00431         
00439         virtual void OnUserInvite(userrec* source,userrec* dest,chanrec* channel);
00440         
00454         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text);
00455 
00472         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text);
00473         
00484         virtual int OnUserPreNick(userrec* user, std::string newnick);
00485 
00494         virtual void OnUserMessage(userrec* user, void* dest, int target_type, std::string text);
00495 
00504         virtual void OnUserNotice(userrec* user, void* dest, int target_type, std::string text);
00505 
00515         virtual void OnMode(userrec* user, void* dest, int target_type, std::string text);
00516 
00525         virtual void OnGetServerDescription(std::string servername,std::string &description);
00526 
00539         virtual void OnSyncUser(userrec* user, Module* proto, void* opaque);
00540 
00556         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque);
00557 
00558         /* Allows modules to syncronize metadata related to channels over the network during a netburst.
00559          * Whenever the linking module wants to send out data, but doesnt know what the data
00560          * represents (e.g. it is Extensible metadata, added to a userrec or chanrec by a module) then
00561          * this method is called.You should use the ProtoSendMetaData function after you've
00562          * correctly decided how the data should be represented, to send the metadata on its way if it belongs
00563          * to your module. For a good example of how to use this method, see src/modules/m_swhois.cpp.
00564          * @param chan The channel whos metadata is being syncronized
00565          * @param proto A pointer to the module handling network protocol
00566          * @param opaque An opaque pointer set by the protocol module, should not be modified!
00567          * @param extname The extensions name which is being searched for
00568          */
00569         virtual void OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, std::string extname);
00570 
00571         /* Allows modules to syncronize metadata related to users over the network during a netburst.
00572          * Whenever the linking module wants to send out data, but doesnt know what the data
00573          * represents (e.g. it is Extensible metadata, added to a userrec or chanrec by a module) then
00574          * this method is called. You should use the ProtoSendMetaData function after you've
00575          * correctly decided how the data should be represented, to send the metadata on its way if
00576          * if it belongs to your module.
00577          * @param user The user whos metadata is being syncronized
00578          * @param proto A pointer to the module handling network protocol
00579          * @param opaque An opaque pointer set by the protocol module, should not be modified!
00580          * @param extname The extensions name which is being searched for
00581          */
00582         virtual void OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, std::string extname);
00583 
00591         virtual void OnDecodeMetaData(int target_type, void* target, std::string extname, std::string extdata);
00592 
00606         virtual void ProtoSendMode(void* opaque, int target_type, void* target, std::string modeline);
00607 
00622         virtual void ProtoSendMetaData(void* opaque, int target_type, void* target, std::string extname, std::string extdata);
00623         
00628         virtual void OnWallops(userrec* user, std::string text);
00629 
00635         virtual void OnChangeHost(userrec* user, std::string newhost);
00636 
00642         virtual void OnChangeName(userrec* user, std::string gecos);
00643 
00651         virtual void OnAddGLine(long duration, userrec* source, std::string reason, std::string hostmask);
00652 
00660         virtual void OnAddZLine(long duration, userrec* source, std::string reason, std::string ipmask);
00661 
00669         virtual void OnAddKLine(long duration, userrec* source, std::string reason, std::string hostmask);
00670 
00678         virtual void OnAddQLine(long duration, userrec* source, std::string reason, std::string nickmask);
00679 
00687         virtual void OnAddELine(long duration, userrec* source, std::string reason, std::string hostmask);
00688 
00694         virtual void OnDelGLine(userrec* source, std::string hostmask);
00695 
00701         virtual void OnDelZLine(userrec* source, std::string ipmask);
00702 
00708         virtual void OnDelKLine(userrec* source, std::string hostmask);
00709         
00715         virtual void OnDelQLine(userrec* source, std::string nickmask);
00716 
00722         virtual void OnDelELine(userrec* source, std::string hostmask);
00723 
00733         virtual void OnCleanup(int target_type, void* item);
00734 
00744         virtual void OnUserPostNick(userrec* user, std::string oldnick);
00745 
00771         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type);
00772 
00777         virtual void On005Numeric(std::string &output);
00778 
00792         virtual int OnKill(userrec* source, userrec* dest, std::string reason);
00793 
00799         virtual void OnRemoteKill(userrec* source, userrec* dest, std::string reason);
00800 
00813         virtual void OnLoadModule(Module* mod,std::string name);
00814 
00827         virtual void OnUnloadModule(Module* mod,std::string name);
00828 
00835         virtual void OnBackgroundTimer(time_t curtime);
00836 
00847         virtual void OnSendList(userrec* user, chanrec* channel, char mode);
00848 
00864         virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user);
00865 
00876         virtual bool OnCheckReady(userrec* user);
00877 
00886         virtual void OnUserRegister(userrec* user);
00887 
00900         virtual int OnRawMode(userrec* user, chanrec* chan, char mode, std::string param, bool adding, int pcnt);
00901 
00910         virtual int OnCheckInvite(userrec* user, chanrec* chan);
00911 
00921         virtual int OnCheckKey(userrec* user, chanrec* chan, std::string keygiven);
00922 
00931         virtual int OnCheckLimit(userrec* user, chanrec* chan);
00932 
00941         virtual int OnCheckBan(userrec* user, chanrec* chan);
00942 
00947         virtual void OnStats(char symbol);
00948 
00955         virtual int OnChangeLocalUserHost(userrec* user, std::string newhost);
00956 
00963         virtual int OnChangeLocalUserGECOS(userrec* user, std::string newhost); 
00964 
00972         virtual int OnLocalTopicChange(userrec* user, chanrec* chan, std::string topic);
00973 
00980         virtual void OnPostLocalTopicChange(userrec* user, chanrec* chan, std::string topic);
00981 
00988         virtual void OnEvent(Event* event);
00989 
00997         virtual char* OnRequest(Request* request);
00998 
01008         virtual int OnOperCompare(std::string password, std::string input);
01009 
01016         virtual void OnGlobalOper(userrec* user);
01017 
01023         virtual void OnGlobalConnect(userrec* user);
01024 
01032         virtual int OnAddBan(userrec* source, chanrec* channel,std::string banmask);
01033 
01041         virtual int OnDelBan(userrec* source, chanrec* channel,std::string banmask);
01042 
01052         virtual void OnRawSocketAccept(int fd, std::string ip, int localport);
01053 
01064         virtual int OnRawSocketWrite(int fd, char* buffer, int count);
01065 
01070         virtual void OnRawSocketClose(int fd);
01071 
01087         virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult);
01088 };
01089 
01090 
01096 class Server : public classbase
01097 {
01098  public:
01102         Server();
01106         virtual ~Server();
01111         ServerConfig* GetConfig();
01115         virtual void SendOpers(std::string s);
01120         virtual void Log(int level, std::string s);
01125         virtual void Send(int Socket, std::string s);
01130         virtual void SendServ(int Socket, std::string s);
01134         virtual void SendChannelServerNotice(std::string ServName, chanrec* Channel, std::string text);
01139         virtual void SendFrom(int Socket, userrec* User, std::string s);
01154         virtual void SendTo(userrec* Source, userrec* Dest, std::string s);
01161         virtual void SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender);
01166         virtual bool CommonChannels(userrec* u1, userrec* u2);
01174         virtual void SendCommon(userrec* User, std::string text,bool IncludeSender);
01179         virtual void SendWallops(userrec* User, std::string text);
01180 
01184         virtual bool IsNick(std::string nick);
01188         virtual int CountUsers(chanrec* c);
01192         virtual userrec* FindNick(std::string nick);
01196         virtual userrec* FindDescriptor(int socket);
01200         virtual chanrec* FindChannel(std::string channel);
01205         virtual std::string ChanMode(userrec* User, chanrec* Chan);
01209         virtual bool IsOnChannel(userrec* User, chanrec* Chan);
01212         virtual std::string GetServerName();
01215         virtual std::string GetNetworkName();
01218         virtual std::string GetServerDescription();
01224         virtual Admin GetAdmin();
01243         virtual bool AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off);
01244 
01266         virtual bool AddExtendedListMode(char modechar);
01267 
01285         virtual void AddCommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
01286          
01308         virtual void SendMode(char **parameters, int pcnt, userrec *user);
01309         
01322         virtual void SendToModeMask(std::string modes, int flags, std::string text);
01323 
01329         virtual chanrec* JoinUserToChannel(userrec* user, std::string cname, std::string key);
01330         
01336         virtual chanrec* PartUserFromChannel(userrec* user, std::string cname, std::string reason);
01337         
01343         virtual void ChangeUserNick(userrec* user, std::string nickname);
01344         
01355         virtual void QuitUser(userrec* user, std::string reason);
01356         
01361         virtual bool MatchText(std::string sliteral, std::string spattern);
01362         
01374         virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
01375 
01376         virtual bool IsValidModuleCommand(std::string commandname, int pcnt, userrec* user);
01377         
01383         virtual void ChangeHost(userrec* user, std::string host);
01384         
01390         virtual void ChangeGECOS(userrec* user, std::string gecos);
01391         
01400         virtual bool IsUlined(std::string server);
01401         
01405         virtual chanuserlist GetUsers(chanrec* chan);
01406 
01413         virtual bool UserToPseudo(userrec* user,std::string message);
01414 
01421         virtual bool PseudoToUser(userrec* alive,userrec* zombie,std::string message);
01422 
01430         virtual void AddGLine(long duration, std::string source, std::string reason, std::string hostmask);
01431 
01439         virtual void AddQLine(long duration, std::string source, std::string reason, std::string nickname);
01440 
01448         virtual void AddZLine(long duration, std::string source, std::string reason, std::string ipaddr);
01449 
01457         virtual void AddKLine(long duration, std::string source, std::string reason, std::string hostmask);
01458 
01466         virtual void AddELine(long duration, std::string source, std::string reason, std::string hostmask);
01467 
01470         virtual bool DelGLine(std::string hostmask);
01471 
01474         virtual bool DelQLine(std::string nickname);
01475 
01478         virtual bool DelZLine(std::string ipaddr);
01479 
01482         virtual bool DelKLine(std::string hostmask);
01483 
01486         virtual bool DelELine(std::string hostmask);
01487 
01493         virtual long CalcDuration(std::string duration);
01494 
01497         virtual bool IsValidMask(std::string mask);
01498 
01503         virtual Module* FindModule(std::string name);
01504 
01507         virtual void AddSocket(InspSocket* sock);
01508 
01511         virtual void DelSocket(InspSocket* sock);
01512 
01513         virtual void RehashServer();
01514 };
01515 
01516 
01517 #define CONF_NOT_A_NUMBER       0x000010
01518 #define CONF_NOT_UNSIGNED       0x000080
01519 #define CONF_VALUE_NOT_FOUND    0x000100
01520 #define CONF_FILE_NOT_FOUND     0x000200
01521 
01522 
01529 class ConfigReader : public classbase
01530 {
01531   protected:
01537         std::stringstream *cache;
01538         std::stringstream *errorlog;
01541         bool readerror;
01542         long error;
01543         
01544   public:
01549         ConfigReader();                 // default constructor reads ircd.conf
01553         ConfigReader(std::string filename);     // read a module-specific config
01557         ~ConfigReader();
01562         std::string ReadValue(std::string tag, std::string name, int index);
01568         bool ReadFlag(std::string tag, std::string name, int index);
01577         long ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned);
01582         long GetError();
01589         int Enumerate(std::string tag);
01594         bool Verify();
01601         void DumpErrors(bool bail,userrec* user);
01602 
01608         int EnumerateValues(std::string tag, int index);
01609 };
01610 
01611 
01612 
01618 class FileReader : public classbase
01619 {
01620  file_cache fc;
01621  public:
01626          FileReader();
01627 
01633          FileReader(std::string filename);
01634 
01638          ~FileReader();
01639 
01645          void LoadFile(std::string filename);
01646 
01650          bool Exists();
01651          
01656          std::string GetLine(int x);
01657 
01663          int FileSize();
01664 };
01665 
01666 
01673 class ModuleFactory : public classbase
01674 {
01675  public:
01676         ModuleFactory() { }
01677         virtual ~ModuleFactory() { }
01682         virtual Module * CreateModule(Server* Me) = 0;
01683 };
01684 
01685 
01686 typedef DLLFactory<ModuleFactory> ircd_module;
01687 
01688 #endif

Generated on Wed Dec 14 15:55:46 2005 for InspIRCd by  doxygen 1.4.4-20050815