]> git.sesse.net Git - vlc/blobdiff - src/modules/cache.c
threads: Make sure we don't re-create a thread if the object has already one.
[vlc] / src / modules / cache.c
index 4d6393c6c6afbfeca8448c3c53fb19790e4f3a7a..538e8a2bd85cc0f95390769412c01dcb0776a3db 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#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>
@@ -63,7 +68,7 @@
 #   endif
 #endif
 
-#include "config/config.h"
+#include "config/configuration.h"
 
 #include "vlc_charset.h"
 
@@ -92,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)];
@@ -102,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" );
@@ -111,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;
     }
 
@@ -174,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 )
@@ -254,13 +272,14 @@ void CacheLoad( vlc_object_t *p_this )
         LOAD_IMMEDIATE( pp_cache[i]->i_time );
         LOAD_IMMEDIATE( pp_cache[i]->i_size );
         LOAD_IMMEDIATE( pp_cache[i]->b_junk );
-        pp_cache[i]->b_used = VLC_FALSE;
+        pp_cache[i]->b_used = false;
 
         if( pp_cache[i]->b_junk ) continue;
 
         pp_cache[i]->p_module = vlc_module_create( p_this );
 
         /* Load additional infos */
+        free( pp_cache[i]->p_module->psz_object_name );
         LOAD_STRING( pp_cache[i]->p_module->psz_object_name );
         LOAD_STRING( pp_cache[i]->p_module->psz_shortname );
         LOAD_STRING( pp_cache[i]->p_module->psz_longname );
@@ -287,6 +306,7 @@ void CacheLoad( vlc_object_t *p_this )
         while( i_submodules-- )
         {
             module_t *p_module = vlc_submodule_create( pp_cache[i]->p_module );
+            free( p_module->psz_object_name );
             LOAD_STRING( p_module->psz_object_name );
             LOAD_STRING( p_module->psz_shortname );
             LOAD_STRING( p_module->psz_longname );
@@ -371,9 +391,9 @@ static int CacheLoadConfig( module_t *p_module, FILE *file )
                     sizeof (p_module->p_config[i].saved));
         }
 
-        p_module->p_config[i].b_dirty = VLC_FALSE;
+        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 )
         {
@@ -448,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" );
@@ -477,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" );
@@ -490,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;
@@ -557,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 );
@@ -681,22 +705,22 @@ 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;
     }
 
-    p_cache->b_loaded = VLC_TRUE;
-    p_module->b_loaded = VLC_FALSE;
+    p_cache->b_loaded = true;
+    p_module->b_loaded = false;
 }
 
 /*****************************************************************************
  * CacheFind: finds the cache entry corresponding to a file
  *****************************************************************************/
-module_cache_t *CacheFind( vlc_object_t *p_this, const char *psz_file,
+module_cache_t *CacheFind( const char *psz_file,
                            int64_t i_time, int64_t i_size )
 {
     module_cache_t **pp_cache;