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