]> git.sesse.net Git - vlc/blobdiff - src/modules/cache.c
libvlc: use vlc_common.h (libvlccore) instead of vlc/vlc.h
[vlc] / src / modules / cache.c
index 140aa4b9d1a540df809b931851e18b47c613ad84..50800081b042211fdf24e4e214385a37fdc5dbad 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;
     }
 
@@ -258,13 +258,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 );
@@ -291,6 +292,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 );
@@ -375,7 +377,7 @@ 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;
 
@@ -452,14 +454,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" );
@@ -481,6 +482,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" );
@@ -561,14 +563,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 );
@@ -685,16 +687,16 @@ 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;
 }
 
 /*****************************************************************************