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 class ServerConfig;
00067 
00070 typedef std::deque<std::string> file_cache;
00071 typedef file_cache string_list;
00072 
00075 typedef std::deque<userrec*> chanuserlist;
00076 
00077 
00078 // This #define allows us to call a method in all
00079 // loaded modules in a readable simple way, e.g.:
00080 // 'FOREACH_MOD OnConnect(user);'
00081 
00082 #define FOREACH_MOD for (int _i = 0; _i <= MODCOUNT; _i++) modules[_i]->
00083 
00084 // This define is similar to the one above but returns a result in MOD_RESULT.
00085 // The first module to return a nonzero result is the value to be accepted,
00086 // and any modules after are ignored.
00087 
00088 // *********************************************************************************************
00089 
00090 #define FOREACH_RESULT(x) { MOD_RESULT = 0; \
00091                         for (int _i = 0; _i <= MODCOUNT; _i++) { \
00092                         int res = modules[_i]->x ; \
00093                         if (res != 0) { \
00094                                 MOD_RESULT = res; \
00095                                 break; \
00096                         } \
00097                 } \
00098         } 
00099    
00100 // *********************************************************************************************
00101 
00102 #define FD_MAGIC_NUMBER -42
00103 
00104 // useful macros
00105 
00106 #define IS_LOCAL(x) (x->fd > -1)
00107 #define IS_REMOTE(x) (x->fd < 0)
00108 #define IS_MODULE_CREATED(x) (x->fd == FD_MAGIC_NUMBER)
00109 
00110 // flags for use with WriteMode
00111 
00112 #define WM_AND 1
00113 #define WM_OR 2
00114 
00115 // flags for use with OnUserPreMessage and OnUserPreNotice
00116 
00117 #define TYPE_USER 1
00118 #define TYPE_CHANNEL 2
00119 #define TYPE_SERVER 3
00120 
00121 /*extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
00122 extern void server_mode(char **parameters, int pcnt, userrec *user);*/
00123 
00124 // class Version holds the version information of a Module, returned
00125 // by Module::GetVersion (thanks RD)
00126 
00131 class Version : public classbase
00132 {
00133  public:
00134          const int Major, Minor, Revision, Build, Flags;
00135          Version(int major, int minor, int revision, int build, int flags);
00136 };
00137 
00143 class Admin : public classbase
00144 {
00145  public:
00146          const std::string Name, Email, Nick;
00147          Admin(std::string name, std::string email, std::string nick);
00148 };
00149 
00150 
00151 // Forward-delacare module for ModuleMessage etc
00152 class Module;
00153 
00154 // Thanks to Rob (from anope) for the idea of this message passing API
00155 // (its been done before, but this seemed a very neat and tidy way...
00156 
00161 class ModuleMessage : public classbase
00162 {
00163  public:
00166         virtual char* Send() = 0;
00167         virtual ~ModuleMessage() {};
00168 };
00169 
00175 class Request : public ModuleMessage
00176 {
00177  protected:
00180         char* data;
00184         Module* source;
00187         Module* dest;
00188  public:
00191         Request(char* anydata, Module* src, Module* dst);
00194         char* GetData();
00197         Module* GetSource();
00200         Module* GetDest();
00206         char* Send();
00207 };
00208 
00209 
00215 class Event : public ModuleMessage
00216 {
00217  protected:
00220         char* data;
00224         Module* source;
00229         std::string id;
00230  public:
00233         Event(char* anydata, Module* src, std::string eventid);
00236         char* GetData();
00239         Module* GetSource();
00243         std::string GetEventID();
00248         char* Send();
00249 };
00250 
00254 class ExtMode : public classbase
00255 {
00256  public:
00257         char modechar;
00258         int type;
00259         bool needsoper;
00260         int params_when_on;
00261         int params_when_off;
00262         bool list;
00263         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) { };
00264 };
00265 
00266 
00272 class Module : public classbase
00273 {
00274  public:
00275 
00280         Module(Server* Me);
00281 
00285         virtual ~Module();
00286 
00291         virtual Version GetVersion();
00292 
00297         virtual void OnUserConnect(userrec* user);
00298 
00306         virtual void OnUserQuit(userrec* user, std::string message);
00307 
00314         virtual void OnUserDisconnect(userrec* user);
00315 
00322         virtual void OnUserJoin(userrec* user, chanrec* channel);
00323 
00330         virtual void OnUserPart(userrec* user, chanrec* channel);
00331 
00339         virtual void OnRehash(std::string parameter);
00340 
00352         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user);
00353 
00369         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params);
00370         
00387         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
00388         
00399         virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason);
00400 
00409         virtual void OnUserKick(userrec* source, userrec* user, chanrec* chan, std::string reason);
00410 
00417         virtual void OnOper(userrec* user, std::string opertype);
00418         
00429         virtual void OnInfo(userrec* user);
00430         
00437         virtual void OnWhois(userrec* source, userrec* dest);
00438         
00448         virtual int OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel);
00449         
00457         virtual void OnUserInvite(userrec* source,userrec* dest,chanrec* channel);
00458         
00472         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text);
00473 
00490         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text);
00491         
00502         virtual int OnUserPreNick(userrec* user, std::string newnick);
00503 
00512         virtual void OnUserMessage(userrec* user, void* dest, int target_type, std::string text);
00513 
00522         virtual void OnUserNotice(userrec* user, void* dest, int target_type, std::string text);
00523 
00533         virtual void OnMode(userrec* user, void* dest, int target_type, std::string text);
00534 
00543         virtual void OnGetServerDescription(std::string servername,std::string &description);
00544 
00557         virtual void OnSyncUser(userrec* user, Module* proto, void* opaque);
00558 
00574         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque);
00575 
00576         /* Allows modules to syncronize metadata related to channels over the network during a netburst.
00577          * Whenever the linking module wants to send out data, but doesnt know what the data
00578          * represents (e.g. it is Extensible metadata, added to a userrec or chanrec by a module) then
00579          * this method is called.You should use the ProtoSendMetaData function after you've
00580          * correctly decided how the data should be represented, to send the metadata on its way if it belongs
00581          * to your module. For a good example of how to use this method, see src/modules/m_swhois.cpp.
00582          * @param chan The channel whos metadata is being syncronized
00583          * @param proto A pointer to the module handling network protocol
00584          * @param opaque An opaque pointer set by the protocol module, should not be modified!
00585          * @param extname The extensions name which is being searched for
00586          */
00587         virtual void OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, std::string extname);
00588 
00589         /* Allows modules to syncronize metadata related to users over the network during a netburst.
00590          * Whenever the linking module wants to send out data, but doesnt know what the data
00591          * represents (e.g. it is Extensible metadata, added to a userrec or chanrec by a module) then
00592          * this method is called. You should use the ProtoSendMetaData function after you've
00593          * correctly decided how the data should be represented, to send the metadata on its way if
00594          * if it belongs to your module.
00595          * @param user The user whos metadata is being syncronized
00596          * @param proto A pointer to the module handling network protocol
00597          * @param opaque An opaque pointer set by the protocol module, should not be modified!
00598          * @param extname The extensions name which is being searched for
00599          */
00600         virtual void OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, std::string extname);
00601 
00609         virtual void OnDecodeMetaData(int target_type, void* target, std::string extname, std::string extdata);
00610 
00624         virtual void ProtoSendMode(void* opaque, int target_type, void* target, std::string modeline);
00625 
00640         virtual void ProtoSendMetaData(void* opaque, int target_type, void* target, std::string extname, std::string extdata);
00641         
00646         virtual void OnWallops(userrec* user, std::string text);
00647 
00653         virtual void OnChangeHost(userrec* user, std::string newhost);
00654 
00660         virtual void OnChangeName(userrec* user, std::string gecos);
00661 
00669         virtual void OnAddGLine(long duration, userrec* source, std::string reason, std::string hostmask);
00670 
00678         virtual void OnAddZLine(long duration, userrec* source, std::string reason, std::string ipmask);
00679 
00687         virtual void OnAddKLine(long duration, userrec* source, std::string reason, std::string hostmask);
00688 
00696         virtual void OnAddQLine(long duration, userrec* source, std::string reason, std::string nickmask);
00697 
00705         virtual void OnAddELine(long duration, userrec* source, std::string reason, std::string hostmask);
00706 
00712         virtual void OnDelGLine(userrec* source, std::string hostmask);
00713 
00719         virtual void OnDelZLine(userrec* source, std::string ipmask);
00720 
00726         virtual void OnDelKLine(userrec* source, std::string hostmask);
00727         
00733         virtual void OnDelQLine(userrec* source, std::string nickmask);
00734 
00740         virtual void OnDelELine(userrec* source, std::string hostmask);
00741 
00751         virtual void OnCleanup(int target_type, void* item);
00752 
00762         virtual void OnUserPostNick(userrec* user, std::string oldnick);
00763 
00789         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type);
00790 
00795         virtual void On005Numeric(std::string &output);
00796 
00810         virtual int OnKill(userrec* source, userrec* dest, std::string reason);
00811 
00817         virtual void OnRemoteKill(userrec* source, userrec* dest, std::string reason);
00818 
00831         virtual void OnLoadModule(Module* mod,std::string name);
00832 
00845         virtual void OnUnloadModule(Module* mod,std::string name);
00846 
00853         virtual void OnBackgroundTimer(time_t curtime);
00854 
00865         virtual void OnSendList(userrec* user, chanrec* channel, char mode);
00866 
00882         virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user);
00883 
00894         virtual bool OnCheckReady(userrec* user);
00895 
00904         virtual void OnUserRegister(userrec* user);
00905 
00918         virtual int OnRawMode(userrec* user, chanrec* chan, char mode, std::string param, bool adding, int pcnt);
00919 
00928         virtual int OnCheckInvite(userrec* user, chanrec* chan);
00929 
00939         virtual int OnCheckKey(userrec* user, chanrec* chan, std::string keygiven);
00940 
00949         virtual int OnCheckLimit(userrec* user, chanrec* chan);
00950 
00959         virtual int OnCheckBan(userrec* user, chanrec* chan);
00960 
00965         virtual void OnStats(char symbol);
00966 
00973         virtual int OnChangeLocalUserHost(userrec* user, std::string newhost);
00974 
00981         virtual int OnChangeLocalUserGECOS(userrec* user, std::string newhost); 
00982 
00990         virtual int OnLocalTopicChange(userrec* user, chanrec* chan, std::string topic);
00991 
00998         virtual void OnPostLocalTopicChange(userrec* user, chanrec* chan, std::string topic);
00999 
01006         virtual void OnEvent(Event* event);
01007 
01015         virtual char* OnRequest(Request* request);
01016 
01026         virtual int OnOperCompare(std::string password, std::string input);
01027 
01034         virtual void OnGlobalOper(userrec* user);
01035 
01041         virtual void OnGlobalConnect(userrec* user);
01042 
01050         virtual int OnAddBan(userrec* source, chanrec* channel,std::string banmask);
01051 
01059         virtual int OnDelBan(userrec* source, chanrec* channel,std::string banmask);
01060 
01070         virtual void OnRawSocketAccept(int fd, std::string ip, int localport);
01071 
01082         virtual int OnRawSocketWrite(int fd, char* buffer, int count);
01083 
01088         virtual void OnRawSocketClose(int fd);
01089 
01105         virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult);
01106 };
01107 
01108 
01114 class Server : public classbase
01115 {
01116  public:
01120         Server();
01124         virtual ~Server();
01129         ServerConfig* GetConfig();
01133         virtual void SendOpers(std::string s);
01136         std::string GetVersion();
01141         virtual void Log(int level, std::string s);
01146         virtual void Send(int Socket, std::string s);
01151         virtual void SendServ(int Socket, std::string s);
01155         virtual void SendChannelServerNotice(std::string ServName, chanrec* Channel, std::string text);
01160         virtual void SendFrom(int Socket, userrec* User, std::string s);
01175         virtual void SendTo(userrec* Source, userrec* Dest, std::string s);
01182         virtual void SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender);
01187         virtual bool CommonChannels(userrec* u1, userrec* u2);
01195         virtual void SendCommon(userrec* User, std::string text,bool IncludeSender);
01200         virtual void SendWallops(userrec* User, std::string text);
01201 
01205         virtual bool IsNick(std::string nick);
01209         virtual int CountUsers(chanrec* c);
01213         virtual userrec* FindNick(std::string nick);
01217         virtual userrec* FindDescriptor(int socket);
01221         virtual chanrec* FindChannel(std::string channel);
01226         virtual std::string ChanMode(userrec* User, chanrec* Chan);
01230         virtual bool IsOnChannel(userrec* User, chanrec* Chan);
01233         virtual std::string GetServerName();
01236         virtual std::string GetNetworkName();
01239         virtual std::string GetServerDescription();
01245         virtual Admin GetAdmin();
01264         virtual bool AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off);
01265 
01287         virtual bool AddExtendedListMode(char modechar);
01288 
01306         virtual void AddCommand(command_t *f);
01307          
01329         virtual void SendMode(char **parameters, int pcnt, userrec *user);
01330         
01343         virtual void SendToModeMask(std::string modes, int flags, std::string text);
01344 
01350         virtual chanrec* JoinUserToChannel(userrec* user, std::string cname, std::string key);
01351         
01357         virtual chanrec* PartUserFromChannel(userrec* user, std::string cname, std::string reason);
01358         
01364         virtual void ChangeUserNick(userrec* user, std::string nickname);
01365         
01376         virtual void QuitUser(userrec* user, std::string reason);
01377         
01382         virtual bool MatchText(std::string sliteral, std::string spattern);
01383         
01395         virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
01396 
01397         virtual bool IsValidModuleCommand(std::string commandname, int pcnt, userrec* user);
01398         
01404         virtual void ChangeHost(userrec* user, std::string host);
01405         
01411         virtual void ChangeGECOS(userrec* user, std::string gecos);
01412         
01421         virtual bool IsUlined(std::string server);
01422         
01426         virtual chanuserlist GetUsers(chanrec* chan);
01427 
01434         virtual bool UserToPseudo(userrec* user,std::string message);
01435 
01442         virtual bool PseudoToUser(userrec* alive,userrec* zombie,std::string message);
01443 
01451         virtual void AddGLine(long duration, std::string source, std::string reason, std::string hostmask);
01452 
01460         virtual void AddQLine(long duration, std::string source, std::string reason, std::string nickname);
01461 
01469         virtual void AddZLine(long duration, std::string source, std::string reason, std::string ipaddr);
01470 
01478         virtual void AddKLine(long duration, std::string source, std::string reason, std::string hostmask);
01479 
01487         virtual void AddELine(long duration, std::string source, std::string reason, std::string hostmask);
01488 
01491         virtual bool DelGLine(std::string hostmask);
01492 
01495         virtual bool DelQLine(std::string nickname);
01496 
01499         virtual bool DelZLine(std::string ipaddr);
01500 
01503         virtual bool DelKLine(std::string hostmask);
01504 
01507         virtual bool DelELine(std::string hostmask);
01508 
01514         virtual long CalcDuration(std::string duration);
01515 
01518         virtual bool IsValidMask(std::string mask);
01519 
01524         virtual Module* FindModule(std::string name);
01525 
01528         virtual void AddSocket(InspSocket* sock);
01529 
01532         virtual void DelSocket(InspSocket* sock);
01533 
01534         virtual void RehashServer();
01535 };
01536 
01537 
01538 #define CONF_NOT_A_NUMBER       0x000010
01539 #define CONF_NOT_UNSIGNED       0x000080
01540 #define CONF_VALUE_NOT_FOUND    0x000100
01541 #define CONF_FILE_NOT_FOUND     0x000200
01542 
01543 
01550 class ConfigReader : public classbase
01551 {
01552   protected:
01558         std::stringstream *cache;
01559         std::stringstream *errorlog;
01562         bool readerror;
01563         long error;
01564         
01565   public:
01570         ConfigReader();                 // default constructor reads ircd.conf
01574         ConfigReader(std::string filename);     // read a module-specific config
01578         ~ConfigReader();
01583         std::string ReadValue(std::string tag, std::string name, int index);
01589         bool ReadFlag(std::string tag, std::string name, int index);
01598         long ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned);
01603         long GetError();
01610         int Enumerate(std::string tag);
01615         bool Verify();
01622         void DumpErrors(bool bail,userrec* user);
01623 
01629         int EnumerateValues(std::string tag, int index);
01630 };
01631 
01632 
01633 
01639 class FileReader : public classbase
01640 {
01641  file_cache fc;
01642  public:
01647          FileReader();
01648 
01654          FileReader(std::string filename);
01655 
01659          ~FileReader();
01660 
01666          void LoadFile(std::string filename);
01667 
01671          bool Exists();
01672          
01677          std::string GetLine(int x);
01678 
01684          int FileSize();
01685 };
01686 
01687 
01694 class ModuleFactory : public classbase
01695 {
01696  public:
01697         ModuleFactory() { }
01698         virtual ~ModuleFactory() { }
01703         virtual Module * CreateModule(Server* Me) = 0;
01704 };
01705 
01706 
01707 typedef DLLFactory<ModuleFactory> ircd_module;
01708 
01709 bool ModeDefined(char c, int i);
01710 bool ModeDefinedOper(char c, int i);
01711 int ModeDefinedOn(char c, int i);
01712 int ModeDefinedOff(char c, int i);
01713 void ModeMakeList(char modechar);
01714 bool ModeIsListMode(char modechar, int type);
01715 
01716 #endif

Generated on Mon Dec 19 18:05:20 2005 for InspIRCd by  doxygen 1.4.4-20050815