]> git.sesse.net Git - vlc/blobdiff - src/modules/modules.c
Win32: fix the path to the plugins cache
[vlc] / src / modules / modules.c
index c1bf56f040e9cf2e913bfb6ecf7b8083cd94b3b3..6c6465a6ff2ea2f97e8506a53e7fbdd5c3d2fe45 100644 (file)
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #endif
-
-#if !defined(HAVE_DYNAMIC_PLUGINS)
-    /* no support for plugins */
-#elif defined(HAVE_DL_DYLD)
-#   if defined(HAVE_MACH_O_DYLD_H)
-#       include <mach-o/dyld.h>
-#   endif
-#elif defined(HAVE_DL_BEOS)
-#   if defined(HAVE_IMAGE_H)
-#       include <image.h>
-#   endif
-#elif defined(HAVE_DL_WINDOWS)
-#   include <windows.h>
-#elif defined(HAVE_DL_DLOPEN)
-#   if defined(HAVE_DLFCN_H) /* Linux, BSD, Hurd */
-#       include <dlfcn.h>
-#   endif
-#   if defined(HAVE_SYS_DL_H)
-#       include <sys/dl.h>
-#   endif
-#elif defined(HAVE_DL_SHL_LOAD)
-#   if defined(HAVE_DL_H)
-#       include <dl.h>
-#   endif
+#ifdef ENABLE_NLS
+# include <libintl.h>
 #endif
 
 #include "config/configuration.h"
 
-#include "vlc_charset.h"
+#include <vlc_fs.h>
 #include "vlc_arrays.h"
 
 #include "modules/modules.h"
@@ -105,6 +83,7 @@ static void   DupModule        ( module_t * );
 static void   UndupModule      ( module_t * );
 #endif
 
+#undef module_InitBank
 /**
  * Init bank
  *
@@ -113,7 +92,7 @@ static void   UndupModule      ( module_t * );
  * \param p_this vlc object structure
  * \return nothing
  */
-void __module_InitBank( vlc_object_t *p_this )
+void module_InitBank( vlc_object_t *p_this )
 {
     module_bank_t *p_bank = NULL;
 
@@ -138,6 +117,7 @@ void __module_InitBank( vlc_object_t *p_this )
          * as for every other module. */
         AllocateBuiltinModule( p_this, vlc_entry__main );
         vlc_rwlock_init (&config_lock);
+        config_SortConfig ();
     }
     else
         p_module_bank->i_usage++;
@@ -181,13 +161,13 @@ void module_EndBank( vlc_object_t *p_this, bool b_plugins )
         vlc_mutex_unlock( &module_lock );
         return;
     }
+
+    config_UnsortConfig ();
     vlc_rwlock_destroy (&config_lock);
     p_module_bank = NULL;
     vlc_mutex_unlock( &module_lock );
 
 #ifdef HAVE_DYNAMIC_PLUGINS
-    if( p_bank->b_cache )
-        CacheSave( p_this, p_bank );
     while( p_bank->i_loaded_cache-- )
     {
         if( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] )
@@ -221,7 +201,7 @@ void module_EndBank( vlc_object_t *p_this, bool b_plugins )
  * \param p_this vlc object structure
  * \return nothing
  */
-void module_LoadPlugins( vlc_object_t * p_this, bool b_cache_delete )
+void module_LoadPlugins( vlc_object_t * p_this )
 {
     module_bank_t *p_bank = p_module_bank;
 
@@ -234,9 +214,9 @@ void module_LoadPlugins( vlc_object_t * p_this, bool b_cache_delete )
         msg_Dbg( p_this, "checking plugin modules" );
         p_module_bank->b_cache = var_InheritBool( p_this, "plugins-cache" );
 
-        if( p_module_bank->b_cache || b_cache_delete )
-            CacheLoad( p_this, p_module_bank, b_cache_delete );
         AllocateAllPlugins( p_this, p_module_bank );
+        config_UnsortConfig ();
+        config_SortConfig ();
     }
 #endif
     vlc_mutex_unlock( &module_lock );
@@ -313,6 +293,24 @@ int module_get_score( const module_t *m )
     return m->i_score;
 }
 
+/**
+ * Translate a string using the module's text domain
+ *
+ * \param m the module
+ * \param str the American English ASCII string to localize
+ * \return the gettext-translated string
+ */
+const char *module_gettext (const module_t *m, const char *str)
+{
+#ifdef ENABLE_NLS
+    const char *domain = m->domain ? m->domain : PACKAGE_NAME;
+    return dgettext (domain, str);
+#else
+    (void)m;
+    return str;
+#endif
+}
+
 module_t *module_hold (module_t *m)
 {
     vlc_hold (&m->vlc_gc_data);
@@ -390,6 +388,7 @@ static int modulecmp (const void *a, const void *b)
     return lb->i_score - la->i_score;
 }
 
+#undef module_need
 /**
  * module Need
  *
@@ -402,8 +401,8 @@ static int modulecmp (const void *a, const void *b)
  *                 but the same capability
  * \return the module or NULL in case of a failure
  */
-module_t * __module_need( vlc_object_t *p_this, const char *psz_capability,
-                          const char *psz_name, bool b_strict )
+module_t * module_need( vlc_object_t *p_this, const char *psz_capability,
+                        const char *psz_name, bool b_strict )
 {
     stats_TimerStart( p_this, "module_need()", STATS_TIMER_MODULE_NEED );
 
@@ -591,30 +590,11 @@ found_shortcut:
                                                : p_module->psz_object_name );
     }
     else if( count == 0 )
-    {
-        if( !strcmp( psz_capability, "access_demux" )
-         || !strcmp( psz_capability, "stream_filter" )
-         || !strcmp( psz_capability, "vout_window" ) )
-        {
-            msg_Dbg( p_this, "no %s module matched \"%s\"",
-                psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
-        }
-        else
-        {
-            msg_Err( p_this, "no %s module matched \"%s\"",
+        msg_Dbg( p_this, "no %s module matched \"%s\"",
                  psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
-
-            msg_StackSet( VLC_EGENERIC, "no %s module matched \"%s\"",
-                 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
-        }
-    }
-    else if( psz_name != NULL && *psz_name )
-    {
-        msg_Warn( p_this, "no %s module matching \"%s\" could be loaded",
-                  psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
-    }
     else
-        msg_StackSet( VLC_EGENERIC, "no suitable %s module", psz_capability );
+        msg_Dbg( p_this, "no %s module matching \"%s\" could be loaded",
+                  psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
 
     free( psz_shortcuts );
     free( psz_var );
@@ -627,6 +607,7 @@ found_shortcut:
     return p_module;
 }
 
+#undef module_unneed
 /**
  * Module unneed
  *
@@ -636,7 +617,7 @@ found_shortcut:
  * \param p_module the module structure
  * \return nothing
  */
-void __module_unneed( vlc_object_t * p_this, module_t * p_module )
+void module_unneed( vlc_object_t * p_this, module_t * p_module )
 {
     /* Use the close method */
     if( p_module->pf_deactivate )
@@ -835,17 +816,14 @@ static void AllocateAllPlugins( vlc_object_t *p_this, module_bank_t *p_bank )
     int count,i;
     char * path;
     vlc_array_t *arraypaths = vlc_array_new();
+    const bool b_reset = var_InheritBool( p_this, "reset-plugins-cache" );
 
     /* Contruct the special search path for system that have a relocatable
-     * executable. Set it to <vlc path>/modules and <vlc path>/plugins. */
+     * executable. Set it to <vlc path>/plugins. */
+    assert( vlcpath );
 
-    if( vlcpath && asprintf( &path, "%s" DIR_SEP "modules", vlcpath ) != -1 )
-        vlc_array_append( arraypaths, path );
-    if( vlcpath && asprintf( &path, "%s" DIR_SEP "plugins", vlcpath ) != -1 )
+    if( asprintf( &path, "%s" DIR_SEP "plugins", vlcpath ) != -1 )
         vlc_array_append( arraypaths, path );
-#ifndef WIN32
-    vlc_array_append( arraypaths, strdup( PLUGIN_PATH ) );
-#endif
 
     /* If the user provided a plugin path, we add it to the list */
     char *userpaths = var_InheritString( p_this, "plugin-path" );
@@ -865,11 +843,20 @@ static void AllocateAllPlugins( vlc_object_t *p_this, module_bank_t *p_bank )
         if( !path )
             continue;
 
+        size_t offset = p_module_bank->i_cache;
+        if( b_reset )
+            CacheDelete( p_this, path );
+        else
+            CacheLoad( p_this, p_module_bank, path );
+
         msg_Dbg( p_this, "recursively browsing `%s'", path );
 
         /* Don't go deeper than 5 subdirectories */
         AllocatePluginDir( p_this, p_bank, path, 5 );
 
+
+        CacheSave( p_this, path, p_module_bank->pp_cache + offset,
+                   p_module_bank->i_cache - offset );
         free( path );
     }
 
@@ -886,14 +873,14 @@ static void AllocatePluginDir( vlc_object_t *p_this, module_bank_t *p_bank,
     if( i_maxdepth == 0 )
         return;
 
-    DIR *dh = utf8_opendir (psz_dir);
+    DIR *dh = vlc_opendir (psz_dir);
     if (dh == NULL)
         return;
 
     /* Parse the directory and try to load all files it contains. */
     for (;;)
     {
-        char *file = utf8_readdir (dh), *path;
+        char *file = vlc_readdir (dh), *path;
         struct stat st;
 
         if (file == NULL)
@@ -910,7 +897,7 @@ static void AllocatePluginDir( vlc_object_t *p_this, module_bank_t *p_bank,
 
         const int pathlen = asprintf (&path, "%s"DIR_SEP"%s", psz_dir, file);
         free (file);
-        if (pathlen == -1 || utf8_stat (path, &st))
+        if (pathlen == -1 || vlc_stat (path, &st))
             continue;
 
         if (S_ISDIR (st.st_mode))
@@ -918,10 +905,11 @@ static void AllocatePluginDir( vlc_object_t *p_this, module_bank_t *p_bank,
             AllocatePluginDir (p_this, p_bank, path, i_maxdepth - 1);
         else
         if (S_ISREG (st.st_mode)
-         && ((size_t)pathlen >= strlen (LIBEXT))
-         && !strncasecmp (path + pathlen - strlen (LIBEXT), LIBEXT,
-                          strlen (LIBEXT)))
-            /* ^^ We only load files ending with LIBEXT */
+         && strncmp (path, "lib", 3)
+         && ((size_t)pathlen >= sizeof ("_plugin"LIBEXT))
+         && !strncasecmp (path + pathlen - strlen ("_plugin"LIBEXT),
+                          "_plugin"LIBEXT, strlen ("_plugni"LIBEXT)))
+            /* ^^ We only load files matching "lib*_plugin"LIBEXT */
             AllocatePluginFile (p_this, p_bank, path, st.st_mtime, st.st_size);
 
         free (path);
@@ -952,16 +940,16 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
         p_module = AllocatePlugin( p_this, psz_file );
     }
     else
-    /* If junk dll, don't try to load it */
-    if( p_cache_entry->b_junk )
-        return -1;
-    else
     {
         module_config_t *p_item = NULL, *p_end = NULL;
 
         p_module = p_cache_entry->p_module;
         p_module->b_loaded = false;
 
+        /* If plugin-path contains duplicate entries... */
+        if( p_module->next != NULL )
+            return 0; /* already taken care of that one */
+
         /* For now we force loading if the module's config contains
          * callbacks or actions.
          * Could be optimized by adding an API call.*/
@@ -974,13 +962,14 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
                 break;
             }
         }
-        if( p_module == p_cache_entry->p_module )
-            p_cache_entry->b_used = true;
     }
 
     if( p_module == NULL )
         return -1;
 
+    /* We have not already scanned and inserted this module */
+    assert( p_module->next == NULL );
+
     /* Everything worked fine !
      * The module is ready to be added to the list. */
     p_module->b_builtin = false;
@@ -989,6 +978,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
                 p_module->psz_object_name, p_module->psz_longname ); */
     p_module->next = p_bank->head;
     p_bank->head = p_module;
+    assert( p_module->next != NULL ); /* Insertion done */
 
     if( !p_module_bank->b_cache )
         return 0;
@@ -1005,8 +995,6 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
     pp_cache[p_bank->i_cache]->psz_file = strdup( psz_file );
     pp_cache[p_bank->i_cache]->i_time = i_file_time;
     pp_cache[p_bank->i_cache]->i_size = i_file_size;
-    pp_cache[p_bank->i_cache]->b_junk = p_module ? 0 : 1;
-    pp_cache[p_bank->i_cache]->b_used = true;
     pp_cache[p_bank->i_cache]->p_module = p_module;
     p_bank->pp_cache = pp_cache;
     p_bank->i_cache++;
@@ -1082,6 +1070,7 @@ static void DupModule( module_t *p_module )
     p_module->psz_longname = strdup( p_module->psz_longname );
     p_module->psz_help = p_module->psz_help ? strdup( p_module->psz_help )
                                             : NULL;
+    p_module->domain = p_module->domain ? strdup( p_module->domain ) : NULL;
 
     for (module_t *subm = p_module->submodule; subm; subm = subm->next)
         DupModule (subm);
@@ -1108,6 +1097,7 @@ static void UndupModule( module_t *p_module )
     FREENULL( p_module->psz_shortname );
     free( p_module->psz_longname );
     FREENULL( p_module->psz_help );
+    free( p_module->domain );
 }
 
 #endif /* HAVE_DYNAMIC_PLUGINS */