gstplugin.c 55.6 KB
Newer Older
1 2 3 4 5
/* GStreamer
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2000 Wim Taymans <wtay@chello.be>
 *
 * gstplugin.c: Plugin subsystem for loading elements, types, and libs
Erik Walthinsen's avatar
Erik Walthinsen committed
6 7 8 9 10
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
11
 *
Erik Walthinsen's avatar
Erik Walthinsen committed
12 13 14 15 16 17 18 19 20 21
 * 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
22

23 24 25 26 27 28
/**
 * SECTION:gstplugin
 * @short_description: Container for features loaded from a shared object module
 * @see_also: #GstPluginFeature, #GstElementFactory
 *
 * GStreamer is extensible, so #GstElement instances can be loaded at runtime.
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
29 30
 * A plugin system can provide one or more of the basic
 * <application>GStreamer</application> #GstPluginFeature subclasses.
31
 *
32
 * A plugin should export a symbol <symbol>gst_plugin_desc</symbol> that is a
33
 * struct of type #GstPluginDesc.
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
34 35
 * the plugin loader will check the version of the core library the plugin was
 * linked against and will create a new #GstPlugin. It will then call the
36 37
 * #GstPluginInitFunc function that was provided in the
 * <symbol>gst_plugin_desc</symbol>.
38
 *
39
 * Once you have a handle to a #GstPlugin (e.g. from the #GstRegistry), you
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
40
 * can add any object that subclasses #GstPluginFeature.
41
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
42 43 44 45 46
 * Usually plugins are always automaticlly loaded so you don't need to call
 * gst_plugin_load() explicitly to bring it into memory. There are options to
 * statically link plugins to an app or even use GStreamer without a plugin
 * repository in which case gst_plugin_load() can be needed to bring the plugin
 * into memory.
47
 */
Erik Walthinsen's avatar
Erik Walthinsen committed
48

49 50 51
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
52 53 54

#include "gst_private.h"

55
#include <glib/gstdio.h>
Erik Walthinsen's avatar
Erik Walthinsen committed
56
#include <sys/types.h>
57
#ifdef HAVE_DIRENT_H
Erik Walthinsen's avatar
Erik Walthinsen committed
58
#include <dirent.h>
59 60
#endif
#ifdef HAVE_UNISTD_H
Erik Walthinsen's avatar
Erik Walthinsen committed
61
#include <unistd.h>
62
#endif
63
#include <signal.h>
64
#include <errno.h>
65
#include <string.h>
Erik Walthinsen's avatar
Erik Walthinsen committed
66

67
#include "glib-compat-private.h"
68

69
#include <gst/gst.h>
70

71 72
#define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING

73 74
static guint _num_static_plugins;       /* 0    */
static GstPluginDesc *_static_plugins;  /* NULL */
75
static gboolean _gst_plugin_inited;
76
static gchar **_plugin_loading_whitelist;       /* NULL */
77

78 79
/* static variables for segfault handling of plugin loading */
static char *_gst_plugin_fault_handler_filename = NULL;
80

81
/* list of valid licenses.
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
82 83
 * One of these must be specified or the plugin won't be loaded
 * Contact gstreamer-devel@lists.sourceforge.net if your license should be
84 85 86 87 88
 * added.
 *
 * GPL: http://www.gnu.org/copyleft/gpl.html
 * LGPL: http://www.gnu.org/copyleft/lesser.html
 * QPL: http://www.trolltech.com/licenses/qpl.html
89
 * MPL: http://www.opensource.org/licenses/mozilla1.1.php
90 91
 * MIT/X11: http://www.opensource.org/licenses/mit-license.php
 * 3-clause BSD: http://www.opensource.org/licenses/bsd-license.php
92
 */
93
static const gchar *valid_licenses[] = {
94 95 96 97
  "LGPL",                       /* GNU Lesser General Public License */
  "GPL",                        /* GNU General Public License */
  "QPL",                        /* Trolltech Qt Public License */
  "GPL/QPL",                    /* Combi-license of GPL + QPL */
98
  "MPL",                        /* MPL 1.1 license */
99 100
  "BSD",                        /* 3-clause BSD license */
  "MIT/X11",                    /* MIT/X11 license */
101
  "Proprietary",                /* Proprietary license */
102
  GST_LICENSE_UNKNOWN,          /* some other license */
103 104 105
  NULL
};

106
static GstPlugin *gst_plugin_register_func (GstPlugin * plugin,
107
    const GstPluginDesc * desc, gpointer user_data);
108 109
static void gst_plugin_desc_copy (GstPluginDesc * dest,
    const GstPluginDesc * src);
110

111
static void gst_plugin_ext_dep_free (GstPluginDep * dep);
David Schleef's avatar
remove  
David Schleef committed
112

113
G_DEFINE_TYPE (GstPlugin, gst_plugin, GST_TYPE_OBJECT);
David Schleef's avatar
remove  
David Schleef committed
114 115 116

static void
gst_plugin_init (GstPlugin * plugin)
David Schleef's avatar
David Schleef committed
117
{
118 119
  plugin->priv =
      G_TYPE_INSTANCE_GET_PRIVATE (plugin, GST_TYPE_PLUGIN, GstPluginPrivate);
David Schleef's avatar
David Schleef committed
120 121
}

David Schleef's avatar
remove  
David Schleef committed
122
static void
123
gst_plugin_finalize (GObject * object)
124
{
125
  GstPlugin *plugin = GST_PLUGIN_CAST (object);
126 127
  GstRegistry *registry = gst_registry_get_default ();
  GList *g;
128

129
  GST_DEBUG ("finalizing plugin %" GST_PTR_FORMAT, plugin);
130 131 132 133 134
  for (g = registry->plugins; g; g = g->next) {
    if (g->data == (gpointer) plugin) {
      g_warning ("removing plugin that is still in registry");
    }
  }
135
  g_free (plugin->filename);
136
  g_free (plugin->basename);
137

138 139 140 141
  g_list_foreach (plugin->priv->deps, (GFunc) gst_plugin_ext_dep_free, NULL);
  g_list_free (plugin->priv->deps);
  plugin->priv->deps = NULL;

142 143 144 145
  if (plugin->priv->cache_data) {
    gst_structure_free (plugin->priv->cache_data);
  }

146
  G_OBJECT_CLASS (gst_plugin_parent_class)->finalize (object);
147 148
}

149 150 151
static void
gst_plugin_class_init (GstPluginClass * klass)
{
152
  G_OBJECT_CLASS (klass)->finalize = gst_plugin_finalize;
153 154

  g_type_class_add_private (klass, sizeof (GstPluginPrivate));
155
}
David Schleef's avatar
remove  
David Schleef committed
156

157
GQuark
158 159 160
gst_plugin_error_quark (void)
{
  static GQuark quark = 0;
161

162 163 164 165 166
  if (!quark)
    quark = g_quark_from_static_string ("gst_plugin_error");
  return quark;
}

167
#ifndef GST_REMOVE_DEPRECATED
168 169 170
#ifdef GST_DISABLE_DEPRECATED
void _gst_plugin_register_static (GstPluginDesc * desc);
#endif
171
/* this function can be called in the GCC constructor extension, before
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
172
 * the _gst_plugin_initialize() was called. In that case, we store the
173 174 175
 * plugin description in a list to initialize it when we open the main
 * module later on.
 * When the main module is known, we can register the plugin right away.
176
 */
177
void
178
_gst_plugin_register_static (GstPluginDesc * desc)
179
{
180 181
  g_return_if_fail (desc != NULL);

182
  if (!_gst_plugin_inited) {
183 184 185 186 187 188 189 190
    /* We can't use any GLib functions here, since g_thread_init hasn't been
     * called yet, and we can't call it here either, or programs that don't
     * guard their g_thread_init calls in main() will just abort */
    ++_num_static_plugins;
    _static_plugins =
        realloc (_static_plugins, _num_static_plugins * sizeof (GstPluginDesc));
    /* assume strings in the GstPluginDesc are static const or live forever */
    _static_plugins[_num_static_plugins - 1] = *desc;
191
  } else {
192 193 194
    gst_plugin_register_static (desc->major_version, desc->minor_version,
        desc->name, desc->description, desc->plugin_init, desc->version,
        desc->license, desc->source, desc->package, desc->origin);
195 196 197
  }
}
#endif
198

199 200
/**
 * gst_plugin_register_static:
201 202 203 204 205 206 207 208
 * @major_version: the major version number of the GStreamer core that the
 *     plugin was compiled for, you can just use GST_VERSION_MAJOR here
 * @minor_version: the minor version number of the GStreamer core that the
 *     plugin was compiled for, you can just use GST_VERSION_MINOR here
 * @name: a unique name of the plugin (ideally prefixed with an application- or
 *     library-specific namespace prefix in order to avoid name conflicts in
 *     case a similar plugin with the same name ever gets added to GStreamer)
 * @description: description of the plugin
209
 * @init_func: (scope call): pointer to the init function of this plugin.
210 211 212 213 214 215
 * @version: version string of the plugin
 * @license: effective license of plugin. Must be one of the approved licenses
 *     (see #GstPluginDesc above) or the plugin will not be registered.
 * @source: source module plugin belongs to
 * @package: shipped package plugin belongs to
 * @origin: URL to provider of plugin
216 217 218 219 220 221 222 223 224 225 226 227 228
 *
 * Registers a static plugin, ie. a plugin which is private to an application
 * or library and contained within the application or library (as opposed to
 * being shipped as a separate module file).
 *
 * You must make sure that GStreamer has been initialised (with gst_init() or
 * via gst_init_get_option_group()) before calling this function.
 *
 * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
 *
 * Since: 0.10.16
 */
gboolean
229
gst_plugin_register_static (gint major_version, gint minor_version,
Benjamin Otte's avatar
Benjamin Otte committed
230
    const gchar * name, const gchar * description, GstPluginInitFunc init_func,
231 232
    const gchar * version, const gchar * license, const gchar * source,
    const gchar * package, const gchar * origin)
233
{
234
  GstPluginDesc desc = { major_version, minor_version, name, description,
235
    init_func, version, license, source, package, origin, NULL,
236
  };
237 238 239
  GstPlugin *plugin;
  gboolean res = FALSE;

240 241 242 243 244 245 246 247
  g_return_val_if_fail (name != NULL, FALSE);
  g_return_val_if_fail (description != NULL, FALSE);
  g_return_val_if_fail (init_func != NULL, FALSE);
  g_return_val_if_fail (version != NULL, FALSE);
  g_return_val_if_fail (license != NULL, FALSE);
  g_return_val_if_fail (source != NULL, FALSE);
  g_return_val_if_fail (package != NULL, FALSE);
  g_return_val_if_fail (origin != NULL, FALSE);
248 249 250 251

  /* make sure gst_init() has been called */
  g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);

252
  GST_LOG ("attempting to load static plugin \"%s\" now...", name);
253
  plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
  if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) {
    GST_INFO ("registered static plugin \"%s\"", name);
    res = gst_default_registry_add_plugin (plugin);
    GST_INFO ("added static plugin \"%s\", result: %d", name, res);
  }
  return res;
}

/**
 * gst_plugin_register_static_full:
 * @major_version: the major version number of the GStreamer core that the
 *     plugin was compiled for, you can just use GST_VERSION_MAJOR here
 * @minor_version: the minor version number of the GStreamer core that the
 *     plugin was compiled for, you can just use GST_VERSION_MINOR here
 * @name: a unique name of the plugin (ideally prefixed with an application- or
 *     library-specific namespace prefix in order to avoid name conflicts in
 *     case a similar plugin with the same name ever gets added to GStreamer)
 * @description: description of the plugin
272 273
 * @init_full_func: (scope call): pointer to the init function with user data
 *     of this plugin.
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
 * @version: version string of the plugin
 * @license: effective license of plugin. Must be one of the approved licenses
 *     (see #GstPluginDesc above) or the plugin will not be registered.
 * @source: source module plugin belongs to
 * @package: shipped package plugin belongs to
 * @origin: URL to provider of plugin
 * @user_data: gpointer to user data
 *
 * Registers a static plugin, ie. a plugin which is private to an application
 * or library and contained within the application or library (as opposed to
 * being shipped as a separate module file) with a #GstPluginInitFullFunc
 * which allows user data to be passed to the callback function (useful
 * for bindings).
 *
 * You must make sure that GStreamer has been initialised (with gst_init() or
 * via gst_init_get_option_group()) before calling this function.
 *
 * Returns: TRUE if the plugin was registered correctly, otherwise FALSE.
 *
 * Since: 0.10.24
 *
 */
gboolean
gst_plugin_register_static_full (gint major_version, gint minor_version,
Benjamin Otte's avatar
Benjamin Otte committed
298
    const gchar * name, const gchar * description,
299 300 301 302 303 304
    GstPluginInitFullFunc init_full_func, const gchar * version,
    const gchar * license, const gchar * source, const gchar * package,
    const gchar * origin, gpointer user_data)
{
  GstPluginDesc desc = { major_version, minor_version, name, description,
    (GstPluginInitFunc) init_full_func, version, license, source, package,
305
    origin, NULL,
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
  };
  GstPlugin *plugin;
  gboolean res = FALSE;

  g_return_val_if_fail (name != NULL, FALSE);
  g_return_val_if_fail (description != NULL, FALSE);
  g_return_val_if_fail (init_full_func != NULL, FALSE);
  g_return_val_if_fail (version != NULL, FALSE);
  g_return_val_if_fail (license != NULL, FALSE);
  g_return_val_if_fail (source != NULL, FALSE);
  g_return_val_if_fail (package != NULL, FALSE);
  g_return_val_if_fail (origin != NULL, FALSE);

  /* make sure gst_init() has been called */
  g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);

  GST_LOG ("attempting to load static plugin \"%s\" now...", name);
323
  plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
324
  if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) {
325
    GST_INFO ("registered static plugin \"%s\"", name);
326
    res = gst_default_registry_add_plugin (plugin);
327
    GST_INFO ("added static plugin \"%s\", result: %d", name, res);
328
  }
329
  return res;
330 331 332 333 334
}

void
_gst_plugin_initialize (void)
{
335
  const gchar *whitelist;
336 337
  guint i;

338
  _gst_plugin_inited = TRUE;
339

340 341 342 343 344 345 346 347 348
  whitelist = g_getenv ("GST_PLUGIN_LOADING_WHITELIST");
  if (whitelist != NULL && *whitelist != '\0') {
    _plugin_loading_whitelist = g_strsplit (whitelist,
        G_SEARCHPATH_SEPARATOR_S, -1);
    for (i = 0; _plugin_loading_whitelist[i] != NULL; ++i) {
      GST_INFO ("plugins whitelist entry: %s", _plugin_loading_whitelist[i]);
    }
  }

349
  /* now register all static plugins */
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
  GST_INFO ("registering %u static plugins", _num_static_plugins);
  for (i = 0; i < _num_static_plugins; ++i) {
    gst_plugin_register_static (_static_plugins[i].major_version,
        _static_plugins[i].minor_version, _static_plugins[i].name,
        _static_plugins[i].description, _static_plugins[i].plugin_init,
        _static_plugins[i].version, _static_plugins[i].license,
        _static_plugins[i].source, _static_plugins[i].package,
        _static_plugins[i].origin);
  }

  if (_static_plugins) {
    free (_static_plugins);
    _static_plugins = NULL;
    _num_static_plugins = 0;
  }
365 366
}

367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
/* Whitelist entry format:
 *
 *   plugin1,plugin2@pathprefix or
 *   plugin1,plugin2@* or just
 *   plugin1,plugin2 or
 *   source-package@pathprefix or
 *   source-package@* or just
 *   source-package
 *
 * ie. the bit before the path will be checked against both the plugin
 * name and the plugin's source package name, to keep the format simple.
 */
static gboolean
gst_plugin_desc_matches_whitelist_entry (GstPluginDesc * desc,
    const gchar * filename, const gchar * pattern)
{
  const gchar *sep;
  gboolean ret = FALSE;
  gchar *name;

  GST_LOG ("Whitelist pattern '%s', plugin: %s of %s@%s", pattern, desc->name,
      desc->source, GST_STR_NULL (filename));

  /* do we have a path prefix? */
  sep = strchr (pattern, '@');
  if (sep != NULL && strcmp (sep, "@*") != 0 && strcmp (sep, "@") != 0) {
    /* paths are not canonicalised or treated with realpath() here. This
     * should be good enough for our use case, since we just use the paths
     * autotools uses, and those will be constructed from the same prefix. */
    if (filename != NULL && !g_str_has_prefix (filename, sep + 1))
      return FALSE;

    GST_LOG ("%s matches path prefix %s", GST_STR_NULL (filename), sep + 1);
  }

  if (sep != NULL) {
    name = g_strndup (pattern, (gsize) (sep - pattern));
  } else {
    name = g_strdup (pattern);
  }

  g_strstrip (name);
  if (!g_ascii_isalnum (*name)) {
    GST_WARNING ("Invalid whitelist pattern: %s", pattern);
    goto done;
  }

  /* now check plugin names / source package name */
  if (strchr (name, ',') == NULL) {
    /* only a single name: either a plugin name or the source package name */
    ret = (strcmp (desc->source, name) == 0 || strcmp (desc->name, name) == 0);
  } else {
    gchar **n, **names;

    /* multiple names: assume these are plugin names */
    names = g_strsplit (name, ",", -1);
    for (n = names; n != NULL && *n != NULL; ++n) {
      g_strstrip (*n);
      if (strcmp (desc->name, *n) == 0) {
        ret = TRUE;
        break;
      }
    }
    g_strfreev (names);
  }

  GST_LOG ("plugin / source package name match: %d", ret);

done:

  g_free (name);
  return ret;
}

gboolean
priv_gst_plugin_desc_is_whitelisted (GstPluginDesc * desc,
    const gchar * filename)
{
  gchar **entry;

  if (_plugin_loading_whitelist == NULL)
    return TRUE;

  for (entry = _plugin_loading_whitelist; *entry != NULL; ++entry) {
    if (gst_plugin_desc_matches_whitelist_entry (desc, filename, *entry)) {
      GST_LOG ("Plugin %s is in whitelist", filename);
      return TRUE;
    }
  }

  GST_LOG ("Plugin %s (package %s, file %s) not in whitelist", desc->name,
      desc->source, filename);
  return FALSE;
}

gboolean
priv_gst_plugin_loading_have_whitelist (void)
{
  return (_plugin_loading_whitelist != NULL);
}

468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
guint32
priv_gst_plugin_loading_get_whitelist_hash (void)
{
  guint32 hash = 0;

  if (_plugin_loading_whitelist != NULL) {
    gchar **w;

    for (w = _plugin_loading_whitelist; *w != NULL; ++w)
      hash = (hash << 1) ^ g_str_hash (*w);
  }

  return hash;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
483
/* this function could be extended to check if the plugin license matches the
484 485 486 487
 * applications license (would require the app to register its license somehow).
 * We'll wait for someone who's interested in it to code it :)
 */
static gboolean
488
gst_plugin_check_license (const gchar * license)
489
{
490
  const gchar **check_license = valid_licenses;
491 492

  g_assert (check_license);
493

494 495 496 497 498 499 500 501
  while (*check_license) {
    if (strcmp (license, *check_license) == 0)
      return TRUE;
    check_license++;
  }
  return FALSE;
}

502 503 504
static gboolean
gst_plugin_check_version (gint major, gint minor)
{
505 506
  /* return NULL if the major and minor version numbers are not compatible */
  /* with ours. */
507
  if (major != GST_VERSION_MAJOR || minor != GST_VERSION_MINOR)
508 509 510 511 512
    return FALSE;

  return TRUE;
}

513
static GstPlugin *
514 515
gst_plugin_register_func (GstPlugin * plugin, const GstPluginDesc * desc,
    gpointer user_data)
516 517
{
  if (!gst_plugin_check_version (desc->major_version, desc->minor_version)) {
518
    if (GST_CAT_DEFAULT)
519
      GST_WARNING ("plugin \"%s\" has incompatible version, not loading",
520
          plugin->filename);
521
    return NULL;
522 523
  }

524 525
  if (!desc->license || !desc->description || !desc->source ||
      !desc->package || !desc->origin) {
526
    if (GST_CAT_DEFAULT)
527
      GST_WARNING ("plugin \"%s\" has incorrect GstPluginDesc, not loading",
528
          plugin->filename);
529
    return NULL;
530
  }
531

532
  if (!gst_plugin_check_license (desc->license)) {
533
    if (GST_CAT_DEFAULT)
534
      GST_WARNING ("plugin \"%s\" has invalid license \"%s\", not loading",
535
          plugin->filename, desc->license);
536
    return NULL;
537
  }
538

539 540 541
  if (GST_CAT_DEFAULT)
    GST_LOG ("plugin \"%s\" looks good", GST_STR_NULL (plugin->filename));

542
  gst_plugin_desc_copy (&plugin->desc, desc);
Wim Taymans's avatar
Wim Taymans committed
543

544 545 546 547 548 549
  /* make resident so we're really sure it never gets unloaded again.
   * Theoretically this is not needed, but practically it doesn't hurt.
   * And we're rather safe than sorry. */
  if (plugin->module)
    g_module_make_resident (plugin->module);

550 551 552 553 554 555 556 557 558 559 560 561
  if (user_data) {
    if (!(((GstPluginInitFullFunc) (desc->plugin_init)) (plugin, user_data))) {
      if (GST_CAT_DEFAULT)
        GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
      return NULL;
    }
  } else {
    if (!((desc->plugin_init) (plugin))) {
      if (GST_CAT_DEFAULT)
        GST_WARNING ("plugin \"%s\" failed to initialise", plugin->filename);
      return NULL;
    }
562
  }
563 564 565

  if (GST_CAT_DEFAULT)
    GST_LOG ("plugin \"%s\" initialised", GST_STR_NULL (plugin->filename));
566

567 568 569
  return plugin;
}

570
#ifdef HAVE_SIGACTION
571
static struct sigaction oldaction;
572
static gboolean _gst_plugin_fault_handler_is_setup = FALSE;
573

574
/*
575 576 577 578 579 580
 * _gst_plugin_fault_handler_restore:
 * segfault handler restorer
 */
static void
_gst_plugin_fault_handler_restore (void)
{
581
  if (!_gst_plugin_fault_handler_is_setup)
582 583
    return;

584
  _gst_plugin_fault_handler_is_setup = FALSE;
585

586
  sigaction (SIGSEGV, &oldaction, NULL);
587 588
}

589
/*
590 591 592 593 594 595 596 597 598
 * _gst_plugin_fault_handler_sighandler:
 * segfault handler implementation
 */
static void
_gst_plugin_fault_handler_sighandler (int signum)
{
  /* We need to restore the fault handler or we'll keep getting it */
  _gst_plugin_fault_handler_restore ();

599
  switch (signum) {
600
    case SIGSEGV:
601
      g_print ("\nERROR: ");
602 603 604 605
      g_print ("Caught a segmentation fault while loading plugin file:\n");
      g_print ("%s\n\n", _gst_plugin_fault_handler_filename);
      g_print ("Please either:\n");
      g_print ("- remove it and restart.\n");
606 607
      g_print
          ("- run with --gst-disable-segtrap --gst-disable-registry-fork and debug.\n");
608 609 610 611 612 613 614 615
      exit (-1);
      break;
    default:
      g_print ("Caught unhandled signal on plugin loading\n");
      break;
  }
}

616
/*
617 618 619 620 621 622 623 624 625
 * _gst_plugin_fault_handler_setup:
 * sets up the segfault handler
 */
static void
_gst_plugin_fault_handler_setup (void)
{
  struct sigaction action;

  /* if asked to leave segfaults alone, just return */
626
  if (!gst_segtrap_is_enabled ())
627
    return;
628

629 630
  if (_gst_plugin_fault_handler_is_setup)
    return;
631

632 633
  _gst_plugin_fault_handler_is_setup = TRUE;

634 635 636
  memset (&action, 0, sizeof (action));
  action.sa_handler = _gst_plugin_fault_handler_sighandler;

637
  sigaction (SIGSEGV, &action, &oldaction);
638
}
639
#else /* !HAVE_SIGACTION */
640 641 642 643 644 645 646 647 648
static void
_gst_plugin_fault_handler_restore (void)
{
}

static void
_gst_plugin_fault_handler_setup (void)
{
}
649
#endif /* HAVE_SIGACTION */
650

651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
/* g_time_val_from_iso8601() doesn't do quite what we want */
static gboolean
check_release_datetime (const gchar * date_time)
{
  guint64 val;

  /* we require YYYY-MM-DD or YYYY-MM-DDTHH:MMZ format */
  if (!g_ascii_isdigit (*date_time))
    return FALSE;

  val = g_ascii_strtoull (date_time, (gchar **) & date_time, 10);
  if (val < 2000 || val > 2100 || *date_time != '-')
    return FALSE;

  val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
  if (val == 0 || val > 12 || *date_time != '-')
    return FALSE;

  val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
  if (val == 0 || val > 32)
    return FALSE;

  /* end of string or date/time separator + HH:MMZ */
  if (*date_time == 'T' || *date_time == ' ') {
    val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
    if (val > 24 || *date_time != ':')
      return FALSE;

    val = g_ascii_strtoull (date_time + 1, (gchar **) & date_time, 10);
    if (val > 59 || *date_time != 'Z')
      return FALSE;

    ++date_time;
  }

  return (*date_time == '\0');
}

689
static GStaticMutex gst_plugin_loading_mutex = G_STATIC_MUTEX_INIT;
690

691 692 693 694 695
#define CHECK_PLUGIN_DESC_FIELD(desc,field,fn)                               \
  if (G_UNLIKELY ((desc)->field == NULL)) {                                  \
    GST_ERROR ("GstPluginDesc for '%s' has no %s", fn, G_STRINGIFY (field)); \
  }

696
/**
David Schleef's avatar
remove  
David Schleef committed
697 698
 * gst_plugin_load_file:
 * @filename: the plugin filename to load
699 700
 * @error: pointer to a NULL-valued GError
 *
701
 * Loads the given plugin and refs it.  Caller needs to unref after use.
702
 *
703 704
 * Returns: (transfer full): a reference to the existing loaded GstPlugin, a 
 * reference to the newly-loaded GstPlugin, or NULL if an error occurred.
705
 */
David Schleef's avatar
remove  
David Schleef committed
706 707
GstPlugin *
gst_plugin_load_file (const gchar * filename, GError ** error)
708
{
709
  GstPluginDesc *desc;
David Schleef's avatar
remove  
David Schleef committed
710 711 712
  GstPlugin *plugin;
  GModule *module;
  gboolean ret;
713
  gpointer ptr;
714
  GStatBuf file_status;
715
  GstRegistry *registry;
716
  gboolean new_plugin = TRUE;
717
  GModuleFlags flags;
718

David Schleef's avatar
remove  
David Schleef committed
719
  g_return_val_if_fail (filename != NULL, NULL);
720

721 722 723 724
  registry = gst_registry_get_default ();
  g_static_mutex_lock (&gst_plugin_loading_mutex);

  plugin = gst_registry_lookup (registry, filename);
725 726
  if (plugin) {
    if (plugin->module) {
727
      /* already loaded */
728 729 730
      g_static_mutex_unlock (&gst_plugin_loading_mutex);
      return plugin;
    } else {
731 732
      /* load plugin and update fields */
      new_plugin = FALSE;
733
    }
734 735
  }

David Schleef's avatar
remove  
David Schleef committed
736 737
  GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "attempt to load plugin \"%s\"",
      filename);
738 739

  if (g_module_supported () == FALSE) {
David Schleef's avatar
remove  
David Schleef committed
740
    GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "module loading not supported");
741 742 743
    g_set_error (error,
        GST_PLUGIN_ERROR,
        GST_PLUGIN_ERROR_MODULE, "Dynamic loading not supported");
744
    goto return_error;
745 746
  }

747
  if (g_stat (filename, &file_status)) {
David Schleef's avatar
remove  
David Schleef committed
748
    GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "problem accessing file");
749 750
    g_set_error (error,
        GST_PLUGIN_ERROR,
751 752
        GST_PLUGIN_ERROR_MODULE, "Problem accessing file %s: %s", filename,
        g_strerror (errno));
753
    goto return_error;
754 755
  }

756 757 758 759 760 761 762
  flags = G_MODULE_BIND_LOCAL;
  /* libgstpython.so is the gst-python plugin loader. It needs to be loaded with
   * G_MODULE_BIND_LAZY.
   *
   * Ideally there should be a generic way for plugins to specify that they
   * need to be loaded with _LAZY.
   * */
763
  if (strstr (filename, "libgstpython"))
764
    flags |= G_MODULE_BIND_LAZY;
765

766
  module = g_module_open (filename, flags);
David Schleef's avatar
remove  
David Schleef committed
767
  if (module == NULL) {
768
    GST_CAT_WARNING (GST_CAT_PLUGIN_LOADING, "module_open failed: %s",
David Schleef's avatar
remove  
David Schleef committed
769 770
        g_module_error ());
    g_set_error (error,
771 772
        GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE, "Opening module failed: %s",
        g_module_error ());
773 774 775
    /* If we failed to open the shared object, then it's probably because a
     * plugin is linked against the wrong libraries. Print out an easy-to-see
     * message in this case. */
776
    g_warning ("Failed to load plugin '%s': %s", filename, g_module_error ());
777
    goto return_error;
778
  }
779

David Schleef's avatar
remove  
David Schleef committed
780 781 782 783 784 785
  ret = g_module_symbol (module, "gst_plugin_desc", &ptr);
  if (!ret) {
    GST_DEBUG ("Could not find plugin entry point in \"%s\"", filename);
    g_set_error (error,
        GST_PLUGIN_ERROR,
        GST_PLUGIN_ERROR_MODULE,
786
        "File \"%s\" is not a GStreamer plugin", filename);
787
    g_module_close (module);
788
    goto return_error;
789
  }
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812

  desc = (GstPluginDesc *) ptr;

  if (priv_gst_plugin_loading_have_whitelist () &&
      !priv_gst_plugin_desc_is_whitelisted (desc, filename)) {
    GST_INFO ("Whitelist specified and plugin not in whitelist, not loading: "
        "name=%s, package=%s, file=%s", desc->name, desc->source, filename);
    g_set_error (error, GST_PLUGIN_ERROR, GST_PLUGIN_ERROR_MODULE,
        "Not loading plugin file \"%s\", not in whitelist", filename);
    g_module_close (module);
    goto return_error;
  }

  if (new_plugin) {
    plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
    plugin->file_mtime = file_status.st_mtime;
    plugin->file_size = file_status.st_size;
    plugin->filename = g_strdup (filename);
    plugin->basename = g_path_get_basename (filename);
  }

  plugin->module = module;
  plugin->orig_desc = desc;
813

814 815 816 817 818 819 820 821 822 823
  if (new_plugin) {
    /* check plugin description: complain about bad values but accept them, to
     * maintain backwards compatibility (FIXME: 0.11) */
    CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, name, filename);
    CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, description, filename);
    CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, version, filename);
    CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, license, filename);
    CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, source, filename);
    CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, package, filename);
    CHECK_PLUGIN_DESC_FIELD (plugin->orig_desc, origin, filename);
824 825 826 827 828 829 830

    if (plugin->orig_desc->release_datetime != NULL &&
        !check_release_datetime (plugin->orig_desc->release_datetime)) {
      GST_ERROR ("GstPluginDesc for '%s' has invalid datetime '%s'",
          filename, plugin->orig_desc->release_datetime);
      plugin->orig_desc->release_datetime = NULL;
    }
831
  }
832

833 834 835 836 837 838 839
  GST_LOG ("Plugin %p for file \"%s\" prepared, calling entry function...",
      plugin, filename);

  /* this is where we load the actual .so, so let's trap SIGSEGV */
  _gst_plugin_fault_handler_setup ();
  _gst_plugin_fault_handler_filename = plugin->filename;

840 841 842
  GST_LOG ("Plugin %p for file \"%s\" prepared, registering...",
      plugin, filename);

843
  if (!gst_plugin_register_func (plugin, plugin->orig_desc, NULL)) {
844 845 846 847 848 849 850
    /* remove signal handler */
    _gst_plugin_fault_handler_restore ();
    GST_DEBUG ("gst_plugin_register_func failed for plugin \"%s\"", filename);
    /* plugin == NULL */
    g_set_error (error,
        GST_PLUGIN_ERROR,
        GST_PLUGIN_ERROR_MODULE,
851 852
        "File \"%s\" appears to be a GStreamer plugin, but it failed to initialize",
        filename);
853
    goto return_error;
Wim Taymans's avatar
Wim Taymans committed
854
  }
David Schleef's avatar
remove  
David Schleef committed
855 856 857 858 859 860

  /* remove signal handler */
  _gst_plugin_fault_handler_restore ();
  _gst_plugin_fault_handler_filename = NULL;
  GST_INFO ("plugin \"%s\" loaded", plugin->filename);

861 862 863 864
  if (new_plugin) {
    gst_object_ref (plugin);
    gst_default_registry_add_plugin (plugin);
  }
David Schleef's avatar
remove  
David Schleef committed
865

866
  g_static_mutex_unlock (&gst_plugin_loading_mutex);
David Schleef's avatar
remove  
David Schleef committed
867
  return plugin;
868

869
return_error:
870 871 872 873 874 875
  {
    if (plugin)
      gst_object_unref (plugin);
    g_static_mutex_unlock (&gst_plugin_loading_mutex);
    return NULL;
  }
Erik Walthinsen's avatar
Erik Walthinsen committed
876 877
}

878
static void
879
gst_plugin_desc_copy (GstPluginDesc * dest, const GstPluginDesc * src)
880 881 882
{
  dest->major_version = src->major_version;
  dest->minor_version = src->minor_version;
883
  dest->name = g_intern_string (src->name);
Benjamin Otte's avatar
Benjamin Otte committed
884
  dest->description = g_intern_string (src->description);
885
  dest->plugin_init = src->plugin_init;
886 887 888 889 890
  dest->version = g_intern_string (src->version);
  dest->license = g_intern_string (src->license);
  dest->source = g_intern_string (src->source);
  dest->package = g_intern_string (src->package);
  dest->origin = g_intern_string (src->origin);
891
  dest->release_datetime = g_intern_string (src->release_datetime);
892
}
893

Wim Taymans's avatar
Wim Taymans committed
894 895 896 897 898 899 900 901
/**
 * gst_plugin_get_name:
 * @plugin: plugin to get the name of
 *
 * Get the short name of the plugin
 *
 * Returns: the name of the plugin
 */
902 903
const gchar *
gst_plugin_get_name (GstPlugin * plugin)
Wim Taymans's avatar
Wim Taymans committed
904 905 906
{
  g_return_val_if_fail (plugin != NULL, NULL);

907
  return plugin->desc.name;
Wim Taymans's avatar
Wim Taymans committed
908 909 910
}

/**
911
 * gst_plugin_get_description:
912
 * @plugin: plugin to get long name of
Wim Taymans's avatar
Wim Taymans committed
913
 *
914 915 916
 * Get the long descriptive name of the plugin
 *
 * Returns: the long name of the plugin
Wim Taymans's avatar
Wim Taymans committed
917
 */
918
const gchar *
919
gst_plugin_get_description (GstPlugin * plugin)
Wim Taymans's avatar
Wim Taymans committed
920
{
921
  g_return_val_if_fail (plugin != NULL, NULL);
Wim Taymans's avatar
Wim Taymans committed
922

923
  return plugin->desc.description;
Wim Taymans's avatar
Wim Taymans committed
924 925
}

Erik Walthinsen's avatar
Erik Walthinsen committed
926
/**
927 928 929 930
 * gst_plugin_get_filename:
 * @plugin: plugin to get the filename of
 *
 * get the filename of the plugin
Erik Walthinsen's avatar
Erik Walthinsen committed
931
 *
932
 * Returns: the filename of the plugin
Erik Walthinsen's avatar
Erik Walthinsen committed
933
 */
934
const gchar *
935
gst_plugin_get_filename (GstPlugin * plugin)
936
{
937
  g_return_val_if_fail (plugin != NULL, NULL);
Wim Taymans's avatar
Wim Taymans committed
938

939
  return plugin->filename;
Erik Walthinsen's avatar
Erik Walthinsen committed
940
}
941

942 943 944 945 946 947 948 949
/**
 * gst_plugin_get_version:
 * @plugin: plugin to get the version of
 *
 * get the version of the plugin
 *
 * Returns: the version of the plugin
 */
950
const gchar *
951 952 953 954 955 956 957
gst_plugin_get_version (GstPlugin * plugin)
{
  g_return_val_if_fail (plugin != NULL, NULL);

  return plugin->desc.version;
}

958 959 960 961 962 963 964 965
/**
 * gst_plugin_get_license:
 * @plugin: plugin to get the license of
 *
 * get the license of the plugin
 *
 * Returns: the license of the plugin
 */
966
const gchar *
967
gst_plugin_get_license (GstPlugin * plugin)
968 969
{
  g_return_val_if_fail (plugin != NULL, NULL);
Erik Walthinsen's avatar
Erik Walthinsen committed
970

971 972
  return plugin->desc.license;
}
973

974 975 976 977 978 979 980 981
/**
 * gst_plugin_get_source:
 * @plugin: plugin to get the source of
 *
 * get the source module the plugin belongs to.
 *
 * Returns: the source of the plugin
 */
982
const gchar *
983 984 985 986 987 988 989
gst_plugin_get_source (GstPlugin * plugin)
{
  g_return_val_if_fail (plugin != NULL, NULL);

  return plugin->desc.source;
}

990 991 992 993 994 995 996 997
/**
 * gst_plugin_get_package:
 * @plugin: plugin to get the package of
 *
 * get the package the plugin belongs to.
 *
 * Returns: the package of the plugin
 */
998
const gchar *
999
gst_plugin_get_package (GstPlugin * plugin)
1000 1001
{
  g_return_val_if_fail (plugin != NULL, NULL);
Wim Taymans's avatar
Wim Taymans committed
1002

1003 1004
  return plugin->desc.package;
}
1005

Wim Taymans's avatar
Wim Taymans committed
1006
/**
1007 1008
 * gst_plugin_get_origin:
 * @plugin: plugin to get the origin of
Wim Taymans's avatar
Wim Taymans committed
1009
 *
1010
 * get the URL where the plugin comes from
Wim Taymans's avatar
Wim Taymans committed
1011
 *
1012
 * Returns: the origin of the plugin
Wim Taymans's avatar
Wim Taymans committed
1013
 */
1014
const gchar *
1015
gst_plugin_get_origin (GstPlugin * plugin)
Wim Taymans's avatar
Wim Taymans committed
1016 1017 1018
{
  g_return_val_if_fail (plugin != NULL, NULL);

1019
  return plugin->desc.origin;
Wim Taymans's avatar
Wim Taymans committed
1020
}
1021

1022 1023 1024 1025
/**
 * gst_plugin_get_module:
 * @plugin: plugin to query
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1026
 * Gets the #GModule of the plugin. If the plugin isn't loaded yet, NULL is
1027 1028
 * returned.
 *
1029 1030
 * Returns: (transfer none): module belonging to the plugin or NULL if the
 *          plugin isn't loaded yet.
1031 1032
 */
GModule *
1033
gst_plugin_get_module (GstPlugin * plugin)
1034
{
1035
  g_return_val_if_fail (plugin != NULL, NULL);
Wim Taymans's avatar
Wim Taymans committed
1036

1037 1038
  return plugin->module;
}
1039

Wim Taymans's avatar
Wim Taymans committed
1040 1041 1042 1043 1044 1045 1046 1047 1048
/**
 * gst_plugin_is_loaded:
 * @plugin: plugin to query
 *
 * queries if the plugin is loaded into memory
 *
 * Returns: TRUE is loaded, FALSE otherwise
 */
gboolean
1049
gst_plugin_is_loaded (GstPlugin * plugin)
Wim Taymans's avatar
Wim Taymans committed
1050 1051 1052
{
  g_return_val_if_fail (plugin != NULL, FALSE);

1053
  return (plugin->module != NULL || plugin->filename == NULL);
Wim Taymans's avatar
Wim Taymans committed
1054 1055
}

1056 1057 1058 1059 1060
/**
 * gst_plugin_get_cache_data:
 * @plugin: a plugin
 *
 * Gets the plugin specific data cache. If it is %NULL there is no cached data
Benjamin Otte's avatar
Benjamin Otte committed
1061
 * stored. This is the case when the registry is getting rebuilt.
1062
 *
1063
 * Returns: (transfer none): The cached data as a #GstStructure or %NULL.
1064 1065
 *
 * Since: 0.10.24
1066
 */
1067
const GstStructure *
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
gst_plugin_get_cache_data (GstPlugin * plugin)
{
  g_return_val_if_fail (GST_IS_PLUGIN (plugin), NULL);

  return plugin->priv->cache_data;
}

/**
 * gst_plugin_set_cache_data:
 * @plugin: a plugin
1078
 * @cache_data: (transfer full): a structure containing the data to cache
1079 1080 1081 1082
 *
 * Adds plugin specific data to cache. Passes the ownership of the structure to
 * the @plugin.
 *
Benjamin Otte's avatar
Benjamin Otte committed
1083
 * The cache is flushed every time the registry is rebuilt.
1084 1085
 *
 * Since: 0.10.24
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
 */
void
gst_plugin_set_cache_data (GstPlugin * plugin, GstStructure * cache_data)
{
  g_return_if_fail (GST_IS_PLUGIN (plugin));
  g_return_if_fail (GST_IS_STRUCTURE (cache_data));

  if (plugin->priv->cache_data) {
    gst_structure_free (plugin->priv->cache_data);
  }
  plugin->priv->cache_data = cache_data;
}

1099
#if 0
Wim Taymans's avatar
Wim Taymans committed
1100 1101 1102 1103 1104 1105 1106 1107
/**
 * gst_plugin_feature_list:
 * @plugin: plugin to query
 * @filter: the filter to use
 * @first: only return first match
 * @user_data: user data passed to the filter function
 *
 * Runs a filter against all plugin features and returns a GList with
1108
 * the results. If the first flag is set, only the first match is
Wim Taymans's avatar
Wim Taymans committed
1109 1110 1111 1112
 * returned (as a list with a single object).
 *
 * Returns: a GList of features, g_list_free after use.
 */
1113 1114 1115
GList *
gst_plugin_feature_filter (GstPlugin * plugin,
    GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1116
{
1117 1118 1119 1120
  GList *list;
  GList *g;

  list = gst_filter_run (plugin->features, (GstFilterFunc) filter, first,
1121
      user_data);
1122 1123 1124 1125 1126
  for (g = list; g; g = g->next) {
    gst_object_ref (plugin);
  }

  return list;
1127 1128 1129
}

typedef struct
1130
{
1131
  GstPluginFeatureFilter filter;
1132 1133 1134
  gboolean first;
  gpointer user_data;
  GList *result;
1135 1136
}
FeatureFilterData;
1137

Wim Taymans's avatar
Wim Taymans committed
1138
static gboolean
1139
_feature_filter (GstPlugin * plugin, gpointer user_data)
1140 1141 1142 1143
{
  GList *result;
  FeatureFilterData *data = (FeatureFilterData *) user_data;

1144
  result = gst_plugin_feature_filter (plugin, data->filter, data->first,
1145
      data->user_data);
1146 1147 1148 1149 1150 1151 1152
  if (result) {
    data->result = g_list_concat (data->result, result);
    return TRUE;
  }
  return FALSE;
}

Wim Taymans's avatar
Wim Taymans committed
1153
/**
1154 1155 1156
 * gst_plugin_list_feature_filter:
 * @list: a #GList of plugins to query
 * @filter: the filter function to use
Wim Taymans's avatar
Wim Taymans committed
1157 1158 1159 1160
 * @first: only return first match
 * @user_data: user data passed to the filter function
 *
 * Runs a filter against all plugin features of the plugins in the given
1161 1162
 * list and returns a GList with the results.
 * If the first flag is set, only the first match is
Wim Taymans's avatar
Wim Taymans committed
1163 1164 1165 1166
 * returned (as a list with a single object).
 *
 * Returns: a GList of features, g_list_free after use.
 */
1167 1168 1169
GList *
gst_plugin_list_feature_filter (GList * list,
    GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
{
  FeatureFilterData data;
  GList *result;

  data.filter = filter;
  data.first = first;
  data.user_data = user_data;
  data.result = NULL;

  result = gst_filter_run (list, (GstFilterFunc) _feature_filter, first, &data);
  g_list_free (result);

  return data.result;
}
1184
#endif
1185

Wim Taymans's avatar
Wim Taymans committed
1186 1187 1188 1189 1190
/**
 * gst_plugin_name_filter:
 * @plugin: the plugin to check
 * @name: the name of the plugin
 *
1191
 * A standard filter that returns TRUE when the plugin is of the
Wim Taymans's avatar
Wim Taymans committed
1192 1193 1194 1195
 * given name.
 *
 * Returns: TRUE if the plugin is of the given name.
 */
1196
gboolean
1197
gst_plugin_name_filter (GstPlugin * plugin, const gchar * name)
1198
{
1199
  return (plugin->desc.name && !strcmp