1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
/* Modular support
*
* (C) 2003-2005 Anope Team
* Contact us at info@anope.org
*
* Please read COPYING and README for furhter details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*
* $Id$
*/
#ifndef MODULES_H
#define MODULES_H
#include <time.h>
#include "services.h"
#include <stdio.h>
/* Cross OS compatibility macros */
#ifdef _WIN32
typedef HMODULE ano_module_t;
#define ano_modopen(file) LoadLibrary(file)
/* ano_moderr in modules.c */
#define ano_modsym(file, symbol) (void *)GetProcAddress(file, symbol)
#define ano_modclose(file) FreeLibrary(file) ? 0 : 1
#define ano_modclearerr() SetLastError(0)
#define MODULE_EXT ".dll"
#else
typedef void * ano_module_t;
#ifdef HAS_RTLD_LOCAL
#define ano_modopen(file) dlopen(file, RTLD_LAZY|RTLD_LOCAL)
#else
#define ano_modopen(file) dlopen(file, RTLD_LAZY)
#endif
#define ano_moderr() dlerror()
#define ano_modsym(file, symbol) dlsym(file, DL_PREFIX symbol)
#define ano_modclose(file) dlclose(file)
#define ano_modclearerr() errno = 0
#define MODULE_EXT ".so"
#endif
/*************************************************************************/
#define CMD_HASH(x) (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */
#define MAX_CMD_HASH 1024
#define MOD_STOP 1
#define MOD_CONT 0
#define HOSTSERV HS_cmdTable /* using HOSTSERV etc. looks nicer than HS_cmdTable for modules */
#define BOTSERV BS_cmdTable
#define MEMOSERV MS_cmdTable
#define NICKSERV NS_cmdTable
#define CHANSERV CS_cmdTable
#define HELPSERV HE_cmdTable
#define OPERSERV OS_cmdTable
#define IRCD IRCD_cmdTable
#define MODULE_HASH Module_table
#define EVENT EVENT_cmdTable
#define EVENTHOOKS HOOK_cmdTable
/**********************************************************************
* Module Returns
**********************************************************************/
#define MOD_ERR_OK 0
#define MOD_ERR_MEMORY 1
#define MOD_ERR_PARAMS 2
#define MOD_ERR_EXISTS 3
#define MOD_ERR_NOEXIST 4
#define MOD_ERR_NOUSER 5
#define MOD_ERR_NOLOAD 6
#define MOD_ERR_NOUNLOAD 7
#define MOD_ERR_SYNTAX 8
#define MOD_ERR_NODELETE 9
#define MOD_ERR_UNKNOWN 10
#define MOD_ERR_FILE_IO 11
#define MOD_ERR_NOSERVICE 12
#define MOD_ERR_NO_MOD_NAME 13
/*************************************************************************/
/* Macros to export the Module API functions/variables */
#ifndef _WIN32
#define MDE
#else
#ifndef MODULE_COMPILE
#define MDE __declspec(dllexport)
#else
#define MDE __declspec(dllimport)
#endif
#endif
/*************************************************************************/
/* Structure for information about a *Serv command. */
typedef struct Command_ Command;
typedef struct CommandHash_ CommandHash;
typedef struct Module_ Module;
typedef struct ModuleHash_ ModuleHash;
typedef struct Message_ Message;
typedef struct MessageHash_ MessageHash;
typedef struct ModuleCallBack_ ModuleCallBack;
typedef struct EvtMessage_ EvtMessage;
typedef struct EvtMessageHash_ EvtMessageHash;
typedef struct EvtHook_ EvtHook;
typedef struct EvtHookHash_ EvtHookHash;
extern MDE CommandHash *HOSTSERV[MAX_CMD_HASH];
extern MDE CommandHash *BOTSERV[MAX_CMD_HASH];
extern MDE CommandHash *MEMOSERV[MAX_CMD_HASH];
extern MDE CommandHash *NICKSERV[MAX_CMD_HASH];
extern MDE CommandHash *CHANSERV[MAX_CMD_HASH];
extern MDE CommandHash *HELPSERV[MAX_CMD_HASH];
extern MDE CommandHash *OPERSERV[MAX_CMD_HASH];
extern MDE MessageHash *IRCD[MAX_CMD_HASH];
extern EvtMessageHash *EVENT[MAX_CMD_HASH];
extern EvtHookHash *EVENTHOOKS[MAX_CMD_HASH];
struct Module_ {
char *name;
char *filename;
void *handle;
time_t time;
char *version;
char *author;
void (*nickHelp)(User *u); /* service 1 */
void (*chanHelp)(User *u); /* 2 */
void (*memoHelp)(User *u); /* 3 */
void (*botHelp)(User *u); /* 4 */
void (*operHelp)(User *u); /* 5 */
void (*hostHelp)(User *u); /* 6 */
void (*helpHelp)(User *u); /* 7 */
/* CommandHash *cmdList[MAX_CMD_HASH]; */
MessageHash *msgList[MAX_CMD_HASH];
};
struct ModuleHash_ {
char *name;
Module *m;
ModuleHash *next;
};
struct Command_ {
char *name;
int (*routine)(User *u);
int (*has_priv)(User *u); /* Returns 1 if user may use command, else 0 */
/* Regrettably, these are hard-coded to correspond to current privilege
* levels (v4.0). Suggestions for better ways to do this are
* appreciated.
*/
int helpmsg_all; /* Displayed to all users; -1 = no message */
int helpmsg_reg; /* Displayed to regular users only */
int helpmsg_oper; /* Displayed to Services operators only */
int helpmsg_admin; /* Displayed to Services admins only */
int helpmsg_root; /* Displayed to Services root only */
char *help_param1;
char *help_param2;
char *help_param3;
char *help_param4;
/* Module related stuff */
int core; /* Can this command be deleted? */
char *mod_name; /* Name of the module who owns us, NULL for core's */
char *service; /* Service we provide this command for */
int (*all_help)(User *u);
int (*regular_help)(User *u);
int (*oper_help)(User *u);
int (*admin_help)(User *u);
int (*root_help)(User *u);
Command *next; /* Next command responsible for the same command */
};
struct CommandHash_ {
char *name; /* Name of the command */
Command *c; /* Actual command */
CommandHash *next; /* Next command */
};
struct Message_ {
char *name;
int (*func)(char *source, int ac, char **av);
int core;
char *mod_name;
Message *next;
};
struct MessageHash_ {
char *name;
Message *m;
MessageHash *next;
};
struct ModuleCallBack_ {
char *name;
char *owner_name;
time_t when;
int (*func)(int argc, char *argv[]);
int argc;
char **argv;
ModuleCallBack *next;
};
struct EvtMessage_ {
char *name;
int (*func)(char *source, int ac, char **av);
int core;
char *mod_name;
EvtMessage *next;
};
struct EvtMessageHash_ {
char *name;
EvtMessage *evm;
EvtMessageHash *next;
};
struct EvtHook_ {
int (*func)(char *source);
int core;
char *name;
char *mod_name;
EvtHook *next;
};
struct EvtHookHash_ {
char *name;
EvtHook *evh;
EvtHookHash *next;
};
/*************************************************************************/
/* Module Managment Functions */
Module *createModule(char *filename); /* Create a new module, using the given name */
int destroyModule(Module *m); /* Delete the module */
int addModule(Module *m); /* Add a module to the module hash */
int delModule(Module *m); /* Remove a module from the module hash */
Module *findModule(char *name); /* Find a module */
int loadModule(Module *m,User *u); /* Load the given module into the program */
int unloadModule(Module *m, User *u); /* Unload the given module from the pro */
int prepForUnload(Module *m); /* Prepare the module for unload */
MDE void moduleAddVersion(char *version);
MDE void moduleAddAuthor(char *author);
void modules_init(void);
void modules_delayed_init(void);
void moduleCallBackPrepForUnload(char *mod_name);
MDE void moduleCallBackDeleteEntry(ModuleCallBack * prev);
MDE char *moduleGetLastBuffer(void);
MDE void moduleSetHelpHelp(void (*func) (User * u));
MDE void moduleDisplayHelp(int service, User *u);
MDE void moduleSetHostHelp(void (*func) (User * u));
MDE void moduleSetOperHelp(void (*func) (User * u));
MDE void moduleSetBotHelp(void (*func) (User * u));
MDE void moduleSetMemoHelp(void (*func) (User * u));
MDE void moduleSetChanHelp(void (*func) (User * u));
MDE void moduleSetNickHelp(void (*func) (User * u));
MDE int moduleAddHelp(Command * c, int (*func) (User * u));
MDE int moduleAddRegHelp(Command * c, int (*func) (User * u));
MDE int moduleAddOperHelp(Command * c, int (*func) (User * u));
MDE int moduleAddAdminHelp(Command * c, int (*func) (User * u));
MDE int moduleAddRootHelp(Command * c, int (*func) (User * u));
/*************************************************************************/
/*************************************************************************/
/* Command Managment Functions */
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);
MDE int destroyCommand(Command *c); /* destroy a command */
MDE int addCoreCommand(CommandHash *cmdTable[], Command *c); /* Add a command to a command table */
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos);
MDE int addCommand(CommandHash *cmdTable[], Command *c,int pos);
MDE int delCommand(CommandHash *cmdTable[], Command *c,char *mod_name); /* Del a command from a cmd table */
MDE int moduleDelCommand(CommandHash *cmdTable[],char *name); /* Del a command from a cmd table */
Command *findCommand(CommandHash *cmdTable[], const char *name); /* Find a command */
/*************************************************************************/
/* Message Managment Functions */
MDE Message *createMessage(char *name,int (*func)(char *source, int ac, char **av));
Message *findMessage(MessageHash *msgTable[], const char *name); /* Find a Message */
MDE int addMessage(MessageHash *msgTable[], Message *m, int pos); /* Add a Message to a Message table */
int addCoreMessage(MessageHash *msgTable[], Message *m); /* Add a Message to a Message table */
MDE int moduleAddMessage(Message *m, int pos);
int delMessage(MessageHash *msgTable[], Message *m, char *mod_name); /* Del a Message from a msg table */
MDE int moduleDelMessage(char *name);
int destroyMessage(Message *m); /* destroy a Message*/
Message *findMessage(MessageHash *msgTable[], const char *name);
/*************************************************************************/
MDE EvtMessage *createEventHandler(char *name, int (*func) (char *source, int ac, char **av));
EvtMessage *findEventHandler(EvtMessageHash * msgEvtTable[], const char *name);
int addCoreEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm);
MDE int moduleAddEventHandler(EvtMessage * evm);
MDE int moduleEventDelHandler(char *name);
int delEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm, char *mod_name);
int destroyEventHandler(EvtMessage * evm);
int addEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm);
MDE EvtHook *createEventHook(char *name, int (*func) (char *source));
EvtHook *findEventHook(EvtHookHash * HookEvtTable[], const char *name);
int addCoreEventHook(EvtHookHash * HookEvtTable[], EvtHook * evh);
MDE int moduleAddEventHook(EvtHook * evh);
MDE int moduleEventDelHook(const char *name);
int delEventHook(EvtHookHash * HookEvtTable[], EvtHook * evh, char *mod_name);
int destroyEventHook(EvtHook * evh);
extern char *mod_current_evtbuffer;
/*************************************************************************/
MDE int moduleAddCallback(char *name,time_t when,int (*func)(int argc, char *argv[]),int argc, char **argv);
MDE void moduleDelCallback(char *name);
MDE void moduleCallBackRun(void);
MDE char *moduleGetData(ModuleData **md, char *key); /* Get the value for this key from this struct */
MDE int moduleAddData(ModuleData **md, char *key, char *value); /* Set the value for this key for this struct */
MDE void moduleDelData(ModuleData **md, char *key); /* Delete this key/value pair */
MDE void moduleDelAllData(ModuleData **md); /* Delete all key/value pairs for this module for this struct */
MDE void moduleCleanStruct(ModuleData **moduleData); /* Clean a moduleData hash */
void moduleDelAllDataMod(Module *m); /* remove all module data from all structs for this module */
int moduleDataDebug(ModuleData **md); /* Allow for debug output of a moduleData struct */
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 */
/*************************************************************************/
#endif
/* EOF */
|