]> git.sesse.net Git - vlc/blob - src/modules/cache.c
Don't load/save module_config_t.b_removed
[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 #include <errno.h>
39
40 #include <sys/types.h>
41 #ifdef HAVE_UNISTD_H
42 #   include <unistd.h>
43 #endif
44 #include <assert.h>
45
46 #include "config/configuration.h"
47
48 #include <vlc_fs.h>
49
50 #include "modules/modules.h"
51
52
53 /*****************************************************************************
54  * Local prototypes
55  *****************************************************************************/
56 #ifdef HAVE_DYNAMIC_PLUGINS
57 static int    CacheLoadConfig  ( module_t *, FILE * );
58
59 /* Sub-version number
60  * (only used to avoid breakage in dev version when cache structure changes) */
61 #define CACHE_SUBVERSION_NUM 14
62
63 /* Cache filename */
64 #define CACHE_NAME "plugins.dat"
65 /* Magic for the cache filename */
66 #define CACHE_STRING "cache "PACKAGE_NAME" "PACKAGE_VERSION
67
68
69 void CacheDelete( vlc_object_t *obj, const char *dir )
70 {
71     char *path;
72
73     assert( dir != NULL );
74
75     if( asprintf( &path, "%s"DIR_SEP CACHE_NAME, dir ) == -1 )
76         return;
77     msg_Dbg( obj, "removing plugins cache file %s", path );
78     vlc_unlink( path );
79     free( path );
80 }
81
82 /**
83  * Loads a plugins cache file.
84  *
85  * This function will load the plugin cache if present and valid. This cache
86  * will in turn be queried by AllocateAllPlugins() to see if it needs to
87  * actually load the dynamically loadable module.
88  * This allows us to only fully load plugins when they are actually used.
89  */
90 size_t CacheLoad( vlc_object_t *p_this, const char *dir, module_cache_t ***r )
91 {
92     char *psz_filename;
93     FILE *file;
94     int i_size, i_read;
95     char p_cachestring[sizeof(CACHE_STRING)];
96     size_t i_cache;
97     int32_t i_file_size, i_marker;
98
99     assert( dir != NULL );
100
101     *r = NULL;
102     if( asprintf( &psz_filename, "%s"DIR_SEP CACHE_NAME, dir ) == -1 )
103         return 0;
104
105     msg_Dbg( p_this, "loading plugins cache file %s", psz_filename );
106
107     file = vlc_fopen( psz_filename, "rb" );
108     if( !file )
109     {
110         msg_Warn( p_this, "cannot read %s (%m)",
111                   psz_filename );
112         free( psz_filename );
113         return 0;
114     }
115     free( psz_filename );
116
117     /* Check the file size */
118     i_read = fread( &i_file_size, 1, sizeof(i_file_size), file );
119     if( i_read != sizeof(i_file_size) )
120     {
121         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
122                   "(too short)" );
123         fclose( file );
124         return 0;
125     }
126
127     fseek( file, 0, SEEK_END );
128     if( ftell( file ) != i_file_size )
129     {
130         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
131                   "(corrupted size)" );
132         fclose( file );
133         return 0;
134     }
135     fseek( file, sizeof(i_file_size), SEEK_SET );
136
137     /* Check the file is a plugins cache */
138     i_size = sizeof(CACHE_STRING) - 1;
139     i_read = fread( p_cachestring, 1, i_size, file );
140     if( i_read != i_size ||
141         memcmp( p_cachestring, CACHE_STRING, i_size ) )
142     {
143         msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
144         fclose( file );
145         return 0;
146     }
147
148 #ifdef DISTRO_VERSION
149     /* Check for distribution specific version */
150     char p_distrostring[sizeof( DISTRO_VERSION )];
151     i_size = sizeof( DISTRO_VERSION ) - 1;
152     i_read = fread( p_distrostring, 1, i_size, file );
153     if( i_read != i_size ||
154         memcmp( p_distrostring, DISTRO_VERSION, i_size ) )
155     {
156         msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
157         fclose( file );
158         return 0;
159     }
160 #endif
161
162     /* Check Sub-version number */
163     i_read = fread( &i_marker, 1, sizeof(i_marker), file );
164     if( i_read != sizeof(i_marker) || i_marker != CACHE_SUBVERSION_NUM )
165     {
166         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
167                   "(corrupted header)" );
168         fclose( file );
169         return 0;
170     }
171
172     /* Check header marker */
173     i_read = fread( &i_marker, 1, sizeof(i_marker), file );
174     if( i_read != sizeof(i_marker) ||
175         i_marker != ftell( file ) - (int)sizeof(i_marker) )
176     {
177         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
178                   "(corrupted header)" );
179         fclose( file );
180         return 0;
181     }
182
183     if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) )
184     {
185         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
186                   "(file too short)" );
187         fclose( file );
188         return 0;
189     }
190
191     module_cache_t **pp_cache = malloc( i_cache * sizeof(*pp_cache) );
192     if( pp_cache == NULL )
193         i_cache = 0; /* don't load anything */
194
195 #define LOAD_IMMEDIATE(a) \
196     if( fread( (void *)&a, sizeof(char), sizeof(a), file ) != sizeof(a) ) goto error
197 #define LOAD_STRING(a) \
198 { \
199     a = NULL; \
200     if( ( fread( &i_size, sizeof(i_size), 1, file ) != 1 ) \
201      || ( i_size > 16384 ) ) \
202         goto error; \
203     if( i_size ) { \
204         char *psz = xmalloc( i_size ); \
205         if( fread( psz, i_size, 1, file ) != 1 ) { \
206             free( psz ); \
207             goto error; \
208         } \
209         if( psz[i_size-1] ) { \
210             free( psz ); \
211             goto error; \
212         } \
213         a = psz; \
214     } \
215 }
216
217     for( size_t i = 0; i < i_cache; i++ )
218     {
219         uint16_t i_size;
220         int i_submodules;
221
222         pp_cache[i] = xmalloc( sizeof(module_cache_t) );
223
224         /* Load common info */
225         LOAD_STRING( pp_cache[i]->path );
226         LOAD_IMMEDIATE( pp_cache[i]->mtime );
227         LOAD_IMMEDIATE( pp_cache[i]->size );
228
229         pp_cache[i]->p_module = vlc_module_create();
230
231         /* Load additional infos */
232         free( pp_cache[i]->p_module->psz_object_name );
233         LOAD_STRING( pp_cache[i]->p_module->psz_object_name );
234         LOAD_STRING( pp_cache[i]->p_module->psz_shortname );
235         LOAD_STRING( pp_cache[i]->p_module->psz_longname );
236         LOAD_STRING( pp_cache[i]->p_module->psz_help );
237
238         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_shortcuts );
239         if( pp_cache[i]->p_module->i_shortcuts > MODULE_SHORTCUT_MAX )
240             goto error;
241         else if( pp_cache[i]->p_module->i_shortcuts == 0 )
242             pp_cache[i]->p_module->pp_shortcuts = NULL;
243         else
244         {
245             pp_cache[i]->p_module->pp_shortcuts =
246                     xmalloc( sizeof( char ** ) * pp_cache[i]->p_module->i_shortcuts );
247             for( unsigned j = 0; j < pp_cache[i]->p_module->i_shortcuts; j++ )
248                 LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] );
249         }
250
251         LOAD_STRING( pp_cache[i]->p_module->psz_capability );
252         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_score );
253         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
254
255         /* Config stuff */
256         if( CacheLoadConfig( pp_cache[i]->p_module, file ) != VLC_SUCCESS )
257             goto error;
258
259         LOAD_STRING( pp_cache[i]->p_module->psz_filename );
260         LOAD_STRING( pp_cache[i]->p_module->domain );
261         if( pp_cache[i]->p_module->domain != NULL )
262             vlc_bindtextdomain( pp_cache[i]->p_module->domain );
263
264         LOAD_IMMEDIATE( i_submodules );
265
266         while( i_submodules-- )
267         {
268             module_t *p_module = vlc_submodule_create( pp_cache[i]->p_module );
269             free( p_module->psz_object_name );
270             free( p_module->pp_shortcuts );
271             LOAD_STRING( p_module->psz_object_name );
272             LOAD_STRING( p_module->psz_shortname );
273             LOAD_STRING( p_module->psz_longname );
274             LOAD_STRING( p_module->psz_help );
275
276             LOAD_IMMEDIATE( p_module->i_shortcuts );
277             if( p_module->i_shortcuts > MODULE_SHORTCUT_MAX )
278                 goto error;
279             else if( p_module->i_shortcuts == 0 )
280                 p_module->pp_shortcuts = NULL;
281             else
282             {
283                 p_module->pp_shortcuts = xmalloc( sizeof( char ** ) * p_module->i_shortcuts );
284                 for( unsigned j = 0; j < p_module->i_shortcuts; j++ )
285                     LOAD_STRING( p_module->pp_shortcuts[j] );
286             }
287
288             LOAD_STRING( p_module->psz_capability );
289             LOAD_IMMEDIATE( p_module->i_score );
290             LOAD_IMMEDIATE( p_module->b_unloadable );
291             LOAD_STRING( p_module->domain );
292         }
293     }
294     fclose( file );
295
296     *r = pp_cache;
297     return i_cache;
298
299  error:
300
301     msg_Warn( p_this, "plugins cache not loaded (corrupted)" );
302
303     /* TODO: cleanup */
304     fclose( file );
305     return 0;
306 }
307
308
309 static int CacheLoadConfig( module_t *p_module, FILE *file )
310 {
311     uint32_t i_lines;
312     uint16_t i_size;
313
314     /* Calculate the structure length */
315     LOAD_IMMEDIATE( p_module->i_config_items );
316     LOAD_IMMEDIATE( p_module->i_bool_items );
317
318     LOAD_IMMEDIATE( i_lines );
319
320     /* Allocate memory */
321     if (i_lines)
322     {
323         p_module->p_config =
324             (module_config_t *)calloc( i_lines, sizeof(module_config_t) );
325         if( p_module->p_config == NULL )
326         {
327             p_module->confsize = 0;
328             return VLC_ENOMEM;
329         }
330     }
331     p_module->confsize = i_lines;
332
333     /* Do the duplication job */
334     for (size_t i = 0; i < i_lines; i++ )
335     {
336         LOAD_IMMEDIATE( p_module->p_config[i] );
337
338         LOAD_STRING( p_module->p_config[i].psz_type );
339         LOAD_STRING( p_module->p_config[i].psz_name );
340         LOAD_STRING( p_module->p_config[i].psz_text );
341         LOAD_STRING( p_module->p_config[i].psz_longtext );
342         LOAD_STRING( p_module->p_config[i].psz_oldname );
343
344         if (IsConfigStringType (p_module->p_config[i].i_type))
345         {
346             LOAD_STRING (p_module->p_config[i].orig.psz);
347             p_module->p_config[i].value.psz =
348                     (p_module->p_config[i].orig.psz != NULL)
349                         ? strdup (p_module->p_config[i].orig.psz) : NULL;
350         }
351         else
352             memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig,
353                     sizeof (p_module->p_config[i].value));
354
355         p_module->p_config[i].b_dirty = false;
356
357         if( p_module->p_config[i].i_list )
358         {
359             if( p_module->p_config[i].ppsz_list )
360             {
361                 int j;
362                 p_module->p_config[i].ppsz_list =
363                     xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
364                 if( p_module->p_config[i].ppsz_list )
365                 {
366                     for( j = 0; j < p_module->p_config[i].i_list; j++ )
367                         LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
368                     p_module->p_config[i].ppsz_list[j] = NULL;
369                 }
370             }
371             if( p_module->p_config[i].ppsz_list_text )
372             {
373                 int j;
374                 p_module->p_config[i].ppsz_list_text =
375                     xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
376                 if( p_module->p_config[i].ppsz_list_text )
377                 {
378                   for( j = 0; j < p_module->p_config[i].i_list; j++ )
379                       LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
380                   p_module->p_config[i].ppsz_list_text[j] = NULL;
381                 }
382             }
383             if( p_module->p_config[i].pi_list )
384             {
385                 p_module->p_config[i].pi_list =
386                     xmalloc( (p_module->p_config[i].i_list + 1) * sizeof(int) );
387                 if( p_module->p_config[i].pi_list )
388                 {
389                     for (int j = 0; j < p_module->p_config[i].i_list; j++)
390                         LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
391                 }
392             }
393         }
394
395         if( p_module->p_config[i].i_action )
396         {
397             p_module->p_config[i].ppf_action =
398                 xmalloc( p_module->p_config[i].i_action * sizeof(void *) );
399             p_module->p_config[i].ppsz_action_text =
400                 xmalloc( p_module->p_config[i].i_action * sizeof(char *) );
401
402             for (int j = 0; j < p_module->p_config[i].i_action; j++)
403             {
404                 p_module->p_config[i].ppf_action[j] = NULL;
405                 LOAD_STRING( p_module->p_config[i].ppsz_action_text[j] );
406             }
407         }
408     }
409
410     return VLC_SUCCESS;
411
412  error:
413
414     return VLC_EGENERIC;
415 }
416
417 static int CacheSaveBank( FILE *file, module_cache_t *const *, size_t );
418
419 /*****************************************************************************
420  * SavePluginsCache: saves the plugins cache to a file
421  *****************************************************************************/
422 void CacheSave (vlc_object_t *p_this, const char *dir,
423                 module_cache_t *const *pp_cache, size_t n)
424 {
425     char *filename, *tmpname;
426
427     if (asprintf (&filename, "%s"DIR_SEP CACHE_NAME, dir ) == -1)
428         return;
429
430     if (asprintf (&tmpname, "%s.%"PRIu32, filename, (uint32_t)getpid ()) == -1)
431     {
432         free (filename);
433         return;
434     }
435     msg_Dbg (p_this, "saving plugins cache %s", filename);
436
437     FILE *file = vlc_fopen (tmpname, "wb");
438     if (file == NULL)
439     {
440         if (errno != EACCES && errno != ENOENT)
441             msg_Warn (p_this, "cannot create %s (%m)", tmpname);
442         goto out;
443     }
444
445     if (CacheSaveBank (file, pp_cache, n))
446     {
447         msg_Warn (p_this, "cannot write %s (%m)", tmpname);
448         clearerr (file);
449         fclose (file);
450         vlc_unlink (tmpname);
451         goto out;
452     }
453
454 #if !defined( WIN32 ) && !defined( __OS2__ )
455     vlc_rename (tmpname, filename); /* atomically replace old cache */
456     fclose (file);
457 #else
458     vlc_unlink (filename);
459     fclose (file);
460     vlc_rename (tmpname, filename);
461 #endif
462 out:
463     free (filename);
464     free (tmpname);
465 }
466
467 static int CacheSaveConfig (FILE *, const module_t *);
468 static int CacheSaveSubmodule (FILE *, const module_t *);
469
470 static int CacheSaveBank (FILE *file, module_cache_t *const *pp_cache,
471                           size_t i_cache)
472 {
473     uint32_t i_file_size = 0;
474
475     /* Empty space for file size */
476     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
477         goto error;
478
479     /* Contains version number */
480     if (fputs (CACHE_STRING, file) == EOF)
481         goto error;
482 #ifdef DISTRO_VERSION
483     /* Allow binary maintaner to pass a string to detect new binary version*/
484     if (fputs( DISTRO_VERSION, file ) == EOF)
485         goto error;
486 #endif
487     /* Sub-version number (to avoid breakage in the dev version when cache
488      * structure changes) */
489     i_file_size = CACHE_SUBVERSION_NUM;
490     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1 )
491         goto error;
492
493     /* Header marker */
494     i_file_size = ftell( file );
495     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
496         goto error;
497
498     if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1)
499         goto error;
500
501 #define SAVE_IMMEDIATE( a ) \
502     if (fwrite (&a, sizeof(a), 1, file) != 1) \
503         goto error
504 #define SAVE_STRING( a ) \
505     { \
506         uint16_t i_size = (a != NULL) ? (strlen (a) + 1) : 0; \
507         if ((fwrite (&i_size, sizeof (i_size), 1, file) != 1) \
508          || (a && (fwrite (a, 1, i_size, file) != i_size))) \
509             goto error; \
510     } while(0)
511
512     for (unsigned i = 0; i < i_cache; i++)
513     {
514         uint32_t i_submodule;
515
516         /* Save common info */
517         SAVE_STRING( pp_cache[i]->path );
518         SAVE_IMMEDIATE( pp_cache[i]->mtime );
519         SAVE_IMMEDIATE( pp_cache[i]->size );
520
521         /* Save additional infos */
522         SAVE_STRING( pp_cache[i]->p_module->psz_object_name );
523         SAVE_STRING( pp_cache[i]->p_module->psz_shortname );
524         SAVE_STRING( pp_cache[i]->p_module->psz_longname );
525         SAVE_STRING( pp_cache[i]->p_module->psz_help );
526         SAVE_IMMEDIATE( pp_cache[i]->p_module->i_shortcuts );
527         for (unsigned j = 0; j < pp_cache[i]->p_module->i_shortcuts; j++)
528             SAVE_STRING( pp_cache[i]->p_module->pp_shortcuts[j] );
529
530         SAVE_STRING( pp_cache[i]->p_module->psz_capability );
531         SAVE_IMMEDIATE( pp_cache[i]->p_module->i_score );
532         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
533
534         /* Config stuff */
535         if (CacheSaveConfig (file, pp_cache[i]->p_module))
536             goto error;
537
538         SAVE_STRING( pp_cache[i]->p_module->psz_filename );
539         SAVE_STRING( pp_cache[i]->p_module->domain );
540
541         i_submodule = pp_cache[i]->p_module->submodule_count;
542         SAVE_IMMEDIATE( i_submodule );
543         if( CacheSaveSubmodule( file, pp_cache[i]->p_module->submodule ) )
544             goto error;
545     }
546
547     /* Fill-up file size */
548     i_file_size = ftell( file );
549     fseek( file, 0, SEEK_SET );
550     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1
551      || fflush (file)) /* flush libc buffers */
552         goto error;
553     return 0; /* success! */
554
555 error:
556     return -1;
557 }
558
559 static int CacheSaveSubmodule( FILE *file, const module_t *p_module )
560 {
561     if( !p_module )
562         return 0;
563     if( CacheSaveSubmodule( file, p_module->next ) )
564         goto error;
565
566     SAVE_STRING( p_module->psz_object_name );
567     SAVE_STRING( p_module->psz_shortname );
568     SAVE_STRING( p_module->psz_longname );
569     SAVE_STRING( p_module->psz_help );
570     SAVE_IMMEDIATE( p_module->i_shortcuts );
571     for( unsigned j = 0; j < p_module->i_shortcuts; j++ )
572          SAVE_STRING( p_module->pp_shortcuts[j] );
573
574     SAVE_STRING( p_module->psz_capability );
575     SAVE_IMMEDIATE( p_module->i_score );
576     SAVE_IMMEDIATE( p_module->b_unloadable );
577     SAVE_STRING( p_module->domain );
578     return 0;
579
580 error:
581     return -1;
582 }
583
584
585 static int CacheSaveConfig (FILE *file, const module_t *p_module)
586 {
587     uint32_t i_lines = p_module->confsize;
588
589     SAVE_IMMEDIATE( p_module->i_config_items );
590     SAVE_IMMEDIATE( p_module->i_bool_items );
591     SAVE_IMMEDIATE( i_lines );
592
593     for (size_t i = 0; i < i_lines ; i++)
594     {
595         SAVE_IMMEDIATE( p_module->p_config[i] );
596
597         SAVE_STRING( p_module->p_config[i].psz_type );
598         SAVE_STRING( p_module->p_config[i].psz_name );
599         SAVE_STRING( p_module->p_config[i].psz_text );
600         SAVE_STRING( p_module->p_config[i].psz_longtext );
601         SAVE_STRING( p_module->p_config[i].psz_oldname );
602
603         if (IsConfigStringType (p_module->p_config[i].i_type))
604             SAVE_STRING( p_module->p_config[i].orig.psz );
605
606         if( p_module->p_config[i].i_list )
607         {
608             if( p_module->p_config[i].ppsz_list )
609             {
610                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
611                     SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
612             }
613
614             if( p_module->p_config[i].ppsz_list_text )
615             {
616                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
617                     SAVE_STRING( p_module->p_config[i].ppsz_list_text[j] );
618             }
619             if( p_module->p_config[i].pi_list )
620             {
621                 for (int j = 0; j < p_module->p_config[i].i_list; j++)
622                     SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
623             }
624         }
625
626         for (int j = 0; j < p_module->p_config[i].i_action; j++)
627             SAVE_STRING( p_module->p_config[i].ppsz_action_text[j] );
628     }
629     return 0;
630
631 error:
632     return -1;
633 }
634
635 /*****************************************************************************
636  * CacheMerge: Merge a cache module descriptor with a full module descriptor.
637  *****************************************************************************/
638 void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
639 {
640     (void)p_this;
641
642     p_cache->pf_activate = p_module->pf_activate;
643     p_cache->pf_deactivate = p_module->pf_deactivate;
644     p_cache->handle = p_module->handle;
645
646     /* FIXME: This looks too simplistic an algorithm to me. What if the module
647      * file was altered such that the number of order of submodules was
648      * altered... after VLC started -- Courmisch, 09/2008 */
649     module_t *p_child = p_module->submodule,
650              *p_cchild = p_cache->submodule;
651     while( p_child && p_cchild )
652     {
653         p_cchild->pf_activate = p_child->pf_activate;
654         p_cchild->pf_deactivate = p_child->pf_deactivate;
655         p_child = p_child->next;
656         p_cchild = p_cchild->next;
657     }
658
659     p_cache->b_loaded = true;
660     p_module->b_loaded = false;
661 }
662
663 /*****************************************************************************
664  * CacheFind: finds the cache entry corresponding to a file
665  *****************************************************************************/
666 module_t *CacheFind( module_bank_t *p_bank,
667                      const char *path, time_t mtime, off_t size )
668 {
669     module_cache_t **cache = p_bank->pp_loaded_cache;
670     size_t n = p_bank->i_loaded_cache;
671
672     for( size_t i = 0; i < n; i++ )
673         if( !strcmp( cache[i]->path, path )
674          && cache[i]->mtime == mtime
675          && cache[i]->size == size )
676        {
677             module_t *module = cache[i]->p_module;
678             cache[i]->p_module = NULL;
679             return module;
680        }
681
682     return NULL;
683 }
684
685 #endif /* HAVE_DYNAMIC_PLUGINS */