]> git.sesse.net Git - vlc/blobdiff - src/misc/modules.c
* - This should fix the "crash upon quit" issue with VLC Mac OS X.
[vlc] / src / misc / modules.c
index 54574a43c1aecfcc68d511c4a8ef4d9919004218..7efcd796613c89a5d7efa8584063aff64c76658a 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * modules.c : Builtin and plugin modules management functions
  *****************************************************************************
- * Copyright (C) 2001-2004 VideoLAN
+ * Copyright (C) 2001-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Sam Hocevar <sam@zoy.org>
@@ -51,8 +51,9 @@
 #   include <unistd.h>
 #endif
 
-#define HAVE_DYNAMIC_PLUGINS
-#if defined(HAVE_DL_DYLD)
+#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
 #   if defined(HAVE_DL_H)
 #       include <dl.h>
 #   endif
-#else
-#   undef HAVE_DYNAMIC_PLUGINS
 #endif
 
 #include "vlc_error.h"
 
 #include "vlc_interface.h"
+#include "vlc_interaction.h"
 #include "intf_eject.h"
 
 #include "vlc_playlist.h"
 #include "aout_internal.h"
 
 #include "stream_output.h"
-#include "osd.h"
 #include "vlc_httpd.h"
+#include "vlc_acl.h"
 #include "vlc_tls.h"
+#include "vlc_md5.h"
 #include "vlc_xml.h"
 
 #include "iso_lang.h"
 #include "vlc_vlm.h"
 
 #include "vlc_image.h"
-
-#ifdef HAVE_DYNAMIC_PLUGINS
-#   include "modules_plugin.h"
-#endif
+#include "vlc_osd.h"
 
 #if defined( _MSC_VER ) && defined( UNDER_CE )
 #    include "modules_builtin_evc.h"
 
 #if defined( WIN32 ) || defined( UNDER_CE )
     /* Avoid name collisions */
-#   define LoadModule(a,b,c) _LoadModule(a,b,c)
+#   define LoadModule(a,b,c) LoadVlcModule(a,b,c)
 #endif
 
 /*****************************************************************************
@@ -156,6 +154,11 @@ static char * GetWindowsError  ( void );
 #endif
 #endif
 
+
+/* Sub-version number
+ * (only used to avoid breakage in dev version when cache structure changes) */
+#define CACHE_SUBVERSION_NUM 1
+
 /*****************************************************************************
  * module_InitBank: create the module bank.
  *****************************************************************************
@@ -191,7 +194,7 @@ void __module_InitBank( vlc_object_t *p_this )
     /*
      * Store the symbols to be exported
      */
-#ifdef HAVE_DYNAMIC_PLUGINS
+#if defined (HAVE_DYNAMIC_PLUGINS) && !defined (HAVE_SHARED_LIBVLC)
     STORE_SYMBOLS( &p_bank->symbols );
 #endif
 
@@ -254,14 +257,17 @@ void __module_EndBank( vlc_object_t *p_this )
     {
         free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->psz_file );
         free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] );
-        if( !p_bank->i_loaded_cache ) free( p_bank->pp_loaded_cache );
     }
+    if( p_bank->pp_loaded_cache )
+        free( p_bank->pp_loaded_cache );
+
     while( p_bank->i_cache-- )
     {
         free( p_bank->pp_cache[p_bank->i_cache]->psz_file );
         free( p_bank->pp_cache[p_bank->i_cache] );
-        if( !p_bank->i_cache ) free( p_bank->pp_cache );
     }
+    if( p_bank->pp_cache )
+        free( p_bank->pp_cache );
 #undef p_bank
 #endif
 
@@ -1084,7 +1090,9 @@ static module_t * AllocatePlugin( vlc_object_t * p_this, char * psz_file )
     /* We need to fill these since they may be needed by CallEntry() */
     p_module->psz_filename = psz_file;
     p_module->handle = handle;
+#ifndef HAVE_SHARED_LIBVLC
     p_module->p_symbols = &p_this->p_libvlc->p_module_bank->symbols;
+#endif
     p_module->b_loaded = VLC_TRUE;
 
     /* Initialize the module: fill p_module, default config */
@@ -1372,7 +1380,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 */
-    static vlc_bool_t b_kde = VLC_FALSE;
 
 #   if defined(SYS_LINUX)
     /* XXX HACK #1 - we should NOT open modules with RTLD_GLOBAL, or we
@@ -1389,18 +1396,6 @@ static int LoadModule( vlc_object_t *p_this, char *psz_file,
         }
     }
 #   endif
-    /* XXX HACK #2 - the ugly KDE workaround. It seems that libkdewhatever
-     * causes dlopen() to segfault if libstdc++ is not loaded in the caller,
-     * so we just load libstdc++. Bwahahaha! ph34r! -- Sam. */
-    /* Update: FYI, this is Debian bug #180505, and seems to be fixed. */
-    if( !b_kde && !strstr( psz_file, "kde" ) )
-    {
-        dlopen( "libstdc++.so.6", RTLD_NOW )
-         || dlopen( "libstdc++.so.5", RTLD_NOW )
-         || dlopen( "libstdc++.so.4", RTLD_NOW )
-         || dlopen( "libstdc++.so.3", RTLD_NOW );
-        b_kde = VLC_TRUE;
-    }
 
     handle = dlopen( psz_file, RTLD_NOW );
     if( handle == NULL )
@@ -1622,6 +1617,7 @@ static void CacheLoad( vlc_object_t *p_this )
         DeleteFile( psz_wf );
 #endif
         msg_Dbg( p_this, "removing plugins cache file %s", psz_filename );
+        free( psz_filename );
         return;
     }
 
@@ -1668,6 +1664,16 @@ static void CacheLoad( vlc_object_t *p_this )
         return;
     }
 
+    /* Check Sub-version number */
+    i_read = fread( &i_marker, sizeof(char), sizeof(i_marker), file );
+    if( i_read != sizeof(i_marker) || i_marker != CACHE_SUBVERSION_NUM )
+    {
+        msg_Warn( p_this, "This doesn't look like a valid plugins cache "
+                  "(corrupted header)" );
+        fclose( file );
+        return;
+    }
+
     /* Check the language hasn't changed */
     sprintf( p_lang, "%5.5s", _("C") ); i_size = 5;
     i_read = fread( p_cachelang, sizeof(char), i_size, file );
@@ -1692,8 +1698,9 @@ static void CacheLoad( vlc_object_t *p_this )
 
     p_this->p_libvlc->p_module_bank->i_loaded_cache = 0;
     fread( &i_cache, sizeof(char), sizeof(i_cache), file );
-    pp_cache = p_this->p_libvlc->p_module_bank->pp_loaded_cache =
-        malloc( i_cache * sizeof(void *) );
+    if( i_cache )
+        pp_cache = p_this->p_libvlc->p_module_bank->pp_loaded_cache =
+                   malloc( i_cache * sizeof(void *) );
 
 #define LOAD_IMMEDIATE(a) \
     if( fread( &a, sizeof(char), sizeof(a), file ) != sizeof(a) ) goto error
@@ -1818,6 +1825,7 @@ int CacheLoadConfig( module_t *p_module, FILE *file )
         LOAD_STRING( p_module->p_config[i].psz_name );
         LOAD_STRING( p_module->p_config[i].psz_text );
         LOAD_STRING( p_module->p_config[i].psz_longtext );
+        LOAD_STRING( p_module->p_config[i].psz_current );
         LOAD_STRING( p_module->p_config[i].psz_value_orig );
 
         p_module->p_config[i].psz_value =
@@ -1965,6 +1973,11 @@ static void CacheSave( vlc_object_t *p_this )
     /* Contains version number */
     fprintf( file, "%s", PLUGINSCACHE_DIR COPYRIGHT_MESSAGE );
 
+    /* Sub-version number (to avoid breakage in the dev version when cache
+     * structure changes) */
+    i_file_size = CACHE_SUBVERSION_NUM;
+    fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file );
+
     /* Language */
     fprintf( file, "%5.5s", _("C") );
 
@@ -2075,6 +2088,7 @@ void CacheSaveConfig( module_t *p_module, FILE *file )
         SAVE_STRING( p_module->p_config[i].psz_name );
         SAVE_STRING( p_module->p_config[i].psz_text );
         SAVE_STRING( p_module->p_config[i].psz_longtext );
+        SAVE_STRING( p_module->p_config[i].psz_current );
         SAVE_STRING( p_module->p_config[i].psz_value_orig );
 
         if( p_module->p_config[i].i_list )
@@ -2134,7 +2148,9 @@ static void CacheMerge( vlc_object_t *p_this, module_t *p_cache,
 
     p_cache->pf_activate = p_module->pf_activate;
     p_cache->pf_deactivate = p_module->pf_deactivate;
+#ifndef HAVE_SHARED_LIBVLC
     p_cache->p_symbols = p_module->p_symbols;
+#endif
     p_cache->handle = p_module->handle;
 
     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
@@ -2143,7 +2159,9 @@ static void CacheMerge( vlc_object_t *p_this, module_t *p_cache,
         module_t *p_cchild = (module_t*)p_cache->pp_children[i_submodule];
         p_cchild->pf_activate = p_child->pf_activate;
         p_cchild->pf_deactivate = p_child->pf_deactivate;
+#ifndef HAVE_SHARED_LIBVLC
         p_cchild->p_symbols = p_child->p_symbols;
+#endif
     }
 
     p_cache->b_loaded = VLC_TRUE;