]> git.sesse.net Git - vlc/blob - src/misc/modules.c
* modules/stream_out/transcode.c: added support for subtitles overlaying when transco...
[vlc] / src / misc / modules.c
1 /*****************************************************************************
2  * modules.c : Builtin and plugin modules management functions
3  *****************************************************************************
4  * Copyright (C) 2001-2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
25  *****************************************************************************/
26
27 /* Some faulty libcs have a broken struct dirent when _FILE_OFFSET_BITS
28  * is set to 64. Don't try to be cleverer. */
29 #ifdef _FILE_OFFSET_BITS
30 #undef _FILE_OFFSET_BITS
31 #endif
32
33 #include <stdlib.h>                                      /* free(), strtol() */
34 #include <stdio.h>                                              /* sprintf() */
35 #include <string.h>                                              /* strdup() */
36
37 #include <vlc/vlc.h>
38 #include <vlc/input.h>
39
40 #ifdef HAVE_DIRENT_H
41 #   include <dirent.h>
42 #elif defined( UNDER_CE )
43 #   include <windows.h>                               /* GetFileAttributes() */
44 #else
45 #   include "../extras/dirent.h"
46 #endif
47
48 #ifdef HAVE_SYS_TYPES_H
49 #   include <sys/types.h>
50 #endif
51 #ifdef HAVE_SYS_STAT_H
52 #   include <sys/stat.h>
53 #endif
54 #ifdef HAVE_UNISTD_H
55 #   include <unistd.h>
56 #endif
57
58 #define HAVE_DYNAMIC_PLUGINS
59 #if defined(HAVE_DL_DYLD)
60 #   if defined(HAVE_MACH_O_DYLD_H)
61 #       include <mach-o/dyld.h>
62 #   endif
63 #elif defined(HAVE_DL_BEOS)
64 #   if defined(HAVE_IMAGE_H)
65 #       include <image.h>
66 #   endif
67 #elif defined(HAVE_DL_WINDOWS)
68 #   include <windows.h>
69 #elif defined(HAVE_DL_DLOPEN)
70 #   if defined(HAVE_DLFCN_H) /* Linux, BSD, Hurd */
71 #       include <dlfcn.h>
72 #   endif
73 #   if defined(HAVE_SYS_DL_H)
74 #       include <sys/dl.h>
75 #   endif
76 #elif defined(HAVE_DL_SHL_LOAD)
77 #   if defined(HAVE_DL_H)
78 #       include <dl.h>
79 #   endif
80 #else
81 #   undef HAVE_DYNAMIC_PLUGINS
82 #endif
83
84 #include "vlc_error.h"
85
86 #include "vlc_interface.h"
87 #include "intf_eject.h"
88
89 #include "vlc_playlist.h"
90
91 #include "vlc_video.h"
92 #include "video_output.h"
93 #include "vout_synchro.h"
94
95 #include "audio_output.h"
96 #include "aout_internal.h"
97
98 #include "stream_output.h"
99 #include "osd.h"
100 #include "vlc_httpd.h"
101
102 #include "iso_lang.h"
103 #include "charset.h"
104
105 #include "vlc_block.h"
106
107 #include "vlc_vlm.h"
108
109 #ifdef HAVE_DYNAMIC_PLUGINS
110 #   include "modules_plugin.h"
111 #endif
112
113 #if defined( UNDER_CE )
114 #    include "modules_builtin_evc.h"
115 #elif defined( _MSC_VER )
116 #    include "modules_builtin_msvc.h"
117 #else
118 #    include "modules_builtin.h"
119 #endif
120 #include "network.h"
121
122 #if defined( WIN32) || defined( UNDER_CE )
123     /* Avoid name collisions */
124 #   define LoadModule(a,b,c) _LoadModule(a,b,c)
125 #endif
126
127 /*****************************************************************************
128  * Local prototypes
129  *****************************************************************************/
130 #ifdef HAVE_DYNAMIC_PLUGINS
131 static void AllocateAllPlugins  ( vlc_object_t * );
132 static void AllocatePluginDir   ( vlc_object_t *, const char *, int );
133 static int  AllocatePluginFile  ( vlc_object_t *, char *, int64_t, int64_t );
134 static module_t * AllocatePlugin( vlc_object_t *, char * );
135 #endif
136 static int  AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
137 static int  DeleteModule ( module_t * );
138 #ifdef HAVE_DYNAMIC_PLUGINS
139 static void   DupModule        ( module_t * );
140 static void   UndupModule      ( module_t * );
141 static int    CallEntry        ( module_t * );
142 static int    LoadModule       ( vlc_object_t *, char *, module_handle_t * );
143 static void   CloseModule      ( module_handle_t );
144 static void * GetSymbol        ( module_handle_t, const char * );
145 static void   CacheLoad        ( vlc_object_t * );
146 static int    CacheLoadConfig  ( module_t *, FILE * );
147 static void   CacheSave        ( vlc_object_t * );
148 static void   CacheSaveConfig  ( module_t *, FILE * );
149 static void   CacheMerge       ( vlc_object_t *, module_t *, module_t * );
150 static module_cache_t * CacheFind( vlc_object_t *, char *, int64_t, int64_t );
151
152 #if defined(HAVE_DL_WINDOWS)
153 static char * GetWindowsError  ( void );
154 #endif
155 #endif
156
157 /*****************************************************************************
158  * module_InitBank: create the module bank.
159  *****************************************************************************
160  * This function creates a module bank structure which will be filled later
161  * on with all the modules found.
162  *****************************************************************************/
163 void __module_InitBank( vlc_object_t *p_this )
164 {
165     module_bank_t *p_bank;
166     vlc_value_t  lockval;
167
168     var_Create( p_this->p_libvlc, "libvlc", VLC_VAR_MUTEX );
169     var_Get( p_this->p_libvlc, "libvlc", &lockval );
170     vlc_mutex_lock( lockval.p_address );
171     if( p_this->p_libvlc->p_module_bank )
172     {
173         p_this->p_libvlc->p_module_bank->i_usage++;
174         vlc_mutex_unlock( lockval.p_address );
175         var_Destroy( p_this->p_libvlc, "libvlc" );
176         return;
177     }
178     vlc_mutex_unlock( lockval.p_address );
179     var_Destroy( p_this->p_libvlc, "libvlc" );
180
181     p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
182     p_bank->psz_object_name = "module bank";
183     p_bank->i_usage = 1;
184     p_bank->i_cache = p_bank->i_loaded_cache = 0;
185     p_bank->pp_cache = p_bank->pp_loaded_cache = 0;
186     p_bank->b_cache = p_bank->b_cache_dirty =
187         p_bank->b_cache_delete = VLC_FALSE;
188
189     /*
190      * Store the symbols to be exported
191      */
192 #ifdef HAVE_DYNAMIC_PLUGINS
193     STORE_SYMBOLS( &p_bank->symbols );
194 #endif
195
196     /* Everything worked, attach the object */
197     p_this->p_libvlc->p_module_bank = p_bank;
198     vlc_object_attach( p_bank, p_this->p_libvlc );
199
200     module_LoadMain( p_this );
201
202     return;
203 }
204
205 /*****************************************************************************
206  * module_ResetBank: reset the module bank.
207  *****************************************************************************
208  * This function resets the module bank by unloading all unused plugin
209  * modules.
210  *****************************************************************************/
211 void __module_ResetBank( vlc_object_t *p_this )
212 {
213     msg_Err( p_this, "FIXME: module_ResetBank unimplemented" );
214     return;
215 }
216
217 /*****************************************************************************
218  * module_EndBank: empty the module bank.
219  *****************************************************************************
220  * This function unloads all unused plugin modules and empties the module
221  * bank in case of success.
222  *****************************************************************************/
223 void __module_EndBank( vlc_object_t *p_this )
224 {
225     module_t * p_next;
226     vlc_value_t  lockval;
227
228     var_Create( p_this->p_libvlc, "libvlc", VLC_VAR_MUTEX );
229     var_Get( p_this->p_libvlc, "libvlc", &lockval );
230     vlc_mutex_lock( lockval.p_address );
231     if( !p_this->p_libvlc->p_module_bank )
232     {
233         vlc_mutex_unlock( lockval.p_address );
234         var_Destroy( p_this->p_libvlc, "libvlc" );
235         return;
236     }
237     if( --p_this->p_libvlc->p_module_bank->i_usage )
238     {
239         vlc_mutex_unlock( lockval.p_address );
240         var_Destroy( p_this->p_libvlc, "libvlc" );
241         return;
242     }
243     vlc_mutex_unlock( lockval.p_address );
244     var_Destroy( p_this->p_libvlc, "libvlc" );
245
246 #ifdef HAVE_DYNAMIC_PLUGINS
247     if( p_this->p_libvlc->p_module_bank->b_cache ) CacheSave( p_this );
248 #endif
249
250     vlc_object_detach( p_this->p_libvlc->p_module_bank );
251
252     while( p_this->p_libvlc->p_module_bank->i_children )
253     {
254         p_next = (module_t *)p_this->p_libvlc->p_module_bank->pp_children[0];
255
256         if( DeleteModule( p_next ) )
257         {
258             /* Module deletion failed */
259             msg_Err( p_this, "module \"%s\" can't be removed, trying harder",
260                      p_next->psz_object_name );
261
262             /* We just free the module by hand. Niahahahahaha. */
263             vlc_object_detach( p_next );
264             vlc_object_destroy( p_next );
265         }
266     }
267
268     vlc_object_destroy( p_this->p_libvlc->p_module_bank );
269
270     return;
271 }
272
273 /*****************************************************************************
274  * module_LoadMain: load the main program info into the module bank.
275  *****************************************************************************
276  * This function fills the module bank structure with the main module infos.
277  * This is very useful as it will allow us to consider the main program just
278  * as another module, and for instance the configuration options of main will
279  * be available in the module bank structure just as for every other module.
280  *****************************************************************************/
281 void __module_LoadMain( vlc_object_t *p_this )
282 {
283     AllocateBuiltinModule( p_this, vlc_entry__main );
284 }
285
286 /*****************************************************************************
287  * module_LoadBuiltins: load all modules which we built with.
288  *****************************************************************************
289  * This function fills the module bank structure with the builtin modules.
290  *****************************************************************************/
291 void __module_LoadBuiltins( vlc_object_t * p_this )
292 {
293     msg_Dbg( p_this, "checking builtin modules" );
294     ALLOCATE_ALL_BUILTINS();
295 }
296
297 /*****************************************************************************
298  * module_LoadPlugins: load all plugin modules we can find.
299  *****************************************************************************
300  * This function fills the module bank structure with the plugin modules.
301  *****************************************************************************/
302 void __module_LoadPlugins( vlc_object_t * p_this )
303 {
304 #ifdef HAVE_DYNAMIC_PLUGINS
305     msg_Dbg( p_this, "checking plugin modules" );
306
307     if( config_GetInt( p_this, "plugins-cache" ) )
308         p_this->p_libvlc->p_module_bank->b_cache = VLC_TRUE;
309
310     if( p_this->p_libvlc->p_module_bank->b_cache ||
311         p_this->p_libvlc->p_module_bank->b_cache_delete ) CacheLoad( p_this );
312
313     AllocateAllPlugins( p_this );
314 #endif
315 }
316
317 /*****************************************************************************
318  * module_Need: return the best module function, given a capability list.
319  *****************************************************************************
320  * This function returns the module that best fits the asked capabilities.
321  *****************************************************************************/
322 module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
323                           const char *psz_name, vlc_bool_t b_strict )
324 {
325     typedef struct module_list_t module_list_t;
326
327     struct module_list_t
328     {
329         module_t *p_module;
330         int i_score;
331         vlc_bool_t b_force;
332         module_list_t *p_next;
333     };
334
335     module_list_t *p_list, *p_first, *p_tmp;
336     vlc_list_t *p_all;
337
338     int i_which_module, i_index = 0;
339     vlc_bool_t b_intf = VLC_FALSE;
340
341     module_t *p_module;
342
343     int   i_shortcuts = 0;
344     char *psz_shortcuts = NULL, *psz_var = NULL;
345
346     msg_Dbg( p_this, "looking for %s module", psz_capability );
347
348     /* Deal with variables */
349     if( psz_name && psz_name[0] == '$' )
350     {
351         vlc_value_t val;
352         var_Create( p_this, psz_name + 1, VLC_VAR_MODULE | VLC_VAR_DOINHERIT );
353         var_Get( p_this, psz_name + 1, &val );
354         psz_var = val.psz_string;
355         psz_name = psz_var;
356     }
357
358     /* Count how many different shortcuts were asked for */
359     if( psz_name && *psz_name )
360     {
361         char *psz_parser, *psz_last_shortcut;
362
363         /* If the user wants none, give him none. */
364         if( !strcmp( psz_name, "none" ) )
365         {
366             if( psz_var ) free( psz_var );
367             return NULL;
368         }
369
370         i_shortcuts++;
371         psz_shortcuts = psz_last_shortcut = strdup( psz_name );
372
373         for( psz_parser = psz_shortcuts; *psz_parser; psz_parser++ )
374         {
375             if( *psz_parser == ',' )
376             {
377                  *psz_parser = '\0';
378                  i_shortcuts++;
379                  psz_last_shortcut = psz_parser + 1;
380             }
381         }
382
383         /* Check if the user wants to override the "strict" mode */
384         if( psz_last_shortcut )
385         {
386             if( !strcmp(psz_last_shortcut, "none") )
387             {
388                 b_strict = VLC_TRUE;
389                 i_shortcuts--;
390             }
391             else if( !strcmp(psz_last_shortcut, "any") )
392             {
393                 b_strict = VLC_FALSE;
394                 i_shortcuts--;
395             }
396         }
397     }
398
399     /* Sort the modules and test them */
400     p_all = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
401     p_list = malloc( p_all->i_count * sizeof( module_list_t ) );
402     p_first = NULL;
403
404     /* Parse the module list for capabilities and probe each of them */
405     for( i_which_module = 0; i_which_module < p_all->i_count; i_which_module++ )
406     {
407         int i_shortcut_bonus = 0;
408
409         p_module = (module_t *)p_all->p_values[i_which_module].p_object;
410
411         /* Test that this module can do what we need */
412         if( strcmp( p_module->psz_capability, psz_capability ) )
413         {
414             /* Don't recurse through the sub-modules because vlc_list_find()
415              * will list them anyway. */
416             continue;
417         }
418
419         /* Test if we have the required CPU */
420         if( (p_module->i_cpu & p_this->p_libvlc->i_cpu) != p_module->i_cpu )
421         {
422             continue;
423         }
424
425         /* If we required a shortcut, check this plugin provides it. */
426         if( i_shortcuts > 0 )
427         {
428             vlc_bool_t b_trash;
429             int i_dummy, i_short = i_shortcuts;
430             char *psz_name = psz_shortcuts;
431
432             /* Let's drop modules with a 0 score (unless they are
433              * explicitly requested) */
434             b_trash = !p_module->i_score;
435
436             while( i_short > 0 )
437             {
438                 for( i_dummy = 0; p_module->pp_shortcuts[i_dummy]; i_dummy++ )
439                 {
440                     if( !strcasecmp( psz_name,
441                                      p_module->pp_shortcuts[i_dummy] ) )
442                     {
443                         /* Found it */
444                         b_trash = VLC_FALSE;
445                         i_shortcut_bonus = i_short * 10000;
446                         break;
447                     }
448                 }
449
450                 if( i_shortcut_bonus )
451                 {
452                     /* We found it... remember ? */
453                     break;
454                 }
455
456                 /* Go to the next shortcut... This is so lame! */
457                 while( *psz_name )
458                 {
459                     psz_name++;
460                 }
461                 psz_name++;
462                 i_short--;
463             }
464
465             /* If we are in "strict" mode and we couldn't
466              * find the module in the list of provided shortcuts,
467              * then kick the bastard out of here!!! */
468             if( i_short == 0 && b_strict )
469             {
470                 b_trash = VLC_TRUE;
471             }
472
473             if( b_trash )
474             {
475                 continue;
476             }
477         }
478         /* If we didn't require a shortcut, trash zero-scored plugins */
479         else if( !p_module->i_score )
480         {
481             continue;
482         }
483
484         /* Special case: test if we requested a particular intf plugin */
485         if( !i_shortcuts && p_module->psz_program
486              && !strcmp( p_module->psz_program,
487                          p_this->p_vlc->psz_object_name ) )
488         {
489             if( !b_intf )
490             {
491                 /* Remove previous non-matching plugins */
492                 i_index = 0;
493                 b_intf = VLC_TRUE;
494             }
495         }
496         else if( b_intf )
497         {
498             /* This one doesn't match */
499             continue;
500         }
501
502         /* Store this new module */
503         p_list[ i_index ].p_module = p_module;
504         p_list[ i_index ].i_score = p_module->i_score + i_shortcut_bonus;
505         p_list[ i_index ].b_force = !!i_shortcut_bonus;
506
507         /* Add it to the modules-to-probe list */
508         if( i_index == 0 )
509         {
510             p_list[ 0 ].p_next = NULL;
511             p_first = p_list;
512         }
513         else
514         {
515             /* Ok, so at school you learned that quicksort is quick, and
516              * bubble sort sucks raw eggs. But that's when dealing with
517              * thousands of items. Here we have barely 50. */
518             module_list_t *p_newlist = p_first;
519
520             if( p_first->i_score < p_list[ i_index ].i_score )
521             {
522                 p_list[ i_index ].p_next = p_first;
523                 p_first = &p_list[ i_index ];
524             }
525             else
526             {
527                 while( p_newlist->p_next != NULL &&
528                     p_newlist->p_next->i_score >= p_list[ i_index ].i_score )
529                 {
530                     p_newlist = p_newlist->p_next;
531                 }
532
533                 p_list[ i_index ].p_next = p_newlist->p_next;
534                 p_newlist->p_next = &p_list[ i_index ];
535             }
536         }
537
538         i_index++;
539     }
540
541     msg_Dbg( p_this, "probing %i candidate%s",
542                      i_index, i_index == 1 ? "" : "s" );
543
544     /* Lock all candidate modules */
545     p_tmp = p_first;
546     while( p_tmp != NULL )
547     {
548         vlc_object_yield( p_tmp->p_module );
549         p_tmp = p_tmp->p_next;
550     }
551
552     /* We can release the list, interesting modules were yielded */
553     vlc_list_release( p_all );
554
555     /* Parse the linked list and use the first successful module */
556     p_tmp = p_first;
557     while( p_tmp != NULL )
558     {
559 #ifdef HAVE_DYNAMIC_PLUGINS
560         /* Make sure the module is loaded in mem */
561         module_t *p_module = p_tmp->p_module->b_submodule ?
562             (module_t *)p_tmp->p_module->p_parent : p_tmp->p_module;
563         if( !p_module->b_builtin && !p_module->b_loaded )
564         {
565             module_t *p_new_module =
566                 AllocatePlugin( p_this, p_module->psz_filename );
567             if( p_new_module )
568             {
569                 CacheMerge( p_this, p_module, p_new_module );
570                 vlc_object_attach( p_new_module, p_module );
571                 DeleteModule( p_new_module );
572             }
573         }
574 #endif
575
576         p_this->b_force = p_tmp->b_force;
577         if( p_tmp->p_module->pf_activate
578              && p_tmp->p_module->pf_activate( p_this ) == VLC_SUCCESS )
579         {
580             break;
581         }
582
583         vlc_object_release( p_tmp->p_module );
584         p_tmp = p_tmp->p_next;
585     }
586
587     /* Store the locked module value */
588     if( p_tmp != NULL )
589     {
590         p_module = p_tmp->p_module;
591         p_tmp = p_tmp->p_next;
592     }
593     else
594     {
595         p_module = NULL;
596     }
597
598     /* Unlock the remaining modules */
599     while( p_tmp != NULL )
600     {
601         vlc_object_release( p_tmp->p_module );
602         p_tmp = p_tmp->p_next;
603     }
604
605     free( p_list );
606     p_this->b_force = VLC_FALSE;
607
608     if( p_module != NULL )
609     {
610         msg_Dbg( p_module, "using %s module \"%s\"",
611                  psz_capability, p_module->psz_object_name );
612     }
613     else if( p_first == NULL )
614     {
615         msg_Err( p_this, "no %s module matched \"%s\"",
616                  psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
617     }
618     else if( psz_name != NULL && *psz_name )
619     {
620         msg_Warn( p_this, "no %s module matching \"%s\" could be loaded",
621                   psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
622     }
623
624     if( psz_shortcuts )
625     {
626         free( psz_shortcuts );
627     }
628
629     if( psz_var )
630     {
631         free( psz_var );
632     }
633
634     /* Don't forget that the module is still locked */
635     return p_module;
636 }
637
638 /*****************************************************************************
639  * module_Unneed: decrease the usage count of a module.
640  *****************************************************************************
641  * This function must be called by the thread that called module_Need, to
642  * decrease the reference count and allow for hiding of modules.
643  *****************************************************************************/
644 void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
645 {
646     /* Use the close method */
647     if( p_module->pf_deactivate )
648     {
649         p_module->pf_deactivate( p_this );
650     }
651
652     msg_Dbg( p_module, "unlocking module \"%s\"", p_module->psz_object_name );
653
654     vlc_object_release( p_module );
655
656     return;
657 }
658
659 /*****************************************************************************
660  * Following functions are local.
661  *****************************************************************************/
662
663 /*****************************************************************************
664  * AllocateAllPlugins: load all plugin modules we can find.
665  *****************************************************************************/
666 #ifdef HAVE_DYNAMIC_PLUGINS
667 static void AllocateAllPlugins( vlc_object_t *p_this )
668 {
669     /* Yes, there are two NULLs because we replace one with "plugin-path". */
670     char *          path[] = { "modules", PLUGIN_PATH, "plugins", NULL,
671                                NULL };
672
673     char **         ppsz_path = path;
674     char *          psz_fullpath;
675
676     /* If the user provided a plugin path, we add it to the list */
677     path[ sizeof(path)/sizeof(char*) - 2 ] =
678         config_GetPsz( p_this, "plugin-path" );
679
680     for( ; *ppsz_path != NULL ; ppsz_path++ )
681     {
682 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
683      || ( defined( WIN32 ) && !defined( UNDER_CE ) )
684
685         /* Handle relative as well as absolute paths */
686 #ifdef WIN32
687         if( !(*ppsz_path)[0] || (*ppsz_path)[1] != ':' )
688 #else
689         if( (*ppsz_path)[0] != '/' )
690 #endif
691         {
692             int i_dirlen = strlen( *ppsz_path );
693             i_dirlen += strlen( p_this->p_libvlc->psz_vlcpath ) + 2;
694
695             psz_fullpath = malloc( i_dirlen );
696             if( psz_fullpath == NULL )
697             {
698                 continue;
699             }
700 #ifdef WIN32
701             sprintf( psz_fullpath, "%s\\%s",
702                      p_this->p_libvlc->psz_vlcpath, *ppsz_path );
703 #else
704             sprintf( psz_fullpath, "%s/%s",
705                      p_this->p_libvlc->psz_vlcpath, *ppsz_path );
706 #endif
707         }
708         else
709 #endif
710         {
711             psz_fullpath = strdup( *ppsz_path );
712         }
713
714         msg_Dbg( p_this, "recursively browsing `%s'", psz_fullpath );
715
716         /* Don't go deeper than 5 subdirectories */
717         AllocatePluginDir( p_this, psz_fullpath, 5 );
718
719         free( psz_fullpath );
720     }
721
722     /* Free plugin-path */
723     if( path[ sizeof(path)/sizeof(char*) - 2 ] )
724         free( path[ sizeof(path)/sizeof(char*) - 2 ] );
725     path[ sizeof(path)/sizeof(char*) - 2 ] = NULL;
726 }
727
728 /*****************************************************************************
729  * AllocatePluginDir: recursively parse a directory to look for plugins
730  *****************************************************************************/
731 static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
732                                int i_maxdepth )
733 {
734 #if defined( UNDER_CE ) || defined( _MSC_VER )
735 #ifdef UNDER_CE
736     wchar_t psz_path[MAX_PATH + 256];
737     wchar_t psz_wdir[MAX_PATH];
738 #else
739     char psz_path[MAX_PATH + 256];
740 #endif
741     WIN32_FIND_DATA finddata;
742     HANDLE handle;
743     unsigned int rc;
744 #else
745     int    i_dirlen;
746     DIR *  dir;
747     struct dirent * file;
748 #endif
749     char * psz_file;
750
751     if( p_this->p_vlc->b_die || i_maxdepth < 0 )
752     {
753         return;
754     }
755
756 #if defined( UNDER_CE ) || defined( _MSC_VER )
757     MultiByteToWideChar( CP_ACP, 0, psz_dir, -1, psz_wdir, MAX_PATH );
758
759     rc = GetFileAttributes( psz_wdir );
760     if( !(rc & FILE_ATTRIBUTE_DIRECTORY) )
761     {
762         /* Not a directory */
763         return;
764     }
765
766     /* Parse all files in the directory */
767 #ifdef UNDER_CE
768     swprintf( psz_path, L"%s\\*.*", psz_dir );
769 #else
770     sprintf( psz_path, "%s\\*.*", psz_dir );
771 #endif
772     handle = FindFirstFile( psz_path, &finddata );
773     if( handle == INVALID_HANDLE_VALUE )
774     {
775         /* Empty directory */
776         return;
777     }
778
779     /* Parse the directory and try to load all files it contains. */
780     do
781     {
782 #ifdef UNDER_CE
783         unsigned int i_len = wcslen( finddata.cFileName );
784         swprintf( psz_path, L"%s\\%s", psz_dir, finddata.cFileName );
785 #else
786         unsigned int i_len = strlen( finddata.cFileName );
787         /* Skip ".", ".." and anything starting with "." */
788         if( !*finddata.cFileName || *finddata.cFileName == '.' )
789         {
790             if( !FindNextFile( handle, &finddata ) ) break;
791             continue;
792         }
793         sprintf( psz_path, "%s\\%s", psz_dir, finddata.cFileName );
794 #endif
795
796         if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY )
797         {
798             AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 );
799         }
800         else if( i_len > strlen( LIBEXT )
801 #ifdef UNDER_CE
802                 )
803 #else
804                   /* We only load files ending with LIBEXT */
805                   && !strncasecmp( psz_path + strlen( psz_path)
806                                    - strlen( LIBEXT ),
807                                    LIBEXT, strlen( LIBEXT ) ) )
808 #endif
809         {
810 #ifdef UNDER_CE
811             char psz_filename[MAX_PATH];
812             WideCharToMultiByte( CP_ACP, WC_DEFAULTCHAR, psz_path, -1,
813                                  psz_filename, MAX_PATH, NULL, NULL );
814             psz_file = psz_filename;
815 #else
816             psz_file = psz_path;
817 #endif
818
819             AllocatePluginFile( p_this, psz_file, 0, 0 );
820         }
821     }
822     while( !p_this->p_vlc->b_die && FindNextFile( handle, &finddata ) );
823
824     /* Close the directory */
825     FindClose( handle );
826
827 #else
828     dir = opendir( psz_dir );
829     if( !dir )
830     {
831         return;
832     }
833
834     i_dirlen = strlen( psz_dir );
835
836     /* Parse the directory and try to load all files it contains. */
837     while( !p_this->p_vlc->b_die && (file = readdir( dir )) )
838     {
839         struct stat statbuf;
840         unsigned int i_len;
841         int i_stat;
842
843         /* Skip ".", ".." and anything starting with "." */
844         if( !*file->d_name || *file->d_name == '.' )
845         {
846             continue;
847         }
848
849         i_len = strlen( file->d_name );
850         psz_file = malloc( i_dirlen + 1 + i_len + 1 );
851 #ifdef WIN32
852         sprintf( psz_file, "%s\\%s", psz_dir, file->d_name );
853 #else
854         sprintf( psz_file, "%s/%s", psz_dir, file->d_name );
855 #endif
856
857         i_stat = stat( psz_file, &statbuf );
858         if( !i_stat && statbuf.st_mode & S_IFDIR )
859         {
860             AllocatePluginDir( p_this, psz_file, i_maxdepth - 1 );
861         }
862         else if( i_len > strlen( LIBEXT )
863                   /* We only load files ending with LIBEXT */
864                   && !strncasecmp( file->d_name + i_len - strlen( LIBEXT ),
865                                    LIBEXT, strlen( LIBEXT ) ) )
866         {
867             int64_t i_time = 0, i_size = 0;
868
869             if( !i_stat )
870             {
871                 i_time = statbuf.st_mtime;
872                 i_size = statbuf.st_size;
873             }
874
875             AllocatePluginFile( p_this, psz_file, i_time, i_size );
876         }
877
878         free( psz_file );
879     }
880
881     /* Close the directory */
882     closedir( dir );
883
884 #endif
885 }
886
887 /*****************************************************************************
888  * AllocatePluginFile: load a module into memory and initialize it.
889  *****************************************************************************
890  * This function loads a dynamically loadable module and allocates a structure
891  * for its information data. The module can then be handled by module_Need
892  * and module_Unneed. It can be removed by DeleteModule.
893  *****************************************************************************/
894 static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
895                                int64_t i_file_time, int64_t i_file_size )
896 {
897     module_t * p_module;
898     module_cache_t *p_cache_entry = NULL;
899
900     /*
901      * Check our plugins cache first then load plugin if needed
902      */
903     p_cache_entry =
904         CacheFind( p_this, psz_file, i_file_time, i_file_size );
905
906     if( !p_cache_entry )
907     {
908         p_module = AllocatePlugin( p_this, psz_file );
909     }
910     else
911     {
912         /* If junk dll, don't try to load it */
913         if( p_cache_entry->b_junk )
914         {
915             p_module = NULL;
916         }
917         else
918         {
919             module_config_t *p_item;
920
921             p_module = p_cache_entry->p_module;
922             p_module->b_loaded = VLC_FALSE;
923
924             /* For now we force loading if the module's config contains
925              * callbacks or actions.
926              * Could be optimized by adding an API call.*/
927             for( p_item = p_module->p_config;
928                  p_item->i_type != CONFIG_HINT_END; p_item++ )
929             {
930                 if( p_item->pf_callback || p_item->i_action )
931                     p_module = AllocatePlugin( p_this, psz_file );
932             }
933         }
934     }
935
936     if( p_module )
937     {
938         /* Everything worked fine !
939          * The module is ready to be added to the list. */
940         p_module->b_builtin = VLC_FALSE;
941
942         /* msg_Dbg( p_this, "plugin \"%s\", %s",
943                     p_module->psz_object_name, p_module->psz_longname ); */
944
945         vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
946     }
947
948     if( !p_this->p_libvlc->p_module_bank->b_cache ) return 0;
949
950     /* Add entry to cache */
951 #define p_bank p_this->p_libvlc->p_module_bank
952     p_bank->pp_cache =
953         realloc( p_bank->pp_cache, (p_bank->i_cache + 1) * sizeof(void *) );
954     p_bank->pp_cache[p_bank->i_cache] = malloc( sizeof(module_cache_t) );
955     p_bank->pp_cache[p_bank->i_cache]->psz_file = strdup( psz_file );
956     p_bank->pp_cache[p_bank->i_cache]->i_time = i_file_time;
957     p_bank->pp_cache[p_bank->i_cache]->i_size = i_file_size;
958     p_bank->pp_cache[p_bank->i_cache]->b_junk = p_module ? 0 : 1;
959     p_bank->pp_cache[p_bank->i_cache]->p_module = p_module;
960     p_bank->i_cache++;
961
962     return p_module ? 0 : -1;
963 }
964
965 /*****************************************************************************
966  * AllocatePlugin: load a module into memory and initialize it.
967  *****************************************************************************
968  * This function loads a dynamically loadable module and allocates a structure
969  * for its information data. The module can then be handled by module_Need
970  * and module_Unneed. It can be removed by DeleteModule.
971  *****************************************************************************/
972 static module_t * AllocatePlugin( vlc_object_t * p_this, char * psz_file )
973 {
974     module_t * p_module;
975     module_handle_t handle;
976
977     if( LoadModule( p_this, psz_file, &handle ) ) return NULL;
978
979     /* Now that we have successfully loaded the module, we can
980      * allocate a structure for it */
981     p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
982     if( p_module == NULL )
983     {
984         msg_Err( p_this, "out of memory" );
985         CloseModule( handle );
986         return NULL;
987     }
988
989     /* We need to fill these since they may be needed by CallEntry() */
990     p_module->psz_filename = psz_file;
991     p_module->handle = handle;
992     p_module->p_symbols = &p_this->p_libvlc->p_module_bank->symbols;
993     p_module->b_loaded = VLC_TRUE;
994
995     /* Initialize the module: fill p_module, default config */
996     if( CallEntry( p_module ) != 0 )
997     {
998         /* We couldn't call module_init() */
999         vlc_object_destroy( p_module );
1000         CloseModule( handle );
1001         return NULL;
1002     }
1003
1004     DupModule( p_module );
1005     p_module->psz_filename = strdup( p_module->psz_filename );
1006     p_module->psz_longname = strdup( p_module->psz_longname );
1007
1008     /* Everything worked fine ! The module is ready to be added to the list. */
1009     p_module->b_builtin = VLC_FALSE;
1010
1011     return p_module;
1012 }
1013
1014 /*****************************************************************************
1015  * DupModule: make a plugin module standalone.
1016  *****************************************************************************
1017  * This function duplicates all strings in the module, so that the dynamic
1018  * object can be unloaded. It acts recursively on submodules.
1019  *****************************************************************************/
1020 static void DupModule( module_t *p_module )
1021 {
1022     char **pp_shortcut;
1023     int i_submodule;
1024
1025     for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
1026     {
1027         *pp_shortcut = strdup( *pp_shortcut );
1028     }
1029
1030     /* We strdup() these entries so that they are still valid when the
1031      * module is unloaded. */
1032     p_module->psz_object_name = strdup( p_module->psz_object_name );
1033     p_module->psz_capability = strdup( p_module->psz_capability );
1034
1035     if( p_module->psz_program != NULL )
1036     {
1037         p_module->psz_program = strdup( p_module->psz_program );
1038     }
1039
1040     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
1041     {
1042         DupModule( (module_t*)p_module->pp_children[ i_submodule ] );
1043     }
1044 }
1045
1046 /*****************************************************************************
1047  * UndupModule: free a duplicated module.
1048  *****************************************************************************
1049  * This function frees the allocations done in DupModule().
1050  *****************************************************************************/
1051 static void UndupModule( module_t *p_module )
1052 {
1053     char **pp_shortcut;
1054     int i_submodule;
1055
1056     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
1057     {
1058         UndupModule( (module_t*)p_module->pp_children[ i_submodule ] );
1059     }
1060
1061     for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
1062     {
1063         free( *pp_shortcut );
1064     }
1065
1066     free( p_module->psz_object_name );
1067     free( p_module->psz_capability );
1068
1069     if( p_module->psz_program != NULL )
1070     {
1071         free( p_module->psz_program );
1072     }
1073 }
1074
1075 #endif /* HAVE_DYNAMIC_PLUGINS */
1076
1077 /*****************************************************************************
1078  * AllocateBuiltinModule: initialize a builtin module.
1079  *****************************************************************************
1080  * This function registers a builtin module and allocates a structure
1081  * for its information data. The module can then be handled by module_Need
1082  * and module_Unneed. It can be removed by DeleteModule.
1083  *****************************************************************************/
1084 static int AllocateBuiltinModule( vlc_object_t * p_this,
1085                                   int ( *pf_entry ) ( module_t * ) )
1086 {
1087     module_t * p_module;
1088
1089     /* Now that we have successfully loaded the module, we can
1090      * allocate a structure for it */
1091     p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
1092     if( p_module == NULL )
1093     {
1094         msg_Err( p_this, "out of memory" );
1095         return -1;
1096     }
1097
1098     /* Initialize the module : fill p_module->psz_object_name, etc. */
1099     if( pf_entry( p_module ) != 0 )
1100     {
1101         /* With a well-written module we shouldn't have to print an
1102          * additional error message here, but just make sure. */
1103         msg_Err( p_this, "failed calling entry point in builtin module" );
1104         vlc_object_destroy( p_module );
1105         return -1;
1106     }
1107
1108     /* Everything worked fine ! The module is ready to be added to the list. */
1109     p_module->b_builtin = VLC_TRUE;
1110
1111     /* msg_Dbg( p_this, "builtin \"%s\", %s",
1112                 p_module->psz_object_name, p_module->psz_longname ); */
1113
1114     vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
1115
1116     return 0;
1117 }
1118
1119 /*****************************************************************************
1120  * DeleteModule: delete a module and its structure.
1121  *****************************************************************************
1122  * This function can only be called if the module isn't being used.
1123  *****************************************************************************/
1124 static int DeleteModule( module_t * p_module )
1125 {
1126     vlc_object_detach( p_module );
1127
1128     /* We free the structures that we strdup()ed in Allocate*Module(). */
1129 #ifdef HAVE_DYNAMIC_PLUGINS
1130     if( !p_module->b_builtin )
1131     {
1132         if( p_module->b_loaded && p_module->b_unloadable )
1133         {
1134             CloseModule( p_module->handle );
1135         }
1136         UndupModule( p_module );
1137         free( p_module->psz_filename );
1138         free( p_module->psz_longname );
1139     }
1140 #endif
1141
1142     /* Free and detach the object's children */
1143     while( p_module->i_children )
1144     {
1145         vlc_object_t *p_this = p_module->pp_children[0];
1146         vlc_object_detach( p_this );
1147         vlc_object_destroy( p_this );
1148     }
1149
1150     config_Free( p_module );
1151     vlc_object_destroy( p_module );
1152
1153     return 0;
1154 }
1155
1156 #ifdef HAVE_DYNAMIC_PLUGINS
1157 /*****************************************************************************
1158  * CallEntry: call an entry point.
1159  *****************************************************************************
1160  * This function calls a symbol given its name and a module structure. The
1161  * symbol MUST refer to a function returning int and taking a module_t* as
1162  * an argument.
1163  *****************************************************************************/
1164 static int CallEntry( module_t * p_module )
1165 {
1166     static char *psz_name = "vlc_entry" MODULE_SUFFIX;
1167     int (* pf_symbol) ( module_t * p_module );
1168
1169     /* Try to resolve the symbol */
1170     pf_symbol = (int (*)(module_t *)) GetSymbol( p_module->handle, psz_name );
1171
1172     if( pf_symbol == NULL )
1173     {
1174 #if defined(HAVE_DL_DYLD) || defined(HAVE_DL_BEOS)
1175         msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s'",
1176                             psz_name, p_module->psz_filename );
1177 #elif defined(HAVE_DL_WINDOWS)
1178         char *psz_error = GetWindowsError();
1179         msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",
1180                             psz_name, p_module->psz_filename, psz_error );
1181         free( psz_error );
1182 #elif defined(HAVE_DL_DLOPEN)
1183         msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",
1184                             psz_name, p_module->psz_filename, dlerror() );
1185 #elif defined(HAVE_DL_SHL_LOAD)
1186         msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",
1187                             psz_name, p_module->psz_filename, strerror(errno) );
1188 #else
1189 #   error "Something is wrong in modules.c"
1190 #endif
1191         return -1;
1192     }
1193
1194     /* We can now try to call the symbol */
1195     if( pf_symbol( p_module ) != 0 )
1196     {
1197         /* With a well-written module we shouldn't have to print an
1198          * additional error message here, but just make sure. */
1199         msg_Err( p_module, "failed calling symbol \"%s\" in file `%s'",
1200                            psz_name, p_module->psz_filename );
1201         return -1;
1202     }
1203
1204     /* Everything worked fine, we can return */
1205     return 0;
1206 }
1207
1208 /*****************************************************************************
1209  * LoadModule: loads a dynamic library
1210  *****************************************************************************
1211  * This function loads a dynamically linked library using a system dependant
1212  * method. Will return 0 on success as well as the module handle.
1213  *****************************************************************************/
1214 static int LoadModule( vlc_object_t *p_this, char *psz_file,
1215                        module_handle_t *p_handle )
1216 {
1217     module_handle_t handle;
1218
1219 #if defined(HAVE_DL_DYLD)
1220     NSObjectFileImage image;
1221     NSObjectFileImageReturnCode ret;
1222
1223     ret = NSCreateObjectFileImageFromFile( psz_file, &image );
1224
1225     if( ret != NSObjectFileImageSuccess )
1226     {
1227         msg_Warn( p_this, "cannot create image from `%s'", psz_file );
1228         return -1;
1229     }
1230
1231     /* Open the dynamic module */
1232     handle = NSLinkModule( image, psz_file,
1233                            NSLINKMODULE_OPTION_RETURN_ON_ERROR );
1234
1235     if( !handle )
1236     {
1237         NSLinkEditErrors errors;
1238         const char *psz_file, *psz_err;
1239         int i_errnum;
1240         NSLinkEditError( &errors, &i_errnum, &psz_file, &psz_err );
1241         msg_Warn( p_this, "cannot link module `%s' (%s)", psz_file, psz_err );
1242         NSDestroyObjectFileImage( image );
1243         return -1;
1244     }
1245
1246     /* Destroy our image, we won't need it */
1247     NSDestroyObjectFileImage( image );
1248
1249 #elif defined(HAVE_DL_BEOS)
1250     handle = load_add_on( psz_file );
1251     if( handle < 0 )
1252     {
1253         msg_Warn( p_this, "cannot load module `%s'", psz_file );
1254         return -1;
1255     }
1256
1257 #elif defined(HAVE_DL_WINDOWS)
1258     handle = LoadLibrary( psz_file );
1259     if( handle == NULL )
1260     {
1261         char *psz_err = GetWindowsError();
1262         msg_Warn( p_this, "cannot load module `%s' (%s)", psz_file, psz_err );
1263         free( psz_err );
1264     }
1265
1266 #elif defined(HAVE_DL_DLOPEN) && defined(RTLD_NOW)
1267     /* static is OK, we are called atomically */
1268     static vlc_bool_t b_kde = VLC_FALSE;
1269
1270 #   if defined(SYS_LINUX)
1271     /* XXX HACK #1 - we should NOT open modules with RTLD_GLOBAL, or we
1272      * are going to get namespace collisions when two modules have common
1273      * public symbols, but ALSA is being a pest here. */
1274     if( strstr( psz_file, "alsa_plugin" ) )
1275     {
1276         handle = dlopen( psz_file, RTLD_NOW | RTLD_GLOBAL );
1277         if( handle == NULL )
1278         {
1279             msg_Warn( p_this, "cannot load module `%s' (%s)",
1280                               psz_file, dlerror() );
1281             return -1;
1282         }
1283     }
1284 #   endif
1285     /* XXX HACK #2 - the ugly KDE workaround. It seems that libkdewhatever
1286      * causes dlopen() to segfault if libstdc++ is not loaded in the caller,
1287      * so we just load libstdc++. Bwahahaha! ph34r! -- Sam. */
1288     /* Update: FYI, this is Debian bug #180505, and seems to be fixed. */
1289     if( !b_kde && !strstr( psz_file, "kde" ) )
1290     {
1291         dlopen( "libstdc++.so.6", RTLD_NOW )
1292          || dlopen( "libstdc++.so.5", RTLD_NOW )
1293          || dlopen( "libstdc++.so.4", RTLD_NOW )
1294          || dlopen( "libstdc++.so.3", RTLD_NOW );
1295         b_kde = VLC_TRUE;
1296     }
1297
1298     handle = dlopen( psz_file, RTLD_NOW );
1299     if( handle == NULL )
1300     {
1301         msg_Warn( p_this, "cannot load module `%s' (%s)",
1302                           psz_file, dlerror() );
1303         return -1;
1304     }
1305
1306 #elif defined(HAVE_DL_DLOPEN)
1307 #   if defined(DL_LAZY)
1308     handle = dlopen( psz_file, DL_LAZY );
1309 #   else
1310     handle = dlopen( psz_file, 0 );
1311 #   endif
1312     if( handle == NULL )
1313     {
1314         msg_Warn( p_this, "cannot load module `%s' (%s)",
1315                           psz_file, dlerror() );
1316         return -1;
1317     }
1318
1319 #elif defined(HAVE_DL_SHL_LOAD)
1320     handle = shl_load( psz_file, BIND_IMMEDIATE | BIND_NONFATAL, NULL );
1321     if( handle == NULL )
1322     {
1323         msg_Warn( p_this, "cannot load module `%s' (%s)",
1324                           psz_file, strerror(errno) );
1325         return -1;
1326     }
1327
1328 #else
1329 #   error "Something is wrong in modules.c"
1330
1331 #endif
1332
1333     *p_handle = handle;
1334     return 0;
1335 }
1336
1337 /*****************************************************************************
1338  * CloseModule: unload a dynamic library
1339  *****************************************************************************
1340  * This function unloads a previously opened dynamically linked library
1341  * using a system dependant method. No return value is taken in consideration,
1342  * since some libraries sometimes refuse to close properly.
1343  *****************************************************************************/
1344 static void CloseModule( module_handle_t handle )
1345 {
1346 #if defined(HAVE_DL_DYLD)
1347     NSUnLinkModule( handle, FALSE );
1348
1349 #elif defined(HAVE_DL_BEOS)
1350     unload_add_on( handle );
1351
1352 #elif defined(HAVE_DL_WINDOWS)
1353     FreeLibrary( handle );
1354
1355 #elif defined(HAVE_DL_DLOPEN)
1356     dlclose( handle );
1357
1358 #elif defined(HAVE_DL_SHL_LOAD)
1359     shl_unload( handle );
1360
1361 #endif
1362     return;
1363 }
1364
1365 /*****************************************************************************
1366  * GetSymbol: get a symbol from a dynamic library
1367  *****************************************************************************
1368  * This function queries a loaded library for a symbol specified in a
1369  * string, and returns a pointer to it. We don't check for dlerror() or
1370  * similar functions, since we want a non-NULL symbol anyway.
1371  *****************************************************************************/
1372 static void * _module_getsymbol( module_handle_t, const char * );
1373
1374 static void * GetSymbol( module_handle_t handle, const char * psz_function )
1375 {
1376     void * p_symbol = _module_getsymbol( handle, psz_function );
1377
1378     /* MacOS X dl library expects symbols to begin with "_". So do
1379      * some other operating systems. That's really lame, but hey, what
1380      * can we do ? */
1381     if( p_symbol == NULL )
1382     {
1383         char *psz_call = malloc( strlen( psz_function ) + 2 );
1384
1385         strcpy( psz_call + 1, psz_function );
1386         psz_call[ 0 ] = '_';
1387         p_symbol = _module_getsymbol( handle, psz_call );
1388         free( psz_call );
1389     }
1390
1391     return p_symbol;
1392 }
1393
1394 static void * _module_getsymbol( module_handle_t handle,
1395                                  const char * psz_function )
1396 {
1397 #if defined(HAVE_DL_DYLD)
1398     NSSymbol sym = NSLookupSymbolInModule( handle, psz_function );
1399     return NSAddressOfSymbol( sym );
1400
1401 #elif defined(HAVE_DL_BEOS)
1402     void * p_symbol;
1403     if( B_OK == get_image_symbol( handle, psz_function,
1404                                   B_SYMBOL_TYPE_TEXT, &p_symbol ) )
1405     {
1406         return p_symbol;
1407     }
1408     else
1409     {
1410         return NULL;
1411     }
1412
1413 #elif defined(HAVE_DL_WINDOWS) && defined(UNDER_CE)
1414     wchar_t psz_real[256];
1415     MultiByteToWideChar( CP_ACP, 0, psz_function, -1, psz_real, 256 );
1416
1417     return (void *)GetProcAddress( handle, psz_real );
1418
1419 #elif defined(HAVE_DL_WINDOWS) && defined(WIN32)
1420     return (void *)GetProcAddress( handle, (char *)psz_function );
1421
1422 #elif defined(HAVE_DL_DLOPEN)
1423     return dlsym( handle, psz_function );
1424
1425 #elif defined(HAVE_DL_SHL_LOAD)
1426     void *p_sym;
1427     shl_findsym( &handle, psz_function, TYPE_UNDEFINED, &p_sym );
1428     return p_sym;
1429
1430 #endif
1431 }
1432
1433 #if defined(HAVE_DL_WINDOWS)
1434 static char * GetWindowsError( void )
1435 {
1436 #if defined(UNDER_CE)
1437     wchar_t psz_tmp[256];
1438     char * psz_buffer = malloc( 256 );
1439 #else
1440     char * psz_tmp = malloc( 256 );
1441 #endif
1442     int i = 0, i_error = GetLastError();
1443
1444     FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1445                    NULL, i_error, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
1446                    (LPTSTR) psz_tmp, 256, NULL );
1447
1448     /* Go to the end of the string */
1449 #if defined(UNDER_CE)
1450     while( psz_tmp[i] && psz_tmp[i] != L'\r' && psz_tmp[i] != L'\n' )
1451 #else
1452     while( psz_tmp[i] && psz_tmp[i] != '\r' && psz_tmp[i] != '\n' )
1453 #endif
1454     {
1455         i++;
1456     }
1457
1458     if( psz_tmp[i] )
1459     {
1460 #if defined(UNDER_CE)
1461         swprintf( psz_tmp + i, L" (error %i)", i_error );
1462         psz_tmp[ 255 ] = L'\0';
1463 #else
1464         snprintf( psz_tmp + i, 256 - i, " (error %i)", i_error );
1465         psz_tmp[ 255 ] = '\0';
1466 #endif
1467     }
1468
1469 #if defined(UNDER_CE)
1470     WideCharToMultiByte( CP_ACP, WC_DEFAULTCHAR, psz_tmp, -1,
1471                          psz_buffer, 256, NULL, NULL );
1472     return psz_buffer;
1473 #else
1474     return psz_tmp;
1475 #endif
1476 }
1477 #endif /* HAVE_DL_WINDOWS */
1478
1479 /*****************************************************************************
1480  * LoadPluginsCache: loads the plugins cache file
1481  *****************************************************************************
1482  * This function will load the plugin cache if present and valid. This cache
1483  * will in turn be queried by AllocateAllPlugins() to see if it needs to
1484  * actually load the dynamically loadable module.
1485  * This allows us to only fully load plugins when they are actually used.
1486  *****************************************************************************/
1487 static void CacheLoad( vlc_object_t *p_this )
1488 {
1489     char *psz_filename, *psz_homedir;
1490     FILE *file;
1491     int i, j, i_size, i_read;
1492     char p_cachestring[sizeof(PLUGINSCACHE_FILE COPYRIGHT_MESSAGE)];
1493     int i_cache;
1494     module_cache_t **pp_cache = 0;
1495     int32_t i_file_size;
1496
1497     psz_homedir = p_this->p_vlc->psz_homedir;
1498     if( !psz_homedir )
1499     {
1500         msg_Err( p_this, "psz_homedir is null" );
1501         return;
1502     }
1503     psz_filename =
1504         (char *)malloc( sizeof("/" CONFIG_DIR "/" PLUGINSCACHE_FILE) +
1505                         strlen(psz_homedir) );
1506
1507     if( psz_filename )
1508         sprintf( psz_filename, "%s/" CONFIG_DIR "/" PLUGINSCACHE_FILE,
1509                  psz_homedir );
1510
1511     if( !psz_filename )
1512     {
1513         msg_Err( p_this, "out of memory" );
1514         return;
1515     }
1516
1517     if( p_this->p_libvlc->p_module_bank->b_cache_delete )
1518     {
1519         msg_Dbg( p_this, "removing plugins cache file %s", psz_filename );
1520         unlink( psz_filename );
1521         return;
1522     }
1523
1524     msg_Dbg( p_this, "loading plugins cache file %s", psz_filename );
1525
1526     file = fopen( psz_filename, "r" );
1527     if( !file )
1528     {
1529         msg_Warn( p_this, "could not open plugins cache file %s for reading",
1530                   psz_filename );
1531         free( psz_filename );
1532         return;
1533     }
1534     free( psz_filename );
1535
1536     /* Check the file size */
1537     i_read = fread( &i_file_size, sizeof(char), sizeof(i_file_size), file );
1538     if( i_read != sizeof(i_file_size) )
1539     {
1540         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
1541                   "(too short)" );
1542         fclose( file );
1543         return;
1544     }
1545
1546     fseek( file, 0, SEEK_END );
1547     if( ftell( file ) != i_file_size )
1548     {
1549         msg_Warn( p_this, "This doesn't look like a valid plugins cache "
1550                   "(corrupted size)" );
1551         fclose( file );
1552         return;
1553     }
1554     fseek( file, sizeof(i_file_size), SEEK_SET );
1555
1556     /* Check the file is a plugins cache */
1557     i_size = sizeof(PLUGINSCACHE_FILE COPYRIGHT_MESSAGE) - 1;
1558     i_read = fread( p_cachestring, sizeof(char), i_size, file );
1559     if( i_read != i_size ||
1560         memcmp( p_cachestring, PLUGINSCACHE_FILE COPYRIGHT_MESSAGE, i_size ) )
1561     {
1562         msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
1563         fclose( file );
1564         return;
1565     }
1566
1567     p_this->p_libvlc->p_module_bank->i_loaded_cache = 0;
1568     fread( &i_cache, sizeof(char), sizeof(i_cache), file );
1569     pp_cache = p_this->p_libvlc->p_module_bank->pp_loaded_cache =
1570         malloc( i_cache * sizeof(void *) );
1571
1572 #define LOAD_IMMEDIATE(a) \
1573     if( fread( &a, sizeof(char), sizeof(a), file ) != sizeof(a) ) goto error
1574 #define LOAD_STRING(a) \
1575     { if( fread( &i_size, sizeof(char), sizeof(i_size), file ) \
1576           != sizeof(i_size) ) goto error; \
1577       if( i_size ) { \
1578           a = malloc( i_size ); \
1579           if( fread( a, sizeof(char), i_size, file ) != (size_t)i_size ) \
1580               goto error; \
1581       } else a = 0; \
1582     } while(0)
1583
1584
1585     for( i = 0; i < i_cache; i++ )
1586     {
1587         int16_t i_size;
1588         int i_submodules;
1589
1590         pp_cache[i] = malloc( sizeof(module_cache_t) );
1591         p_this->p_libvlc->p_module_bank->i_loaded_cache++;
1592
1593         /* Save common info */
1594         LOAD_STRING( pp_cache[i]->psz_file );
1595         LOAD_IMMEDIATE( pp_cache[i]->i_time );
1596         LOAD_IMMEDIATE( pp_cache[i]->i_size );
1597         LOAD_IMMEDIATE( pp_cache[i]->b_junk );
1598
1599         if( pp_cache[i]->b_junk ) continue;
1600
1601         pp_cache[i]->p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
1602
1603         /* Save additional infos */
1604         LOAD_STRING( pp_cache[i]->p_module->psz_object_name );
1605         LOAD_STRING( pp_cache[i]->p_module->psz_shortname );
1606         LOAD_STRING( pp_cache[i]->p_module->psz_longname );
1607         LOAD_STRING( pp_cache[i]->p_module->psz_program );
1608         for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
1609         {
1610             LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
1611         }
1612         LOAD_STRING( pp_cache[i]->p_module->psz_capability );
1613         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_score );
1614         LOAD_IMMEDIATE( pp_cache[i]->p_module->i_cpu );
1615         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
1616         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_reentrant );
1617         LOAD_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
1618
1619         /* Config stuff */
1620         if( CacheLoadConfig( pp_cache[i]->p_module, file ) != VLC_SUCCESS )
1621             goto error;
1622
1623         LOAD_STRING( pp_cache[i]->p_module->psz_filename );
1624
1625         LOAD_IMMEDIATE( i_submodules );
1626
1627         while( i_submodules-- )
1628         {
1629             module_t *p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE);
1630             vlc_object_attach( p_module, pp_cache[i]->p_module );
1631             p_module->b_submodule = VLC_TRUE; 
1632
1633             LOAD_STRING( p_module->psz_object_name );
1634             LOAD_STRING( p_module->psz_shortname );
1635             LOAD_STRING( p_module->psz_longname );
1636             LOAD_STRING( p_module->psz_program );
1637             for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
1638             {
1639                 LOAD_STRING( p_module->pp_shortcuts[j] ); // FIX
1640             }
1641             LOAD_STRING( p_module->psz_capability );
1642             LOAD_IMMEDIATE( p_module->i_score );
1643             LOAD_IMMEDIATE( p_module->i_cpu );
1644             LOAD_IMMEDIATE( p_module->b_unloadable );
1645             LOAD_IMMEDIATE( p_module->b_reentrant );
1646         }
1647     }
1648
1649     fclose( file );
1650     return;
1651
1652  error:
1653
1654     msg_Warn( p_this, "plugins cache not loaded (corrupted)" );
1655
1656     /* TODO: cleanup */
1657     p_this->p_libvlc->p_module_bank->i_loaded_cache = 0;
1658
1659     fclose( file );
1660     return;
1661 }
1662
1663 int CacheLoadConfig( module_t *p_module, FILE *file )
1664 {
1665     int i, j, i_lines;
1666     int16_t i_size;
1667
1668     /* Calculate the structure length */
1669     LOAD_IMMEDIATE( p_module->i_config_items );
1670     LOAD_IMMEDIATE( p_module->i_bool_items );
1671
1672     LOAD_IMMEDIATE( i_lines );
1673
1674     /* Allocate memory */
1675     p_module->p_config =
1676         (module_config_t *)malloc( sizeof(module_config_t) * (i_lines + 1));
1677     if( p_module->p_config == NULL )
1678     {
1679         msg_Err( p_module, "config error: can't duplicate p_config" );
1680         return VLC_ENOMEM;
1681     }
1682
1683     /* Do the duplication job */
1684     for( i = 0; i < i_lines ; i++ )
1685     {
1686         LOAD_IMMEDIATE( p_module->p_config[i] );
1687
1688         LOAD_STRING( p_module->p_config[i].psz_type );
1689         LOAD_STRING( p_module->p_config[i].psz_name );
1690         LOAD_STRING( p_module->p_config[i].psz_text );
1691         LOAD_STRING( p_module->p_config[i].psz_longtext );
1692         LOAD_STRING( p_module->p_config[i].psz_value_orig );
1693
1694         p_module->p_config[i].psz_value =
1695             p_module->p_config[i].psz_value_orig ?
1696                 strdup( p_module->p_config[i].psz_value_orig ) : 0;
1697         p_module->p_config[i].i_value = p_module->p_config[i].i_value_orig;
1698         p_module->p_config[i].f_value = p_module->p_config[i].f_value_orig;
1699
1700         p_module->p_config[i].p_lock = &p_module->object_lock;
1701
1702         if( p_module->p_config[i].i_list )
1703         {
1704             if( p_module->p_config[i].ppsz_list )
1705             {
1706                 p_module->p_config[i].ppsz_list =
1707                     malloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
1708                 if( p_module->p_config[i].ppsz_list )
1709                 {
1710                     for( j = 0; j < p_module->p_config[i].i_list; j++ )
1711                         LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
1712                     p_module->p_config[i].ppsz_list[j] = NULL;
1713                 }
1714             }
1715             if( p_module->p_config[i].ppsz_list_text )
1716             {
1717                 p_module->p_config[i].ppsz_list_text =
1718                     malloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
1719                 if( p_module->p_config[i].ppsz_list_text )
1720                 {
1721                   for( j = 0; j < p_module->p_config[i].i_list; j++ )
1722                       LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
1723                   p_module->p_config[i].ppsz_list_text[j] = NULL;
1724                 }
1725             }
1726             if( p_module->p_config[i].pi_list )
1727             {
1728                 p_module->p_config[i].pi_list =
1729                     malloc( (p_module->p_config[i].i_list + 1) * sizeof(int) );
1730                 if( p_module->p_config[i].pi_list )
1731                 {
1732                     for( j = 0; j < p_module->p_config[i].i_list; j++ )
1733                         LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
1734                 }
1735             }
1736         }
1737
1738         if( p_module->p_config[i].i_action )
1739         {
1740             p_module->p_config[i].ppf_action =
1741                 malloc( p_module->p_config[i].i_action * sizeof(void *) );
1742             p_module->p_config[i].ppsz_action_text =
1743                 malloc( p_module->p_config[i].i_action * sizeof(char *) );
1744
1745             for( j = 0; j < p_module->p_config[i].i_action; j++ )
1746             {
1747                 p_module->p_config[i].ppf_action[j] = 0;
1748                 LOAD_STRING( p_module->p_config[i].ppsz_action_text[j] );
1749             }
1750         }
1751
1752         LOAD_IMMEDIATE( p_module->p_config[i].pf_callback );
1753     }
1754
1755     p_module->p_config[i].i_type = CONFIG_HINT_END;
1756
1757     return VLC_SUCCESS;
1758
1759  error:
1760
1761     return VLC_EGENERIC;
1762 }
1763
1764 /*****************************************************************************
1765  * SavePluginsCache: saves the plugins cache to a file
1766  *****************************************************************************/
1767 static void CacheSave( vlc_object_t *p_this )
1768 {
1769     char *psz_filename, *psz_homedir;
1770     FILE *file;
1771     int i, j, i_cache;
1772     module_cache_t **pp_cache;
1773     int32_t i_file_size = 0;
1774
1775     psz_homedir = p_this->p_vlc->psz_homedir;
1776     if( !psz_homedir )
1777     {
1778         msg_Err( p_this, "psz_homedir is null" );
1779         return;
1780     }
1781     psz_filename =
1782        (char *)malloc( sizeof("/" CONFIG_DIR "/" PLUGINSCACHE_FILE) +
1783                        strlen(psz_homedir) );
1784
1785     if( psz_filename )
1786         sprintf( psz_filename, "%s/" CONFIG_DIR, psz_homedir );
1787
1788     if( !psz_filename )
1789     {
1790         msg_Err( p_this, "out of memory" );
1791         return;
1792     }
1793
1794     config_CreateDir( p_this, psz_filename );
1795
1796     strcat( psz_filename, "/" PLUGINSCACHE_FILE );
1797
1798     msg_Dbg( p_this, "saving plugins cache file %s", psz_filename );
1799
1800     file = fopen( psz_filename, "w" );
1801     if( !file )
1802     {
1803         msg_Warn( p_this, "could not open plugins cache file %s for writing",
1804                   psz_filename );
1805         free( psz_filename );
1806         return;
1807     }
1808     free( psz_filename );
1809
1810     /* Empty space for file size */
1811     fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file );
1812
1813     /* Contains version number */
1814     fprintf( file, PLUGINSCACHE_FILE COPYRIGHT_MESSAGE );
1815
1816     i_cache = p_this->p_libvlc->p_module_bank->i_cache;
1817     pp_cache = p_this->p_libvlc->p_module_bank->pp_cache;
1818
1819     fwrite( &i_cache, sizeof(char), sizeof(i_cache), file );
1820
1821 #define SAVE_IMMEDIATE(a) \
1822     fwrite( &a, sizeof(char), sizeof(a), file )
1823 #define SAVE_STRING(a) \
1824     { i_size = a ? strlen( a ) + 1 : 0; \
1825       fwrite( &i_size, sizeof(char), sizeof(i_size), file ); \
1826       if( a ) fwrite( a, sizeof(char), i_size, file ); \
1827     } while(0)
1828
1829     for( i = 0; i < i_cache; i++ )
1830     {
1831         int16_t i_size;
1832         int32_t i_submodule;
1833
1834         /* Save common info */
1835         SAVE_STRING( pp_cache[i]->psz_file );
1836         SAVE_IMMEDIATE( pp_cache[i]->i_time );
1837         SAVE_IMMEDIATE( pp_cache[i]->i_size );
1838         SAVE_IMMEDIATE( pp_cache[i]->b_junk );
1839
1840         if( pp_cache[i]->b_junk ) continue;
1841
1842         /* Save additional infos */
1843         SAVE_STRING( pp_cache[i]->p_module->psz_object_name );
1844         SAVE_STRING( pp_cache[i]->p_module->psz_shortname );
1845         SAVE_STRING( pp_cache[i]->p_module->psz_longname );
1846         SAVE_STRING( pp_cache[i]->p_module->psz_program );
1847         for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
1848         {
1849             SAVE_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
1850         }
1851         SAVE_STRING( pp_cache[i]->p_module->psz_capability );
1852         SAVE_IMMEDIATE( pp_cache[i]->p_module->i_score );
1853         SAVE_IMMEDIATE( pp_cache[i]->p_module->i_cpu );
1854         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
1855         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_reentrant );
1856         SAVE_IMMEDIATE( pp_cache[i]->p_module->b_submodule );
1857
1858         /* Config stuff */
1859         CacheSaveConfig( pp_cache[i]->p_module, file );
1860
1861         SAVE_STRING( pp_cache[i]->p_module->psz_filename );
1862
1863         i_submodule = pp_cache[i]->p_module->i_children;
1864         SAVE_IMMEDIATE( i_submodule );
1865         for( i_submodule = 0; i_submodule < pp_cache[i]->p_module->i_children;
1866              i_submodule++ )
1867         {
1868             module_t *p_module =
1869                 (module_t *)pp_cache[i]->p_module->pp_children[i_submodule];
1870
1871             SAVE_STRING( p_module->psz_object_name );
1872             SAVE_STRING( p_module->psz_shortname );
1873             SAVE_STRING( p_module->psz_longname );
1874             SAVE_STRING( p_module->psz_program );
1875             for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
1876             {
1877                 SAVE_STRING( p_module->pp_shortcuts[j] ); // FIX
1878             }
1879             SAVE_STRING( p_module->psz_capability );
1880             SAVE_IMMEDIATE( p_module->i_score );
1881             SAVE_IMMEDIATE( p_module->i_cpu );
1882             SAVE_IMMEDIATE( p_module->b_unloadable );
1883             SAVE_IMMEDIATE( p_module->b_reentrant );
1884         }
1885     }
1886
1887     /* Fill-up file size */
1888     i_file_size = ftell( file );
1889     fseek( file, 0, SEEK_SET );
1890     fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file );
1891
1892     fclose( file );
1893
1894     return;
1895 }
1896
1897 void CacheSaveConfig( module_t *p_module, FILE *file )
1898 {
1899     int i, j, i_lines = 0;
1900     module_config_t *p_item;
1901     int16_t i_size;
1902
1903     SAVE_IMMEDIATE( p_module->i_config_items );
1904     SAVE_IMMEDIATE( p_module->i_bool_items );
1905
1906     for( p_item = p_module->p_config; p_item->i_type != CONFIG_HINT_END;
1907          p_item++ ) i_lines++;
1908
1909     SAVE_IMMEDIATE( i_lines );
1910
1911     for( i = 0; i < i_lines ; i++ )
1912     {
1913         SAVE_IMMEDIATE( p_module->p_config[i] );
1914
1915         SAVE_STRING( p_module->p_config[i].psz_type );
1916         SAVE_STRING( p_module->p_config[i].psz_name );
1917         SAVE_STRING( p_module->p_config[i].psz_text );
1918         SAVE_STRING( p_module->p_config[i].psz_longtext );
1919         SAVE_STRING( p_module->p_config[i].psz_value_orig );
1920
1921         if( p_module->p_config[i].i_list )
1922         {
1923             if( p_module->p_config[i].ppsz_list )
1924             {
1925                 for( j = 0; j < p_module->p_config[i].i_list; j++ )
1926                     SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
1927             }
1928
1929             if( p_module->p_config[i].ppsz_list_text )
1930             {
1931                 for( j = 0; j < p_module->p_config[i].i_list; j++ )
1932                     SAVE_STRING( p_module->p_config[i].ppsz_list_text[j] );
1933             }
1934             if( p_module->p_config[i].pi_list )
1935             {
1936                 for( j = 0; j < p_module->p_config[i].i_list; j++ )
1937                     SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
1938             }
1939         }
1940
1941         for( j = 0; j < p_module->p_config[i].i_action; j++ )
1942             SAVE_STRING( p_module->p_config[i].ppsz_action_text[j] );
1943
1944         SAVE_IMMEDIATE( p_module->p_config[i].pf_callback );
1945     }
1946 }
1947
1948 /*****************************************************************************
1949  * CacheMerge: Merge a cache module descriptor with a full module descriptor.
1950  *****************************************************************************/
1951 static void CacheMerge( vlc_object_t *p_this, module_t *p_cache,
1952                         module_t *p_module )
1953 {
1954     int i_submodule;
1955
1956     p_cache->pf_activate = p_module->pf_activate;
1957     p_cache->pf_deactivate = p_module->pf_deactivate;
1958     p_cache->p_symbols = p_module->p_symbols;
1959     p_cache->handle = p_module->handle;
1960
1961     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
1962     {
1963         module_t *p_child = (module_t*)p_module->pp_children[i_submodule];
1964         module_t *p_cchild = (module_t*)p_cache->pp_children[i_submodule];
1965         p_cchild->pf_activate = p_child->pf_activate;
1966         p_cchild->pf_deactivate = p_child->pf_deactivate;
1967         p_cchild->p_symbols = p_child->p_symbols;
1968     }
1969
1970     p_cache->b_loaded = VLC_TRUE;
1971     p_module->b_loaded = VLC_FALSE;
1972 }
1973
1974 /*****************************************************************************
1975  * FindPluginCache: finds the cache entry corresponding to a file
1976  *****************************************************************************/
1977 static module_cache_t *CacheFind( vlc_object_t *p_this, char *psz_file,
1978                                   int64_t i_time, int64_t i_size )
1979 {
1980     module_cache_t **pp_cache;
1981     int i_cache, i;
1982
1983     pp_cache = p_this->p_libvlc->p_module_bank->pp_loaded_cache;
1984     i_cache = p_this->p_libvlc->p_module_bank->i_loaded_cache;
1985
1986     for( i = 0; i < i_cache; i++ )
1987     {
1988         if( !strcmp( pp_cache[i]->psz_file, psz_file ) &&
1989             pp_cache[i]->i_time == i_time &&
1990             pp_cache[i]->i_size == i_size ) return pp_cache[i];
1991     }
1992
1993     return NULL;
1994 }
1995
1996 #endif /* HAVE_DYNAMIC_PLUGINS */