libvlc_version.h: build-time version macros
[vlc/asuraparaju-public.git] / src / modules / cache.c
blob3f09ad8325ed6c3b9b0cd8d817ada68a5fcdebc6
1 /*****************************************************************************
2 * cache.c: Plugins cache
3 *****************************************************************************
4 * Copyright (C) 2001-2007 the VideoLAN team
5 * $Id$
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>
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.
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.
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 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include "libvlc.h"
34 #include <stdlib.h> /* free(), strtol() */
35 #include <stdio.h> /* sprintf() */
36 #include <string.h> /* strdup() */
37 #include <vlc_plugin.h>
38 #include <vlc_cpu.h>
39 #include <errno.h>
41 #include <sys/types.h>
42 #ifdef HAVE_UNISTD_H
43 # include <unistd.h>
44 #endif
45 #include <assert.h>
47 #include "config/configuration.h"
49 #include <vlc_fs.h>
51 #include "modules/modules.h"
54 /*****************************************************************************
55 * Local prototypes
56 *****************************************************************************/
57 #ifdef HAVE_DYNAMIC_PLUGINS
58 static int CacheLoadConfig ( module_t *, FILE * );
60 /* Sub-version number
61 * (only used to avoid breakage in dev version when cache structure changes) */
62 #define CACHE_SUBVERSION_NUM 11
64 /* Format string for the cache filename */
65 #define CACHENAME_FORMAT \
66 "plugins-%.2zx%.2zx%.2"PRIx8"-%x.dat"
67 /* Magic for the cache filename */
68 #define CACHENAME_VALUES \
69 sizeof(int), sizeof(void *), *(uint8_t *)&(uint16_t){ 0xbe1e }, vlc_CPU()
70 #define CACHE_STRING "cache "PACKAGE_NAME" "PACKAGE_VERSION
73 void CacheDelete( vlc_object_t *obj, const char *dir )
75 char *path;
77 assert( dir != NULL );
79 if( asprintf( &path, "%s"DIR_SEP CACHENAME_FORMAT,
80 dir, CACHENAME_VALUES ) == -1 )
81 return;
82 msg_Dbg( obj, "removing plugins cache file %s", path );
83 vlc_unlink( path );
84 free( path );
87 /*****************************************************************************
88 * LoadPluginsCache: loads the plugins cache file
89 *****************************************************************************
90 * This function will load the plugin cache if present and valid. This cache
91 * will in turn be queried by AllocateAllPlugins() to see if it needs to
92 * actually load the dynamically loadable module.
93 * This allows us to only fully load plugins when they are actually used.
94 *****************************************************************************/
95 void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
97 char *psz_filename;
98 FILE *file;
99 int i_size, i_read;
100 char p_cachestring[sizeof(CACHE_STRING)];
101 size_t i_cache;
102 module_cache_t **pp_cache = NULL;
103 int32_t i_file_size, i_marker;
105 assert( dir != NULL );
107 if( !p_bank->b_cache )
108 return;
110 if( asprintf( &psz_filename, "%s"DIR_SEP CACHENAME_FORMAT,
111 dir, CACHENAME_VALUES ) == -1 )
112 return;
114 msg_Dbg( p_this, "loading plugins cache file %s", psz_filename );
116 file = vlc_fopen( psz_filename, "rb" );
117 if( !file )
119 msg_Warn( p_this, "cannot read %s (%m)",
120 psz_filename );
121 free( psz_filename );
122 return;
124 free( psz_filename );
126 /* Check the file size */
127 i_read = fread( &i_file_size, 1, sizeof(i_file_size), file );
128 if( i_read != sizeof(i_file_size) )
130 msg_Warn( p_this, "This doesn't look like a valid plugins cache "
131 "(too short)" );
132 fclose( file );
133 return;
136 fseek( file, 0, SEEK_END );
137 if( ftell( file ) != i_file_size )
139 msg_Warn( p_this, "This doesn't look like a valid plugins cache "
140 "(corrupted size)" );
141 fclose( file );
142 return;
144 fseek( file, sizeof(i_file_size), SEEK_SET );
146 /* Check the file is a plugins cache */
147 i_size = sizeof(CACHE_STRING) - 1;
148 i_read = fread( p_cachestring, 1, i_size, file );
149 if( i_read != i_size ||
150 memcmp( p_cachestring, CACHE_STRING, i_size ) )
152 msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
153 fclose( file );
154 return;
157 #ifdef DISTRO_VERSION
158 /* Check for distribution specific version */
159 char p_distrostring[sizeof( DISTRO_VERSION )];
160 i_size = sizeof( DISTRO_VERSION ) - 1;
161 i_read = fread( p_distrostring, 1, i_size, file );
162 if( i_read != i_size ||
163 memcmp( p_distrostring, DISTRO_VERSION, i_size ) )
165 msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
166 fclose( file );
167 return;
169 #endif
171 /* Check Sub-version number */
172 i_read = fread( &i_marker, 1, sizeof(i_marker), file );
173 if( i_read != sizeof(i_marker) || i_marker != CACHE_SUBVERSION_NUM )
175 msg_Warn( p_this, "This doesn't look like a valid plugins cache "
176 "(corrupted header)" );
177 fclose( file );
178 return;
181 /* Check header marker */
182 i_read = fread( &i_marker, 1, sizeof(i_marker), file );
183 if( i_read != sizeof(i_marker) ||
184 i_marker != ftell( file ) - (int)sizeof(i_marker) )
186 msg_Warn( p_this, "This doesn't look like a valid plugins cache "
187 "(corrupted header)" );
188 fclose( file );
189 return;
192 if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) )
194 msg_Warn( p_this, "This doesn't look like a valid plugins cache "
195 "(file too short)" );
196 fclose( file );
197 return;
200 if( i_cache )
202 size_t i_already = p_bank->i_loaded_cache;
203 pp_cache = realloc( p_bank->pp_loaded_cache,
204 (i_already + i_cache) * sizeof(*pp_cache) );
205 if( unlikely(pp_cache == NULL) )
206 i_cache = 0; /* don't load */
207 else
209 p_bank->pp_loaded_cache = pp_cache;
210 pp_cache += i_already;
214 #define LOAD_IMMEDIATE(a) \
215 if( fread( (void *)&a, sizeof(char), sizeof(a), file ) != sizeof(a) ) goto error
216 #define LOAD_STRING(a) \
218 a = NULL; \
219 if( ( fread( &i_size, sizeof(i_size), 1, file ) != 1 ) \
220 || ( i_size > 16384 ) ) \
221 goto error; \
222 if( i_size ) { \
223 char *psz = xmalloc( i_size ); \
224 if( fread( psz, i_size, 1, file ) != 1 ) { \
225 free( psz ); \
226 goto error; \
228 if( psz[i_size-1] ) { \
229 free( psz ); \
230 goto error; \
232 a = psz; \
236 for( size_t i = 0; i < i_cache; i++ )
238 uint16_t i_size;
239 int i_submodules;
241 pp_cache[i] = xmalloc( sizeof(module_cache_t) );
243 /* Load common info */
244 LOAD_STRING( pp_cache[i]->psz_file );
245 LOAD_IMMEDIATE( pp_cache[i]->i_time );
246 LOAD_IMMEDIATE( pp_cache[i]->i_size );
248 pp_cache[i]->p_module = vlc_module_create( p_this );
250 /* Load additional infos */
251 free( pp_cache[i]->p_module->psz_object_name );
252 LOAD_STRING( pp_cache[i]->p_module->psz_object_name );
253 LOAD_STRING( pp_cache[i]->p_module->psz_shortname );
254 LOAD_STRING( pp_cache[i]->p_module->psz_longname );
255 LOAD_STRING( pp_cache[i]->p_module->psz_help );
257 LOAD_IMMEDIATE( pp_cache[i]->p_module->i_shortcuts );
258 if( pp_cache[i]->p_module->i_shortcuts > MODULE_SHORTCUT_MAX )
259 goto error;
260 else if( pp_cache[i]->p_module->i_shortcuts == 0 )
261 pp_cache[i]->p_module->pp_shortcuts = NULL;
262 else
264 pp_cache[i]->p_module->pp_shortcuts =
265 xmalloc( sizeof( char ** ) * pp_cache[i]->p_module->i_shortcuts );
266 for( unsigned j = 0; j < pp_cache[i]->p_module->i_shortcuts; j++ )
267 LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] );
270 LOAD_STRING( pp_cache[i]->p_module->psz_capability );
271 LOAD_IMMEDIATE( pp_cache[i]->p_module->i_score );
272 LOAD_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
273 LOAD_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
275 /* Config stuff */
276 if( CacheLoadConfig( pp_cache[i]->p_module, file ) != VLC_SUCCESS )
277 goto error;
279 LOAD_STRING( pp_cache[i]->p_module->psz_filename );
280 LOAD_STRING( pp_cache[i]->p_module->domain );
281 if( pp_cache[i]->p_module->domain != NULL )
282 vlc_bindtextdomain( pp_cache[i]->p_module->domain );
284 LOAD_IMMEDIATE( i_submodules );
286 while( i_submodules-- )
288 module_t *p_module = vlc_submodule_create( pp_cache[i]->p_module );
289 free( p_module->psz_object_name );
290 free( p_module->pp_shortcuts );
291 LOAD_STRING( p_module->psz_object_name );
292 LOAD_STRING( p_module->psz_shortname );
293 LOAD_STRING( p_module->psz_longname );
294 LOAD_STRING( p_module->psz_help );
296 LOAD_IMMEDIATE( p_module->i_shortcuts );
297 if( p_module->i_shortcuts > MODULE_SHORTCUT_MAX )
298 goto error;
299 else if( p_module->i_shortcuts == 0 )
300 p_module->pp_shortcuts = NULL;
301 else
303 p_module->pp_shortcuts = xmalloc( sizeof( char ** ) * p_module->i_shortcuts );
304 for( unsigned j = 0; j < p_module->i_shortcuts; j++ )
305 LOAD_STRING( p_module->pp_shortcuts[j] );
308 LOAD_STRING( p_module->psz_capability );
309 LOAD_IMMEDIATE( p_module->i_score );
310 LOAD_IMMEDIATE( p_module->b_unloadable );
311 LOAD_STRING( p_module->domain );
314 p_bank->i_loaded_cache += i_cache;
316 fclose( file );
317 return;
319 error:
321 msg_Warn( p_this, "plugins cache not loaded (corrupted)" );
323 /* TODO: cleanup */
324 fclose( file );
325 return;
329 /* This function should never be called.
330 * It is only used as a non-NULL vlc_callback_t value for comparison. */
331 static int dummy_callback (vlc_object_t *obj, const char *name,
332 vlc_value_t oldval, vlc_value_t newval, void *data)
334 (void) obj; (void)name; (void)oldval; (void)newval; (void)data;
335 assert (0);
339 static int CacheLoadConfig( module_t *p_module, FILE *file )
341 uint32_t i_lines;
342 uint16_t i_size;
344 /* Calculate the structure length */
345 LOAD_IMMEDIATE( p_module->i_config_items );
346 LOAD_IMMEDIATE( p_module->i_bool_items );
348 LOAD_IMMEDIATE( i_lines );
350 /* Allocate memory */
351 if (i_lines)
353 p_module->p_config =
354 (module_config_t *)calloc( i_lines, sizeof(module_config_t) );
355 if( p_module->p_config == NULL )
357 p_module->confsize = 0;
358 return VLC_ENOMEM;
361 p_module->confsize = i_lines;
363 /* Do the duplication job */
364 for (size_t i = 0; i < i_lines; i++ )
366 LOAD_IMMEDIATE( p_module->p_config[i] );
368 LOAD_STRING( p_module->p_config[i].psz_type );
369 LOAD_STRING( p_module->p_config[i].psz_name );
370 LOAD_STRING( p_module->p_config[i].psz_text );
371 LOAD_STRING( p_module->p_config[i].psz_longtext );
372 LOAD_STRING( p_module->p_config[i].psz_oldname );
373 LOAD_IMMEDIATE( p_module->p_config[i].b_removed );
375 if (IsConfigStringType (p_module->p_config[i].i_type))
377 LOAD_STRING (p_module->p_config[i].orig.psz);
378 p_module->p_config[i].value.psz =
379 (p_module->p_config[i].orig.psz != NULL)
380 ? strdup (p_module->p_config[i].orig.psz) : NULL;
381 p_module->p_config[i].saved.psz = NULL;
383 else
385 memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig,
386 sizeof (p_module->p_config[i].value));
387 memcpy (&p_module->p_config[i].saved, &p_module->p_config[i].orig,
388 sizeof (p_module->p_config[i].saved));
391 p_module->p_config[i].b_dirty = false;
393 if( p_module->p_config[i].i_list )
395 if( p_module->p_config[i].ppsz_list )
397 int j;
398 p_module->p_config[i].ppsz_list =
399 xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
400 if( p_module->p_config[i].ppsz_list )
402 for( j = 0; j < p_module->p_config[i].i_list; j++ )
403 LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
404 p_module->p_config[i].ppsz_list[j] = NULL;
407 if( p_module->p_config[i].ppsz_list_text )
409 int j;
410 p_module->p_config[i].ppsz_list_text =
411 xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
412 if( p_module->p_config[i].ppsz_list_text )
414 for( j = 0; j < p_module->p_config[i].i_list; j++ )
415 LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
416 p_module->p_config[i].ppsz_list_text[j] = NULL;
419 if( p_module->p_config[i].pi_list )
421 p_module->p_config[i].pi_list =
422 xmalloc( (p_module->p_config[i].i_list + 1) * sizeof(int) );
423 if( p_module->p_config[i].pi_list )
425 for (int j = 0; j < p_module->p_config[i].i_list; j++)
426 LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
431 if( p_module->p_config[i].i_action )
433 p_module->p_config[i].ppf_action =
434 xmalloc( p_module->p_config[i].i_action * sizeof(void *) );
435 p_module->p_config[i].ppsz_action_text =
436 xmalloc( p_module->p_config[i].i_action * sizeof(char *) );
438 for (int j = 0; j < p_module->p_config[i].i_action; j++)
440 p_module->p_config[i].ppf_action[j] = NULL;
441 LOAD_STRING( p_module->p_config[i].ppsz_action_text[j] );
445 bool has_callback;
446 LOAD_IMMEDIATE( has_callback );
447 if (has_callback)
448 p_module->p_config[i].pf_callback = dummy_callback;
451 return VLC_SUCCESS;
453 error:
455 return VLC_EGENERIC;
458 static int CacheSaveBank( FILE *file, module_cache_t *const *, size_t );
460 /*****************************************************************************
461 * SavePluginsCache: saves the plugins cache to a file
462 *****************************************************************************/
463 void CacheSave (vlc_object_t *p_this, const char *dir,
464 module_cache_t *const *pp_cache, size_t n)
466 char *filename, *tmpname;
468 if (asprintf (&filename, "%s"DIR_SEP CACHENAME_FORMAT, dir,
469 CACHENAME_VALUES ) == -1)
470 return;
472 if (asprintf (&tmpname, "%s.%"PRIu32, filename, (uint32_t)getpid ()) == -1)
474 free (filename);
475 return;
477 msg_Dbg (p_this, "saving plugins cache %s", filename);
479 FILE *file = vlc_fopen (tmpname, "wb");
480 if (file == NULL)
482 if (errno != EACCES && errno != ENOENT)
483 msg_Warn (p_this, "cannot create %s (%m)", tmpname);
484 goto out;
487 if (CacheSaveBank (file, pp_cache, n))
489 msg_Warn (p_this, "cannot write %s (%m)", tmpname);
490 clearerr (file);
491 fclose (file);
492 vlc_unlink (tmpname);
493 goto out;
496 #ifndef WIN32
497 vlc_rename (tmpname, filename); /* atomically replace old cache */
498 fclose (file);
499 #else
500 vlc_unlink (filename);
501 fclose (file);
502 vlc_rename (tmpname, filename);
503 #endif
504 out:
505 free (filename);
506 free (tmpname);
509 static int CacheSaveConfig (FILE *, const module_t *);
510 static int CacheSaveSubmodule (FILE *, const module_t *);
512 static int CacheSaveBank (FILE *file, module_cache_t *const *pp_cache,
513 size_t i_cache)
515 uint32_t i_file_size = 0;
517 /* Empty space for file size */
518 if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
519 goto error;
521 /* Contains version number */
522 if (fputs (CACHE_STRING, file) == EOF)
523 goto error;
524 #ifdef DISTRO_VERSION
525 /* Allow binary maintaner to pass a string to detect new binary version*/
526 if (fputs( DISTRO_VERSION, file ) == EOF)
527 goto error;
528 #endif
529 /* Sub-version number (to avoid breakage in the dev version when cache
530 * structure changes) */
531 i_file_size = CACHE_SUBVERSION_NUM;
532 if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1 )
533 goto error;
535 /* Header marker */
536 i_file_size = ftell( file );
537 if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
538 goto error;
540 if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1)
541 goto error;
543 #define SAVE_IMMEDIATE( a ) \
544 if (fwrite (&a, sizeof(a), 1, file) != 1) \
545 goto error
546 #define SAVE_STRING( a ) \
548 uint16_t i_size = (a != NULL) ? (strlen (a) + 1) : 0; \
549 if ((fwrite (&i_size, sizeof (i_size), 1, file) != 1) \
550 || (a && (fwrite (a, 1, i_size, file) != i_size))) \
551 goto error; \
552 } while(0)
554 for (unsigned i = 0; i < i_cache; i++)
556 uint32_t i_submodule;
558 /* Save common info */
559 SAVE_STRING( pp_cache[i]->psz_file );
560 SAVE_IMMEDIATE( pp_cache[i]->i_time );
561 SAVE_IMMEDIATE( pp_cache[i]->i_size );
563 /* Save additional infos */
564 SAVE_STRING( pp_cache[i]->p_module->psz_object_name );
565 SAVE_STRING( pp_cache[i]->p_module->psz_shortname );
566 SAVE_STRING( pp_cache[i]->p_module->psz_longname );
567 SAVE_STRING( pp_cache[i]->p_module->psz_help );
568 SAVE_IMMEDIATE( pp_cache[i]->p_module->i_shortcuts );
569 for (unsigned j = 0; j < pp_cache[i]->p_module->i_shortcuts; j++)
570 SAVE_STRING( pp_cache[i]->p_module->pp_shortcuts[j] );
572 SAVE_STRING( pp_cache[i]->p_module->psz_capability );
573 SAVE_IMMEDIATE( pp_cache[i]->p_module->i_score );
574 SAVE_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
575 SAVE_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
577 /* Config stuff */
578 if (CacheSaveConfig (file, pp_cache[i]->p_module))
579 goto error;
581 SAVE_STRING( pp_cache[i]->p_module->psz_filename );
582 SAVE_STRING( pp_cache[i]->p_module->domain );
584 i_submodule = pp_cache[i]->p_module->submodule_count;
585 SAVE_IMMEDIATE( i_submodule );
586 if( CacheSaveSubmodule( file, pp_cache[i]->p_module->submodule ) )
587 goto error;
590 /* Fill-up file size */
591 i_file_size = ftell( file );
592 fseek( file, 0, SEEK_SET );
593 if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1
594 || fflush (file)) /* flush libc buffers */
595 goto error;
596 return 0; /* success! */
598 error:
599 return -1;
602 static int CacheSaveSubmodule( FILE *file, const module_t *p_module )
604 if( !p_module )
605 return 0;
606 if( CacheSaveSubmodule( file, p_module->next ) )
607 goto error;
609 SAVE_STRING( p_module->psz_object_name );
610 SAVE_STRING( p_module->psz_shortname );
611 SAVE_STRING( p_module->psz_longname );
612 SAVE_STRING( p_module->psz_help );
613 SAVE_IMMEDIATE( p_module->i_shortcuts );
614 for( unsigned j = 0; j < p_module->i_shortcuts; j++ )
615 SAVE_STRING( p_module->pp_shortcuts[j] );
617 SAVE_STRING( p_module->psz_capability );
618 SAVE_IMMEDIATE( p_module->i_score );
619 SAVE_IMMEDIATE( p_module->b_unloadable );
620 SAVE_STRING( p_module->domain );
621 return 0;
623 error:
624 return -1;
628 static int CacheSaveConfig (FILE *file, const module_t *p_module)
630 uint32_t i_lines = p_module->confsize;
632 SAVE_IMMEDIATE( p_module->i_config_items );
633 SAVE_IMMEDIATE( p_module->i_bool_items );
634 SAVE_IMMEDIATE( i_lines );
636 for (size_t i = 0; i < i_lines ; i++)
638 SAVE_IMMEDIATE( p_module->p_config[i] );
640 SAVE_STRING( p_module->p_config[i].psz_type );
641 SAVE_STRING( p_module->p_config[i].psz_name );
642 SAVE_STRING( p_module->p_config[i].psz_text );
643 SAVE_STRING( p_module->p_config[i].psz_longtext );
644 SAVE_STRING( p_module->p_config[i].psz_oldname );
645 SAVE_IMMEDIATE( p_module->p_config[i].b_removed );
647 if (IsConfigStringType (p_module->p_config[i].i_type))
648 SAVE_STRING( p_module->p_config[i].orig.psz );
650 if( p_module->p_config[i].i_list )
652 if( p_module->p_config[i].ppsz_list )
654 for (int j = 0; j < p_module->p_config[i].i_list; j++)
655 SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
658 if( p_module->p_config[i].ppsz_list_text )
660 for (int j = 0; j < p_module->p_config[i].i_list; j++)
661 SAVE_STRING( p_module->p_config[i].ppsz_list_text[j] );
663 if( p_module->p_config[i].pi_list )
665 for (int j = 0; j < p_module->p_config[i].i_list; j++)
666 SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
670 for (int j = 0; j < p_module->p_config[i].i_action; j++)
671 SAVE_STRING( p_module->p_config[i].ppsz_action_text[j] );
673 bool has_callback = p_module->p_config[i].pf_callback != NULL;
674 SAVE_IMMEDIATE( has_callback );
676 return 0;
678 error:
679 return -1;
682 /*****************************************************************************
683 * CacheMerge: Merge a cache module descriptor with a full module descriptor.
684 *****************************************************************************/
685 void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
687 (void)p_this;
689 p_cache->pf_activate = p_module->pf_activate;
690 p_cache->pf_deactivate = p_module->pf_deactivate;
691 p_cache->handle = p_module->handle;
693 /* FIXME: This looks too simplistic an algorithm to me. What if the module
694 * file was altered such that the number of order of submodules was
695 * altered... after VLC started -- Courmisch, 09/2008 */
696 module_t *p_child = p_module->submodule,
697 *p_cchild = p_cache->submodule;
698 while( p_child && p_cchild )
700 p_cchild->pf_activate = p_child->pf_activate;
701 p_cchild->pf_deactivate = p_child->pf_deactivate;
702 p_child = p_child->next;
703 p_cchild = p_cchild->next;
706 p_cache->b_loaded = true;
707 p_module->b_loaded = false;
710 /*****************************************************************************
711 * CacheFind: finds the cache entry corresponding to a file
712 *****************************************************************************/
713 module_cache_t *CacheFind( module_bank_t *p_bank, const char *psz_file,
714 int64_t i_time, int64_t i_size )
716 module_cache_t **pp_cache;
717 int i_cache, i;
719 pp_cache = p_bank->pp_loaded_cache;
720 i_cache = p_bank->i_loaded_cache;
722 for( i = 0; i < i_cache; i++ )
724 if( !strcmp( pp_cache[i]->psz_file, psz_file ) &&
725 pp_cache[i]->i_time == i_time &&
726 pp_cache[i]->i_size == i_size ) return pp_cache[i];
729 return NULL;
732 #endif /* HAVE_DYNAMIC_PLUGINS */