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