]> git.sesse.net Git - vlc/blob - src/modules/cache.c
More verbose error when failing to load the cache file
[vlc] / src / modules / cache.c
1 /*****************************************************************************
2  * cache.c: Plugins cache
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sam Hocevar <sam@zoy.org>
8  *          Ethan C. Baldridge <BaldridgeE@cadmus.com>
9  *          Hans-Peter Jansen <hpj@urpla.net>
10  *          Gildas Bazin <gbazin@videolan.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include "libvlc.h"
33
34 #include <stdlib.h>                                      /* free(), strtol() */
35 #include <stdio.h>                                              /* sprintf() */
36 #include <string.h>                                              /* strdup() */
37 #include <vlc_plugin.h>
38 #include <vlc_cpu.h>
39
40 #include <sys/types.h>
41 #ifdef HAVE_UNISTD_H
42 #   include <unistd.h>
43 #endif
44 #include <assert.h>
45
46 #include "config/configuration.h"
47
48 #include "vlc_charset.h"
49
50 #include "modules/modules.h"
51
52
53 /*****************************************************************************
54  * Local prototypes
55  *****************************************************************************/
56 #ifdef HAVE_DYNAMIC_PLUGINS
57 static int    CacheLoadConfig  ( module_t *, FILE * );
58
59 /* Sub-version number
60  * (only used to avoid breakage in dev version when cache structure changes) */
61 #define CACHE_SUBVERSION_NUM 10
62
63 /* Format string for the cache filename */
64 #define CACHENAME_FORMAT \
65     "plugins-%.2zx%.2zx%.2"PRIx8"-%x.dat"
66 /* Magic for the cache filename */
67 #define CACHENAME_VALUES \
68     sizeof(int), sizeof(void *), *(uint8_t *)&(uint16_t){ 0xbe1e }, vlc_CPU()
69
70
71 /*****************************************************************************
72  * LoadPluginsCache: loads the plugins cache file
73  *****************************************************************************
74  * This function will load the plugin cache if present and valid. This cache
75  * will in turn be queried by AllocateAllPlugins() to see if it needs to
76  * actually load the dynamically loadable module.
77  * This allows us to only fully load plugins when they are actually used.
78  *****************************************************************************/
79 void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, bool b_delete )
80 {
81     char *psz_filename, *psz_cachedir = config_GetUserDir(VLC_CACHE_DIR);
82     FILE *file;
83     int j, i_size, i_read;
84     char p_cachestring[sizeof("cache " COPYRIGHT_MESSAGE)];
85     unsigned i_cache;
86     module_cache_t **pp_cache = NULL;
87     int32_t i_file_size, i_marker;
88
89     if( !psz_cachedir ) /* XXX: this should never happen */
90     {
91         msg_Err( p_this, "Unable to get cache directory" );
92         return;
93     }
94
95     if( asprintf( &psz_filename, "%s"DIR_SEP CACHENAME_FORMAT,
96                   psz_cachedir, CACHENAME_VALUES ) == -1 )
97     {
98         free( psz_cachedir );
99         return;
100     }
101     free( psz_cachedir );
102
103     if( b_delete )
104     {
105         msg_Dbg( p_this, "removing plugins cache file %s", psz_filename );
106         utf8_unlink( psz_filename );
107         free( psz_filename );
108         return;
109     }
110
111     msg_Dbg( p_this, "loading plugins cache file %s", psz_filename );
112
113     file = utf8_fopen( psz_filename, "rb" );
114     if( !file )
115     {
116         msg_Warn( p_this, "cannot read %s (%m)",
117                   psz_filename );
118         free( psz_filename );
119         return;
120     }
121     free( psz_filename );
122
123     /* Check the file size */
124     i_read = fread( &i_file_size, 1, sizeof(i_file_size), file );
125     if( i_read != sizeof(i_file_size) )
126     {
127         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
128                   "(too short)" );
129         fclose( file );
130         return;
131     }
132
133     fseek( file, 0, SEEK_END );
134     if( ftell( file ) != i_file_size )
135     {
136         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
137                   "(corrupted size)" );
138         fclose( file );
139         return;
140     }
141     fseek( file, sizeof(i_file_size), SEEK_SET );
142
143     /* Check the file is a plugins cache */
144     i_size = sizeof("cache " COPYRIGHT_MESSAGE) - 1;
145     i_read = fread( p_cachestring, 1, i_size, file );
146     if( i_read != i_size ||
147         memcmp( p_cachestring, "cache " COPYRIGHT_MESSAGE, i_size ) )
148     {
149         msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
150         fclose( file );
151         return;
152     }
153
154 #ifdef DISTRO_VERSION
155     /* Check for distribution specific version */
156     char p_distrostring[sizeof( DISTRO_VERSION )];
157     i_size = sizeof( DISTRO_VERSION ) - 1;
158     i_read = fread( p_distrostring, 1, i_size, file );
159     if( i_read != i_size ||
160         memcmp( p_distrostring, DISTRO_VERSION, i_size ) )
161     {
162         msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
163         fclose( file );
164         return;
165     }
166 #endif
167
168     /* Check Sub-version number */
169     i_read = fread( &i_marker, 1, sizeof(i_marker), file );
170     if( i_read != sizeof(i_marker) || i_marker != CACHE_SUBVERSION_NUM )
171     {
172         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
173                   "(corrupted header)" );
174         fclose( file );
175         return;
176     }
177
178     /* Check header marker */
179     i_read = fread( &i_marker, 1, sizeof(i_marker), file );
180     if( i_read != sizeof(i_marker) ||
181         i_marker != ftell( file ) - (int)sizeof(i_marker) )
182     {
183         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
184                   "(corrupted header)" );
185         fclose( file );
186         return;
187     }
188
189     if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) )
190     {
191         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
192                   "(file too short)" );
193         fclose( file );
194         return;
195     }
196
197     if( i_cache )
198     {
199         unsigned i_already = p_bank->i_loaded_cache;
200         pp_cache = realloc( p_bank->pp_loaded_cache,
201                             (i_already + i_cache) * sizeof(*pp_cache) );
202         if( unlikely(pp_cache == NULL) )
203             i_cache = 0; /* don't load */
204         else
205         {
206             p_bank->pp_loaded_cache = pp_cache;
207             pp_cache += i_already;
208         }
209    }
210
211 #define LOAD_IMMEDIATE(a) \
212     if( fread( (void *)&a, sizeof(char), sizeof(a), file ) != sizeof(a) ) goto error
213 #define LOAD_STRING(a) \
214 { \
215     a = NULL; \
216     if( ( fread( &i_size, sizeof(i_size), 1, file ) != 1 ) \
217      || ( i_size > 16384 ) ) \
218         goto error; \
219     if( i_size ) { \
220         char *psz = xmalloc( i_size ); \
221         if( fread( psz, i_size, 1, file ) != 1 ) { \
222             free( psz ); \
223             goto error; \
224         } \
225         if( psz[i_size-1] ) { \
226             free( psz ); \
227             goto error; \
228         } \
229         a = psz; \
230     } \
231 }
232
233     for( unsigned i = 0; i < i_cache; i++ )
234     {
235         uint16_t i_size;
236         int i_submodules;
237
238         pp_cache[i] = xmalloc( sizeof(module_cache_t) );
239
240         /* Load common info */
241         LOAD_STRING( pp_cache[i]->psz_file );
242         LOAD_IMMEDIATE( pp_cache[i]->i_time );
243         LOAD_IMMEDIATE( pp_cache[i]->i_size );
244
245         pp_cache[i]->p_module = vlc_module_create( p_this );
246
247         /* Load additional infos */
248         free( pp_cache[i]->p_module->psz_object_name );
249         LOAD_STRING( pp_cache[i]->p_module->psz_object_name );
250         LOAD_STRING( pp_cache[i]->p_module->psz_shortname );
251         LOAD_STRING( pp_cache[i]->p_module->psz_longname );
252         LOAD_STRING( pp_cache[i]->p_module->psz_help );
253         for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
254         {
255             LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
256         }
257         LOAD_STRING( pp_cache[i]->p_module->psz_capability );
258         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_score );
259         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
260         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
261
262         /* Config stuff */
263         if( CacheLoadConfig( pp_cache[i]->p_module, file ) != VLC_SUCCESS )
264             goto error;
265
266         LOAD_STRING( pp_cache[i]->p_module->psz_filename );
267         LOAD_STRING( pp_cache[i]->p_module->domain );
268         if( pp_cache[i]->p_module->domain != NULL )
269             vlc_bindtextdomain( pp_cache[i]->p_module->domain );
270
271         LOAD_IMMEDIATE( i_submodules );
272
273         while( i_submodules-- )
274         {
275             module_t *p_module = vlc_submodule_create( pp_cache[i]->p_module );
276             free( p_module->psz_object_name );
277             LOAD_STRING( p_module->psz_object_name );
278             LOAD_STRING( p_module->psz_shortname );
279             LOAD_STRING( p_module->psz_longname );
280             LOAD_STRING( p_module->psz_help );
281             for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
282             {
283                 LOAD_STRING( p_module->pp_shortcuts[j] ); // FIX
284             }
285             LOAD_STRING( p_module->psz_capability );
286             LOAD_IMMEDIATE( p_module->i_score );
287             LOAD_IMMEDIATE( p_module->b_unloadable );
288             LOAD_STRING( p_module->domain );
289         }
290     }
291     p_bank->i_loaded_cache += i_cache;
292
293     fclose( file );
294     return;
295
296  error:
297
298     msg_Warn( p_this, "plugins cache not loaded (corrupted)" );
299
300     /* TODO: cleanup */
301     fclose( file );
302     return;
303 }
304
305
306 /* This function should never be called.
307  * It is only used as a non-NULL vlc_callback_t value for comparison. */
308 static int dummy_callback (vlc_object_t *obj, const char *name,
309                            vlc_value_t oldval, vlc_value_t newval, void *data)
310 {
311     (void) obj; (void)name; (void)oldval; (void)newval; (void)data;
312     assert (0);
313 }
314
315
316 static int CacheLoadConfig( module_t *p_module, FILE *file )
317 {
318     uint32_t i_lines;
319     uint16_t i_size;
320
321     /* Calculate the structure length */
322     LOAD_IMMEDIATE( p_module->i_config_items );
323     LOAD_IMMEDIATE( p_module->i_bool_items );
324
325     LOAD_IMMEDIATE( i_lines );
326
327     /* Allocate memory */
328     if (i_lines)
329     {
330         p_module->p_config =
331             (module_config_t *)calloc( i_lines, sizeof(module_config_t) );
332         if( p_module->p_config == NULL )
333         {
334             p_module->confsize = 0;
335             return VLC_ENOMEM;
336         }
337     }
338     p_module->confsize = i_lines;
339
340     /* Do the duplication job */
341     for (size_t i = 0; i < i_lines; i++ )
342     {
343         LOAD_IMMEDIATE( p_module->p_config[i] );
344
345         LOAD_STRING( p_module->p_config[i].psz_type );
346         LOAD_STRING( p_module->p_config[i].psz_name );
347         LOAD_STRING( p_module->p_config[i].psz_text );
348         LOAD_STRING( p_module->p_config[i].psz_longtext );
349         LOAD_STRING( p_module->p_config[i].psz_oldname );
350         LOAD_IMMEDIATE( p_module->p_config[i].b_removed );
351
352         if (IsConfigStringType (p_module->p_config[i].i_type))
353         {
354             LOAD_STRING (p_module->p_config[i].orig.psz);
355             p_module->p_config[i].value.psz =
356                     (p_module->p_config[i].orig.psz != NULL)
357                         ? strdup (p_module->p_config[i].orig.psz) : NULL;
358             p_module->p_config[i].saved.psz = NULL;
359         }
360         else
361         {
362             memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig,
363                     sizeof (p_module->p_config[i].value));
364             memcpy (&p_module->p_config[i].saved, &p_module->p_config[i].orig,
365                     sizeof (p_module->p_config[i].saved));
366         }
367
368         p_module->p_config[i].b_dirty = false;
369
370         if( p_module->p_config[i].i_list )
371         {
372             if( p_module->p_config[i].ppsz_list )
373             {
374                 int j;
375                 p_module->p_config[i].ppsz_list =
376                     xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
377                 if( p_module->p_config[i].ppsz_list )
378                 {
379                     for( j = 0; j < p_module->p_config[i].i_list; j++ )
380                         LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
381                     p_module->p_config[i].ppsz_list[j] = NULL;
382                 }
383             }
384             if( p_module->p_config[i].ppsz_list_text )
385             {
386                 int j;
387                 p_module->p_config[i].ppsz_list_text =
388                     xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
389                 if( p_module->p_config[i].ppsz_list_text )
390                 {
391                   for( j = 0; j < p_module->p_config[i].i_list; j++ )
392                       LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
393                   p_module->p_config[i].ppsz_list_text[j] = NULL;
394                 }
395             }
396             if( p_module->p_config[i].pi_list )
397             {
398                 p_module->p_config[i].pi_list =
399                     xmalloc( (p_module->p_config[i].i_list + 1) * sizeof(int) );
400                 if( p_module->p_config[i].pi_list )
401                 {
402                     for (int j = 0; j < p_module->p_config[i].i_list; j++)
403                         LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
404                 }
405             }
406         }
407
408         if( p_module->p_config[i].i_action )
409         {
410             p_module->p_config[i].ppf_action =
411                 xmalloc( p_module->p_config[i].i_action * sizeof(void *) );
412             p_module->p_config[i].ppsz_action_text =
413                 xmalloc( p_module->p_config[i].i_action * sizeof(char *) );
414
415             for (int j = 0; j < p_module->p_config[i].i_action; j++)
416             {
417                 p_module->p_config[i].ppf_action[j] = NULL;
418                 LOAD_STRING( p_module->p_config[i].ppsz_action_text[j] );
419             }
420         }
421
422         bool has_callback;
423         LOAD_IMMEDIATE( has_callback );
424         if (has_callback)
425             p_module->p_config[i].pf_callback = dummy_callback;
426     }
427
428     return VLC_SUCCESS;
429
430  error:
431
432     return VLC_EGENERIC;
433 }
434
435 static int CacheSaveBank( FILE *file, module_bank_t *p_bank );
436
437 /*****************************************************************************
438  * SavePluginsCache: saves the plugins cache to a file
439  *****************************************************************************/
440 void CacheSave( vlc_object_t *p_this, module_bank_t *p_bank )
441 {
442     char *psz_cachedir = config_GetUserDir(VLC_CACHE_DIR);
443     if( !psz_cachedir ) /* XXX: this should never happen */
444     {
445         msg_Err( p_this, "unable to get cache directory" );
446         return;
447     }
448
449     char psz_filename[sizeof(DIR_SEP) + 32 + strlen(psz_cachedir)];
450     config_CreateDir( p_this, psz_cachedir );
451
452     snprintf( psz_filename, sizeof( psz_filename ),
453               "%s"DIR_SEP CACHENAME_FORMAT, psz_cachedir,
454               CACHENAME_VALUES );
455     free( psz_cachedir );
456
457     char psz_tmpname[sizeof (psz_filename) + 12];
458     snprintf (psz_tmpname, sizeof (psz_tmpname), "%s.%"PRIu32, psz_filename,
459               (uint32_t)getpid ());
460     FILE *file = utf8_fopen( psz_tmpname, "wb" );
461     if (file == NULL)
462         goto error;
463
464     msg_Dbg (p_this, "saving plugins cache %s", psz_filename);
465     if (CacheSaveBank (file, p_bank))
466         goto error;
467
468 #ifndef WIN32
469     utf8_rename (psz_tmpname, psz_filename); /* atomically replace old cache */
470     fclose (file);
471 #else
472     utf8_unlink (psz_filename);
473     fclose (file);
474     utf8_rename (psz_tmpname, psz_filename);
475 #endif
476     return; /* success! */
477
478 error:
479     msg_Warn (p_this, "could not write plugins cache %s (%m)",
480               psz_filename);
481     if (file != NULL)
482     {
483         clearerr (file);
484         fclose (file);
485     }
486 }
487
488 static int CacheSaveConfig (FILE *, module_t *);
489 static int CacheSaveSubmodule (FILE *, module_t *);
490
491 static int CacheSaveBank (FILE *file, module_bank_t *p_bank)
492 {
493     uint32_t i_file_size = 0;
494
495     /* Empty space for file size */
496     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
497         goto error;
498
499     /* Contains version number */
500     if (fputs ("cache "COPYRIGHT_MESSAGE, file) == EOF)
501         goto error;
502 #ifdef DISTRO_VERSION
503     /* Allow binary maintaner to pass a string to detect new binary version*/
504     if (fputs( DISTRO_VERSION, file ) == EOF)
505         goto error;
506 #endif
507     /* Sub-version number (to avoid breakage in the dev version when cache
508      * structure changes) */
509     i_file_size = CACHE_SUBVERSION_NUM;
510     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1 )
511         goto error;
512
513     /* Header marker */
514     i_file_size = ftell( file );
515     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
516         goto error;
517
518     module_cache_t **pp_cache = p_bank->pp_cache;
519     uint32_t i_cache = p_bank->i_cache;
520
521     if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1)
522         goto error;
523
524 #define SAVE_IMMEDIATE( a ) \
525     if (fwrite (&a, sizeof(a), 1, file) != 1) \
526         goto error
527 #define SAVE_STRING( a ) \
528     { \
529         uint16_t i_size = (a != NULL) ? (strlen (a) + 1) : 0; \
530         if ((fwrite (&i_size, sizeof (i_size), 1, file) != 1) \
531          || (a && (fwrite (a, 1, i_size, file) != i_size))) \
532             goto error; \
533     } while(0)
534
535     for (unsigned i = 0; i < i_cache; i++)
536     {
537         uint32_t i_submodule;
538
539         /* Save common info */
540         SAVE_STRING( pp_cache[i]->psz_file );
541         SAVE_IMMEDIATE( pp_cache[i]->i_time );
542         SAVE_IMMEDIATE( pp_cache[i]->i_size );
543
544         /* Save additional infos */
545         SAVE_STRING( pp_cache[i]->p_module->psz_object_name );
546         SAVE_STRING( pp_cache[i]->p_module->psz_shortname );
547         SAVE_STRING( pp_cache[i]->p_module->psz_longname );
548         SAVE_STRING( pp_cache[i]->p_module->psz_help );
549         for (unsigned j = 0; j < MODULE_SHORTCUT_MAX; j++)
550         {
551             SAVE_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
552         }
553         SAVE_STRING( pp_cache[i]->p_module->psz_capability );
554         SAVE_IMMEDIATE( pp_cache[i]->p_module->i_score );
555         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
556         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
557
558         /* Config stuff */
559         if (CacheSaveConfig (file, pp_cache[i]->p_module))
560             goto error;
561
562         SAVE_STRING( pp_cache[i]->p_module->psz_filename );
563         SAVE_STRING( pp_cache[i]->p_module->domain );
564
565         i_submodule = pp_cache[i]->p_module->submodule_count;
566         SAVE_IMMEDIATE( i_submodule );
567         if( CacheSaveSubmodule( file, pp_cache[i]->p_module->submodule ) )
568             goto error;
569     }
570
571     /* Fill-up file size */
572     i_file_size = ftell( file );
573     fseek( file, 0, SEEK_SET );
574     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1
575      || fflush (file)) /* flush libc buffers */
576         goto error;
577     return 0; /* success! */
578
579 error:
580     return -1;
581 }
582
583 static int CacheSaveSubmodule( FILE *file, module_t *p_module )
584 {
585     if( !p_module )
586         return 0;
587     if( CacheSaveSubmodule( file, p_module->next ) )
588         goto error;
589
590     SAVE_STRING( p_module->psz_object_name );
591     SAVE_STRING( p_module->psz_shortname );
592     SAVE_STRING( p_module->psz_longname );
593     SAVE_STRING( p_module->psz_help );
594     for( unsigned j = 0; j < MODULE_SHORTCUT_MAX; j++ )
595          SAVE_STRING( p_module->pp_shortcuts[j] ); // FIXME
596
597     SAVE_STRING( p_module->psz_capability );
598     SAVE_IMMEDIATE( p_module->i_score );
599     SAVE_IMMEDIATE( p_module->b_unloadable );
600     SAVE_STRING( p_module->domain );
601     return 0;
602
603 error:
604     return -1;
605 }
606
607
608 static int CacheSaveConfig (FILE *file, module_t *p_module)
609 {
610     uint32_t i_lines = p_module->confsize;
611
612     SAVE_IMMEDIATE( p_module->i_config_items );
613     SAVE_IMMEDIATE( p_module->i_bool_items );
614     SAVE_IMMEDIATE( i_lines );
615
616     for (size_t i = 0; i < i_lines ; i++)
617     {
618         SAVE_IMMEDIATE( p_module->p_config[i] );
619
620         SAVE_STRING( p_module->p_config[i].psz_type );
621         SAVE_STRING( p_module->p_config[i].psz_name );
622         SAVE_STRING( p_module->p_config[i].psz_text );
623         SAVE_STRING( p_module->p_config[i].psz_longtext );
624         SAVE_STRING( p_module->p_config[i].psz_oldname );
625         SAVE_IMMEDIATE( p_module->p_config[i].b_removed );
626
627         if (IsConfigStringType (p_module->p_config[i].i_type))
628             SAVE_STRING( p_module->p_config[i].orig.psz );
629
630         if( p_module->p_config[i].i_list )
631         {
632             if( p_module->p_config[i].ppsz_list )
633             {
634                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
635                     SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
636             }
637
638             if( p_module->p_config[i].ppsz_list_text )
639             {
640                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
641                     SAVE_STRING( p_module->p_config[i].ppsz_list_text[j] );
642             }
643             if( p_module->p_config[i].pi_list )
644             {
645                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
646                     SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
647             }
648         }
649
650         for (int j = 0; j < p_module->p_config[i].i_action; j++)
651             SAVE_STRING( p_module->p_config[i].ppsz_action_text[j] );
652
653         bool has_callback = p_module->p_config[i].pf_callback != NULL;
654         SAVE_IMMEDIATE( has_callback );
655     }
656     return 0;
657
658 error:
659     return -1;
660 }
661
662 /*****************************************************************************
663  * CacheMerge: Merge a cache module descriptor with a full module descriptor.
664  *****************************************************************************/
665 void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
666 {
667     (void)p_this;
668
669     p_cache->pf_activate = p_module->pf_activate;
670     p_cache->pf_deactivate = p_module->pf_deactivate;
671     p_cache->handle = p_module->handle;
672
673     /* FIXME: This looks too simplistic an algorithm to me. What if the module
674      * file was altered such that the number of order of submodules was
675      * altered... after VLC started -- Courmisch, 09/2008 */
676     module_t *p_child = p_module->submodule,
677              *p_cchild = p_cache->submodule;
678     while( p_child && p_cchild )
679     {
680         p_cchild->pf_activate = p_child->pf_activate;
681         p_cchild->pf_deactivate = p_child->pf_deactivate;
682         p_child = p_child->next;
683         p_cchild = p_cchild->next;
684     }
685
686     p_cache->b_loaded = true;
687     p_module->b_loaded = false;
688 }
689
690 /*****************************************************************************
691  * CacheFind: finds the cache entry corresponding to a file
692  *****************************************************************************/
693 module_cache_t *CacheFind( module_bank_t *p_bank, const char *psz_file,
694                            int64_t i_time, int64_t i_size )
695 {
696     module_cache_t **pp_cache;
697     int i_cache, i;
698
699     pp_cache = p_bank->pp_loaded_cache;
700     i_cache = p_bank->i_loaded_cache;
701
702     for( i = 0; i < i_cache; i++ )
703     {
704         if( !strcmp( pp_cache[i]->psz_file, psz_file ) &&
705             pp_cache[i]->i_time == i_time &&
706             pp_cache[i]->i_size == i_size ) return pp_cache[i];
707     }
708
709     return NULL;
710 }
711
712 #endif /* HAVE_DYNAMIC_PLUGINS */