modules.h

Go to the documentation of this file.
00001 /* Modular support
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Please read COPYING and README for furhter details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  * $Id: modules.h 1265 2007-08-26 15:33:06Z geniusdex $
00012  */
00013 
00014 #ifndef MODULES_H
00015 #define MODULES_H
00016 
00017 #include <time.h>
00018 #include "services.h"
00019 #include <stdio.h>
00020 
00021 /* Cross OS compatibility macros */
00022 #ifdef _WIN32
00023 typedef HMODULE ano_module_t;
00024 
00025 #define ano_modopen(file)       LoadLibrary(file)
00026 /* ano_moderr in modules.c */
00027 #define ano_modsym(file, symbol)    (void *)GetProcAddress(file, symbol)
00028 #define ano_modclose(file)      FreeLibrary(file) ? 0 : 1
00029 #define ano_modclearerr()       SetLastError(0)
00030 #define MODULE_EXT          ".dll"
00031 
00032 #else
00033 typedef void *  ano_module_t;
00034 
00035 #define ano_modopen(file)       dlopen(file, RTLD_LAZY)
00036 #define ano_moderr()            dlerror()
00037 #define ano_modsym(file, symbol)    dlsym(file, DL_PREFIX symbol)
00038 #define ano_modclose(file)      dlclose(file)
00039 /* We call dlerror() here because it clears the module error after being
00040  * called. This previously read 'errno = 0', but that didn't work on
00041  * all POSIX-compliant architectures. This way the error is guaranteed
00042  * to be cleared, POSIX-wise. -GD
00043  */
00044 #define ano_modclearerr()       dlerror()
00045 #define MODULE_EXT          ".so"
00046 
00047 #endif
00048 
00049 
00050 /*************************************************************************/
00051 #define CMD_HASH(x)      (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */
00052 #define MAX_CMD_HASH 1024
00053 
00054 #define MOD_STOP 1
00055 #define MOD_CONT 0
00056 
00057 #define HOSTSERV HS_cmdTable /* using HOSTSERV etc. looks nicer than HS_cmdTable for modules */
00058 #define BOTSERV BS_cmdTable
00059 #define MEMOSERV MS_cmdTable
00060 #define NICKSERV NS_cmdTable
00061 #define CHANSERV CS_cmdTable
00062 #define HELPSERV HE_cmdTable
00063 #define OPERSERV OS_cmdTable
00064 #define IRCD IRCD_cmdTable
00065 #define MODULE_HASH Module_table
00066 #define EVENT EVENT_cmdTable
00067 #define EVENTHOOKS HOOK_cmdTable
00068 
00069 /**********************************************************************
00070  * Module Returns
00071  **********************************************************************/
00072  #define MOD_ERR_OK          0
00073  #define MOD_ERR_MEMORY      1
00074  #define MOD_ERR_PARAMS      2
00075  #define MOD_ERR_EXISTS      3
00076  #define MOD_ERR_NOEXIST     4
00077  #define MOD_ERR_NOUSER      5
00078  #define MOD_ERR_NOLOAD      6
00079  #define MOD_ERR_NOUNLOAD    7
00080  #define MOD_ERR_SYNTAX      8
00081  #define MOD_ERR_NODELETE    9
00082  #define MOD_ERR_UNKNOWN     10
00083  #define MOD_ERR_FILE_IO     11
00084  #define MOD_ERR_NOSERVICE   12
00085  #define MOD_ERR_NO_MOD_NAME 13
00086 
00087 /*************************************************************************/
00088 /* Macros to export the Module API functions/variables */
00089 #ifndef _WIN32
00090 #define MDE
00091 #else
00092 #ifndef MODULE_COMPILE
00093 #define MDE __declspec(dllexport)
00094 #else
00095 #define MDE __declspec(dllimport)
00096 #endif
00097 #endif
00098 /*************************************************************************/
00099 
00100 typedef enum { CORE,PROTOCOL,THIRD,SUPPORTED,QATESTED,ENCRYPTION } MODType;
00101 typedef enum { MOD_OP_LOAD, MOD_OP_UNLOAD } ModuleOperation;
00102 
00103 /*************************************************************************/
00104 /* Structure for information about a *Serv command. */
00105 
00106 typedef struct Command_ Command;
00107 typedef struct CommandHash_ CommandHash;
00108 typedef struct Module_ Module;
00109 typedef struct ModuleLang_ ModuleLang;
00110 typedef struct ModuleHash_ ModuleHash;
00111 typedef struct ModuleQueue_ ModuleQueue;
00112 typedef struct Message_ Message;
00113 typedef struct MessageHash_ MessageHash;
00114 typedef struct ModuleCallBack_ ModuleCallBack;
00115 typedef struct EvtMessage_ EvtMessage;
00116 typedef struct EvtMessageHash_ EvtMessageHash;
00117 typedef struct EvtHook_ EvtHook;
00118 typedef struct EvtHookHash_ EvtHookHash;
00119 
00120 extern MDE CommandHash *HOSTSERV[MAX_CMD_HASH];
00121 extern MDE CommandHash  *BOTSERV[MAX_CMD_HASH];
00122 extern MDE CommandHash *MEMOSERV[MAX_CMD_HASH];
00123 extern MDE CommandHash *NICKSERV[MAX_CMD_HASH];
00124 extern MDE CommandHash *CHANSERV[MAX_CMD_HASH];
00125 extern MDE CommandHash *HELPSERV[MAX_CMD_HASH];
00126 extern MDE CommandHash *OPERSERV[MAX_CMD_HASH];
00127 extern MDE MessageHash *IRCD[MAX_CMD_HASH];
00128 extern MDE ModuleHash *MODULE_HASH[MAX_CMD_HASH];
00129 extern MDE EvtMessageHash *EVENT[MAX_CMD_HASH];
00130 extern MDE EvtHookHash *EVENTHOOKS[MAX_CMD_HASH];
00131 
00132 struct ModuleLang_ {
00133     int argc;
00134     char **argv;
00135 };
00136 
00137 struct Module_ {
00138     char *name;
00139     char *filename;
00140     void *handle;
00141     time_t time;
00142     char *version;
00143     char *author;
00144 
00145     MODType type;
00146 
00147     void (*nickHelp)(User *u); /* service 1 */
00148     void (*chanHelp)(User *u); /* 2 */
00149     void (*memoHelp)(User *u); /* 3 */
00150     void (*botHelp)(User *u); /* 4 */
00151     void (*operHelp)(User *u); /* 5 */
00152     void (*hostHelp)(User *u); /* 6 */
00153     void (*helpHelp)(User *u); /* 7 */
00154 
00155 /*  CommandHash *cmdList[MAX_CMD_HASH]; */
00156     MessageHash *msgList[MAX_CMD_HASH];
00157     ModuleLang lang[NUM_LANGS];
00158 };
00159 
00160 struct ModuleHash_ {
00161         char *name;
00162         Module *m;
00163         ModuleHash *next;
00164 };
00165 
00166 struct ModuleQueue_ {
00167     Module *m;
00168     ModuleOperation op;
00169     User *u;
00170     
00171     ModuleQueue *next;
00172 };
00173 
00174 struct Command_ {
00175     char *name;
00176     int (*routine)(User *u);
00177     int (*has_priv)(User *u);   /* Returns 1 if user may use command, else 0 */
00178 
00179     /* Regrettably, these are hard-coded to correspond to current privilege
00180      * levels (v4.0).  Suggestions for better ways to do this are
00181      * appreciated.
00182      */
00183     int helpmsg_all;    /* Displayed to all users; -1 = no message */
00184     int helpmsg_reg;    /* Displayed to regular users only */
00185     int helpmsg_oper;   /* Displayed to Services operators only */
00186     int helpmsg_admin;  /* Displayed to Services admins only */
00187     int helpmsg_root;   /* Displayed to Services root only */
00188     char *help_param1;
00189     char *help_param2;
00190     char *help_param3;
00191     char *help_param4;
00192 
00193     /* Module related stuff */
00194     int core;           /* Can this command be deleted? */
00195     char *mod_name; /* Name of the module who owns us, NULL for core's  */
00196     char *service;  /* Service we provide this command for */
00197     int (*all_help)(User *u);
00198     int (*regular_help)(User *u);
00199     int (*oper_help)(User *u);
00200     int (*admin_help)(User *u);
00201     int (*root_help)(User *u);
00202 
00203     Command *next;  /* Next command responsible for the same command */
00204 };
00205 
00206 struct CommandHash_ {
00207         char *name; /* Name of the command */
00208         Command *c; /* Actual command */
00209         CommandHash *next; /* Next command */
00210 };
00211 
00212 struct Message_ {
00213     char *name;
00214     int (*func)(char *source, int ac, char **av);
00215     int core;
00216     char *mod_name;
00217     Message *next;
00218 };
00219 
00220 struct MessageHash_ {
00221         char *name;
00222         Message *m;
00223         MessageHash *next;
00224 };
00225 
00226 struct ModuleCallBack_ {
00227     char *name;
00228     char *owner_name;
00229     time_t when;
00230     int (*func)(int argc, char *argv[]);
00231     int argc;
00232     char **argv;
00233     ModuleCallBack *next;
00234 };
00235 
00236 struct EvtMessage_ {
00237     char *name;
00238     int (*func)(char *source, int ac, char **av);
00239     int core;
00240     char *mod_name;
00241     EvtMessage *next;
00242 };
00243 
00244 struct EvtMessageHash_ {
00245         char *name;
00246         EvtMessage *evm;
00247         EvtMessageHash *next;
00248 };
00249 
00250 
00251 struct EvtHook_ {
00252     int (*func)(int argc, char **argv);
00253     int core;
00254     char *name;
00255     char *mod_name;
00256     EvtHook *next;
00257 };
00258 
00259 struct EvtHookHash_ {
00260         char *name;
00261         EvtHook *evh;
00262         EvtHookHash *next;
00263 };
00264 
00265 
00266 /*************************************************************************/
00267 /* Module Managment Functions */
00268 MDE Module *createModule(char *filename);        /* Create a new module, using the given name */
00269 int destroyModule(Module *m);       /* Delete the module */
00270 int addModule(Module *m);       /* Add a module to the module hash */
00271 int delModule(Module *m);       /* Remove a module from the module hash */
00272 MDE Module *findModule(char *name);                /* Find a module */
00273 int loadModule(Module *m,User *u);  /* Load the given module into the program */
00274 int encryption_module_init(void); /* Load the encryption module */
00275 int protocol_module_init(void); /* Load the IRCD Protocol Module up*/
00276 int unloadModule(Module *m, User *u);   /* Unload the given module from the pro */
00277 int prepForUnload(Module *m);       /* Prepare the module for unload */
00278 MDE void moduleAddVersion(const char *version);
00279 MDE void moduleAddAuthor(const char *author);
00280 void modules_init(void);
00281 void modules_delayed_init(void);
00282 void moduleCallBackPrepForUnload(char *mod_name);
00283 MDE void moduleCallBackDeleteEntry(ModuleCallBack * prev);
00284 MDE char *moduleGetLastBuffer(void);
00285 MDE void moduleSetHelpHelp(void (*func) (User * u));
00286 MDE void moduleDisplayHelp(int service, User *u);
00287 MDE void moduleSetHostHelp(void (*func) (User * u));
00288 MDE void moduleSetOperHelp(void (*func) (User * u));
00289 MDE void moduleSetBotHelp(void (*func) (User * u));
00290 MDE void moduleSetMemoHelp(void (*func) (User * u));
00291 MDE void moduleSetChanHelp(void (*func) (User * u));
00292 MDE void moduleSetNickHelp(void (*func) (User * u));
00293 MDE int moduleAddHelp(Command * c, int (*func) (User * u));
00294 MDE int moduleAddRegHelp(Command * c, int (*func) (User * u));
00295 MDE int moduleAddOperHelp(Command * c, int (*func) (User * u));
00296 MDE int moduleAddAdminHelp(Command * c, int (*func) (User * u));
00297 MDE int moduleAddRootHelp(Command * c, int (*func) (User * u));
00298 MDE void moduleSetType(MODType type);
00299 extern MDE Module *mod_current_module;
00300 extern MDE char *mod_current_module_name;
00301 extern MDE char *mod_current_buffer;
00302 extern MDE int mod_current_op;
00303 extern MDE User *mod_current_user;
00304 
00305 MDE int moduleGetConfigDirective(Directive *h);
00306 /*************************************************************************/
00307 /*************************************************************************/
00308 /* Command Managment Functions */
00309 MDE Command *createCommand(const char *name,int (*func)(User *u),int (*has_priv)(User *u),int help_all, int help_reg, int help_oper, int help_admin,int help_root);
00310 MDE int destroyCommand(Command *c);                 /* destroy a command */
00311 MDE int addCoreCommand(CommandHash *cmdTable[], Command *c);    /* Add a command to a command table */
00312 MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos);
00313 MDE int addCommand(CommandHash *cmdTable[], Command *c,int pos);
00314 MDE int delCommand(CommandHash *cmdTable[], Command *c,char *mod_name);     /* Del a command from a cmd table */
00315 MDE int moduleDelCommand(CommandHash *cmdTable[],char *name);       /* Del a command from a cmd table */
00316 Command *findCommand(CommandHash *cmdTable[], const char *name);    /* Find a command */
00317 
00318 /*************************************************************************/
00319 
00320 /* Message Managment Functions */
00321 MDE Message *createMessage(const char *name,int (*func)(char *source, int ac, char **av));
00322 Message *findMessage(MessageHash *msgTable[], const char *name);    /* Find a Message */
00323 MDE int addMessage(MessageHash *msgTable[], Message *m, int pos);       /* Add a Message to a Message table */
00324 MDE int addCoreMessage(MessageHash *msgTable[], Message *m);        /* Add a Message to a Message table */
00325 MDE int moduleAddMessage(Message *m, int pos);
00326 int delMessage(MessageHash *msgTable[], Message *m, char *mod_name);        /* Del a Message from a msg table */
00327 MDE int moduleDelMessage(char *name);
00328 int destroyMessage(Message *m);                 /* destroy a Message*/
00329 
00330 /*************************************************************************/
00331 
00332 MDE EvtMessage *createEventHandler(char *name, int (*func) (char *source, int ac, char **av));
00333 EvtMessage *findEventHandler(EvtMessageHash * msgEvtTable[], const char *name);
00334 int addCoreEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm);
00335 MDE int moduleAddEventHandler(EvtMessage * evm);
00336 MDE int moduleEventDelHandler(char *name);
00337 int delEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm, char *mod_name);
00338 int destroyEventHandler(EvtMessage * evm);
00339 int addEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm);
00340 
00341 MDE EvtHook *createEventHook(char *name, int (*func) (int argc, char **argv));
00342 EvtHook *findEventHook(EvtHookHash * HookEvtTable[], const char *name);
00343 int addCoreEventHook(EvtHookHash * HookEvtTable[], EvtHook * evh);
00344 MDE int moduleAddEventHook(EvtHook * evh);
00345 MDE int moduleEventDelHook(const char *name);
00346 int delEventHook(EvtHookHash * HookEvtTable[], EvtHook * evh, char *mod_name);
00347 int destroyEventHook(EvtHook * evh);
00348 extern char *mod_current_evtbuffer;
00349 
00350 MDE void moduleInsertLanguage(int langNumber, int ac, char **av);
00351 MDE void moduleNoticeLang(char *source, User *u, int number, ...);
00352 MDE char *moduleGetLangString(User * u, int number);
00353 MDE void moduleDeleteLanguage(int langNumber);
00354 
00355 /*************************************************************************/
00356 
00357 MDE int moduleAddCallback(char *name,time_t when,int (*func)(int argc, char *argv[]),int argc, char **argv);
00358 MDE void moduleDelCallback(char *name);
00359 
00360 MDE char *moduleGetData(ModuleData **md, char *key);            /* Get the value for this key from this struct */
00361 MDE int moduleAddData(ModuleData **md, char *key, char *value);     /* Set the value for this key for this struct */
00362 MDE void moduleDelData(ModuleData **md, char *key);             /* Delete this key/value pair */
00363 MDE void moduleDelAllData(ModuleData **md);                 /* Delete all key/value pairs for this module for this struct */
00364 void moduleDelAllDataMod(Module *m);                    /* remove all module data from all structs for this module */
00365 int moduleDataDebug(ModuleData **md);                   /* Allow for debug output of a moduleData struct */
00366 MDE boolean moduleMinVersion(int major,int minor,int patch,int build);  /* Checks if the current version of anope is before or after a given verison */
00367 
00368 /*************************************************************************/
00369 /* Module Queue Operations */
00370 MDE int queueModuleLoad(char *name, User *u);
00371 MDE int queueModuleUnload(char *name, User *u);
00372 MDE void handleModuleOperationQueue(void);
00373 
00374 /*************************************************************************/
00375 /* Some IRCD protocol module support functions */
00376 
00378 MDE void updateProtectDetails(char *level_info_protect_word, char *level_info_protectme_word, char *fant_protect_add, char *fant_protect_del, char *level_protect_word, char *protect_set_mode, char *protect_unset_mode);
00379 
00380 /************************************************************************/
00381 
00382 #endif
00383 /* EOF */

Generated on Sun Dec 30 09:26:45 2007 for Anope by  doxygen 1.5.1-20070107