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