2007-11-26 17:13:05 +01:00
|
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006-2007 Red Hat, Inc.
|
|
|
|
|
*
|
2022-05-18 10:12:45 +02:00
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
2017-05-27 18:21:30 +02:00
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2007-11-26 17:13:05 +01:00
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
2014-01-23 12:58:29 +01:00
|
|
|
|
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2007-11-26 17:13:05 +01:00
|
|
|
|
*
|
|
|
|
|
* Author: Alexander Larsson <alexl@redhat.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 17:10:51 +02:00
|
|
|
|
#include "config.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
2019-05-27 20:30:31 +02:00
|
|
|
|
/* For the #GDesktopAppInfoLookup macros; since macro deprecation is implemented
|
|
|
|
|
* in the preprocessor, we need to define this before including glib.h*/
|
2020-07-27 16:40:13 +02:00
|
|
|
|
#ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
|
2019-05-27 20:30:31 +02:00
|
|
|
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
2020-07-27 16:40:13 +02:00
|
|
|
|
#endif
|
2019-05-27 20:30:31 +02:00
|
|
|
|
|
2008-01-28 20:43:10 +01:00
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
#include "giomodule.h"
|
2007-12-05 12:05:49 +01:00
|
|
|
|
#include "giomodule-priv.h"
|
2020-12-05 00:33:43 +01:00
|
|
|
|
#include "glib-private.h"
|
2007-12-19 17:08:55 +01:00
|
|
|
|
#include "glocalfilemonitor.h"
|
|
|
|
|
#include "gnativevolumemonitor.h"
|
2010-05-07 21:55:54 +02:00
|
|
|
|
#include "gproxyresolver.h"
|
2010-08-10 21:24:37 +02:00
|
|
|
|
#include "gproxy.h"
|
2010-12-05 15:34:26 +01:00
|
|
|
|
#include "gsettingsbackendinternal.h"
|
2015-02-28 11:05:02 +01:00
|
|
|
|
#include "ghttpproxy.h"
|
2010-05-25 22:02:42 +02:00
|
|
|
|
#include "gsocks4proxy.h"
|
|
|
|
|
#include "gsocks4aproxy.h"
|
2010-04-29 21:22:55 +02:00
|
|
|
|
#include "gsocks5proxy.h"
|
2009-12-21 20:50:32 +01:00
|
|
|
|
#include "gtlsbackend.h"
|
2007-12-19 17:08:55 +01:00
|
|
|
|
#include "gvfs.h"
|
2013-10-15 17:21:10 +02:00
|
|
|
|
#include "gnotificationbackend.h"
|
2015-01-12 20:59:35 +01:00
|
|
|
|
#include "ginitable.h"
|
|
|
|
|
#include "gnetworkmonitor.h"
|
2021-11-11 11:56:50 +01:00
|
|
|
|
#include "gdebugcontroller.h"
|
|
|
|
|
#include "gdebugcontrollerdbus.h"
|
2019-07-25 15:52:09 +02:00
|
|
|
|
#include "gmemorymonitor.h"
|
|
|
|
|
#include "gmemorymonitorportal.h"
|
|
|
|
|
#include "gmemorymonitordbus.h"
|
2021-07-20 23:04:31 +02:00
|
|
|
|
#include "gpowerprofilemonitor.h"
|
|
|
|
|
#include "gpowerprofilemonitordbus.h"
|
2021-08-09 23:19:17 +02:00
|
|
|
|
#include "gpowerprofilemonitorportal.h"
|
2010-08-12 17:10:23 +02:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
#include "gregistrysettingsbackend.h"
|
2020-10-04 00:44:19 +02:00
|
|
|
|
#include "giowin32-priv.h"
|
2010-08-12 17:10:23 +02:00
|
|
|
|
#endif
|
2010-01-12 11:36:12 +01:00
|
|
|
|
#include <glib/gstdio.h>
|
2007-11-28 13:39:07 +01:00
|
|
|
|
|
2022-11-03 19:22:18 +01:00
|
|
|
|
#if defined(G_OS_UNIX) && !defined(__APPLE__)
|
2010-11-09 13:19:19 +01:00
|
|
|
|
#include "gdesktopappinfo.h"
|
|
|
|
|
#endif
|
2015-03-25 23:26:50 +01:00
|
|
|
|
#ifdef HAVE_COCOA
|
|
|
|
|
#include "gosxappinfo.h"
|
|
|
|
|
#endif
|
2010-11-09 13:19:19 +01:00
|
|
|
|
|
2022-11-03 19:22:18 +01:00
|
|
|
|
#ifdef __APPLE__
|
2017-03-09 04:26:00 +01:00
|
|
|
|
#include <AvailabilityMacros.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-01-19 14:19:05 +01:00
|
|
|
|
#define __GLIB_H_INSIDE__
|
|
|
|
|
#include "gconstructor.h"
|
|
|
|
|
#undef __GLIB_H_INSIDE__
|
|
|
|
|
|
2007-11-27 15:00:13 +01:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:giomodule
|
|
|
|
|
* @short_description: Loadable GIO Modules
|
2008-02-21 19:20:17 +01:00
|
|
|
|
* @include: gio/gio.h
|
2007-11-27 15:00:13 +01:00
|
|
|
|
*
|
|
|
|
|
* Provides an interface and default functions for loading and unloading
|
2008-02-11 08:12:56 +01:00
|
|
|
|
* modules. This is used internally to make GIO extensible, but can also
|
|
|
|
|
* be used by others to implement module loading.
|
2007-11-27 15:00:13 +01:00
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:extensionpoints
|
|
|
|
|
* @short_description: Extension Points
|
|
|
|
|
* @include: gio.h
|
2014-02-08 18:26:56 +01:00
|
|
|
|
* @see_also: [Extending GIO][extending-gio]
|
2008-02-11 08:12:56 +01:00
|
|
|
|
*
|
|
|
|
|
* #GIOExtensionPoint provides a mechanism for modules to extend the
|
|
|
|
|
* functionality of the library or application that loaded it in an
|
|
|
|
|
* organized fashion.
|
|
|
|
|
*
|
|
|
|
|
* An extension point is identified by a name, and it may optionally
|
2013-11-09 16:33:42 +01:00
|
|
|
|
* require that any implementation must be of a certain type (or derived
|
2008-02-11 08:12:56 +01:00
|
|
|
|
* thereof). Use g_io_extension_point_register() to register an
|
|
|
|
|
* extension point, and g_io_extension_point_set_required_type() to
|
|
|
|
|
* set a required type.
|
|
|
|
|
*
|
|
|
|
|
* A module can implement an extension point by specifying the #GType
|
|
|
|
|
* that implements the functionality. Additionally, each implementation
|
|
|
|
|
* of an extension point has a name, and a priority. Use
|
|
|
|
|
* g_io_extension_point_implement() to implement an extension point.
|
|
|
|
|
*
|
2014-02-01 21:11:49 +01:00
|
|
|
|
* |[<!-- language="C" -->
|
2008-02-11 08:12:56 +01:00
|
|
|
|
* GIOExtensionPoint *ep;
|
|
|
|
|
*
|
2014-02-15 03:33:36 +01:00
|
|
|
|
* // Register an extension point
|
2008-02-11 08:12:56 +01:00
|
|
|
|
* ep = g_io_extension_point_register ("my-extension-point");
|
|
|
|
|
* g_io_extension_point_set_required_type (ep, MY_TYPE_EXAMPLE);
|
|
|
|
|
* ]|
|
|
|
|
|
*
|
2014-02-01 21:11:49 +01:00
|
|
|
|
* |[<!-- language="C" -->
|
2014-02-15 03:33:36 +01:00
|
|
|
|
* // Implement an extension point
|
2014-10-17 12:54:02 +02:00
|
|
|
|
* G_DEFINE_TYPE (MyExampleImpl, my_example_impl, MY_TYPE_EXAMPLE)
|
2008-02-11 08:12:56 +01:00
|
|
|
|
* g_io_extension_point_implement ("my-extension-point",
|
|
|
|
|
* my_example_impl_get_type (),
|
|
|
|
|
* "my-example",
|
|
|
|
|
* 10);
|
|
|
|
|
* ]|
|
|
|
|
|
*
|
|
|
|
|
* It is up to the code that registered the extension point how
|
|
|
|
|
* it uses the implementations that have been associated with it.
|
|
|
|
|
* Depending on the use case, it may use all implementations, or
|
|
|
|
|
* only the one with the highest priority, or pick a specific
|
2010-04-18 21:55:14 +02:00
|
|
|
|
* one by name.
|
|
|
|
|
*
|
|
|
|
|
* To avoid opening all modules just to find out what extension
|
|
|
|
|
* points they implement, GIO makes use of a caching mechanism,
|
2014-02-08 18:26:56 +01:00
|
|
|
|
* see [gio-querymodules][gio-querymodules].
|
2010-04-18 21:55:14 +02:00
|
|
|
|
* You are expected to run this command after installing a
|
|
|
|
|
* GIO module.
|
2011-08-26 15:27:19 +02:00
|
|
|
|
*
|
2014-02-06 01:32:41 +01:00
|
|
|
|
* The `GIO_EXTRA_MODULES` environment variable can be used to
|
|
|
|
|
* specify additional directories to automatically load modules
|
2011-08-26 15:27:19 +02:00
|
|
|
|
* from. This environment variable has the same syntax as the
|
2014-02-06 01:32:41 +01:00
|
|
|
|
* `PATH`. If two modules have the same base name in different
|
2011-08-26 15:27:19 +02:00
|
|
|
|
* directories, then the latter one will be ignored. If additional
|
|
|
|
|
* directories are specified GIO will load modules from the built-in
|
|
|
|
|
* directory last.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GIOModuleScope:
|
|
|
|
|
*
|
|
|
|
|
* Represents a scope for loading IO modules. A scope can be used for blocking
|
|
|
|
|
* duplicate modules, or blocking a module you don't want to load.
|
|
|
|
|
*
|
|
|
|
|
* The scope can be used with g_io_modules_load_all_in_directory_with_scope()
|
|
|
|
|
* or g_io_modules_scan_all_in_directory_with_scope().
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.30
|
|
|
|
|
*/
|
|
|
|
|
struct _GIOModuleScope {
|
|
|
|
|
GIOModuleScopeFlags flags;
|
|
|
|
|
GHashTable *basenames;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_io_module_scope_new:
|
|
|
|
|
* @flags: flags for the new scope
|
|
|
|
|
*
|
|
|
|
|
* Create a new scope for loading of IO modules. A scope can be used for
|
|
|
|
|
* blocking duplicate modules, or blocking a module you don't want to load.
|
|
|
|
|
*
|
2012-02-18 12:10:00 +01:00
|
|
|
|
* Specify the %G_IO_MODULE_SCOPE_BLOCK_DUPLICATES flag to block modules
|
2011-08-26 15:27:19 +02:00
|
|
|
|
* which have the same base name as a module that has already been seen
|
|
|
|
|
* in this scope.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the new module scope
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.30
|
|
|
|
|
*/
|
|
|
|
|
GIOModuleScope *
|
|
|
|
|
g_io_module_scope_new (GIOModuleScopeFlags flags)
|
|
|
|
|
{
|
|
|
|
|
GIOModuleScope *scope = g_new0 (GIOModuleScope, 1);
|
|
|
|
|
scope->flags = flags;
|
|
|
|
|
scope->basenames = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
|
|
return scope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_io_module_scope_free:
|
|
|
|
|
* @scope: a module loading scope
|
|
|
|
|
*
|
|
|
|
|
* Free a module scope.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.30
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
g_io_module_scope_free (GIOModuleScope *scope)
|
|
|
|
|
{
|
|
|
|
|
if (!scope)
|
|
|
|
|
return;
|
|
|
|
|
g_hash_table_destroy (scope->basenames);
|
|
|
|
|
g_free (scope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_io_module_scope_block:
|
|
|
|
|
* @scope: a module loading scope
|
2011-08-30 05:55:48 +02:00
|
|
|
|
* @basename: the basename to block
|
2011-08-26 15:27:19 +02:00
|
|
|
|
*
|
2011-08-30 05:55:48 +02:00
|
|
|
|
* Block modules with the given @basename from being loaded when
|
|
|
|
|
* this scope is used with g_io_modules_scan_all_in_directory_with_scope()
|
|
|
|
|
* or g_io_modules_load_all_in_directory_with_scope().
|
2011-08-26 15:27:19 +02:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.30
|
2008-02-11 08:12:56 +01:00
|
|
|
|
*/
|
2011-08-26 15:27:19 +02:00
|
|
|
|
void
|
|
|
|
|
g_io_module_scope_block (GIOModuleScope *scope,
|
|
|
|
|
const gchar *basename)
|
|
|
|
|
{
|
|
|
|
|
gchar *key;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (scope != NULL);
|
|
|
|
|
g_return_if_fail (basename != NULL);
|
|
|
|
|
|
|
|
|
|
key = g_strdup (basename);
|
2017-10-25 11:53:14 +02:00
|
|
|
|
g_hash_table_add (scope->basenames, key);
|
2011-08-26 15:27:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
_g_io_module_scope_contains (GIOModuleScope *scope,
|
|
|
|
|
const gchar *basename)
|
|
|
|
|
{
|
2017-10-25 11:53:14 +02:00
|
|
|
|
return g_hash_table_contains (scope->basenames, basename);
|
2011-08-26 15:27:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
struct _GIOModule {
|
|
|
|
|
GTypeModule parent_instance;
|
2010-01-12 11:36:12 +01:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
gchar *filename;
|
|
|
|
|
GModule *library;
|
2010-01-12 11:36:12 +01:00
|
|
|
|
gboolean initialized; /* The module was loaded at least once */
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
void (* load) (GIOModule *module);
|
|
|
|
|
void (* unload) (GIOModule *module);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _GIOModuleClass
|
|
|
|
|
{
|
|
|
|
|
GTypeModuleClass parent_class;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void g_io_module_finalize (GObject *object);
|
|
|
|
|
static gboolean g_io_module_load_module (GTypeModule *gmodule);
|
|
|
|
|
static void g_io_module_unload_module (GTypeModule *gmodule);
|
|
|
|
|
|
2015-02-05 16:20:43 +01:00
|
|
|
|
/**
|
|
|
|
|
* GIOExtension:
|
|
|
|
|
*
|
|
|
|
|
* #GIOExtension is an opaque data structure and can only be accessed
|
|
|
|
|
* using the following functions.
|
|
|
|
|
*/
|
2010-01-12 11:36:12 +01:00
|
|
|
|
struct _GIOExtension {
|
|
|
|
|
char *name;
|
|
|
|
|
GType type;
|
|
|
|
|
gint priority;
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-05 16:20:43 +01:00
|
|
|
|
/**
|
|
|
|
|
* GIOExtensionPoint:
|
|
|
|
|
*
|
|
|
|
|
* #GIOExtensionPoint is an opaque data structure and can only be accessed
|
|
|
|
|
* using the following functions.
|
|
|
|
|
*/
|
2010-01-12 11:36:12 +01:00
|
|
|
|
struct _GIOExtensionPoint {
|
|
|
|
|
GType required_type;
|
|
|
|
|
char *name;
|
|
|
|
|
GList *extensions;
|
|
|
|
|
GList *lazy_load_modules;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GHashTable *extension_points = NULL;
|
|
|
|
|
G_LOCK_DEFINE_STATIC(extension_points);
|
|
|
|
|
|
2014-10-17 12:54:02 +02:00
|
|
|
|
G_DEFINE_TYPE (GIOModule, g_io_module, G_TYPE_TYPE_MODULE)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_io_module_class_init (GIOModuleClass *class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
GTypeModuleClass *type_module_class = G_TYPE_MODULE_CLASS (class);
|
|
|
|
|
|
|
|
|
|
object_class->finalize = g_io_module_finalize;
|
|
|
|
|
|
|
|
|
|
type_module_class->load = g_io_module_load_module;
|
|
|
|
|
type_module_class->unload = g_io_module_unload_module;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_io_module_init (GIOModule *module)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_io_module_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GIOModule *module = G_IO_MODULE (object);
|
|
|
|
|
|
|
|
|
|
g_free (module->filename);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (g_io_module_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 21:36:21 +01:00
|
|
|
|
static gboolean
|
|
|
|
|
load_symbols (GIOModule *module)
|
|
|
|
|
{
|
|
|
|
|
gchar *name;
|
|
|
|
|
gchar *load_symname;
|
|
|
|
|
gchar *unload_symname;
|
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
|
|
name = _g_io_module_extract_name (module->filename);
|
|
|
|
|
load_symname = g_strconcat ("g_io_", name, "_load", NULL);
|
|
|
|
|
unload_symname = g_strconcat ("g_io_", name, "_unload", NULL);
|
|
|
|
|
|
|
|
|
|
ret = g_module_symbol (module->library,
|
|
|
|
|
load_symname,
|
|
|
|
|
(gpointer) &module->load) &&
|
|
|
|
|
g_module_symbol (module->library,
|
|
|
|
|
unload_symname,
|
|
|
|
|
(gpointer) &module->unload);
|
|
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
|
{
|
|
|
|
|
/* Fallback to old names */
|
|
|
|
|
ret = g_module_symbol (module->library,
|
|
|
|
|
"g_io_module_load",
|
|
|
|
|
(gpointer) &module->load) &&
|
|
|
|
|
g_module_symbol (module->library,
|
|
|
|
|
"g_io_module_unload",
|
|
|
|
|
(gpointer) &module->unload);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
|
g_free (load_symname);
|
|
|
|
|
g_free (unload_symname);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
static gboolean
|
|
|
|
|
g_io_module_load_module (GTypeModule *gmodule)
|
|
|
|
|
{
|
|
|
|
|
GIOModule *module = G_IO_MODULE (gmodule);
|
2021-07-21 22:54:35 +02:00
|
|
|
|
GError *error = NULL;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
if (!module->filename)
|
|
|
|
|
{
|
|
|
|
|
g_warning ("GIOModule path not set");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 22:54:35 +02:00
|
|
|
|
module->library = g_module_open_full (module->filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL, &error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
if (!module->library)
|
|
|
|
|
{
|
2021-07-21 22:54:35 +02:00
|
|
|
|
g_printerr ("%s\n", error->message);
|
|
|
|
|
g_clear_error (&error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make sure that the loaded library contains the required methods */
|
2017-11-30 21:36:21 +01:00
|
|
|
|
if (!load_symbols (module))
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
g_printerr ("%s\n", g_module_error ());
|
|
|
|
|
g_module_close (module->library);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the loaded module */
|
|
|
|
|
module->load (module);
|
2010-01-12 11:36:12 +01:00
|
|
|
|
module->initialized = TRUE;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_io_module_unload_module (GTypeModule *gmodule)
|
|
|
|
|
{
|
|
|
|
|
GIOModule *module = G_IO_MODULE (gmodule);
|
|
|
|
|
|
|
|
|
|
module->unload (module);
|
|
|
|
|
|
|
|
|
|
g_module_close (module->library);
|
|
|
|
|
module->library = NULL;
|
|
|
|
|
|
|
|
|
|
module->load = NULL;
|
|
|
|
|
module->unload = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_io_module_new:
|
2016-06-04 17:53:42 +02:00
|
|
|
|
* @filename: (type filename): filename of the shared library module.
|
2007-11-26 17:13:05 +01:00
|
|
|
|
*
|
2007-12-05 12:05:49 +01:00
|
|
|
|
* Creates a new GIOModule that will load the specific
|
|
|
|
|
* shared library when in use.
|
2007-11-27 15:00:13 +01:00
|
|
|
|
*
|
|
|
|
|
* Returns: a #GIOModule from given @filename,
|
2007-11-26 17:13:05 +01:00
|
|
|
|
* or %NULL on error.
|
|
|
|
|
**/
|
|
|
|
|
GIOModule *
|
|
|
|
|
g_io_module_new (const gchar *filename)
|
|
|
|
|
{
|
|
|
|
|
GIOModule *module;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
module = g_object_new (G_IO_TYPE_MODULE, NULL);
|
|
|
|
|
module->filename = g_strdup (filename);
|
|
|
|
|
|
|
|
|
|
return module;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-08-26 15:27:19 +02:00
|
|
|
|
is_valid_module_name (const gchar *basename,
|
|
|
|
|
GIOModuleScope *scope)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2011-08-26 15:27:19 +02:00
|
|
|
|
gboolean result;
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
#if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN)
|
2022-11-02 11:01:09 +01:00
|
|
|
|
#if defined(__APPLE__)
|
Improve g_module_open(), deprecate G_MODULE_SUFFIX
G_MODULE_SUFFIX is deprecated now because you will get the wrong
results using it most of the time:
1. The suffix on macOS is usually 'dylib', but it's 'so' when using
Autotools, so there's no way to get the suffix correct using
a pre-processor macro.
2. Prefixes also vary in a platform-specific way. You may or may not have
a 'lib' prefix for the name on Windows and on Cygwin the prefix is
'cyg'.
3. The library name itself can vary per platform. For instance, you may
want to load foo-1.dll on Windows and libfoo.1.dylib on macOS. This
is for libraries, not modules, but that is still a use-case that
people use the GModule API for.
g_module_build_path() does take care of (2) on Cygwin, but it
fundamentally cannot handle the possibility of multiple options for
the module name, since it does not do any I/O. Hence, it is also
deprecated.
Instead, g_module_open() has been improved so that it takes care of
all this by searching the filesystem for combinations of possible
suffixes and prefixes on each platform. Along the way, the
documentation for it was also improved to make it clearer what it
does.
Closes https://gitlab.gnome.org/GNOME/glib/-/issues/520
Closes https://gitlab.gnome.org/GNOME/glib/-/issues/1413
2022-10-14 01:04:13 +02:00
|
|
|
|
if (!g_str_has_prefix (basename, "lib") ||
|
|
|
|
|
!(g_str_has_suffix (basename, ".so") ||
|
|
|
|
|
g_str_has_suffix (basename, ".dylib")))
|
|
|
|
|
return FALSE;
|
|
|
|
|
#else
|
2011-08-26 15:27:19 +02:00
|
|
|
|
if (!g_str_has_prefix (basename, "lib") ||
|
|
|
|
|
!g_str_has_suffix (basename, ".so"))
|
|
|
|
|
return FALSE;
|
Improve g_module_open(), deprecate G_MODULE_SUFFIX
G_MODULE_SUFFIX is deprecated now because you will get the wrong
results using it most of the time:
1. The suffix on macOS is usually 'dylib', but it's 'so' when using
Autotools, so there's no way to get the suffix correct using
a pre-processor macro.
2. Prefixes also vary in a platform-specific way. You may or may not have
a 'lib' prefix for the name on Windows and on Cygwin the prefix is
'cyg'.
3. The library name itself can vary per platform. For instance, you may
want to load foo-1.dll on Windows and libfoo.1.dylib on macOS. This
is for libraries, not modules, but that is still a use-case that
people use the GModule API for.
g_module_build_path() does take care of (2) on Cygwin, but it
fundamentally cannot handle the possibility of multiple options for
the module name, since it does not do any I/O. Hence, it is also
deprecated.
Instead, g_module_open() has been improved so that it takes care of
all this by searching the filesystem for combinations of possible
suffixes and prefixes on each platform. Along the way, the
documentation for it was also improved to make it clearer what it
does.
Closes https://gitlab.gnome.org/GNOME/glib/-/issues/520
Closes https://gitlab.gnome.org/GNOME/glib/-/issues/1413
2022-10-14 01:04:13 +02:00
|
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
|
#else
|
2011-08-26 15:27:19 +02:00
|
|
|
|
if (!g_str_has_suffix (basename, ".dll"))
|
|
|
|
|
return FALSE;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
#endif
|
2011-08-26 15:27:19 +02:00
|
|
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
|
if (scope)
|
|
|
|
|
{
|
|
|
|
|
result = _g_io_module_scope_contains (scope, basename) ? FALSE : TRUE;
|
|
|
|
|
if (result && (scope->flags & G_IO_MODULE_SCOPE_BLOCK_DUPLICATES))
|
|
|
|
|
g_io_module_scope_block (scope, basename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 15:27:19 +02:00
|
|
|
|
|
2010-01-12 11:36:12 +01:00
|
|
|
|
/**
|
2011-08-26 15:27:19 +02:00
|
|
|
|
* g_io_modules_scan_all_in_directory_with_scope:
|
2016-06-04 17:53:42 +02:00
|
|
|
|
* @dirname: (type filename): pathname for a directory containing modules
|
|
|
|
|
* to scan.
|
2011-08-26 15:27:19 +02:00
|
|
|
|
* @scope: a scope to use when scanning the modules
|
2010-01-12 11:36:12 +01:00
|
|
|
|
*
|
|
|
|
|
* Scans all the modules in the specified directory, ensuring that
|
|
|
|
|
* any extension point implemented by a module is registered.
|
|
|
|
|
*
|
|
|
|
|
* This may not actually load and initialize all the types in each
|
|
|
|
|
* module, some modules may be lazily loaded and initialized when
|
2020-06-12 15:02:30 +02:00
|
|
|
|
* an extension point it implements is used with e.g.
|
2010-01-12 11:36:12 +01:00
|
|
|
|
* g_io_extension_point_get_extensions() or
|
|
|
|
|
* g_io_extension_point_get_extension_by_name().
|
|
|
|
|
*
|
|
|
|
|
* If you need to guarantee that all types are loaded in all the modules,
|
2010-11-29 15:36:07 +01:00
|
|
|
|
* use g_io_modules_load_all_in_directory().
|
2010-01-12 11:36:12 +01:00
|
|
|
|
*
|
2011-08-26 15:27:19 +02:00
|
|
|
|
* Since: 2.30
|
2010-01-12 11:36:12 +01:00
|
|
|
|
**/
|
|
|
|
|
void
|
2011-08-26 15:27:19 +02:00
|
|
|
|
g_io_modules_scan_all_in_directory_with_scope (const char *dirname,
|
|
|
|
|
GIOModuleScope *scope)
|
2010-01-12 11:36:12 +01:00
|
|
|
|
{
|
|
|
|
|
const gchar *name;
|
|
|
|
|
char *filename;
|
|
|
|
|
GDir *dir;
|
2010-03-21 19:04:18 +01:00
|
|
|
|
GStatBuf statbuf;
|
2010-01-12 11:36:12 +01:00
|
|
|
|
char *data;
|
2020-07-03 15:16:33 +02:00
|
|
|
|
time_t cache_time;
|
2010-01-12 11:36:12 +01:00
|
|
|
|
GHashTable *cache;
|
|
|
|
|
|
|
|
|
|
if (!g_module_supported ())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
dir = g_dir_open (dirname, 0, NULL);
|
|
|
|
|
if (!dir)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
filename = g_build_filename (dirname, "giomodule.cache", NULL);
|
|
|
|
|
|
2020-12-31 14:48:31 +01:00
|
|
|
|
cache = NULL;
|
2020-07-03 15:16:33 +02:00
|
|
|
|
cache_time = 0;
|
2010-01-12 11:36:12 +01:00
|
|
|
|
if (g_stat (filename, &statbuf) == 0 &&
|
|
|
|
|
g_file_get_contents (filename, &data, NULL, NULL))
|
|
|
|
|
{
|
|
|
|
|
char **lines;
|
|
|
|
|
int i;
|
|
|
|
|
|
2020-07-03 15:16:33 +02:00
|
|
|
|
/* cache_time is the time the cache file was created; we also take
|
|
|
|
|
* into account the change time because in ostree based systems, all
|
|
|
|
|
* system file have mtime equal to epoch 0.
|
|
|
|
|
*
|
|
|
|
|
* Any file that has a ctime before this was created then and not modified
|
|
|
|
|
* since then (userspace can't change ctime). Its possible to change the
|
|
|
|
|
* ctime forward without changing the file content, by e.g. chmoding the
|
|
|
|
|
* file, but this is uncommon and will only cause us to not use the cache
|
|
|
|
|
* so will not cause bugs.
|
2010-01-12 11:36:12 +01:00
|
|
|
|
*/
|
2020-07-03 15:16:33 +02:00
|
|
|
|
cache_time = MAX(statbuf.st_mtime, statbuf.st_ctime);
|
2010-01-12 11:36:12 +01:00
|
|
|
|
|
|
|
|
|
lines = g_strsplit (data, "\n", -1);
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
|
|
for (i = 0; lines[i] != NULL; i++)
|
|
|
|
|
{
|
|
|
|
|
char *line = lines[i];
|
|
|
|
|
char *file;
|
|
|
|
|
char *colon;
|
2022-01-19 18:37:24 +01:00
|
|
|
|
char **strv_extension_points;
|
2010-01-12 11:36:12 +01:00
|
|
|
|
|
|
|
|
|
if (line[0] == '#')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
colon = strchr (line, ':');
|
|
|
|
|
if (colon == NULL || line == colon)
|
|
|
|
|
continue; /* Invalid line, ignore */
|
|
|
|
|
|
|
|
|
|
*colon = 0; /* terminate filename */
|
2010-03-07 23:42:25 +01:00
|
|
|
|
file = g_strdup (line);
|
2010-01-12 11:36:12 +01:00
|
|
|
|
colon++; /* after colon */
|
|
|
|
|
|
|
|
|
|
while (g_ascii_isspace (*colon))
|
|
|
|
|
colon++;
|
|
|
|
|
|
2020-12-31 14:48:31 +01:00
|
|
|
|
if (G_UNLIKELY (!cache))
|
|
|
|
|
cache = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
|
g_free, (GDestroyNotify)g_strfreev);
|
|
|
|
|
|
2022-01-19 18:37:24 +01:00
|
|
|
|
strv_extension_points = g_strsplit (colon, ",", -1);
|
|
|
|
|
g_hash_table_insert (cache, file, strv_extension_points);
|
2010-01-12 11:36:12 +01:00
|
|
|
|
}
|
|
|
|
|
g_strfreev (lines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ((name = g_dir_read_name (dir)))
|
|
|
|
|
{
|
2011-08-26 15:27:19 +02:00
|
|
|
|
if (is_valid_module_name (name, scope))
|
2010-01-12 11:36:12 +01:00
|
|
|
|
{
|
|
|
|
|
GIOExtensionPoint *extension_point;
|
|
|
|
|
GIOModule *module;
|
|
|
|
|
gchar *path;
|
2022-01-19 18:37:24 +01:00
|
|
|
|
char **strv_extension_points = NULL;
|
2010-01-12 11:36:12 +01:00
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
path = g_build_filename (dirname, name, NULL);
|
|
|
|
|
module = g_io_module_new (path);
|
|
|
|
|
|
2020-12-31 14:48:31 +01:00
|
|
|
|
if (cache)
|
2022-01-19 18:37:24 +01:00
|
|
|
|
strv_extension_points = g_hash_table_lookup (cache, name);
|
2020-12-31 14:48:31 +01:00
|
|
|
|
|
2022-01-19 18:37:24 +01:00
|
|
|
|
if (strv_extension_points != NULL &&
|
2010-01-12 11:36:12 +01:00
|
|
|
|
g_stat (path, &statbuf) == 0 &&
|
2020-07-03 15:16:33 +02:00
|
|
|
|
statbuf.st_ctime <= cache_time)
|
2010-01-12 11:36:12 +01:00
|
|
|
|
{
|
|
|
|
|
/* Lazy load/init the library when first required */
|
2022-01-19 18:37:24 +01:00
|
|
|
|
for (i = 0; strv_extension_points[i] != NULL; i++)
|
2010-01-12 11:36:12 +01:00
|
|
|
|
{
|
|
|
|
|
extension_point =
|
2022-01-19 18:37:24 +01:00
|
|
|
|
g_io_extension_point_register (strv_extension_points[i]);
|
2010-01-12 11:36:12 +01:00
|
|
|
|
extension_point->lazy_load_modules =
|
|
|
|
|
g_list_prepend (extension_point->lazy_load_modules,
|
2013-11-07 22:56:11 +01:00
|
|
|
|
module);
|
2010-01-12 11:36:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Try to load and init types */
|
|
|
|
|
if (g_type_module_use (G_TYPE_MODULE (module)))
|
2022-10-18 09:01:11 +02:00
|
|
|
|
{
|
|
|
|
|
g_type_module_unuse (G_TYPE_MODULE (module)); /* Unload */
|
|
|
|
|
/* module must remain alive, because the type system keeps weak refs */
|
|
|
|
|
g_ignore_leak (module);
|
|
|
|
|
}
|
2013-11-07 22:56:11 +01:00
|
|
|
|
else
|
2022-10-18 08:52:00 +02:00
|
|
|
|
{
|
|
|
|
|
g_printerr ("Failed to load module: %s\n", path);
|
|
|
|
|
g_object_unref (module);
|
|
|
|
|
}
|
2010-01-12 11:36:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_dir_close (dir);
|
|
|
|
|
|
2020-12-31 14:48:31 +01:00
|
|
|
|
if (cache)
|
|
|
|
|
g_hash_table_destroy (cache);
|
2010-02-05 02:14:20 +01:00
|
|
|
|
|
|
|
|
|
g_free (filename);
|
2010-01-12 11:36:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 15:27:19 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_io_modules_scan_all_in_directory:
|
2016-06-04 17:53:42 +02:00
|
|
|
|
* @dirname: (type filename): pathname for a directory containing modules
|
|
|
|
|
* to scan.
|
2011-08-26 15:27:19 +02:00
|
|
|
|
*
|
|
|
|
|
* Scans all the modules in the specified directory, ensuring that
|
|
|
|
|
* any extension point implemented by a module is registered.
|
|
|
|
|
*
|
|
|
|
|
* This may not actually load and initialize all the types in each
|
|
|
|
|
* module, some modules may be lazily loaded and initialized when
|
2020-06-12 15:02:30 +02:00
|
|
|
|
* an extension point it implements is used with e.g.
|
2011-08-26 15:27:19 +02:00
|
|
|
|
* g_io_extension_point_get_extensions() or
|
|
|
|
|
* g_io_extension_point_get_extension_by_name().
|
|
|
|
|
*
|
|
|
|
|
* If you need to guarantee that all types are loaded in all the modules,
|
|
|
|
|
* use g_io_modules_load_all_in_directory().
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.24
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
g_io_modules_scan_all_in_directory (const char *dirname)
|
|
|
|
|
{
|
|
|
|
|
g_io_modules_scan_all_in_directory_with_scope (dirname, NULL);
|
|
|
|
|
}
|
2010-01-12 11:36:12 +01:00
|
|
|
|
|
2007-12-05 12:05:49 +01:00
|
|
|
|
/**
|
2011-08-26 15:27:19 +02:00
|
|
|
|
* g_io_modules_load_all_in_directory_with_scope:
|
2016-06-04 17:53:42 +02:00
|
|
|
|
* @dirname: (type filename): pathname for a directory containing modules
|
|
|
|
|
* to load.
|
2011-08-26 15:27:19 +02:00
|
|
|
|
* @scope: a scope to use when scanning the modules.
|
2008-02-25 15:04:38 +01:00
|
|
|
|
*
|
|
|
|
|
* Loads all the modules in the specified directory.
|
|
|
|
|
*
|
2010-01-12 11:36:12 +01:00
|
|
|
|
* If don't require all modules to be initialized (and thus registering
|
|
|
|
|
* all gtypes) then you can use g_io_modules_scan_all_in_directory()
|
|
|
|
|
* which allows delayed/lazy loading of modules.
|
|
|
|
|
*
|
2010-09-24 20:51:26 +02:00
|
|
|
|
* Returns: (element-type GIOModule) (transfer full): a list of #GIOModules loaded
|
|
|
|
|
* from the directory,
|
2007-12-19 17:08:55 +01:00
|
|
|
|
* All the modules are loaded into memory, if you want to
|
|
|
|
|
* unload them (enabling on-demand loading) you must call
|
|
|
|
|
* g_type_module_unuse() on all the modules. Free the list
|
|
|
|
|
* with g_list_free().
|
2011-08-26 15:27:19 +02:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.30
|
2007-12-05 12:05:49 +01:00
|
|
|
|
**/
|
|
|
|
|
GList *
|
2011-08-26 15:27:19 +02:00
|
|
|
|
g_io_modules_load_all_in_directory_with_scope (const char *dirname,
|
|
|
|
|
GIOModuleScope *scope)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
const gchar *name;
|
|
|
|
|
GDir *dir;
|
|
|
|
|
GList *modules;
|
|
|
|
|
|
|
|
|
|
if (!g_module_supported ())
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
dir = g_dir_open (dirname, 0, NULL);
|
|
|
|
|
if (!dir)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
modules = NULL;
|
|
|
|
|
while ((name = g_dir_read_name (dir)))
|
|
|
|
|
{
|
2011-08-26 15:27:19 +02:00
|
|
|
|
if (is_valid_module_name (name, scope))
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
GIOModule *module;
|
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
|
|
path = g_build_filename (dirname, name, NULL);
|
|
|
|
|
module = g_io_module_new (path);
|
|
|
|
|
|
|
|
|
|
if (!g_type_module_use (G_TYPE_MODULE (module)))
|
|
|
|
|
{
|
|
|
|
|
g_printerr ("Failed to load module: %s\n", path);
|
|
|
|
|
g_object_unref (module);
|
|
|
|
|
g_free (path);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
|
|
modules = g_list_prepend (modules, module);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_dir_close (dir);
|
|
|
|
|
|
|
|
|
|
return modules;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 15:27:19 +02:00
|
|
|
|
/**
|
|
|
|
|
* g_io_modules_load_all_in_directory:
|
2016-06-04 17:53:42 +02:00
|
|
|
|
* @dirname: (type filename): pathname for a directory containing modules
|
|
|
|
|
* to load.
|
2011-08-26 15:27:19 +02:00
|
|
|
|
*
|
|
|
|
|
* Loads all the modules in the specified directory.
|
|
|
|
|
*
|
|
|
|
|
* If don't require all modules to be initialized (and thus registering
|
|
|
|
|
* all gtypes) then you can use g_io_modules_scan_all_in_directory()
|
|
|
|
|
* which allows delayed/lazy loading of modules.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (element-type GIOModule) (transfer full): a list of #GIOModules loaded
|
|
|
|
|
* from the directory,
|
|
|
|
|
* All the modules are loaded into memory, if you want to
|
|
|
|
|
* unload them (enabling on-demand loading) you must call
|
|
|
|
|
* g_type_module_unuse() on all the modules. Free the list
|
|
|
|
|
* with g_list_free().
|
|
|
|
|
**/
|
|
|
|
|
GList *
|
|
|
|
|
g_io_modules_load_all_in_directory (const char *dirname)
|
|
|
|
|
{
|
|
|
|
|
return g_io_modules_load_all_in_directory_with_scope (dirname, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 00:27:57 +01:00
|
|
|
|
static gpointer
|
|
|
|
|
try_class (GIOExtension *extension,
|
|
|
|
|
guint is_supported_offset)
|
|
|
|
|
{
|
|
|
|
|
GType type = g_io_extension_get_type (extension);
|
|
|
|
|
typedef gboolean (*verify_func) (void);
|
|
|
|
|
gpointer class;
|
|
|
|
|
|
|
|
|
|
class = g_type_class_ref (type);
|
|
|
|
|
if (!is_supported_offset || (* G_STRUCT_MEMBER(verify_func, class, is_supported_offset)) ())
|
|
|
|
|
return class;
|
|
|
|
|
|
|
|
|
|
g_type_class_unref (class);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-21 02:39:57 +01:00
|
|
|
|
static void
|
|
|
|
|
print_help (const char *envvar,
|
|
|
|
|
GIOExtensionPoint *ep)
|
|
|
|
|
{
|
|
|
|
|
g_print ("Supported arguments for %s environment variable:\n", envvar);
|
|
|
|
|
|
|
|
|
|
if (g_io_extension_point_get_extensions (ep) == NULL)
|
|
|
|
|
g_print (" (none)\n");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
GIOExtension *extension;
|
2020-11-18 19:53:33 +01:00
|
|
|
|
gsize width = 0;
|
2019-01-21 02:39:57 +01:00
|
|
|
|
|
|
|
|
|
for (l = g_io_extension_point_get_extensions (ep); l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
extension = l->data;
|
|
|
|
|
width = MAX (width, strlen (g_io_extension_get_name (extension)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (l = g_io_extension_point_get_extensions (ep); l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
extension = l->data;
|
|
|
|
|
|
2020-11-18 19:53:33 +01:00
|
|
|
|
g_print (" %*s - %d\n", (int) MIN (width, G_MAXINT),
|
|
|
|
|
g_io_extension_get_name (extension),
|
|
|
|
|
g_io_extension_get_priority (extension));
|
2019-01-21 02:39:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 00:27:57 +01:00
|
|
|
|
/**
|
|
|
|
|
* _g_io_module_get_default_type:
|
|
|
|
|
* @extension_point: the name of an extension point
|
2016-10-29 03:29:02 +02:00
|
|
|
|
* @envvar: (nullable): the name of an environment variable to
|
2013-01-19 00:27:57 +01:00
|
|
|
|
* override the default implementation.
|
|
|
|
|
* @is_supported_offset: a vtable offset, or zero
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the default class implementing @extension_point.
|
|
|
|
|
*
|
|
|
|
|
* If @envvar is not %NULL, and the environment variable with that
|
|
|
|
|
* name is set, then the implementation it specifies will be tried
|
|
|
|
|
* first. After that, or if @envvar is not set, all other
|
|
|
|
|
* implementations will be tried in order of decreasing priority.
|
|
|
|
|
*
|
|
|
|
|
* If @is_supported_offset is non-zero, then it is the offset into the
|
|
|
|
|
* class vtable at which there is a function that takes no arguments and
|
|
|
|
|
* returns a boolean. This function will be called on each candidate
|
|
|
|
|
* implementation to check if it is actually usable or not.
|
|
|
|
|
*
|
|
|
|
|
* The result is cached after it is generated the first time, and
|
|
|
|
|
* the function is thread-safe.
|
|
|
|
|
*
|
2018-03-21 16:32:13 +01:00
|
|
|
|
* Returns: (transfer none): the type to instantiate to implement
|
|
|
|
|
* @extension_point, or %G_TYPE_INVALID if there are no usable
|
2013-01-19 00:27:57 +01:00
|
|
|
|
* implementations.
|
|
|
|
|
*/
|
|
|
|
|
GType
|
|
|
|
|
_g_io_module_get_default_type (const gchar *extension_point,
|
|
|
|
|
const gchar *envvar,
|
|
|
|
|
guint is_supported_offset)
|
|
|
|
|
{
|
|
|
|
|
static GRecMutex default_modules_lock;
|
|
|
|
|
static GHashTable *default_modules;
|
|
|
|
|
const char *use_this;
|
|
|
|
|
GList *l;
|
|
|
|
|
GIOExtensionPoint *ep;
|
|
|
|
|
GIOExtension *extension, *preferred;
|
|
|
|
|
gpointer impl;
|
|
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&default_modules_lock);
|
|
|
|
|
if (default_modules)
|
|
|
|
|
{
|
|
|
|
|
gpointer key;
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_lookup_extended (default_modules, extension_point, &key, &impl))
|
|
|
|
|
{
|
|
|
|
|
g_rec_mutex_unlock (&default_modules_lock);
|
|
|
|
|
return impl ? G_OBJECT_CLASS_TYPE (impl) : G_TYPE_INVALID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
default_modules = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_g_io_modules_ensure_loaded ();
|
|
|
|
|
ep = g_io_extension_point_lookup (extension_point);
|
|
|
|
|
|
|
|
|
|
if (!ep)
|
|
|
|
|
{
|
|
|
|
|
g_warn_if_reached ();
|
|
|
|
|
g_rec_mutex_unlock (&default_modules_lock);
|
|
|
|
|
return G_TYPE_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-05 00:33:43 +01:00
|
|
|
|
/* It’s OK to query the environment here, even when running as setuid, because
|
|
|
|
|
* it only allows a choice between existing already-loaded modules. No new
|
|
|
|
|
* code is loaded based on the environment variable value. */
|
2013-01-19 00:27:57 +01:00
|
|
|
|
use_this = envvar ? g_getenv (envvar) : NULL;
|
2019-01-21 02:39:57 +01:00
|
|
|
|
if (g_strcmp0 (use_this, "help") == 0)
|
|
|
|
|
{
|
|
|
|
|
print_help (envvar, ep);
|
|
|
|
|
use_this = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 00:27:57 +01:00
|
|
|
|
if (use_this)
|
|
|
|
|
{
|
|
|
|
|
preferred = g_io_extension_point_get_extension_by_name (ep, use_this);
|
|
|
|
|
if (preferred)
|
|
|
|
|
{
|
|
|
|
|
impl = try_class (preferred, is_supported_offset);
|
|
|
|
|
if (impl)
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_warning ("Can't find module '%s' specified in %s", use_this, envvar);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
preferred = NULL;
|
|
|
|
|
|
|
|
|
|
for (l = g_io_extension_point_get_extensions (ep); l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
extension = l->data;
|
|
|
|
|
if (extension == preferred)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
impl = try_class (extension, is_supported_offset);
|
|
|
|
|
if (impl)
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl = NULL;
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
g_hash_table_insert (default_modules, g_strdup (extension_point), impl);
|
|
|
|
|
g_rec_mutex_unlock (&default_modules_lock);
|
|
|
|
|
|
|
|
|
|
return impl ? G_OBJECT_CLASS_TYPE (impl) : G_TYPE_INVALID;
|
|
|
|
|
}
|
2011-06-22 00:21:27 +02:00
|
|
|
|
|
|
|
|
|
static gpointer
|
2018-07-21 00:53:09 +02:00
|
|
|
|
try_implementation (const char *extension_point,
|
|
|
|
|
GIOExtension *extension,
|
2011-06-22 00:21:27 +02:00
|
|
|
|
GIOModuleVerifyFunc verify_func)
|
|
|
|
|
{
|
|
|
|
|
GType type = g_io_extension_get_type (extension);
|
|
|
|
|
gpointer impl;
|
|
|
|
|
|
|
|
|
|
if (g_type_is_a (type, G_TYPE_INITABLE))
|
2018-07-21 00:53:09 +02:00
|
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
impl = g_initable_new (type, NULL, &error, NULL);
|
|
|
|
|
if (impl)
|
|
|
|
|
return impl;
|
|
|
|
|
|
|
|
|
|
g_debug ("Failed to initialize %s (%s) for %s: %s",
|
|
|
|
|
g_io_extension_get_name (extension),
|
|
|
|
|
g_type_name (type),
|
|
|
|
|
extension_point,
|
|
|
|
|
error ? error->message : "");
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-06-22 00:21:27 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
impl = g_object_new (type, NULL);
|
|
|
|
|
if (!verify_func || verify_func (impl))
|
|
|
|
|
return impl;
|
|
|
|
|
|
|
|
|
|
g_object_unref (impl);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 17:07:51 +01:00
|
|
|
|
static void
|
|
|
|
|
weak_ref_free (GWeakRef *weak_ref)
|
|
|
|
|
{
|
|
|
|
|
g_weak_ref_clear (weak_ref);
|
|
|
|
|
g_free (weak_ref);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-22 00:21:27 +02:00
|
|
|
|
/**
|
|
|
|
|
* _g_io_module_get_default:
|
|
|
|
|
* @extension_point: the name of an extension point
|
2016-10-29 03:29:02 +02:00
|
|
|
|
* @envvar: (nullable): the name of an environment variable to
|
2011-06-22 00:21:27 +02:00
|
|
|
|
* override the default implementation.
|
2016-10-29 03:29:02 +02:00
|
|
|
|
* @verify_func: (nullable): a function to call to verify that
|
2011-06-22 00:21:27 +02:00
|
|
|
|
* a given implementation is usable in the current environment.
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the default object implementing @extension_point.
|
|
|
|
|
*
|
|
|
|
|
* If @envvar is not %NULL, and the environment variable with that
|
|
|
|
|
* name is set, then the implementation it specifies will be tried
|
|
|
|
|
* first. After that, or if @envvar is not set, all other
|
|
|
|
|
* implementations will be tried in order of decreasing priority.
|
|
|
|
|
*
|
|
|
|
|
* If an extension point implementation implements #GInitable, then
|
|
|
|
|
* that implementation will only be used if it initializes
|
|
|
|
|
* successfully. Otherwise, if @verify_func is not %NULL, then it will
|
|
|
|
|
* be called on each candidate implementation after construction, to
|
|
|
|
|
* check if it is actually usable or not.
|
|
|
|
|
*
|
2019-01-23 17:07:51 +01:00
|
|
|
|
* The result is cached after it is generated the first time (but the cache does
|
|
|
|
|
* not keep a strong reference to the object), and
|
2011-06-22 00:21:27 +02:00
|
|
|
|
* the function is thread-safe.
|
|
|
|
|
*
|
2019-01-23 17:07:51 +01:00
|
|
|
|
* Returns: (transfer full) (nullable): an object implementing
|
2011-06-22 00:21:27 +02:00
|
|
|
|
* @extension_point, or %NULL if there are no usable
|
|
|
|
|
* implementations.
|
|
|
|
|
*/
|
|
|
|
|
gpointer
|
|
|
|
|
_g_io_module_get_default (const gchar *extension_point,
|
|
|
|
|
const gchar *envvar,
|
|
|
|
|
GIOModuleVerifyFunc verify_func)
|
|
|
|
|
{
|
2013-01-19 00:27:57 +01:00
|
|
|
|
static GRecMutex default_modules_lock;
|
|
|
|
|
static GHashTable *default_modules;
|
2011-06-22 00:21:27 +02:00
|
|
|
|
const char *use_this;
|
|
|
|
|
GList *l;
|
|
|
|
|
GIOExtensionPoint *ep;
|
2019-01-24 15:35:13 +01:00
|
|
|
|
GIOExtension *extension = NULL, *preferred;
|
2019-01-23 17:07:51 +01:00
|
|
|
|
gpointer impl, value;
|
|
|
|
|
GWeakRef *impl_weak_ref = NULL;
|
2011-06-22 00:21:27 +02:00
|
|
|
|
|
2011-10-12 19:57:44 +02:00
|
|
|
|
g_rec_mutex_lock (&default_modules_lock);
|
2011-06-22 00:21:27 +02:00
|
|
|
|
if (default_modules)
|
|
|
|
|
{
|
|
|
|
|
if (g_hash_table_lookup_extended (default_modules, extension_point,
|
2019-01-23 17:07:51 +01:00
|
|
|
|
NULL, &value))
|
|
|
|
|
{
|
2018-09-13 00:45:46 +02:00
|
|
|
|
/* Don’t debug here, since we’re returning a cached object which was
|
|
|
|
|
* already printed earlier. */
|
2019-01-23 17:07:51 +01:00
|
|
|
|
impl_weak_ref = value;
|
|
|
|
|
impl = g_weak_ref_get (impl_weak_ref);
|
|
|
|
|
|
|
|
|
|
/* If the object has been finalised (impl == NULL), fall through and
|
|
|
|
|
* instantiate a new one. */
|
|
|
|
|
if (impl != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_rec_mutex_unlock (&default_modules_lock);
|
|
|
|
|
return g_steal_pointer (&impl);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-22 00:21:27 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-23 17:07:51 +01:00
|
|
|
|
default_modules = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
|
g_free, (GDestroyNotify) weak_ref_free);
|
2011-06-22 00:21:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_g_io_modules_ensure_loaded ();
|
|
|
|
|
ep = g_io_extension_point_lookup (extension_point);
|
|
|
|
|
|
|
|
|
|
if (!ep)
|
|
|
|
|
{
|
2018-09-13 00:45:46 +02:00
|
|
|
|
g_debug ("%s: Failed to find extension point ‘%s’",
|
|
|
|
|
G_STRFUNC, extension_point);
|
2011-06-22 00:21:27 +02:00
|
|
|
|
g_warn_if_reached ();
|
2011-10-12 19:57:44 +02:00
|
|
|
|
g_rec_mutex_unlock (&default_modules_lock);
|
2011-06-22 00:21:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-05 00:33:43 +01:00
|
|
|
|
/* It’s OK to query the environment here, even when running as setuid, because
|
|
|
|
|
* it only allows a choice between existing already-loaded modules. No new
|
|
|
|
|
* code is loaded based on the environment variable value. */
|
2011-06-22 00:21:27 +02:00
|
|
|
|
use_this = envvar ? g_getenv (envvar) : NULL;
|
2019-01-21 02:39:57 +01:00
|
|
|
|
if (g_strcmp0 (use_this, "help") == 0)
|
|
|
|
|
{
|
|
|
|
|
print_help (envvar, ep);
|
|
|
|
|
use_this = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-22 00:21:27 +02:00
|
|
|
|
if (use_this)
|
|
|
|
|
{
|
|
|
|
|
preferred = g_io_extension_point_get_extension_by_name (ep, use_this);
|
|
|
|
|
if (preferred)
|
|
|
|
|
{
|
2018-07-21 00:53:09 +02:00
|
|
|
|
impl = try_implementation (extension_point, preferred, verify_func);
|
2018-09-13 00:45:46 +02:00
|
|
|
|
extension = preferred;
|
2011-06-22 00:21:27 +02:00
|
|
|
|
if (impl)
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
else
|
2019-01-21 02:39:57 +01:00
|
|
|
|
g_warning ("Can't find module '%s' specified in %s", use_this, envvar);
|
2011-06-22 00:21:27 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
preferred = NULL;
|
|
|
|
|
|
|
|
|
|
for (l = g_io_extension_point_get_extensions (ep); l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
extension = l->data;
|
|
|
|
|
if (extension == preferred)
|
|
|
|
|
continue;
|
|
|
|
|
|
2018-07-21 00:53:09 +02:00
|
|
|
|
impl = try_implementation (extension_point, extension, verify_func);
|
2011-06-22 00:21:27 +02:00
|
|
|
|
if (impl)
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl = NULL;
|
|
|
|
|
|
|
|
|
|
done:
|
2019-01-23 17:07:51 +01:00
|
|
|
|
if (impl_weak_ref == NULL)
|
|
|
|
|
{
|
|
|
|
|
impl_weak_ref = g_new0 (GWeakRef, 1);
|
|
|
|
|
g_weak_ref_init (impl_weak_ref, impl);
|
|
|
|
|
g_hash_table_insert (default_modules, g_strdup (extension_point),
|
|
|
|
|
g_steal_pointer (&impl_weak_ref));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_weak_ref_set (impl_weak_ref, impl);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-12 19:57:44 +02:00
|
|
|
|
g_rec_mutex_unlock (&default_modules_lock);
|
2011-06-22 00:21:27 +02:00
|
|
|
|
|
2018-09-13 00:45:46 +02:00
|
|
|
|
if (impl != NULL)
|
2019-01-24 15:35:13 +01:00
|
|
|
|
{
|
|
|
|
|
g_assert (extension != NULL);
|
|
|
|
|
g_debug ("%s: Found default implementation %s (%s) for ‘%s’",
|
|
|
|
|
G_STRFUNC, g_io_extension_get_name (extension),
|
|
|
|
|
G_OBJECT_TYPE_NAME (impl), extension_point);
|
|
|
|
|
}
|
2018-09-13 00:45:46 +02:00
|
|
|
|
else
|
|
|
|
|
g_debug ("%s: Failed to find default implementation for ‘%s’",
|
|
|
|
|
G_STRFUNC, extension_point);
|
|
|
|
|
|
2019-01-23 17:07:51 +01:00
|
|
|
|
return g_steal_pointer (&impl);
|
2011-06-22 00:21:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 20:59:35 +01:00
|
|
|
|
extern GType g_inotify_file_monitor_get_type (void);
|
|
|
|
|
extern GType g_kqueue_file_monitor_get_type (void);
|
|
|
|
|
extern GType g_win32_file_monitor_get_type (void);
|
|
|
|
|
|
2007-12-19 17:08:55 +01:00
|
|
|
|
extern GType _g_unix_volume_monitor_get_type (void);
|
|
|
|
|
extern GType _g_local_vfs_get_type (void);
|
|
|
|
|
|
2008-06-17 23:40:04 +02:00
|
|
|
|
extern GType _g_win32_volume_monitor_get_type (void);
|
2008-08-13 01:09:04 +02:00
|
|
|
|
extern GType _g_winhttp_vfs_get_type (void);
|
2008-03-12 20:09:11 +01:00
|
|
|
|
|
2010-05-07 21:55:54 +02:00
|
|
|
|
extern GType _g_dummy_proxy_resolver_get_type (void);
|
2009-12-21 20:50:32 +01:00
|
|
|
|
extern GType _g_dummy_tls_backend_get_type (void);
|
2011-06-12 21:59:36 +02:00
|
|
|
|
extern GType g_network_monitor_base_get_type (void);
|
|
|
|
|
#ifdef HAVE_NETLINK
|
|
|
|
|
extern GType _g_network_monitor_netlink_get_type (void);
|
2014-12-03 18:36:25 +01:00
|
|
|
|
extern GType _g_network_monitor_nm_get_type (void);
|
2011-06-12 21:59:36 +02:00
|
|
|
|
#endif
|
2010-05-07 21:55:54 +02:00
|
|
|
|
|
2021-11-11 11:56:50 +01:00
|
|
|
|
extern GType g_debug_controller_dbus_get_type (void);
|
2019-07-25 15:52:09 +02:00
|
|
|
|
extern GType g_memory_monitor_dbus_get_type (void);
|
|
|
|
|
extern GType g_memory_monitor_portal_get_type (void);
|
2022-01-23 21:36:56 +01:00
|
|
|
|
extern GType g_memory_monitor_win32_get_type (void);
|
2021-07-20 23:04:31 +02:00
|
|
|
|
extern GType g_power_profile_monitor_dbus_get_type (void);
|
2019-07-25 15:52:09 +02:00
|
|
|
|
|
2013-10-15 17:21:10 +02:00
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
|
extern GType g_fdo_notification_backend_get_type (void);
|
2013-10-15 18:19:09 +02:00
|
|
|
|
extern GType g_gtk_notification_backend_get_type (void);
|
2016-07-01 07:12:30 +02:00
|
|
|
|
extern GType g_portal_notification_backend_get_type (void);
|
2016-07-11 15:51:37 +02:00
|
|
|
|
extern GType g_proxy_resolver_portal_get_type (void);
|
|
|
|
|
extern GType g_network_monitor_portal_get_type (void);
|
2013-10-15 17:21:10 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2017-03-09 04:26:00 +01:00
|
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
|
2015-03-25 20:51:29 +01:00
|
|
|
|
extern GType g_cocoa_notification_backend_get_type (void);
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-10-11 23:18:48 +02:00
|
|
|
|
#ifdef G_PLATFORM_WIN32
|
2018-03-21 16:48:52 +01:00
|
|
|
|
extern GType g_win32_notification_backend_get_type (void);
|
2009-10-11 23:18:48 +02:00
|
|
|
|
|
|
|
|
|
#include <windows.h>
|
2018-01-17 13:58:40 +01:00
|
|
|
|
extern GType _g_win32_network_monitor_get_type (void);
|
2009-10-11 23:18:48 +02:00
|
|
|
|
|
|
|
|
|
static HMODULE gio_dll = NULL;
|
|
|
|
|
|
2022-01-19 14:19:05 +01:00
|
|
|
|
#ifndef GLIB_STATIC_COMPILATION
|
2009-10-11 23:18:48 +02:00
|
|
|
|
|
2012-11-10 16:58:19 +01:00
|
|
|
|
BOOL WINAPI DllMain (HINSTANCE hinstDLL,
|
|
|
|
|
DWORD fdwReason,
|
|
|
|
|
LPVOID lpvReserved);
|
|
|
|
|
|
2009-10-11 23:18:48 +02:00
|
|
|
|
BOOL WINAPI
|
|
|
|
|
DllMain (HINSTANCE hinstDLL,
|
|
|
|
|
DWORD fdwReason,
|
|
|
|
|
LPVOID lpvReserved)
|
|
|
|
|
{
|
|
|
|
|
if (fdwReason == DLL_PROCESS_ATTACH)
|
2020-10-04 00:44:19 +02:00
|
|
|
|
{
|
2009-10-11 23:18:48 +02:00
|
|
|
|
gio_dll = hinstDLL;
|
2020-10-04 00:44:19 +02:00
|
|
|
|
gio_win32_appinfo_init (FALSE);
|
|
|
|
|
}
|
2009-10-11 23:18:48 +02:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 14:19:05 +01:00
|
|
|
|
#elif defined(G_HAS_CONSTRUCTORS) /* && G_PLATFORM_WIN32 && GLIB_STATIC_COMPILATION */
|
|
|
|
|
extern void glib_win32_init (void);
|
|
|
|
|
extern void gobject_win32_init (void);
|
|
|
|
|
|
|
|
|
|
#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
|
|
|
|
|
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(giomodule_init_ctor)
|
2012-12-02 15:34:37 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2022-01-19 14:19:05 +01:00
|
|
|
|
G_DEFINE_CONSTRUCTOR (giomodule_init_ctor)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
giomodule_init_ctor (void)
|
|
|
|
|
{
|
|
|
|
|
/* When built dynamically, module initialization is done through DllMain
|
|
|
|
|
* function which is called when the dynamic library is loaded by the glib
|
|
|
|
|
* module AFTER loading gobject. So, in dynamic configuration glib and
|
|
|
|
|
* gobject are always initialized BEFORE gio.
|
|
|
|
|
*
|
|
|
|
|
* When built statically, initialization mechanism relies on hooking
|
|
|
|
|
* functions to the CRT section directly at compilation time. As we don't
|
|
|
|
|
* control how each compilation unit will be built and in which order, we
|
|
|
|
|
* obtain the same kind of issue as the "static initialization order fiasco".
|
|
|
|
|
* In this case, we must ensure explicitly that glib and gobject are always
|
|
|
|
|
* well initialized BEFORE gio.
|
|
|
|
|
*/
|
|
|
|
|
glib_win32_init ();
|
|
|
|
|
gobject_win32_init ();
|
|
|
|
|
gio_win32_appinfo_init (FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else /* G_PLATFORM_WIN32 && GLIB_STATIC_COMPILATION && !G_HAS_CONSTRUCTORS */
|
|
|
|
|
#error Your platform/compiler is missing constructor support
|
|
|
|
|
#endif /* GLIB_STATIC_COMPILATION */
|
|
|
|
|
|
2012-04-18 16:25:29 +02:00
|
|
|
|
void *
|
|
|
|
|
_g_io_win32_get_module (void)
|
|
|
|
|
{
|
2012-12-02 15:34:37 +01:00
|
|
|
|
if (!gio_dll)
|
2021-03-25 16:20:27 +01:00
|
|
|
|
GetModuleHandleExA (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
|
|
|
|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
2012-12-02 15:34:37 +01:00
|
|
|
|
(const char *) _g_io_win32_get_module,
|
|
|
|
|
&gio_dll);
|
2012-04-18 16:25:29 +02:00
|
|
|
|
return gio_dll;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 14:19:05 +01:00
|
|
|
|
#endif /* G_PLATFORM_WIN32 */
|
2009-10-11 23:18:48 +02:00
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
|
void
|
2009-02-27 16:22:11 +01:00
|
|
|
|
_g_io_modules_ensure_extension_points_registered (void)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2022-07-13 00:42:29 +02:00
|
|
|
|
static gsize registered_extensions = FALSE;
|
2008-01-28 20:43:10 +01:00
|
|
|
|
GIOExtensionPoint *ep;
|
2007-12-19 17:08:55 +01:00
|
|
|
|
|
2022-07-13 00:42:29 +02:00
|
|
|
|
if (g_once_init_enter (®istered_extensions))
|
2007-11-26 17:13:05 +01:00
|
|
|
|
{
|
2022-11-03 19:22:18 +01:00
|
|
|
|
#if defined(G_OS_UNIX) && !defined(__APPLE__)
|
2010-11-09 13:19:19 +01:00
|
|
|
|
#if !GLIB_CHECK_VERSION (3, 0, 0)
|
|
|
|
|
ep = g_io_extension_point_register (G_DESKTOP_APP_INFO_LOOKUP_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_DESKTOP_APP_INFO_LOOKUP);
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2015-01-12 20:59:35 +01:00
|
|
|
|
|
2008-01-28 20:43:10 +01:00
|
|
|
|
ep = g_io_extension_point_register (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_LOCAL_FILE_MONITOR);
|
2013-01-19 00:44:11 +01:00
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register (G_NFS_FILE_MONITOR_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_LOCAL_FILE_MONITOR);
|
|
|
|
|
|
2008-01-28 20:43:10 +01:00
|
|
|
|
ep = g_io_extension_point_register (G_VOLUME_MONITOR_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_VOLUME_MONITOR);
|
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register (G_NATIVE_VOLUME_MONITOR_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_NATIVE_VOLUME_MONITOR);
|
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register (G_VFS_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_VFS);
|
2009-08-28 05:40:16 +02:00
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register ("gsettings-backend");
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_OBJECT);
|
2010-05-07 21:55:54 +02:00
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register (G_PROXY_RESOLVER_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_PROXY_RESOLVER);
|
2010-08-10 21:24:37 +02:00
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register (G_PROXY_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_PROXY);
|
2009-12-21 20:50:32 +01:00
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register (G_TLS_BACKEND_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_TLS_BACKEND);
|
2011-06-12 21:59:36 +02:00
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register (G_NETWORK_MONITOR_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_NETWORK_MONITOR);
|
2013-10-15 17:21:10 +02:00
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register (G_NOTIFICATION_BACKEND_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_NOTIFICATION_BACKEND);
|
2019-07-25 15:52:09 +02:00
|
|
|
|
|
2021-11-11 11:56:50 +01:00
|
|
|
|
ep = g_io_extension_point_register (G_DEBUG_CONTROLLER_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_DEBUG_CONTROLLER);
|
|
|
|
|
|
2019-07-25 15:52:09 +02:00
|
|
|
|
ep = g_io_extension_point_register (G_MEMORY_MONITOR_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_MEMORY_MONITOR);
|
2021-07-20 23:04:31 +02:00
|
|
|
|
|
|
|
|
|
ep = g_io_extension_point_register (G_POWER_PROFILE_MONITOR_EXTENSION_POINT_NAME);
|
|
|
|
|
g_io_extension_point_set_required_type (ep, G_TYPE_POWER_PROFILE_MONITOR);
|
2022-07-13 00:42:29 +02:00
|
|
|
|
|
|
|
|
|
g_once_init_leave (®istered_extensions, TRUE);
|
2009-02-27 16:22:11 +01:00
|
|
|
|
}
|
2012-01-30 21:25:09 +01:00
|
|
|
|
}
|
2009-02-27 16:22:11 +01:00
|
|
|
|
|
2015-10-22 08:18:24 +02:00
|
|
|
|
static gchar *
|
|
|
|
|
get_gio_module_dir (void)
|
|
|
|
|
{
|
|
|
|
|
gchar *module_dir;
|
2020-12-05 00:33:43 +01:00
|
|
|
|
gboolean is_setuid = GLIB_PRIVATE_CALL (g_check_setuid) ();
|
|
|
|
|
|
|
|
|
|
/* If running as setuid, loading modules from an arbitrary directory
|
|
|
|
|
* controlled by the unprivileged user who is running the program could allow
|
|
|
|
|
* for execution of arbitrary code (in constructors in modules).
|
|
|
|
|
* Don’t allow it.
|
|
|
|
|
*
|
|
|
|
|
* If a setuid program somehow needs to load additional GIO modules, it should
|
|
|
|
|
* explicitly call g_io_modules_scan_all_in_directory(). */
|
|
|
|
|
module_dir = !is_setuid ? g_strdup (g_getenv ("GIO_MODULE_DIR")) : NULL;
|
2015-10-22 08:18:24 +02:00
|
|
|
|
if (module_dir == NULL)
|
|
|
|
|
{
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
gchar *install_dir;
|
|
|
|
|
|
|
|
|
|
install_dir = g_win32_get_package_installation_directory_of_module (gio_dll);
|
|
|
|
|
module_dir = g_build_filename (install_dir,
|
|
|
|
|
"lib", "gio", "modules",
|
|
|
|
|
NULL);
|
|
|
|
|
g_free (install_dir);
|
|
|
|
|
#else
|
2015-10-22 10:36:00 +02:00
|
|
|
|
module_dir = g_strdup (GIO_MODULE_DIR);
|
2022-11-02 11:01:09 +01:00
|
|
|
|
#ifdef __APPLE__
|
2022-08-09 10:42:39 +02:00
|
|
|
|
#include "TargetConditionals.h"
|
2023-04-18 03:35:08 +02:00
|
|
|
|
/* Only auto-relocate on macOS, not watchOS etc; older macOS SDKs only define TARGET_OS_MAC */
|
|
|
|
|
#if (defined (TARGET_OS_OSX) && TARGET_OS_OSX) || \
|
|
|
|
|
(!defined (TARGET_OS_OSX) && defined (TARGET_OS_MAC) && TARGET_OS_MAC)
|
2022-08-09 10:42:39 +02:00
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
{
|
|
|
|
|
g_autofree gchar *path = NULL;
|
|
|
|
|
g_autofree gchar *possible_dir = NULL;
|
|
|
|
|
Dl_info info;
|
|
|
|
|
|
|
|
|
|
if (dladdr (get_gio_module_dir, &info))
|
|
|
|
|
{
|
|
|
|
|
/* Gets path to the PREFIX/lib directory */
|
|
|
|
|
path = g_path_get_dirname (info.dli_fname);
|
|
|
|
|
possible_dir = g_build_filename (path, "gio", "modules", NULL);
|
|
|
|
|
if (g_file_test (possible_dir, G_FILE_TEST_IS_DIR))
|
|
|
|
|
{
|
|
|
|
|
g_free (module_dir);
|
|
|
|
|
module_dir = g_steal_pointer (&possible_dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-11-02 11:01:09 +01:00
|
|
|
|
#endif
|
2015-10-22 08:18:24 +02:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return module_dir;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-27 16:22:11 +01:00
|
|
|
|
void
|
|
|
|
|
_g_io_modules_ensure_loaded (void)
|
|
|
|
|
{
|
2022-07-13 00:42:29 +02:00
|
|
|
|
static gsize loaded_dirs = FALSE;
|
2009-02-27 16:22:11 +01:00
|
|
|
|
const char *module_path;
|
2011-08-26 15:27:19 +02:00
|
|
|
|
GIOModuleScope *scope;
|
2009-02-27 16:22:11 +01:00
|
|
|
|
|
|
|
|
|
_g_io_modules_ensure_extension_points_registered ();
|
|
|
|
|
|
2022-07-13 00:42:29 +02:00
|
|
|
|
if (g_once_init_enter (&loaded_dirs))
|
2009-02-27 16:22:11 +01:00
|
|
|
|
{
|
2020-12-05 00:33:43 +01:00
|
|
|
|
gboolean is_setuid = GLIB_PRIVATE_CALL (g_check_setuid) ();
|
2015-10-22 08:18:24 +02:00
|
|
|
|
gchar *module_dir;
|
|
|
|
|
|
2011-08-26 15:27:19 +02:00
|
|
|
|
scope = g_io_module_scope_new (G_IO_MODULE_SCOPE_BLOCK_DUPLICATES);
|
2009-02-27 16:22:11 +01:00
|
|
|
|
|
2020-12-05 00:33:43 +01:00
|
|
|
|
/* First load any overrides, extras (but not if running as setuid!) */
|
|
|
|
|
module_path = !is_setuid ? g_getenv ("GIO_EXTRA_MODULES") : NULL;
|
2008-03-28 15:31:09 +01:00
|
|
|
|
if (module_path)
|
2010-01-12 11:57:17 +01:00
|
|
|
|
{
|
|
|
|
|
gchar **paths;
|
|
|
|
|
int i;
|
2008-03-28 15:31:09 +01:00
|
|
|
|
|
2011-10-15 23:57:23 +02:00
|
|
|
|
paths = g_strsplit (module_path, G_SEARCHPATH_SEPARATOR_S, 0);
|
2010-01-12 11:57:17 +01:00
|
|
|
|
|
|
|
|
|
for (i = 0; paths[i] != NULL; i++)
|
2011-08-26 15:27:19 +02:00
|
|
|
|
{
|
|
|
|
|
g_io_modules_scan_all_in_directory_with_scope (paths[i], scope);
|
|
|
|
|
}
|
2010-01-12 11:57:17 +01:00
|
|
|
|
|
|
|
|
|
g_strfreev (paths);
|
|
|
|
|
}
|
2008-03-28 15:31:09 +01:00
|
|
|
|
|
2011-08-26 15:27:19 +02:00
|
|
|
|
/* Then load the compiled in path */
|
2015-10-22 08:18:24 +02:00
|
|
|
|
module_dir = get_gio_module_dir ();
|
2013-11-08 14:26:33 +01:00
|
|
|
|
|
|
|
|
|
g_io_modules_scan_all_in_directory_with_scope (module_dir, scope);
|
2015-10-22 08:18:24 +02:00
|
|
|
|
g_free (module_dir);
|
2011-08-26 15:27:19 +02:00
|
|
|
|
|
|
|
|
|
g_io_module_scope_free (scope);
|
|
|
|
|
|
2007-12-19 17:08:55 +01:00
|
|
|
|
/* Initialize types from built-in "modules" */
|
2010-01-03 20:47:56 +01:00
|
|
|
|
g_type_ensure (g_null_settings_backend_get_type ());
|
|
|
|
|
g_type_ensure (g_memory_settings_backend_get_type ());
|
2019-07-08 16:31:51 +02:00
|
|
|
|
g_type_ensure (g_keyfile_settings_backend_get_type ());
|
2021-07-20 23:04:31 +02:00
|
|
|
|
g_type_ensure (g_power_profile_monitor_dbus_get_type ());
|
2014-02-14 00:26:07 +01:00
|
|
|
|
#if defined(HAVE_INOTIFY_INIT1)
|
2015-01-12 20:59:35 +01:00
|
|
|
|
g_type_ensure (g_inotify_file_monitor_get_type ());
|
2008-03-14 10:45:44 +01:00
|
|
|
|
#endif
|
2012-11-14 12:57:42 +01:00
|
|
|
|
#if defined(HAVE_KQUEUE)
|
2015-01-12 20:59:35 +01:00
|
|
|
|
g_type_ensure (g_kqueue_file_monitor_get_type ());
|
2012-11-14 12:57:42 +01:00
|
|
|
|
#endif
|
2008-03-14 10:45:44 +01:00
|
|
|
|
#ifdef G_OS_WIN32
|
2010-01-03 20:47:56 +01:00
|
|
|
|
g_type_ensure (_g_win32_volume_monitor_get_type ());
|
2015-01-12 20:59:35 +01:00
|
|
|
|
g_type_ensure (g_win32_file_monitor_get_type ());
|
2023-04-14 19:00:01 +02:00
|
|
|
|
g_type_ensure (g_registry_settings_backend_get_type ());
|
2008-03-14 10:45:44 +01:00
|
|
|
|
#endif
|
2014-06-09 21:17:19 +02:00
|
|
|
|
#ifdef HAVE_COCOA
|
2017-03-09 04:27:06 +01:00
|
|
|
|
g_type_ensure (g_nextstep_settings_backend_get_type ());
|
2015-03-25 23:26:50 +01:00
|
|
|
|
g_type_ensure (g_osx_app_info_get_type ());
|
2011-12-26 16:04:38 +01:00
|
|
|
|
#endif
|
2007-12-19 17:08:55 +01:00
|
|
|
|
#ifdef G_OS_UNIX
|
2010-01-03 20:47:56 +01:00
|
|
|
|
g_type_ensure (_g_unix_volume_monitor_get_type ());
|
2022-02-10 20:23:49 +01:00
|
|
|
|
g_type_ensure (g_debug_controller_dbus_get_type ());
|
2013-10-15 17:21:10 +02:00
|
|
|
|
g_type_ensure (g_fdo_notification_backend_get_type ());
|
2013-10-15 18:19:09 +02:00
|
|
|
|
g_type_ensure (g_gtk_notification_backend_get_type ());
|
2016-07-01 07:12:30 +02:00
|
|
|
|
g_type_ensure (g_portal_notification_backend_get_type ());
|
2019-07-25 15:52:09 +02:00
|
|
|
|
g_type_ensure (g_memory_monitor_dbus_get_type ());
|
|
|
|
|
g_type_ensure (g_memory_monitor_portal_get_type ());
|
2016-07-11 15:51:37 +02:00
|
|
|
|
g_type_ensure (g_network_monitor_portal_get_type ());
|
2021-08-09 23:19:17 +02:00
|
|
|
|
g_type_ensure (g_power_profile_monitor_portal_get_type ());
|
2016-07-11 15:51:37 +02:00
|
|
|
|
g_type_ensure (g_proxy_resolver_portal_get_type ());
|
2008-08-13 01:09:04 +02:00
|
|
|
|
#endif
|
2019-03-29 15:52:38 +01:00
|
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
|
2015-03-25 20:51:29 +01:00
|
|
|
|
g_type_ensure (g_cocoa_notification_backend_get_type ());
|
|
|
|
|
#endif
|
2008-08-13 01:09:04 +02:00
|
|
|
|
#ifdef G_OS_WIN32
|
2018-03-21 16:48:52 +01:00
|
|
|
|
g_type_ensure (g_win32_notification_backend_get_type ());
|
2010-01-03 20:47:56 +01:00
|
|
|
|
g_type_ensure (_g_winhttp_vfs_get_type ());
|
2022-01-23 21:36:56 +01:00
|
|
|
|
g_type_ensure (g_memory_monitor_win32_get_type ());
|
2007-12-19 17:08:55 +01:00
|
|
|
|
#endif
|
2010-01-03 20:47:56 +01:00
|
|
|
|
g_type_ensure (_g_local_vfs_get_type ());
|
|
|
|
|
g_type_ensure (_g_dummy_proxy_resolver_get_type ());
|
2015-02-28 11:05:02 +01:00
|
|
|
|
g_type_ensure (_g_http_proxy_get_type ());
|
|
|
|
|
g_type_ensure (_g_https_proxy_get_type ());
|
2010-01-03 20:47:56 +01:00
|
|
|
|
g_type_ensure (_g_socks4a_proxy_get_type ());
|
|
|
|
|
g_type_ensure (_g_socks4_proxy_get_type ());
|
|
|
|
|
g_type_ensure (_g_socks5_proxy_get_type ());
|
|
|
|
|
g_type_ensure (_g_dummy_tls_backend_get_type ());
|
|
|
|
|
g_type_ensure (g_network_monitor_base_get_type ());
|
2011-06-12 21:59:36 +02:00
|
|
|
|
#ifdef HAVE_NETLINK
|
2010-01-03 20:47:56 +01:00
|
|
|
|
g_type_ensure (_g_network_monitor_netlink_get_type ());
|
2014-12-03 18:36:25 +01:00
|
|
|
|
g_type_ensure (_g_network_monitor_nm_get_type ());
|
2017-12-26 14:06:08 +01:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef G_OS_WIN32
|
2018-01-17 13:58:40 +01:00
|
|
|
|
g_type_ensure (_g_win32_network_monitor_get_type ());
|
2011-06-12 21:59:36 +02:00
|
|
|
|
#endif
|
2007-12-19 17:08:55 +01:00
|
|
|
|
|
2022-07-13 00:42:29 +02:00
|
|
|
|
g_once_init_leave (&loaded_dirs, TRUE);
|
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
}
|
2007-11-28 13:39:07 +01:00
|
|
|
|
|
2008-01-28 20:43:10 +01:00
|
|
|
|
static void
|
|
|
|
|
g_io_extension_point_free (GIOExtensionPoint *ep)
|
|
|
|
|
{
|
|
|
|
|
g_free (ep->name);
|
|
|
|
|
g_free (ep);
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_point_register:
|
|
|
|
|
* @name: The name of the extension point
|
|
|
|
|
*
|
|
|
|
|
* Registers an extension point.
|
|
|
|
|
*
|
2010-07-29 13:59:42 +02:00
|
|
|
|
* Returns: (transfer none): the new #GIOExtensionPoint. This object is
|
|
|
|
|
* owned by GIO and should not be freed.
|
2008-02-11 08:12:56 +01:00
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
GIOExtensionPoint *
|
|
|
|
|
g_io_extension_point_register (const char *name)
|
|
|
|
|
{
|
|
|
|
|
GIOExtensionPoint *ep;
|
|
|
|
|
|
|
|
|
|
G_LOCK (extension_points);
|
|
|
|
|
if (extension_points == NULL)
|
|
|
|
|
extension_points = g_hash_table_new_full (g_str_hash,
|
|
|
|
|
g_str_equal,
|
|
|
|
|
NULL,
|
|
|
|
|
(GDestroyNotify)g_io_extension_point_free);
|
|
|
|
|
|
2010-01-12 11:36:12 +01:00
|
|
|
|
ep = g_hash_table_lookup (extension_points, name);
|
|
|
|
|
if (ep != NULL)
|
2008-01-28 20:43:10 +01:00
|
|
|
|
{
|
|
|
|
|
G_UNLOCK (extension_points);
|
2010-01-12 11:36:12 +01:00
|
|
|
|
return ep;
|
2008-01-28 20:43:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ep = g_new0 (GIOExtensionPoint, 1);
|
|
|
|
|
ep->name = g_strdup (name);
|
|
|
|
|
|
|
|
|
|
g_hash_table_insert (extension_points, ep->name, ep);
|
|
|
|
|
|
|
|
|
|
G_UNLOCK (extension_points);
|
|
|
|
|
|
|
|
|
|
return ep;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_point_lookup:
|
|
|
|
|
* @name: the name of the extension point
|
|
|
|
|
*
|
|
|
|
|
* Looks up an existing extension point.
|
|
|
|
|
*
|
2010-07-29 13:59:42 +02:00
|
|
|
|
* Returns: (transfer none): the #GIOExtensionPoint, or %NULL if there
|
|
|
|
|
* is no registered extension point with the given name.
|
2008-02-11 08:12:56 +01:00
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
GIOExtensionPoint *
|
|
|
|
|
g_io_extension_point_lookup (const char *name)
|
|
|
|
|
{
|
|
|
|
|
GIOExtensionPoint *ep;
|
|
|
|
|
|
|
|
|
|
G_LOCK (extension_points);
|
|
|
|
|
ep = NULL;
|
|
|
|
|
if (extension_points != NULL)
|
|
|
|
|
ep = g_hash_table_lookup (extension_points, name);
|
|
|
|
|
|
|
|
|
|
G_UNLOCK (extension_points);
|
|
|
|
|
|
|
|
|
|
return ep;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_point_set_required_type:
|
|
|
|
|
* @extension_point: a #GIOExtensionPoint
|
|
|
|
|
* @type: the #GType to require
|
|
|
|
|
*
|
|
|
|
|
* Sets the required type for @extension_point to @type.
|
|
|
|
|
* All implementations must henceforth have this type.
|
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
void
|
|
|
|
|
g_io_extension_point_set_required_type (GIOExtensionPoint *extension_point,
|
|
|
|
|
GType type)
|
|
|
|
|
{
|
|
|
|
|
extension_point->required_type = type;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_point_get_required_type:
|
|
|
|
|
* @extension_point: a #GIOExtensionPoint
|
|
|
|
|
*
|
|
|
|
|
* Gets the required type for @extension_point.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #GType that all implementations must have,
|
2022-03-04 17:21:55 +01:00
|
|
|
|
* or %G_TYPE_INVALID if the extension point has no required type
|
2008-02-11 08:12:56 +01:00
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
GType
|
|
|
|
|
g_io_extension_point_get_required_type (GIOExtensionPoint *extension_point)
|
|
|
|
|
{
|
|
|
|
|
return extension_point->required_type;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-17 03:24:45 +02:00
|
|
|
|
static void
|
2010-01-12 11:36:12 +01:00
|
|
|
|
lazy_load_modules (GIOExtensionPoint *extension_point)
|
|
|
|
|
{
|
|
|
|
|
GIOModule *module;
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
for (l = extension_point->lazy_load_modules; l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
module = l->data;
|
|
|
|
|
|
|
|
|
|
if (!module->initialized)
|
|
|
|
|
{
|
|
|
|
|
if (g_type_module_use (G_TYPE_MODULE (module)))
|
|
|
|
|
g_type_module_unuse (G_TYPE_MODULE (module)); /* Unload */
|
|
|
|
|
else
|
|
|
|
|
g_printerr ("Failed to load module: %s\n",
|
|
|
|
|
module->filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_point_get_extensions:
|
|
|
|
|
* @extension_point: a #GIOExtensionPoint
|
|
|
|
|
*
|
|
|
|
|
* Gets a list of all extensions that implement this extension point.
|
|
|
|
|
* The list is sorted by priority, beginning with the highest priority.
|
2010-07-26 17:21:14 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: (element-type GIOExtension) (transfer none): a #GList of
|
2014-02-01 17:57:13 +01:00
|
|
|
|
* #GIOExtensions. The list is owned by GIO and should not be
|
|
|
|
|
* modified.
|
2008-02-11 08:12:56 +01:00
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
GList *
|
|
|
|
|
g_io_extension_point_get_extensions (GIOExtensionPoint *extension_point)
|
|
|
|
|
{
|
2017-02-24 16:46:55 +01:00
|
|
|
|
g_return_val_if_fail (extension_point != NULL, NULL);
|
|
|
|
|
|
2010-01-12 11:36:12 +01:00
|
|
|
|
lazy_load_modules (extension_point);
|
2008-01-28 20:43:10 +01:00
|
|
|
|
return extension_point->extensions;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_point_get_extension_by_name:
|
|
|
|
|
* @extension_point: a #GIOExtensionPoint
|
|
|
|
|
* @name: the name of the extension to get
|
|
|
|
|
*
|
|
|
|
|
* Finds a #GIOExtension for an extension point by name.
|
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
|
* Returns: (transfer none): the #GIOExtension for @extension_point that has the
|
2008-02-11 08:12:56 +01:00
|
|
|
|
* given name, or %NULL if there is no extension with that name
|
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
GIOExtension *
|
|
|
|
|
g_io_extension_point_get_extension_by_name (GIOExtensionPoint *extension_point,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
|
2014-04-10 15:26:45 +02:00
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
2010-01-12 11:36:12 +01:00
|
|
|
|
lazy_load_modules (extension_point);
|
2008-01-28 20:43:10 +01:00
|
|
|
|
for (l = extension_point->extensions; l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GIOExtension *e = l->data;
|
|
|
|
|
|
|
|
|
|
if (e->name != NULL &&
|
|
|
|
|
strcmp (e->name, name) == 0)
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
extension_prio_compare (gconstpointer a,
|
|
|
|
|
gconstpointer b)
|
|
|
|
|
{
|
|
|
|
|
const GIOExtension *extension_a = a, *extension_b = b;
|
|
|
|
|
|
2010-09-04 01:03:34 +02:00
|
|
|
|
if (extension_a->priority > extension_b->priority)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (extension_b->priority > extension_a->priority)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2008-01-28 20:43:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_point_implement:
|
|
|
|
|
* @extension_point_name: the name of the extension point
|
|
|
|
|
* @type: the #GType to register as extension
|
|
|
|
|
* @extension_name: the name for the extension
|
|
|
|
|
* @priority: the priority for the extension
|
|
|
|
|
*
|
|
|
|
|
* Registers @type as extension for the extension point with name
|
|
|
|
|
* @extension_point_name.
|
|
|
|
|
*
|
|
|
|
|
* If @type has already been registered as an extension for this
|
|
|
|
|
* extension point, the existing #GIOExtension object is returned.
|
|
|
|
|
*
|
2010-07-29 13:59:42 +02:00
|
|
|
|
* Returns: (transfer none): a #GIOExtension object for #GType
|
2008-02-11 08:12:56 +01:00
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
GIOExtension *
|
|
|
|
|
g_io_extension_point_implement (const char *extension_point_name,
|
2008-02-11 08:12:56 +01:00
|
|
|
|
GType type,
|
2008-01-28 20:43:10 +01:00
|
|
|
|
const char *extension_name,
|
2008-02-11 08:12:56 +01:00
|
|
|
|
gint priority)
|
2008-01-28 20:43:10 +01:00
|
|
|
|
{
|
|
|
|
|
GIOExtensionPoint *extension_point;
|
|
|
|
|
GIOExtension *extension;
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (extension_point_name != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
extension_point = g_io_extension_point_lookup (extension_point_name);
|
|
|
|
|
if (extension_point == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_warning ("Tried to implement non-registered extension point %s", extension_point_name);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (extension_point->required_type != 0 &&
|
|
|
|
|
!g_type_is_a (type, extension_point->required_type))
|
|
|
|
|
{
|
|
|
|
|
g_warning ("Tried to register an extension of the type %s to extension point %s. "
|
|
|
|
|
"Expected type is %s.",
|
|
|
|
|
g_type_name (type),
|
|
|
|
|
extension_point_name,
|
|
|
|
|
g_type_name (extension_point->required_type));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-23 05:30:06 +01:00
|
|
|
|
/* It's safe to register the same type multiple times */
|
2008-01-28 20:43:10 +01:00
|
|
|
|
for (l = extension_point->extensions; l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
extension = l->data;
|
|
|
|
|
if (extension->type == type)
|
|
|
|
|
return extension;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension = g_slice_new0 (GIOExtension);
|
|
|
|
|
extension->type = type;
|
|
|
|
|
extension->name = g_strdup (extension_name);
|
|
|
|
|
extension->priority = priority;
|
|
|
|
|
|
|
|
|
|
extension_point->extensions = g_list_insert_sorted (extension_point->extensions,
|
|
|
|
|
extension, extension_prio_compare);
|
|
|
|
|
|
|
|
|
|
return extension;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_ref_class:
|
|
|
|
|
* @extension: a #GIOExtension
|
|
|
|
|
*
|
|
|
|
|
* Gets a reference to the class for the type that is
|
|
|
|
|
* associated with @extension.
|
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
|
* Returns: (transfer full): the #GTypeClass for the type of @extension
|
2008-02-11 08:12:56 +01:00
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
GTypeClass *
|
|
|
|
|
g_io_extension_ref_class (GIOExtension *extension)
|
|
|
|
|
{
|
|
|
|
|
return g_type_class_ref (extension->type);
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_get_type:
|
|
|
|
|
* @extension: a #GIOExtension
|
|
|
|
|
*
|
|
|
|
|
* Gets the type associated with @extension.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the type of @extension
|
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
GType
|
|
|
|
|
g_io_extension_get_type (GIOExtension *extension)
|
|
|
|
|
{
|
|
|
|
|
return extension->type;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_get_name:
|
|
|
|
|
* @extension: a #GIOExtension
|
|
|
|
|
*
|
|
|
|
|
* Gets the name under which @extension was registered.
|
|
|
|
|
*
|
|
|
|
|
* Note that the same type may be registered as extension
|
|
|
|
|
* for multiple extension points, under different names.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the name of @extension.
|
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
const char *
|
|
|
|
|
g_io_extension_get_name (GIOExtension *extension)
|
|
|
|
|
{
|
|
|
|
|
return extension->name;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-11 08:12:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* g_io_extension_get_priority:
|
|
|
|
|
* @extension: a #GIOExtension
|
|
|
|
|
*
|
|
|
|
|
* Gets the priority with which @extension was registered.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the priority of @extension
|
|
|
|
|
*/
|
2008-01-28 20:43:10 +01:00
|
|
|
|
gint
|
|
|
|
|
g_io_extension_get_priority (GIOExtension *extension)
|
|
|
|
|
{
|
|
|
|
|
return extension->priority;
|
|
|
|
|
}
|