]> git.sesse.net Git - vlc/blobdiff - src/misc/modules.c
Complete rewrite of vlc_symbols.h generation (closes #155)
[vlc] / src / misc / modules.c
index 99b02daa8f7599691ebe99148536e115e92a4e8d..e29267750274fd7d37e90c02fdc9aa9fe7973050 100644 (file)
 
 #ifdef HAVE_DIRENT_H
 #   include <dirent.h>
-#elif defined( UNDER_CE )
-#   include <windows.h>                               /* GetFileAttributes() */
-#else
-#   include "../extras/dirent.h"
 #endif
 
 #ifdef HAVE_SYS_TYPES_H
@@ -55,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
@@ -77,8 +74,6 @@
 #   if defined(HAVE_DL_H)
 #       include <dl.h>
 #   endif
-#else
-#   undef HAVE_DYNAMIC_PLUGINS
 #endif
 
 #include "vlc_error.h"
 #include "osd.h"
 #include "vlc_httpd.h"
 #include "vlc_tls.h"
+#include "vlc_md5.h"
 #include "vlc_xml.h"
 
 #include "iso_lang.h"
 
 #include "vlc_image.h"
 
-#ifdef HAVE_DYNAMIC_PLUGINS
-#   include "modules_plugin.h"
-#endif
-
-#if defined( UNDER_CE )
+#if defined( _MSC_VER ) && defined( UNDER_CE )
 #    include "modules_builtin_evc.h"
 #elif defined( _MSC_VER )
 #    include "modules_builtin_msvc.h"
 #endif
 #include "network.h"
 
-#if defined( WIN32) || defined( UNDER_CE )
+#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
 
 /*****************************************************************************
@@ -160,6 +152,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.
  *****************************************************************************
@@ -249,6 +246,8 @@ void __module_EndBank( vlc_object_t *p_this )
     vlc_mutex_unlock( lockval.p_address );
     var_Destroy( p_this->p_libvlc, "libvlc" );
 
+    config_AutoSaveConfigFile( p_this );
+
 #ifdef HAVE_DYNAMIC_PLUGINS
 #define p_bank p_this->p_libvlc->p_module_bank
     if( p_bank->b_cache ) CacheSave( p_this );
@@ -410,7 +409,6 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
     char *psz_shortcuts = NULL, *psz_var = NULL;
     vlc_bool_t b_force_backup = p_this->b_force;
 
-    msg_Dbg( p_this, "looking for %s module", psz_capability );
 
     /* Deal with variables */
     if( psz_name && psz_name[0] == '$' )
@@ -606,8 +604,8 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
         i_index++;
     }
 
-    msg_Dbg( p_this, "probing %i candidate%s",
-                     i_index, i_index == 1 ? "" : "s" );
+    msg_Dbg( p_this, "looking for %s module: %i candidate%s", psz_capability,
+                                            i_index, i_index == 1 ? "" : "s" );
 
     /* Lock all candidate modules */
     p_tmp = p_first;
@@ -820,7 +818,7 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
     char psz_path[MAX_PATH + 256];
     WIN32_FIND_DATA finddata;
     HANDLE handle;
-    unsigned int rc;
+    int rc;
 #else
     int    i_dirlen;
     DIR *  dir;
@@ -838,13 +836,13 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
     MultiByteToWideChar( CP_ACP, 0, psz_dir, -1, psz_wdir, MAX_PATH );
 
     rc = GetFileAttributes( psz_wdir );
-    if( !(rc & FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */
+    if( rc<0 || !(rc&FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */
 
     /* Parse all files in the directory */
     swprintf( psz_wpath, L"%ls\\*", psz_wdir );
 #else
     rc = GetFileAttributes( psz_dir );
-    if( !(rc & FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */
+    if( rc<0 || !(rc&FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */
 #endif
 
     /* Parse all files in the directory */
@@ -1625,6 +1623,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;
     }
 
@@ -1671,6 +1670,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 );
@@ -1695,18 +1704,22 @@ 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
 #define LOAD_STRING(a) \
     { if( fread( &i_size, sizeof(char), sizeof(i_size), file ) \
           != sizeof(i_size) ) goto error; \
-      if( i_size ) { \
+      if( i_size && i_size < 16384 ) { \
           a = malloc( i_size ); \
           if( fread( a, sizeof(char), i_size, file ) != (size_t)i_size ) \
               goto error; \
+          if( a[i_size-1] ) { \
+              free( a ); a = 0; \
+              goto error; } \
       } else a = 0; \
     } while(0)
 
@@ -1818,6 +1831,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 =
@@ -1825,6 +1839,10 @@ int CacheLoadConfig( module_t *p_module, FILE *file )
                 strdup( p_module->p_config[i].psz_value_orig ) : 0;
         p_module->p_config[i].i_value = p_module->p_config[i].i_value_orig;
         p_module->p_config[i].f_value = p_module->p_config[i].f_value_orig;
+        p_module->p_config[i].i_value_saved = p_module->p_config[i].i_value;
+        p_module->p_config[i].f_value_saved = p_module->p_config[i].f_value;
+        p_module->p_config[i].psz_value_saved = 0;
+        p_module->p_config[i].b_dirty = VLC_FALSE;
 
         p_module->p_config[i].p_lock = &p_module->object_lock;
 
@@ -1961,6 +1979,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") );
 
@@ -2071,6 +2094,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 )