]> git.sesse.net Git - vlc/blob - src/modules/cache.c
afda6074da84f0016d0ad2de83733d9c9d7b057e
[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 #include <vlc/vlc.h>
28 #include "libvlc.h"
29
30 #include <stdlib.h>                                      /* free(), strtol() */
31 #include <stdio.h>                                              /* sprintf() */
32 #include <string.h>                                              /* strdup() */
33
34 #ifdef HAVE_SYS_TYPES_H
35 #   include <sys/types.h>
36 #endif
37 #ifdef HAVE_UNISTD_H
38 #   include <unistd.h>
39 #endif
40
41 #if !defined(HAVE_DYNAMIC_PLUGINS)
42     /* no support for plugins */
43 #elif defined(HAVE_DL_DYLD)
44 #   if defined(HAVE_MACH_O_DYLD_H)
45 #       include <mach-o/dyld.h>
46 #   endif
47 #elif defined(HAVE_DL_BEOS)
48 #   if defined(HAVE_IMAGE_H)
49 #       include <image.h>
50 #   endif
51 #elif defined(HAVE_DL_WINDOWS)
52 #   include <windows.h>
53 #elif defined(HAVE_DL_DLOPEN)
54 #   if defined(HAVE_DLFCN_H) /* Linux, BSD, Hurd */
55 #       include <dlfcn.h>
56 #   endif
57 #   if defined(HAVE_SYS_DL_H)
58 #       include <sys/dl.h>
59 #   endif
60 #elif defined(HAVE_DL_SHL_LOAD)
61 #   if defined(HAVE_DL_H)
62 #       include <dl.h>
63 #   endif
64 #endif
65
66 #include "config/config.h"
67
68 #include "vlc_charset.h"
69
70 #include "modules/modules.h"
71
72
73 /*****************************************************************************
74  * Local prototypes
75  *****************************************************************************/
76 #ifdef HAVE_DYNAMIC_PLUGINS
77 static int    CacheLoadConfig  ( module_t *, FILE * );
78 static int    CacheSaveConfig  ( module_t *, FILE * );
79 static char * CacheName        ( void );
80
81 /* Sub-version number
82  * (only used to avoid breakage in dev version when cache structure changes) */
83 #define CACHE_SUBVERSION_NUM 3
84
85 /*****************************************************************************
86  * LoadPluginsCache: loads the plugins cache file
87  *****************************************************************************
88  * This function will load the plugin cache if present and valid. This cache
89  * will in turn be queried by AllocateAllPlugins() to see if it needs to
90  * actually load the dynamically loadable module.
91  * This allows us to only fully load plugins when they are actually used.
92  *****************************************************************************/
93 void CacheLoad( vlc_object_t *p_this )
94 {
95     char *psz_filename, *psz_cachedir;
96     FILE *file;
97     int i, j, i_size, i_read;
98     char p_cachestring[sizeof("cache " COPYRIGHT_MESSAGE)];
99     char p_cachelang[6], p_lang[6];
100     int i_cache;
101     module_cache_t **pp_cache = 0;
102     int32_t i_file_size, i_marker;
103     libvlc_global_data_t *p_libvlc_global = vlc_global();
104
105     psz_cachedir = p_this->p_libvlc->psz_cachedir;
106     if( !psz_cachedir ) /* XXX: this should never happen */
107     {
108         msg_Err( p_this, "Unable to get cache directory" );
109         return;
110     }
111
112     i_size = asprintf( &psz_filename, "%s"DIR_SEP"%s",
113                        psz_cachedir, CacheName() );
114     if( i_size <= 0 )
115     {
116         msg_Err( p_this, "out of memory" );
117         return;
118     }
119
120     if( p_libvlc_global->p_module_bank->b_cache_delete )
121     {
122 #if !defined( UNDER_CE )
123         unlink( psz_filename );
124 #else
125         wchar_t psz_wf[MAX_PATH];
126         MultiByteToWideChar( CP_ACP, 0, psz_filename, -1, psz_wf, MAX_PATH );
127         DeleteFile( psz_wf );
128 #endif
129         msg_Dbg( p_this, "removing plugins cache file %s", psz_filename );
130         free( psz_filename );
131         return;
132     }
133
134     msg_Dbg( p_this, "loading plugins cache file %s", psz_filename );
135
136     file = utf8_fopen( psz_filename, "rb" );
137     if( !file )
138     {
139         msg_Warn( p_this, "could not open plugins cache file %s for reading",
140                   psz_filename );
141         free( psz_filename );
142         return;
143     }
144     free( psz_filename );
145
146     /* Check the file size */
147     i_read = fread( &i_file_size, 1, sizeof(i_file_size), file );
148     if( i_read != sizeof(i_file_size) )
149     {
150         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
151                   "(too short)" );
152         fclose( file );
153         return;
154     }
155
156     fseek( file, 0, SEEK_END );
157     if( ftell( file ) != i_file_size )
158     {
159         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
160                   "(corrupted size)" );
161         fclose( file );
162         return;
163     }
164     fseek( file, sizeof(i_file_size), SEEK_SET );
165
166     /* Check the file is a plugins cache */
167     i_size = sizeof("cache " COPYRIGHT_MESSAGE) - 1;
168     i_read = fread( p_cachestring, 1, i_size, file );
169     if( i_read != i_size ||
170         memcmp( p_cachestring, "cache " COPYRIGHT_MESSAGE, i_size ) )
171     {
172         msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
173         fclose( file );
174         return;
175     }
176
177     /* Check Sub-version number */
178     i_read = fread( &i_marker, 1, sizeof(i_marker), file );
179     if( i_read != sizeof(i_marker) || i_marker != CACHE_SUBVERSION_NUM )
180     {
181         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
182                   "(corrupted header)" );
183         fclose( file );
184         return;
185     }
186
187     /* Check the language hasn't changed */
188     sprintf( p_lang, "%5.5s", _("C") ); i_size = 5;
189     i_read = fread( p_cachelang, 1, i_size, file );
190     if( i_read != i_size || memcmp( p_cachelang, p_lang, i_size ) )
191     {
192         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
193                   "(language changed)" );
194         fclose( file );
195         return;
196     }
197
198     /* Check header marker */
199     i_read = fread( &i_marker, 1, sizeof(i_marker), file );
200     if( i_read != sizeof(i_marker) ||
201         i_marker != ftell( file ) - (int)sizeof(i_marker) )
202     {
203         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
204                   "(corrupted header)" );
205         fclose( file );
206         return;
207     }
208
209     p_libvlc_global->p_module_bank->i_loaded_cache = 0;
210     if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) )
211     {
212         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
213                   "(file too short)" );
214         fclose( file );
215         return;
216     }
217
218     if( i_cache )
219         pp_cache = p_libvlc_global->p_module_bank->pp_loaded_cache =
220                    malloc( i_cache * sizeof(void *) );
221
222 #define LOAD_IMMEDIATE(a) \
223     if( fread( (void *)&a, sizeof(char), sizeof(a), file ) != sizeof(a) ) goto error
224 #define LOAD_STRING(a) \
225 { \
226     a = NULL; \
227     if( ( fread( &i_size, sizeof(i_size), 1, file ) != 1 ) \
228      || ( i_size > 16384 ) ) \
229         goto error; \
230     if( i_size ) { \
231         char *psz = malloc( i_size ); \
232         if( fread( psz, i_size, 1, file ) != 1 ) { \
233             free( psz ); \
234             goto error; \
235         } \
236         if( psz[i_size-1] ) { \
237             free( psz ); \
238             goto error; \
239         } \
240         a = psz; \
241     } \
242 }
243
244     for( i = 0; i < i_cache; i++ )
245     {
246         uint16_t i_size;
247         int i_submodules;
248
249         pp_cache[i] = malloc( sizeof(module_cache_t) );
250         p_libvlc_global->p_module_bank->i_loaded_cache++;
251
252         /* Load common info */
253         LOAD_STRING( pp_cache[i]->psz_file );
254         LOAD_IMMEDIATE( pp_cache[i]->i_time );
255         LOAD_IMMEDIATE( pp_cache[i]->i_size );
256         LOAD_IMMEDIATE( pp_cache[i]->b_junk );
257         pp_cache[i]->b_used = VLC_FALSE;
258
259         if( pp_cache[i]->b_junk ) continue;
260
261         pp_cache[i]->p_module = vlc_module_create( p_this );
262
263         /* Load additional infos */
264         LOAD_STRING( pp_cache[i]->p_module->psz_object_name );
265         LOAD_STRING( pp_cache[i]->p_module->psz_shortname );
266         LOAD_STRING( pp_cache[i]->p_module->psz_longname );
267         LOAD_STRING( pp_cache[i]->p_module->psz_help );
268         for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
269         {
270             LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
271         }
272         LOAD_STRING( pp_cache[i]->p_module->psz_capability );
273         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_score );
274         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_cpu );
275         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
276         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_reentrant );
277         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
278
279         /* Config stuff */
280         if( CacheLoadConfig( pp_cache[i]->p_module, file ) != VLC_SUCCESS )
281             goto error;
282
283         LOAD_STRING( pp_cache[i]->p_module->psz_filename );
284
285         LOAD_IMMEDIATE( i_submodules );
286
287         while( i_submodules-- )
288         {
289             module_t *p_module = vlc_submodule_create( pp_cache[i]->p_module );
290             LOAD_STRING( p_module->psz_object_name );
291             LOAD_STRING( p_module->psz_shortname );
292             LOAD_STRING( p_module->psz_longname );
293             LOAD_STRING( p_module->psz_help );
294             for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
295             {
296                 LOAD_STRING( p_module->pp_shortcuts[j] ); // FIX
297             }
298             LOAD_STRING( p_module->psz_capability );
299             LOAD_IMMEDIATE( p_module->i_score );
300             LOAD_IMMEDIATE( p_module->i_cpu );
301             LOAD_IMMEDIATE( p_module->b_unloadable );
302             LOAD_IMMEDIATE( p_module->b_reentrant );
303         }
304     }
305
306     fclose( file );
307     return;
308
309  error:
310
311     msg_Warn( p_this, "plugins cache not loaded (corrupted)" );
312
313     /* TODO: cleanup */
314     p_libvlc_global->p_module_bank->i_loaded_cache = 0;
315
316     fclose( file );
317     return;
318 }
319
320
321 static int CacheLoadConfig( module_t *p_module, FILE *file )
322 {
323     uint32_t i_lines;
324     uint16_t i_size;
325
326     /* Calculate the structure length */
327     LOAD_IMMEDIATE( p_module->i_config_items );
328     LOAD_IMMEDIATE( p_module->i_bool_items );
329
330     LOAD_IMMEDIATE( i_lines );
331
332     /* Allocate memory */
333     if (i_lines)
334     {
335         p_module->p_config =
336             (module_config_t *)calloc( i_lines, sizeof(module_config_t) );
337         if( p_module->p_config == NULL )
338         {
339             p_module->confsize = 0;
340             msg_Err( p_module, "config error: can't duplicate p_config" );
341             return VLC_ENOMEM;
342         }
343     }
344     p_module->confsize = i_lines;
345
346     /* Do the duplication job */
347     for (size_t i = 0; i < i_lines; i++ )
348     {
349         LOAD_IMMEDIATE( p_module->p_config[i] );
350
351         LOAD_STRING( p_module->p_config[i].psz_type );
352         LOAD_STRING( p_module->p_config[i].psz_name );
353         LOAD_STRING( p_module->p_config[i].psz_text );
354         LOAD_STRING( p_module->p_config[i].psz_longtext );
355         LOAD_STRING( p_module->p_config[i].psz_current );
356
357         if (IsConfigStringType (p_module->p_config[i].i_type))
358         {
359             LOAD_STRING (p_module->p_config[i].orig.psz);
360             p_module->p_config[i].value.psz =
361                     (p_module->p_config[i].orig.psz != NULL)
362                         ? strdup (p_module->p_config[i].orig.psz) : NULL;
363             p_module->p_config[i].saved.psz = NULL;
364         }
365         else
366         {
367             memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig,
368                     sizeof (p_module->p_config[i].value));
369             memcpy (&p_module->p_config[i].saved, &p_module->p_config[i].orig,
370                     sizeof (p_module->p_config[i].saved));
371         }
372
373         p_module->p_config[i].b_dirty = VLC_FALSE;
374
375         p_module->p_config[i].p_lock = &p_module->object_lock;
376
377         if( p_module->p_config[i].i_list )
378         {
379             if( p_module->p_config[i].ppsz_list )
380             {
381                 int j;
382                 p_module->p_config[i].ppsz_list =
383                     malloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
384                 if( p_module->p_config[i].ppsz_list )
385                 {
386                     for( j = 0; j < p_module->p_config[i].i_list; j++ )
387                         LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
388                     p_module->p_config[i].ppsz_list[j] = NULL;
389                 }
390             }
391             if( p_module->p_config[i].ppsz_list_text )
392             {
393                 int j;
394                 p_module->p_config[i].ppsz_list_text =
395                     malloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
396                 if( p_module->p_config[i].ppsz_list_text )
397                 {
398                   for( j = 0; j < p_module->p_config[i].i_list; j++ )
399                       LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
400                   p_module->p_config[i].ppsz_list_text[j] = NULL;
401                 }
402             }
403             if( p_module->p_config[i].pi_list )
404             {
405                 p_module->p_config[i].pi_list =
406                     malloc( (p_module->p_config[i].i_list + 1) * sizeof(int) );
407                 if( p_module->p_config[i].pi_list )
408                 {
409                     for (int j = 0; j < p_module->p_config[i].i_list; j++)
410                         LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
411                 }
412             }
413         }
414
415         if( p_module->p_config[i].i_action )
416         {
417             p_module->p_config[i].ppf_action =
418                 malloc( p_module->p_config[i].i_action * sizeof(void *) );
419             p_module->p_config[i].ppsz_action_text =
420                 malloc( p_module->p_config[i].i_action * sizeof(char *) );
421
422             for (int j = 0; j < p_module->p_config[i].i_action; j++)
423             {
424                 p_module->p_config[i].ppf_action[j] = 0;
425                 LOAD_STRING( p_module->p_config[i].ppsz_action_text[j] );
426             }
427         }
428
429         LOAD_IMMEDIATE( p_module->p_config[i].pf_callback );
430     }
431
432     return VLC_SUCCESS;
433
434  error:
435
436     return VLC_EGENERIC;
437 }
438
439 /*****************************************************************************
440  * SavePluginsCache: saves the plugins cache to a file
441  *****************************************************************************/
442 void CacheSave( vlc_object_t *p_this )
443 {
444     static char const psz_tag[] =
445         "Signature: 8a477f597d28d172789f06886806bc55\r\n"
446         "# This file is a cache directory tag created by VLC.\r\n"
447         "# For information about cache directory tags, see:\r\n"
448         "#   http://www.brynosaurus.com/cachedir/\r\n";
449
450     char *psz_cachedir;
451     FILE *file;
452     int i, j, i_cache;
453     module_cache_t **pp_cache;
454     uint32_t i_file_size = 0;
455     libvlc_global_data_t *p_libvlc_global = vlc_global();
456
457     psz_cachedir = p_this->p_libvlc->psz_cachedir;
458     if( !psz_cachedir ) /* XXX: this should never happen */
459     {
460         msg_Err( p_this, "unable to get cache directory" );
461         return;
462     }
463
464     char psz_filename[sizeof(DIR_SEP) + 32 + strlen(psz_cachedir)];
465     config_CreateDir( p_this, psz_cachedir );
466
467     snprintf( psz_filename, sizeof( psz_filename ),
468               "%s"DIR_SEP"CACHEDIR.TAG", psz_cachedir );
469     file = utf8_fopen( psz_filename, "wb" );
470     if (file != NULL)
471     {
472         if (fwrite (psz_tag, 1, sizeof (psz_tag) - 1, file) != 1)
473             clearerr (file); /* what else can we do? */
474         fclose( file );
475     }
476
477     snprintf( psz_filename, sizeof( psz_filename ),
478               "%s"DIR_SEP"%s", psz_cachedir, CacheName() );
479     msg_Dbg( p_this, "writing plugins cache %s", psz_filename );
480
481     file = utf8_fopen( psz_filename, "wb" );
482     if (file == NULL)
483         goto error;
484
485     /* Empty space for file size */
486     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
487         goto error;
488
489     /* Contains version number */
490     if (fputs ("cache "COPYRIGHT_MESSAGE, file) == EOF)
491         goto error;
492
493     /* Sub-version number (to avoid breakage in the dev version when cache
494      * structure changes) */
495     i_file_size = CACHE_SUBVERSION_NUM;
496     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1 )
497         goto error;
498
499     /* Language */
500     if (fprintf (file, "%5.5s", _("C")) == EOF)
501         goto error;
502
503     /* Header marker */
504     i_file_size = ftell( file );
505     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
506         goto error;
507
508     i_cache = p_libvlc_global->p_module_bank->i_cache;
509     pp_cache = p_libvlc_global->p_module_bank->pp_cache;
510
511     if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1)
512         goto error;
513
514 #define SAVE_IMMEDIATE( a ) \
515     if (fwrite (&a, sizeof(a), 1, file) != 1) \
516         goto error
517 #define SAVE_STRING( a ) \
518     { \
519         uint16_t i_size = (a != NULL) ? (strlen (a) + 1) : 0; \
520         if ((fwrite (&i_size, sizeof (i_size), 1, file) != 1) \
521          || (a && (fwrite (a, 1, i_size, file) != i_size))) \
522             goto error; \
523     } while(0)
524
525     for( i = 0; i < i_cache; i++ )
526     {
527         uint32_t i_submodule;
528
529         /* Save common info */
530         SAVE_STRING( pp_cache[i]->psz_file );
531         SAVE_IMMEDIATE( pp_cache[i]->i_time );
532         SAVE_IMMEDIATE( pp_cache[i]->i_size );
533         SAVE_IMMEDIATE( pp_cache[i]->b_junk );
534
535         if( pp_cache[i]->b_junk ) continue;
536
537         /* Save additional infos */
538         SAVE_STRING( pp_cache[i]->p_module->psz_object_name );
539         SAVE_STRING( pp_cache[i]->p_module->psz_shortname );
540         SAVE_STRING( pp_cache[i]->p_module->psz_longname );
541         SAVE_STRING( pp_cache[i]->p_module->psz_help );
542         for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
543         {
544             SAVE_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
545         }
546         SAVE_STRING( pp_cache[i]->p_module->psz_capability );
547         SAVE_IMMEDIATE( pp_cache[i]->p_module->i_score );
548         SAVE_IMMEDIATE( pp_cache[i]->p_module->i_cpu );
549         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
550         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_reentrant );
551         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
552
553         /* Config stuff */
554         if (CacheSaveConfig (pp_cache[i]->p_module, file))
555             goto error;
556
557         SAVE_STRING( pp_cache[i]->p_module->psz_filename );
558
559         i_submodule = pp_cache[i]->p_module->i_children;
560         SAVE_IMMEDIATE( i_submodule );
561         for( i_submodule = 0;
562              i_submodule < (unsigned)pp_cache[i]->p_module->i_children;
563              i_submodule++ )
564         {
565             module_t *p_module =
566                 (module_t *)pp_cache[i]->p_module->pp_children[i_submodule];
567
568             SAVE_STRING( p_module->psz_object_name );
569             SAVE_STRING( p_module->psz_shortname );
570             SAVE_STRING( p_module->psz_longname );
571             SAVE_STRING( p_module->psz_help );
572             for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
573             {
574                 SAVE_STRING( p_module->pp_shortcuts[j] ); // FIX
575             }
576             SAVE_STRING( p_module->psz_capability );
577             SAVE_IMMEDIATE( p_module->i_score );
578             SAVE_IMMEDIATE( p_module->i_cpu );
579             SAVE_IMMEDIATE( p_module->b_unloadable );
580             SAVE_IMMEDIATE( p_module->b_reentrant );
581         }
582     }
583
584     /* Fill-up file size */
585     i_file_size = ftell( file );
586     fseek( file, 0, SEEK_SET );
587     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
588         goto error;
589
590     if (fclose (file) == 0)
591         return; /* success! */
592
593     file = NULL;
594 error:
595     msg_Warn (p_this, "could not write plugins cache %s (%m)",
596               psz_filename);
597     if (file != NULL)
598     {
599         clearerr (file);
600         fclose (file);
601     }
602 }
603
604 static int CacheSaveConfig( module_t *p_module, FILE *file )
605 {
606     uint32_t i_lines = p_module->confsize;
607
608     SAVE_IMMEDIATE( p_module->i_config_items );
609     SAVE_IMMEDIATE( p_module->i_bool_items );
610     SAVE_IMMEDIATE( i_lines );
611
612     for (size_t i = 0; i < i_lines ; i++)
613     {
614         SAVE_IMMEDIATE( p_module->p_config[i] );
615
616         SAVE_STRING( p_module->p_config[i].psz_type );
617         SAVE_STRING( p_module->p_config[i].psz_name );
618         SAVE_STRING( p_module->p_config[i].psz_text );
619         SAVE_STRING( p_module->p_config[i].psz_longtext );
620         SAVE_STRING( p_module->p_config[i].psz_current );
621         if (IsConfigStringType (p_module->p_config[i].i_type))
622             SAVE_STRING( p_module->p_config[i].orig.psz );
623
624         if( p_module->p_config[i].i_list )
625         {
626             if( p_module->p_config[i].ppsz_list )
627             {
628                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
629                     SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
630             }
631
632             if( p_module->p_config[i].ppsz_list_text )
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_text[j] );
636             }
637             if( p_module->p_config[i].pi_list )
638             {
639                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
640                     SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
641             }
642         }
643
644         for (int j = 0; j < p_module->p_config[i].i_action; j++)
645             SAVE_STRING( p_module->p_config[i].ppsz_action_text[j] );
646
647         SAVE_IMMEDIATE( p_module->p_config[i].pf_callback );
648     }
649     return 0;
650
651 error:
652     return -1;
653 }
654
655 /*****************************************************************************
656  * CacheName: Return the cache file name for this platform.
657  *****************************************************************************/
658 static char *CacheName( void )
659 {
660     static char psz_cachename[32];
661
662     /* Code int size, pointer size and endianness in the filename */
663     int32_t x = 0xbe00001e;
664     sprintf( psz_cachename, "plugins-%.2x%.2x%.2x.dat", (int)sizeof(int),
665              (int)sizeof(void *), (unsigned int)((unsigned char *)&x)[0] );
666     return psz_cachename;
667 }
668
669 /*****************************************************************************
670  * CacheMerge: Merge a cache module descriptor with a full module descriptor.
671  *****************************************************************************/
672 void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
673 {
674     int i_submodule;
675     (void)p_this;
676
677     p_cache->pf_activate = p_module->pf_activate;
678     p_cache->pf_deactivate = p_module->pf_deactivate;
679     p_cache->handle = p_module->handle;
680
681     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
682     {
683         module_t *p_child = (module_t*)p_module->pp_children[i_submodule];
684         module_t *p_cchild = (module_t*)p_cache->pp_children[i_submodule];
685         p_cchild->pf_activate = p_child->pf_activate;
686         p_cchild->pf_deactivate = p_child->pf_deactivate;
687     }
688
689     p_cache->b_loaded = VLC_TRUE;
690     p_module->b_loaded = VLC_FALSE;
691 }
692
693 /*****************************************************************************
694  * CacheFind: finds the cache entry corresponding to a file
695  *****************************************************************************/
696 module_cache_t *CacheFind( vlc_object_t *p_this, const char *psz_file,
697                            int64_t i_time, int64_t i_size )
698 {
699     module_cache_t **pp_cache;
700     int i_cache, i;
701     libvlc_global_data_t *p_libvlc_global = vlc_global();
702
703     pp_cache = p_libvlc_global->p_module_bank->pp_loaded_cache;
704     i_cache = p_libvlc_global->p_module_bank->i_loaded_cache;
705
706     for( i = 0; i < i_cache; i++ )
707     {
708         if( !strcmp( pp_cache[i]->psz_file, psz_file ) &&
709             pp_cache[i]->i_time == i_time &&
710             pp_cache[i]->i_size == i_size ) return pp_cache[i];
711     }
712
713     return NULL;
714 }
715
716 #endif /* HAVE_DYNAMIC_PLUGINS */