// test a module. int test_module(char *module, char *file, char *path) { void *handle; module_list_t *module_func; module_list_t* (*module_loader)(); char *args[] = {"", "Whatever-REL", "mp3"}; handle = dlopen(module, RTLD_LAZY); if (!handle) { printf("Error loading module %s: %s\n", module, dlerror()); return 0; } module_loader = dlsym(handle, MODULE_LOADER_FUNC); if (!module_loader) { printf("Error loading module %s: No loader func\n"); dlclose(handle); return 0; } // show module name printf("module name = %s\n", module_loader()->mod_name); // test module file func module_loader()->mod_func_file(file, args); // test module dir func module_loader()->mod_func_dir(path, args); dlclose(handle); return 1; }
int do_module(char *path, char *file) { module_list_t *module_func; char *args[] = {"", "Whatever-REL", "mp3"}; module_func = module_loader(); if (module_func->mod_func_file) module_func->mod_func_file(file, args); if (module_func->mod_func_dir) module_func->mod_func_dir(path, args); }
int pre_do_module(char *module, filelist_t *files, char *path, char *argv[], struct subdir_list *subdirs) { void *handle; module_list_t *module_func; module_list_t* (*module_loader)(); void (*set_config)(hashtable_t *ht); char *err; pre_log("MODULE", "%s", module); handle = dlopen(module, RTLD_LAZY); if (!handle) { err = dlerror(); pre_log("MODULE-ERROR", "%s \"%s\"", module, err); printf("Error loading module %s: %s\n", module, err); return 0; } module_loader = dlsym(handle, MODULE_LOADER_FUNC); set_config = dlsym(handle, MODULE_SETCONFIG_FUNC); if (!module_loader || !set_config) { pre_log("MODULE-ERROR", "%s %s", module, "No loader func found"); printf("Error loading module %s: No loader func found\n"); dlclose(handle); return 0; } pre_log("MODULE-RUN", "%s %s", module, path); set_config(get_config()); // try to set environment if module allows. set_config = dlsym(handle, MODULE_SETENV_FUNC); if (set_config) set_config(get_context()); pre_exec_module(module_loader(), files, path, argv, subdirs); pre_log("MODULE-DONE", "%s %s", module, path); dlclose(handle); return 1; }
/* Load Module name */ int module_open(char *path, char *name) { char file[BUFFER_LEN]; int (*module_loader)(struct module_entry_t *); struct module_entry_t *module; void *handle; memset(file, '\0', BUFFER_LEN); snprintf(file, BUFFER_LEN, "%s/%s", path, name); handle = lt_dlopen(file); if(!handle) { do_rawlog(LT_ERR, "Error Loading Module: %s | %s ", file, lt_dlerror()); return 0; } /* Some OSes may need symbols to be prefixed with _.. Will need to look into autoconfig code for this */ module_loader = MODULE_FUNCRET(handle, "module_load"); if(!module_loader) { do_rawlog(LT_ERR, "Error Loading Module: Could not call module_load | %s", file); return 0; } /* Add the module to the linked list */ module = module_entry_add(name); if(module == NULL) { return 0; } module->handle = handle; module->load = module_loader; module->unload = MODULE_FUNCRET(handle, "module_unload"); /* Grab info and version from module & put it in */ /* Success.. Call the module */ return module_loader(module); }