Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound 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 
00021 // log levels
00022 
00023 #define DEBUG 10
00024 #define VERBOSE 20
00025 #define DEFAULT 30
00026 #define SPARSE 40
00027 #define NONE 50
00028 
00029 // used with OnExtendedMode() method of modules
00030 
00031 #define MT_CHANNEL 1
00032 #define MT_CLIENT 2
00033 #define MT_SERVER 3
00034 
00035 // used with OnAccessCheck() method of modules
00036 
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 
00041 #define AC_KICK 0               // a user is being kicked
00042 #define AC_DEOP 1               // a user is being deopped
00043 #define AC_OP 2                 // a user is being opped
00044 #define AC_VOICE 3              // a user is being voiced
00045 #define AC_DEVOICE 4            // a user is being devoiced
00046 #define AC_HALFOP 5             // a user is being halfopped
00047 #define AC_DEHALFOP 6           // a user is being dehalfopped
00048 #define AC_INVITE 7             // a user is being invited
00049 #define AC_GENERAL_MODE 8       // a user channel mode is being changed
00050 
00051 // used to define a set of behavior bits for a module
00052 
00053 #define VF_STATIC               1       // module is static, cannot be /unloadmodule'd
00054 #define VF_VENDOR               2       // module is a vendor module (came in the original tarball, not 3rd party)
00055 #define VF_SERVICEPROVIDER      4       // module provides a service to other modules (can be a dependency)
00056 #define VF_COMMON               8       // module needs to be common on all servers in a mesh to link
00057 
00058 #include "dynamic.h"
00059 #include "base.h"
00060 #include "ctables.h"
00061 #include <string>
00062 #include <deque>
00063 #include <sstream>
00064 
00067 typedef std::deque<std::string> file_cache;
00068 typedef file_cache string_list;
00069 
00072 typedef std::deque<userrec*> chanuserlist;
00073 
00074 
00075 // This #define allows us to call a method in all
00076 // loaded modules in a readable simple way, e.g.:
00077 // 'FOREACH_MOD OnConnect(user);'
00078 
00079 #define FOREACH_MOD for (int _i = 0; _i <= MODCOUNT; _i++) modules[_i]->
00080 
00081 // This define is similar to the one above but returns a result in MOD_RESULT.
00082 // The first module to return a nonzero result is the value to be accepted,
00083 // and any modules after are ignored.
00084 
00085 // *********************************************************************************************
00086 
00087 #define FOREACH_RESULT(x) { MOD_RESULT = 0; \
00088                         for (int _i = 0; _i <= MODCOUNT; _i++) { \
00089                         int res = modules[_i]->x ; \
00090                         if (res != 0) { \
00091                                 MOD_RESULT = res; \
00092                                 break; \
00093                         } \
00094                 } \
00095         } 
00096    
00097 // *********************************************************************************************
00098 
00099 #define FD_MAGIC_NUMBER -42
00100 
00101 extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
00102 extern void server_mode(char **parameters, int pcnt, userrec *user);
00103 
00104 // class Version holds the version information of a Module, returned
00105 // by Module::GetVersion (thanks RD)
00106 
00111 class Version : public classbase
00112 {
00113  public:
00114          const int Major, Minor, Revision, Build, Flags;
00115          Version(int major, int minor, int revision, int build, int flags);
00116 };
00117 
00123 class Admin : public classbase
00124 {
00125  public:
00126          const std::string Name, Email, Nick;
00127          Admin(std::string name, std::string email, std::string nick);
00128 };
00129 
00130 
00131 // Forward-delacare module for ModuleMessage etc
00132 class Module;
00133 
00134 // Thanks to Rob (from anope) for the idea of this message passing API
00135 // (its been done before, but this seemed a very neat and tidy way...
00136 
00141 class ModuleMessage : public classbase
00142 {
00143  public:
00146         virtual char* Send() = 0;
00147 };
00148 
00154 class Request : public ModuleMessage
00155 {
00156  protected:
00159         char* data;
00163         Module* source;
00166         Module* dest;
00167  public:
00170         Request(char* anydata, Module* src, Module* dst);
00173         char* GetData();
00176         Module* GetSource();
00179         Module* GetDest();
00185         char* Send();
00186 };
00187 
00188 
00194 class Event : public ModuleMessage
00195 {
00196  protected:
00199         char* data;
00203         Module* source;
00208         std::string id;
00209  public:
00212         Event(char* anydata, Module* src, std::string eventid);
00215         char* GetData();
00218         Module* GetSource();
00222         std::string GetEventID();
00227         char* Send();
00228 };
00229 
00230 
00236 class Module : public classbase
00237 {
00238  public:
00239 
00243         Module();
00244 
00248         virtual ~Module();
00249 
00254         virtual Version GetVersion();
00255 
00259         virtual void OnUserConnect(userrec* user);
00260 
00266         virtual void OnUserQuit(userrec* user);
00267 
00273         virtual void OnUserDisconnect(userrec* user);
00274 
00279         virtual void OnUserJoin(userrec* user, chanrec* channel);
00280 
00285         virtual void OnUserPart(userrec* user, chanrec* channel);
00286 
00292         virtual void OnPacketTransmit(std::string &data, std::string serv);
00293 
00300         virtual void OnPacketReceive(std::string &data, std::string serv);
00301 
00307         virtual void OnRehash();
00308 
00317         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user);
00318 
00328         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params);
00329         
00343         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
00344         
00350         virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason);
00351 
00356         virtual void OnUserKick(userrec* source, userrec* user, chanrec* chan, std::string reason);
00357 
00362         virtual void OnOper(userrec* user);
00363         
00372         virtual void OnInfo(userrec* user);
00373         
00378         virtual void OnWhois(userrec* source, userrec* dest);
00379         
00385         virtual int OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel);
00386         
00395         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text);
00396 
00408         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text);
00409         
00417         virtual int OnUserPreNick(userrec* user, std::string newnick);
00418         
00426         virtual void OnUserPostNick(userrec* user, std::string oldnick);
00427 
00449         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type);
00450 
00456         virtual string_list OnUserSync(userrec* user);
00457 
00463         virtual string_list OnChannelSync(chanrec* chan);
00464 
00468         virtual void On005Numeric(std::string &output);
00469 
00479         virtual int OnKill(userrec* source, userrec* dest, std::string reason);
00480 
00491         virtual void OnLoadModule(Module* mod,std::string name);
00492 
00498         virtual void OnBackgroundTimer(time_t curtime);
00499 
00507         virtual void OnSendList(userrec* user, chanrec* channel, char mode);
00508 
00519         virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user);
00520 
00529         virtual bool OnCheckReady(userrec* user);
00530 
00538         virtual void OnUserRegister(userrec* user);
00539 
00545         virtual int OnRawMode(userrec* user, chanrec* chan, char mode, std::string param, bool adding, int pcnt);
00546 
00552         virtual int OnCheckInvite(userrec* user, chanrec* chan);
00553 
00560         virtual int OnCheckKey(userrec* user, chanrec* chan, std::string keygiven);
00561 
00567         virtual int OnCheckLimit(userrec* user, chanrec* chan);
00568 
00574         virtual int OnCheckBan(userrec* user, chanrec* chan);
00575 
00579         virtual void OnStats(char symbol);
00580 
00584         virtual int OnChangeLocalUserHost(userrec* user, std::string newhost);
00585 
00589         virtual int OnChangeLocalUserGECOS(userrec* user, std::string newhost); 
00590 
00594         virtual int OnLocalTopicChange(userrec* user, chanrec* chan, std::string topic);
00595 
00606         virtual int OnMeshToken(char token,string_list params,serverrec* source,serverrec* reply, std::string tcp_host,std::string ipaddr,int port);
00607 
00613         virtual void OnEvent(Event* event);
00614 
00621         virtual char* OnRequest(Request* request);
00622 
00629         virtual int OnOperCompare(std::string password, std::string input);
00630 
00636         virtual void OnGlobalOper(userrec* user);
00637 
00642         virtual void OnGlobalConnect(userrec* user);
00643 
00647         virtual int OnAddBan(userrec* source, chanrec* channel,std::string banmask);
00648 
00652         virtual int OnDelBan(userrec* source, chanrec* channel,std::string banmask);
00653 
00660         virtual void OnRawSocketAccept(int fd, std::string ip, int localport);
00661 
00668         virtual int OnRawSocketWrite(int fd, char* buffer, int count);
00669 
00673         virtual void OnRawSocketClose(int fd);
00674 
00685         virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult);
00686 };
00687 
00688 
00694 class Server : public classbase
00695 {
00696  public:
00700         Server();
00704         virtual ~Server();
00705 
00709         virtual void SendOpers(std::string s);
00714         virtual void Log(int level, std::string s);
00719         virtual void Send(int Socket, std::string s);
00724         virtual void SendServ(int Socket, std::string s);
00728         virtual void SendChannelServerNotice(std::string ServName, chanrec* Channel, std::string text);
00733         virtual void SendFrom(int Socket, userrec* User, std::string s);
00748         virtual void SendTo(userrec* Source, userrec* Dest, std::string s);
00755         virtual void SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender);
00760         virtual bool CommonChannels(userrec* u1, userrec* u2);
00768         virtual void SendCommon(userrec* User, std::string text,bool IncludeSender);
00773         virtual void SendWallops(userrec* User, std::string text);
00774 
00778         virtual bool IsNick(std::string nick);
00782         virtual int CountUsers(chanrec* c);
00786         virtual userrec* FindNick(std::string nick);
00790         virtual userrec* FindDescriptor(int socket);
00794         virtual chanrec* FindChannel(std::string channel);
00799         virtual std::string ChanMode(userrec* User, chanrec* Chan);
00803         virtual bool IsOnChannel(userrec* User, chanrec* Chan);
00806         virtual std::string GetServerName();
00809         virtual std::string GetNetworkName();
00812         virtual std::string GetServerDescription();
00818         virtual Admin GetAdmin();
00837         virtual bool AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off);
00838 
00860         virtual bool AddExtendedListMode(char modechar);
00861 
00879         virtual void AddCommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
00880          
00902         virtual void SendMode(char **parameters, int pcnt, userrec *user);
00903         
00916         virtual void SendToModeMask(std::string modes, int flags, std::string text);
00917 
00923         virtual chanrec* JoinUserToChannel(userrec* user, std::string cname, std::string key);
00924         
00930         virtual chanrec* PartUserFromChannel(userrec* user, std::string cname, std::string reason);
00931         
00937         virtual void ChangeUserNick(userrec* user, std::string nickname);
00938         
00949         virtual void QuitUser(userrec* user, std::string reason);
00950         
00955         virtual bool MatchText(std::string sliteral, std::string spattern);
00956         
00968         virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
00969         
00975         virtual void ChangeHost(userrec* user, std::string host);
00976         
00982         virtual void ChangeGECOS(userrec* user, std::string gecos);
00983         
00992         virtual bool IsUlined(std::string server);
00993         
00997         virtual chanuserlist GetUsers(chanrec* chan);
00998 
01005         virtual bool UserToPseudo(userrec* user,std::string message);
01006 
01013         virtual bool PseudoToUser(userrec* alive,userrec* zombie,std::string message);
01014 
01022         virtual void AddGLine(long duration, std::string source, std::string reason, std::string hostmask);
01023 
01031         virtual void AddQLine(long duration, std::string source, std::string reason, std::string nickname);
01032 
01040         virtual void AddZLine(long duration, std::string source, std::string reason, std::string ipaddr);
01041 
01049         virtual void AddKLine(long duration, std::string source, std::string reason, std::string hostmask);
01050 
01058         virtual void AddELine(long duration, std::string source, std::string reason, std::string hostmask);
01059 
01062         virtual bool DelGLine(std::string hostmask);
01063 
01066         virtual bool DelQLine(std::string nickname);
01067 
01070         virtual bool DelZLine(std::string ipaddr);
01071 
01074         virtual bool DelKLine(std::string hostmask);
01075 
01078         virtual bool DelELine(std::string hostmask);
01079 
01085         virtual long CalcDuration(std::string duration);
01086 
01089         virtual bool IsValidMask(std::string mask);
01090 
01095         virtual void MeshSendAll(std::string text);
01096 
01103         virtual void MeshSendCommon(userrec* user, std::string text);
01104 
01107         virtual void MeshSendAllAlive(std::string text);
01108 
01112         virtual void MeshSendUnicast(std::string destination, std::string text);
01113 
01118         virtual void MeshSendAllExcept(std::string target, std::string text);
01119 
01123         virtual bool MeshCheckChan(chanrec *c,std::string servername);
01124 
01128         virtual bool MeshCheckCommon(userrec* u,std::string servername);
01129 
01134         virtual Module* FindModule(std::string name);
01135 };
01136 
01137 
01138 #define CONF_NOT_A_NUMBER       0x000010
01139 #define CONF_NOT_UNSIGNED       0x000080
01140 #define CONF_VALUE_NOT_FOUND    0x000100
01141 #define CONF_FILE_NOT_FOUND     0x000200
01142 
01143 
01150 class ConfigReader : public classbase
01151 {
01152   protected:
01158         std::stringstream *cache;
01159         std::stringstream *errorlog;
01162         bool readerror;
01163         long error;
01164         
01165   public:
01170         ConfigReader();                 // default constructor reads ircd.conf
01174         ConfigReader(std::string filename);     // read a module-specific config
01178         ~ConfigReader();
01183         std::string ReadValue(std::string tag, std::string name, int index);
01189         bool ReadFlag(std::string tag, std::string name, int index);
01198         long ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned);
01203         long GetError();
01210         int Enumerate(std::string tag);
01215         bool Verify();
01222         void DumpErrors(bool bail,userrec* user);
01223 
01229         int EnumerateValues(std::string tag, int index);
01230 };
01231 
01232 
01233 
01239 class FileReader : public classbase
01240 {
01241  file_cache fc;
01242  public:
01247          FileReader();
01248 
01254          FileReader(std::string filename);
01255 
01259          ~FileReader();
01260 
01266          void LoadFile(std::string filename);
01267 
01271          bool Exists();
01272          
01277          std::string GetLine(int x);
01278 
01284          int FileSize();
01285 };
01286 
01287 
01294 class ModuleFactory : public classbase
01295 {
01296  public:
01297         ModuleFactory() { }
01298         virtual ~ModuleFactory() { }
01303         virtual Module * CreateModule() = 0;
01304 };
01305 
01306 
01307 typedef DLLFactory<ModuleFactory> ircd_module;
01308 
01309 #endif

Generated on Wed May 25 22:02:05 2005 for InspIRCd by doxygen 1.3.3