24
# define LIBRARY_DIR "."
24
31
* @brief module manager
25
32
* @author Robert Norris
26
* $Date: 2005/01/19 18:29:38 $
27
* $Revision: 1.32.2.2 $
33
* $Date: 2005/08/17 07:48:28 $
30
37
/* these functions implement a multiplexor to get calls to the correct module
31
38
* for the given type */
34
/* if you add a module, you'll need to update these arrays */
36
extern int active_init(mod_instance_t);
37
extern int announce_init(mod_instance_t);
38
extern int deliver_init(mod_instance_t);
39
extern int disco_init(mod_instance_t);
40
extern int disco_publish_init(mod_instance_t);
41
extern int echo_init(mod_instance_t);
42
extern int help_init(mod_instance_t);
43
extern int offline_init(mod_instance_t);
44
extern int presence_init(mod_instance_t);
45
extern int privacy_init(mod_instance_t);
46
extern int roster_init(mod_instance_t);
47
extern int session_init(mod_instance_t);
48
extern int vacation_init(mod_instance_t);
49
extern int validate_init(mod_instance_t);
50
extern int iq_last_init(mod_instance_t);
51
extern int iq_private_init(mod_instance_t);
52
extern int iq_time_init(mod_instance_t);
53
extern int iq_vcard_init(mod_instance_t);
54
extern int iq_version_init(mod_instance_t);
55
extern int template_roster_init(mod_instance_t);
57
char *module_names[] = {
81
module_init_fn module_inits[] = {
101
template_roster_init,
40
/* Notes on dynamic modules (cedricv@) :
41
Modules are searched by name mod_[modulename].so or mod_[modulename].dll
43
You have to set <path>[full_path]</path> within <modules> in sm.xml config,
44
else it will only search in LD_LIBRARY_PATH or c:\windows\system32
105
47
mm_t mm_new(sm_t sm) {
107
int celem, melem, attr, i, *nlist = NULL;
108
char id[13], name[32], arg[1024];
49
int celem, melem, attr, *nlist = NULL;
50
char id[13], name[32], mod_fullpath[PATH_MAX], arg[1024], *modules_path;
109
51
mod_chain_t chain = (mod_chain_t) NULL;
110
52
mod_instance_t **list = NULL, mi;
113
mm = (mm_t) malloc(sizeof(struct mm_st));
114
memset(mm, 0, sizeof(struct mm_st));
55
mm = (mm_t) calloc(1, sizeof(struct mm_st));
117
58
mm->modules = xhash_new(101);
163
attr = nad_find_attr(sm->config->nad, melem, -1, "arg", NULL);
165
snprintf(arg, 1024, "%.*s", NAD_AVAL_L(sm->config->nad, attr), NAD_AVAL(sm->config->nad, attr));
166
log_debug(ZONE, "module arg: %s", arg);
210
169
snprintf(name, 32, "%.*s", NAD_CDATA_L(sm->config->nad, melem), NAD_CDATA(sm->config->nad, melem));
212
for(i = 0; module_names[i] != NULL; i++) {
213
if(strcmp(name, module_names[i]) == 0) {
214
log_debug(ZONE, "adding module '%s' to chain '%s'", name, id);
217
attr = nad_find_attr(sm->config->nad, melem, -1, "arg", NULL);
219
snprintf(arg, 1024, "%.*s", NAD_AVAL_L(sm->config->nad, attr), NAD_AVAL(sm->config->nad, attr));
220
log_debug(ZONE, "module arg: %s", arg);
223
mod = xhash_get(mm->modules, name);
225
mod = (module_t) malloc(sizeof(struct module_st));
226
memset(mod, 0, sizeof(struct module_st));
229
mod->index = mm->nindex;
230
mod->name = strdup(name);
171
mod = xhash_get(mm->modules, name);
173
mod = (module_t) calloc(1, sizeof(struct module_st));
176
mod->index = mm->nindex;
177
mod->name = strdup(name);
179
if (modules_path != NULL)
180
snprintf(mod_fullpath, PATH_MAX, "%s/mod_%s.so", modules_path, name);
182
snprintf(mod_fullpath, PATH_MAX, "%s/mod_%s.so", LIBRARY_DIR, name);
183
mod->handle = dlopen(mod_fullpath, RTLD_LAZY);
184
if (mod->handle != NULL)
185
mod->module_init_fn = dlsym(mod->handle, "module_init");
187
if (modules_path != NULL)
188
snprintf(mod_fullpath, PATH_MAX, "%s\\mod_%s.dll", modules_path, name);
190
snprintf(mod_fullpath, PATH_MAX, "mod_%s.dll", name);
191
mod->handle = (void*) LoadLibrary(mod_fullpath);
192
if (mod->handle != NULL)
193
mod->module_init_fn = (int (*)(mod_instance_t))GetProcAddress((HMODULE) mod->handle, "module_init");
196
if (mod->handle != NULL && mod->module_init_fn != NULL) {
197
log_debug(ZONE, "preloaded module '%s' to chain '%s' (not added yet)", name, id);
232
198
xhash_put(mm->modules, mod->name, (void *) mod);
237
mi = (mod_instance_t) malloc(sizeof(struct mod_instance_st));
238
memset(mi, 0, sizeof(struct mod_instance_st));
243
mi->arg = (arg[0] == '\0') ? NULL : strdup(arg);
246
if((module_inits[i])(mi) != 0) {
247
log_debug(ZONE, "init for module '%s' (seq %d) failed", name, mi->seq);
252
xhash_zap(mm->modules, mod->name);
258
melem = nad_find_elem(sm->config->nad, melem, -1, "module", 0);
265
*list = (mod_instance_t *) realloc(*list, sizeof(mod_instance_t) * (*nlist + 1));
266
(*list)[*nlist] = mi;
268
log_debug(ZONE, "module '%s' added to chain '%s' (order %d index %d seq %d)", mod->name, id, *nlist, mod->index, mi->seq);
202
log_write(sm->log, LOG_ERR, "failed loading module '%s' to chain '%s' (%s)", name, id, dlerror());
203
if (mod->handle != NULL)
204
dlclose(mod->handle);
206
log_write(sm->log, LOG_ERR, "failed loading module '%s' to chain '%s' (errcode: %x)", name, id, GetLastError());
207
if (mod->handle != NULL)
208
FreeLibrary((HMODULE) mod->handle);
211
melem = nad_find_elem(sm->config->nad, melem, -1, "module", 0);
216
mi = (mod_instance_t) calloc(1, sizeof(struct mod_instance_st));
221
mi->arg = (arg[0] == '\0') ? NULL : strdup(arg);
224
if(mod->module_init_fn(mi) != 0) {
225
log_write(sm->log, LOG_ERR, "init for module '%s' (seq %d) failed", name, mi->seq);
229
xhash_zap(mm->modules, mod->name);
232
if (mod->handle != NULL)
233
dlclose(mod->handle);
235
if (mod->handle != NULL)
236
FreeLibrary((HMODULE) mod->handle);
244
melem = nad_find_elem(sm->config->nad, melem, -1, "module", 0);
251
*list = (mod_instance_t *) realloc(*list, sizeof(mod_instance_t) * (*nlist + 1));
252
(*list)[*nlist] = mi;
254
log_write(sm->log, LOG_NOTICE, "module '%s' added to chain '%s' (order %d index %d seq %d)", mod->name, id, *nlist, mod->index, mi->seq);
274
258
melem = nad_find_elem(sm->config->nad, melem, -1, "module", 0);