]> git.sesse.net Git - vlc/blob - src/modules/cache.c
libvlc: use vlc_common.h (libvlccore) instead of vlc/vlc.h
[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
39 #ifdef HAVE_SYS_TYPES_H
40 #   include <sys/types.h>
41 #endif
42 #ifdef HAVE_UNISTD_H
43 #   include <unistd.h>
44 #endif
45
46 #if !defined(HAVE_DYNAMIC_PLUGINS)
47     /* no support for plugins */
48 #elif defined(HAVE_DL_DYLD)
49 #   if defined(HAVE_MACH_O_DYLD_H)
50 #       include <mach-o/dyld.h>
51 #   endif
52 #elif defined(HAVE_DL_BEOS)
53 #   if defined(HAVE_IMAGE_H)
54 #       include <image.h>
55 #   endif
56 #elif defined(HAVE_DL_WINDOWS)
57 #   include <windows.h>
58 #elif defined(HAVE_DL_DLOPEN)
59 #   if defined(HAVE_DLFCN_H) /* Linux, BSD, Hurd */
60 #       include <dlfcn.h>
61 #   endif
62 #   if defined(HAVE_SYS_DL_H)
63 #       include <sys/dl.h>
64 #   endif
65 #elif defined(HAVE_DL_SHL_LOAD)
66 #   if defined(HAVE_DL_H)
67 #       include <dl.h>
68 #   endif
69 #endif
70
71 #include "config/configuration.h"
72
73 #include "vlc_charset.h"
74
75 #include "modules/modules.h"
76
77
78 /*****************************************************************************
79  * Local prototypes
80  *****************************************************************************/
81 #ifdef HAVE_DYNAMIC_PLUGINS
82 static int    CacheLoadConfig  ( module_t *, FILE * );
83 static int    CacheSaveConfig  ( module_t *, FILE * );
84 static char * CacheName        ( void );
85
86 /* Sub-version number
87  * (only used to avoid breakage in dev version when cache structure changes) */
88 #define CACHE_SUBVERSION_NUM 3
89
90 /*****************************************************************************
91  * LoadPluginsCache: loads the plugins cache file
92  *****************************************************************************
93  * This function will load the plugin cache if present and valid. This cache
94  * will in turn be queried by AllocateAllPlugins() to see if it needs to
95  * actually load the dynamically loadable module.
96  * This allows us to only fully load plugins when they are actually used.
97  *****************************************************************************/
98 void CacheLoad( vlc_object_t *p_this )
99 {
100     char *psz_filename, *psz_cachedir = config_GetCacheDir();
101     FILE *file;
102     int i, j, i_size, i_read;
103     char p_cachestring[sizeof("cache " COPYRIGHT_MESSAGE)];
104     char p_cachelang[6], p_lang[6];
105     int i_cache;
106     module_cache_t **pp_cache = 0;
107     int32_t i_file_size, i_marker;
108     libvlc_global_data_t *p_libvlc_global = vlc_global();
109
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     free( psz_cachedir );
119     if( i_size <= 0 )
120     {
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         free( pp_cache[i]->p_module->psz_object_name );
269         LOAD_STRING( pp_cache[i]->p_module->psz_object_name );
270         LOAD_STRING( pp_cache[i]->p_module->psz_shortname );
271         LOAD_STRING( pp_cache[i]->p_module->psz_longname );
272         LOAD_STRING( pp_cache[i]->p_module->psz_help );
273         for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
274         {
275             LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
276         }
277         LOAD_STRING( pp_cache[i]->p_module->psz_capability );
278         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_score );
279         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_cpu );
280         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
281         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_reentrant );
282         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
283
284         /* Config stuff */
285         if( CacheLoadConfig( pp_cache[i]->p_module, file ) != VLC_SUCCESS )
286             goto error;
287
288         LOAD_STRING( pp_cache[i]->p_module->psz_filename );
289
290         LOAD_IMMEDIATE( i_submodules );
291
292         while( i_submodules-- )
293         {
294             module_t *p_module = vlc_submodule_create( pp_cache[i]->p_module );
295             free( p_module->psz_object_name );
296             LOAD_STRING( p_module->psz_object_name );
297             LOAD_STRING( p_module->psz_shortname );
298             LOAD_STRING( p_module->psz_longname );
299             LOAD_STRING( p_module->psz_help );
300             for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
301             {
302                 LOAD_STRING( p_module->pp_shortcuts[j] ); // FIX
303             }
304             LOAD_STRING( p_module->psz_capability );
305             LOAD_IMMEDIATE( p_module->i_score );
306             LOAD_IMMEDIATE( p_module->i_cpu );
307             LOAD_IMMEDIATE( p_module->b_unloadable );
308             LOAD_IMMEDIATE( p_module->b_reentrant );
309         }
310     }
311
312     fclose( file );
313     return;
314
315  error:
316
317     msg_Warn( p_this, "plugins cache not loaded (corrupted)" );
318
319     /* TODO: cleanup */
320     p_libvlc_global->p_module_bank->i_loaded_cache = 0;
321
322     fclose( file );
323     return;
324 }
325
326
327 static int CacheLoadConfig( module_t *p_module, FILE *file )
328 {
329     uint32_t i_lines;
330     uint16_t i_size;
331
332     /* Calculate the structure length */
333     LOAD_IMMEDIATE( p_module->i_config_items );
334     LOAD_IMMEDIATE( p_module->i_bool_items );
335
336     LOAD_IMMEDIATE( i_lines );
337
338     /* Allocate memory */
339     if (i_lines)
340     {
341         p_module->p_config =
342             (module_config_t *)calloc( i_lines, sizeof(module_config_t) );
343         if( p_module->p_config == NULL )
344         {
345             p_module->confsize = 0;
346             msg_Err( p_module, "config error: can't duplicate p_config" );
347             return VLC_ENOMEM;
348         }
349     }
350     p_module->confsize = i_lines;
351
352     /* Do the duplication job */
353     for (size_t i = 0; i < i_lines; i++ )
354     {
355         LOAD_IMMEDIATE( p_module->p_config[i] );
356
357         LOAD_STRING( p_module->p_config[i].psz_type );
358         LOAD_STRING( p_module->p_config[i].psz_name );
359         LOAD_STRING( p_module->p_config[i].psz_text );
360         LOAD_STRING( p_module->p_config[i].psz_longtext );
361         LOAD_STRING( p_module->p_config[i].psz_oldname );
362         LOAD_IMMEDIATE( p_module->p_config[i].b_removed );
363
364         if (IsConfigStringType (p_module->p_config[i].i_type))
365         {
366             LOAD_STRING (p_module->p_config[i].orig.psz);
367             p_module->p_config[i].value.psz =
368                     (p_module->p_config[i].orig.psz != NULL)
369                         ? strdup (p_module->p_config[i].orig.psz) : NULL;
370             p_module->p_config[i].saved.psz = NULL;
371         }
372         else
373         {
374             memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig,
375                     sizeof (p_module->p_config[i].value));
376             memcpy (&p_module->p_config[i].saved, &p_module->p_config[i].orig,
377                     sizeof (p_module->p_config[i].saved));
378         }
379
380         p_module->p_config[i].b_dirty = false;
381
382         p_module->p_config[i].p_lock = &p_module->object_lock;
383
384         if( p_module->p_config[i].i_list )
385         {
386             if( p_module->p_config[i].ppsz_list )
387             {
388                 int j;
389                 p_module->p_config[i].ppsz_list =
390                     malloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
391                 if( p_module->p_config[i].ppsz_list )
392                 {
393                     for( j = 0; j < p_module->p_config[i].i_list; j++ )
394                         LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
395                     p_module->p_config[i].ppsz_list[j] = NULL;
396                 }
397             }
398             if( p_module->p_config[i].ppsz_list_text )
399             {
400                 int j;
401                 p_module->p_config[i].ppsz_list_text =
402                     malloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
403                 if( p_module->p_config[i].ppsz_list_text )
404                 {
405                   for( j = 0; j < p_module->p_config[i].i_list; j++ )
406                       LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
407                   p_module->p_config[i].ppsz_list_text[j] = NULL;
408                 }
409             }
410             if( p_module->p_config[i].pi_list )
411             {
412                 p_module->p_config[i].pi_list =
413                     malloc( (p_module->p_config[i].i_list + 1) * sizeof(int) );
414                 if( p_module->p_config[i].pi_list )
415                 {
416                     for (int j = 0; j < p_module->p_config[i].i_list; j++)
417                         LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
418                 }
419             }
420         }
421
422         if( p_module->p_config[i].i_action )
423         {
424             p_module->p_config[i].ppf_action =
425                 malloc( p_module->p_config[i].i_action * sizeof(void *) );
426             p_module->p_config[i].ppsz_action_text =
427                 malloc( p_module->p_config[i].i_action * sizeof(char *) );
428
429             for (int j = 0; j < p_module->p_config[i].i_action; j++)
430             {
431                 p_module->p_config[i].ppf_action[j] = 0;
432                 LOAD_STRING( p_module->p_config[i].ppsz_action_text[j] );
433             }
434         }
435
436         LOAD_IMMEDIATE( p_module->p_config[i].pf_callback );
437     }
438
439     return VLC_SUCCESS;
440
441  error:
442
443     return VLC_EGENERIC;
444 }
445
446 /*****************************************************************************
447  * SavePluginsCache: saves the plugins cache to a file
448  *****************************************************************************/
449 void CacheSave( vlc_object_t *p_this )
450 {
451     static char const psz_tag[] =
452         "Signature: 8a477f597d28d172789f06886806bc55\r\n"
453         "# This file is a cache directory tag created by VLC.\r\n"
454         "# For information about cache directory tags, see:\r\n"
455         "#   http://www.brynosaurus.com/cachedir/\r\n";
456
457     char *psz_cachedir = config_GetCacheDir();
458     FILE *file;
459     int i, j, i_cache;
460     module_cache_t **pp_cache;
461     uint32_t i_file_size = 0;
462     libvlc_global_data_t *p_libvlc_global = vlc_global();
463
464     if( !psz_cachedir ) /* XXX: this should never happen */
465     {
466         msg_Err( p_this, "unable to get cache directory" );
467         return;
468     }
469
470     char psz_filename[sizeof(DIR_SEP) + 32 + strlen(psz_cachedir)];
471     config_CreateDir( p_this, psz_cachedir );
472
473     snprintf( psz_filename, sizeof( psz_filename ),
474               "%s"DIR_SEP"CACHEDIR.TAG", psz_cachedir );
475     file = utf8_fopen( psz_filename, "wb" );
476     if (file != NULL)
477     {
478         if (fwrite (psz_tag, 1, sizeof (psz_tag) - 1, file) != 1)
479             clearerr (file); /* what else can we do? */
480         fclose( file );
481     }
482
483     snprintf( psz_filename, sizeof( psz_filename ),
484               "%s"DIR_SEP"%s", psz_cachedir, CacheName() );
485     free( psz_cachedir );
486     msg_Dbg( p_this, "writing plugins cache %s", psz_filename );
487
488     file = utf8_fopen( psz_filename, "wb" );
489     if (file == NULL)
490         goto error;
491
492     /* Empty space for file size */
493     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
494         goto error;
495
496     /* Contains version number */
497     if (fputs ("cache "COPYRIGHT_MESSAGE, file) == EOF)
498         goto error;
499
500     /* Sub-version number (to avoid breakage in the dev version when cache
501      * structure changes) */
502     i_file_size = CACHE_SUBVERSION_NUM;
503     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1 )
504         goto error;
505
506     /* Language */
507     if (fprintf (file, "%5.5s", _("C")) == EOF)
508         goto error;
509
510     /* Header marker */
511     i_file_size = ftell( file );
512     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
513         goto error;
514
515     i_cache = p_libvlc_global->p_module_bank->i_cache;
516     pp_cache = p_libvlc_global->p_module_bank->pp_cache;
517
518     if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1)
519         goto error;
520
521 #define SAVE_IMMEDIATE( a ) \
522     if (fwrite (&a, sizeof(a), 1, file) != 1) \
523         goto error
524 #define SAVE_STRING( a ) \
525     { \
526         uint16_t i_size = (a != NULL) ? (strlen (a) + 1) : 0; \
527         if ((fwrite (&i_size, sizeof (i_size), 1, file) != 1) \
528          || (a && (fwrite (a, 1, i_size, file) != i_size))) \
529             goto error; \
530     } while(0)
531
532     for( i = 0; i < i_cache; i++ )
533     {
534         uint32_t i_submodule;
535
536         /* Save common info */
537         SAVE_STRING( pp_cache[i]->psz_file );
538         SAVE_IMMEDIATE( pp_cache[i]->i_time );
539         SAVE_IMMEDIATE( pp_cache[i]->i_size );
540         SAVE_IMMEDIATE( pp_cache[i]->b_junk );
541
542         if( pp_cache[i]->b_junk ) continue;
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( 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->i_cpu );
556         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
557         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_reentrant );
558         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
559
560         /* Config stuff */
561         if (CacheSaveConfig (pp_cache[i]->p_module, file))
562             goto error;
563
564         SAVE_STRING( pp_cache[i]->p_module->psz_filename );
565
566         i_submodule = vlc_internals( pp_cache[i]->p_module )->i_children;
567         SAVE_IMMEDIATE( i_submodule );
568         for( i_submodule = 0;
569              i_submodule < (unsigned)vlc_internals( pp_cache[i]->p_module)->i_children;
570              i_submodule++ )
571         {
572             module_t *p_module =
573                 (module_t *)vlc_internals( pp_cache[i]->p_module )->pp_children[i_submodule];
574
575             SAVE_STRING( p_module->psz_object_name );
576             SAVE_STRING( p_module->psz_shortname );
577             SAVE_STRING( p_module->psz_longname );
578             SAVE_STRING( p_module->psz_help );
579             for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
580             {
581                 SAVE_STRING( p_module->pp_shortcuts[j] ); // FIX
582             }
583             SAVE_STRING( p_module->psz_capability );
584             SAVE_IMMEDIATE( p_module->i_score );
585             SAVE_IMMEDIATE( p_module->i_cpu );
586             SAVE_IMMEDIATE( p_module->b_unloadable );
587             SAVE_IMMEDIATE( p_module->b_reentrant );
588         }
589     }
590
591     /* Fill-up file size */
592     i_file_size = ftell( file );
593     fseek( file, 0, SEEK_SET );
594     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
595         goto error;
596
597     if (fclose (file) == 0)
598         return; /* success! */
599
600     file = NULL;
601 error:
602     msg_Warn (p_this, "could not write plugins cache %s (%m)",
603               psz_filename);
604     if (file != NULL)
605     {
606         clearerr (file);
607         fclose (file);
608     }
609 }
610
611 static int CacheSaveConfig( module_t *p_module, FILE *file )
612 {
613     uint32_t i_lines = p_module->confsize;
614
615     SAVE_IMMEDIATE( p_module->i_config_items );
616     SAVE_IMMEDIATE( p_module->i_bool_items );
617     SAVE_IMMEDIATE( i_lines );
618
619     for (size_t i = 0; i < i_lines ; i++)
620     {
621         SAVE_IMMEDIATE( p_module->p_config[i] );
622
623         SAVE_STRING( p_module->p_config[i].psz_type );
624         SAVE_STRING( p_module->p_config[i].psz_name );
625         SAVE_STRING( p_module->p_config[i].psz_text );
626         SAVE_STRING( p_module->p_config[i].psz_longtext );
627         SAVE_STRING( p_module->p_config[i].psz_oldname );
628         SAVE_IMMEDIATE( p_module->p_config[i].b_removed );
629
630         if (IsConfigStringType (p_module->p_config[i].i_type))
631             SAVE_STRING( p_module->p_config[i].orig.psz );
632
633         if( p_module->p_config[i].i_list )
634         {
635             if( p_module->p_config[i].ppsz_list )
636             {
637                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
638                     SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
639             }
640
641             if( p_module->p_config[i].ppsz_list_text )
642             {
643                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
644                     SAVE_STRING( p_module->p_config[i].ppsz_list_text[j] );
645             }
646             if( p_module->p_config[i].pi_list )
647             {
648                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
649                     SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
650             }
651         }
652
653         for (int j = 0; j < p_module->p_config[i].i_action; j++)
654             SAVE_STRING( p_module->p_config[i].ppsz_action_text[j] );
655
656         SAVE_IMMEDIATE( p_module->p_config[i].pf_callback );
657     }
658     return 0;
659
660 error:
661     return -1;
662 }
663
664 /*****************************************************************************
665  * CacheName: Return the cache file name for this platform.
666  *****************************************************************************/
667 static char *CacheName( void )
668 {
669     static char psz_cachename[32];
670
671     /* Code int size, pointer size and endianness in the filename */
672     int32_t x = 0xbe00001e;
673     sprintf( psz_cachename, "plugins-%.2x%.2x%.2x.dat", (int)sizeof(int),
674              (int)sizeof(void *), (unsigned int)((unsigned char *)&x)[0] );
675     return psz_cachename;
676 }
677
678 /*****************************************************************************
679  * CacheMerge: Merge a cache module descriptor with a full module descriptor.
680  *****************************************************************************/
681 void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
682 {
683     int i_submodule;
684     (void)p_this;
685
686     p_cache->pf_activate = p_module->pf_activate;
687     p_cache->pf_deactivate = p_module->pf_deactivate;
688     p_cache->handle = p_module->handle;
689
690     for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ )
691     {
692         module_t *p_child = (module_t*)vlc_internals( p_module )->pp_children[i_submodule];
693         module_t *p_cchild = (module_t*)vlc_internals( p_cache )->pp_children[i_submodule];
694         p_cchild->pf_activate = p_child->pf_activate;
695         p_cchild->pf_deactivate = p_child->pf_deactivate;
696     }
697
698     p_cache->b_loaded = true;
699     p_module->b_loaded = false;
700 }
701
702 /*****************************************************************************
703  * CacheFind: finds the cache entry corresponding to a file
704  *****************************************************************************/
705 module_cache_t *CacheFind( const char *psz_file,
706                            int64_t i_time, int64_t i_size )
707 {
708     module_cache_t **pp_cache;
709     int i_cache, i;
710     libvlc_global_data_t *p_libvlc_global = vlc_global();
711
712     pp_cache = p_libvlc_global->p_module_bank->pp_loaded_cache;
713     i_cache = p_libvlc_global->p_module_bank->i_loaded_cache;
714
715     for( i = 0; i < i_cache; i++ )
716     {
717         if( !strcmp( pp_cache[i]->psz_file, psz_file ) &&
718             pp_cache[i]->i_time == i_time &&
719             pp_cache[i]->i_size == i_size ) return pp_cache[i];
720     }
721
722     return NULL;
723 }
724
725 #endif /* HAVE_DYNAMIC_PLUGINS */