gchar* gconf_backend_file(const gchar* address) { gchar* back; gchar* file; gchar* retval; const gchar* backenddir; g_return_val_if_fail(address != NULL, NULL); back = gconf_address_backend(address); if (back == NULL) return NULL; backenddir = g_getenv("GCONF_BACKEND_DIR"); if (backenddir == NULL) backenddir = GCONF_BACKEND_DIR; file = g_strconcat("gconfbackend-", back, NULL); retval = g_module_build_path(backenddir, file); g_free(back); if (g_file_test(retval, G_FILE_TEST_EXISTS)) { g_free(file); return retval; } else { /* -- debug only */ #ifdef GCONF_ENABLE_DEBUG gchar* dir; g_free(retval); dir = g_strconcat(GCONF_SRCDIR, "/gconf/", GCONF_BUILDDIR, "/backends/.libs", NULL); retval = g_module_build_path(dir, file); g_free(dir); if (g_file_test(retval, G_FILE_TEST_EXISTS)) { g_free(file); return retval; } #endif /* -- end debug only */ gconf_log(GCL_ERR, _("No such file `%s'\n"), retval); g_free(file); g_free(retval); return NULL; } }
GModule * ws_module_open(gchar *module_name, GModuleFlags flags) { gchar *full_path; GModule *mod; if (!init_dll_load_paths() || !module_name) return NULL; /* First try the program directory */ full_path = g_module_build_path(program_path, module_name); if (full_path) { mod = g_module_open(full_path, flags); if (mod) { g_free(full_path); return mod; } } /* Next try the system directory */ full_path = g_module_build_path(system_path, module_name); if (full_path) { mod = g_module_open(full_path, flags); if (mod) { g_free(full_path); return mod; } } return NULL; }
static gpointer plugin_lookup_symbol (GigglePlugin *plugin, const char *symbol_name) { GigglePluginPriv *priv = GET_PRIV (plugin); char *plugin_dir, *path; const char *plugin_name; gpointer symbol; if (G_UNLIKELY (!priv->module)) { plugin_name = giggle_plugin_get_name (plugin); plugin_dir = g_path_get_dirname (priv->filename); path = g_module_build_path (plugin_dir, plugin_name); priv->module = g_module_open (path, G_MODULE_BIND_LAZY); if (!priv->module) { g_free (path); plugin_dir = g_build_filename (path = plugin_dir, ".libs", NULL); g_free (path); path = g_module_build_path (plugin_dir, plugin_name); priv->module = g_module_open (path, G_MODULE_BIND_LAZY); } if (!priv->module) { g_warning ("%s: Cannot find shared library for %s plugin", G_STRFUNC, plugin_name); } g_free (plugin_dir); g_free (path); } if (priv->module && g_module_symbol (priv->module, symbol_name, &symbol)) return symbol; return NULL; }
static GModule *module_open(const char *name, int *found) { struct stat statbuf; GModule *module; char *path, *str; if (g_path_is_absolute(name) || *name == '~' || (*name == '.' && name[1] == G_DIR_SEPARATOR)) path = g_strdup(name); else { /* first try from home dir */ str = g_strdup_printf("%s/modules", get_irssi_dir()); path = g_module_build_path(str, name); g_free(str); if (stat(path, &statbuf) == 0) { module = g_module_open(path, (GModuleFlags) 0); g_free(path); *found = TRUE; return module; } /* module not found from home dir, try global module dir */ g_free(path); // MacIrssi, /usr/local/lib/foo isn't good on OSX path = g_module_build_path("Contents/Resources", name); } *found = stat(path, &statbuf) == 0; module = g_module_open(path, (GModuleFlags) 0); g_free(path); return module; }
/* perhaps these actions should be combined in one function */ void gdk_pixbuf_load_module (GdkPixbufModule *image_module) { char *module_name; char *path; GModule *module; gpointer load_sym; char *name; g_return_if_fail (image_module->module == NULL); name = image_module->module_name; module_name = g_strconcat ("pixbufloader-", name, NULL); path = g_module_build_path (PIXBUF_LIBDIR, module_name); module = g_module_open (path, G_MODULE_BIND_LAZY); if (!module) { /* Debug feature, check in present working directory */ g_free (path); path = g_module_build_path ("", module_name); module = g_module_open (path, G_MODULE_BIND_LAZY); if (!module) { g_warning ("Unable to load module: %s: %s", path, g_module_error ()); g_free (module_name); g_free (path); return; } g_free (path); } else { g_free (path); } g_free (module_name); image_module->module = module; if (pixbuf_module_symbol (module, name, "image_load", &load_sym)) image_module->load = load_sym; if (pixbuf_module_symbol (module, name, "image_load_xpm_data", &load_sym)) image_module->load_xpm_data = load_sym; if (pixbuf_module_symbol (module, name, "image_begin_load", &load_sym)) image_module->begin_load = load_sym; if (pixbuf_module_symbol (module, name, "image_stop_load", &load_sym)) image_module->stop_load = load_sym; if (pixbuf_module_symbol (module, name, "image_load_increment", &load_sym)) image_module->load_increment = load_sym; if (pixbuf_module_symbol (module, name, "image_load_animation", &load_sym)) image_module->load_animation = load_sym; }
gchar* mateconf_backend_file(const gchar* address) { gchar* back; gchar* file; gchar* retval; g_return_val_if_fail(address != NULL, NULL); back = mateconf_address_backend(address); if (back == NULL) return NULL; file = g_strconcat("mateconfbackend-", back, NULL); retval = g_module_build_path(MATECONF_BACKEND_DIR, file); g_free(back); if (mateconf_file_exists(retval)) { g_free(file); return retval; } else { /* -- debug only */ #ifdef MATECONF_ENABLE_DEBUG gchar* dir; g_free(retval); dir = g_strconcat(MATECONF_SRCDIR, "/mateconf/", MATECONF_BUILDDIR, "/backends/.libs", NULL); retval = g_module_build_path(dir, file); g_free(dir); if (mateconf_file_exists(retval)) { g_free(file); return retval; } #endif /* -- end debug only */ mateconf_log(GCL_ERR, _("No such file `%s'\n"), retval); g_free(file); g_free(retval); return NULL; } }
static void guile_main(void *closure, int argc, char ** argv) { GModule *gmodule; gchar *msg = "Module '../../../src/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n"; gchar *logdomain = "gnc.module"; gchar *modpath; guint loglevel = G_LOG_LEVEL_WARNING; TestErrorStruct check = { loglevel, logdomain, msg }; g_log_set_handler (logdomain, loglevel, (GLogFunc)test_checked_handler, &check); g_test_message(" test-dynload.c: testing dynamic linking of libgnc-module ..."); #ifdef G_OS_WIN32 /* MinGW builds libgnc-module-0.dll */ modpath = g_module_build_path ("../.libs", "gnc-module-0"); #elif defined(GNC_PLATFORM_OSX) /* We build libgnc-module as a shared library for testing, and on OSX * that means that g_module_build_path (), which uses ".so", doesn't * build the right path name. */ modpath = g_build_filename ("..", ".libs", "libgnc-module.dylib", NULL); #else /* Regular Unix */ modpath = g_module_build_path ("../.libs", "gnc-module"); #endif gmodule = g_module_open(modpath, 0); if (gmodule) { gpointer ptr; if (g_module_symbol(gmodule, "gnc_module_system_init", &ptr)) { void (* fn)(void) = ptr; fn(); printf(" OK\n"); exit(0); } else { printf(" failed to find gnc_module_system_init\n"); exit(-1); } } else { printf(" failed to open library.\n"); printf("%s\n", g_module_error()); exit(-1); } }
static void xfsm_splash_screen_load (XfsmSplashScreen *splash, const gchar *engine) { void (*init) (XfsmSplashEngine *engine); gchar *filename; filename = g_module_build_path (LIBDIR "/xfce4/session/splash-engines", engine); splash->module = g_module_open (filename, G_MODULE_BIND_LOCAL); g_free (filename); if (G_LIKELY (splash->module != NULL)) { if (g_module_symbol (splash->module, "engine_init", (gpointer)&init)) { init (&splash->engine); } else { g_module_close (splash->module); splash->module = NULL; } } else { g_warning ("Unable to load engine \"%s\": %s", engine, g_module_error ()); } }
static GMod* gmod_new (const char* module_name, gboolean is_resident) { if(!module_name) return NULL; GMod* gmod = g_new0(GMod, 1); gmod->name = g_strdup(module_name); if(!gmod->name) { g_free(gmod); return NULL; } gmod->path = g_module_build_path (MODULE_PATH_PREFIX, gmod->name); if(!gmod->path){ g_free(gmod->name); g_free(gmod); gmod->name = NULL; return NULL; } gmod->module = g_module_open(gmod->path, G_MODULE_BIND_LAZY); if(!gmod->module){ g_free(gmod->name); g_free(gmod->path); g_free(gmod); gmod->name = NULL; gmod->path = NULL; return NULL; } if(is_resident) g_module_make_resident(gmod->module); return gmod; }
static int pipeline_set_ruta(pipeline_t* p, const char * elemento, const char *ruta, const char *dir) { elemento_t *dato = g_hash_table_lookup(p->m_modulos, elemento); int dev = 0; if (ruta) { if (dato->m_handler) { g_module_close(dato->m_handler); } char *ruta_modulo = g_module_build_path(dir, ruta); dato->m_handler = g_module_open(ruta_modulo, G_MODULE_BIND_LAZY); if (dato->m_handler) { typedef modulo_t *(*funcion_modulo_t) (); funcion_modulo_t f; if(g_module_symbol(dato->m_handler, "get_modulo", (gpointer *)&f) != TRUE) { dev = -1; } else { dato->m_modulo = f ? f() : 0; dato->m_modulo->m_tabla = g_hash_table_new(g_str_hash, g_str_equal); } } else { dev = -1; } pipeline_salida_error(p, "Pipeline", "Bibliotecas", g_module_error()); } else { dev = -1; } return dev; }
static gboolean pluma_object_module_load (GTypeModule *gmodule) { PlumaObjectModule *module = PLUMA_OBJECT_MODULE (gmodule); PlumaObjectModuleRegisterFunc register_func; gchar *path; pluma_debug_message (DEBUG_PLUGINS, "Loading %s module from %s", module->priv->module_name, module->priv->path); path = g_module_build_path (module->priv->path, module->priv->module_name); g_return_val_if_fail (path != NULL, FALSE); pluma_debug_message (DEBUG_PLUGINS, "Module filename: %s", path); module->priv->library = g_module_open (path, G_MODULE_BIND_LAZY); g_free (path); if (module->priv->library == NULL) { g_warning ("%s: %s", module->priv->module_name, g_module_error()); return FALSE; } /* extract symbols from the lib */ if (!g_module_symbol (module->priv->library, module->priv->type_registration, (void *) ®ister_func)) { g_warning ("%s: %s", module->priv->module_name, g_module_error()); g_module_close (module->priv->library); return FALSE; } /* symbol can still be NULL even though g_module_symbol * returned TRUE */ if (register_func == NULL) { g_warning ("Symbol '%s' should not be NULL", module->priv->type_registration); g_module_close (module->priv->library); return FALSE; } module->priv->type = register_func (gmodule); if (module->priv->type == 0) { g_warning ("Invalid object contained by module %s", module->priv->module_name); return FALSE; } if (module->priv->resident) { g_module_make_resident (module->priv->library); } return TRUE; }
static gboolean load_storage_module (const char *module_name) { GModule *module; char *filename; filename = g_module_build_path (PLUGINDIR, module_name); module = g_module_open (filename, 0); g_free (filename); if (module == NULL) return FALSE; if (!g_module_symbol (module, "init", (gpointer *) &store.init) || !g_module_symbol (module, "deinit", (gpointer *) &store.deinit) || !g_module_symbol (module, "print_data_save", (gpointer *) &store.print_data_save) || !g_module_symbol (module, "print_data_load", (gpointer *) &store.print_data_load) || !g_module_symbol (module, "print_data_delete", (gpointer *) &store.print_data_delete) || !g_module_symbol (module, "discover_prints", (gpointer *) &store.discover_prints)) { g_module_close (module); return FALSE; } g_module_make_resident (module); return TRUE; }
static void init_dynamic_plugins_dir (gchar * dirname) { DIR * dir; struct dirent * dirent; char * path; struct stat statbuf; dir = opendir (dirname); if (!dir) { /* fail silently */ return; } while ((dirent = readdir (dir)) != NULL) { path = g_module_build_path (PACKAGE_PLUGIN_DIR, dirent->d_name); if (stat (path, &statbuf) == -1) { /* system error -- non-fatal, ignore for plugin loading */ } else if (sw_stat_regular (statbuf.st_mode)) { sweep_plugin_init (path); } } closedir (dir); }
/* ***************************************************************************** * load and initialize and external module */ gboolean nav_init (const gchar *mod_path, const gchar *mod_name) { gchar *t_path; nav_close (); t_path = g_module_build_path (mod_path, mod_name); nav_module = g_module_open (t_path, G_MODULE_BIND_LAZY); if (!nav_module) { g_print (_("WARNING: %s\n"), g_module_error ()); return FALSE; } if (!g_module_symbol (nav_module, "calculate_route", (gpointer *)&calculate_route)) { g_print (_("ERROR: %s\n"), g_module_error ()); nav_close (); return FALSE; } if (calculate_route == NULL) { g_print (_("ERROR: Missing symbol \"calculate_route\" in navigation module '%s'\n"), g_module_name (nav_module)); nav_close (); return FALSE; } g_print (_("Navigation module '%s' successfully loaded.\n"), g_module_name (nav_module)); return TRUE; }
static int dt_imageio_load_modules_storage(dt_imageio_t *iio) { iio->plugins_storage = NULL; dt_imageio_module_storage_t *module; char plugindir[PATH_MAX] = { 0 }, plugin_name[256]; const gchar *d_name; dt_loc_get_plugindir(plugindir, sizeof(plugindir)); g_strlcat(plugindir, "/plugins/imageio/storage", sizeof(plugindir)); GDir *dir = g_dir_open(plugindir, 0, NULL); if(!dir) return 1; const int name_offset = strlen(SHARED_MODULE_PREFIX), name_end = strlen(SHARED_MODULE_PREFIX) + strlen(SHARED_MODULE_SUFFIX); while((d_name = g_dir_read_name(dir))) { // get lib*.so if(!g_str_has_prefix(d_name, SHARED_MODULE_PREFIX)) continue; if(!g_str_has_suffix(d_name, SHARED_MODULE_SUFFIX)) continue; strncpy(plugin_name, d_name + name_offset, strlen(d_name) - name_end); plugin_name[strlen(d_name) - name_end] = '\0'; module = (dt_imageio_module_storage_t *)malloc(sizeof(dt_imageio_module_storage_t)); gchar *libname = g_module_build_path(plugindir, (const gchar *)plugin_name); if(dt_imageio_load_module_storage(module, libname, plugin_name)) { free(module); continue; } module->gui_data = NULL; module->gui_init(module); if(module->widget) g_object_ref(module->widget); g_free(libname); dt_imageio_insert_storage(module); } g_dir_close(dir); return 0; }
EvDocument * ev_backends_manager_get_document (const gchar *mime_type) { EvDocument *document; EvBackendInfo *info; info = ev_backends_manager_get_backend_info (mime_type); if (!info) return NULL; if (!info->module) { gchar *path; path = g_module_build_path (backends_dir(), info->module_name); info->module = G_TYPE_MODULE (ev_module_new (path, info->resident)); g_free (path); } if (!g_type_module_use (info->module)) { g_warning ("Cannot load backend '%s' since file '%s' cannot be read.", info->module_name, ev_module_get_path (EV_MODULE (info->module))); g_object_unref (G_OBJECT (info->module)); info->module = NULL; return NULL; } document = EV_DOCUMENT (ev_module_new_object (EV_MODULE (info->module))); g_type_module_unuse (info->module); return document; }
/* Note that, while this initialized mate-vfs, it does * not guarentee that mate-vfs actually loads and initializes * the modules in question */ int main (int argc, char **argv) { int i; GModule *module; TestFunc test_func; gboolean result; gboolean running_result; make_asserts_break ("GLib"); make_asserts_break ("MateVFS"); /* Initialize the libraries we use. */ mate_vfs_init (); running_result = TRUE; for (i=0 ; self_test_modules[i] != NULL ; i++) { char *module_path; char *dummy_uri_string; MateVFSURI *uri; printf ("Module self-test: '%s'\n", self_test_modules[i]); module_path = g_module_build_path (MODULES_PATH, self_test_modules[i]); module = g_module_open (module_path, G_MODULE_BIND_LAZY); g_free (module_path); module_path = NULL; if (module == NULL) { fprintf (stderr, "Couldn't load module '%s'\n", self_test_modules[i]); continue; } g_module_symbol (module, "vfs_module_self_test", (gpointer *) &test_func); if (test_func == NULL) { fprintf (stderr, "Module had no self-test func '%s'\n", self_test_modules[i]); continue; } dummy_uri_string = g_strdup_printf ("%s:///", self_test_modules[i]); /* force normal initializing of the module by creating a URI * for that scheme */ uri = mate_vfs_uri_new (dummy_uri_string); mate_vfs_uri_unref (uri); g_free (dummy_uri_string); result = test_func(); fprintf (stderr, "%s: %s\n", self_test_modules[i], result ? "PASS" : "FAIL"); running_result = running_result && result; } exit (running_result ? 0 : -1); }
static void search_module_in_paths(const char* plugin, GModule** module, const char* const* search_dir) { int search_dir_index = 0; while (!*module && search_dir[search_dir_index]) { char* path = g_module_build_path(search_dir[search_dir_index], plugin); *module = g_module_open(path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); g_free(path); ++search_dir_index; } }
/* * Automatically find GLib prefix and suffix of dynamic modules. */ static gboolean gdisp_findDynamicPrefixAndSuffix ( gchar **prefix, gchar **suffix ) { gchar *moduleName = (gchar*)NULL; gchar *fakePath = "fakePath"; gchar *sharp = "#"; gchar *localPrefix = (gchar*)NULL; gchar *localSuffix = (gchar*)NULL; /* * Init. */ *prefix = (gchar*)NULL; *suffix = (gchar*)NULL; /* * Create fake module name. */ moduleName = g_module_build_path(fakePath,sharp); if (strstr(moduleName,fakePath) != moduleName) { g_free(moduleName); return FALSE; } localPrefix = moduleName + strlen(fakePath); if (*localPrefix == G_DIR_SEPARATOR) { localPrefix++; } localSuffix = strstr(localPrefix,sharp); *localSuffix = '\0'; localSuffix++; /* * Return the strings. */ if (strlen(localPrefix) > 0) { *prefix = gdisp_strDup(localPrefix); } if (strlen(localSuffix) > 0) { *suffix = gdisp_strDup(localSuffix); } g_free(moduleName); return TRUE; }
GObject * object_from_module (GType type, const gchar *module_dir, const gchar *module_name, const gchar *first_property_name, ...) { va_list ap; GType *filters = NULL; GType child_type = G_TYPE_INVALID; guint n_filters; const gchar *fmt; gchar *module_filename; gchar *module_path; GObject *fnval = NULL; DmapdModule *module; va_start (ap, first_property_name); if (! (fmt = find_plugin_template (type))) { g_error ("Could not find plugin template"); } /* dmapd-dmap-db-ghashtable is built in because it is used by DmapdDMAPContainerRecord: */ if (! strcmp (module_name, "ghashtable")) { g_debug ("Not loading built in %s.", g_type_name (TYPE_DMAPD_DMAP_DB_GHASHTABLE)); child_type = TYPE_DMAPD_DMAP_DB_GHASHTABLE; fnval = g_object_new_valist (child_type, first_property_name, ap); } else { module_filename = g_strdup_printf (fmt, module_name); module_path = g_module_build_path (module_dir, module_filename); module = dmapd_module_new (module_path); if (module == NULL || ! g_type_module_use (G_TYPE_MODULE (module))) { g_warning ("Error opening %s", module_path); } else { /* FIXME: free filters */ filters = g_type_children (type, &n_filters); g_assert (n_filters == 1); g_assert (g_type_is_a (filters[0], type)); child_type = filters[0]; fnval = g_object_new_valist (child_type, first_property_name, ap); } if (filters) g_free (filters); g_free (module_filename); g_free (module_path); } va_end (ap); return fnval; }
static gboolean mmp_plugin_proxy_load_module (gchar *prefix) { MoonlightPlugin *plugin_host = MMP_HANDLE (); // Moonlight's loader is named libmoonloader if it is installed as a // package, and libmoonloaderxpi if it is installed as an XPI gchar *path = g_module_build_path (prefix, "moonloader"); if (!g_file_test (path, G_FILE_TEST_EXISTS)) { g_free (path); path = g_module_build_path (prefix, "moonloaderxpi"); if (!g_file_test (path, G_FILE_TEST_EXISTS)) { g_free (path); return FALSE; } } plugin_host->module = g_module_open (path, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY); if (plugin_host->module != NULL && mmp_plugin_proxy_load_symbol ("NP_Initialize", (gpointer *)&plugin_host->np_initialize) && mmp_plugin_proxy_load_symbol ("NP_Shutdown", (gpointer *)&plugin_host->np_shutdown) && mmp_plugin_proxy_load_symbol ("NP_GetValue", (gpointer *)&plugin_host->np_getvalue)) { mp_debug ("Loaded Moonlight plugin: %s", path); g_free (path); return TRUE; } else if (plugin_host->module != NULL) { if (!g_module_close (plugin_host->module)) { mp_error ("Could not unload library that was loaded but had invalid symbols: %s (%s)", path, g_module_error ()); } plugin_host->module = NULL; } mp_error ("Could not load Moonlight plugin: %s (%s)", path, g_module_error ()); g_free (path); return FALSE; }
void * ws_load_library(gchar *library_name) { gchar *full_path; wchar_t *full_path_w; HMODULE dll_h; if (!init_dll_load_paths() || !library_name) return NULL; /* First try the program directory */ full_path = g_module_build_path(program_path, library_name); full_path_w = g_utf8_to_utf16(full_path, -1, NULL, NULL, NULL); if (full_path && full_path_w) { dll_h = LoadLibraryW(full_path_w); if (dll_h) { g_free(full_path); g_free(full_path_w); return dll_h; } } /* Next try the system directory */ full_path = g_module_build_path(system_path, library_name); full_path_w = g_utf8_to_utf16(full_path, -1, NULL, NULL, NULL); if (full_path && full_path_w) { dll_h = LoadLibraryW(full_path_w); if (dll_h) { g_free(full_path); g_free(full_path_w); return dll_h; } } return NULL; }
static gboolean x11_available (void) { #ifdef HAVE_GMODULE gchar *x11_module_fname; if (lost_connection) return FALSE; if (x11_module != NULL) return TRUE; x11_module_fname = g_module_build_path (NULL, "X11"); x11_module = g_module_open (x11_module_fname, G_MODULE_BIND_LAZY); if (x11_module == NULL) x11_module = g_module_open ("libX11.so.6", G_MODULE_BIND_LAZY); g_free (x11_module_fname); if (x11_module == NULL) return FALSE; if (!g_module_symbol (x11_module, "XOpenDisplay", (void *) &func_XOpenDisplay)) goto cleanup; if (!g_module_symbol (x11_module, "XCloseDisplay", (void *) &func_XCloseDisplay)) goto cleanup; if (!g_module_symbol (x11_module, "XQueryPointer", (void *) &func_XQueryPointer)) goto cleanup; if (!g_module_symbol (x11_module, "XSetErrorHandler", (void *) &func_XSetErrorHandler)) goto cleanup; if (!g_module_symbol (x11_module, "XSetIOErrorHandler", (void *) &func_XSetIOErrorHandler)) goto cleanup; install_error_handlers (); return TRUE; cleanup: func_XOpenDisplay = 0; func_XCloseDisplay = 0; func_XQueryPointer = 0; func_XSetErrorHandler = 0; func_XSetIOErrorHandler = 0; g_module_close (x11_module); x11_module = NULL; return FALSE; #else install_error_handlers (); return !(lost_connection); #endif }
static GModule* plugin_open(char* module_name, char** search_path, gsize size_search_path) { int i; gchar* module_path; GModule* module; for (i=0; i < size_search_path; i++) { module_path = g_module_build_path(search_path[i], module_name); module = g_module_open(module_path, G_MODULE_BIND_LAZY); g_free(module_path); if (module) return module; } return g_module_open(module_name, G_MODULE_BIND_LAZY); }
int dt_lib_load_modules() { darktable.lib->plugins = NULL; GList *res = NULL; dt_lib_module_t *module; char plugindir[PATH_MAX] = { 0 }, plugin_name[256]; const gchar *d_name; dt_loc_get_plugindir(plugindir, sizeof(plugindir)); g_strlcat(plugindir, "/plugins/lighttable", sizeof(plugindir)); GDir *dir = g_dir_open(plugindir, 0, NULL); if(!dir) return 1; const int name_offset = strlen(SHARED_MODULE_PREFIX), name_end = strlen(SHARED_MODULE_PREFIX) + strlen(SHARED_MODULE_SUFFIX); while((d_name = g_dir_read_name(dir))) { // get lib*.(so|dll) if(!g_str_has_prefix(d_name, SHARED_MODULE_PREFIX)) continue; if(!g_str_has_suffix(d_name, SHARED_MODULE_SUFFIX)) continue; strncpy(plugin_name, d_name + name_offset, strlen(d_name) - name_end); plugin_name[strlen(d_name) - name_end] = '\0'; module = (dt_lib_module_t *)malloc(sizeof(dt_lib_module_t)); gchar *libname = g_module_build_path(plugindir, (const gchar *)plugin_name); if(dt_lib_load_module(module, libname, plugin_name)) { free(module); continue; } // TODO: init presets g_free(libname); res = g_list_insert_sorted(res, module, dt_lib_sort_plugins); dt_lib_init_presets(module); // Calling the keyboard shortcut initialization callback if present // do not init accelerators if there is no gui if(darktable.gui) { if(module->init_key_accels) module->init_key_accels(module); module->gui_init(module); g_object_ref_sink(module->widget); } } g_dir_close(dir); darktable.lib->plugins = res; return 0; }
int gen_cnode_module_load_required( gen_cnode_module_t* module ){ int rc = 0; int i; gboolean sym = FALSE; const char* (*fp) (int) = NULL; if( !module || module->reqs ){ rc = -EINVAL; goto load_required_exit; } sym = g_module_symbol( module->lib, "GEN_CNODE_REQUIRED", ((gpointer*)&fp) ); if( !sym ){ printf("DEBUG: No prereqs detected\n"); } else { for( i=0; fp(i); i++ ){ GModule* lib = NULL; char* fullname = NULL; //Stitch together full filename based on LD_LIBRARY_PATH fullname = g_module_build_path( NULL, fp(i) ); printf("DEBUG: Attempting to open %s...\n", fullname); //Attempt to load the module lib = g_module_open( fullname, (GModuleFlags)0 ); if( !lib ){ rc = -EINVAL; g_free(fullname); goto load_required_exit; } //Not intending on using this pointer as all symbols //for the library are bound globally, but will store //them for later removal should the module be unloaded. module->reqs = g_list_append(module->reqs, lib); g_free(fullname); } } load_required_exit: return rc; }
static void load_plugins (KaPluginLoader *self) { int i; KaPluginLoaderPrivate *priv = GET_PRIVATE (self); GSettings *settings; char **plugins = NULL; if (!g_module_supported ()) { g_warning ("GModules are not supported on your platform!"); return; } settings = g_settings_get_child(ka_applet_get_settings (priv->applet), KA_SETTING_CHILD_PLUGINS); /* For now we only load the plugins on program startup */ plugins = g_settings_get_strv(settings, KA_SETTING_KEY_PLUGINS_ENABLED); if (!plugins) { g_message ("No plugins to load"); return; } for (i = 0; plugins[i]; i++) { char *path; char *fname; KaPlugin *plugin; fname = g_strdup_printf("libka-plugin-%s.%s", plugins[i], G_MODULE_SUFFIX); path = g_module_build_path (KA_PLUGINS_DIR, fname); plugin = load_plugin (path); if (plugin) { ka_plugin_activate(plugin, priv->applet); priv->active_plugins = g_slist_prepend (priv->active_plugins, plugin); } g_free (fname); g_free (path); } g_strfreev (plugins); g_object_unref (settings); }
/* Creates 'module' object which resolves symbol names to lightuserdata addresses. module, path = core.module(basename[, version]) */ static int core_module (lua_State *L) { char *name; /* If the version is present, combine it with basename. Except on OpenBSD, where libraries are versioned like libfoo.so.0.0 and we will always load the shared object with the highest version number. */ #ifndef __OpenBSD__ if (!lua_isnoneornil (L, 2)) name = g_strdup_printf (MODULE_NAME_FORMAT_VERSION, luaL_checkstring (L, 1), (int) luaL_checkinteger (L, 2)); else #endif name = g_strdup_printf (MODULE_NAME_FORMAT_PLAIN, luaL_checkstring (L, 1)); #if defined(__APPLE__) char *path = g_module_build_path (GOBJECT_INTROSPECTION_LIBDIR, name); g_free(name); name = path; #endif /* Try to load the module. */ GModule *module = g_module_open (name, 0); if (module == NULL) { lua_pushnil (L); goto end; } /* Embed the module in the userdata for the module. */ *(GModule **) lua_newuserdata (L, sizeof (module)) = module; luaL_getmetatable (L, UD_MODULE); lua_setmetatable (L, -2); end: lua_pushstring (L, name); g_free (name); return 2; }
GObject * gnome_window_manager_new (GnomeDesktopItem *it) { const char *settings_lib; char *module_name; GnomeWindowManagerNewFunc wm_new_func = NULL; GObject *wm; GModule *module; gboolean success; settings_lib = gnome_desktop_item_get_string (it, "X-GNOME-WMSettingsModule"); module_name = g_module_build_path (GNOME_WINDOW_MANAGER_MODULE_PATH, settings_lib); module = g_module_open (module_name, G_MODULE_BIND_LAZY); if (module == NULL) { g_warning ("Couldn't load window manager settings module `%s' (%s)", module_name, g_module_error ()); g_free (module_name); return NULL; } success = g_module_symbol (module, "window_manager_new", (gpointer *) &wm_new_func); if ((!success) || wm_new_func == NULL) { g_warning ("Couldn't load window manager settings module `%s`, couldn't find symbol \'window_manager_new\'", module_name); g_free (module_name); return NULL; } g_free (module_name); wm = (* wm_new_func) (GNOME_WINDOW_MANAGER_INTERFACE_VERSION); if (wm == NULL) return NULL; (GNOME_WINDOW_MANAGER (wm))->p->window_manager_name = g_strdup (gnome_desktop_item_get_string (it, GNOME_DESKTOP_ITEM_NAME)); (GNOME_WINDOW_MANAGER (wm))->p->ditem = gnome_desktop_item_ref (it); return wm; }
int dt_lib_load_modules () { darktable.lib->plugins = NULL; GList *res = NULL; dt_lib_module_t *module; char plugindir[1024], plugin_name[256]; const gchar *d_name; dt_loc_get_plugindir(plugindir, 1024); g_strlcat(plugindir, "/plugins/lighttable", 1024); GDir *dir = g_dir_open(plugindir, 0, NULL); if(!dir) return 1; while((d_name = g_dir_read_name(dir))) { // get lib*.so if(strncmp(d_name, "lib", 3)) continue; if(strncmp(d_name + strlen(d_name) - 3, ".so", 3)) continue; strncpy(plugin_name, d_name+3, strlen(d_name)-6); plugin_name[strlen(d_name)-6] = '\0'; module = (dt_lib_module_t *)malloc(sizeof(dt_lib_module_t)); gchar *libname = g_module_build_path(plugindir, (const gchar *)plugin_name); if(dt_lib_load_module(module, libname, plugin_name)) { free(module); continue; } // TODO: init presets g_free(libname); res = g_list_insert_sorted(res, module, dt_lib_sort_plugins); init_presets(module); // Calling the keyboard shortcut initialization callback if present if(module->init_key_accels) module->init_key_accels(module); } g_dir_close(dir); darktable.lib->plugins = res; return 0; }