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