X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fmodules.c;h=8b40d6e0db2f18a6424ae22af706d0b6234f18c3;hb=fc5c3b368e0b62eb5e8ce9de83ecd30490adef77;hp=99b02daa8f7599691ebe99148536e115e92a4e8d;hpb=0a5efa39e8f52fe8ac98bc74373e9ea625729225;p=vlc diff --git a/src/misc/modules.c b/src/misc/modules.c index 99b02daa8f..8b40d6e0db 100644 --- a/src/misc/modules.c +++ b/src/misc/modules.c @@ -39,10 +39,6 @@ #ifdef HAVE_DIRENT_H # include -#elif defined( UNDER_CE ) -# include /* GetFileAttributes() */ -#else -# include "../extras/dirent.h" #endif #ifdef HAVE_SYS_TYPES_H @@ -115,7 +111,7 @@ # 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" @@ -124,7 +120,7 @@ #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) #endif @@ -160,6 +156,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 +250,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 +413,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 +608,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 +822,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 +840,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 */ @@ -1671,6 +1673,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 +1707,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) @@ -1825,6 +1841,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 +1981,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") );