]> git.sesse.net Git - vlc/blobdiff - src/modules/modules.c
Revert [23438] because --enable-fast-install does the same.
[vlc] / src / modules / modules.c
index 49c179dca356ed0acdfe563edb6f1a5faff1b5fd..bc51f8523f293f2f2afebceb39991da005d6b54b 100644 (file)
 #include "modules/configuration.h"
 #include "libvlc.h"
 
-#include "vlc_interface.h"
-#include "vlc_playlist.h"
-
-#include "vlc_stream.h"
-#include "vlc_access.h"
-#include "vlc_demux.h"
-#include "vlc_codec.h"
-
-#include "vlc_vout.h"
-#include "vlc_vout_synchro.h"
-
-#include "vlc_aout.h"
-
-#include "vlc_sout.h"
-#include "vlc_httpd.h"
-#include "vlc_acl.h"
-#include "vlc_tls.h"
-#include "vlc_md5.h"
-#include "vlc_xml.h"
-#include "vlc_url.h"
-
-#include "iso_lang.h"
 #include "vlc_charset.h"
 
-#include "vlc_block.h"
-
-#include "vlc_vlm.h"
-
-#include "vlc_image.h"
-#include "vlc_osd.h"
-
-#include "vlc_update.h"
-#include "vlc_strings.h"
-#include "vlc_streaming.h"
-
 #include "modules/modules.h"
 #include "modules/builtin.h"
 
-#include "vlc_network.h"
-
 #if defined( WIN32 ) || defined( UNDER_CE )
     /* Avoid name collisions */
 #   define LoadModule(a,b,c) LoadVlcModule(a,b,c)
@@ -406,7 +371,7 @@ const char *module_GetName( const module_t *m, vlc_bool_t long_name )
 {
     if( long_name && ( m->psz_longname != NULL) )
         return m->psz_longname;
-    
     return m->psz_shortname ?: m->psz_object_name;
 }
 
@@ -808,6 +773,58 @@ vlc_bool_t __module_Exists(  vlc_object_t *p_this, const char * psz_name )
     }
 }
 
+/*****************************************************************************
+ * module_GetModuleNamesForCapability: Return a NULL terminated array with the
+ * names of the modules that have a certain capability.
+ * Free after uses both the string and the table.
+ *****************************************************************************/
+char ** __module_GetModulesNamesForCapability( vlc_object_t *p_this,
+                                               const char * psz_capability,
+                                               char ***pppsz_longname )
+{
+    vlc_list_t *p_list;
+    int i, j, count = 0;
+    char ** psz_ret;
+
+    /* Do it in two passes */
+    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    for( i = 0 ; i < p_list->i_count; i++)
+    {
+        module_t *p_module = ((module_t *) p_list->p_values[i].p_object);
+        const char *psz_module_capability = p_module->psz_capability;
+        if( psz_module_capability && !strcmp( psz_module_capability, psz_capability ) )
+            count++;
+    }
+    psz_ret = malloc( sizeof(char*) * (count+1) );
+    if( pppsz_longname )
+        *pppsz_longname = malloc( sizeof(char*) * (count+1) );
+    j = 0;
+    for( i = 0 ; i < p_list->i_count; i++)
+    {
+        module_t *p_module = ((module_t *) p_list->p_values[i].p_object);
+        const char *psz_module_capability = p_module->psz_capability;
+        if( psz_module_capability && !strcmp( psz_module_capability, psz_capability ) )
+        {
+            int k = -1; /* hack to handle submodules properly */
+            if( p_module->b_submodule )
+            {
+                while( p_module->pp_shortcuts[++k] != NULL );
+                k--;
+            }
+            psz_ret[j] = strdup( k>=0?p_module->pp_shortcuts[k]
+                                     :p_module->psz_object_name );
+            if( pppsz_longname )
+                (*pppsz_longname)[j] = strdup( module_GetName( p_module, VLC_TRUE ) );
+            j++;
+        }
+    }
+    psz_ret[count] = NULL;
+
+    vlc_list_release( p_list );
+
+    return psz_ret;
+}
+
 
 /*****************************************************************************
  * Following functions are local.
@@ -1369,8 +1386,8 @@ static int CallEntry( module_t * p_module )
         msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",
                             psz_name, p_module->psz_filename, dlerror() );
 #elif defined(HAVE_DL_SHL_LOAD)
-        msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",
-                            psz_name, p_module->psz_filename, strerror(errno) );
+        msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%m)",
+                            psz_name, p_module->psz_filename );
 #else
 #   error "Something is wrong in modules.c"
 #endif
@@ -1460,23 +1477,6 @@ static int LoadModule( vlc_object_t *p_this, char *psz_file,
 
 #elif defined(HAVE_DL_DLOPEN) && defined(RTLD_NOW)
     /* static is OK, we are called atomically */
-
-#   if defined(SYS_LINUX)
-    /* XXX HACK #1 - we should NOT open modules with RTLD_GLOBAL, or we
-     * are going to get namespace collisions when two modules have common
-     * public symbols, but ALSA is being a pest here. */
-    if( strstr( psz_file, "alsa_plugin" ) )
-    {
-        handle = dlopen( psz_file, RTLD_NOW | RTLD_GLOBAL );
-        if( handle == NULL )
-        {
-            msg_Warn( p_this, "cannot load module `%s' (%s)",
-                              psz_file, dlerror() );
-            return -1;
-        }
-    }
-#   endif
-
     handle = dlopen( psz_file, RTLD_NOW );
     if( handle == NULL )
     {
@@ -1502,8 +1502,7 @@ static int LoadModule( vlc_object_t *p_this, char *psz_file,
     handle = shl_load( psz_file, BIND_IMMEDIATE | BIND_NONFATAL, NULL );
     if( handle == NULL )
     {
-        msg_Warn( p_this, "cannot load module `%s' (%s)",
-                          psz_file, strerror(errno) );
+        msg_Warn( p_this, "cannot load module `%s' (%m)", psz_file );
         return -1;
     }
 
@@ -1535,7 +1534,7 @@ static void CloseModule( module_handle_t handle )
     FreeLibrary( handle );
 
 #elif defined(HAVE_DL_DLOPEN)
-# ifndef NDEBUG
+# ifdef NDEBUG
     dlclose( handle );
 # endif
 
@@ -1664,25 +1663,25 @@ static char * GetWindowsError( void )
  *****************************************************************************/
 static void CacheLoad( vlc_object_t *p_this )
 {
-    char *psz_filename, *psz_homedir;
+    char *psz_filename, *psz_cachedir;
     FILE *file;
     int i, j, i_size, i_read;
-    char p_cachestring[sizeof(PLUGINSCACHE_DIR COPYRIGHT_MESSAGE)];
+    char p_cachestring[sizeof("cache " COPYRIGHT_MESSAGE)];
     char p_cachelang[6], p_lang[6];
     int i_cache;
     module_cache_t **pp_cache = 0;
     int32_t i_file_size, i_marker;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    psz_homedir = p_this->p_libvlc->psz_homedir;
-    if( !psz_homedir )
+    psz_cachedir = p_this->p_libvlc->psz_cachedir;
+    if( !psz_cachedir ) /* XXX: this should never happen */
     {
-        msg_Err( p_this, "psz_homedir is null" );
+        msg_Err( p_this, "Unable to get cache directory" );
         return;
     }
 
-    i_size = asprintf( &psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s"DIR_SEP"%s",
-            psz_homedir, CONFIG_DIR, PLUGINSCACHE_DIR, CacheName() );
+    i_size = asprintf( &psz_filename, "%s"DIR_SEP"%s",
+                       psz_cachedir, CacheName() );
     if( i_size <= 0 )
     {
         msg_Err( p_this, "out of memory" );
@@ -1736,10 +1735,10 @@ static void CacheLoad( vlc_object_t *p_this )
     fseek( file, sizeof(i_file_size), SEEK_SET );
 
     /* Check the file is a plugins cache */
-    i_size = sizeof(PLUGINSCACHE_DIR COPYRIGHT_MESSAGE) - 1;
+    i_size = sizeof("cache " COPYRIGHT_MESSAGE) - 1;
     i_read = fread( p_cachestring, 1, i_size, file );
     if( i_read != i_size ||
-        memcmp( p_cachestring, PLUGINSCACHE_DIR COPYRIGHT_MESSAGE, i_size ) )
+        memcmp( p_cachestring, "cache " COPYRIGHT_MESSAGE, i_size ) )
     {
         msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
         fclose( file );
@@ -2021,39 +2020,24 @@ static void CacheSave( vlc_object_t *p_this )
         "# For information about cache directory tags, see:\r\n"
         "#   http://www.brynosaurus.com/cachedir/\r\n";
 
-    char *psz_filename, *psz_homedir;
+    char *psz_cachedir;
     FILE *file;
     int i, j, i_cache;
     module_cache_t **pp_cache;
     int32_t i_file_size = 0;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    psz_homedir = p_this->p_libvlc->psz_homedir;
-    if( !psz_homedir )
+    psz_cachedir = p_this->p_libvlc->psz_cachedir;
+    if( !psz_cachedir ) /* XXX: this should never happen */
     {
-        msg_Err( p_this, "psz_homedir is null" );
+        msg_Err( p_this, "Unable to get cache directory" );
         return;
     }
-    psz_filename =
-       (char *)malloc( sizeof(DIR_SEP CONFIG_DIR DIR_SEP PLUGINSCACHE_DIR DIR_SEP ) +
-                       strlen(psz_homedir) + strlen(CacheName()) );
 
-    if( !psz_filename )
-    {
-        msg_Err( p_this, "out of memory" );
-        return;
-    }
-
-    sprintf( psz_filename, "%s"DIR_SEP"%s", psz_homedir, CONFIG_DIR );
-
-    config_CreateDir( p_this, psz_filename );
-
-    strcat( psz_filename, DIR_SEP PLUGINSCACHE_DIR );
-
-    config_CreateDir( p_this, psz_filename );
-
-    strcat( psz_filename, DIR_SEP"CACHEDIR.TAG" );
+    char psz_filename[sizeof(DIR_SEP) + 32 + strlen(psz_cachedir)];
+    config_CreateDir( p_this, psz_cachedir );
 
+    sprintf( psz_filename, "%s"DIR_SEP"CACHEDIR.TAG", psz_cachedir );
     file = utf8_fopen( psz_filename, "wb" );
     if( file )
     {
@@ -2061,8 +2045,7 @@ static void CacheSave( vlc_object_t *p_this )
         fclose( file );
     }
 
-    sprintf( psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s"DIR_SEP"%s", psz_homedir, CONFIG_DIR,
-             PLUGINSCACHE_DIR, CacheName() );
+    sprintf( psz_filename, "%s"DIR_SEP"%s", psz_cachedir, CacheName() );
 
     msg_Dbg( p_this, "saving plugins cache file %s", psz_filename );
 
@@ -2074,13 +2057,12 @@ static void CacheSave( vlc_object_t *p_this )
         free( psz_filename );
         return;
     }
-    free( psz_filename );
 
     /* Empty space for file size */
     fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file );
 
     /* Contains version number */
-    fprintf( file, "%s", PLUGINSCACHE_DIR COPYRIGHT_MESSAGE );
+    fprintf( file, "%s", "cache " COPYRIGHT_MESSAGE );
 
     /* Sub-version number (to avoid breakage in the dev version when cache
      * structure changes) */