]> git.sesse.net Git - vlc/blobdiff - src/modules/cache.c
Don't leak every https parameters.
[vlc] / src / modules / cache.c
index 00233efb88d959db408b6fdccdcd583936201605..538e8a2bd85cc0f95390769412c01dcb0776a3db 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include "libvlc.h"
 
 #include <stdlib.h>                                      /* free(), strtol() */
 #include <stdio.h>                                              /* sprintf() */
 #include <string.h>                                              /* strdup() */
+#include <vlc_plugin.h>
 
 #ifdef HAVE_SYS_TYPES_H
 #   include <sys/types.h>
@@ -96,7 +97,7 @@ static char * CacheName        ( void );
  *****************************************************************************/
 void CacheLoad( vlc_object_t *p_this )
 {
-    char *psz_filename, *psz_cachedir;
+    char *psz_filename, *psz_cachedir = config_GetCacheDir();
     FILE *file;
     int i, j, i_size, i_read;
     char p_cachestring[sizeof("cache " COPYRIGHT_MESSAGE)];
@@ -106,7 +107,6 @@ void CacheLoad( vlc_object_t *p_this )
     int32_t i_file_size, i_marker;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    psz_cachedir = p_this->p_libvlc->psz_cachedir;
     if( !psz_cachedir ) /* XXX: this should never happen */
     {
         msg_Err( p_this, "Unable to get cache directory" );
@@ -115,9 +115,9 @@ void CacheLoad( vlc_object_t *p_this )
 
     i_size = asprintf( &psz_filename, "%s"DIR_SEP"%s",
                        psz_cachedir, CacheName() );
+    free( psz_cachedir );
     if( i_size <= 0 )
     {
-        msg_Err( p_this, "out of memory" );
         return;
     }
 
@@ -178,6 +178,20 @@ void CacheLoad( vlc_object_t *p_this )
         return;
     }
 
+#ifdef DISTRO_VERSION
+    /* Check for distribution specific version */
+    char p_distrostring[sizeof( DISTRO_VERSION )];
+    i_size = sizeof( DISTRO_VERSION ) - 1;
+    i_read = fread( p_distrostring, 1, i_size, file );
+    if( i_read != i_size ||
+        memcmp( p_distrostring, DISTRO_VERSION, i_size ) )
+    {
+        msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
+        fclose( file );
+        return;
+    }
+#endif
+
     /* Check Sub-version number */
     i_read = fread( &i_marker, 1, sizeof(i_marker), file );
     if( i_read != sizeof(i_marker) || i_marker != CACHE_SUBVERSION_NUM )
@@ -379,7 +393,7 @@ static int CacheLoadConfig( module_t *p_module, FILE *file )
 
         p_module->p_config[i].b_dirty = false;
 
-        p_module->p_config[i].p_lock = &p_module->object_lock;
+        p_module->p_config[i].p_lock = &(vlc_internals(p_module)->lock);
 
         if( p_module->p_config[i].i_list )
         {
@@ -454,14 +468,13 @@ 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_cachedir;
+    char *psz_cachedir = config_GetCacheDir();
     FILE *file;
     int i, j, i_cache;
     module_cache_t **pp_cache;
     uint32_t i_file_size = 0;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    psz_cachedir = p_this->p_libvlc->psz_cachedir;
     if( !psz_cachedir ) /* XXX: this should never happen */
     {
         msg_Err( p_this, "unable to get cache directory" );
@@ -483,6 +496,7 @@ void CacheSave( vlc_object_t *p_this )
 
     snprintf( psz_filename, sizeof( psz_filename ),
               "%s"DIR_SEP"%s", psz_cachedir, CacheName() );
+    free( psz_cachedir );
     msg_Dbg( p_this, "writing plugins cache %s", psz_filename );
 
     file = utf8_fopen( psz_filename, "wb" );
@@ -496,7 +510,11 @@ void CacheSave( vlc_object_t *p_this )
     /* Contains version number */
     if (fputs ("cache "COPYRIGHT_MESSAGE, file) == EOF)
         goto error;
-
+#ifdef DISTRO_VERSION
+    /* Allow binary maintaner to pass a string to detect new binary version*/
+    if (fputs( DISTRO_VERSION, file ) == EOF)
+        goto error;
+#endif
     /* Sub-version number (to avoid breakage in the dev version when cache
      * structure changes) */
     i_file_size = CACHE_SUBVERSION_NUM;
@@ -563,14 +581,14 @@ void CacheSave( vlc_object_t *p_this )
 
         SAVE_STRING( pp_cache[i]->p_module->psz_filename );
 
-        i_submodule = pp_cache[i]->p_module->i_children;
+        i_submodule = vlc_internals( pp_cache[i]->p_module )->i_children;
         SAVE_IMMEDIATE( i_submodule );
         for( i_submodule = 0;
-             i_submodule < (unsigned)pp_cache[i]->p_module->i_children;
+             i_submodule < (unsigned)vlc_internals( pp_cache[i]->p_module)->i_children;
              i_submodule++ )
         {
             module_t *p_module =
-                (module_t *)pp_cache[i]->p_module->pp_children[i_submodule];
+                (module_t *)vlc_internals( pp_cache[i]->p_module )->pp_children[i_submodule];
 
             SAVE_STRING( p_module->psz_object_name );
             SAVE_STRING( p_module->psz_shortname );
@@ -687,10 +705,10 @@ void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
     p_cache->pf_deactivate = p_module->pf_deactivate;
     p_cache->handle = p_module->handle;
 
-    for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
+    for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ )
     {
-        module_t *p_child = (module_t*)p_module->pp_children[i_submodule];
-        module_t *p_cchild = (module_t*)p_cache->pp_children[i_submodule];
+        module_t *p_child = (module_t*)vlc_internals( p_module )->pp_children[i_submodule];
+        module_t *p_cchild = (module_t*)vlc_internals( p_cache )->pp_children[i_submodule];
         p_cchild->pf_activate = p_child->pf_activate;
         p_cchild->pf_deactivate = p_child->pf_deactivate;
     }