+/* 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 (const 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 (const 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);
+}
+
+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 ^= g_str_hash (*w);
+ }
+
+ return hash;
+}
+