static void
gp11_module_finalize (GObject *obj)
{
	GP11ModulePrivate *pv = G_TYPE_INSTANCE_GET_PRIVATE (obj, GP11_TYPE_MODULE, GP11ModulePrivate);
	GP11ModuleData *data = GP11_MODULE_GET_DATA (obj);

	g_assert (!pv->open_sessions);
	
	data->funcs = NULL;
	
	if (data->module) {
		if (!g_module_close (data->module))
			g_warning ("failed to close the pkcs11 module: %s", 
			           g_module_error ());
		data->module = NULL;
	}

	g_free (data->path);
	data->path = NULL;
	
	g_static_mutex_free (&pv->mutex);
	
	G_OBJECT_CLASS (gp11_module_parent_class)->finalize (obj);
}
示例#2
0
gboolean core_config_provider_init() {
	GError* err;
	ConfigModuleFunc entry;

	// load config module
	module_loaded* module = core_module_load(MODULE_TYPE_CONFIG, g_hash_table_lookup(g_options, "config"), &err);
	if (module == NULL)
		return FALSE;

	// find ConfigModule
	g_module_symbol(module->module, "ConfigModule", (gpointer*) &entry);
	if (entry == NULL) {
		core_log("core", LOG_CRIT, 1111, (gchar*) g_module_error());
		return FALSE;
	}

	// get vtable from module
	module->vtable = (module_vtable*) entry();

	// setup module as config_provider
	g_provider_config = module;

	return TRUE;
}
static gboolean
infinoted_plugin_manager_load_plugin(InfinotedPluginManager* manager,
                                     const gchar* plugin_path,
                                     const gchar* plugin_name,
                                     GKeyFile* key_file,
                                     GError** error)
{
  gchar* plugin_basename;
  gchar* plugin_filename;

  GModule* module;
  const InfinotedPlugin* plugin;
  InfinotedPluginInstance* instance;

  gboolean result;
  GError* local_error;

  InfBrowserIter root;
  InfinotedPluginManagerForeachConnectionData data;

  plugin_basename = g_strdup_printf(
    "libinfinoted-plugin-%s.%s",
    plugin_name,
    G_MODULE_SUFFIX
  );

  plugin_filename = g_build_filename(plugin_path, plugin_basename, NULL);
  g_free(plugin_basename);

  module = g_module_open(plugin_filename, G_MODULE_BIND_LOCAL);
  g_free(plugin_filename);

  if(module == NULL)
  {
    g_set_error(
      error,
      infinoted_plugin_manager_error_quark(),
      INFINOTED_PLUGIN_MANAGER_ERROR_OPEN_FAILED,
      "%s",
      g_module_error()
    );

    
    return FALSE;
  }

  if(g_module_symbol(module, "INFINOTED_PLUGIN", (gpointer*)&plugin) == FALSE)
  {
    g_set_error(
      error,
      infinoted_plugin_manager_error_quark(),
      INFINOTED_PLUGIN_MANAGER_ERROR_NO_ENTRY_POINT,
      "%s",
      g_module_error()
    );
    
    g_module_close(module);
    return FALSE;
  }

  instance = g_malloc(sizeof(InfinotedPluginInstance) + plugin->info_size);
  instance->module = module;
  instance->plugin = plugin;

  /* Call on_info_initialize, allowing the plugin to set default values */
  if(plugin->on_info_initialize != NULL)
    plugin->on_info_initialize(instance+1);

  /* Next, parse options from keyfile */
  if(plugin->options != NULL)
  {
    local_error = NULL;

    result = infinoted_parameter_load_from_key_file(
      plugin->options,
      key_file,
      plugin->name,
      instance+1,
      &local_error
    );
    
    if(result == FALSE)
    {
      g_free(instance);
      g_module_close(module);

      g_propagate_prefixed_error(
        error,
        local_error,
        "Failed to initialize plugin \"%s\": ",
        plugin_name
      );

      return FALSE;
    }
  }

  /* Finally, call on_initialize, which allows the plugin to initialize
   * itself with the plugin options. */
  if(plugin->on_initialize != NULL)
  {
    local_error = NULL;

    result = plugin->on_initialize(manager, instance+1, &local_error);

    if(local_error != NULL)
    {
      if(instance->plugin->on_deinitialize != NULL)
        instance->plugin->on_deinitialize(instance+1);

      g_free(instance);
      g_module_close(module);

      g_propagate_prefixed_error(
        error,
        local_error,
        "Failed to initialize plugin \"%s\": ",
        plugin_name
      );

      return FALSE;
    }
  }

  /* Register initial connections with plugin */
  data.manager = manager;
  data.instance = instance;
  infd_directory_foreach_connection(
    manager->directory,
    infinoted_plugin_manager_load_plugin_foreach_connection_func,
    &data
  );

  /* Register initial sessions with plugin */
  inf_browser_get_root(INF_BROWSER(manager->directory), &root);
  infinoted_plugin_manager_walk_directory(
    manager,
    &root,
    instance,
    infinoted_plugin_manager_add_session
  );

  infinoted_log_info(
    manager->log,
    _("Loaded plugin \"%s\" from \"%s\""),
    plugin_name,
    g_module_name(module)
  );

  manager->plugins = g_slist_prepend(manager->plugins, instance);

  return TRUE;
}
示例#4
0
文件: blog.c 项目: naihe2010/amblog
static void
blog_plugin_init_dir (const gchar *realpath)
{
  GDir *dir;
  GModule *mod;
  const gchar *name;
  gchar *modpath;
  blog_plugin_t *plg;
  const gchar * (*modname) ();
  GList *cur;

  dir = g_dir_open (realpath, 0600, NULL);
  if (dir == NULL)
    {
      return;
    }

  while ((name = g_dir_read_name (dir)) != NULL)
    {
      if (*name == '.')
        {
          continue;
        }

#ifdef WIN32
      if (g_ascii_strcasecmp (name + strlen (name) - 4, ".dll") != 0)
#else
      if (g_ascii_strcasecmp (name + strlen (name) - 3, ".so") != 0)
#endif
        {
          continue;
        }

      modpath = g_build_filename (realpath, name, NULL);
      if (modpath == NULL)
        {
          continue;
        }

      mod = g_module_open (modpath, G_MODULE_BIND_MASK);
      g_free (modpath);
      if (mod == NULL)
        {
          g_error (g_module_error ());
          continue;
        }

      g_module_symbol (mod, "module_name", (gpointer) &modname);
      if (modname == NULL)
        {
          g_error (g_module_error ());
          continue;
        }

      for (cur = blog_plugin_list;
           cur != NULL;
           cur = g_list_next (cur)
      )
        {
          plg = cur->data;
          if (plg 
              && plg->name 
              && strcmp (plg->name (), modname ()) == 0)
            {
              break;
            }
        }

      if (cur)
        {
          g_module_close (mod);
          continue;
        }

      plg = g_malloc (sizeof (blog_plugin_t));
      if (plg == NULL)
        {
          g_error (_ ("Memory error.\n"));
          g_module_close (mod);
          continue;
        } 

      g_module_symbol (mod, "module_name", (gpointer) &plg->name);
      g_module_symbol (mod, "module_version", (gpointer) &plg->version);
      g_module_symbol (mod, "module_init", (gpointer) &plg->init);
      g_module_symbol (mod, "module_destroy", (gpointer) &plg->destroy);
      g_module_symbol (mod, "blog_add_widget", (gpointer) &plg->add_widget);
      g_module_symbol (mod, "blog_add", (gpointer) &plg->add);
      g_module_symbol (mod, "blog_pub", (gpointer) &plg->pub);

      if (plg->init () == FALSE)
        {
          g_error (_ ("Module '%s' init failed.\n"), name);
          g_module_close (mod);
          g_free (plg);
        }

      blog_plugin_list = g_list_append (blog_plugin_list, plg);
    }

  g_dir_close (dir);
}
示例#5
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;
}
示例#6
0
char *
plugin_load (session *sess, char *filename, char *arg)
{
	void *handle;
	char *filepart;
	hexchat_init_func *init_func;
	hexchat_deinit_func *deinit_func;
#ifndef USE_GMODULE
	char *error;
#else
	char *pluginpath;
#endif

	/* get the filename without path */
	filepart = file_part (filename);

#ifdef USE_GMODULE
	/* load the plugin */
	if (!g_ascii_strcasecmp (filepart, filename))
	{
		/* no path specified, it's just the filename, try to load from config dir */
		pluginpath = g_build_filename (get_xdir (), filename, NULL);
		handle = g_module_open (pluginpath, 0);
		g_free (pluginpath);
	}
	else
	{
		/* try to load with absolute path */
		handle = g_module_open (filename, 0);
	}

	if (handle == NULL)
		return (char *)g_module_error ();

	/* find the init routine hexchat_plugin_init */
	if (!g_module_symbol (handle, "hexchat_plugin_init", (gpointer *)&init_func))
	{
		g_module_close (handle);
		return _("No hexchat_plugin_init symbol; is this really a HexChat plugin?");
	}

	/* find the plugin's deinit routine, if any */
	if (!g_module_symbol (handle, "hexchat_plugin_deinit", (gpointer *)&deinit_func))
		deinit_func = NULL;

#else

/* OpenBSD lacks this! */
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif

#ifndef RTLD_NOW
#define RTLD_NOW 0
#endif

	/* 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 hexchat_plugin_init */
	init_func = dlsym (handle, "hexchat_plugin_init");
	error = (char *)dlerror ();
	if (error != NULL)
	{
		dlclose (handle);
		return _("No hexchat_plugin_init symbol; is this really a HexChat plugin?");
	}

	/* find the plugin's deinit routine, if any */
	deinit_func = dlsym (handle, "hexchat_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;
}
示例#7
0
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(!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, "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(pseudo_type_name,module->params_size(module));
    module->parameter_lua_type = dt_lua_init_type_typeid(darktable.lua_state.state,my_type);
    luaA_struct_typeid(darktable.lua_state.state,my_type);
    dt_lua_register_format_typeid(darktable.lua_state.state,module,my_type);
#endif
    module->init(module);
#ifdef USE_LUA
    dt_lua_register_type_callback_type_typeid(darktable.lua_state.state,my_type,NULL,NULL,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;
}
示例#8
0
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;
}
示例#9
0
文件: plugin.c 项目: Louisvh/zathura
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_debug("%s is not a regular file. Skipping.", path);
      g_free(path);
      continue;
    }

    if (check_suffix(path) == false) {
      girara_debug("%s is not a plugin 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*) &register_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_try_malloc0(sizeof(zathura_plugin_t));
    if (plugin == NULL) {
      girara_error("Failed to allocate memory for plugin.");
      g_free(path);
      g_module_close(handle);
      continue;
    }

    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_debug("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);
}
示例#10
0
static gboolean
lt_ext_module_load(lt_ext_module_t *module)
{
	gchar *filename = g_strdup_printf("liblangtag-ext-%s." G_MODULE_SUFFIX,
					  module->name);
	gchar **path_list, *s, *path = NULL, *fullname = NULL;
	const gchar *env = g_getenv("LANGTAG_EXT_MODULE_PATH");
	gint i;
	gboolean retval = FALSE;
	gsize len;

	if (!env) {
		path_list = g_strsplit(
#ifdef GNOME_ENABLE_DEBUG
			BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_SEARCHPATH_SEPARATOR_S
			BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_DIR_SEPARATOR_S ".libs" G_SEARCHPATH_SEPARATOR_S
#endif
			LANGTAG_EXT_MODULE_PATH,
			G_SEARCHPATH_SEPARATOR_S,
			-1);
	} else {
		path_list = g_strsplit(env, 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--;
		g_free(path);
		path = g_strndup(s, len);
		if (path[0] != 0) {
			g_free(fullname);
			fullname = g_build_filename(path, filename, NULL);
			module->module = g_module_open(fullname,
						       G_MODULE_BIND_LAZY|G_MODULE_BIND_LOCAL);
			if (module->module) {
				gpointer func;

				lt_mem_add_ref(&module->parent, module->module,
					       (lt_destroy_func_t)g_module_close);
				g_module_symbol(module->module,
						"module_get_version",
						&func);
				if (!func) {
					g_warning(g_module_error());
					break;
				}
				if (((lt_ext_module_version_func_t)func)() != LT_EXT_MODULE_VERSION) {
					g_warning("`%s' isn't satisfied the required module version.",
						  filename);
					break;
				}
				g_module_symbol(module->module,
						"module_get_funcs",
						&func);
				if (!func) {
					g_warning(g_module_error());
					break;
				}
				if (!(module->funcs = ((lt_ext_module_get_funcs_func_t)func)())) {
					g_warning("No function table for `%s'",
						  filename);
					break;
				}
				g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
				      "Loading the external extension handler module: %s",
				      fullname);
				retval = TRUE;
			}
		}
	}
	if (!retval)
		g_warning("No such modules: %s", module->name);

	g_free(fullname);
	g_free(path);
	g_free(filename);
	g_strfreev(path_list);

	return retval;
}
示例#11
0
MidoriBrowser*
midori_private_app_new (const gchar* config,
                        const gchar* webapp,
                        gchar**      open_uris,
                        gchar**      execute_commands,
                        gint         inactivity_reset,
                        const gchar* block_uris)
{
    guint i;

    midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, config);
#ifndef HAVE_WEBKIT2
    g_object_set_data (G_OBJECT (webkit_get_default_session ()), "pass-through-console", (void*)1);
#endif

    /* Mask the timezone, which can be read by Javascript */
    g_setenv ("TZ", "UTC", TRUE);

    MidoriBrowser* browser = midori_browser_new ();
    g_signal_connect (browser, "new-window",
        G_CALLBACK (midori_frontend_browser_new_window_cb), NULL);

    MidoriWebSettings* settings = midori_settings_new_full (NULL);
    g_object_set (settings,
                  "preferred-languages", "en",
                  "enable-private-browsing", TRUE,
    #ifdef HAVE_LIBSOUP_2_29_91
                  "first-party-cookies-only", TRUE,
    #endif
                  "enable-html5-database", FALSE,
                  "enable-html5-local-storage", FALSE,
                  "enable-offline-web-application-cache", FALSE,
    /* Arguably DNS prefetching is or isn't a privacy concern. For the
     * lack of more fine-grained control we'll go the safe route. */
                  "enable-dns-prefetching", FALSE,
                  "strip-referer", TRUE,
                  "show-panel", FALSE,
                  "last-window-state", MIDORI_WINDOW_NORMAL,
                  "inactivity-reset", inactivity_reset,
                  "block-uris", block_uris,
                  NULL);
    midori_load_soup_session (settings);

    /* In-memory trash for re-opening closed tabs */
    KatzeArray* trash = katze_array_new (KATZE_TYPE_ITEM);
    g_signal_connect_after (trash, "add-item",
      G_CALLBACK (midori_trash_add_item_no_save_cb), NULL);

    KatzeArray* search_engines = midori_search_engines_new_from_folder (NULL);
    g_object_set (browser,
                  "settings", settings,
                  "trash", trash,
                  "search-engines", search_engines,
                  NULL);
    g_object_unref (settings);
    g_object_unref (trash);
    g_object_unref (search_engines);

    midori_browser_set_action_visible (browser, "Tools", FALSE);
    midori_browser_set_action_visible (browser, "ClearPrivateData", FALSE);
#if ENABLE_ADDSPEEDDIAL
    midori_browser_set_action_visible (browser, "AddSpeedDial", FALSE);
#endif
    #if GTK_CHECK_VERSION (3, 0, 0)
    g_object_set (gtk_widget_get_settings (GTK_WIDGET (browser)),
                  "gtk-application-prefer-dark-theme", TRUE,
                  NULL);
    #endif

    if (webapp != NULL)
    {
        gchar* tmp_uri = sokoke_magic_uri (webapp, FALSE, TRUE);
        g_object_set (settings, "homepage", tmp_uri, NULL);
        midori_browser_add_uri (browser, tmp_uri);
        g_free (tmp_uri);
    }

    for (i = 0; open_uris && open_uris[i]; i++)
    {
        gchar* new_uri = sokoke_magic_uri (open_uris[i], FALSE, TRUE);
        midori_browser_add_uri (browser, new_uri);
        g_free (new_uri);
    }
    if (midori_browser_get_n_pages (browser) == 0)
        midori_browser_add_uri (browser, "about:private");
    gtk_widget_show (GTK_WIDGET (browser));

    for (i = 0; execute_commands && execute_commands[i]; i++)
    {
        midori_browser_assert_action (browser, execute_commands[i]);
        midori_browser_activate_action (browser, execute_commands[i]);
    }

    /* FIXME need proper stock extension mechanism */
//由于整合了若干预置扩展,此处相应修改
#if 0
    midori_browser_activate_action (browser, "libtransfers." G_MODULE_SUFFIX "=true");
    midori_browser_activate_action (browser, "libabout." G_MODULE_SUFFIX "=true");
    midori_browser_activate_action (browser, "libopen-with." G_MODULE_SUFFIX "=true");
#else
    midori_browser_activate_action (browser, "libtransfers." G_MODULE_SUFFIX "=true");
    midori_browser_activate_action (browser, "libbuiltinextension." G_MODULE_SUFFIX "=true");
#endif
    
    g_assert (g_module_error () == NULL);

    return browser;
}
GHashTable *
vpn_get_plugins (GError **error)
{
	GDir *dir;
	const char *f;

	if (error)
		g_return_val_if_fail (*error == NULL, NULL);

	if (plugins)
		return plugins;

	dir = g_dir_open (NM_VPN_CONFIG_DIR, 0, error);
	if (!dir)
		return NULL;

	plugins = g_hash_table_new_full (g_str_hash, g_str_equal,
	                                 (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref);

	while ((f = g_dir_read_name (dir))) {
		char *path = NULL, *service = NULL;
		char *so_path = NULL, *so_name = NULL;
		GKeyFile *keyfile = NULL;
		GModule *module;
		NMVpnPluginUiFactory factory = NULL;

		if (!g_str_has_suffix (f, ".name"))
			continue;

		path = g_strdup_printf ("%s/%s", NM_VPN_CONFIG_DIR, f);

		keyfile = g_key_file_new ();
		if (!g_key_file_load_from_file (keyfile, path, 0, NULL))
			goto next;

		service = g_key_file_get_string (keyfile, "VPN Connection", "service", NULL);
		if (!service)
			goto next;

		so_path = g_key_file_get_string (keyfile,  "GNOME", "properties", NULL);
		if (!so_path)
			goto next;

		/* Remove any path and extension components, then reconstruct path
		 * to the SO in LIBDIR
		 */
		so_name = g_path_get_basename (so_path);
		g_free (so_path);
		so_path = g_build_filename (NM_VPN_MODULE_DIR, so_name, NULL);
		g_free (so_name);

		module = g_module_open (so_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
		if (!module) {
			g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Cannot load the VPN plugin which provides the "
			             "service '%s'.", service);
			goto next;
		}

		if (g_module_symbol (module, "nm_vpn_plugin_ui_factory", (gpointer) &factory)) {
			NMVpnPluginUiInterface *plugin;
			GError *factory_error = NULL;
			gboolean success = FALSE;

			plugin = factory (&factory_error);
			if (plugin) {
				char *plug_name = NULL, *plug_service = NULL;

				/* Validate plugin properties */
				g_object_get (G_OBJECT (plugin),
				              NM_VPN_PLUGIN_UI_INTERFACE_NAME, &plug_name,
				              NM_VPN_PLUGIN_UI_INTERFACE_SERVICE, &plug_service,
				              NULL);
				if (!plug_name || !strlen (plug_name)) {
					g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "cannot load VPN plugin in '%s': missing plugin name", 
					             g_module_name (module));
				} else if (!plug_service || strcmp (plug_service, service)) {
					g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "cannot load VPN plugin in '%s': invalid service name", 
					             g_module_name (module));
				} else {
					/* Success! */
					g_object_set_data_full (G_OBJECT (plugin), "gmodule", module,
					                        (GDestroyNotify) g_module_close);
					g_hash_table_insert (plugins, g_strdup (service), plugin);
					success = TRUE;
				}
				g_free (plug_name);
				g_free (plug_service);
			} else {
				g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "cannot load VPN plugin in '%s': %s", 
				             g_module_name (module), g_module_error ());
			}

			if (!success)
				g_module_close (module);
		} else {
			g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "cannot locate nm_vpn_plugin_ui_factory() in '%s': %s", 
			             g_module_name (module), g_module_error ());
			g_module_close (module);
		}

	next:
		g_free (so_path);
		g_free (service);
		g_key_file_free (keyfile);
		g_free (path);
	}
	g_dir_close (dir);

	return plugins;
}
示例#13
0
/* Returns 1 if ok, 0 if error in module and
   -1 if module wasn't found */
static int module_load_name(const char *path, const char *rootmodule,
			    const char *submodule, int silent)
{
	void (*module_init) (void);
	void (*module_deinit) (void);
	void (*module_version) (int *);
	GModule *gmodule;
        MODULE_REC *module;
	MODULE_FILE_REC *rec;
	gpointer value_version = NULL;
	gpointer value1, value2 = NULL;
	char *versionfunc, *initfunc, *deinitfunc;
	int module_abi_version = 0;
        int found;

	gmodule = module_open(path, &found);
	if (gmodule == NULL) {
		if (!silent || found) {
			module_error(MODULE_ERROR_LOAD, g_module_error(),
				     rootmodule, submodule);
		}
		return found ? 0 : -1;
	}

	/* get the module's irssi abi version and bail out on mismatch */
	versionfunc = module_get_func(rootmodule, submodule, "abicheck");
	if (!g_module_symbol(gmodule, versionfunc, &value_version)) {
		g_free(versionfunc);
		module_error(MODULE_ERROR_VERSION_MISMATCH, "0",
			     rootmodule, submodule);
		g_module_close(gmodule);
		return 0;
	}
	g_free(versionfunc);
	module_version = value_version;
	module_version(&module_abi_version);
	if (module_abi_version != IRSSI_ABI_VERSION) {
		char *module_abi_versionstr = g_strdup_printf("%d", module_abi_version);
		module_error(MODULE_ERROR_VERSION_MISMATCH, module_abi_versionstr,
			     rootmodule, submodule);
		g_free(module_abi_versionstr);
		g_module_close(gmodule);
		return 0;
	}

	/* get the module's init() and deinit() functions */
	initfunc = module_get_func(rootmodule, submodule, "init");
	deinitfunc = module_get_func(rootmodule, submodule, "deinit");
	found = g_module_symbol(gmodule, initfunc, &value1) &&
		g_module_symbol(gmodule, deinitfunc, &value2);
	g_free(initfunc);
	g_free(deinitfunc);

	if (!found) {
		module_error(MODULE_ERROR_INVALID, NULL,
			     rootmodule, submodule);
		g_module_close(gmodule);
		return 0;
	}

	module_init = value1;
	module_deinit = value2;

	/* Call the module's init() function - it should register itself
	   with module_register() function, abort if it doesn't. */
	module_init();

	module = module_find(rootmodule);
	rec = module == NULL ? NULL :
                g_strcmp0(rootmodule, submodule) == 0 ?
		module_file_find(module, "core") :
		module_file_find(module, submodule);
	if (rec == NULL) {
		rec = module_register_full(rootmodule, submodule, NULL);
		rec->gmodule = gmodule;
		module_file_unload(rec);

		module_error(MODULE_ERROR_INVALID, NULL,
			     rootmodule, submodule);
                return 0;
	}

        rec->module_deinit = module_deinit;
	rec->gmodule = gmodule;
        rec->initialized = TRUE;

	settings_check_module(rec->defined_module_name);

	signal_emit("module loaded", 2, rec->root, rec);
	return 1;
}
示例#14
0
struct plugin *load_plugin(const char *modulesdir, const char *name)
{
	GModule *m = NULL;
	struct plugin_ops *ops = NULL;
	struct plugin *p = g_new0(struct plugin, 1);
	gchar *path_name = NULL;

	/* Try to load from .so file */
	if (!ops) {

		if (g_file_test(name, G_FILE_TEST_EXISTS))path_name = g_strdup(name);
		else path_name = g_module_build_path(modulesdir, name);

		m = g_module_open(path_name, 0);

		if (!m) {
			log_global(LOG_ERROR, "Unable to open module %s(%s), ignoring", path_name, g_module_error());
			g_free(path_name);
			g_free(p);
			return NULL;
		}

		if (!g_module_symbol(m, "plugin", (gpointer)&ops)) {
			log_global(LOG_ERROR, "%s: No valid plugin information found",
				strchr(path_name, '/')?(strrchr(path_name, '/')+1):"error"
					   );
			g_free(path_name);
			g_free(p);
			return NULL;
		}
	}

	if (plugin_loaded(ops->name)) {
		log_global(LOG_WARNING, "%s: Plugin already loaded", ops->name);
		g_free(path_name);
		g_free(p);
		return NULL;
	}

	if (ops->version != CTRLPROXY_PLUGIN_VERSION) {
		log_global(LOG_WARNING, "%s: Plugin has incompatible version %d, expected %d",
				   ops->name, ops->version, CTRLPROXY_PLUGIN_VERSION);
		g_free(path_name);
		g_free(p);
		return NULL;
	}

	g_free(path_name);

	p->module = m;
	p->ops = ops;

	if (!p->ops->init()) {
		log_global( LOG_ERROR, "%s: Error during initialization.", p->ops->name);
		g_free(p);
		return NULL;
	}

	log_global(LOG_INFO, "Plugin '%s' loaded", ops->name);

	plugins = g_list_append(plugins, p);

	return p;
}
示例#15
0
int main (int argc,
	  char **argv)
{
	gint retval;
	GList *etds, *l;
	UhmServer *server;
	const gchar *module_path;
	GModule *module = NULL;

	retval = ews_test_init (argc, argv);

	if (retval < 0) {
		g_printerr ("Failed to initialize test\n");
		goto exit;
	}

	if (!g_module_supported ()) {
		g_printerr ("GModule not supported\n");
		retval = 1;
		goto exit;
	}

	module_path = CALENDAR_MODULE_DIR "libecalbackendews.so";
	module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);

	if (module == NULL) {
		g_printerr ("Failed to load module '%s': %s\n", module_path, g_module_error ());
		retval = 2;
		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 ());
			retval = 3;
			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 ());
			retval = 4;
			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 ());
			retval = 5;
			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:
	if (module != NULL)
		g_module_close (module);
	if (builtin_timezones != NULL)
		icalarray_free (builtin_timezones);
	ews_test_cleanup ();

	return retval;
}
示例#16
0
bool PluginPackage::load()
{
    if (m_isLoaded) {
        m_loadCount++;
        return true;
    }

    m_module = g_module_open((m_path.utf8()).data(), G_MODULE_BIND_LOCAL);

    if (!m_module) {
        LOG(Plugin,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error());
        return false;
    }

    m_isLoaded = true;

    NP_InitializeFuncPtr NP_Initialize;
    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);

    m_browserFuncs.size = sizeof (m_browserFuncs);
    m_browserFuncs.version = NP_VERSION_MINOR;
    m_browserFuncs.geturl = NPN_GetURL;
    m_browserFuncs.posturl = NPN_PostURL;
    m_browserFuncs.requestread = NPN_RequestRead;
    m_browserFuncs.newstream = NPN_NewStream;
    m_browserFuncs.write = NPN_Write;
    m_browserFuncs.destroystream = NPN_DestroyStream;
    m_browserFuncs.status = NPN_Status;
    m_browserFuncs.uagent = NPN_UserAgent;
    m_browserFuncs.memalloc = NPN_MemAlloc;
    m_browserFuncs.memfree = NPN_MemFree;
    m_browserFuncs.memflush = NPN_MemFlush;
    m_browserFuncs.reloadplugins = NPN_ReloadPlugins;
    m_browserFuncs.geturlnotify = NPN_GetURLNotify;
    m_browserFuncs.posturlnotify = NPN_PostURLNotify;
    m_browserFuncs.getvalue = NPN_GetValue;
    m_browserFuncs.setvalue = NPN_SetValue;
    m_browserFuncs.invalidaterect = NPN_InvalidateRect;
    m_browserFuncs.invalidateregion = NPN_InvalidateRegion;
    m_browserFuncs.forceredraw = NPN_ForceRedraw;
    m_browserFuncs.getJavaEnv = NPN_GetJavaEnv;
    m_browserFuncs.getJavaPeer = NPN_GetJavaPeer;
    m_browserFuncs.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
    m_browserFuncs.poppopupsenabledstate = NPN_PopPopupsEnabledState;

    m_browserFuncs.releasevariantvalue = _NPN_ReleaseVariantValue;
    m_browserFuncs.getstringidentifier = _NPN_GetStringIdentifier;
    m_browserFuncs.getstringidentifiers = _NPN_GetStringIdentifiers;
    m_browserFuncs.getintidentifier = _NPN_GetIntIdentifier;
    m_browserFuncs.identifierisstring = _NPN_IdentifierIsString;
    m_browserFuncs.utf8fromidentifier = _NPN_UTF8FromIdentifier;
    m_browserFuncs.createobject = _NPN_CreateObject;
    m_browserFuncs.retainobject = _NPN_RetainObject;
    m_browserFuncs.releaseobject = _NPN_ReleaseObject;
    m_browserFuncs.invoke = _NPN_Invoke;
    m_browserFuncs.invokeDefault = _NPN_InvokeDefault;
    m_browserFuncs.evaluate = _NPN_Evaluate;
    m_browserFuncs.getproperty = _NPN_GetProperty;
    m_browserFuncs.setproperty = _NPN_SetProperty;
    m_browserFuncs.removeproperty = _NPN_RemoveProperty;
    m_browserFuncs.hasproperty = _NPN_HasMethod;
    m_browserFuncs.hasmethod = _NPN_HasProperty;
    m_browserFuncs.setexception = _NPN_SetException;
    m_browserFuncs.enumerate = _NPN_Enumerate;
    m_browserFuncs.construct = _NPN_Construct;

#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;
}
示例#17
0
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;
}
示例#18
0
/**
 * 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;
}
示例#19
0
sc_result sc_ext_initialize(const sc_char *ext_dir_path)
{
    GDir *ext_dir = nullptr;
    const gchar *file_name = 0;
    GModule *module = 0;
    gchar *module_path = 0;
    fModuleFunc func = 0;

    // doesn't need to initialize extensions
    if (ext_dir_path == nullptr)
        return SC_RESULT_OK;

    // check if modules supported on this platform
    if (g_module_supported() == FALSE)
    {
        g_warning("Modules not supported on this platform");
        return SC_RESULT_ERROR;
    }

    g_message("Initialize extensions from %s", ext_dir_path);

    // check if specified directory exist
    if (g_file_test(ext_dir_path, G_FILE_TEST_IS_DIR) == FALSE)
        return SC_RESULT_ERROR_INVALID_PARAMS;

    // get list of files in extension directory
    ext_dir = g_dir_open(ext_dir_path, 0, 0);
    if (ext_dir == nullptr)
        return SC_RESULT_ERROR;

    modules_table = g_hash_table_new(&g_str_hash, &modules_table_equal_func);

    // list all files in directory and try to load them
    file_name = g_dir_read_name(ext_dir);
    while (file_name != nullptr)
    {
        // build module path
        module_path = g_module_build_path(ext_dir_path, file_name);

        // open module
        module = g_module_open(module_path, G_MODULE_BIND_LOCAL);

        // skip non module files
        if (g_str_has_suffix(file_name, G_MODULE_SUFFIX) == TRUE)
        {

            if (module == nullptr)
            {
                g_warning("Can't load module: %s. Error: %s", file_name, g_module_error());
            }else
            {
                g_message("Initialize module: %s", file_name);
                if (g_module_symbol(module, "initialize", (gpointer*) &func) == FALSE)
                {
                    g_warning("Can't find 'initialize' symbol in module: %s", file_name);
                }else
                {
                    if (func() != SC_RESULT_OK)
                    {
                        g_warning("Something happends, on module initialization: %s", file_name);
                    }
                }

                g_hash_table_insert(modules_table, module_path, (gpointer)module);
            }
        }

        file_name = g_dir_read_name(ext_dir);
    }

    g_dir_close(ext_dir);

    return SC_RESULT_OK;
}
示例#20
0
GType
gsk_load_type_introspective (const char  *type_name,
			     gpointer     unused,
			     GError     **error)
{
  static gboolean self_inited = FALSE;
  static GModule *self_module = NULL;
  guint index = 0;
  GType type;
  GString *func_name;
  gpointer symbol;

  (void) unused;

  type = g_type_from_name (type_name);
  if (type != G_TYPE_INVALID)
    return type;

  /* Transform `GObject' into `g_object_get_type',
   * which should be a function that returns a GType,
   * if we're lucky...
   */
  func_name = g_string_new ("");
  while (type_name[index] != '\0')
    {
      if ('A' <= type_name[index] && type_name[index] <= 'Z')
	{
	  if (index > 0)
	    g_string_append_c (func_name, '_');
	  g_string_append_c (func_name, g_ascii_tolower (type_name[index]));
	}
      else
	g_string_append_c (func_name, type_name[index]);
      ++index;
    }
  g_string_append (func_name, "_get_type");

  if (!self_inited)
    {
      self_inited = TRUE;
      self_module = g_module_open (NULL, G_MODULE_BIND_LAZY);
      if (self_module == NULL)
	{
	  g_set_error (error,
		       GSK_G_ERROR_DOMAIN,
		       GSK_ERROR_UNKNOWN,
		       "g_module_open: %s",
		       g_module_error ());
	  goto DONE;
	}
    }
  if (g_module_symbol (self_module, func_name->str, &symbol))
    {
      GType (*func) () = (GType (*)()) symbol;
      const char *name;
      GTypeClass *klass;

      type = (*func) ();
      name = g_type_name (type);
      if (name == NULL)
	{
	  g_set_error (error,
		       GSK_G_ERROR_DOMAIN,
		       GSK_ERROR_UNKNOWN,
		       "called %s, didn't get a valid GType",
		       func_name->str);
	  type = G_TYPE_INVALID;
	  goto DONE;
	}
      if (strcmp (name, type_name) != 0)
	{
	  g_set_error (error,
		       GSK_G_ERROR_DOMAIN,
		       GSK_ERROR_UNKNOWN,
		       "called %s: got %s instead of %s",
		       func_name->str,
		       name,
		       type_name);
	  type = G_TYPE_INVALID;
	  goto DONE;
	}

      /* Sometimes the registrations in the class_init are vital. */
      klass = g_type_class_ref (type);
      g_type_class_unref (klass);
    }
  else
    {
      g_set_error (error,
		   GSK_G_ERROR_DOMAIN,
		   GSK_ERROR_UNKNOWN,
		   "couldn't find symbol %s: %s",
		   func_name->str,
		   g_module_error ());
    }

DONE:
  g_string_free (func_name, TRUE);
  return type;
}
示例#21
0
/* Returns 1 if ok, 0 if error in module and
   -1 if module wasn't found */
static int module_load_name(const char *path, const char *rootmodule,
			    const char *submodule, int silent)
{
	void (*module_init) (void);
	void (*module_deinit) (void);
	GModule *gmodule;
        MODULE_REC *module;
	MODULE_FILE_REC *rec;
	gpointer value1, value2;
	char *initfunc, *deinitfunc;
        int found;

	gmodule = module_open(path, &found);
	if (gmodule == NULL) {
		if (!silent || found) {
			module_error(MODULE_ERROR_LOAD, g_module_error(),
				     rootmodule, submodule);
		}
		return found ? 0 : -1;
	}

	/* get the module's init() and deinit() functions */
	initfunc = module_get_func(rootmodule, submodule, "init");
	deinitfunc = module_get_func(rootmodule, submodule, "deinit");
	found = g_module_symbol(gmodule, initfunc, &value1) &&
		g_module_symbol(gmodule, deinitfunc, &value2);
	g_free(initfunc);
	g_free(deinitfunc);

	module_init = value1;
	module_deinit = value2;

	if (!found) {
		module_error(MODULE_ERROR_INVALID, NULL,
			     rootmodule, submodule);
		g_module_close(gmodule);
		return 0;
	}

	/* Call the module's init() function - it should register itself
	   with module_register() function, abort if it doesn't. */
	module_init();

	module = module_find(rootmodule);
	rec = module == NULL ? NULL :
                strcmp(rootmodule, submodule) == 0 ?
		module_file_find(module, "core") :
		module_file_find(module, submodule);
	if (rec == NULL) {
		rec = module_register_full(rootmodule, submodule, NULL);
		rec->gmodule = gmodule;
		module_file_unload(rec);

		module_error(MODULE_ERROR_INVALID, NULL,
			     rootmodule, submodule);
                return 0;
	}

        rec->module_deinit = module_deinit;
	rec->gmodule = gmodule;
        rec->initialized = TRUE;

	settings_check_module(rec->defined_module_name);

	signal_emit("module loaded", 2, rec->root, rec);
	return 1;
}
示例#22
0
int
main (int   arg,
      char *argv[])
{
  GModule *module_self, *module_a, *module_b;
  gchar *string;
  gchar *plugin_a, *plugin_b;
  SimpleFunc f_a, f_b, f_self;
  GModuleFunc gmod_f;

  string = g_get_current_dir ();
  g_print ("testgmodule (%s):\n", string);

#if (G_MODULE_IMPL == G_MODULE_IMPL_WIN32)
  plugin_a = g_strconcat (string, "\\libgplugin_a.dll", NULL);
  plugin_b = g_strconcat (string, "\\libgplugin_b.dll", NULL);
#elif (G_MODULE_IMPL == G_MODULE_IMPL_DLD)
  plugin_a = g_strconcat (string, "/.libs/", "libgplugin_a.sl", NULL);
  plugin_b = g_strconcat (string, "/.libs/", "libgplugin_b.sl", NULL);
#else /* neither DLD nor WIN32 */
  plugin_a = g_strconcat (string, "/.libs/", "libgplugin_a.so", NULL);
  plugin_b = g_strconcat (string, "/.libs/", "libgplugin_b.so", NULL);
#endif
  g_free (string);

  /* module handles
   */
  g_print ("get main module handle\n");
  module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
  if (!module_self)
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("check that not yet bound symbols in shared libraries of main module are retrievable:\n");
  string = "g_module_close";
  g_print ("retrive symbol `%s' from \"%s\":\n", string, g_basename (g_module_name (module_self)));
  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrived symbol `%s' as %p\n", string, f_self);
  g_print ("load plugin from \"%s\"\n", plugin_a);
  module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
  if (!module_a)
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("load plugin from \"%s\"\n", plugin_b);
  module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
  if (!module_b)
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }

  /* get plugin specific symbols and call them
   */
  string = "gplugin_a_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  string = "gplugin_b_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin function(%p) A: ", f_a);
  f_a ();
  g_print ("call plugin function(%p) B: ", f_b);
  f_b ();

  /* get and call globally clashing functions
   */
  string = "g_clash_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin function(%p) self: ", f_self);
  f_self ();
  g_print ("call plugin function(%p) A: ", f_a);
  f_a ();
  g_print ("call plugin function(%p) B: ", f_b);
  f_b ();

  /* get and call clashing plugin functions
   */
  string = "gplugin_clash_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
    f_self = NULL;
  g_print ("retrived function `%s' from self: %p\n", string, f_self);
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin function(%p) A: ", f_a);
  plugin_clash_func = f_a;
  plugin_clash_func ();
  g_print ("call plugin function(%p) B: ", f_b);
  plugin_clash_func = f_b;
  plugin_clash_func ();

  /* call gmodule function form A
   */
  string = "gplugin_a_module_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &gmod_f))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin A's module function(%p):\n{\n", gmod_f);
  gmod_f (module_b);
  g_print ("}\n");

  
  /* unload plugins
   */
  g_print ("unload plugin A:\n");
  if (!g_module_close (module_a))
    g_print ("error: %s\n", g_module_error ());
  g_print ("unload plugin B:\n");
  if (!g_module_close (module_b))
    g_print ("error: %s\n", g_module_error ());

#if 0
  g_log_set_fatal_mask ("GModule", G_LOG_FATAL_MASK|G_LOG_LEVEL_WARNING);
  g_module_symbol (0, 0, 0);
  g_warning("jahooo");
  g_on_error_query (".libs/testgmodule");
#endif
  
  return 0;
}
int
main (int   arg,
      char *argv[])
{
  GModule *module_self, *module_a, *module_b;
  gchar *dir;
  gchar *plugin_a, *plugin_b;
  SimpleFunc f_a, f_b, f_self;
  GModuleFunc gmod_f;

  if (!g_module_supported ())
    return 0;

  dir = g_get_current_dir ();

  plugin_a = g_strconcat (dir, G_DIR_SEPARATOR_S "libmoduletestplugin_a", 
			  NULL);
  plugin_b = g_strconcat (dir, G_DIR_SEPARATOR_S "libmoduletestplugin_b", 
			  NULL);

  g_free (dir);

  /* module handles */
  
  module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
  if (!module_self)
    g_error ("error: %s", g_module_error ());

  if (!g_module_symbol (module_self, "g_module_close", (gpointer *) &f_self))
    g_error ("error: %s", g_module_error ());

  module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
  if (!module_a)
    g_error ("error: %s", g_module_error ());

  module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
  if (!module_b)
    g_error ("error: %s", g_module_error ());

  /* get plugin state vars */

  if (!g_module_symbol (module_a, "gplugin_a_state", 
			(gpointer *) &gplugin_a_state))
    g_error ("error: %s", g_module_error ());
  
  if (!g_module_symbol (module_b, "gplugin_b_state", 
			(gpointer *) &gplugin_b_state))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, "check-init");
  
  /* get plugin specific symbols and call them
   */
  if (!g_module_symbol (module_a, "gplugin_a_func", (gpointer *) &f_a))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  if (!g_module_symbol (module_b, "gplugin_b_func", (gpointer *) &f_b))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  f_a ();
  test_states (NULL, "Hello world", NULL);
  
  f_b ();
  test_states (NULL, NULL, "Hello world");
  
  /* get and call globally clashing functions
   */
 
  if (!g_module_symbol (module_self, "g_clash_func", (gpointer *) &f_self))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  if (!g_module_symbol (module_a, "g_clash_func", (gpointer *) &f_a))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  if (!g_module_symbol (module_b, "g_clash_func", (gpointer *) &f_b))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  f_self ();
  test_states ("global clash", NULL, NULL);
  
  f_a ();
  test_states (NULL, "global clash", NULL);

  f_b ();
  test_states (NULL, NULL, "global clash");

  /* get and call clashing plugin functions  */

  if (!g_module_symbol (module_a, "gplugin_clash_func", (gpointer *) &f_a))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  if (!g_module_symbol (module_b, "gplugin_clash_func", (gpointer *) &f_b))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  plugin_clash_func = f_a;
  plugin_clash_func ();
  test_states (NULL, "plugin clash", NULL);

  plugin_clash_func = f_b;
  plugin_clash_func ();
  test_states (NULL, NULL, "plugin clash");

  /* call gmodule function from A  */

  if (!g_module_symbol (module_a, "gplugin_a_module_func", (gpointer *) &gmod_f))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  gmod_f (module_b);
  test_states (NULL, NULL, "BOOH");
 
  gmod_f (module_a);
  test_states (NULL, "BOOH", NULL);

  /* unload plugins  */

  if (!g_module_close (module_a))
    g_error ("error: %s", g_module_error ());

  if (!g_module_close (module_b))
    g_error ("error: %s", g_module_error ());
 
  return 0;
}
static ThemeEngine* load_theme_engine(const char *name)
{
	ThemeEngine* engine;
	char* path;

	path = g_module_build_path (ENGINES_DIR, name);

	engine = g_new0(ThemeEngine, 1);
	engine->ref_count = 1;
	engine->module = g_module_open(path, G_MODULE_BIND_LAZY);

	g_free(path);

	if (engine->module == NULL)
			goto error;

	#define BIND_REQUIRED_FUNC(name) \
		if (!g_module_symbol(engine->module, #name, (gpointer*) &engine->name)) \
		{ \
			/* Too harsh! Fall back to default. */ \
			g_warning("Theme doesn't provide the required function '%s'", #name); \
			goto error; \
		}

	#define BIND_OPTIONAL_FUNC(name) \
		g_module_symbol(engine->module, #name, (gpointer*) &engine->name);

	BIND_REQUIRED_FUNC(theme_check_init);
	BIND_REQUIRED_FUNC(get_theme_info);
	BIND_REQUIRED_FUNC(create_notification);
	BIND_REQUIRED_FUNC(set_notification_text);
	BIND_REQUIRED_FUNC(set_notification_icon);
	BIND_REQUIRED_FUNC(set_notification_arrow);
	BIND_REQUIRED_FUNC(add_notification_action);
	BIND_REQUIRED_FUNC(clear_notification_actions);
	BIND_REQUIRED_FUNC(move_notification);

	BIND_OPTIONAL_FUNC(destroy_notification);
	BIND_OPTIONAL_FUNC(show_notification);
	BIND_OPTIONAL_FUNC(hide_notification);
	BIND_OPTIONAL_FUNC(set_notification_timeout);
	BIND_OPTIONAL_FUNC(set_notification_hints);
	BIND_OPTIONAL_FUNC(notification_tick);
	BIND_OPTIONAL_FUNC(get_always_stack);

	if (!engine->theme_check_init(NOTIFICATION_DAEMON_MAJOR_VERSION, NOTIFICATION_DAEMON_MINOR_VERSION, NOTIFICATION_DAEMON_MICRO_VERSION))
	{
		g_warning ("Theme doesn't work with this version of mate-notification-daemon");
		goto error;
	}

	return engine;

	error:

		if (engine->module != NULL && !g_module_close (engine->module))
		{
			g_warning("%s: %s", name, g_module_error());
		}

		g_free(engine);
		return NULL;
}
示例#25
0
void PluginManager::loadLibrary(const char* library)
{    
    GModule *module = NULL;
    rsGetPluginFunc getPluginFunc = NULL;

    /* Check whether glib is compiled with plugin support */
    if(g_module_supported() == FALSE) {
        throw runtime_error("GLib is not compiled with module support which is necessary to load the tools");
    }

    module = g_module_open(library, G_MODULE_BIND_MASK);

    /* Check whether the plugin was loaded successfully */
    if(module == NULL) {
        throw runtime_error( (string("Library '") + string(library) + string("' could not be opened, because of the following error: ") + string(g_module_error())).c_str() );
    }

    /* Load the symbol and assign it to our function pointer */
    if(g_module_symbol(module, "rsGetPlugin", (gpointer *) &getPluginFunc) == FALSE) {
        throw runtime_error( (string("Library '") + string(library) + string("' could not be loaded, due to the following error: ") + string(g_module_error()) ).c_str() );
    }

    /* acquire the plugin */
    Plugin *plugin = getPluginFunc();
    registerPlugin(plugin);

    //if(g_module_close(module) == FALSE) {
    //    throw runtime_error( (string("Library '") + string(library) + string("' could not be closed, due to the following error: ") + string(g_module_error()) ).c_str() );
    //}
}
static gboolean
open_library (GstRealAudioDec * dec, gint version, GstRADecLibrary * lib)
{
  const gchar *path, *names;
  gchar **split_names, **split_path;
  gint i, j;
  gpointer ra_close_codec, ra_decode, ra_free_decoder;
  gpointer ra_open_codec2, ra_init_decoder, ra_set_flavor;
  gpointer set_dll_access_path = NULL, ra_set_pwd = NULL;
  gchar *tmppath = NULL;
  guint16 res = 0;

  path = dec->real_codecs_path ? dec->real_codecs_path :
      DEFAULT_REAL_CODECS_PATH;

  switch (version) {
    case GST_REAL_AUDIO_DEC_VERSION_COOK:
      names = dec->racook_names ? dec->racook_names : DEFAULT_RACOOK_NAMES;
      break;
    case GST_REAL_AUDIO_DEC_VERSION_ATRK:
      names = dec->raatrk_names ? dec->raatrk_names : DEFAULT_RAATRK_NAMES;
      break;
    case GST_REAL_AUDIO_DEC_VERSION_14_4:
      names = dec->ra14_4_names ? dec->ra14_4_names : DEFAULT_RA14_4_NAMES;
      break;
    case GST_REAL_AUDIO_DEC_VERSION_28_8:
      names = dec->ra28_8_names ? dec->ra28_8_names : DEFAULT_RA28_8_NAMES;
      break;
    case GST_REAL_AUDIO_DEC_VERSION_SIPR:
      names = dec->rasipr_names ? dec->rasipr_names : DEFAULT_RASIPR_NAMES;
      break;
    default:
      goto unknown_version;
  }

  GST_LOG_OBJECT (dec, "splitting paths %s, names %s", path, names);

  split_path = g_strsplit (path, ":", 0);
  split_names = g_strsplit (names, ":", 0);

  for (i = 0; split_path[i]; i++) {
    for (j = 0; split_names[j]; j++) {
      gchar *codec = g_strconcat (split_path[i], "/", split_names[j], NULL);

      GST_LOG_OBJECT (dec, "opening module %s", codec);

      /* This is racy, but it doesn't matter here; would be nice if GModule
       * gave us a GError instead of an error string, but it doesn't, so.. */
      if (g_file_test (codec, G_FILE_TEST_EXISTS)) {
        lib->module = g_module_open (codec, G_MODULE_BIND_LAZY);
        if (lib->module == NULL) {
          GST_ERROR_OBJECT (dec, "Could not open codec library '%s': %s",
              codec, g_module_error ());
        }
      } else {
        GST_DEBUG_OBJECT (dec, "%s does not exist", codec);
      }
      g_free (codec);
      if (lib->module)
        goto codec_search_done;
    }
  }

codec_search_done:
  /* we keep the path for a while to set the dll access path */
  g_strfreev (split_names);

  if (lib->module == NULL)
    goto could_not_open;

  GST_LOG_OBJECT (dec, "finding symbols");

  if (!g_module_symbol (lib->module, "RACloseCodec", &ra_close_codec) ||
      !g_module_symbol (lib->module, "RADecode", &ra_decode) ||
      !g_module_symbol (lib->module, "RAFreeDecoder", &ra_free_decoder) ||
      !g_module_symbol (lib->module, "RAOpenCodec2", &ra_open_codec2) ||
      !g_module_symbol (lib->module, "RAInitDecoder", &ra_init_decoder) ||
      !g_module_symbol (lib->module, "RASetFlavor", &ra_set_flavor)) {
    goto could_not_load;
  }

  g_module_symbol (lib->module, "RASetPwd", &ra_set_pwd);
  g_module_symbol (lib->module, "SetDLLAccessPath", &set_dll_access_path);

  lib->RACloseCodec = (guint16 (*)(gpointer)) ra_close_codec;
  lib->RADecode =
      (guint16 (*)(gpointer, guint8 *, guint32, guint8 *, guint32 *, guint32))
      ra_decode;
  lib->RAFreeDecoder = (guint16 (*)(gpointer)) ra_free_decoder;
  lib->RAOpenCodec2 = (guint16 (*)(gpointer, const gchar *)) ra_open_codec2;
  lib->RAInitDecoder = (guint16 (*)(gpointer, gpointer)) ra_init_decoder;
  lib->RASetFlavor = (guint16 (*)(gpointer, guint16)) ra_set_flavor;
  lib->RASetPwd = (void (*)(gpointer, const gchar *)) ra_set_pwd;
  lib->SetDLLAccessPath = (void (*)(gchar *)) set_dll_access_path;

  if (lib->SetDLLAccessPath)
    lib->SetDLLAccessPath (split_path[i]);

  tmppath = g_strdup_printf ("%s/", split_path[i]);
  if ((res = lib->RAOpenCodec2 (&lib->context, tmppath))) {
    g_free (tmppath);
    goto could_not_initialize;
  }
  g_free (tmppath);

  /* now we are done with the split paths, so free them */
  g_strfreev (split_path);

  return TRUE;

  /* ERRORS */
unknown_version:
  {
    GST_DEBUG_OBJECT (dec, "Cannot handle version %i.", version);
    return FALSE;
  }
could_not_open:
  {
    g_strfreev (split_path);
    GST_DEBUG_OBJECT (dec, "Could not find library '%s' in '%s'", names, path);
    return FALSE;
  }
could_not_load:
  {
    g_strfreev (split_path);
    close_library (dec, lib);
    GST_DEBUG_OBJECT (dec, "Could not load all symbols: %s", g_module_error ());
    return FALSE;
  }
could_not_initialize:
  {
    close_library (dec, lib);
    GST_WARNING_OBJECT (dec, "Initialization of REAL driver failed (%i).", res);
    return FALSE;
  }
}
static void cairo_dock_open_module (CairoDockModule *pCairoDockModule, GError **erreur)
{
	GModule *module = g_module_open (pCairoDockModule->cSoFilePath, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
	if (!module)
	{
		g_set_error (erreur, 1, 1, "Attention : while opening module '%s' : (%s)", pCairoDockModule->cSoFilePath, g_module_error ());
		return ;
	}

	gboolean bSymbolFound;

	CairoDockModulePreInit function_pre_init = NULL;
	bSymbolFound = g_module_symbol (module, "pre_init", (gpointer) &function_pre_init);
	pCairoDockModule->pVisitCard = NULL;
	if (bSymbolFound && function_pre_init != NULL)
	{
		pCairoDockModule->pVisitCard = function_pre_init ();
	}
	if (pCairoDockModule->pVisitCard == NULL)
	{
		g_set_error (erreur, 1, 1, "Attention : this module ('%s') does not have any visit card, it may be broken or icompatible with cairo-dock\n", pCairoDockModule->cSoFilePath);
		return ;
	}
	else
	{
		CairoDockVisitCard *pVisitCard = pCairoDockModule->pVisitCard;
		if (pVisitCard->iMajorVersionNeeded > g_iMajorVersion || (pVisitCard->iMajorVersionNeeded == g_iMajorVersion && pVisitCard->iMinorVersionNeeded > g_iMinorVersion) || (pVisitCard->iMajorVersionNeeded == g_iMajorVersion && pVisitCard->iMinorVersionNeeded == g_iMinorVersion && pVisitCard->iMicroVersionNeeded > g_iMicroVersion))
		{
			g_set_error (erreur, 1, 1, "Attention : this module ('%s') needs at least Cairo-Dock v%d.%d.%d, but Cairo-Dock is in v%s\n  It will be ignored", pCairoDockModule->cSoFilePath, pVisitCard->iMajorVersionNeeded, pVisitCard->iMinorVersionNeeded, pVisitCard->iMicroVersionNeeded, CAIRO_DOCK_VERSION);
			cairo_dock_free_visit_card (pCairoDockModule->pVisitCard);
			pCairoDockModule->pVisitCard = NULL;
			return ;
		}
		if (pVisitCard->cDockVersionOnCompilation != NULL && strcmp (pVisitCard->cDockVersionOnCompilation, CAIRO_DOCK_VERSION) != 0)
		{
			g_set_error (erreur, 1, 1, "Attention : this module ('%s') was compiled with Cairo-Dock v%s, but Cairo-Dock is in v%s\n  It will be ignored", pCairoDockModule->cSoFilePath, pVisitCard->cDockVersionOnCompilation, CAIRO_DOCK_VERSION);
			cairo_dock_free_visit_card (pCairoDockModule->pVisitCard);
			pCairoDockModule->pVisitCard = NULL;
			return ;
		}

		if (pVisitCard->cModuleName == NULL)
			pVisitCard->cModuleName = cairo_dock_extract_default_module_name_from_path (pCairoDockModule->cSoFilePath);
	}

	CairoDockModuleInit function_init;
	bSymbolFound = g_module_symbol (module, "init", (gpointer) &function_init);
	if (! bSymbolFound)
	{
		g_set_error (erreur, 1, 1, "Attention : the module '%s' is not valid : (%s)", pCairoDockModule->cSoFilePath, g_module_error ());
		if (!g_module_close (module))
			g_warning ("%s: %s", pCairoDockModule->cSoFilePath, g_module_error ());
		return ;
	}


	CairoDockModuleStop function_stop;
	bSymbolFound = g_module_symbol (module, "stop", (gpointer) &function_stop);
	if (! bSymbolFound)
	{
		function_stop = NULL;
	}

	CairoDockModuleReload function_reload;
	bSymbolFound = g_module_symbol (module, "reload", (gpointer) &function_reload);
	if (! bSymbolFound)
	{
		function_reload = NULL;
	}


	pCairoDockModule->pModule = module;
	pCairoDockModule->initModule = function_init;
	pCairoDockModule->stopModule = function_stop;
	pCairoDockModule->reloadModule = function_reload;
}
示例#28
0
void plugins_init() {
    GString* module_name = NULL;
    GModule* module;

    gchar* audio_output;

    char** search_path;
    gsize search_path_size;
    char** plugins;
    gsize plugins_size;
    void (*plugin_init)();
    void (*plugin_close)();

    int i;

    module_name = g_string_sized_new(80);
    if (!module_name)
        g_error("Can't allocate memory.");

    search_path = config_get_string_list("plugins_search_path", &search_path_size);

    /* Load audio plugin */
    audio_output = config_get_string("audio_output");
    g_string_printf(module_name, "libspop_audio_%s", audio_output);

    module = plugin_open(module_name->str, search_path, search_path_size);
    if (!module)
        g_error("Can't load %s audio plugin: %s", audio_output, g_module_error());

    if (!g_module_symbol(module, "audio_delivery", (void**) &g_audio_delivery_func))
        g_error("Can't find symbol in audio plugin: %s", g_module_error());

    /* Now load other plugins */
    plugins = config_get_string_list("plugins", &plugins_size);
    for (i=0; i < plugins_size; i++) {
        g_strstrip(plugins[i]);
        g_info("Loading plugin %s...", plugins[i]);

        /* Load the module and the symbols (spop_<module>_init and spop_<module>_close) */
        g_string_printf(module_name, "libspop_plugin_%s", plugins[i]);
        module = plugin_open(module_name->str, search_path, search_path_size);
        if (!module) {
            g_warning("Can't load plugin \"%s\": %s", plugins[i], g_module_error());
            continue;
        }

        g_string_printf(module_name, "spop_%s_init", plugins[i]);
        if (!g_module_symbol(module, module_name->str, (void**) &plugin_init)) {
            g_warning("Can't find symbol \"%s\" in module \"%s\": %s", module_name->str, plugins[i], g_module_error());
            continue;
        }

        g_string_printf(module_name, "spop_%s_close", plugins[i]);
        if (g_module_symbol(module, module_name->str, (void**) &plugin_close))
            g_plugins_close_functions = g_list_prepend(g_plugins_close_functions, plugin_close);
        else
            g_info("Module \"%s\" does not have a \"%s\" symbol: %s", plugins[i], module_name->str, g_module_error());

        /* Really init the plugin (hoping it will not blow up) */
        plugin_init();

        g_debug("Plugin %s loaded and initialized", plugins[i]);
    }
    g_string_free(module_name, TRUE);
    g_strfreev(plugins);
    g_strfreev(search_path);
}
示例#29
0
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 */
    gpointer       gp;
    plugin        *new_plug;
    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, (GModuleFlags)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;
            }

            new_plug = (plugin *)g_malloc(sizeof(plugin));
            new_plug->handle = handle;
            new_plug->name = g_strdup(name);
            new_plug->version = (char *)gp;
            new_plug->types = 0;
            new_plug->next = NULL;

            /*
             * Hand the plugin to each of the plugin type callbacks.
             */
            g_slist_foreach(plugin_types, call_plugin_callback, new_plug);

            /*
             * Does this dissector do anything useful?
             */
            if (new_plug->types == 0)
            {
                /*
                 * No.
                 */
                report_failure("The plugin '%s' has no registration routines",
                               name);
                g_module_close(handle);
                g_free(new_plug->name);
                g_free(new_plug);
                continue;
            }

            /*
             * OK, attempt to add it to the list of plugins.
             */
            if ((cr = add_plugin(new_plug)))
            {
                if (cr == EEXIST)
                    fprintf(stderr, "The plugin %s, version %s\n"
                            "was found in multiple directories\n",
                            new_plug->name, new_plug->version);
                else
                    fprintf(stderr, "Memory allocation problem\n"
                            "when processing plugin %s, version %s\n",
                            new_plug->name, new_plug->version);
                g_module_close(handle);
                g_free(new_plug->name);
                g_free(new_plug);
                continue;
            }

        }
        ws_dir_close(dir);
    }
}
示例#30
0
/**
 * cd_sensor_load:
 * @sensor: a valid #CdSensor instance
 * @kind: the sensor kind, e.g %CD_SENSOR_KIND_HUEY
 *
 * Sets the device kind.
 **/
gboolean
cd_sensor_load (CdSensor *sensor, GError **error)
{
	CdSensorIface *desc;
	gboolean ret = FALSE;
	gchar *backend_name = NULL;
	gchar *path = NULL;
	gchar *path_fallback = NULL;
	GModule *handle;

	/* no module */
	if (sensor->priv->kind == CD_SENSOR_KIND_UNKNOWN) {
		ret = TRUE;
		goto out;
	}

	/* can we load a module? */
	backend_name = g_strdup_printf ("libcolord_sensor_%s." G_MODULE_SUFFIX,
					cd_sensor_kind_to_string (sensor->priv->kind));
	path = g_build_filename (LIBDIR, "colord-sensors", backend_name, NULL);
	g_debug ("Trying to load sensor driver: %s", path);
	handle = g_module_open (path, G_MODULE_BIND_LOCAL);
	if (handle == NULL) {
		g_debug ("opening module %s failed : %s",
			 backend_name, g_module_error ());
		g_debug ("Trying to fall back to : libcolord_sensor_argyll");
		path_fallback = g_build_filename (LIBDIR,
						  "colord-sensors",
						  "libcolord_sensor_argyll.so",
						  NULL);
		handle = g_module_open (path_fallback, G_MODULE_BIND_LOCAL);
	}
	if (handle == NULL) {
		g_set_error (error, 1, 0,
			     "opening module %s (and fallback) failed : %s",
			     backend_name, g_module_error ());
		goto out;
	}

	/* dlload module if it exists */
	desc = sensor->priv->desc = g_new0 (CdSensorIface, 1);

	/* connect up exported methods */
	g_module_symbol (handle, "cd_sensor_get_sample_async", (gpointer *)&desc->get_sample_async);
	g_module_symbol (handle, "cd_sensor_get_sample_finish", (gpointer *)&desc->get_sample_finish);
	g_module_symbol (handle, "cd_sensor_set_options_async", (gpointer *)&desc->set_options_async);
	g_module_symbol (handle, "cd_sensor_set_options_finish", (gpointer *)&desc->set_options_finish);
	g_module_symbol (handle, "cd_sensor_coldplug", (gpointer *)&desc->coldplug);
	g_module_symbol (handle, "cd_sensor_dump_device", (gpointer *)&desc->dump_device);
	g_module_symbol (handle, "cd_sensor_lock_async", (gpointer *)&desc->lock_async);
	g_module_symbol (handle, "cd_sensor_lock_finish", (gpointer *)&desc->lock_finish);
	g_module_symbol (handle, "cd_sensor_unlock_async", (gpointer *)&desc->unlock_async);
	g_module_symbol (handle, "cd_sensor_unlock_finish", (gpointer *)&desc->unlock_finish);

	/* coldplug with data */
	if (desc->coldplug != NULL) {
		ret = desc->coldplug (sensor, error);
		if (!ret)
			goto out;
	}
out:
//		g_module_close (handle);
	g_free (backend_name);
	g_free (path);
	g_free (path_fallback);
	return ret;
}