/* return value means the number of successfully loaded plugins */ static int enumerate_plugins(const gchar *plugin_path, GPtrArray *plugin_array, GOptionContext *ctx) { GDir *dir; const gchar *fname; dir = g_dir_open(plugin_path, 0, NULL); if (!dir) { ERROR("unable to open plugin directory %s (err=%s)\n", plugin_path, strerror(errno)); return 0; } DEBUG("search for plugins in directory %s\n", plugin_path); /* add common options to help context: */ g_option_context_add_main_entries(ctx, loggen_options, 0); GModule *module = NULL; while ((fname = g_dir_read_name(dir))) { if (!g_str_has_suffix(fname,G_MODULE_SUFFIX)) continue; gchar *full_lib_path = g_build_filename(plugin_path,fname,NULL); module = g_module_open(full_lib_path, G_MODULE_BIND_LAZY); if (!module) { ERROR("error opening plugin module %s (%s)\n", fname, g_module_error()); continue; } /* get plugin info from lib file */ PluginInfo *plugin; if (!g_module_symbol(module, LOGGEN_PLUGIN_INFO, (gpointer *) &plugin)) { DEBUG("%s isn't a plugin for loggen. skip it. (%s)\n", fname, g_module_error()); g_module_close(module); continue; } if (is_plugin_already_loaded(plugin_array, plugin->name)) { DEBUG("plugin %s was already loaded. skip it\n", plugin->name); continue; } if (plugin->set_generate_message) plugin->set_generate_message(generate_message); else ERROR("plugin (%s) doesn't have set_generate_message function\n",plugin->name); g_ptr_array_add(plugin_array, (gpointer) plugin); /* create sub group for plugin specific parameters: */ GOptionGroup *group = g_option_group_new(plugin->name, plugin->name, "Show options", NULL, NULL); g_option_group_add_entries(group, plugin->get_options_list()); g_option_context_add_group(ctx, group); DEBUG("%s in %s is a loggen plugin\n", plugin->name, fname); } if (plugin_array->len == 0) { ERROR("no loggen plugin found in %s\n", plugin_path); } return plugin_array->len; }
PurplePlugin * purple_plugin_probe(const char *filename) { #ifdef PURPLE_PLUGINS PurplePlugin *plugin = NULL; PurplePlugin *loader; gpointer unpunned; gchar *basename = NULL; gboolean (*purple_init_plugin)(PurplePlugin *); purple_debug_misc("plugins", "probing %s\n", filename); g_return_val_if_fail(filename != NULL, NULL); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) return NULL; /* If this plugin has already been probed then exit */ basename = purple_plugin_get_basename(filename); plugin = purple_plugins_find_with_basename(basename); g_free(basename); if (plugin != NULL) { if (purple_strequal(filename, plugin->path)) return plugin; else if (!purple_plugin_is_unloadable(plugin)) { purple_debug_warning("plugins", "Not loading %s. " "Another plugin with the same name (%s) has already been loaded.\n", filename, plugin->path); return plugin; } else { /* The old plugin was a different file and it was unloadable. * There's no guarantee that this new file with the same name * will be loadable, but unless it fails in one of the silent * ways and the first one didn't, it's not any worse. The user * will still see a greyed-out plugin, which is what we want. */ purple_plugin_destroy(plugin); } } plugin = purple_plugin_new(has_file_extension(filename, G_MODULE_SUFFIX), filename); if (plugin->native_plugin) { const char *error; #ifdef _WIN32 /* Suppress error popups for failing to load plugins */ UINT old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS); #endif /* * We pass G_MODULE_BIND_LOCAL here to prevent symbols from * plugins being added to the global name space. * * G_MODULE_BIND_LOCAL was added in glib 2.3.3. */ plugin->handle = g_module_open(filename, G_MODULE_BIND_LOCAL); if (plugin->handle == NULL) { const char *error = g_module_error(); if (error != NULL && purple_str_has_prefix(error, filename)) { error = error + strlen(filename); /* These are just so we don't crash. If we * got this far, they should always be true. */ if (*error == ':') error++; if (*error == ' ') error++; } if (error == NULL || !*error) { plugin->error = g_strdup(_("Unknown error")); purple_debug_error("plugins", "%s is not loadable: Unknown error\n", plugin->path); } else { plugin->error = g_strdup(error); purple_debug_error("plugins", "%s is not loadable: %s\n", plugin->path, plugin->error); } plugin->handle = g_module_open(filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (plugin->handle == NULL) { #ifdef _WIN32 /* Restore the original error mode */ SetErrorMode(old_error_mode); #endif purple_plugin_destroy(plugin); return NULL; } else { /* We were able to load the plugin with lazy symbol binding. * This means we're missing some symbol. Mark it as * unloadable and keep going so we get the info to display * to the user so they know to rebuild this plugin. */ plugin->unloadable = TRUE; } } if (!g_module_symbol(plugin->handle, "purple_init_plugin", &unpunned)) { purple_debug_error("plugins", "%s is not usable because the " "'purple_init_plugin' symbol could not be " "found. Does the plugin call the " "PURPLE_INIT_PLUGIN() macro?\n", plugin->path); g_module_close(plugin->handle); error = g_module_error(); if (error != NULL) purple_debug_error("plugins", "Error closing module %s: %s\n", plugin->path, error); plugin->handle = NULL; #ifdef _WIN32 /* Restore the original error mode */ SetErrorMode(old_error_mode); #endif purple_plugin_destroy(plugin); return NULL; } purple_init_plugin = unpunned; #ifdef _WIN32 /* Restore the original error mode */ SetErrorMode(old_error_mode); #endif } else { loader = find_loader_for_plugin(plugin); if (loader == NULL) { purple_plugin_destroy(plugin); return NULL; } purple_init_plugin = PURPLE_PLUGIN_LOADER_INFO(loader)->probe; } if (!purple_init_plugin(plugin) || plugin->info == NULL) { purple_plugin_destroy(plugin); return NULL; } else if (plugin->info->ui_requirement && !purple_strequal(plugin->info->ui_requirement, purple_core_get_ui())) { plugin->error = g_strdup_printf(_("You are using %s, but this plugin requires %s."), purple_core_get_ui(), plugin->info->ui_requirement); purple_debug_error("plugins", "%s is not loadable: The UI requirement is not met. (%s)\n", plugin->path, plugin->error); plugin->unloadable = TRUE; return plugin; } /* * Check to make sure a plugin has defined an id. * Not having this check caused purple_plugin_unload to * enter an infinite loop in certain situations by passing * purple_find_plugin_by_id a NULL value. -- ecoffey */ if (plugin->info->id == NULL || *plugin->info->id == '\0') { plugin->error = g_strdup(_("This plugin has not defined an ID.")); purple_debug_error("plugins", "%s is not loadable: info->id is not defined.\n", plugin->path); plugin->unloadable = TRUE; return plugin; } /* Really old plugins. */ if (plugin->info->magic != PURPLE_PLUGIN_MAGIC) { if (plugin->info->magic >= 2 && plugin->info->magic <= 4) { struct _PurplePluginInfo2 { unsigned int api_version; PurplePluginType type; char *ui_requirement; unsigned long flags; GList *dependencies; PurplePluginPriority priority; char *id; char *name; char *version; char *summary; char *description; char *author; char *homepage; gboolean (*load)(PurplePlugin *plugin); gboolean (*unload)(PurplePlugin *plugin); void (*destroy)(PurplePlugin *plugin); void *ui_info; void *extra_info; PurplePluginUiInfo *prefs_info; GList *(*actions)(PurplePlugin *plugin, gpointer context); } *info2 = (struct _PurplePluginInfo2 *)plugin->info; /* This leaks... but only for ancient plugins, so deal with it. */ plugin->info = g_new0(PurplePluginInfo, 1); /* We don't really need all these to display the plugin info, but * I'm copying them all for good measure. */ plugin->info->magic = info2->api_version; plugin->info->type = info2->type; plugin->info->ui_requirement = info2->ui_requirement; plugin->info->flags = info2->flags; plugin->info->dependencies = info2->dependencies; plugin->info->id = info2->id; plugin->info->name = info2->name; plugin->info->version = info2->version; plugin->info->summary = info2->summary; plugin->info->description = info2->description; plugin->info->author = info2->author; plugin->info->homepage = info2->homepage; plugin->info->load = info2->load; plugin->info->unload = info2->unload; plugin->info->destroy = info2->destroy; plugin->info->ui_info = info2->ui_info; plugin->info->extra_info = info2->extra_info; if (info2->api_version >= 3) plugin->info->prefs_info = info2->prefs_info; if (info2->api_version >= 4) plugin->info->actions = info2->actions; plugin->error = g_strdup_printf(_("Plugin magic mismatch %d (need %d)"), plugin->info->magic, PURPLE_PLUGIN_MAGIC); purple_debug_error("plugins", "%s is not loadable: Plugin magic mismatch %d (need %d)\n", plugin->path, plugin->info->magic, PURPLE_PLUGIN_MAGIC); plugin->unloadable = TRUE; return plugin; } purple_debug_error("plugins", "%s is not loadable: Plugin magic mismatch %d (need %d)\n", plugin->path, plugin->info->magic, PURPLE_PLUGIN_MAGIC); purple_plugin_destroy(plugin); return NULL; } if (plugin->info->major_version != PURPLE_MAJOR_VERSION || plugin->info->minor_version > PURPLE_MINOR_VERSION) { plugin->error = g_strdup_printf(_("ABI version mismatch %d.%d.x (need %d.%d.x)"), plugin->info->major_version, plugin->info->minor_version, PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION); purple_debug_error("plugins", "%s is not loadable: ABI version mismatch %d.%d.x (need %d.%d.x)\n", plugin->path, plugin->info->major_version, plugin->info->minor_version, PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION); plugin->unloadable = TRUE; return plugin; } if (plugin->info->type == PURPLE_PLUGIN_PROTOCOL) { /* If plugin is a PRPL, make sure it implements the required functions */ if ((PURPLE_PLUGIN_PROTOCOL_INFO(plugin)->list_icon == NULL) || (PURPLE_PLUGIN_PROTOCOL_INFO(plugin)->login == NULL) || (PURPLE_PLUGIN_PROTOCOL_INFO(plugin)->close == NULL)) { plugin->error = g_strdup(_("Plugin does not implement all required functions (list_icon, login and close)")); purple_debug_error("plugins", "%s is not loadable: %s\n", plugin->path, plugin->error); plugin->unloadable = TRUE; return plugin; } /* For debugging, let's warn about prpl prefs. */ if (plugin->info->prefs_info != NULL) { purple_debug_error("plugins", "%s has a prefs_info, but is a prpl. This is no longer supported.\n", plugin->path); } } return plugin; #else return NULL; #endif /* !PURPLE_PLUGINS */ }
static int dt_imageio_load_module_format (dt_imageio_module_format_t *module, const char *libname, const char *plugin_name) { module->widget = NULL; module->parameter_lua_type = LUAA_INVALID_TYPE; g_strlcpy(module->plugin_name, plugin_name, sizeof(module->plugin_name)); module->module = g_module_open(libname, G_MODULE_BIND_LAZY); if(!module->module) goto error; int (*version)(); if(!g_module_symbol(module->module, "dt_module_dt_version", (gpointer)&(version))) goto error; if(version() != dt_version()) { fprintf(stderr, "[imageio_load_module] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n", libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()), dt_version() < 0 ? "debug" : "opt"); goto error; } if(!g_module_symbol(module->module, "name", (gpointer)&(module->name))) goto error; if(!g_module_symbol(module->module, "init", (gpointer)&(module->init))) goto error; if(!g_module_symbol(module->module, "cleanup", (gpointer)&(module->cleanup))) goto error; if(!g_module_symbol(module->module, "gui_reset", (gpointer)&(module->gui_reset))) goto error; if(darktable.gui) { if(!g_module_symbol(module->module, "gui_init", (gpointer)&(module->gui_init))) goto error; } else { module->gui_init = _default_format_gui_init; } if(!g_module_symbol(module->module, "gui_cleanup", (gpointer)&(module->gui_cleanup))) goto error; if(!g_module_symbol(module->module, "mime", (gpointer)&(module->mime))) goto error; if(!g_module_symbol(module->module, "extension", (gpointer)&(module->extension))) goto error; if(!g_module_symbol(module->module, "dimension", (gpointer)&(module->dimension))) module->dimension = _default_format_dimension; if(!g_module_symbol(module->module, "params_size", (gpointer)&(module->params_size))) goto error; if(!g_module_symbol(module->module, "get_params", (gpointer)&(module->get_params))) goto error; if(!g_module_symbol(module->module, "free_params", (gpointer)&(module->free_params))) goto error; if(!g_module_symbol(module->module, "set_params", (gpointer)&(module->set_params))) goto error; if(!g_module_symbol(module->module, "write_image", (gpointer)&(module->write_image))) goto error; if(!g_module_symbol(module->module, "bpp", (gpointer)&(module->bpp))) goto error; if(!g_module_symbol(module->module, "flags", (gpointer)&(module->flags))) module->flags = _default_format_flags; if(!g_module_symbol(module->module, "levels", (gpointer)&(module->levels))) module->levels = _default_format_levels; if(!g_module_symbol(module->module, "read_image", (gpointer)&(module->read_image))) module->read_image = NULL; #ifdef USE_LUA { char pseudo_type_name[1024]; snprintf(pseudo_type_name,sizeof(pseudo_type_name),"dt_imageio_module_format_data_%s",module->plugin_name); luaA_Type my_type = luaA_type_add(darktable.lua_state.state,pseudo_type_name,module->params_size(module)); module->parameter_lua_type = dt_lua_init_type_type(darktable.lua_state.state,my_type); luaA_struct_type(darktable.lua_state.state,my_type); dt_lua_register_format_type(darktable.lua_state.state,module,my_type); #endif module->init(module); #ifdef USE_LUA lua_pushcfunction(darktable.lua_state.state,dt_lua_type_member_luaautoc); dt_lua_type_register_struct_type(darktable.lua_state.state,my_type); } #endif return 0; error: fprintf(stderr, "[imageio_load_module] failed to open format `%s': %s\n", plugin_name, g_module_error()); if(module->module) g_module_close(module->module); return 1; }
bool PluginPackage::fetchInfo() { #if defined(XP_UNIX) if (!load()) return false; NP_GetMIMEDescriptionFuncPtr NP_GetMIMEDescription = 0; NPP_GetValueProcPtr NPP_GetValue = 0; g_module_symbol(m_module, "NP_GetMIMEDescription", (void**)&NP_GetMIMEDescription); g_module_symbol(m_module, "NP_GetValue", (void**)&NPP_GetValue); if (!NP_GetMIMEDescription || !NPP_GetValue) return false; char* buffer = 0; NPError err = NPP_GetValue(0, NPPVpluginNameString, &buffer); if (err == NPERR_NO_ERROR) m_name = buffer; buffer = 0; err = NPP_GetValue(0, NPPVpluginDescriptionString, &buffer); if (err == NPERR_NO_ERROR) { m_description = buffer; determineModuleVersionFromDescription(); } const gchar* types = NP_GetMIMEDescription(); if (!types) return true; gchar** mimeDescs = g_strsplit(types, ";", -1); for (int i = 0; mimeDescs[i] && mimeDescs[i][0]; i++) { gchar** mimeData = g_strsplit(mimeDescs[i], ":", 3); if (g_strv_length(mimeData) < 3) { g_strfreev(mimeData); continue; } String description = String::fromUTF8(mimeData[2]); gchar** extensions = g_strsplit(mimeData[1], ",", -1); Vector<String> extVector; for (int j = 0; extensions[j]; j++) extVector.append(String::fromUTF8(extensions[j])); determineQuirks(mimeData[0]); m_mimeToExtensions.add(mimeData[0], extVector); m_mimeToDescriptions.add(mimeData[0], description); g_strfreev(extensions); g_strfreev(mimeData); } g_strfreev(mimeDescs); return true; #else notImplemented(); return false; #endif }
/* * XXX - when we remove support for old-style plugins (which we should * probably do eventually, as all plugins should be written as new-style * ones), we may want to have "init_plugins()" merely save a pointer * to the plugin's "init" routine, just as we save a pointer to its * "reg_handoff" routine, and have a "register_all_plugins()" routine * to go through the list of plugins and call all of them. * * Then we'd have "epan_init()", or perhaps even something higher up * in the call tree, call "init_plugins()", and have "proto_init()" * call "register_all_plugins()" right after calling "register_all_protocols()"; * this might be a bit cleaner. */ static void plugins_scan_dir(const char *dirname) { #define FILENAME_LEN 1024 WS_DIR *dir; /* scanned directory */ WS_DIRENT *file; /* current file */ const char *name; gchar filename[FILENAME_LEN]; /* current file name */ GModule *handle; /* handle returned by g_module_open */ gchar *version; gpointer gp; void (*register_protoinfo)(void); void (*reg_handoff)(void); void (*register_tap_listener)(void); void (*register_wtap_module)(void); void (*register_codec_module)(void); gchar *dot; int cr; if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL) { while ((file = ws_dir_read_name(dir)) != NULL) { name = ws_dir_get_name(file); /* * GLib 2.x defines G_MODULE_SUFFIX as the extension used on * this platform for loadable modules. */ /* skip anything but files with G_MODULE_SUFFIX */ dot = strrchr(name, '.'); if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0) continue; g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s", dirname, name); if ((handle = g_module_open(filename, 0)) == NULL) { report_failure("Couldn't load module %s: %s", filename, g_module_error()); continue; } if (!g_module_symbol(handle, "version", &gp)) { report_failure("The plugin %s has no version symbol", name); g_module_close(handle); continue; } version = gp; /* * Do we have a register routine? */ if (g_module_symbol(handle, "plugin_register", &gp)) { /* * Yes - this plugin includes one or more dissectors. */ register_protoinfo = gp; } else { /* * No - no dissectors. */ register_protoinfo = NULL; } /* * Do we have a reg_handoff routine? */ if (g_module_symbol(handle, "plugin_reg_handoff", &gp)) { /* * Yes. */ reg_handoff = gp; } else { /* * No - that's OK even if we have dissectors, as long * as the plugin registers by name *and* there's * a caller looking for that name. */ reg_handoff = NULL; } /* * Do we have a register_tap_listener routine? */ if (g_module_symbol(handle, "plugin_register_tap_listener", &gp)) { /* * Yes - this plugin includes one or more taps. */ register_tap_listener = gp; } else { /* * No - no taps here. */ register_tap_listener = NULL; } /* * Do we have an old-style init routine? */ if (g_module_symbol(handle, "plugin_init", &gp)) { /* * Yes - do we also have a register routine or a * register_tap_listener routine? If so, this is a bogus * hybrid of an old-style and new-style plugin. */ if (register_protoinfo != NULL || register_tap_listener != NULL) { report_failure("The plugin '%s' has an old plugin init routine\nand a new register or register_tap_listener routine.", name); g_module_close(handle); continue; } /* * It's just an unsupported old-style plugin; */ report_failure("The plugin '%s' has an old plugin init routine. Support has been dropped.\n Information on how to update your plugin is available at \nhttp://anonsvn.wireshark.org/wireshark/trunk/doc/README.plugins", name); g_module_close(handle); continue; } /* * Do we have a register_wtap_module routine? */ if (g_module_symbol(handle, "register_wtap_module", &gp)) { register_wtap_module = gp; } else { register_wtap_module = NULL; } /* * Do we have a register_codec_module routine? */ if (g_module_symbol(handle, "register_codec_module", &gp)) { register_codec_module = gp; } else { register_codec_module = NULL; } /* * Does this dissector do anything useful? */ if (register_protoinfo == NULL && register_tap_listener == NULL && register_wtap_module == NULL && register_codec_module == NULL ) { /* * No. */ report_failure("The plugin '%s' has neither a register routine, " "a register_tap_listener or a register_wtap_module or a register_codec_module routine", name); g_module_close(handle); continue; } /* * OK, attempt to add it to the list of plugins. */ if ((cr = add_plugin(handle, g_strdup(name), version, register_protoinfo, reg_handoff, register_tap_listener,register_wtap_module,register_codec_module))) { if (cr == EEXIST) fprintf(stderr, "The plugin %s, version %s\n" "was found in multiple directories\n", name, version); else fprintf(stderr, "Memory allocation problem\n" "when processing plugin %s, version %s\n", name, version); g_module_close(handle); continue; } } ws_dir_close(dir); } }
static gboolean ToolsCoreLoadDirectory(ToolsAppCtx *ctx, const gchar *pluginPath, GPtrArray *regs) { gboolean ret = FALSE; const gchar *staticEntry; guint i; GDir *dir = NULL; GError *err = NULL; GPtrArray *plugins; dir = g_dir_open(pluginPath, 0, &err); if (dir == NULL) { g_warning("Error opening dir: %s\n", err->message); goto exit; } plugins = g_ptr_array_new(); /* * Load plugins in alphabetical order, so the load order is the same * regardless of how the filesystem returns entries. */ while ((staticEntry = g_dir_read_name(dir)) != NULL) { if (g_str_has_suffix(staticEntry, "." G_MODULE_SUFFIX)) { g_ptr_array_add(plugins, g_strdup(staticEntry)); } } g_dir_close(dir); g_ptr_array_sort(plugins, ToolsCoreStrPtrCompare); for (i = 0; i < plugins->len; i++) { gchar *entry; gchar *path; GModule *module = NULL; ToolsPlugin *plugin = NULL; ToolsPluginOnLoad onload; entry = g_ptr_array_index(plugins, i); path = g_strdup_printf("%s%c%s", pluginPath, DIRSEPC, entry); if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) { g_warning("File '%s' is not a regular file, skipping.\n", entry); goto next; } #ifdef USE_APPLOADER /* Trying loading the plugins with system libraries */ if (!LoadDependencies(path, FALSE)) { g_warning("Loading of library dependencies for %s failed.\n", entry); goto next; } #endif module = g_module_open(path, G_MODULE_BIND_LOCAL); #ifdef USE_APPLOADER if (module == NULL) { /* Falling back to the shipped libraries */ if (!LoadDependencies(path, TRUE)) { g_warning("Loading of shipped library dependencies for %s failed.\n", entry); goto next; } module = g_module_open(path, G_MODULE_BIND_LOCAL); } #endif if (module == NULL) { g_warning("Opening plugin '%s' failed: %s.\n", entry, g_module_error()); goto next; } if (!g_module_symbol(module, "ToolsOnLoad", (gpointer *) &onload)) { g_warning("Lookup of plugin entry point for '%s' failed.\n", entry); goto next; } plugin = g_malloc(sizeof *plugin); plugin->fileName = entry; plugin->data = NULL; plugin->module = module; plugin->onload = onload; g_ptr_array_add(regs, plugin); next: g_free(path); if (plugin == NULL && module != NULL) { if (!g_module_close(module)) { g_warning("Error unloading plugin '%s': %s\n", entry, g_module_error()); } } } g_ptr_array_free(plugins, TRUE); ret = TRUE; exit: return ret; }
GkrellmMonitor * install_plugin(gchar *plugin_name) { GList *list; GModule *module; GkrellmMonitor *m, *mm; GkrellmMonitor *(*init_plugin)(); gchar buf[256]; static GkrellmMonitor mon_tmp; if (!g_module_supported()) return NULL; module = g_module_open(plugin_name, 0); plugin_log(plugin_name, "\n", NULL); if (! module) { snprintf(buf, sizeof(buf), _("\tError: %s\n"), g_module_error()); plugin_log(buf, NULL); return NULL; } if (!g_module_symbol(module, "gkrellm_init_plugin", (gpointer) &init_plugin)) { snprintf(buf, sizeof(buf), _("\tError: %s\n"), g_module_error()); plugin_log(buf, NULL); g_module_close(module); return NULL; } _GK.no_messages = TRUE; /* Enforce policy */ mon_tmp.name = g_strdup(plugin_name); gkrellm_record_state(INIT_MONITOR, &mon_tmp); #if defined(WIN32) { win32_plugin_callbacks ** plugin_cb = NULL; if (!g_module_symbol(module, "callbacks", (gpointer) &plugin_cb)) { snprintf(buf, sizeof(buf), _("\tError: %s\n"), g_module_error()); plugin_log(buf, NULL); g_module_close(module); return NULL; } *plugin_cb = &gkrellm_callbacks; } #endif m = (*init_plugin)(); _GK.no_messages = FALSE; g_free(mon_tmp.name); mon_tmp.name = NULL; gkrellm_record_state(INTERNAL, NULL); if (m == NULL) { plugin_log(_("\tOoops! plugin returned NULL, aborting\n"), NULL); g_module_close(module); return NULL; } for (list = gkrellm_monitor_list; list; list = list->next) { mm = (GkrellmMonitor *) list->data; if ( !mm->privat || !mm->privat->style_name || !m->privat || !m->privat->style_name || strcmp(mm->privat->style_name, m->privat->style_name) ) continue; plugin_log(_("\tWarning: style name \""), m->privat->style_name, _("\" already used by:\n\t\t"), mm->path, "\n", NULL); } for (list = gkrellm_monitor_list; list; list = list->next) { mm = (GkrellmMonitor *) list->data; if ( !mm->config_keyword || !m->config_keyword || strcmp(mm->config_keyword, m->config_keyword) ) continue; plugin_log(_("\tWarning: config keyword \""), m->config_keyword, _("\" already used by:\n\t\t"), mm->path, "\n", NULL); } m->handle = module; m->path = plugin_name; if (!m->name) m->name = g_path_get_basename(m->path); if (m->privat == NULL) /* Won't be null if style was added */ m->privat = g_new0(GkrellmMonprivate, 1); m->privat->enabled = TRUE; /* Enforce some id fields. */ m->id &= ~(MON_ID_MASK | MON_CONFIG_MASK); m->id |= MON_PLUGIN; if (PLUGIN_INSERT_BEFORE_ID(m) >= N_BUILTIN_MONITORS) m->insert_before_id = MON_UPTIME; if (!user_placement(m)) { m->privat->insert_before_id = PLUGIN_INSERT_BEFORE_ID(m); m->privat->gravity = PLUGIN_GRAVITY(m); m->privat->insert_after = PLUGIN_INSERT_AFTER(m); } gkrellm_place_plugin(&gkrellm_monitor_list, m); return m; }
static void vte_register_symbols(GModule *mod) { g_module_symbol(mod, "vte_terminal_new", (void*)&vf->vte_terminal_new); g_module_symbol(mod, "vte_terminal_set_size", (void*)&vf->vte_terminal_set_size); g_module_symbol(mod, "vte_terminal_fork_command", (void*)&vf->vte_terminal_fork_command); g_module_symbol(mod, "vte_terminal_set_word_chars", (void*)&vf->vte_terminal_set_word_chars); g_module_symbol(mod, "vte_terminal_set_mouse_autohide", (void*)&vf->vte_terminal_set_mouse_autohide); g_module_symbol(mod, "vte_terminal_reset", (void*)&vf->vte_terminal_reset); g_module_symbol(mod, "vte_terminal_get_type", (void*)&vf->vte_terminal_get_type); g_module_symbol(mod, "vte_terminal_set_scroll_on_output", (void*)&vf->vte_terminal_set_scroll_on_output); g_module_symbol(mod, "vte_terminal_set_scroll_on_keystroke", (void*)&vf->vte_terminal_set_scroll_on_keystroke); g_module_symbol(mod, "vte_terminal_set_font_from_string", (void*)&vf->vte_terminal_set_font_from_string); g_module_symbol(mod, "vte_terminal_set_scrollback_lines", (void*)&vf->vte_terminal_set_scrollback_lines); g_module_symbol(mod, "vte_terminal_get_has_selection", (void*)&vf->vte_terminal_get_has_selection); g_module_symbol(mod, "vte_terminal_copy_clipboard", (void*)&vf->vte_terminal_copy_clipboard); g_module_symbol(mod, "vte_terminal_paste_clipboard", (void*)&vf->vte_terminal_paste_clipboard); g_module_symbol(mod, "vte_terminal_set_emulation", (void*)&vf->vte_terminal_set_emulation); g_module_symbol(mod, "vte_terminal_set_color_foreground", (void*)&vf->vte_terminal_set_color_foreground); g_module_symbol(mod, "vte_terminal_set_color_bold", (void*)&vf->vte_terminal_set_color_bold); g_module_symbol(mod, "vte_terminal_set_color_background", (void*)&vf->vte_terminal_set_color_background); g_module_symbol(mod, "vte_terminal_feed_child", (void*)&vf->vte_terminal_feed_child); g_module_symbol(mod, "vte_terminal_im_append_menuitems", (void*)&vf->vte_terminal_im_append_menuitems); g_module_symbol(mod, "vte_terminal_set_cursor_blink_mode", (void*)&vf->vte_terminal_set_cursor_blink_mode); if (vf->vte_terminal_set_cursor_blink_mode == NULL) /* vte_terminal_set_cursor_blink_mode() is only available since 0.17.1, so if we don't find * this symbol, we are probably on an older version and use the old API instead */ g_module_symbol(mod, "vte_terminal_set_cursor_blinks", (void*)&vf->vte_terminal_set_cursor_blinks); g_module_symbol(mod, "vte_terminal_select_all", (void*)&vf->vte_terminal_select_all); g_module_symbol(mod, "vte_terminal_set_audible_bell", (void*)&vf->vte_terminal_set_audible_bell); }
/** * gp11_module_initialize: * @path: The file system path to the PKCS#11 module to load. * @reserved: Extra arguments for the PKCS#11 module, should usually be NULL. * @err: A location to store an error resulting from a failed load. * * Load and initialize a PKCS#11 module represented by a GP11Module object. * * Return value: The loaded PKCS#11 module or NULL if failed. **/ GP11Module* gp11_module_initialize (const gchar *path, gpointer reserved, GError **err) { CK_C_GetFunctionList get_function_list; CK_FUNCTION_LIST_PTR funcs; GP11ModuleData *data; GModule *module; GP11Module *mod; CK_RV rv; g_return_val_if_fail (path != NULL, NULL); g_return_val_if_fail (!err || !*err, NULL); /* Load the actual module */ module = g_module_open (path, 0); if (!module) { g_set_error (err, GP11_ERROR, (int)CKR_GP11_MODULE_PROBLEM, "Error loading pkcs11 module: %s", g_module_error ()); return NULL; } /* Get the entry point */ if (!g_module_symbol (module, "C_GetFunctionList", (void**)&get_function_list)) { g_set_error (err, GP11_ERROR, (int)CKR_GP11_MODULE_PROBLEM, "Invalid pkcs11 module: %s", g_module_error ()); g_module_close (module); return NULL; } /* Get the function list */ rv = (get_function_list) (&funcs); if (rv != CKR_OK) { g_set_error (err, GP11_ERROR, rv, "Couldn't get pkcs11 function list: %s", gp11_message_from_rv (rv)); g_module_close (module); return NULL; } mod = g_object_new (GP11_TYPE_MODULE, "functions", funcs, "path", path, NULL); data = GP11_MODULE_GET_DATA (mod); data->module = module; memset (&data->init_args, 0, sizeof (data->init_args)); data->init_args.flags = CKF_OS_LOCKING_OK; data->init_args.CreateMutex = create_mutex; data->init_args.DestroyMutex = destroy_mutex; data->init_args.LockMutex = lock_mutex; data->init_args.UnlockMutex = unlock_mutex; data->init_args.pReserved = reserved; /* Now initialize the module */ rv = (data->funcs->C_Initialize) (&data->init_args); if (rv != CKR_OK) { g_set_error (err, GP11_ERROR, rv, "Couldn't initialize module: %s", gp11_message_from_rv (rv)); g_object_unref (mod); return NULL; } data->initialized = TRUE; return mod; }
int main (int argc, char **argv) { gint retval; GList *etds, *l; UhmServer *server; gchar *module_path = NULL; GModule *module = NULL; retval = ews_test_init (argc, argv); if (retval < 0) goto exit; if (!g_module_supported ()) goto exit; module_path = g_module_build_path (CALENDAR_MODULE_DIR, "libecalbackendews"); module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (module == NULL) goto exit; if (!g_module_symbol ( module, "e_cal_backend_ews_populate_windows_zones", (gpointer *) &populate_windows_zones)) { g_printerr ("\n%s\n", g_module_error ()); goto exit; } if (!g_module_symbol ( module, "e_cal_backend_ews_tz_util_get_msdn_equivalent", (gpointer *) &ical_to_msdn_equivalent)) { g_printerr ("\n%s\n", g_module_error ()); goto exit; } if (!g_module_symbol ( module, "e_cal_backend_ews_convert_calcomp_to_xml", (gpointer *) &convert_calcomp_to_xml)) { g_printerr ("\n%s\n", g_module_error ()); goto exit; } server = ews_test_get_mock_server (); etds = ews_test_get_test_data_list (); /* Set handler of debug information */ populate_windows_zones (); builtin_timezones = icaltimezone_get_builtin_timezones (); for (l = etds; l != NULL; l = l->next) { EwsTestData *etd = l->data; gchar *message; if (!uhm_server_get_enable_online (server)) g_signal_connect (server, "notify::resolver", (GCallback) server_notify_resolver_cb, etd); /* Create folder */ if (e_ews_debug_get_server_version_from_string (etd->version) >= E_EWS_EXCHANGE_2010) { message = g_strdup_printf ("/%s/calendar/timezones/ical_compatibility", etd->version); g_test_add_data_func (message, etd, test_libical_timezones_compatibility); g_free (message); message = g_strdup_printf ("/%s/calendar/timezones/time_zones_sync", etd->version); g_test_add_data_func (message, etd, test_time_zones_sync); g_free (message); } } retval = g_test_run (); if (!uhm_server_get_enable_online (server)) for (l = etds; l != NULL; l = l->next) g_signal_handlers_disconnect_by_func (server, server_notify_resolver_cb, l->data); exit: g_free (module_path); if (module != NULL) g_module_close (module); if (builtin_timezones != NULL) icalarray_free (builtin_timezones); ews_test_cleanup (); return retval; }
/** * gst_plugin_load_file: * @filename: the plugin filename to load * @error: pointer to a NULL-valued GError * * Loads the given plugin and refs it. Caller needs to unref after use. * * Returns: a reference to the existing loaded GstPlugin, a reference to the * newly-loaded GstPlugin, or NULL if an error occurred. */ GstPlugin * gst_plugin_load_file (const gchar * filename, GError ** error) { GstPlugin *plugin; GModule *module; gboolean ret; gpointer ptr; struct stat file_status; GstRegistry *registry; g_return_val_if_fail (filename != NULL, NULL); registry = gst_registry_get_default (); g_static_mutex_lock (&gst_plugin_loading_mutex); plugin = gst_registry_lookup (registry, filename); if (plugin) { if (plugin->module) { g_static_mutex_unlock (&gst_plugin_loading_mutex); return plugin; } else { gst_object_unref (plugin); plugin = NULL; } } GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"", filename); if (g_module_supported () == FALSE) { GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported"); g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported"); goto return_error; } if (g_stat (filename, &file_status)) { GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file"); g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename, g_strerror (errno)); goto return_error; } module = g_module_open (filename, G_MODULE_BIND_LOCAL); if (module == NULL) { GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s", g_module_error ()); g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s", g_module_error ()); /* If we failed to open the shared object, then it's probably because a * plugin is linked against the wrong libraries. Print out an easy-to-see * message in this case. */ g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ()); goto return_error; } plugin = g_object_new (GST_TYPE_PLUGIN, NULL); plugin->module = module; plugin->filename = g_strdup (filename); plugin->basename = g_path_get_basename (filename); plugin->file_mtime = file_status.st_mtime; plugin->file_size = file_status.st_size; ret = g_module_symbol (module, "gst_plugin_desc", &ptr); if (!ret) { GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename); g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "File \"%s\" is not a GStreamer plugin", filename); g_module_close (module); goto return_error; } plugin->orig_desc = (GstPluginDesc *) ptr; /* check plugin description: complain about bad values but accept them, to * maintain backwards compatibility (FIXME: 0.11) */ CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, name, filename); CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, description, filename); CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, version, filename); CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, license, filename); CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, source, filename); CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, package, filename); CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, origin, filename); GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...", plugin, filename); /* this is where we load the actual .so, so let's trap SIGSEGV */ _gst_plugin_fault_handler_setup (); _gst_plugin_fault_handler_filename = plugin->filename; GST_LOG ("Plugin %p for file \"%s\" prepared, registering...", plugin, filename); if (!gst_plugin_register_func (plugin, plugin->orig_desc)) { /* remove signal handler */ _gst_plugin_fault_handler_restore (); GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename); /* plugin == NULL */ g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize", filename); g_module_close (module); goto return_error; } /* remove signal handler */ _gst_plugin_fault_handler_restore (); _gst_plugin_fault_handler_filename = NULL; GST_INFO ("plugin \"%s\" loaded", plugin->filename); gst_object_ref (plugin); gst_default_registry_add_plugin (plugin); g_static_mutex_unlock (&gst_plugin_loading_mutex); return plugin; return_error: { if (plugin) gst_object_unref (plugin); g_static_mutex_unlock (&gst_plugin_loading_mutex); return NULL; } }
/** * pk_backend_load: * * Responsible for initialising the external backend object. * * Typically this will involve taking database locks for exclusive package access. * This method should only be called from the engine, unless the backend object * is used in self-check code, in which case the lock and unlock will have to * be done manually. **/ gboolean pk_backend_load (PkBackend *backend, GError **error) { GModule *handle; gboolean ret = FALSE; gpointer func = NULL; _cleanup_free_ gchar *backend_name = NULL; _cleanup_free_ gchar *path = NULL; g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE); /* already loaded */ if (backend->priv->loaded) { g_set_error (error, 1, 0, "already set name to %s", backend->priv->name); return FALSE; } /* can we load it? */ backend_name = g_key_file_get_string (backend->priv->conf, "Daemon", "DefaultBackend", error); if (backend_name == NULL) return FALSE; /* the "hawkey" backend was renamed to "hif" */ if (g_strcmp0 (backend_name, "hawkey") == 0) { g_free (backend_name); backend_name = g_strdup ("hif"); } g_debug ("Trying to load : %s", backend_name); path = pk_backend_build_library_path (backend, backend_name); handle = g_module_open (path, 0); if (handle == NULL) { g_set_error (error, 1, 0, "opening module %s failed : %s", backend_name, g_module_error ()); return FALSE; } /* then check for the new style exported functions */ ret = g_module_symbol (handle, "pk_backend_get_description", (gpointer *)&func); if (ret) { PkBackendDesc *desc; PkBackendGetCompatStringFunc backend_vfunc; desc = g_new0 (PkBackendDesc, 1); /* connect up exported methods */ g_module_symbol (handle, "pk_backend_cancel", (gpointer *)&desc->cancel); g_module_symbol (handle, "pk_backend_destroy", (gpointer *)&desc->destroy); g_module_symbol (handle, "pk_backend_download_packages", (gpointer *)&desc->download_packages); g_module_symbol (handle, "pk_backend_get_categories", (gpointer *)&desc->get_categories); g_module_symbol (handle, "pk_backend_depends_on", (gpointer *)&desc->depends_on); g_module_symbol (handle, "pk_backend_get_details", (gpointer *)&desc->get_details); g_module_symbol (handle, "pk_backend_get_details_local", (gpointer *)&desc->get_details_local); g_module_symbol (handle, "pk_backend_get_files_local", (gpointer *)&desc->get_files_local); g_module_symbol (handle, "pk_backend_get_distro_upgrades", (gpointer *)&desc->get_distro_upgrades); g_module_symbol (handle, "pk_backend_get_files", (gpointer *)&desc->get_files); g_module_symbol (handle, "pk_backend_get_filters", (gpointer *)&desc->get_filters); g_module_symbol (handle, "pk_backend_get_groups", (gpointer *)&desc->get_groups); g_module_symbol (handle, "pk_backend_get_mime_types", (gpointer *)&desc->get_mime_types); g_module_symbol (handle, "pk_backend_supports_parallelization", (gpointer *)&desc->supports_parallelization); g_module_symbol (handle, "pk_backend_get_packages", (gpointer *)&desc->get_packages); g_module_symbol (handle, "pk_backend_get_repo_list", (gpointer *)&desc->get_repo_list); g_module_symbol (handle, "pk_backend_required_by", (gpointer *)&desc->required_by); g_module_symbol (handle, "pk_backend_get_roles", (gpointer *)&desc->get_roles); g_module_symbol (handle, "pk_backend_get_provides", (gpointer *)&desc->get_provides); g_module_symbol (handle, "pk_backend_get_update_detail", (gpointer *)&desc->get_update_detail); g_module_symbol (handle, "pk_backend_get_updates", (gpointer *)&desc->get_updates); g_module_symbol (handle, "pk_backend_initialize", (gpointer *)&desc->initialize); g_module_symbol (handle, "pk_backend_install_files", (gpointer *)&desc->install_files); g_module_symbol (handle, "pk_backend_install_packages", (gpointer *)&desc->install_packages); g_module_symbol (handle, "pk_backend_install_signature", (gpointer *)&desc->install_signature); g_module_symbol (handle, "pk_backend_refresh_cache", (gpointer *)&desc->refresh_cache); g_module_symbol (handle, "pk_backend_remove_packages", (gpointer *)&desc->remove_packages); g_module_symbol (handle, "pk_backend_repo_enable", (gpointer *)&desc->repo_enable); g_module_symbol (handle, "pk_backend_repo_set_data", (gpointer *)&desc->repo_set_data); g_module_symbol (handle, "pk_backend_repo_remove", (gpointer *)&desc->repo_remove); g_module_symbol (handle, "pk_backend_resolve", (gpointer *)&desc->resolve); g_module_symbol (handle, "pk_backend_search_details", (gpointer *)&desc->search_details); g_module_symbol (handle, "pk_backend_search_files", (gpointer *)&desc->search_files); g_module_symbol (handle, "pk_backend_search_groups", (gpointer *)&desc->search_groups); g_module_symbol (handle, "pk_backend_search_names", (gpointer *)&desc->search_names); g_module_symbol (handle, "pk_backend_start_job", (gpointer *)&desc->job_start); g_module_symbol (handle, "pk_backend_stop_job", (gpointer *)&desc->job_stop); g_module_symbol (handle, "pk_backend_reset_job", (gpointer *)&desc->job_reset); g_module_symbol (handle, "pk_backend_update_packages", (gpointer *)&desc->update_packages); g_module_symbol (handle, "pk_backend_what_provides", (gpointer *)&desc->what_provides); g_module_symbol (handle, "pk_backend_repair_system", (gpointer *)&desc->repair_system); /* get old static string data */ ret = g_module_symbol (handle, "pk_backend_get_author", (gpointer *)&backend_vfunc); if (ret) desc->author = backend_vfunc (backend); ret = g_module_symbol (handle, "pk_backend_get_description", (gpointer *)&backend_vfunc); if (ret) desc->description = backend_vfunc (backend); /* make available */ backend->priv->desc = desc; } else { g_module_close (handle); g_set_error (error, 1, 0, "could not find description in plugin %s, not loading", backend_name); return FALSE; } /* save the backend name and handle */ g_free (backend->priv->name); backend->priv->name = g_strdup (backend_name); backend->priv->handle = handle; /* initialize if we can */ if (backend->priv->desc->initialize != NULL) { backend->priv->during_initialize = TRUE; backend->priv->desc->initialize (backend->priv->conf, backend); backend->priv->during_initialize = FALSE; } backend->priv->loaded = TRUE; return TRUE; }
/** * nm_vpn_editor_plugin_load_from_file: * @plugin_filename: The path to the share library to load. * Apply some common heuristics to find the library, such as * appending "so" file ending. * If the path is not an absolute path or no matching module * can be found, lookup inside a directory defined at compile time. * Due to this, @check_file might be called for two different paths. * @check_service: if not-null, check that the loaded plugin advertises * the given service. * @check_owner: if non-negative, check whether the file is owned * by UID @check_owner or by root. In this case also check that * the file is not writable by anybody else. * @check_file: (scope call): optional callback to validate the file prior to * loading the shared library. * @user_data: user data for @check_file * @error: on failure the error reason. * * Load the shared libary @plugin_filename and create a new * #NMVpnEditorPlugin instace via the #NMVpnEditorPluginFactory * function. * * Returns: (transfer full): a new plugin instance or %NULL on error. * * Since: 1.2 */ NMVpnEditorPlugin * nm_vpn_editor_plugin_load_from_file (const char *plugin_filename, const char *check_service, int check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, GError **error) { GModule *module = NULL; gs_free_error GError *local = NULL; NMVpnEditorPluginFactory factory = NULL; NMVpnEditorPlugin *editor_plugin = NULL; g_return_val_if_fail (plugin_filename && *plugin_filename, NULL); /* _nm_utils_check_module_file() fails with ENOENT if the plugin file * does not exist. That is relevant, because nm-applet checks for that. */ if (_nm_utils_check_module_file (plugin_filename, check_owner, check_file, user_data, &local)) module = g_module_open (plugin_filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (!module) { if (local) { g_propagate_error (error, local); local = NULL; } else { g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, _("cannot load plugin %s"), plugin_filename); } return NULL; } g_clear_error (&local); if (g_module_symbol (module, "nm_vpn_editor_plugin_factory", (gpointer) &factory)) { gs_free_error GError *factory_error = NULL; gboolean success = FALSE; editor_plugin = factory (&factory_error); g_assert (!editor_plugin || G_IS_OBJECT (editor_plugin)); if (editor_plugin) { gs_free char *plug_name = NULL, *plug_service = NULL; /* Validate plugin properties */ g_object_get (G_OBJECT (editor_plugin), NM_VPN_EDITOR_PLUGIN_NAME, &plug_name, NM_VPN_EDITOR_PLUGIN_SERVICE, &plug_service, NULL); if (!plug_name || !*plug_name) { g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, _("cannot load VPN plugin in '%s': missing plugin name"), g_module_name (module)); } else if ( check_service && g_strcmp0 (plug_service, check_service) != 0) { g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, _("cannot load VPN plugin in '%s': invalid service name"), g_module_name (module)); } else { /* Success! */ g_object_set_data_full (G_OBJECT (editor_plugin), "gmodule", module, (GDestroyNotify) g_module_close); success = TRUE; } } else { if (factory_error) { g_propagate_error (error, factory_error); factory_error = NULL; } else { g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, _("unknown error initializing plugin %s"), plugin_filename); } } if (!success) { g_module_close (module); editor_plugin = NULL; } } else { g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, _("failed to load nm_vpn_editor_plugin_factory() from %s (%s)"), g_module_name (module), g_module_error ()); g_module_close (module); editor_plugin = NULL; } return editor_plugin; }
void zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager) { if (plugin_manager == NULL || plugin_manager->path == NULL) { return; } GIRARA_LIST_FOREACH(plugin_manager->path, char*, iter, plugindir) /* read all files in the plugin directory */ GDir* dir = g_dir_open(plugindir, 0, NULL); if (dir == NULL) { girara_error("could not open plugin directory: %s", plugindir); girara_list_iterator_next(iter); continue; } char* name = NULL; while ((name = (char*) g_dir_read_name(dir)) != NULL) { char* path = g_build_filename(plugindir, name, NULL); if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == 0) { girara_info("%s is not a regular file. Skipping.", path); g_free(path); continue; } zathura_plugin_t* plugin = NULL; /* load plugin */ GModule* handle = g_module_open(path, G_MODULE_BIND_LOCAL); if (handle == NULL) { girara_error("could not load plugin %s (%s)", path, g_module_error()); g_free(path); continue; } /* resolve symbols and check API and ABI version*/ zathura_plugin_api_version_t api_version = NULL; if (g_module_symbol(handle, PLUGIN_API_VERSION_FUNCTION, (gpointer*) &api_version) == FALSE || api_version == NULL) { girara_error("could not find '%s' function in plugin %s", PLUGIN_API_VERSION_FUNCTION, path); g_free(path); g_module_close(handle); continue; } if (api_version() != ZATHURA_API_VERSION) { girara_error("plugin %s has been built againt zathura with a different API version (plugin: %d, zathura: %d)", path, api_version(), ZATHURA_API_VERSION); g_free(path); g_module_close(handle); continue; } zathura_plugin_abi_version_t abi_version = NULL; if (g_module_symbol(handle, PLUGIN_ABI_VERSION_FUNCTION, (gpointer*) &abi_version) == FALSE || abi_version == NULL) { girara_error("could not find '%s' function in plugin %s", PLUGIN_ABI_VERSION_FUNCTION, path); g_free(path); g_module_close(handle); continue; } if (abi_version() != ZATHURA_ABI_VERSION) { girara_error("plugin %s has been built againt zathura with a different ABI version (plugin: %d, zathura: %d)", path, abi_version(), ZATHURA_ABI_VERSION); g_free(path); g_module_close(handle); continue; } zathura_plugin_register_service_t register_service = NULL; if (g_module_symbol(handle, PLUGIN_REGISTER_FUNCTION, (gpointer*) ®ister_service) == FALSE || register_service == NULL) { girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path); g_free(path); g_module_close(handle); continue; } plugin = g_malloc0(sizeof(zathura_plugin_t)); plugin->content_types = girara_list_new2(g_free); plugin->handle = handle; register_service(plugin); /* register functions */ if (plugin->register_function == NULL) { girara_error("plugin has no document functions register function"); g_free(path); g_free(plugin); g_module_close(handle); continue; } plugin->register_function(&(plugin->functions)); plugin->path = path; bool ret = register_plugin(plugin_manager, plugin); if (ret == false) { girara_error("could not register plugin %s", path); zathura_plugin_free(plugin); } else { girara_info("successfully loaded plugin %s", path); zathura_plugin_version_function_t plugin_major = NULL, plugin_minor = NULL, plugin_rev = NULL; g_module_symbol(handle, PLUGIN_VERSION_MAJOR_FUNCTION, (gpointer*) &plugin_major); g_module_symbol(handle, PLUGIN_VERSION_MINOR_FUNCTION, (gpointer*) &plugin_minor); g_module_symbol(handle, PLUGIN_VERSION_REVISION_FUNCTION, (gpointer*) &plugin_rev); if (plugin_major != NULL && plugin_minor != NULL && plugin_rev != NULL) { plugin->version.major = plugin_major(); plugin->version.minor = plugin_minor(); plugin->version.rev = plugin_rev(); girara_debug("plugin '%s': version %u.%u.%u", path, plugin->version.major, plugin->version.minor, plugin->version.rev); } } } g_dir_close(dir); GIRARA_LIST_FOREACH_END(zathura->plugins.path, char*, iter, plugindir); }
/** * @internal Scan a particular directory for plugins to load * @param[in] dir Absolute path to plugins directory * @return TRUE if directory successfully scanned for plugins */ static gboolean xmms_plugin_scan_directory (const gchar *dir) { GDir *d; const char *name; gchar *path; gchar *temp; gchar *pattern; GModule *module; gpointer sym; temp = get_module_ext (dir); XMMS_DBG ("Scanning directory for plugins (%s)", temp); pattern = g_path_get_basename (temp); g_free (temp); d = g_dir_open (dir, 0, NULL); if (!d) { xmms_log_error ("Failed to open plugin directory (%s)", dir); return FALSE; } while ((name = g_dir_read_name (d))) { if (!g_pattern_match_simple (pattern, name)) continue; path = g_build_filename (dir, name, NULL); if (!g_file_test (path, G_FILE_TEST_IS_REGULAR)) { g_free (path); continue; } XMMS_DBG ("Trying to load file: %s", path); module = g_module_open (path, G_MODULE_BIND_LOCAL); if (!module) { xmms_log_error ("Failed to open plugin %s: %s", path, g_module_error ()); g_free (path); continue; } if (!g_module_symbol (module, "XMMS_PLUGIN_DESC", &sym)) { xmms_log_error ("Failed to find plugin header in %s", path); g_module_close (module); g_free (path); continue; } g_free (path); if (!xmms_plugin_load ((const xmms_plugin_desc_t *) sym, module)) { g_module_close (module); } } g_dir_close (d); g_free (pattern); return TRUE; }
static gboolean spell_available (void) { gchar *spell_module_fname; gboolean ret = FALSE; if (spell_module != NULL) return TRUE; spell_module_fname = g_module_build_path (NULL, "libaspell"); spell_module = g_module_open (spell_module_fname, G_MODULE_BIND_LAZY); g_free (spell_module_fname); if (spell_module == NULL) return FALSE; if (!g_module_symbol (spell_module, "new_aspell_config", (void *) &mc_new_aspell_config)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_dict_info_list_elements", (void *) &mc_aspell_dict_info_list_elements)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_dict_info_enumeration_next", (void *) &mc_aspell_dict_info_enumeration_next)) goto error_ret; if (!g_module_symbol (spell_module, "new_aspell_speller", (void *) &mc_new_aspell_speller)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_error_number", (void *) &mc_aspell_error_number)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_speller_error_message", (void *) &mc_aspell_speller_error_message)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_speller_error", (void *) &mc_aspell_speller_error)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_error", (void *) &mc_aspell_error)) goto error_ret; if (!g_module_symbol (spell_module, "to_aspell_speller", (void *) &mc_to_aspell_speller)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_speller_check", (void *) &mc_aspell_speller_check)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_speller_suggest", (void *) &mc_aspell_speller_suggest)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_word_list_elements", (void *) &mc_aspell_word_list_elements)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_string_enumeration_next", (void *) &mc_aspell_string_enumeration_next)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_config_replace", (void *) &mc_aspell_config_replace)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_error_message", (void *) &mc_aspell_error_message)) goto error_ret; if (!g_module_symbol (spell_module, "delete_aspell_speller", (void *) &mc_delete_aspell_speller)) goto error_ret; if (!g_module_symbol (spell_module, "delete_aspell_config", (void *) &mc_delete_aspell_config)) goto error_ret; if (!g_module_symbol (spell_module, "delete_aspell_string_enumeration", (void *) &mc_delete_aspell_string_enumeration)) goto error_ret; if (!g_module_symbol (spell_module, "get_aspell_dict_info_list", (void *) &mc_get_aspell_dict_info_list)) goto error_ret; if (!g_module_symbol (spell_module, "delete_aspell_can_have_error", (void *) &mc_delete_aspell_can_have_error)) goto error_ret; if (!g_module_symbol (spell_module, "delete_aspell_dict_info_enumeration", (void *) &mc_delete_aspell_dict_info_enumeration)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_config_retrieve", (void *) &mc_aspell_config_retrieve)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_word_list_size", (void *) &mc_aspell_word_list_size)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_speller_add_to_personal", (void *) &mc_aspell_speller_add_to_personal)) goto error_ret; if (!g_module_symbol (spell_module, "aspell_speller_save_all_word_lists", (void *) &mc_aspell_speller_save_all_word_lists)) goto error_ret; ret = TRUE; error_ret: if (!ret) { g_module_close (spell_module); spell_module = NULL; } return ret; }
/* Load a particular status provider */ static gboolean load_status_provider (gpointer dir) { gchar * provider = dir; /* load the module */ GModule * module = NULL; if (g_file_test(provider, G_FILE_TEST_EXISTS)) { g_debug("Loading status provider: %s", provider); module = g_module_open(provider, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (module == NULL) { g_warning("Unable to open module: %s", provider); } } /* find the status provider's GType */ GType provider_type = 0; if (module != NULL) { GType (*type_func) (void); if (!g_module_symbol(module, STATUS_PROVIDER_EXPORT_S, (gpointer *)&type_func)) { g_warning("Unable to find type symbol in: %s", provider); } else { provider_type = type_func(); if (provider_type == 0) { g_warning("Unable to create type from: %s", provider); } } } /* instantiate the status provider */ StatusProvider * sprovider = NULL; if (provider_type != 0) { sprovider = STATUS_PROVIDER(g_object_new(provider_type, NULL)); if (sprovider == NULL) { g_warning("Unable to build provider from: %s", provider); } } /* use the provider */ if (sprovider != NULL) { /* On update let's talk to all of them and create the aggregate value to export */ g_signal_connect(G_OBJECT(sprovider), STATUS_PROVIDER_SIGNAL_STATUS_CHANGED, G_CALLBACK(update_status), NULL); /* Attach the module object to the status provider so that when the status provider is free'd the module is closed automatically. */ g_object_set_data_full(G_OBJECT(sprovider), "status-provider-module", module, module_destroy_in_idle); module = NULL; /* don't close module in this func */ status_providers = g_list_prepend(status_providers, sprovider); /* Force an update to ensure a consistent state */ update_status(); } /* cleanup */ if (module != NULL) g_module_close(module); g_free(provider); return FALSE; /* only call this idle func once */ }
static int dt_lib_load_module (dt_lib_module_t *module, const char *libname, const char *plugin_name) { // char name[1024]; module->dt = &darktable; module->widget = NULL; g_strlcpy(module->plugin_name, plugin_name, 20); module->module = g_module_open(libname, G_MODULE_BIND_LAZY); if(!module->module) goto error; int (*version)(); if(!g_module_symbol(module->module, "dt_module_dt_version", (gpointer)&(version))) goto error; if(version() != dt_version()) { fprintf(stderr, "[lib_load_module] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n", libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()), dt_version() < 0 ? "debug" : "opt"); goto error; } if(!g_module_symbol(module->module, "dt_module_mod_version", (gpointer)&(module->version))) goto error; if(!g_module_symbol(module->module, "name", (gpointer)&(module->name))) goto error; if(!g_module_symbol(module->module, "views", (gpointer)&(module->views))) goto error; if(!g_module_symbol(module->module, "container", (gpointer)&(module->container))) goto error; if(!g_module_symbol(module->module, "expandable", (gpointer)&(module->expandable))) module->expandable = _lib_default_expandable; if(!g_module_symbol(module->module, "gui_reset", (gpointer)&(module->gui_reset))) module->gui_reset = NULL; if(!g_module_symbol(module->module, "gui_init", (gpointer)&(module->gui_init))) goto error; if(!g_module_symbol(module->module, "gui_cleanup", (gpointer)&(module->gui_cleanup))) goto error; if(!g_module_symbol(module->module, "gui_post_expose", (gpointer)&(module->gui_post_expose))) module->gui_post_expose = NULL; if(!g_module_symbol(module->module, "mouse_leave", (gpointer)&(module->mouse_leave))) module->mouse_leave = NULL; if(!g_module_symbol(module->module, "mouse_moved", (gpointer)&(module->mouse_moved))) module->mouse_moved = NULL; if(!g_module_symbol(module->module, "button_released", (gpointer)&(module->button_released))) module->button_released = NULL; if(!g_module_symbol(module->module, "button_pressed", (gpointer)&(module->button_pressed))) module->button_pressed = NULL; if(!g_module_symbol(module->module, "configure", (gpointer)&(module->configure))) module->configure = NULL; if(!g_module_symbol(module->module, "scrolled", (gpointer)&(module->scrolled))) module->scrolled = NULL; if(!g_module_symbol(module->module, "position", (gpointer)&(module->position))) module->position = NULL; if((!g_module_symbol(module->module, "get_params", (gpointer)&(module->get_params))) || (!g_module_symbol(module->module, "set_params", (gpointer)&(module->set_params))) || (!g_module_symbol(module->module, "init_presets", (gpointer)&(module->init_presets)))) { // need both at the same time, or none. module->set_params = NULL; module->get_params = NULL; module->init_presets = NULL; } if(!g_module_symbol(module->module, "init_key_accels", (gpointer)&(module->init_key_accels))) module->init_key_accels = NULL; if(!g_module_symbol(module->module, "connect_key_accels", (gpointer)&(module->connect_key_accels))) module->connect_key_accels = NULL; module->accel_closures = NULL; module->reset_button = NULL; module->presets_button = NULL; if (module->gui_reset) { dt_accel_register_lib(module, NC_("accel", "reset module parameters"), 0, 0); } if(module->get_params) { dt_accel_register_lib(module, NC_("accel", "show preset menu"), 0, 0); } return 0; error: fprintf(stderr, "[lib_load_module] failed to open operation `%s': %s\n", plugin_name, g_module_error()); if(module->module) g_module_close(module->module); return 1; }
gboolean ToolsCore_LoadPlugins(ToolsServiceState *state) { gboolean pluginDirExists; gboolean ret = FALSE; gchar *pluginRoot; guint i; GPtrArray *plugins = NULL; #if defined(sun) && defined(__x86_64__) const char *subdir = "/amd64"; #else const char *subdir = ""; #endif #if defined(OPEN_VM_TOOLS) pluginRoot = g_strdup(VMTOOLSD_PLUGIN_ROOT); #else char *instPath = GuestApp_GetInstallPath(); pluginRoot = g_strdup_printf("%s%cplugins", instPath, DIRSEPC); vm_free(instPath); #endif ASSERT(g_module_supported()); #ifdef USE_APPLOADER { Bool ret = FALSE; GModule *mainModule = g_module_open(NULL, G_MODULE_BIND_LAZY); ASSERT(mainModule); ret = g_module_symbol(mainModule, "AppLoader_LoadLibraryDependencies", (gpointer *)&LoadDependencies); g_module_close(mainModule); if (!ret) { g_critical("Unable to locate library dependency loading function.\n"); goto exit; } } #endif plugins = g_ptr_array_new(); /* * First, load plugins from the common directory. The common directory * is not required to exist unless provided on the command line. */ if (state->commonPath == NULL) { state->commonPath = g_strdup_printf("%s%s%c%s", pluginRoot, subdir, DIRSEPC, TOOLSCORE_COMMON); } else if (!g_file_test(state->commonPath, G_FILE_TEST_IS_DIR)) { g_warning("Common plugin path is not a directory: %s\n", state->commonPath); goto exit; } if (g_file_test(state->commonPath, G_FILE_TEST_IS_DIR) && !ToolsCoreLoadDirectory(&state->ctx, state->commonPath, plugins)) { goto exit; } /* * Load the container-specific plugins. Ignore if the plugin directory * doesn't exist when running in debug mode. */ if (state->pluginPath == NULL) { state->pluginPath = g_strdup_printf("%s%s%c%s", pluginRoot, subdir, DIRSEPC, state->name); } pluginDirExists = g_file_test(state->pluginPath, G_FILE_TEST_IS_DIR); if (state->debugPlugin == NULL && !pluginDirExists) { g_warning("Plugin path is not a directory: %s\n", state->pluginPath); goto exit; } if (pluginDirExists && !ToolsCoreLoadDirectory(&state->ctx, state->pluginPath, plugins)) { goto exit; } /* * All plugins are loaded, now initialize them. */ state->plugins = g_ptr_array_new(); for (i = 0; i < plugins->len; i++) { ToolsPlugin *plugin = g_ptr_array_index(plugins, i); plugin->data = plugin->onload(&state->ctx); if (plugin->data == NULL) { g_info("Plugin '%s' didn't provide deployment data, unloading.\n", plugin->fileName); ToolsCoreFreePlugin(plugin); } else if (state->ctx.errorCode != 0) { /* Break early if a plugin has requested the container to quit. */ ToolsCoreFreePlugin(plugin); break; } else { ASSERT(plugin->data->name != NULL); g_module_make_resident(plugin->module); g_ptr_array_add(state->plugins, plugin); VMTools_BindTextDomain(plugin->data->name, NULL, NULL); g_message("Plugin '%s' initialized.\n", plugin->data->name); } } /* * If there is a debug plugin, see if it exports standard plugin registration * data too. */ if (state->debugData != NULL && state->debugData->debugPlugin->plugin != NULL) { ToolsPluginData *data = state->debugData->debugPlugin->plugin; ToolsPlugin *plugin = g_malloc(sizeof *plugin); plugin->fileName = NULL; plugin->module = NULL; plugin->data = data; VMTools_BindTextDomain(data->name, NULL, NULL); g_ptr_array_add(state->plugins, plugin); } ret = TRUE; exit: if (plugins != NULL) { g_ptr_array_free(plugins, TRUE); } g_free(pluginRoot); return ret; }
int input_init(char* exe_name, const char* forced_plugin) { int plugin_found = 0; const char** cur_plugin_name = plugin_names; struct input_ops* ops; char** exts; GModule* module; char* exe_dir; const char* env_path; char** env_path_split; char** it; exe_dir = g_path_get_dirname(exe_name); plugin_search_dirs[3] = exe_dir; env_path = g_getenv("PATH"); env_path_split = g_strsplit(env_path, G_SEARCHPATH_SEPARATOR_S, 0); for (it = env_path_split; *it; ++it) { char* r128_path = g_build_filename(*it, "r128", NULL); g_free(*it); *it = r128_path; } if (forced_plugin) plugin_forced = 1; /* Load plugins */ while (*cur_plugin_name) { if (forced_plugin && strcmp(forced_plugin, (*cur_plugin_name) + 6)) { ++cur_plugin_name; continue; } ops = NULL; exts = NULL; module = NULL; search_module_in_paths(*cur_plugin_name, &module, plugin_search_dirs); search_module_in_paths(*cur_plugin_name, &module, (const char* const*) env_path_split); if (!module) { /* fprintf(stderr, "%s\n", g_module_error()); */ } else { if (!g_module_symbol(module, "ip_ops", (gpointer*) &ops)) { fprintf(stderr, "%s: %s\n", *cur_plugin_name, g_module_error()); } if (!g_module_symbol(module, "ip_exts", (gpointer*) &exts)) { fprintf(stderr, "%s: %s\n", *cur_plugin_name, g_module_error()); } } if (ops) { if (verbose) fprintf(stderr, "found plugin %s\n", *cur_plugin_name); ops->init_library(); plugin_found = 1; } g_modules = g_slist_append(g_modules, module); plugin_ops = g_slist_append(plugin_ops, ops); plugin_exts = g_slist_append(plugin_exts, exts); ++cur_plugin_name; } #ifdef GSTREAMER_INPUT_STATIC plugin_ops = g_slist_append(plugin_ops, &gstreamer_ip_ops); plugin_exts = g_slist_append(plugin_exts, &gstreamer_ip_exts); gstreamer_ip_ops.init_library(); plugin_found = 1; #endif g_free(exe_dir); g_strfreev(env_path_split); if (!plugin_found) { fprintf(stderr, "Warning: no plugins found!\n"); return 1; } return 0; }
bool PluginPackage::load() { if (m_isLoaded) { m_loadCount++; return true; } GOwnPtr<gchar> finalPath(g_strdup(m_path.utf8().data())); while (g_file_test(finalPath.get(), G_FILE_TEST_IS_SYMLINK)) { GOwnPtr<GFile> file(g_file_new_for_path(finalPath.get())); GOwnPtr<GFile> dir(g_file_get_parent(file.get())); GOwnPtr<gchar> linkPath(g_file_read_link(finalPath.get(), 0)); GOwnPtr<GFile> resolvedFile(g_file_resolve_relative_path(dir.get(), linkPath.get())); finalPath.set(g_file_get_path(resolvedFile.get())); } // No joke. If there is a netscape component in the path, go back // to the symlink, as flash breaks otherwise. // See http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/plugins/plugin_list_posix.cc GOwnPtr<gchar> baseName(g_path_get_basename(finalPath.get())); if (!g_strcmp0(baseName.get(), "libflashplayer.so") && g_strstr_len(finalPath.get(), -1, "/netscape/")) finalPath.set(g_strdup(m_path.utf8().data())); m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL); if (!m_module) { LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error()); return false; } m_isLoaded = true; NP_InitializeFuncPtr NP_Initialize = 0; m_NPP_Shutdown = 0; NPError npErr; g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize); g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown); if (!NP_Initialize || !m_NPP_Shutdown) goto abort; memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); m_pluginFuncs.size = sizeof(m_pluginFuncs); initializeBrowserFuncs(); #if defined(XP_UNIX) npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs); #else npErr = NP_Initialize(&m_browserFuncs); #endif if (npErr != NPERR_NO_ERROR) goto abort; m_loadCount++; return true; abort: unloadWithoutShutdown(); return false; }
GdkGLProc _gdk_x11_gl_get_proc_address (const char *proc_name) { #ifdef __APPLE__ #define _GDK_GL_LIBGL_PATH "/usr/X11R6/lib/libGL.1.dylib" #define _GDK_GL_LIBGLU_PATH "/usr/X11R6/lib/libGLU.1.dylib" typedef GdkGLProc (*__glXGetProcAddressProc) (const GLubyte *); static __glXGetProcAddressProc glx_get_proc_address = (__glXGetProcAddressProc) -1; const char *image_name; static const struct mach_header *libgl_image = NULL; static const struct mach_header *libglu_image = NULL; NSSymbol symbol; char *symbol_name; GdkGLProc proc_address; GDK_GL_NOTE_FUNC (); if (strncmp ("glu", proc_name, 3) != 0) { /* libGL */ if (libgl_image == NULL) { image_name = g_getenv ("GDK_GL_LIBGL_PATH"); if (image_name == NULL) image_name = _GDK_GL_LIBGL_PATH; GDK_GL_NOTE (MISC, g_message (" - Add Mach-O image %s", image_name)); libgl_image = NSAddImage (image_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR); if (libgl_image == NULL) { g_warning ("Cannot add Mach-O image %s", image_name); return NULL; } } if (glx_get_proc_address == (__glXGetProcAddressProc) -1) { /* * Look up glXGetProcAddress () function. */ symbol = NSLookupSymbolInImage (libgl_image, "_glXGetProcAddress", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); if (symbol == NULL) { symbol = NSLookupSymbolInImage (libgl_image, "_glXGetProcAddressARB", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); if (symbol == NULL) { symbol = NSLookupSymbolInImage (libgl_image, "_glXGetProcAddressEXT", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); } } GDK_GL_NOTE (MISC, g_message (" - glXGetProcAddress () - %s", symbol ? "supported" : "not supported")); if (symbol != NULL) glx_get_proc_address = NSAddressOfSymbol (symbol); else glx_get_proc_address = NULL; } /* Try glXGetProcAddress () */ if (glx_get_proc_address != NULL) { proc_address = glx_get_proc_address ((unsigned char *) proc_name); GDK_GL_NOTE (IMPL, g_message (" ** glXGetProcAddress () - %s", proc_address ? "succeeded" : "failed")); if (proc_address != NULL) return proc_address; } /* Try Mach-O dyld */ symbol_name = g_strconcat ("_", proc_name, NULL); symbol = NSLookupSymbolInImage (libgl_image, symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); GDK_GL_NOTE (MISC, g_message (" - NSLookupSymbolInImage () - %s", symbol ? "succeeded" : "failed")); g_free (symbol_name); if (symbol != NULL) return NSAddressOfSymbol (symbol); } else { /* libGLU */ if (libglu_image == NULL) { image_name = g_getenv ("GDK_GL_LIBGLU_PATH"); if (image_name == NULL) image_name = _GDK_GL_LIBGLU_PATH; GDK_GL_NOTE (MISC, g_message (" - Add Mach-O image %s", image_name)); libglu_image = NSAddImage (image_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR); if (libglu_image == NULL) { g_warning ("Cannot add Mach-O image %s", image_name); return NULL; } } symbol_name = g_strconcat ("_", proc_name, NULL); symbol = NSLookupSymbolInImage (libglu_image, symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); GDK_GL_NOTE (MISC, g_message (" - NSLookupSymbolInImage () - %s", symbol ? "succeeded" : "failed")); g_free (symbol_name); if (symbol != NULL) return NSAddressOfSymbol (symbol); } return NULL; #else /* __APPLE__ */ typedef GdkGLProc (*__glXGetProcAddressProc) (const GLubyte *); static __glXGetProcAddressProc glx_get_proc_address = (__glXGetProcAddressProc) -1; gchar *file_name; GModule *module; GdkGLProc proc_address = NULL; GDK_GL_NOTE_FUNC (); if (strncmp ("glu", proc_name, 3) != 0) { if (glx_get_proc_address == (__glXGetProcAddressProc) -1) { /* * Look up glXGetProcAddress () function. */ file_name = g_module_build_path (NULL, "GL"); GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name)); module = g_module_open (file_name, G_MODULE_BIND_LAZY); g_free (file_name); if (module != NULL) { g_module_symbol (module, "glXGetProcAddress", (gpointer) &glx_get_proc_address); if (glx_get_proc_address == NULL) { g_module_symbol (module, "glXGetProcAddressARB", (gpointer) &glx_get_proc_address); if (glx_get_proc_address == NULL) { g_module_symbol (module, "glXGetProcAddressEXT", (gpointer) &glx_get_proc_address); } } GDK_GL_NOTE (MISC, g_message (" - glXGetProcAddress () - %s", glx_get_proc_address ? "supported" : "not supported")); g_module_close (module); } else { g_warning ("Cannot open %s", file_name); glx_get_proc_address = NULL; return NULL; } } /* Try glXGetProcAddress () */ if (glx_get_proc_address != NULL) { proc_address = glx_get_proc_address ((unsigned char *) proc_name); GDK_GL_NOTE (IMPL, g_message (" ** glXGetProcAddress () - %s", proc_address ? "succeeded" : "failed")); if (proc_address != NULL) return proc_address; } /* Try g_module_symbol () */ /* libGL */ file_name = g_module_build_path (NULL, "GL"); GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name)); module = g_module_open (file_name, G_MODULE_BIND_LAZY); g_free (file_name); if (module != NULL) { g_module_symbol (module, proc_name, (gpointer) &proc_address); GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s", proc_address ? "succeeded" : "failed")); g_module_close (module); } else { g_warning ("Cannot open %s", file_name); } if (proc_address == NULL) { /* libGLcore */ file_name = g_module_build_path (NULL, "GLcore"); GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name)); module = g_module_open (file_name, G_MODULE_BIND_LAZY); g_free (file_name); if (module != NULL) { g_module_symbol (module, proc_name, (gpointer) &proc_address); GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s", proc_address ? "succeeded" : "failed")); g_module_close (module); } } } else { /* libGLU */ file_name = g_module_build_path (NULL, "GLU"); GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name)); module = g_module_open (file_name, G_MODULE_BIND_LAZY); g_free (file_name); if (module != NULL) { g_module_symbol (module, proc_name, (gpointer) &proc_address); GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s", proc_address ? "succeeded" : "failed")); g_module_close (module); } else { g_warning ("Cannot open %s", file_name); } } return proc_address; #endif /* __APPLE__ */ }
static void _eventd_plugins_load_dir(EventdCoreContext *core, EventdCoreInterface *interface, const gchar *plugins_dir_name, gchar **whitelist, gchar **blacklist) { GError *error; GDir *plugins_dir; const gchar *file; #ifdef DEBUG g_debug("Scannig plugins dir: %s", plugins_dir_name); #endif /* DEBUG */ plugins_dir = g_dir_open(plugins_dir_name, 0, &error); if ( ! plugins_dir ) { g_warning("Couldn't read the plugins directory: %s", error->message); g_clear_error(&error); return; } while ( ( file = g_dir_read_name(plugins_dir) ) != NULL ) { gchar *full_filename; EventdPlugin *plugin; const gchar **id; EventdPluginGetInterfaceFunc get_interface; GModule *module; if ( ! g_str_has_suffix(file, G_MODULE_SUFFIX) ) continue; if ( whitelist != NULL ) { gboolean whitelisted = FALSE; gchar **wname; for ( wname = whitelist ; *wname != NULL ; ++wname ) { if ( g_str_has_prefix(file, *wname) ) { whitelisted = TRUE; break; } } if ( ! whitelisted ) continue; } if ( blacklist != NULL ) { gboolean blacklisted = FALSE; gchar **bname; for ( bname = blacklist ; *bname != NULL ; ++bname ) { if ( g_str_has_prefix(file, *bname) ) { blacklisted = TRUE; break; } } if ( blacklisted ) continue; } full_filename = g_build_filename(plugins_dir_name, file, NULL); if ( g_file_test(full_filename, G_FILE_TEST_IS_DIR) ) { g_free(full_filename); continue; } module = g_module_open(full_filename, G_MODULE_BIND_LAZY|G_MODULE_BIND_LOCAL); if ( module == NULL ) { g_warning("Couldn't load module '%s': %s", file, g_module_error()); g_free(full_filename); continue; } g_free(full_filename); if ( ! g_module_symbol(module, "eventd_plugin_id", (void **)&id) ) continue; if ( id == NULL ) { g_warning("Plugin '%s' must define eventd_plugin_id", file); continue; } if ( g_hash_table_contains(plugins, *id) ) { #ifdef DEBUG g_debug("Plugin '%s' with id '%s' already loaded", file, *id); #endif /* ! DEBUG */ continue; } if ( ! g_module_symbol(module, "eventd_plugin_get_interface", (void **)&get_interface) ) continue; #ifdef DEBUG g_debug("Loading plugin '%s': %s", file, *id); #endif /* ! DEBUG */ plugin = g_new0(EventdPlugin, 1); plugin->module = module; get_interface(&plugin->interface); if ( plugin->interface.init != NULL ) { plugin->context = plugin->interface.init(core, interface); if ( plugin->context == NULL ) { g_warning("Couldn't load plugin '%s'", file); g_module_close(plugin->module); g_free(plugin); continue; } } g_hash_table_insert(plugins, (gpointer) *id, plugin); } g_dir_close(plugins_dir); }
static int dt_imageio_load_module_storage (dt_imageio_module_storage_t *module, const char *libname, const char *plugin_name) { module->widget = NULL; g_strlcpy(module->plugin_name, plugin_name, 20); module->module = g_module_open(libname, G_MODULE_BIND_LAZY); if(!module->module) goto error; int (*version)(); if(!g_module_symbol(module->module, "dt_module_dt_version", (gpointer)&(version))) goto error; if(version() != dt_version()) { fprintf(stderr, "[imageio_load_module] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n", libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()), dt_version() < 0 ? "debug" : "opt"); goto error; } if(!g_module_symbol(module->module, "name", (gpointer)&(module->name))) goto error; if(!g_module_symbol(module->module, "gui_reset", (gpointer)&(module->gui_reset))) goto error; if(!g_module_symbol(module->module, "gui_init", (gpointer)&(module->gui_init))) goto error; if(!g_module_symbol(module->module, "gui_cleanup", (gpointer)&(module->gui_cleanup))) goto error; if(!g_module_symbol(module->module, "store", (gpointer)&(module->store))) goto error; if(!g_module_symbol(module->module, "get_params", (gpointer)&(module->get_params))) goto error; if(!g_module_symbol(module->module, "free_params", (gpointer)&(module->free_params))) goto error; if(!g_module_symbol(module->module, "finalize_store", (gpointer)&(module->finalize_store))) module->finalize_store = NULL; if(!g_module_symbol(module->module, "set_params", (gpointer)&(module->set_params))) goto error; if(!g_module_symbol(module->module, "supported", (gpointer)&(module->supported))) module->supported = _default_supported; if(!g_module_symbol(module->module, "dimension", (gpointer)&(module->dimension))) module->dimension = _default_storage_dimension; if(!g_module_symbol(module->module, "recommended_dimension", (gpointer)&(module->recommended_dimension))) module->recommended_dimension = _default_storage_dimension; return 0; error: fprintf(stderr, "[imageio_load_module] failed to open storage `%s': %s\n", plugin_name, g_module_error()); if(module->module) g_module_close(module->module); return 1; }
static ModuleInfo * load_module (RuleInfo *info, gboolean initialize) { ModuleInfo *module_info = NULL; if (modules) { module_info = g_hash_table_lookup (modules, info->module_path); } if (!module_info) { GModule *module; /* Load the module */ module = g_module_open (info->module_path, G_MODULE_BIND_LOCAL); if (!module) { g_warning ("Could not load module '%s': %s", info->module_path, g_module_error ()); return NULL; } g_module_make_resident (module); module_info = g_slice_new0 (ModuleInfo); module_info->module = module; if (!g_module_symbol (module, EXTRACTOR_FUNCTION, (gpointer *) &module_info->extract_func)) { g_warning ("Could not load module '%s': Function %s() was not found, is it exported?", g_module_name (module), EXTRACTOR_FUNCTION); g_slice_free (ModuleInfo, module_info); return NULL; } g_module_symbol (module, INIT_FUNCTION, (gpointer *) &module_info->init_func); g_module_symbol (module, SHUTDOWN_FUNCTION, (gpointer *) &module_info->shutdown_func); /* Add it to the cache */ if (G_UNLIKELY (!modules)) { /* Key is an intern string, so * pointer comparison suffices */ modules = g_hash_table_new (NULL, NULL); } g_hash_table_insert (modules, (gpointer) info->module_path, module_info); } if (module_info && initialize && !module_info->initialized) { if (module_info->init_func) { GError *error = NULL; if (!(module_info->init_func) (&module_info->thread_awareness, &error)) { g_critical ("Could not initialize module %s: %s", g_module_name (module_info->module), (error) ? error->message : "No error given"); if (error) { g_error_free (error); } return NULL; } } else { module_info->thread_awareness = TRACKER_MODULE_MAIN_THREAD; } module_info->initialized = TRUE; } return module_info; }
static int dt_imageio_load_module_format (dt_imageio_module_format_t *module, const char *libname, const char *plugin_name) { module->widget = NULL; g_strlcpy(module->plugin_name, plugin_name, 20); module->module = g_module_open(libname, G_MODULE_BIND_LAZY); if(!module->module) goto error; int (*version)(); if(!g_module_symbol(module->module, "dt_module_dt_version", (gpointer)&(version))) goto error; if(version() != dt_version()) { fprintf(stderr, "[imageio_load_module] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n", libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()), dt_version() < 0 ? "debug" : "opt"); goto error; } if(!g_module_symbol(module->module, "name", (gpointer)&(module->name))) goto error; if(!g_module_symbol(module->module, "init", (gpointer)&(module->init))) goto error; if(!g_module_symbol(module->module, "cleanup", (gpointer)&(module->cleanup))) goto error; if(!g_module_symbol(module->module, "gui_reset", (gpointer)&(module->gui_reset))) goto error; if(!g_module_symbol(module->module, "gui_init", (gpointer)&(module->gui_init))) goto error; if(!g_module_symbol(module->module, "gui_cleanup", (gpointer)&(module->gui_cleanup))) goto error; if(!g_module_symbol(module->module, "mime", (gpointer)&(module->mime))) goto error; if(!g_module_symbol(module->module, "extension", (gpointer)&(module->extension))) goto error; if(!g_module_symbol(module->module, "dimension", (gpointer)&(module->dimension))) module->dimension = _default_format_dimension; if(!g_module_symbol(module->module, "get_params", (gpointer)&(module->get_params))) goto error; if(!g_module_symbol(module->module, "free_params", (gpointer)&(module->free_params))) goto error; if(!g_module_symbol(module->module, "set_params", (gpointer)&(module->set_params))) goto error; if(!g_module_symbol(module->module, "write_image", (gpointer)&(module->write_image))) goto error; if(!g_module_symbol(module->module, "bpp", (gpointer)&(module->bpp))) goto error; if(!g_module_symbol(module->module, "flags", (gpointer)&(module->flags))) module->flags = _default_format_flags; if(!g_module_symbol(module->module, "decompress_header", (gpointer)&(module->decompress_header))) module->decompress_header = NULL; if(!g_module_symbol(module->module, "decompress", (gpointer)&(module->decompress))) module->decompress = NULL; if(!g_module_symbol(module->module, "compress", (gpointer)&(module->compress))) module->compress = NULL; if(!g_module_symbol(module->module, "read_header", (gpointer)&(module->read_header))) module->read_header = NULL; if(!g_module_symbol(module->module, "read_image", (gpointer)&(module->read_image))) module->read_image = NULL; module->init(module); return 0; error: fprintf(stderr, "[imageio_load_module] failed to open format `%s': %s\n", plugin_name, g_module_error()); if(module->module) g_module_close(module->module); return 1; }
/** * imsettings_module_load: * @module: * * FIXME * * Returns: */ gboolean imsettings_module_load(IMSettingsModule *module) { IMSettingsModulePrivate *priv; gchar **path_list, *modulename, *s, *path, *fullpath; const gchar *p; gint i; gsize len; gboolean retval = FALSE; g_return_val_if_fail (IMSETTINGS_IS_MODULE (module), FALSE); priv = module->priv; modulename = g_strdup_printf("libimsettings-%s.so", priv->name); p = g_getenv("IMSETTINGS_MODULE_PATH"); if (!p) { path_list = g_strsplit(IMSETTINGS_MODULE_PATH, G_SEARCHPATH_SEPARATOR_S, -1); } else { path_list = g_strsplit(p, G_SEARCHPATH_SEPARATOR_S, -1); } for (i = 0; path_list[i] != NULL && !retval; i++) { s = path_list[i]; while (*s && g_ascii_isspace(*s)) s++; len = strlen(s); while (len > 0 && g_ascii_isspace(s[len - 1])) len--; path = g_strndup(s, len); if (path[0] != 0) { fullpath = g_build_filename(path, modulename, NULL); priv->module = g_module_open(fullpath, G_MODULE_BIND_LAZY|G_MODULE_BIND_LOCAL); if (priv->module) { gpointer mod_cb; g_module_symbol(priv->module, "module_switch_im", &mod_cb); if (!mod_cb) { g_warning(g_module_error()); goto next; } priv->callback = mod_cb; g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Loading imsettings module: %s", fullpath); retval = TRUE; } next: g_free(fullpath); } g_free(path); } g_free(modulename); g_strfreev(path_list); return retval; }
char * plugin_load (session *sess, char *filename, char *arg) { void *handle; xchat_init_func *init_func; xchat_deinit_func *deinit_func; #ifdef USE_GMODULE /* load the plugin */ handle = g_module_open (filename, 0); if (handle == NULL) return (char *)g_module_error (); /* find the init routine xchat_plugin_init */ if (!g_module_symbol (handle, "xchat_plugin_init", (gpointer *)&init_func)) { g_module_close (handle); return _("No xchat_plugin_init symbol; is this really an xchat plugin?"); } /* find the plugin's deinit routine, if any */ if (!g_module_symbol (handle, "xchat_plugin_deinit", (gpointer *)&deinit_func)) deinit_func = NULL; #else char *error; char *filepart; /* OpenBSD lacks this! */ #ifndef RTLD_GLOBAL #define RTLD_GLOBAL 0 #endif #ifndef RTLD_NOW #define RTLD_NOW 0 #endif /* get the filename without path */ filepart = file_part (filename); /* load the plugin */ if (filepart && /* xsys draws in libgtk-1.2, causing crashes, so force RTLD_LOCAL */ (strstr (filepart, "local") || strncmp (filepart, "libxsys-1", 9) == 0) ) handle = dlopen (filename, RTLD_NOW); else handle = dlopen (filename, RTLD_GLOBAL | RTLD_NOW); if (handle == NULL) return (char *)dlerror (); dlerror (); /* Clear any existing error */ /* find the init routine xchat_plugin_init */ init_func = dlsym (handle, "xchat_plugin_init"); error = (char *)dlerror (); if (error != NULL) { dlclose (handle); return _("No xchat_plugin_init symbol; is this really an xchat plugin?"); } /* find the plugin's deinit routine, if any */ deinit_func = dlsym (handle, "xchat_plugin_deinit"); error = (char *)dlerror (); #endif /* add it to our linked list */ plugin_add (sess, filename, handle, init_func, deinit_func, arg, FALSE); return NULL; }
GModule* g_module_open (const gchar *file_name, GModuleFlags flags) { GModule *module; gpointer handle = NULL; gchar *name = NULL; SUPPORT_OR_RETURN (NULL); g_static_rec_mutex_lock (&g_module_global_lock); if (G_UNLIKELY (!module_debug_initialized)) _g_module_debug_init (); if (module_debug_flags & G_MODULE_DEBUG_BIND_NOW_MODULES) flags &= ~G_MODULE_BIND_LAZY; if (!file_name) { if (!main_module) { handle = _g_module_self (); if (handle) { main_module = g_new (GModule, 1); main_module->file_name = NULL; #if defined (G_OS_WIN32) && !defined(_WIN64) main_module->cp_file_name = NULL; #endif main_module->handle = handle; main_module->ref_count = 1; main_module->is_resident = TRUE; main_module->unload = NULL; main_module->next = NULL; } } else main_module->ref_count++; g_static_rec_mutex_unlock (&g_module_global_lock); return main_module; } /* we first search the module list by name */ module = g_module_find_by_name (file_name); if (module) { module->ref_count++; g_static_rec_mutex_unlock (&g_module_global_lock); return module; } /* check whether we have a readable file right away */ if (g_file_test (file_name, G_FILE_TEST_IS_REGULAR)) name = g_strdup (file_name); /* try completing file name with standard library suffix */ if (!name) { name = g_strconcat (file_name, "." G_MODULE_SUFFIX, NULL); if (!g_file_test (name, G_FILE_TEST_IS_REGULAR)) { g_free (name); name = NULL; } } /* try completing by appending libtool suffix */ if (!name) { name = g_strconcat (file_name, ".la", NULL); if (!g_file_test (name, G_FILE_TEST_IS_REGULAR)) { g_free (name); name = NULL; } } /* we can't access() the file, lets hope the platform backends finds * it via library paths */ if (!name) { gchar *dot = strrchr (file_name, '.'); gchar *slash = strrchr (file_name, G_DIR_SEPARATOR); /* make sure the name has a suffix */ if (!dot || dot < slash) name = g_strconcat (file_name, "." G_MODULE_SUFFIX, NULL); else name = g_strdup (file_name); } /* ok, try loading the module */ if (name) { /* if it's a libtool archive, figure library file to load */ if (str_check_suffix (name, ".la")) /* libtool archive? */ { gchar *real_name = parse_libtool_archive (name); /* real_name might be NULL, but then module error is already set */ if (real_name) { g_free (name); name = real_name; } } if (name) handle = _g_module_open (name, (flags & G_MODULE_BIND_LAZY) != 0, (flags & G_MODULE_BIND_LOCAL) != 0); } else { gchar *display_file_name = g_filename_display_name (file_name); g_module_set_error_unduped (g_strdup_printf ("unable to access file \"%s\"", display_file_name)); g_free (display_file_name); } g_free (name); if (handle) { gchar *saved_error; GModuleCheckInit check_init; const gchar *check_failed = NULL; /* search the module list by handle, since file names are not unique */ module = g_module_find_by_handle (handle); if (module) { _g_module_close (module->handle, TRUE); module->ref_count++; g_module_set_error (NULL); g_static_rec_mutex_unlock (&g_module_global_lock); return module; } saved_error = g_strdup (g_module_error ()); g_module_set_error (NULL); module = g_new (GModule, 1); module->file_name = g_strdup (file_name); #if defined (G_OS_WIN32) && !defined(_WIN64) module->cp_file_name = g_locale_from_utf8 (file_name, -1, NULL, NULL, NULL); #endif module->handle = handle; module->ref_count = 1; module->is_resident = FALSE; module->unload = NULL; module->next = modules; modules = module; /* check initialization */ if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init) && check_init != NULL) check_failed = check_init (module); /* we don't call unload() if the initialization check failed. */ if (!check_failed) g_module_symbol (module, "g_module_unload", (gpointer) &module->unload); if (check_failed) { gchar *error; error = g_strconcat ("GModule (", file_name, ") ", "initialization check failed: ", check_failed, NULL); g_module_close (module); module = NULL; g_module_set_error (error); g_free (error); } else g_module_set_error (saved_error); g_free (saved_error); } if (module != NULL && (module_debug_flags & G_MODULE_DEBUG_RESIDENT_MODULES)) g_module_make_resident (module); g_static_rec_mutex_unlock (&g_module_global_lock); return module; }
PUSS_EXPORT void* puss_plugin_create(Puss* app) { PussVConsole* self; gchar* vconsole_file; PangoFontDescription* desc; bindtextdomain(TEXT_DOMAIN, app->get_locale_path()); bind_textdomain_codeset(TEXT_DOMAIN, "UTF-8"); self = g_new0(PussVConsole, 1); self->app = app; self->line_height = -1; #ifdef _DEBUG vconsole_file = g_build_filename(app->get_plugins_path(), "vconsole_d.dll", NULL); #else vconsole_file = g_build_filename(app->get_plugins_path(), "vconsole.dll", NULL); #endif self->module = g_module_open(vconsole_file, G_MODULE_BIND_LAZY); g_free(vconsole_file); if( !self->module ) return self; if( !g_module_symbol(self->module, "get_vconsole_api", (gpointer*)&(self->get_vconsole_api)) ) return self; self->api = self->get_vconsole_api(); self->view = gtk_text_view_new(); desc = pango_font_description_from_string("monospace 9"); if( desc ) { gtk_widget_modify_font(self->view, desc); pango_font_description_free(desc); } self->adjust = GTK_ADJUSTMENT( gtk_adjustment_new(0, 0, 14, 1, 14, 14) ); self->sbar = gtk_vscrollbar_new(self->adjust); { GtkWidget* reset_btn = gtk_button_new_with_label("reset"); GtkWidget* show_hide_btn = gtk_button_new_with_label("show/hide"); GtkWidget* chdir_btn = gtk_button_new_with_label("chdir"); GtkWidget* vbox = gtk_vbox_new(FALSE, 2); GtkWidget* hbox = gtk_hbox_new(FALSE, 2); GtkWidget* panel = gtk_viewport_new(0, 0); g_signal_connect(reset_btn, "clicked", (GCallback)on_reset_btn_click, self); g_signal_connect(show_hide_btn, "clicked", (GCallback)on_show_hide_btn_click, self); g_signal_connect(chdir_btn, "clicked", (GCallback)on_chdir_btn_click, self); g_signal_connect(panel, "focus-in-event",G_CALLBACK(&on_active), self); gtk_box_pack_start(GTK_BOX(vbox), reset_btn, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), show_hide_btn, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), chdir_btn, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), self->view, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), self->sbar, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(panel), hbox); gtk_widget_show_all(panel); self->panel = panel; self->app->panel_append(self->panel, gtk_label_new(_("Terminal")), "puss_vconsole_plugin_panel", PUSS_PANEL_POS_BOTTOM); } self->need_update = FALSE; self->vcon = self->api->create(); if( self->vcon ) { self->vcon->on_screen_changed = vcon_on_screen_changed; self->vcon->on_quit = vcon_on_quit; self->vcon->tag = self; } g_signal_connect(self->view, "key-press-event", (GCallback)on_key_press, self); g_signal_connect(self->view, "scroll-event", (GCallback)on_scroll_event, self); g_signal_connect(self->view, "paste-clipboard", (GCallback)on_paste, self); g_signal_connect(self->view, "size-allocate", (GCallback)on_size_allocate, self); g_signal_connect(self->view, "size-request", (GCallback)on_size_request, self); g_signal_connect(GTK_TEXT_VIEW(self->view)->im_context, "commit", (GCallback)on_im_commit, self); g_signal_connect(self->adjust, "value-changed", (GCallback)on_sbar_changed, self); return self; }