Blame gst/gstplugin.c

Packit a6ee4b
/* GStreamer
Packit a6ee4b
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
Packit a6ee4b
 *                    2000 Wim Taymans <wtay@chello.be>
Packit a6ee4b
 *
Packit a6ee4b
 * gstplugin.c: Plugin subsystem for loading elements, types, and libs
Packit a6ee4b
 *
Packit a6ee4b
 * This library is free software; you can redistribute it and/or
Packit a6ee4b
 * modify it under the terms of the GNU Library General Public
Packit a6ee4b
 * License as published by the Free Software Foundation; either
Packit a6ee4b
 * version 2 of the License, or (at your option) any later version.
Packit a6ee4b
 *
Packit a6ee4b
 * This library is distributed in the hope that it will be useful,
Packit a6ee4b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a6ee4b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a6ee4b
 * Library General Public License for more details.
Packit a6ee4b
 *
Packit a6ee4b
 * You should have received a copy of the GNU Library General Public
Packit a6ee4b
 * License along with this library; if not, write to the
Packit a6ee4b
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit a6ee4b
 * Boston, MA 02110-1301, USA.
Packit a6ee4b
 */
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * SECTION:gstplugin
Packit a6ee4b
 * @title: GstPlugin
Packit a6ee4b
 * @short_description: Container for features loaded from a shared object module
Packit a6ee4b
 * @see_also: #GstPluginFeature, #GstElementFactory
Packit a6ee4b
 *
Packit a6ee4b
 * GStreamer is extensible, so #GstElement instances can be loaded at runtime.
Packit a6ee4b
 * A plugin system can provide one or more of the basic
Packit a6ee4b
 * <application>GStreamer</application> #GstPluginFeature subclasses.
Packit a6ee4b
 *
Packit a6ee4b
 * A plugin should export a symbol <symbol>gst_plugin_desc</symbol> that is a
Packit a6ee4b
 * struct of type #GstPluginDesc.
Packit a6ee4b
 * the plugin loader will check the version of the core library the plugin was
Packit a6ee4b
 * linked against and will create a new #GstPlugin. It will then call the
Packit a6ee4b
 * #GstPluginInitFunc function that was provided in the
Packit a6ee4b
 * <symbol>gst_plugin_desc</symbol>.
Packit a6ee4b
 *
Packit a6ee4b
 * Once you have a handle to a #GstPlugin (e.g. from the #GstRegistry), you
Packit a6ee4b
 * can add any object that subclasses #GstPluginFeature.
Packit a6ee4b
 *
Packit a6ee4b
 * Usually plugins are always automatically loaded so you don't need to call
Packit a6ee4b
 * gst_plugin_load() explicitly to bring it into memory. There are options to
Packit a6ee4b
 * statically link plugins to an app or even use GStreamer without a plugin
Packit a6ee4b
 * repository in which case gst_plugin_load() can be needed to bring the plugin
Packit a6ee4b
 * into memory.
Packit a6ee4b
 */
Packit a6ee4b
Packit a6ee4b
#ifdef HAVE_CONFIG_H
Packit a6ee4b
#include "config.h"
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
#include "gst_private.h"
Packit a6ee4b
Packit a6ee4b
#include <glib/gstdio.h>
Packit a6ee4b
#include <sys/types.h>
Packit a6ee4b
#ifdef HAVE_DIRENT_H
Packit a6ee4b
#include <dirent.h>
Packit a6ee4b
#endif
Packit a6ee4b
#ifdef HAVE_UNISTD_H
Packit a6ee4b
#include <unistd.h>
Packit a6ee4b
#endif
Packit a6ee4b
#include <signal.h>
Packit a6ee4b
#include <errno.h>
Packit a6ee4b
#include <string.h>
Packit a6ee4b
Packit a6ee4b
#include "glib-compat-private.h"
Packit a6ee4b
Packit a6ee4b
#include <gst/gst.h>
Packit a6ee4b
Packit a6ee4b
#define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
Packit a6ee4b
Packit a6ee4b
static guint _num_static_plugins;       /* 0    */
Packit a6ee4b
static GstPluginDesc *_static_plugins;  /* NULL */
Packit a6ee4b
static gboolean _gst_plugin_inited;
Packit a6ee4b
static gchar **_plugin_loading_whitelist;       /* NULL */
Packit a6ee4b
Packit a6ee4b
/* static variables for segfault handling of plugin loading */
Packit a6ee4b
static char *_gst_plugin_fault_handler_filename = NULL;
Packit a6ee4b
Packit a6ee4b
/* list of valid licenses.
Packit a6ee4b
 * One of these must be specified or the plugin won't be loaded
Packit a6ee4b
 * Please file a bug to request any additional license be added.
Packit a6ee4b
 *
Packit a6ee4b
 * GPL: http://www.gnu.org/copyleft/gpl.html
Packit a6ee4b
 * LGPL: http://www.gnu.org/copyleft/lesser.html
Packit a6ee4b
 * QPL: http://www.trolltech.com/licenses/qpl.html
Packit a6ee4b
 * MPL: http://www.opensource.org/licenses/mozilla1.1.php
Packit a6ee4b
 * MIT/X11: http://www.opensource.org/licenses/mit-license.php
Packit a6ee4b
 * 3-clause BSD: https://opensource.org/licenses/BSD-3-Clause
Packit a6ee4b
 * Zero-Clause BSD: https://opensource.org/licenses/0BSD
Packit a6ee4b
 */
Packit a6ee4b
static const gchar valid_licenses[] = "LGPL\000"        /* GNU Lesser General Public License */
Packit a6ee4b
    "GPL\000"                   /* GNU General Public License */
Packit a6ee4b
    "QPL\000"                   /* Trolltech Qt Public License */
Packit a6ee4b
    "GPL/QPL\000"               /* Combi-license of GPL + QPL */
Packit a6ee4b
    "MPL\000"                   /* MPL 1.1 license */
Packit a6ee4b
    "BSD\000"                   /* 3-clause BSD license */
Packit a6ee4b
    "MIT/X11\000"               /* MIT/X11 license */
Packit a6ee4b
    "0BSD\000"                  /* Zero-Clause BSD */
Packit a6ee4b
    "Proprietary\000"           /* Proprietary license */
Packit a6ee4b
    GST_LICENSE_UNKNOWN;        /* some other license */
Packit a6ee4b
Packit a6ee4b
static const guint8 valid_licenses_idx[] = { 0, 5, 9, 13, 21, 25, 29, 37, 42,
Packit a6ee4b
  54
Packit a6ee4b
};
Packit a6ee4b
Packit a6ee4b
static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
Packit a6ee4b
    const GstPluginDesc * desc, gpointer user_data);
Packit a6ee4b
static void gst_plugin_desc_copy (GstPluginDesc * dest,
Packit a6ee4b
    const GstPluginDesc * src);
Packit a6ee4b
Packit a6ee4b
static void gst_plugin_ext_dep_free (GstPluginDep * dep);
Packit a6ee4b
Packit a6ee4b
G_DEFINE_TYPE_WITH_PRIVATE (GstPlugin, gst_plugin, GST_TYPE_OBJECT);
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_plugin_init (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  plugin->priv = gst_plugin_get_instance_private (plugin);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_plugin_finalize (GObject * object)
Packit a6ee4b
{
Packit a6ee4b
  GstPlugin *plugin = GST_PLUGIN_CAST (object);
Packit a6ee4b
Packit a6ee4b
  GST_DEBUG ("finalizing plugin %" GST_PTR_FORMAT, plugin);
Packit a6ee4b
Packit a6ee4b
  /* FIXME: make registry add a weak ref instead */
Packit a6ee4b
#if 0
Packit a6ee4b
  GstRegistry *registry = gst_registry_get ();
Packit a6ee4b
  GList *g;
Packit a6ee4b
  for (g = registry->plugins; g; g = g->next) {
Packit a6ee4b
    if (g->data == (gpointer) plugin) {
Packit a6ee4b
      g_warning ("removing plugin that is still in registry");
Packit a6ee4b
    }
Packit a6ee4b
  }
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
  g_free (plugin->filename);
Packit a6ee4b
  g_free (plugin->basename);
Packit a6ee4b
Packit a6ee4b
  g_list_foreach (plugin->priv->deps, (GFunc) gst_plugin_ext_dep_free, NULL);
Packit a6ee4b
  g_list_free (plugin->priv->deps);
Packit a6ee4b
  plugin->priv->deps = NULL;
Packit a6ee4b
Packit a6ee4b
  if (plugin->priv->cache_data) {
Packit a6ee4b
    gst_structure_free (plugin->priv->cache_data);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_plugin_class_init (GstPluginClass * klass)
Packit a6ee4b
{
Packit a6ee4b
  G_OBJECT_CLASS (klass)->finalize = gst_plugin_finalize;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GQuark
Packit a6ee4b
gst_plugin_error_quark (void)
Packit a6ee4b
{
Packit a6ee4b
  static GQuark quark = 0;
Packit a6ee4b
Packit a6ee4b
  if (!quark)
Packit a6ee4b
    quark = g_quark_from_static_string ("gst_plugin_error");
Packit a6ee4b
  return quark;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_register_static:
Packit a6ee4b
 * @major_version: the major version number of the GStreamer core that the
Packit a6ee4b
 *     plugin was compiled for, you can just use GST_VERSION_MAJOR here
Packit a6ee4b
 * @minor_version: the minor version number of the GStreamer core that the
Packit a6ee4b
 *     plugin was compiled for, you can just use GST_VERSION_MINOR here
Packit a6ee4b
 * @name: a unique name of the plugin (ideally prefixed with an application- or
Packit a6ee4b
 *     library-specific namespace prefix in order to avoid name conflicts in
Packit a6ee4b
 *     case a similar plugin with the same name ever gets added to GStreamer)
Packit a6ee4b
 * @description: description of the plugin
Packit a6ee4b
 * @init_func: (scope call): pointer to the init function of this plugin.
Packit a6ee4b
 * @version: version string of the plugin
Packit a6ee4b
 * @license: effective license of plugin. Must be one of the approved licenses
Packit a6ee4b
 *     (see #GstPluginDesc above) or the plugin will not be registered.
Packit a6ee4b
 * @source: source module plugin belongs to
Packit a6ee4b
 * @package: shipped package plugin belongs to
Packit a6ee4b
 * @origin: URL to provider of plugin
Packit a6ee4b
 *
Packit a6ee4b
 * Registers a static plugin, ie. a plugin which is private to an application
Packit a6ee4b
 * or library and contained within the application or library (as opposed to
Packit a6ee4b
 * being shipped as a separate module file).
Packit a6ee4b
 *
Packit a6ee4b
 * You must make sure that GStreamer has been initialised (with gst_init() or
Packit a6ee4b
 * via gst_init_get_option_group()) before calling this function.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
Packit a6ee4b
 */
Packit a6ee4b
gboolean
Packit a6ee4b
gst_plugin_register_static (gint major_version, gint minor_version,
Packit a6ee4b
    const gchar * name, const gchar * description, GstPluginInitFunc init_func,
Packit a6ee4b
    const gchar * version, const gchar * license, const gchar * source,
Packit a6ee4b
    const gchar * package, const gchar * origin)
Packit a6ee4b
{
Packit a6ee4b
  GstPluginDesc desc = { major_version, minor_version, name, description,
Packit a6ee4b
    init_func, version, license, source, package, origin, NULL,
Packit a6ee4b
  };
Packit a6ee4b
  GstPlugin *plugin;
Packit a6ee4b
  gboolean res = FALSE;
Packit a6ee4b
Packit a6ee4b
  g_return_val_if_fail (name != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (description != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (init_func != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (version != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (license != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (source != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (package != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (origin != NULL, FALSE);
Packit a6ee4b
Packit a6ee4b
  /* make sure gst_init() has been called */
Packit a6ee4b
  g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
Packit a6ee4b
Packit a6ee4b
  GST_LOG ("attempting to load static plugin \"%s\" now...", name);
Packit a6ee4b
  plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
Packit a6ee4b
  if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) {
Packit a6ee4b
    GST_INFO ("registered static plugin \"%s\"", name);
Packit a6ee4b
    res = gst_registry_add_plugin (gst_registry_get (), plugin);
Packit a6ee4b
    GST_INFO ("added static plugin \"%s\", result: %d", name, res);
Packit a6ee4b
  }
Packit a6ee4b
  return res;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_register_static_full:
Packit a6ee4b
 * @major_version: the major version number of the GStreamer core that the
Packit a6ee4b
 *     plugin was compiled for, you can just use GST_VERSION_MAJOR here
Packit a6ee4b
 * @minor_version: the minor version number of the GStreamer core that the
Packit a6ee4b
 *     plugin was compiled for, you can just use GST_VERSION_MINOR here
Packit a6ee4b
 * @name: a unique name of the plugin (ideally prefixed with an application- or
Packit a6ee4b
 *     library-specific namespace prefix in order to avoid name conflicts in
Packit a6ee4b
 *     case a similar plugin with the same name ever gets added to GStreamer)
Packit a6ee4b
 * @description: description of the plugin
Packit a6ee4b
 * @init_full_func: (scope call): pointer to the init function with user data
Packit a6ee4b
 *     of this plugin.
Packit a6ee4b
 * @version: version string of the plugin
Packit a6ee4b
 * @license: effective license of plugin. Must be one of the approved licenses
Packit a6ee4b
 *     (see #GstPluginDesc above) or the plugin will not be registered.
Packit a6ee4b
 * @source: source module plugin belongs to
Packit a6ee4b
 * @package: shipped package plugin belongs to
Packit a6ee4b
 * @origin: URL to provider of plugin
Packit a6ee4b
 * @user_data: gpointer to user data
Packit a6ee4b
 *
Packit a6ee4b
 * Registers a static plugin, ie. a plugin which is private to an application
Packit a6ee4b
 * or library and contained within the application or library (as opposed to
Packit a6ee4b
 * being shipped as a separate module file) with a #GstPluginInitFullFunc
Packit a6ee4b
 * which allows user data to be passed to the callback function (useful
Packit a6ee4b
 * for bindings).
Packit a6ee4b
 *
Packit a6ee4b
 * You must make sure that GStreamer has been initialised (with gst_init() or
Packit a6ee4b
 * via gst_init_get_option_group()) before calling this function.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
Packit a6ee4b
 */
Packit a6ee4b
gboolean
Packit a6ee4b
gst_plugin_register_static_full (gint major_version, gint minor_version,
Packit a6ee4b
    const gchar * name, const gchar * description,
Packit a6ee4b
    GstPluginInitFullFunc init_full_func, const gchar * version,
Packit a6ee4b
    const gchar * license, const gchar * source, const gchar * package,
Packit a6ee4b
    const gchar * origin, gpointer user_data)
Packit a6ee4b
{
Packit a6ee4b
  GstPluginDesc desc = { major_version, minor_version, name, description,
Packit a6ee4b
    (GstPluginInitFunc) init_full_func, version, license, source, package,
Packit a6ee4b
    origin, NULL,
Packit a6ee4b
  };
Packit a6ee4b
  GstPlugin *plugin;
Packit a6ee4b
  gboolean res = FALSE;
Packit a6ee4b
Packit a6ee4b
  g_return_val_if_fail (name != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (description != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (init_full_func != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (version != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (license != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (source != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (package != NULL, FALSE);
Packit a6ee4b
  g_return_val_if_fail (origin != NULL, FALSE);
Packit a6ee4b
Packit a6ee4b
  /* make sure gst_init() has been called */
Packit a6ee4b
  g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
Packit a6ee4b
Packit a6ee4b
  GST_LOG ("attempting to load static plugin \"%s\" now...", name);
Packit a6ee4b
  plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
Packit a6ee4b
  if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) {
Packit a6ee4b
    GST_INFO ("registered static plugin \"%s\"", name);
Packit a6ee4b
    res = gst_registry_add_plugin (gst_registry_get (), plugin);
Packit a6ee4b
    GST_INFO ("added static plugin \"%s\", result: %d", name, res);
Packit a6ee4b
  }
Packit a6ee4b
  return res;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
void
Packit a6ee4b
_priv_gst_plugin_initialize (void)
Packit a6ee4b
{
Packit a6ee4b
  const gchar *whitelist;
Packit a6ee4b
  guint i;
Packit a6ee4b
Packit a6ee4b
  _gst_plugin_inited = TRUE;
Packit a6ee4b
Packit a6ee4b
  whitelist = g_getenv ("GST_PLUGIN_LOADING_WHITELIST");
Packit a6ee4b
  if (whitelist != NULL && *whitelist != '\0') {
Packit a6ee4b
    _plugin_loading_whitelist = g_strsplit (whitelist,
Packit a6ee4b
        G_SEARCHPATH_SEPARATOR_S, -1);
Packit a6ee4b
    for (i = 0; _plugin_loading_whitelist[i] != NULL; ++i) {
Packit a6ee4b
      GST_INFO ("plugins whitelist entry: %s", _plugin_loading_whitelist[i]);
Packit a6ee4b
    }
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  /* now register all static plugins */
Packit a6ee4b
  GST_INFO ("registering %u static plugins", _num_static_plugins);
Packit a6ee4b
  for (i = 0; i < _num_static_plugins; ++i) {
Packit a6ee4b
    gst_plugin_register_static (_static_plugins[i].major_version,
Packit a6ee4b
        _static_plugins[i].minor_version, _static_plugins[i].name,
Packit a6ee4b
        _static_plugins[i].description, _static_plugins[i].plugin_init,
Packit a6ee4b
        _static_plugins[i].version, _static_plugins[i].license,
Packit a6ee4b
        _static_plugins[i].source, _static_plugins[i].package,
Packit a6ee4b
        _static_plugins[i].origin);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (_static_plugins) {
Packit a6ee4b
    free (_static_plugins);
Packit a6ee4b
    _static_plugins = NULL;
Packit a6ee4b
    _num_static_plugins = 0;
Packit a6ee4b
  }
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/* Whitelist entry format:
Packit a6ee4b
 *
Packit a6ee4b
 *   plugin1,plugin2@pathprefix or
Packit a6ee4b
 *   plugin1,plugin2@* or just
Packit a6ee4b
 *   plugin1,plugin2 or
Packit a6ee4b
 *   source-package@pathprefix or
Packit a6ee4b
 *   source-package@* or just
Packit a6ee4b
 *   source-package
Packit a6ee4b
 *
Packit a6ee4b
 * ie. the bit before the path will be checked against both the plugin
Packit a6ee4b
 * name and the plugin's source package name, to keep the format simple.
Packit a6ee4b
 */
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_plugin_desc_matches_whitelist_entry (const GstPluginDesc * desc,
Packit a6ee4b
    const gchar * filename, const gchar * pattern)
Packit a6ee4b
{
Packit a6ee4b
  const gchar *sep;
Packit a6ee4b
  gboolean ret = FALSE;
Packit a6ee4b
  gchar *name;
Packit a6ee4b
Packit a6ee4b
  GST_LOG ("Whitelist pattern '%s', plugin: %s of %s@%s", pattern, desc->name,
Packit a6ee4b
      desc->source, GST_STR_NULL (filename));
Packit a6ee4b
Packit a6ee4b
  /* do we have a path prefix? */
Packit a6ee4b
  sep = strchr (pattern, '@');
Packit a6ee4b
  if (sep != NULL && strcmp (sep, "@*") != 0 && strcmp (sep, "@") != 0) {
Packit a6ee4b
    /* paths are not canonicalised or treated with realpath() here. This
Packit a6ee4b
     * should be good enough for our use case, since we just use the paths
Packit a6ee4b
     * autotools uses, and those will be constructed from the same prefix. */
Packit a6ee4b
    if (filename != NULL && !g_str_has_prefix (filename, sep + 1))
Packit a6ee4b
      return FALSE;
Packit a6ee4b
Packit a6ee4b
    GST_LOG ("%s matches path prefix %s", GST_STR_NULL (filename), sep + 1);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (sep != NULL) {
Packit a6ee4b
    name = g_strndup (pattern, (gsize) (sep - pattern));
Packit a6ee4b
  } else {
Packit a6ee4b
    name = g_strdup (pattern);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  g_strstrip (name);
Packit a6ee4b
  if (!g_ascii_isalnum (*name)) {
Packit a6ee4b
    GST_WARNING ("Invalid whitelist pattern: %s", pattern);
Packit a6ee4b
    goto done;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  /* now check plugin names / source package name */
Packit a6ee4b
  if (strchr (name, ',') == NULL) {
Packit a6ee4b
    /* only a single name: either a plugin name or the source package name */
Packit a6ee4b
    ret = (strcmp (desc->source, name) == 0 || strcmp (desc->name, name) == 0);
Packit a6ee4b
  } else {
Packit a6ee4b
    gchar **n, **names;
Packit a6ee4b
Packit a6ee4b
    /* multiple names: assume these are plugin names */
Packit a6ee4b
    names = g_strsplit (name, ",", -1);
Packit a6ee4b
    for (n = names; n != NULL && *n != NULL; ++n) {
Packit a6ee4b
      g_strstrip (*n);
Packit a6ee4b
      if (strcmp (desc->name, *n) == 0) {
Packit a6ee4b
        ret = TRUE;
Packit a6ee4b
        break;
Packit a6ee4b
      }
Packit a6ee4b
    }
Packit a6ee4b
    g_strfreev (names);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  GST_LOG ("plugin / source package name match: %d", ret);
Packit a6ee4b
Packit a6ee4b
done:
Packit a6ee4b
Packit a6ee4b
  g_free (name);
Packit a6ee4b
  return ret;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
gboolean
Packit a6ee4b
priv_gst_plugin_desc_is_whitelisted (const GstPluginDesc * desc,
Packit a6ee4b
    const gchar * filename)
Packit a6ee4b
{
Packit a6ee4b
  gchar **entry;
Packit a6ee4b
Packit a6ee4b
  if (_plugin_loading_whitelist == NULL)
Packit a6ee4b
    return TRUE;
Packit a6ee4b
Packit a6ee4b
  for (entry = _plugin_loading_whitelist; *entry != NULL; ++entry) {
Packit a6ee4b
    if (gst_plugin_desc_matches_whitelist_entry (desc, filename, *entry)) {
Packit a6ee4b
      GST_LOG ("Plugin %s is in whitelist", filename);
Packit a6ee4b
      return TRUE;
Packit a6ee4b
    }
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  GST_LOG ("Plugin %s (package %s, file %s) not in whitelist", desc->name,
Packit a6ee4b
      desc->source, filename);
Packit a6ee4b
  return FALSE;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
gboolean
Packit a6ee4b
priv_gst_plugin_loading_have_whitelist (void)
Packit a6ee4b
{
Packit a6ee4b
  return (_plugin_loading_whitelist != NULL);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
guint32
Packit a6ee4b
priv_gst_plugin_loading_get_whitelist_hash (void)
Packit a6ee4b
{
Packit a6ee4b
  guint32 hash = 0;
Packit a6ee4b
Packit a6ee4b
  if (_plugin_loading_whitelist != NULL) {
Packit a6ee4b
    gchar **w;
Packit a6ee4b
Packit a6ee4b
    for (w = _plugin_loading_whitelist; *w != NULL; ++w)
Packit a6ee4b
      hash ^= g_str_hash (*w);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return hash;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/* this function could be extended to check if the plugin license matches the
Packit a6ee4b
 * applications license (would require the app to register its license somehow).
Packit a6ee4b
 * We'll wait for someone who's interested in it to code it :)
Packit a6ee4b
 */
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_plugin_check_license (const gchar * license)
Packit a6ee4b
{
Packit a6ee4b
  gint i;
Packit a6ee4b
Packit a6ee4b
  for (i = 0; i < G_N_ELEMENTS (valid_licenses_idx); ++i) {
Packit a6ee4b
    if (strcmp (license, valid_licenses + valid_licenses_idx[i]) == 0)
Packit a6ee4b
      return TRUE;
Packit a6ee4b
  }
Packit a6ee4b
  return FALSE;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_plugin_check_version (gint major, gint minor)
Packit a6ee4b
{
Packit a6ee4b
  /* return NULL if the major and minor version numbers are not compatible */
Packit a6ee4b
  /* with ours. */
Packit a6ee4b
  if (major != GST_VERSION_MAJOR || minor > GST_VERSION_MINOR)
Packit a6ee4b
    return FALSE;
Packit a6ee4b
Packit a6ee4b
  return TRUE;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static GstPlugin *
Packit a6ee4b
gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc,
Packit a6ee4b
    gpointer user_data)
Packit a6ee4b
{
Packit a6ee4b
  if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
Packit a6ee4b
    if (GST_CAT_DEFAULT)
Packit a6ee4b
      GST_WARNING ("plugin \"%s\" has incompatible version "
Packit a6ee4b
          "(plugin: %d.%d, gst: %d,%d), not loading",
Packit a6ee4b
          GST_STR_NULL (plugin->filename), desc->major_version,
Packit a6ee4b
          desc->minor_version, GST_VERSION_MAJOR, GST_VERSION_MINOR);
Packit a6ee4b
    return NULL;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (!desc->license || !desc->description || !desc->source ||
Packit a6ee4b
      !desc->package || !desc->origin) {
Packit a6ee4b
    if (GST_CAT_DEFAULT)
Packit a6ee4b
      GST_WARNING ("plugin \"%s\" has missing detail in GstPluginDesc, not "
Packit a6ee4b
          "loading", GST_STR_NULL (plugin->filename));
Packit a6ee4b
    return NULL;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (!gst_plugin_check_license (desc->license)) {
Packit a6ee4b
    if (GST_CAT_DEFAULT)
Packit a6ee4b
      GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
Packit a6ee4b
          GST_STR_NULL (plugin->filename), desc->license);
Packit a6ee4b
    return NULL;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (GST_CAT_DEFAULT)
Packit a6ee4b
    GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));
Packit a6ee4b
Packit a6ee4b
  gst_plugin_desc_copy (&plugin->desc, desc);
Packit a6ee4b
Packit a6ee4b
  /* make resident so we're really sure it never gets unloaded again.
Packit a6ee4b
   * Theoretically this is not needed, but practically it doesn't hurt.
Packit a6ee4b
   * And we're rather safe than sorry. */
Packit a6ee4b
  if (plugin->module)
Packit a6ee4b
    g_module_make_resident (plugin->module);
Packit a6ee4b
Packit a6ee4b
  if (user_data) {
Packit a6ee4b
    if (!(((GstPluginInitFullFunc) (desc->plugin_init)) (plugin, user_data))) {
Packit a6ee4b
      if (GST_CAT_DEFAULT)
Packit a6ee4b
        GST_WARNING ("plugin \"%s\" failed to initialise",
Packit a6ee4b
            GST_STR_NULL (plugin->filename));
Packit a6ee4b
      return NULL;
Packit a6ee4b
    }
Packit a6ee4b
  } else {
Packit a6ee4b
    if (!((desc->plugin_init) (plugin))) {
Packit a6ee4b
      if (GST_CAT_DEFAULT)
Packit a6ee4b
        GST_WARNING ("plugin \"%s\" failed to initialise",
Packit a6ee4b
            GST_STR_NULL (plugin->filename));
Packit a6ee4b
      return NULL;
Packit a6ee4b
    }
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (GST_CAT_DEFAULT)
Packit a6ee4b
    GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
Packit a6ee4b
Packit a6ee4b
  return plugin;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
#ifdef HAVE_SIGACTION
Packit a6ee4b
static struct sigaction oldaction;
Packit a6ee4b
static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
Packit a6ee4b
Packit a6ee4b
/*
Packit a6ee4b
 * _gst_plugin_fault_handler_restore:
Packit a6ee4b
 * segfault handler restorer
Packit a6ee4b
 */
Packit a6ee4b
static void
Packit a6ee4b
_gst_plugin_fault_handler_restore (void)
Packit a6ee4b
{
Packit a6ee4b
  if (!_gst_plugin_fault_handler_is_setup)
Packit a6ee4b
    return;
Packit a6ee4b
Packit a6ee4b
  _gst_plugin_fault_handler_is_setup = FALSE;
Packit a6ee4b
Packit a6ee4b
  sigaction (SIGSEGV, &oldaction, NULL);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/*
Packit a6ee4b
 * _gst_plugin_fault_handler_sighandler:
Packit a6ee4b
 * segfault handler implementation
Packit a6ee4b
 */
Packit a6ee4b
static void
Packit a6ee4b
_gst_plugin_fault_handler_sighandler (int signum)
Packit a6ee4b
{
Packit a6ee4b
  /* We need to restore the fault handler or we'll keep getting it */
Packit a6ee4b
  _gst_plugin_fault_handler_restore ();
Packit a6ee4b
Packit a6ee4b
  switch (signum) {
Packit a6ee4b
    case SIGSEGV:
Packit a6ee4b
      g_print ("\nERROR: ");
Packit a6ee4b
      g_print ("Caught a segmentation fault while loading plugin file:\n");
Packit a6ee4b
      g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
Packit a6ee4b
      g_print ("Please either:\n");
Packit a6ee4b
      g_print ("- remove it and restart.\n");
Packit a6ee4b
      g_print
Packit a6ee4b
          ("- run with --gst-disable-segtrap --gst-disable-registry-fork and debug.\n");
Packit a6ee4b
      exit (-1);
Packit a6ee4b
      break;
Packit a6ee4b
    default:
Packit a6ee4b
      g_print ("Caught unhandled signal on plugin loading\n");
Packit a6ee4b
      break;
Packit a6ee4b
  }
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/*
Packit a6ee4b
 * _gst_plugin_fault_handler_setup:
Packit a6ee4b
 * sets up the segfault handler
Packit a6ee4b
 */
Packit a6ee4b
static void
Packit a6ee4b
_gst_plugin_fault_handler_setup (void)
Packit a6ee4b
{
Packit a6ee4b
  struct sigaction action;
Packit a6ee4b
Packit a6ee4b
  /* if asked to leave segfaults alone, just return */
Packit a6ee4b
  if (!gst_segtrap_is_enabled ())
Packit a6ee4b
    return;
Packit a6ee4b
Packit a6ee4b
  if (_gst_plugin_fault_handler_is_setup)
Packit a6ee4b
    return;
Packit a6ee4b
Packit a6ee4b
  _gst_plugin_fault_handler_is_setup = TRUE;
Packit a6ee4b
Packit a6ee4b
  memset (&action, 0, sizeof (action));
Packit a6ee4b
  action.sa_handler = _gst_plugin_fault_handler_sighandler;
Packit a6ee4b
Packit a6ee4b
  sigaction (SIGSEGV, &action, &oldaction);
Packit a6ee4b
}
Packit a6ee4b
#else /* !HAVE_SIGACTION */
Packit a6ee4b
static void
Packit a6ee4b
_gst_plugin_fault_handler_restore (void)
Packit a6ee4b
{
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
_gst_plugin_fault_handler_setup (void)
Packit a6ee4b
{
Packit a6ee4b
}
Packit a6ee4b
#endif /* HAVE_SIGACTION */
Packit a6ee4b
Packit a6ee4b
/* g_time_val_from_iso8601() doesn't do quite what we want */
Packit a6ee4b
static gboolean
Packit a6ee4b
check_release_datetime (const gchar * date_time)
Packit a6ee4b
{
Packit a6ee4b
  guint64 val;
Packit a6ee4b
Packit a6ee4b
  /* we require YYYY-MM-DD or YYYY-MM-DDTHH:MMZ format */
Packit a6ee4b
  if (!g_ascii_isdigit (*date_time))
Packit a6ee4b
    return FALSE;
Packit a6ee4b
Packit a6ee4b
  val = g_ascii_strtoull (date_time, (gchar **) & date_time, 10);
Packit a6ee4b
  if (val < 2000 || val > 2100 || *date_time != '-')
Packit a6ee4b
    return FALSE;
Packit a6ee4b
Packit a6ee4b
  val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
Packit a6ee4b
  if (val == 0 || val > 12 || *date_time != '-')
Packit a6ee4b
    return FALSE;
Packit a6ee4b
Packit a6ee4b
  val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
Packit a6ee4b
  if (val == 0 || val > 32)
Packit a6ee4b
    return FALSE;
Packit a6ee4b
Packit a6ee4b
  /* end of string or date/time separator + HH:MMZ */
Packit a6ee4b
  if (*date_time == 'T' || *date_time == ' ') {
Packit a6ee4b
    val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
Packit a6ee4b
    if (val > 24 || *date_time != ':')
Packit a6ee4b
      return FALSE;
Packit a6ee4b
Packit a6ee4b
    val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
Packit a6ee4b
    if (val > 59 || *date_time != 'Z')
Packit a6ee4b
      return FALSE;
Packit a6ee4b
Packit a6ee4b
    ++date_time;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return (*date_time == '\0');
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static GMutex gst_plugin_loading_mutex;
Packit a6ee4b
Packit a6ee4b
#define CHECK_PLUGIN_DESC_FIELD(desc,field,fn)                               \
Packit a6ee4b
  if (G_UNLIKELY ((desc)->field == NULL || *(desc)->field == '\0')) {        \
Packit a6ee4b
    g_warning ("Plugin description for '%s' has no valid %s field", fn, G_STRINGIFY (field)); \
Packit a6ee4b
    g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, \
Packit a6ee4b
        "Plugin %s has invalid plugin description field '%s'", \
Packit a6ee4b
        filename, G_STRINGIFY (field)); \
Packit a6ee4b
    goto return_error;                                                       \
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_load_file:
Packit a6ee4b
 * @filename: (type filename): the plugin filename to load
Packit a6ee4b
 * @error: pointer to a %NULL-valued GError
Packit a6ee4b
 *
Packit a6ee4b
 * Loads the given plugin and refs it.  Caller needs to unref after use.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: (transfer full): a reference to the existing loaded GstPlugin, a
Packit a6ee4b
 * reference to the newly-loaded GstPlugin, or %NULL if an error occurred.
Packit a6ee4b
 */
Packit a6ee4b
GstPlugin *
Packit a6ee4b
gst_plugin_load_file (const gchar * filename, GError ** error)
Packit a6ee4b
{
Packit a6ee4b
  return _priv_gst_plugin_load_file_for_registry (filename, NULL, error);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static gchar *
Packit a6ee4b
extract_symname (const char *filename)
Packit a6ee4b
{
Packit a6ee4b
  gchar *bname, *name, *symname;
Packit a6ee4b
  const gchar *dot;
Packit a6ee4b
  gsize prefix_len, len;
Packit a6ee4b
  int i;
Packit a6ee4b
Packit a6ee4b
  bname = g_path_get_basename (filename);
Packit a6ee4b
  for (i = 0; bname[i]; ++i) {
Packit a6ee4b
    if (bname[i] == '-')
Packit a6ee4b
      bname[i] = '_';
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (g_str_has_prefix (bname, "libgst"))
Packit a6ee4b
    prefix_len = 6;
Packit a6ee4b
  else if (g_str_has_prefix (bname, "lib"))
Packit a6ee4b
    prefix_len = 3;
Packit a6ee4b
  else if (g_str_has_prefix (bname, "gst"))
Packit a6ee4b
    prefix_len = 3;
Packit a6ee4b
  else
Packit a6ee4b
    prefix_len = 0;             /* use whole name (minus suffix) as plugin name */
Packit a6ee4b
Packit a6ee4b
  dot = g_utf8_strchr (bname, -1, '.');
Packit a6ee4b
  if (dot)
Packit a6ee4b
    len = dot - bname - prefix_len;
Packit a6ee4b
  else
Packit a6ee4b
    len = strlen (bname + prefix_len);
Packit a6ee4b
Packit a6ee4b
  name = g_strndup (bname + prefix_len, len);
Packit a6ee4b
  g_free (bname);
Packit a6ee4b
Packit a6ee4b
  symname = g_strconcat ("gst_plugin_", name, "_get_desc", NULL);
Packit a6ee4b
  g_free (name);
Packit a6ee4b
Packit a6ee4b
  return symname;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/* Note: The return value is (transfer full) although we work with floating
Packit a6ee4b
 * references here. If a new plugin instance is created, it is always sinked
Packit a6ee4b
 * in the registry first and a new reference is returned
Packit a6ee4b
 */
Packit a6ee4b
GstPlugin *
Packit a6ee4b
_priv_gst_plugin_load_file_for_registry (const gchar * filename,
Packit a6ee4b
    GstRegistry * registry, GError ** error)
Packit a6ee4b
{
Packit a6ee4b
  const GstPluginDesc *desc;
Packit a6ee4b
  GstPlugin *plugin;
Packit a6ee4b
  gchar *symname;
Packit a6ee4b
  GModule *module;
Packit a6ee4b
  gboolean ret;
Packit a6ee4b
  gpointer ptr;
Packit a6ee4b
  GStatBuf file_status;
Packit a6ee4b
  gboolean new_plugin = TRUE;
Packit a6ee4b
  GModuleFlags flags;
Packit a6ee4b
Packit a6ee4b
  g_return_val_if_fail (filename != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  if (registry == NULL)
Packit a6ee4b
    registry = gst_registry_get ();
Packit a6ee4b
Packit a6ee4b
  g_mutex_lock (&gst_plugin_loading_mutex);
Packit a6ee4b
Packit a6ee4b
  plugin = gst_registry_lookup (registry, filename);
Packit a6ee4b
  if (plugin) {
Packit a6ee4b
    if (plugin->module) {
Packit a6ee4b
      /* already loaded */
Packit a6ee4b
      g_mutex_unlock (&gst_plugin_loading_mutex);
Packit a6ee4b
      return plugin;
Packit a6ee4b
    } else {
Packit a6ee4b
      /* load plugin and update fields */
Packit a6ee4b
      new_plugin = FALSE;
Packit a6ee4b
    }
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
Packit a6ee4b
      filename);
Packit a6ee4b
Packit a6ee4b
  if (!g_module_supported ()) {
Packit a6ee4b
    GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
Packit a6ee4b
    g_set_error (error,
Packit a6ee4b
        GST_PLUGIN_ERROR,
Packit a6ee4b
        GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
Packit a6ee4b
    goto return_error;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (g_stat (filename, &file_status)) {
Packit a6ee4b
    GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
Packit a6ee4b
    g_set_error (error,
Packit a6ee4b
        GST_PLUGIN_ERROR,
Packit a6ee4b
        GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
Packit a6ee4b
        g_strerror (errno));
Packit a6ee4b
    goto return_error;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  flags = G_MODULE_BIND_LOCAL;
Packit a6ee4b
  /* libgstpython.so is the gst-python plugin loader. It needs to be loaded with
Packit a6ee4b
   * G_MODULE_BIND_LAZY.
Packit a6ee4b
   *
Packit a6ee4b
   * Ideally there should be a generic way for plugins to specify that they
Packit a6ee4b
   * need to be loaded with _LAZY.
Packit a6ee4b
   * */
Packit a6ee4b
  if (strstr (filename, "libgstpython"))
Packit a6ee4b
    flags |= G_MODULE_BIND_LAZY;
Packit a6ee4b
Packit a6ee4b
  module = g_module_open (filename, flags);
Packit a6ee4b
  if (module == NULL) {
Packit a6ee4b
    GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
Packit a6ee4b
        g_module_error ());
Packit a6ee4b
    g_set_error (error,
Packit a6ee4b
        GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
Packit a6ee4b
        g_module_error ());
Packit a6ee4b
    /* If we failed to open the shared object, then it's probably because a
Packit a6ee4b
     * plugin is linked against the wrong libraries. Print out an easy-to-see
Packit a6ee4b
     * message in this case. */
Packit a6ee4b
    g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
Packit a6ee4b
    goto return_error;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  symname = extract_symname (filename);
Packit a6ee4b
  ret = g_module_symbol (module, symname, &ptr);
Packit a6ee4b
Packit a6ee4b
  if (ret) {
Packit a6ee4b
    GstPluginDesc *(*get_desc) (void) = ptr;
Packit a6ee4b
    ptr = get_desc ();
Packit a6ee4b
  } else {
Packit a6ee4b
    GST_DEBUG ("Could not find symbol '%s', falling back to gst_plugin_desc",
Packit a6ee4b
        symname);
Packit a6ee4b
    ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  g_free (symname);
Packit a6ee4b
Packit a6ee4b
  if (!ret) {
Packit a6ee4b
    GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
Packit a6ee4b
    g_set_error (error,
Packit a6ee4b
        GST_PLUGIN_ERROR,
Packit a6ee4b
        GST_PLUGIN_ERROR_MODULE,
Packit a6ee4b
        "File \"%s\" is not a GStreamer plugin", filename);
Packit a6ee4b
    g_module_close (module);
Packit a6ee4b
    goto return_error;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  desc = (const GstPluginDesc *) ptr;
Packit a6ee4b
Packit a6ee4b
  if (priv_gst_plugin_loading_have_whitelist () &&
Packit a6ee4b
      !priv_gst_plugin_desc_is_whitelisted (desc, filename)) {
Packit a6ee4b
    GST_INFO ("Whitelist specified and plugin not in whitelist, not loading: "
Packit a6ee4b
        "name=%s, package=%s, file=%s", desc->name, desc->source, filename);
Packit a6ee4b
    g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
Packit a6ee4b
        "Not loading plugin file \"%s\", not in whitelist", filename);
Packit a6ee4b
    g_module_close (module);
Packit a6ee4b
    goto return_error;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (new_plugin) {
Packit a6ee4b
    plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
Packit a6ee4b
    plugin->file_mtime = file_status.st_mtime;
Packit a6ee4b
    plugin->file_size = file_status.st_size;
Packit a6ee4b
    plugin->filename = g_strdup (filename);
Packit a6ee4b
    plugin->basename = g_path_get_basename (filename);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  plugin->module = module;
Packit a6ee4b
Packit a6ee4b
  if (new_plugin) {
Packit a6ee4b
    /* check plugin description: complain about bad values and fail */
Packit a6ee4b
    CHECK_PLUGIN_DESC_FIELD (desc, name, filename);
Packit a6ee4b
    CHECK_PLUGIN_DESC_FIELD (desc, description, filename);
Packit a6ee4b
    CHECK_PLUGIN_DESC_FIELD (desc, version, filename);
Packit a6ee4b
    CHECK_PLUGIN_DESC_FIELD (desc, license, filename);
Packit a6ee4b
    CHECK_PLUGIN_DESC_FIELD (desc, source, filename);
Packit a6ee4b
    CHECK_PLUGIN_DESC_FIELD (desc, package, filename);
Packit a6ee4b
    CHECK_PLUGIN_DESC_FIELD (desc, origin, filename);
Packit a6ee4b
Packit a6ee4b
    if (desc->name != NULL && desc->name[0] == '"') {
Packit a6ee4b
      g_warning ("Invalid plugin name '%s' - fix your GST_PLUGIN_DEFINE "
Packit a6ee4b
          "(remove quotes around plugin name)", desc->name);
Packit a6ee4b
    }
Packit a6ee4b
Packit a6ee4b
    if (desc->release_datetime != NULL &&
Packit a6ee4b
        !check_release_datetime (desc->release_datetime)) {
Packit a6ee4b
      g_warning ("GstPluginDesc for '%s' has invalid datetime '%s'",
Packit a6ee4b
          filename, desc->release_datetime);
Packit a6ee4b
      g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
Packit a6ee4b
          "Plugin %s has invalid plugin description field 'release_datetime'",
Packit a6ee4b
          filename);
Packit a6ee4b
      goto return_error;
Packit a6ee4b
    }
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
Packit a6ee4b
      plugin, filename);
Packit a6ee4b
Packit a6ee4b
  /* this is where we load the actual .so, so let's trap SIGSEGV */
Packit a6ee4b
  _gst_plugin_fault_handler_setup ();
Packit a6ee4b
  _gst_plugin_fault_handler_filename = plugin->filename;
Packit a6ee4b
Packit a6ee4b
  GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
Packit a6ee4b
      plugin, filename);
Packit a6ee4b
Packit a6ee4b
  if (!gst_plugin_register_func (plugin, desc, NULL)) {
Packit a6ee4b
    /* remove signal handler */
Packit a6ee4b
    _gst_plugin_fault_handler_restore ();
Packit a6ee4b
    GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
Packit a6ee4b
    /* plugin == NULL */
Packit a6ee4b
    g_set_error (error,
Packit a6ee4b
        GST_PLUGIN_ERROR,
Packit a6ee4b
        GST_PLUGIN_ERROR_MODULE,
Packit a6ee4b
        "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
Packit a6ee4b
        filename);
Packit a6ee4b
    goto return_error;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  /* remove signal handler */
Packit a6ee4b
  _gst_plugin_fault_handler_restore ();
Packit a6ee4b
  _gst_plugin_fault_handler_filename = NULL;
Packit a6ee4b
  GST_INFO ("plugin \"%s\" loaded", plugin->filename);
Packit a6ee4b
Packit a6ee4b
  if (new_plugin) {
Packit a6ee4b
    gst_object_ref (plugin);
Packit a6ee4b
    gst_registry_add_plugin (registry, plugin);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  g_mutex_unlock (&gst_plugin_loading_mutex);
Packit a6ee4b
  return plugin;
Packit a6ee4b
Packit a6ee4b
return_error:
Packit a6ee4b
  {
Packit a6ee4b
    if (plugin)
Packit a6ee4b
      gst_object_unref (plugin);
Packit a6ee4b
    g_mutex_unlock (&gst_plugin_loading_mutex);
Packit a6ee4b
    return NULL;
Packit a6ee4b
  }
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
Packit a6ee4b
{
Packit a6ee4b
  dest->major_version = src->major_version;
Packit a6ee4b
  dest->minor_version = src->minor_version;
Packit a6ee4b
  dest->name = g_intern_string (src->name);
Packit a6ee4b
  dest->description = g_intern_string (src->description);
Packit a6ee4b
  dest->plugin_init = src->plugin_init;
Packit a6ee4b
  dest->version = g_intern_string (src->version);
Packit a6ee4b
  dest->license = g_intern_string (src->license);
Packit a6ee4b
  dest->source = g_intern_string (src->source);
Packit a6ee4b
  dest->package = g_intern_string (src->package);
Packit a6ee4b
  dest->origin = g_intern_string (src->origin);
Packit a6ee4b
  dest->release_datetime = g_intern_string (src->release_datetime);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_name:
Packit a6ee4b
 * @plugin: plugin to get the name of
Packit a6ee4b
 *
Packit a6ee4b
 * Get the short name of the plugin
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: the name of the plugin
Packit a6ee4b
 */
Packit a6ee4b
const gchar *
Packit a6ee4b
gst_plugin_get_name (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->desc.name;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_description:
Packit a6ee4b
 * @plugin: plugin to get long name of
Packit a6ee4b
 *
Packit a6ee4b
 * Get the long descriptive name of the plugin
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: the long name of the plugin
Packit a6ee4b
 */
Packit a6ee4b
const gchar *
Packit a6ee4b
gst_plugin_get_description (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->desc.description;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_filename:
Packit a6ee4b
 * @plugin: plugin to get the filename of
Packit a6ee4b
 *
Packit a6ee4b
 * get the filename of the plugin
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: (type filename): the filename of the plugin
Packit a6ee4b
 */
Packit a6ee4b
const gchar *
Packit a6ee4b
gst_plugin_get_filename (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->filename;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_version:
Packit a6ee4b
 * @plugin: plugin to get the version of
Packit a6ee4b
 *
Packit a6ee4b
 * get the version of the plugin
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: the version of the plugin
Packit a6ee4b
 */
Packit a6ee4b
const gchar *
Packit a6ee4b
gst_plugin_get_version (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->desc.version;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_license:
Packit a6ee4b
 * @plugin: plugin to get the license of
Packit a6ee4b
 *
Packit a6ee4b
 * get the license of the plugin
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: the license of the plugin
Packit a6ee4b
 */
Packit a6ee4b
const gchar *
Packit a6ee4b
gst_plugin_get_license (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->desc.license;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_source:
Packit a6ee4b
 * @plugin: plugin to get the source of
Packit a6ee4b
 *
Packit a6ee4b
 * get the source module the plugin belongs to.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: the source of the plugin
Packit a6ee4b
 */
Packit a6ee4b
const gchar *
Packit a6ee4b
gst_plugin_get_source (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->desc.source;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_package:
Packit a6ee4b
 * @plugin: plugin to get the package of
Packit a6ee4b
 *
Packit a6ee4b
 * get the package the plugin belongs to.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: the package of the plugin
Packit a6ee4b
 */
Packit a6ee4b
const gchar *
Packit a6ee4b
gst_plugin_get_package (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->desc.package;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_origin:
Packit a6ee4b
 * @plugin: plugin to get the origin of
Packit a6ee4b
 *
Packit a6ee4b
 * get the URL where the plugin comes from
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: the origin of the plugin
Packit a6ee4b
 */
Packit a6ee4b
const gchar *
Packit a6ee4b
gst_plugin_get_origin (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->desc.origin;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_release_date_string:
Packit a6ee4b
 * @plugin: plugin to get the release date of
Packit a6ee4b
 *
Packit a6ee4b
 * Get the release date (and possibly time) in form of a string, if available.
Packit a6ee4b
 *
Packit a6ee4b
 * For normal GStreamer plugin releases this will usually just be a date in
Packit a6ee4b
 * the form of "YYYY-MM-DD", while pre-releases and builds from git may contain
Packit a6ee4b
 * a time component after the date as well, in which case the string will be
Packit a6ee4b
 * formatted like "YYYY-MM-DDTHH:MMZ" (e.g. "2012-04-30T09:30Z").
Packit a6ee4b
 *
Packit a6ee4b
 * There may be plugins that do not have a valid release date set on them.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: (nullable): the date string of the plugin, or %NULL if not
Packit a6ee4b
 * available.
Packit a6ee4b
 */
Packit a6ee4b
const gchar *
Packit a6ee4b
gst_plugin_get_release_date_string (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->desc.release_datetime;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_is_loaded:
Packit a6ee4b
 * @plugin: plugin to query
Packit a6ee4b
 *
Packit a6ee4b
 * queries if the plugin is loaded into memory
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: %TRUE is loaded, %FALSE otherwise
Packit a6ee4b
 */
Packit a6ee4b
gboolean
Packit a6ee4b
gst_plugin_is_loaded (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (plugin != NULL, FALSE);
Packit a6ee4b
Packit a6ee4b
  return (plugin->module != NULL || plugin->filename == NULL);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_get_cache_data:
Packit a6ee4b
 * @plugin: a plugin
Packit a6ee4b
 *
Packit a6ee4b
 * Gets the plugin specific data cache. If it is %NULL there is no cached data
Packit a6ee4b
 * stored. This is the case when the registry is getting rebuilt.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: (transfer none) (nullable): The cached data as a
Packit a6ee4b
 * #GstStructure or %NULL.
Packit a6ee4b
 */
Packit a6ee4b
const GstStructure *
Packit a6ee4b
gst_plugin_get_cache_data (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  g_return_val_if_fail (GST_IS_PLUGIN (plugin), NULL);
Packit a6ee4b
Packit a6ee4b
  return plugin->priv->cache_data;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_set_cache_data:
Packit a6ee4b
 * @plugin: a plugin
Packit a6ee4b
 * @cache_data: (transfer full): a structure containing the data to cache
Packit a6ee4b
 *
Packit a6ee4b
 * Adds plugin specific data to cache. Passes the ownership of the structure to
Packit a6ee4b
 * the @plugin.
Packit a6ee4b
 *
Packit a6ee4b
 * The cache is flushed every time the registry is rebuilt.
Packit a6ee4b
 */
Packit a6ee4b
void
Packit a6ee4b
gst_plugin_set_cache_data (GstPlugin * plugin, GstStructure * cache_data)
Packit a6ee4b
{
Packit a6ee4b
  g_return_if_fail (GST_IS_PLUGIN (plugin));
Packit a6ee4b
  g_return_if_fail (GST_IS_STRUCTURE (cache_data));
Packit a6ee4b
Packit a6ee4b
  if (plugin->priv->cache_data) {
Packit a6ee4b
    gst_structure_free (plugin->priv->cache_data);
Packit a6ee4b
  }
Packit a6ee4b
  plugin->priv->cache_data = cache_data;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
#if 0
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_feature_list:
Packit a6ee4b
 * @plugin: plugin to query
Packit a6ee4b
 * @filter: the filter to use
Packit a6ee4b
 * @first: only return first match
Packit a6ee4b
 * @user_data: user data passed to the filter function
Packit a6ee4b
 *
Packit a6ee4b
 * Runs a filter against all plugin features and returns a GList with
Packit a6ee4b
 * the results. If the first flag is set, only the first match is
Packit a6ee4b
 * returned (as a list with a single object).
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: a GList of features, g_list_free after use.
Packit a6ee4b
 */
Packit a6ee4b
GList *
Packit a6ee4b
gst_plugin_feature_filter (GstPlugin * plugin,
Packit a6ee4b
    GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
Packit a6ee4b
{
Packit a6ee4b
  GList *list;
Packit a6ee4b
  GList *g;
Packit a6ee4b
Packit a6ee4b
  list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
Packit a6ee4b
      user_data);
Packit a6ee4b
  for (g = list; g; g = g->next) {
Packit a6ee4b
    gst_object_ref (plugin);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return list;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
typedef struct
Packit a6ee4b
{
Packit a6ee4b
  GstPluginFeatureFilter filter;
Packit a6ee4b
  gboolean first;
Packit a6ee4b
  gpointer user_data;
Packit a6ee4b
  GList *result;
Packit a6ee4b
}
Packit a6ee4b
FeatureFilterData;
Packit a6ee4b
Packit a6ee4b
static gboolean
Packit a6ee4b
_feature_filter (GstPlugin * plugin, gpointer user_data)
Packit a6ee4b
{
Packit a6ee4b
  GList *result;
Packit a6ee4b
  FeatureFilterData *data = (FeatureFilterData *) user_data;
Packit a6ee4b
Packit a6ee4b
  result = gst_plugin_feature_filter (plugin, data->filter, data->first,
Packit a6ee4b
      data->user_data);
Packit a6ee4b
  if (result) {
Packit a6ee4b
    data->result = g_list_concat (data->result, result);
Packit a6ee4b
    return TRUE;
Packit a6ee4b
  }
Packit a6ee4b
  return FALSE;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_list_feature_filter:
Packit a6ee4b
 * @list: a #GList of plugins to query
Packit a6ee4b
 * @filter: the filter function to use
Packit a6ee4b
 * @first: only return first match
Packit a6ee4b
 * @user_data: user data passed to the filter function
Packit a6ee4b
 *
Packit a6ee4b
 * Runs a filter against all plugin features of the plugins in the given
Packit a6ee4b
 * list and returns a GList with the results.
Packit a6ee4b
 * If the first flag is set, only the first match is
Packit a6ee4b
 * returned (as a list with a single object).
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: a GList of features, g_list_free after use.
Packit a6ee4b
 */
Packit a6ee4b
GList *
Packit a6ee4b
gst_plugin_list_feature_filter (GList * list,
Packit a6ee4b
    GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
Packit a6ee4b
{
Packit a6ee4b
  FeatureFilterData data;
Packit a6ee4b
  GList *result;
Packit a6ee4b
Packit a6ee4b
  data.filter = filter;
Packit a6ee4b
  data.first = first;
Packit a6ee4b
  data.user_data = user_data;
Packit a6ee4b
  data.result = NULL;
Packit a6ee4b
Packit a6ee4b
  result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
Packit a6ee4b
  g_list_free (result);
Packit a6ee4b
Packit a6ee4b
  return data.result;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_find_feature:
Packit a6ee4b
 * @plugin: plugin to get the feature from
Packit a6ee4b
 * @name: The name of the feature to find
Packit a6ee4b
 * @type: The type of the feature to find
Packit a6ee4b
 *
Packit a6ee4b
 * Find a feature of the given name and type in the given plugin.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: a GstPluginFeature or %NULL if the feature was not found.
Packit a6ee4b
 */
Packit a6ee4b
GstPluginFeature *
Packit a6ee4b
gst_plugin_find_feature (GstPlugin * plugin, const gchar * name, GType type)
Packit a6ee4b
{
Packit a6ee4b
  GList *walk;
Packit a6ee4b
  GstPluginFeature *result = NULL;
Packit a6ee4b
  GstTypeNameData data;
Packit a6ee4b
Packit a6ee4b
  g_return_val_if_fail (name != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  data.type = type;
Packit a6ee4b
  data.name = name;
Packit a6ee4b
Packit a6ee4b
  walk = gst_filter_run (plugin->features,
Packit a6ee4b
      (GstFilterFunc) gst_plugin_feature_type_name_filter, TRUE, &data);
Packit a6ee4b
Packit a6ee4b
  if (walk) {
Packit a6ee4b
    result = GST_PLUGIN_FEATURE (walk->data);
Packit a6ee4b
Packit a6ee4b
    gst_object_ref (result);
Packit a6ee4b
    gst_plugin_feature_list_free (walk);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return result;
Packit a6ee4b
}
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
#if 0
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_plugin_feature_name_filter (GstPluginFeature * feature, const gchar * name)
Packit a6ee4b
{
Packit a6ee4b
  return !strcmp (name, GST_PLUGIN_FEATURE_NAME (feature));
Packit a6ee4b
}
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
#if 0
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_find_feature_by_name:
Packit a6ee4b
 * @plugin: plugin to get the feature from
Packit a6ee4b
 * @name: The name of the feature to find
Packit a6ee4b
 *
Packit a6ee4b
 * Find a feature of the given name in the given plugin.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: a GstPluginFeature or %NULL if the feature was not found.
Packit a6ee4b
 */
Packit a6ee4b
GstPluginFeature *
Packit a6ee4b
gst_plugin_find_feature_by_name (GstPlugin * plugin, const gchar * name)
Packit a6ee4b
{
Packit a6ee4b
  GList *walk;
Packit a6ee4b
  GstPluginFeature *result = NULL;
Packit a6ee4b
Packit a6ee4b
  g_return_val_if_fail (name != NULL, NULL);
Packit a6ee4b
Packit a6ee4b
  walk = gst_filter_run (plugin->features,
Packit a6ee4b
      (GstFilterFunc) gst_plugin_feature_name_filter, TRUE, (void *) name);
Packit a6ee4b
Packit a6ee4b
  if (walk) {
Packit a6ee4b
    result = GST_PLUGIN_FEATURE (walk->data);
Packit a6ee4b
Packit a6ee4b
    gst_object_ref (result);
Packit a6ee4b
    gst_plugin_feature_list_free (walk);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return result;
Packit a6ee4b
}
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_load_by_name:
Packit a6ee4b
 * @name: name of plugin to load
Packit a6ee4b
 *
Packit a6ee4b
 * Load the named plugin. Refs the plugin.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: (transfer full) (nullable): a reference to a loaded plugin, or
Packit a6ee4b
 * %NULL on error.
Packit a6ee4b
 */
Packit a6ee4b
GstPlugin *
Packit a6ee4b
gst_plugin_load_by_name (const gchar * name)
Packit a6ee4b
{
Packit a6ee4b
  GstPlugin *plugin, *newplugin;
Packit a6ee4b
  GError *error = NULL;
Packit a6ee4b
Packit a6ee4b
  GST_DEBUG ("looking up plugin %s in default registry", name);
Packit a6ee4b
  plugin = gst_registry_find_plugin (gst_registry_get (), name);
Packit a6ee4b
  if (plugin) {
Packit a6ee4b
    GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
Packit a6ee4b
    newplugin = gst_plugin_load_file (plugin->filename, &error);
Packit a6ee4b
    gst_object_unref (plugin);
Packit a6ee4b
Packit a6ee4b
    if (!newplugin) {
Packit a6ee4b
      GST_WARNING ("load_plugin error: %s", error->message);
Packit a6ee4b
      g_error_free (error);
Packit a6ee4b
      return NULL;
Packit a6ee4b
    }
Packit a6ee4b
    /* newplugin was reffed by load_file */
Packit a6ee4b
    return newplugin;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  GST_DEBUG ("Could not find plugin %s in registry", name);
Packit a6ee4b
  return NULL;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_load:
Packit a6ee4b
 * @plugin: (transfer none): plugin to load
Packit a6ee4b
 *
Packit a6ee4b
 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
Packit a6ee4b
 * untouched. The normal use pattern of this function goes like this:
Packit a6ee4b
 *
Packit a6ee4b
 * |[
Packit a6ee4b
 * GstPlugin *loaded_plugin;
Packit a6ee4b
 * loaded_plugin = gst_plugin_load (plugin);
Packit a6ee4b
 * // presumably, we're no longer interested in the potentially-unloaded plugin
Packit a6ee4b
 * gst_object_unref (plugin);
Packit a6ee4b
 * plugin = loaded_plugin;
Packit a6ee4b
 * ]|
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: (transfer full) (nullable): a reference to a loaded plugin, or
Packit a6ee4b
 * %NULL on error.
Packit a6ee4b
 */
Packit a6ee4b
GstPlugin *
Packit a6ee4b
gst_plugin_load (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  GError *error = NULL;
Packit a6ee4b
  GstPlugin *newplugin;
Packit a6ee4b
Packit a6ee4b
  if (gst_plugin_is_loaded (plugin)) {
Packit a6ee4b
    return gst_object_ref (plugin);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  if (!(newplugin = gst_plugin_load_file (plugin->filename, &error)))
Packit a6ee4b
    goto load_error;
Packit a6ee4b
Packit a6ee4b
  return newplugin;
Packit a6ee4b
Packit a6ee4b
load_error:
Packit a6ee4b
  {
Packit a6ee4b
    GST_WARNING ("load_plugin error: %s", error->message);
Packit a6ee4b
    g_error_free (error);
Packit a6ee4b
    return NULL;
Packit a6ee4b
  }
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_list_free:
Packit a6ee4b
 * @list: (transfer full) (element-type Gst.Plugin): list of #GstPlugin
Packit a6ee4b
 *
Packit a6ee4b
 * Unrefs each member of @list, then frees the list.
Packit a6ee4b
 */
Packit a6ee4b
void
Packit a6ee4b
gst_plugin_list_free (GList * list)
Packit a6ee4b
{
Packit a6ee4b
  GList *g;
Packit a6ee4b
Packit a6ee4b
  for (g = list; g; g = g->next) {
Packit a6ee4b
    gst_object_unref (GST_PLUGIN_CAST (g->data));
Packit a6ee4b
  }
Packit a6ee4b
  g_list_free (list);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/* ===== plugin dependencies ===== */
Packit a6ee4b
Packit a6ee4b
/* Scenarios:
Packit a6ee4b
 * ENV + xyz     where ENV can contain multiple values separated by SEPARATOR
Packit a6ee4b
 *               xyz may be "" (if ENV contains path to file rather than dir)
Packit a6ee4b
 * ENV + *xyz   same as above, but xyz acts as suffix filter
Packit a6ee4b
 * ENV + xyz*   same as above, but xyz acts as prefix filter (is this needed?)
Packit a6ee4b
 * ENV + *xyz*  same as above, but xyz acts as strstr filter (is this needed?)
Packit a6ee4b
 * 
Packit a6ee4b
 * same as above, with additional paths hard-coded at compile-time:
Packit a6ee4b
 *   - only check paths + ... if ENV is not set or yields not paths
Packit a6ee4b
 *   - always check paths + ... in addition to ENV
Packit a6ee4b
 *
Packit a6ee4b
 * When user specifies set of environment variables, he/she may also use e.g.
Packit a6ee4b
 * "HOME/.mystuff/plugins", and we'll expand the content of $HOME with the
Packit a6ee4b
 * remainder 
Packit a6ee4b
 */
Packit a6ee4b
Packit a6ee4b
/* we store in registry:
Packit a6ee4b
 *  sets of:
Packit a6ee4b
 *   { 
Packit a6ee4b
 *     - environment variables (array of strings)
Packit a6ee4b
 *     - last hash of env variable contents (uint) (so we can avoid doing stats
Packit a6ee4b
 *       if one of the env vars has changed; premature optimisation galore)
Packit a6ee4b
 *     - hard-coded paths (array of strings)
Packit a6ee4b
 *     - xyz filename/suffix/prefix strings (array of strings)
Packit a6ee4b
 *     - flags (int)
Packit a6ee4b
 *     - last hash of file/dir stats (int)
Packit a6ee4b
 *   }
Packit a6ee4b
 *   (= struct GstPluginDep)
Packit a6ee4b
 */
Packit a6ee4b
Packit a6ee4b
static guint
Packit a6ee4b
gst_plugin_ext_dep_get_env_vars_hash (GstPlugin * plugin, GstPluginDep * dep)
Packit a6ee4b
{
Packit a6ee4b
  gchar **e;
Packit a6ee4b
  guint hash;
Packit a6ee4b
Packit a6ee4b
  /* there's no deeper logic to what we do here; all we want to know (when
Packit a6ee4b
   * checking if the plugin needs to be rescanned) is whether the content of
Packit a6ee4b
   * one of the environment variables in the list is different from when it
Packit a6ee4b
   * was last scanned */
Packit a6ee4b
  hash = 0;
Packit a6ee4b
  for (e = dep->env_vars; e != NULL && *e != NULL; ++e) {
Packit a6ee4b
    const gchar *val;
Packit a6ee4b
    gchar env_var[256];
Packit a6ee4b
Packit a6ee4b
    /* order matters: "val",NULL needs to yield a different hash than
Packit a6ee4b
     * NULL,"val", so do a shift here whether the var is set or not */
Packit a6ee4b
    hash = hash << 5;
Packit a6ee4b
Packit a6ee4b
    /* want environment variable at beginning of string */
Packit a6ee4b
    if (!g_ascii_isalnum (**e)) {
Packit a6ee4b
      GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
Packit a6ee4b
          "variable string: %s", *e);
Packit a6ee4b
      continue;
Packit a6ee4b
    }
Packit a6ee4b
Packit a6ee4b
    /* user is allowed to specify e.g. "HOME/.pitivi/plugins" */
Packit a6ee4b
    g_strlcpy (env_var, *e, sizeof (env_var));
Packit a6ee4b
    g_strdelimit (env_var, "/\\", '\0');
Packit a6ee4b
Packit a6ee4b
    if ((val = g_getenv (env_var)))
Packit a6ee4b
      hash += g_str_hash (val);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return hash;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
gboolean
Packit a6ee4b
_priv_plugin_deps_env_vars_changed (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  GList *l;
Packit a6ee4b
Packit a6ee4b
  for (l = plugin->priv->deps; l != NULL; l = l->next) {
Packit a6ee4b
    GstPluginDep *dep = l->data;
Packit a6ee4b
Packit a6ee4b
    if (dep->env_hash != gst_plugin_ext_dep_get_env_vars_hash (plugin, dep))
Packit a6ee4b
      return TRUE;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return FALSE;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_plugin_ext_dep_extract_env_vars_paths (GstPlugin * plugin,
Packit a6ee4b
    GstPluginDep * dep, GQueue * paths)
Packit a6ee4b
{
Packit a6ee4b
  gchar **evars;
Packit a6ee4b
Packit a6ee4b
  for (evars = dep->env_vars; evars != NULL && *evars != NULL; ++evars) {
Packit a6ee4b
    const gchar *e;
Packit a6ee4b
    gchar **components;
Packit a6ee4b
Packit a6ee4b
    /* want environment variable at beginning of string */
Packit a6ee4b
    if (!g_ascii_isalnum (**evars)) {
Packit a6ee4b
      GST_WARNING_OBJECT (plugin, "string prefix is not a valid environment "
Packit a6ee4b
          "variable string: %s", *evars);
Packit a6ee4b
      continue;
Packit a6ee4b
    }
Packit a6ee4b
Packit a6ee4b
    /* user is allowed to specify e.g. "HOME/.pitivi/plugins", which we want to
Packit a6ee4b
     * split into the env_var name component and the path component */
Packit a6ee4b
    components = g_strsplit_set (*evars, "/\\", 2);
Packit a6ee4b
    g_assert (components != NULL);
Packit a6ee4b
Packit a6ee4b
    e = g_getenv (components[0]);
Packit a6ee4b
    GST_LOG_OBJECT (plugin, "expanding %s = '%s' (path suffix: %s)",
Packit a6ee4b
        components[0], GST_STR_NULL (e), GST_STR_NULL (components[1]));
Packit a6ee4b
Packit a6ee4b
    if (components[1] != NULL) {
Packit a6ee4b
      g_strdelimit (components[1], "/\\", G_DIR_SEPARATOR);
Packit a6ee4b
    }
Packit a6ee4b
Packit a6ee4b
    if (e != NULL && *e != '\0') {
Packit a6ee4b
      gchar **arr;
Packit a6ee4b
      guint i;
Packit a6ee4b
Packit a6ee4b
      arr = g_strsplit (e, G_SEARCHPATH_SEPARATOR_S, -1);
Packit a6ee4b
Packit a6ee4b
      for (i = 0; arr != NULL && arr[i] != NULL; ++i) {
Packit a6ee4b
        gchar *full_path;
Packit a6ee4b
Packit a6ee4b
        if (!g_path_is_absolute (arr[i])) {
Packit a6ee4b
          GST_INFO_OBJECT (plugin, "ignoring environment variable content '%s'"
Packit a6ee4b
              ": either not an absolute path or not a path at all", arr[i]);
Packit a6ee4b
          continue;
Packit a6ee4b
        }
Packit a6ee4b
Packit a6ee4b
        if (components[1] != NULL) {
Packit a6ee4b
          full_path = g_build_filename (arr[i], components[1], NULL);
Packit a6ee4b
        } else {
Packit a6ee4b
          full_path = g_strdup (arr[i]);
Packit a6ee4b
        }
Packit a6ee4b
Packit a6ee4b
        if (!g_queue_find_custom (paths, full_path, (GCompareFunc) strcmp)) {
Packit a6ee4b
          GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
Packit a6ee4b
          g_queue_push_tail (paths, full_path);
Packit a6ee4b
          full_path = NULL;
Packit a6ee4b
        } else {
Packit a6ee4b
          GST_LOG_OBJECT (plugin, "path: '%s' (duplicate,ignoring)", full_path);
Packit a6ee4b
          g_free (full_path);
Packit a6ee4b
        }
Packit a6ee4b
      }
Packit a6ee4b
Packit a6ee4b
      g_strfreev (arr);
Packit a6ee4b
    }
Packit a6ee4b
Packit a6ee4b
    g_strfreev (components);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  GST_LOG_OBJECT (plugin, "Extracted %d paths from environment", paths->length);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static guint
Packit a6ee4b
gst_plugin_ext_dep_get_hash_from_stat_entry (GStatBuf * s)
Packit a6ee4b
{
Packit a6ee4b
#ifdef S_IFBLK
Packit a6ee4b
  if (!(s->st_mode & (S_IFDIR | S_IFREG | S_IFBLK | S_IFCHR)))
Packit a6ee4b
#else
Packit a6ee4b
  /* MSVC does not have S_IFBLK */
Packit a6ee4b
  if (!(s->st_mode & (S_IFDIR | S_IFREG | S_IFCHR)))
Packit a6ee4b
#endif
Packit a6ee4b
    return (guint) - 1;
Packit a6ee4b
Packit a6ee4b
  /* completely random formula */
Packit a6ee4b
  return ((s->st_size << 3) + (s->st_mtime << 5)) ^ s->st_ctime;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_plugin_ext_dep_direntry_matches (GstPlugin * plugin, const gchar * entry,
Packit a6ee4b
    const gchar ** filenames, GstPluginDependencyFlags flags)
Packit a6ee4b
{
Packit a6ee4b
  /* no filenames specified, match all entries for now (could probably
Packit a6ee4b
   * optimise by just taking the dir stat hash or so) */
Packit a6ee4b
  if (filenames == NULL || *filenames == NULL || **filenames == '\0')
Packit a6ee4b
    return TRUE;
Packit a6ee4b
Packit a6ee4b
  while (*filenames != NULL) {
Packit a6ee4b
    /* suffix match? */
Packit a6ee4b
    if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX)) &&
Packit a6ee4b
        g_str_has_suffix (entry, *filenames)) {
Packit a6ee4b
      return TRUE;
Packit a6ee4b
    } else if (((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_PREFIX)) &&
Packit a6ee4b
        g_str_has_prefix (entry, *filenames)) {
Packit a6ee4b
      return TRUE;
Packit a6ee4b
      /* else it's an exact match that's needed */
Packit a6ee4b
    } else if (strcmp (entry, *filenames) == 0) {
Packit a6ee4b
      return TRUE;
Packit a6ee4b
    }
Packit a6ee4b
    GST_LOG ("%s does not match %s, flags=0x%04x", entry, *filenames, flags);
Packit a6ee4b
    ++filenames;
Packit a6ee4b
  }
Packit a6ee4b
  return FALSE;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static guint
Packit a6ee4b
gst_plugin_ext_dep_scan_dir_and_match_names (GstPlugin * plugin,
Packit a6ee4b
    const gchar * path, const gchar ** filenames,
Packit a6ee4b
    GstPluginDependencyFlags flags, int depth)
Packit a6ee4b
{
Packit a6ee4b
  const gchar *entry;
Packit a6ee4b
  gboolean recurse_dirs;
Packit a6ee4b
  GError *err = NULL;
Packit a6ee4b
  GDir *dir;
Packit a6ee4b
  guint hash = 0;
Packit a6ee4b
Packit a6ee4b
  recurse_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
Packit a6ee4b
Packit a6ee4b
  dir = g_dir_open (path, 0, &err;;
Packit a6ee4b
  if (dir == NULL) {
Packit a6ee4b
    GST_DEBUG_OBJECT (plugin, "g_dir_open(%s) failed: %s", path, err->message);
Packit a6ee4b
    g_error_free (err);
Packit a6ee4b
    return (guint) - 1;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  /* FIXME: we're assuming here that we always get the directory entries in
Packit a6ee4b
   * the same order, and not in a random order */
Packit a6ee4b
  while ((entry = g_dir_read_name (dir))) {
Packit a6ee4b
    gboolean have_match;
Packit a6ee4b
    GStatBuf s;
Packit a6ee4b
    gchar *full_path;
Packit a6ee4b
    guint fhash;
Packit a6ee4b
Packit a6ee4b
    have_match =
Packit a6ee4b
        gst_plugin_ext_dep_direntry_matches (plugin, entry, filenames, flags);
Packit a6ee4b
Packit a6ee4b
    /* avoid the stat if possible */
Packit a6ee4b
    if (!have_match && !recurse_dirs)
Packit a6ee4b
      continue;
Packit a6ee4b
Packit a6ee4b
    full_path = g_build_filename (path, entry, NULL);
Packit a6ee4b
    if (g_stat (full_path, &s) < 0) {
Packit a6ee4b
      fhash = (guint) - 1;
Packit a6ee4b
      GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
Packit a6ee4b
          g_strerror (errno));
Packit a6ee4b
    } else if (have_match) {
Packit a6ee4b
      fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
Packit a6ee4b
      GST_LOG_OBJECT (plugin, "stat: %s (result: %u)", full_path, fhash);
Packit a6ee4b
    } else if ((s.st_mode & (S_IFDIR))) {
Packit a6ee4b
      fhash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, full_path,
Packit a6ee4b
          filenames, flags, depth + 1);
Packit a6ee4b
    } else {
Packit a6ee4b
      /* it's not a name match, we want to recurse, but it's not a directory */
Packit a6ee4b
      g_free (full_path);
Packit a6ee4b
      continue;
Packit a6ee4b
    }
Packit a6ee4b
Packit a6ee4b
    hash = hash + fhash;
Packit a6ee4b
    g_free (full_path);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  g_dir_close (dir);
Packit a6ee4b
  return hash;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static guint
Packit a6ee4b
gst_plugin_ext_dep_scan_path_with_filenames (GstPlugin * plugin,
Packit a6ee4b
    const gchar * path, const gchar ** filenames,
Packit a6ee4b
    GstPluginDependencyFlags flags)
Packit a6ee4b
{
Packit a6ee4b
  const gchar *empty_filenames[] = { "", NULL };
Packit a6ee4b
  gboolean recurse_into_dirs, partial_names = FALSE;
Packit a6ee4b
  guint i, hash = 0;
Packit a6ee4b
Packit a6ee4b
  /* to avoid special-casing below (FIXME?) */
Packit a6ee4b
  if (filenames == NULL || *filenames == NULL)
Packit a6ee4b
    filenames = empty_filenames;
Packit a6ee4b
Packit a6ee4b
  recurse_into_dirs = ! !(flags & GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
Packit a6ee4b
Packit a6ee4b
  if ((flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_SUFFIX) ||
Packit a6ee4b
      (flags & GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_PREFIX))
Packit a6ee4b
    partial_names = TRUE;
Packit a6ee4b
Packit a6ee4b
  /* if we can construct the exact paths to check with the data we have, just
Packit a6ee4b
   * stat them one by one; this is more efficient than opening the directory
Packit a6ee4b
   * and going through each entry to see if it matches one of our filenames. */
Packit a6ee4b
  if (!recurse_into_dirs && !partial_names) {
Packit a6ee4b
    for (i = 0; filenames[i] != NULL; ++i) {
Packit a6ee4b
      GStatBuf s;
Packit a6ee4b
      gchar *full_path;
Packit a6ee4b
      guint fhash;
Packit a6ee4b
Packit a6ee4b
      full_path = g_build_filename (path, filenames[i], NULL);
Packit a6ee4b
      if (g_stat (full_path, &s) < 0) {
Packit a6ee4b
        fhash = (guint) - 1;
Packit a6ee4b
        GST_LOG_OBJECT (plugin, "stat: %s (error: %s)", full_path,
Packit a6ee4b
            g_strerror (errno));
Packit a6ee4b
      } else {
Packit a6ee4b
        fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
Packit a6ee4b
        GST_LOG_OBJECT (plugin, "stat: %s (result: %08x)", full_path, fhash);
Packit a6ee4b
      }
Packit a6ee4b
      hash += fhash;
Packit a6ee4b
      g_free (full_path);
Packit a6ee4b
    }
Packit a6ee4b
  } else {
Packit a6ee4b
    hash = gst_plugin_ext_dep_scan_dir_and_match_names (plugin, path,
Packit a6ee4b
        filenames, flags, 0);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return hash;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static guint
Packit a6ee4b
gst_plugin_ext_dep_get_stat_hash (GstPlugin * plugin, GstPluginDep * dep)
Packit a6ee4b
{
Packit a6ee4b
  gboolean paths_are_default_only;
Packit a6ee4b
  gboolean paths_are_relative_to_exe;
Packit a6ee4b
  GQueue scan_paths = G_QUEUE_INIT;
Packit a6ee4b
  guint scan_hash = 0;
Packit a6ee4b
  gchar *path;
Packit a6ee4b
Packit a6ee4b
  GST_LOG_OBJECT (plugin, "start");
Packit a6ee4b
Packit a6ee4b
  paths_are_default_only =
Packit a6ee4b
      dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_DEFAULT_ONLY;
Packit a6ee4b
  paths_are_relative_to_exe =
Packit a6ee4b
      dep->flags & GST_PLUGIN_DEPENDENCY_FLAG_PATHS_ARE_RELATIVE_TO_EXE;
Packit a6ee4b
Packit a6ee4b
  gst_plugin_ext_dep_extract_env_vars_paths (plugin, dep, &scan_paths);
Packit a6ee4b
Packit a6ee4b
  if (g_queue_is_empty (&scan_paths) || !paths_are_default_only) {
Packit a6ee4b
    gchar **paths;
Packit a6ee4b
Packit a6ee4b
    for (paths = dep->paths; paths != NULL && *paths != NULL; ++paths) {
Packit a6ee4b
      const gchar *path = *paths;
Packit a6ee4b
      gchar *full_path;
Packit a6ee4b
Packit a6ee4b
      if (paths_are_relative_to_exe && !g_path_is_absolute (path)) {
Packit a6ee4b
        gchar *appdir;
Packit a6ee4b
Packit a6ee4b
        if (!_gst_executable_path) {
Packit a6ee4b
          GST_FIXME_OBJECT (plugin,
Packit a6ee4b
              "Path dependency %s relative to executable path but could not retrieve executable path",
Packit a6ee4b
              path);
Packit a6ee4b
          continue;
Packit a6ee4b
        }
Packit a6ee4b
        appdir = g_path_get_dirname (_gst_executable_path);
Packit a6ee4b
        full_path = g_build_filename (appdir, path, NULL);
Packit a6ee4b
        g_free (appdir);
Packit a6ee4b
      } else {
Packit a6ee4b
        full_path = g_strdup (path);
Packit a6ee4b
      }
Packit a6ee4b
Packit a6ee4b
      if (!g_queue_find_custom (&scan_paths, full_path, (GCompareFunc) strcmp)) {
Packit a6ee4b
        GST_LOG_OBJECT (plugin, "path: '%s'", full_path);
Packit a6ee4b
        g_queue_push_tail (&scan_paths, full_path);
Packit a6ee4b
      } else {
Packit a6ee4b
        GST_LOG_OBJECT (plugin, "path: '%s' (duplicate, ignoring)", full_path);
Packit a6ee4b
        g_free (full_path);
Packit a6ee4b
      }
Packit a6ee4b
    }
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  while ((path = g_queue_pop_head (&scan_paths))) {
Packit a6ee4b
    scan_hash += gst_plugin_ext_dep_scan_path_with_filenames (plugin, path,
Packit a6ee4b
        (const gchar **) dep->names, dep->flags);
Packit a6ee4b
    g_free (path);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  GST_LOG_OBJECT (plugin, "done, scan_hash: %08x", scan_hash);
Packit a6ee4b
  return scan_hash;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
gboolean
Packit a6ee4b
_priv_plugin_deps_files_changed (GstPlugin * plugin)
Packit a6ee4b
{
Packit a6ee4b
  GList *l;
Packit a6ee4b
Packit a6ee4b
  for (l = plugin->priv->deps; l != NULL; l = l->next) {
Packit a6ee4b
    GstPluginDep *dep = l->data;
Packit a6ee4b
Packit a6ee4b
    if (dep->stat_hash != gst_plugin_ext_dep_get_stat_hash (plugin, dep))
Packit a6ee4b
      return TRUE;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return FALSE;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_plugin_ext_dep_free (GstPluginDep * dep)
Packit a6ee4b
{
Packit a6ee4b
  g_strfreev (dep->env_vars);
Packit a6ee4b
  g_strfreev (dep->paths);
Packit a6ee4b
  g_strfreev (dep->names);
Packit a6ee4b
  g_slice_free (GstPluginDep, dep);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_plugin_ext_dep_strv_equal (gchar ** arr1, gchar ** arr2)
Packit a6ee4b
{
Packit a6ee4b
  if (arr1 == arr2)
Packit a6ee4b
    return TRUE;
Packit a6ee4b
  if (arr1 == NULL || arr2 == NULL)
Packit a6ee4b
    return FALSE;
Packit a6ee4b
  for (; *arr1 != NULL && *arr2 != NULL; ++arr1, ++arr2) {
Packit a6ee4b
    if (strcmp (*arr1, *arr2) != 0)
Packit a6ee4b
      return FALSE;
Packit a6ee4b
  }
Packit a6ee4b
  return (*arr1 == *arr2);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_plugin_ext_dep_equals (GstPluginDep * dep, const gchar ** env_vars,
Packit a6ee4b
    const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
Packit a6ee4b
{
Packit a6ee4b
  if (dep->flags != flags)
Packit a6ee4b
    return FALSE;
Packit a6ee4b
Packit a6ee4b
  return gst_plugin_ext_dep_strv_equal (dep->env_vars, (gchar **) env_vars) &&
Packit a6ee4b
      gst_plugin_ext_dep_strv_equal (dep->paths, (gchar **) paths) &&
Packit a6ee4b
      gst_plugin_ext_dep_strv_equal (dep->names, (gchar **) names);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_add_dependency:
Packit a6ee4b
 * @plugin: a #GstPlugin
Packit a6ee4b
 * @env_vars: (allow-none) (array zero-terminated=1): %NULL-terminated array of environment variables affecting the
Packit a6ee4b
 *     feature set of the plugin (e.g. an environment variable containing
Packit a6ee4b
 *     paths where to look for additional modules/plugins of a library),
Packit a6ee4b
 *     or %NULL. Environment variable names may be followed by a path component
Packit a6ee4b
 *      which will be added to the content of the environment variable, e.g.
Packit a6ee4b
 *      "HOME/.mystuff/plugins".
Packit a6ee4b
 * @paths: (allow-none) (array zero-terminated=1): %NULL-terminated array of directories/paths where dependent files
Packit a6ee4b
 *     may be, or %NULL.
Packit a6ee4b
 * @names: (allow-none) (array zero-terminated=1): %NULL-terminated array of file names (or file name suffixes,
Packit a6ee4b
 *     depending on @flags) to be used in combination with the paths from
Packit a6ee4b
 *     @paths and/or the paths extracted from the environment variables in
Packit a6ee4b
 *     @env_vars, or %NULL.
Packit a6ee4b
 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
Packit a6ee4b
 *
Packit a6ee4b
 * Make GStreamer aware of external dependencies which affect the feature
Packit a6ee4b
 * set of this plugin (ie. the elements or typefinders associated with it).
Packit a6ee4b
 *
Packit a6ee4b
 * GStreamer will re-inspect plugins with external dependencies whenever any
Packit a6ee4b
 * of the external dependencies change. This is useful for plugins which wrap
Packit a6ee4b
 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
Packit a6ee4b
 * library and makes visualisations available as GStreamer elements, or a
Packit a6ee4b
 * codec loader which exposes elements and/or caps dependent on what external
Packit a6ee4b
 * codec libraries are currently installed.
Packit a6ee4b
 */
Packit a6ee4b
void
Packit a6ee4b
gst_plugin_add_dependency (GstPlugin * plugin, const gchar ** env_vars,
Packit a6ee4b
    const gchar ** paths, const gchar ** names, GstPluginDependencyFlags flags)
Packit a6ee4b
{
Packit a6ee4b
  GstPluginDep *dep;
Packit a6ee4b
  GList *l;
Packit a6ee4b
Packit a6ee4b
  g_return_if_fail (GST_IS_PLUGIN (plugin));
Packit a6ee4b
Packit a6ee4b
  if ((env_vars == NULL || env_vars[0] == NULL) &&
Packit a6ee4b
      (paths == NULL || paths[0] == NULL)) {
Packit a6ee4b
    GST_DEBUG_OBJECT (plugin,
Packit a6ee4b
        "plugin registered empty dependency set. Ignoring");
Packit a6ee4b
    return;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  for (l = plugin->priv->deps; l != NULL; l = l->next) {
Packit a6ee4b
    if (gst_plugin_ext_dep_equals (l->data, env_vars, paths, names, flags)) {
Packit a6ee4b
      GST_LOG_OBJECT (plugin, "dependency already registered");
Packit a6ee4b
      return;
Packit a6ee4b
    }
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  dep = g_slice_new (GstPluginDep);
Packit a6ee4b
Packit a6ee4b
  dep->env_vars = g_strdupv ((gchar **) env_vars);
Packit a6ee4b
  dep->paths = g_strdupv ((gchar **) paths);
Packit a6ee4b
  dep->names = g_strdupv ((gchar **) names);
Packit a6ee4b
  dep->flags = flags;
Packit a6ee4b
Packit a6ee4b
  dep->env_hash = gst_plugin_ext_dep_get_env_vars_hash (plugin, dep);
Packit a6ee4b
  dep->stat_hash = gst_plugin_ext_dep_get_stat_hash (plugin, dep);
Packit a6ee4b
Packit a6ee4b
  plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
Packit a6ee4b
Packit a6ee4b
  GST_DEBUG_OBJECT (plugin, "added dependency:");
Packit a6ee4b
  for (; env_vars != NULL && *env_vars != NULL; ++env_vars)
Packit a6ee4b
    GST_DEBUG_OBJECT (plugin, " evar: %s", *env_vars);
Packit a6ee4b
  for (; paths != NULL && *paths != NULL; ++paths)
Packit a6ee4b
    GST_DEBUG_OBJECT (plugin, " path: %s", *paths);
Packit a6ee4b
  for (; names != NULL && *names != NULL; ++names)
Packit a6ee4b
    GST_DEBUG_OBJECT (plugin, " name: %s", *names);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_plugin_add_dependency_simple:
Packit a6ee4b
 * @plugin: the #GstPlugin
Packit a6ee4b
 * @env_vars: (allow-none): one or more environment variables (separated by ':', ';' or ','),
Packit a6ee4b
 *      or %NULL. Environment variable names may be followed by a path component
Packit a6ee4b
 *      which will be added to the content of the environment variable, e.g.
Packit a6ee4b
 *      "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
Packit a6ee4b
 * @paths: (allow-none): one ore more directory paths (separated by ':' or ';' or ','),
Packit a6ee4b
 *      or %NULL. Example: "/usr/lib/mystuff/plugins"
Packit a6ee4b
 * @names: (allow-none): one or more file names or file name suffixes (separated by commas),
Packit a6ee4b
 *      or %NULL
Packit a6ee4b
 * @flags: optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
Packit a6ee4b
 *
Packit a6ee4b
 * Make GStreamer aware of external dependencies which affect the feature
Packit a6ee4b
 * set of this plugin (ie. the elements or typefinders associated with it).
Packit a6ee4b
 *
Packit a6ee4b
 * GStreamer will re-inspect plugins with external dependencies whenever any
Packit a6ee4b
 * of the external dependencies change. This is useful for plugins which wrap
Packit a6ee4b
 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
Packit a6ee4b
 * library and makes visualisations available as GStreamer elements, or a
Packit a6ee4b
 * codec loader which exposes elements and/or caps dependent on what external
Packit a6ee4b
 * codec libraries are currently installed.
Packit a6ee4b
 *
Packit a6ee4b
 * Convenience wrapper function for gst_plugin_add_dependency() which
Packit a6ee4b
 * takes simple strings as arguments instead of string arrays, with multiple
Packit a6ee4b
 * arguments separated by predefined delimiters (see above).
Packit a6ee4b
 */
Packit a6ee4b
void
Packit a6ee4b
gst_plugin_add_dependency_simple (GstPlugin * plugin,
Packit a6ee4b
    const gchar * env_vars, const gchar * paths, const gchar * names,
Packit a6ee4b
    GstPluginDependencyFlags flags)
Packit a6ee4b
{
Packit a6ee4b
  gchar **a_evars = NULL;
Packit a6ee4b
  gchar **a_paths = NULL;
Packit a6ee4b
  gchar **a_names = NULL;
Packit a6ee4b
Packit a6ee4b
  if (env_vars)
Packit a6ee4b
    a_evars = g_strsplit_set (env_vars, ":;,", -1);
Packit a6ee4b
  if (paths)
Packit a6ee4b
    a_paths = g_strsplit_set (paths, ":;,", -1);
Packit a6ee4b
  if (names)
Packit a6ee4b
    a_names = g_strsplit_set (names, ",", -1);
Packit a6ee4b
Packit a6ee4b
  gst_plugin_add_dependency (plugin, (const gchar **) a_evars,
Packit a6ee4b
      (const gchar **) a_paths, (const gchar **) a_names, flags);
Packit a6ee4b
Packit a6ee4b
  if (a_evars)
Packit a6ee4b
    g_strfreev (a_evars);
Packit a6ee4b
  if (a_paths)
Packit a6ee4b
    g_strfreev (a_paths);
Packit a6ee4b
  if (a_names)
Packit a6ee4b
    g_strfreev (a_names);
Packit a6ee4b
}