[vlc-devel] [RFC PATCH] modules: add plugins-blacklist option

Thomas Guillem thomas at gllm.fr
Wed Oct 21 19:10:47 CEST 2015


---
 src/libvlc-module.c |  5 ++++
 src/modules/bank.c  | 71 ++++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index a13093d..a959f22 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1026,6 +1026,9 @@ static const char *const ppsz_prefres[] = {
 #define PLUGINS_CACHE_LONGTEXT N_( \
     "Use a plugins cache which will greatly improve the startup time of VLC.")
 
+#define PLUGINS_BLACKLIST_TEXT N_("Blacklist plugins")
+#define PLUGINS_BLACKLIST_LONGTEXT N_("List of blacklisted plugins (won't be loaded)")
+
 #define STATS_TEXT N_("Locally collect statistics")
 #define STATS_LONGTEXT N_( \
      "Collect miscellaneous local statistics about the playing media.")
@@ -1950,6 +1953,8 @@ vlc_module_begin ()
               PLUGINS_CACHE_LONGTEXT, true )
     add_obsolete_string( "plugin-path" ) /* since 2.0.0 */
     add_obsolete_string( "data-path" ) /* since 2.1.0 */
+    add_string( "plugins-blacklist", NULL, PLUGINS_BLACKLIST_TEXT,
+                PLUGINS_BLACKLIST_LONGTEXT, true );
 
     set_section( N_("Performance options"), NULL )
 
diff --git a/src/modules/bank.c b/src/modules/bank.c
index 19292e6..8cec6aa 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -56,7 +56,7 @@ static struct
  * Local prototypes
  *****************************************************************************/
 #ifdef HAVE_DYNAMIC_PLUGINS
-static void AllocateAllPlugins (vlc_object_t *);
+static void AllocateAllPlugins (vlc_object_t *, const char *);
 #endif
 static module_t *module_InitStatic (vlc_plugin_cb);
 
@@ -75,7 +75,23 @@ __attribute__((weak))
 # endif
 extern vlc_plugin_cb vlc_static_modules[];
 
-static void module_InitStaticModules(void)
+static bool module_blacklisted(const module_t *m, const char *psz_blacklist)
+{
+    if (!psz_blacklist)
+        return false;
+    for (unsigned i = 0; i < m->i_shortcuts; i++)
+    {
+        const char *name = psz_blacklist;
+        const char *end = name + strlen(name);
+        for (size_t slen = strcspn(name, ","); name < end;
+             name += slen + 1, slen = strcspn(name, ","))
+            if (slen && strncmp(name, m->pp_shortcuts[i], slen) == 0 )
+                return true;
+    }
+    return false;
+}
+
+static void module_InitStaticModules(const char *psz_blacklist)
 {
     if (!vlc_static_modules)
         return;
@@ -83,11 +99,16 @@ static void module_InitStaticModules(void)
     for (unsigned i = 0; vlc_static_modules[i]; i++) {
         module_t *module = module_InitStatic (vlc_static_modules[i]);
         if (likely(module != NULL))
-            module_StoreBank (module);
+        {
+            if (module_blacklisted (module, psz_blacklist))
+                vlc_module_destroy (module);
+            else
+                module_StoreBank (module);
+        }
     }
 }
 #else
-static void module_InitStaticModules(void) { }
+static void module_InitStaticModules(const char *psz_blacklist) { (void) psz_blacklist; }
 #endif
 
 /**
@@ -175,14 +196,15 @@ void module_EndBank (bool b_plugins)
 size_t module_LoadPlugins (vlc_object_t *obj)
 {
     /*vlc_assert_locked (&modules.lock); not for static mutexes :( */
-
     if (modules.usage == 1)
     {
-        module_InitStaticModules ();
+        char *psz_blacklist = var_GetNonEmptyString (obj, "plugins-blacklist");
+        module_InitStaticModules (psz_blacklist);
 #ifdef HAVE_DYNAMIC_PLUGINS
         msg_Dbg (obj, "searching plug-in modules");
-        AllocateAllPlugins (obj);
+        AllocateAllPlugins (obj, psz_blacklist);
 #endif
+        free(psz_blacklist);
         config_UnsortConfig ();
         config_SortConfig ();
     }
@@ -293,7 +315,8 @@ ssize_t module_list_cap (module_t ***restrict list, const char *cap)
 #ifdef HAVE_DYNAMIC_PLUGINS
 typedef enum { CACHE_USE, CACHE_RESET, CACHE_IGNORE } cache_mode_t;
 
-static void AllocatePluginPath (vlc_object_t *, const char *, cache_mode_t);
+static void AllocatePluginPath (vlc_object_t *, const char *, cache_mode_t,
+                                const char *);
 
 /**
  * Enumerates all dynamic plug-ins that can be found.
@@ -303,7 +326,7 @@ static void AllocatePluginPath (vlc_object_t *, const char *, cache_mode_t);
  * For performance reasons, a cache is normally used so that plug-in shared
  * objects do not need to loaded and linked into the process.
  */
-static void AllocateAllPlugins (vlc_object_t *p_this)
+static void AllocateAllPlugins (vlc_object_t *p_this, const char *psz_blacklist)
 {
     char *paths;
     cache_mode_t mode;
@@ -317,7 +340,7 @@ static void AllocateAllPlugins (vlc_object_t *p_this)
 
 #if VLC_WINSTORE_APP
     /* Windows Store Apps can not load external plugins with absolute paths. */
-    AllocatePluginPath (p_this, "plugins", mode);
+    AllocatePluginPath (p_this, "plugins", mode, psz_blacklist);
 #else
     /* Contruct the special search path for system that have a relocatable
      * executable. Set it to <vlc path>/plugins. */
@@ -325,7 +348,7 @@ static void AllocateAllPlugins (vlc_object_t *p_this)
     if (likely(vlcpath != NULL)
      && likely(asprintf (&paths, "%s" DIR_SEP "plugins", vlcpath) != -1))
     {
-        AllocatePluginPath (p_this, paths, mode);
+        AllocatePluginPath (p_this, paths, mode, psz_blacklist);
         free( paths );
     }
     free (vlcpath);
@@ -343,7 +366,7 @@ static void AllocateAllPlugins (vlc_object_t *p_this)
     for( char *buf, *path = strtok_r( paths, PATH_SEP, &buf );
          path != NULL;
          path = strtok_r( NULL, PATH_SEP, &buf ) )
-        AllocatePluginPath (p_this, path, mode);
+        AllocatePluginPath (p_this, path, mode, psz_blacklist);
 
     free( paths );
 }
@@ -362,14 +385,14 @@ typedef struct module_bank
 } module_bank_t;
 
 static void AllocatePluginDir (module_bank_t *, unsigned,
-                               const char *, const char *);
+                               const char *, const char *, const char *);
 
 /**
  * Scans for plug-ins within a file system hierarchy.
  * \param path base directory to browse
  */
 static void AllocatePluginPath (vlc_object_t *p_this, const char *path,
-                                cache_mode_t mode)
+                                cache_mode_t mode, const char *psz_blacklist)
 {
     module_bank_t bank;
     module_cache_t *cache = NULL;
@@ -398,7 +421,7 @@ static void AllocatePluginPath (vlc_object_t *p_this, const char *path,
     bank.i_loaded_cache = count;
 
     /* Don't go deeper than 5 subdirectories */
-    AllocatePluginDir (&bank, 5, path, NULL);
+    AllocatePluginDir (&bank, 5, path, NULL, psz_blacklist);
 
     switch( mode )
     {
@@ -423,13 +446,14 @@ static void AllocatePluginPath (vlc_object_t *p_this, const char *path,
 }
 
 static int AllocatePluginFile (module_bank_t *, const char *,
-                               const char *, const struct stat *);
+                               const char *, const struct stat *, const char *);
 
 /**
  * Recursively browses a directory to look for plug-ins.
  */
 static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
-                               const char *absdir, const char *reldir)
+                               const char *absdir, const char *reldir,
+                               const char *psz_blacklist)
 {
     if (maxdepth == 0)
         return;
@@ -490,11 +514,11 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
             if (len > strlen (LIBEXT)
              && !strcasecmp (file + len - strlen (LIBEXT), LIBEXT))
 #endif
-                AllocatePluginFile (bank, abspath, relpath, &st);
+                AllocatePluginFile (bank, abspath, relpath, &st, psz_blacklist);
         }
         else if (S_ISDIR (st.st_mode))
             /* Recurse into another directory */
-            AllocatePluginDir (bank, maxdepth, abspath, relpath);
+            AllocatePluginDir (bank, maxdepth, abspath, relpath, psz_blacklist);
     skip:
         free (relpath);
         free (abspath);
@@ -508,7 +532,8 @@ static module_t *module_InitDynamic (vlc_object_t *, const char *, bool);
  * Scans a plug-in from a file.
  */
 static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
-                               const char *relpath, const struct stat *st)
+                               const char *relpath, const struct stat *st,
+                               const char *psz_blacklist)
 {
     module_t *module = NULL;
 
@@ -532,6 +557,12 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
     if (module == NULL)
         return -1;
 
+    if (module_blacklisted(module, psz_blacklist))
+    {
+        vlc_module_destroy (module);
+        return -1;
+    }
+
     /* We have not already scanned and inserted this module */
     assert (module->next == NULL);
 
-- 
2.1.4



More information about the vlc-devel mailing list