]> git.sesse.net Git - vlc/blob - src/modules/modules.c
92ba948e0fbf7b8f81498b27089437e9fdbb18cf
[vlc] / src / modules / modules.c
1 /*****************************************************************************
2  * modules.c : Builtin and plugin modules management functions
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/vlc.h>
32 #include "libvlc.h"
33
34 /* Some faulty libcs have a broken struct dirent when _FILE_OFFSET_BITS
35  * is set to 64. Don't try to be cleverer. */
36 #ifdef _FILE_OFFSET_BITS
37 #undef _FILE_OFFSET_BITS
38 #endif
39
40 #include <stdlib.h>                                      /* free(), strtol() */
41 #include <stdio.h>                                              /* sprintf() */
42 #include <string.h>                                              /* strdup() */
43 #include <assert.h>
44
45 #ifdef HAVE_DIRENT_H
46 #   include <dirent.h>
47 #endif
48
49 #ifdef HAVE_SYS_TYPES_H
50 #   include <sys/types.h>
51 #endif
52 #ifdef HAVE_SYS_STAT_H
53 #   include <sys/stat.h>
54 #endif
55 #ifdef HAVE_UNISTD_H
56 #   include <unistd.h>
57 #endif
58
59 #if !defined(HAVE_DYNAMIC_PLUGINS)
60     /* no support for plugins */
61 #elif defined(HAVE_DL_DYLD)
62 #   if defined(HAVE_MACH_O_DYLD_H)
63 #       include <mach-o/dyld.h>
64 #   endif
65 #elif defined(HAVE_DL_BEOS)
66 #   if defined(HAVE_IMAGE_H)
67 #       include <image.h>
68 #   endif
69 #elif defined(HAVE_DL_WINDOWS)
70 #   include <windows.h>
71 #elif defined(HAVE_DL_DLOPEN)
72 #   if defined(HAVE_DLFCN_H) /* Linux, BSD, Hurd */
73 #       include <dlfcn.h>
74 #   endif
75 #   if defined(HAVE_SYS_DL_H)
76 #       include <sys/dl.h>
77 #   endif
78 #elif defined(HAVE_DL_SHL_LOAD)
79 #   if defined(HAVE_DL_H)
80 #       include <dl.h>
81 #   endif
82 #endif
83
84 #include "config/configuration.h"
85
86 #include "vlc_charset.h"
87 #include "vlc_arrays.h"
88
89 #include "modules/modules.h"
90 #include "modules/builtin.h"
91
92 /*****************************************************************************
93  * Local prototypes
94  *****************************************************************************/
95 #ifdef HAVE_DYNAMIC_PLUGINS
96 static void AllocateAllPlugins  ( vlc_object_t * );
97 static void AllocatePluginDir   ( vlc_object_t *, const char *, int );
98 static int  AllocatePluginFile  ( vlc_object_t *, char *, int64_t, int64_t );
99 static module_t * AllocatePlugin( vlc_object_t *, char * );
100 #endif
101 static int  AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
102 static int  DeleteModule ( module_t *, bool );
103 #ifdef HAVE_DYNAMIC_PLUGINS
104 static void   DupModule        ( module_t * );
105 static void   UndupModule      ( module_t * );
106 #endif
107
108 /**
109  * Init bank
110  *
111  * Creates a module bank structure which will be filled later
112  * on with all the modules found.
113  * \param p_this vlc object structure
114  * \return nothing
115  */
116 void __module_InitBank( vlc_object_t *p_this )
117 {
118     module_bank_t *p_bank = NULL;
119     libvlc_global_data_t *p_libvlc_global = vlc_global();
120
121     vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
122
123     if( p_libvlc_global->p_module_bank == NULL )
124     {
125         p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
126         p_bank->psz_object_name = "module bank";
127         p_bank->i_usage = 1;
128         p_bank->i_cache = p_bank->i_loaded_cache = 0;
129         p_bank->pp_cache = p_bank->pp_loaded_cache = NULL;
130         p_bank->b_cache = p_bank->b_cache_dirty =
131         p_bank->b_cache_delete = false;
132
133         /* Everything worked, attach the object */
134         p_libvlc_global->p_module_bank = p_bank;
135         vlc_object_attach( p_bank, p_libvlc_global );
136
137         /* Fills the module bank structure with the main module infos.
138          * This is very useful as it will allow us to consider the main
139          * library just as another module, and for instance the configuration
140          * options of main will be available in the module bank structure just
141          * as for every other module. */
142         AllocateBuiltinModule( p_this, vlc_entry__main );
143     }
144     else
145         p_libvlc_global->p_module_bank->i_usage++;
146
147     vlc_mutex_unlock( lock );
148 }
149
150
151 /**
152  * End bank
153  *
154  * Unloads all unused plugin modules and empties the module
155  * bank in case of success.
156  * \param p_this vlc object structure
157  * \return nothing
158  */
159 void __module_EndBank( vlc_object_t *p_this )
160 {
161     module_t * p_next = NULL;
162     libvlc_global_data_t *p_libvlc_global = vlc_global();
163
164     vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
165     if( !p_libvlc_global->p_module_bank )
166     {
167         vlc_mutex_unlock( lock );
168         return;
169     }
170     if( --p_libvlc_global->p_module_bank->i_usage )
171     {
172         vlc_mutex_unlock( lock );
173         return;
174     }
175     vlc_mutex_unlock( lock );
176
177     /* Save the configuration */
178     config_AutoSaveConfigFile( p_this );
179
180 #ifdef HAVE_DYNAMIC_PLUGINS
181 # define p_bank p_libvlc_global->p_module_bank
182     if( p_bank->b_cache ) CacheSave( p_this );
183     while( p_bank->i_loaded_cache-- )
184     {
185         if( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] )
186         {
187             DeleteModule(
188                     p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->p_module,
189                     p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->b_used );
190             free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->psz_file );
191             free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] );
192             p_bank->pp_loaded_cache[p_bank->i_loaded_cache] = NULL;
193         }
194     }
195     if( p_bank->pp_loaded_cache )
196     {
197         free( p_bank->pp_loaded_cache );
198         p_bank->pp_loaded_cache = NULL;
199     }
200     while( p_bank->i_cache-- )
201     {
202         free( p_bank->pp_cache[p_bank->i_cache]->psz_file );
203         free( p_bank->pp_cache[p_bank->i_cache] );
204         p_bank->pp_cache[p_bank->i_cache] = NULL;
205     }
206     if( p_bank->pp_cache )
207     {
208         free( p_bank->pp_cache );
209         p_bank->pp_cache = NULL;
210     }
211 # undef p_bank
212 #endif
213
214     vlc_object_detach( p_libvlc_global->p_module_bank );
215
216     while( p_libvlc_global->p_module_bank->i_children )
217     {
218         p_next = (module_t *)p_libvlc_global->p_module_bank->pp_children[0];
219
220         if( DeleteModule( p_next, true ) )
221         {
222             /* Module deletion failed */
223             msg_Err( p_this, "module \"%s\" can't be removed, trying harder",
224                      p_next->psz_object_name );
225
226             /* We just free the module by hand. Niahahahahaha. */
227             vlc_object_detach( p_next );
228             vlc_object_release( p_next );
229         }
230     }
231
232     vlc_object_release( p_libvlc_global->p_module_bank );
233     p_libvlc_global->p_module_bank = NULL;
234 }
235
236 /**
237  * Load all modules which we built with.
238  *
239  * Fills the module bank structure with the builtin modules.
240  * \param p_this vlc object structure
241  * \return nothing
242  */
243 void __module_LoadBuiltins( vlc_object_t * p_this )
244 {
245     libvlc_global_data_t *p_libvlc_global = vlc_global();
246
247     vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
248     if( p_libvlc_global->p_module_bank->b_builtins )
249     {
250         vlc_mutex_unlock( lock );
251         return;
252     }
253     p_libvlc_global->p_module_bank->b_builtins = true;
254     vlc_mutex_unlock( lock );
255
256     msg_Dbg( p_this, "checking builtin modules" );
257     ALLOCATE_ALL_BUILTINS();
258 }
259
260 /**
261  * Load all plugins
262  *
263  * Load all plugin modules we can find.
264  * Fills the module bank structure with the plugin modules.
265  * \param p_this vlc object structure
266  * \return nothing
267  */
268 void __module_LoadPlugins( vlc_object_t * p_this )
269 {
270 #ifdef HAVE_DYNAMIC_PLUGINS
271     libvlc_global_data_t *p_libvlc_global = vlc_global();
272
273     vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
274     if( p_libvlc_global->p_module_bank->b_plugins )
275     {
276         vlc_mutex_unlock( lock );
277         return;
278     }
279     p_libvlc_global->p_module_bank->b_plugins = true;
280     vlc_mutex_unlock( lock );
281
282     msg_Dbg( p_this, "checking plugin modules" );
283
284     if( config_GetInt( p_this, "plugins-cache" ) )
285         p_libvlc_global->p_module_bank->b_cache = true;
286
287     if( p_libvlc_global->p_module_bank->b_cache ||
288         p_libvlc_global->p_module_bank->b_cache_delete ) CacheLoad( p_this );
289
290     AllocateAllPlugins( p_this );
291 #endif
292 }
293
294 /**
295  * Checks whether a module implements a capability.
296  *
297  * \param m the module
298  * \param cap the capability to check
299  * \return TRUE if the module have the capability
300  */
301 bool module_IsCapable( const module_t *m, const char *cap )
302 {
303     return !strcmp( m->psz_capability, cap );
304 }
305
306 /**
307  * Get the internal name of a module
308  *
309  * \param m the module
310  * \return the module name
311  */
312 const char *module_GetObjName( const module_t *m )
313 {
314     return m->psz_object_name;
315 }
316
317 /**
318  * Get the human-friendly name of a module.
319  *
320  * \param m the module
321  * \param long_name TRUE to have the long name of the module
322  * \return the short or long name of the module
323  */
324 const char *module_GetName( const module_t *m, bool long_name )
325 {
326     if( long_name && ( m->psz_longname != NULL) )
327         return m->psz_longname;
328
329     return m->psz_shortname ?: m->psz_object_name;
330 }
331
332 /**
333  * Get the help for a module
334  *
335  * \param m the module
336  * \return the help
337  */
338 const char *module_GetHelp( const module_t *m )
339 {
340     return m->psz_help;
341 }
342
343 /**
344  * module Need
345  *
346  * Return the best module function, given a capability list.
347  * \param p_this the vlc object
348  * \param psz_capability list of capabilities needed
349  * \param psz_name name of the module asked
350  * \param b_strict TRUE yto use the strict mode
351  * \return the module or NULL in case of a failure
352  */
353 module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
354                           const char *psz_name, bool b_strict )
355 {
356     typedef struct module_list_t module_list_t;
357
358     stats_TimerStart( p_this, "module_Need()", STATS_TIMER_MODULE_NEED );
359
360     struct module_list_t
361     {
362         module_t *p_module;
363         int i_score;
364         bool b_force;
365         module_list_t *p_next;
366     };
367
368     module_list_t *p_list, *p_first, *p_tmp;
369     vlc_list_t *p_all;
370
371     int i_which_module, i_index = 0;
372
373     module_t *p_module;
374
375     int   i_shortcuts = 0;
376     char *psz_shortcuts = NULL, *psz_var = NULL, *psz_alias = NULL;
377     bool b_force_backup = p_this->b_force;
378
379
380     /* Deal with variables */
381     if( psz_name && psz_name[0] == '$' )
382     {
383         vlc_value_t val;
384         var_Create( p_this, psz_name + 1, VLC_VAR_MODULE | VLC_VAR_DOINHERIT );
385         var_Get( p_this, psz_name + 1, &val );
386         psz_var = val.psz_string;
387         psz_name = psz_var;
388     }
389
390     /* Count how many different shortcuts were asked for */
391     if( psz_name && *psz_name )
392     {
393         char *psz_parser, *psz_last_shortcut;
394
395         /* If the user wants none, give him none. */
396         if( !strcmp( psz_name, "none" ) )
397         {
398             free( psz_var );
399             stats_TimerStop( p_this, STATS_TIMER_MODULE_NEED );
400             stats_TimerDump( p_this, STATS_TIMER_MODULE_NEED );
401             stats_TimerClean( p_this, STATS_TIMER_MODULE_NEED );
402             return NULL;
403         }
404
405         i_shortcuts++;
406         psz_shortcuts = psz_last_shortcut = strdup( psz_name );
407
408         for( psz_parser = psz_shortcuts; *psz_parser; psz_parser++ )
409         {
410             if( *psz_parser == ',' )
411             {
412                  *psz_parser = '\0';
413                  i_shortcuts++;
414                  psz_last_shortcut = psz_parser + 1;
415             }
416         }
417
418         /* Check if the user wants to override the "strict" mode */
419         if( psz_last_shortcut )
420         {
421             if( !strcmp(psz_last_shortcut, "none") )
422             {
423                 b_strict = true;
424                 i_shortcuts--;
425             }
426             else if( !strcmp(psz_last_shortcut, "any") )
427             {
428                 b_strict = false;
429                 i_shortcuts--;
430             }
431         }
432     }
433
434     /* Sort the modules and test them */
435     p_all = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
436     p_list = malloc( p_all->i_count * sizeof( module_list_t ) );
437     p_first = NULL;
438     unsigned i_cpu = vlc_CPU();
439
440     /* Parse the module list for capabilities and probe each of them */
441     for( i_which_module = 0; i_which_module < p_all->i_count; i_which_module++ )
442     {
443         int i_shortcut_bonus = 0;
444
445         p_module = (module_t *)p_all->p_values[i_which_module].p_object;
446
447         /* Test that this module can do what we need */
448         if( !module_IsCapable( p_module, psz_capability ) )
449         {
450             /* Don't recurse through the sub-modules because vlc_list_find()
451              * will list them anyway. */
452             continue;
453         }
454
455         /* Test if we have the required CPU */
456         if( (p_module->i_cpu & i_cpu) != p_module->i_cpu )
457         {
458             continue;
459         }
460
461         /* If we required a shortcut, check this plugin provides it. */
462         if( i_shortcuts > 0 )
463         {
464             bool b_trash;
465             const char *psz_name = psz_shortcuts;
466
467             /* Let's drop modules with a <= 0 score (unless they are
468              * explicitly requested) */
469             b_trash = p_module->i_score <= 0;
470
471             for( unsigned i_short = i_shortcuts; i_short > 0; i_short-- )
472             {
473                 for( unsigned i = 0; p_module->pp_shortcuts[i]; i++ )
474                 {
475                     char *c;
476                     if( ( c = strchr( psz_name, '@' ) )
477                         ? !strncasecmp( psz_name, p_module->pp_shortcuts[i],
478                                         c-psz_name )
479                         : !strcasecmp( psz_name, p_module->pp_shortcuts[i] ) )
480                     {
481                         /* Found it */
482                         if( c && c[1] )
483                             psz_alias = c+1;
484                         i_shortcut_bonus = i_short * 10000;
485                         goto found_shortcut;
486                     }
487                 }
488
489                 /* Go to the next shortcut... This is so lame! */
490                 psz_name += strlen( psz_name ) + 1;
491             }
492
493             /* If we are in "strict" mode and we couldn't
494              * find the module in the list of provided shortcuts,
495              * then kick the bastard out of here!!! */
496             if( b_strict )
497                 continue;
498         }
499         /* If we didn't require a shortcut, trash <= 0 scored plugins */
500         else if( p_module->i_score <= 0 )
501         {
502             continue;
503         }
504
505 found_shortcut:
506
507         /* Store this new module */
508         p_list[ i_index ].p_module = p_module;
509         p_list[ i_index ].i_score = p_module->i_score + i_shortcut_bonus;
510         p_list[ i_index ].b_force = i_shortcut_bonus && b_strict;
511
512         /* Add it to the modules-to-probe list */
513         if( i_index == 0 )
514         {
515             p_list[ 0 ].p_next = NULL;
516             p_first = p_list;
517         }
518         else
519         {
520             /* Ok, so at school you learned that quicksort is quick, and
521              * bubble sort sucks raw eggs. But that's when dealing with
522              * thousands of items. Here we have barely 50. */
523             module_list_t *p_newlist = p_first;
524
525             if( p_first->i_score < p_list[ i_index ].i_score )
526             {
527                 p_list[ i_index ].p_next = p_first;
528                 p_first = &p_list[ i_index ];
529             }
530             else
531             {
532                 while( p_newlist->p_next != NULL &&
533                     p_newlist->p_next->i_score >= p_list[ i_index ].i_score )
534                 {
535                     p_newlist = p_newlist->p_next;
536                 }
537
538                 p_list[ i_index ].p_next = p_newlist->p_next;
539                 p_newlist->p_next = &p_list[ i_index ];
540             }
541         }
542
543         i_index++;
544     }
545
546     msg_Dbg( p_this, "looking for %s module: %i candidate%s", psz_capability,
547                                             i_index, i_index == 1 ? "" : "s" );
548
549     /* Lock all candidate modules */
550     p_tmp = p_first;
551     while( p_tmp != NULL )
552     {
553         vlc_object_yield( p_tmp->p_module );
554         p_tmp = p_tmp->p_next;
555     }
556
557     /* We can release the list, interesting modules were yielded */
558     vlc_list_release( p_all );
559
560     /* Parse the linked list and use the first successful module */
561     p_tmp = p_first;
562     while( p_tmp != NULL )
563     {
564 #ifdef HAVE_DYNAMIC_PLUGINS
565         /* Make sure the module is loaded in mem */
566         module_t *p_module = p_tmp->p_module;
567         if( p_module->b_submodule )
568             p_module = (module_t *)p_module->p_parent;
569
570         if( !p_module->b_builtin && !p_module->b_loaded )
571         {
572             module_t *p_new_module =
573                 AllocatePlugin( p_this, p_module->psz_filename );
574             if( p_new_module )
575             {
576                 CacheMerge( p_this, p_module, p_new_module );
577                 vlc_object_attach( p_new_module, p_module );
578                 DeleteModule( p_new_module, true );
579             }
580         }
581 #endif
582
583         p_this->b_force = p_tmp->b_force;
584         if( p_tmp->p_module->pf_activate
585              && p_tmp->p_module->pf_activate( p_this ) == VLC_SUCCESS )
586         {
587             break;
588         }
589
590         vlc_object_release( p_tmp->p_module );
591         p_tmp = p_tmp->p_next;
592     }
593
594     /* Store the locked module value */
595     if( p_tmp != NULL )
596     {
597         p_module = p_tmp->p_module;
598         p_tmp = p_tmp->p_next;
599     }
600     else
601     {
602         p_module = NULL;
603     }
604
605     /* Unlock the remaining modules */
606     while( p_tmp != NULL )
607     {
608         vlc_object_release( p_tmp->p_module );
609         p_tmp = p_tmp->p_next;
610     }
611
612     free( p_list );
613     p_this->b_force = b_force_backup;
614
615     if( p_module != NULL )
616     {
617         msg_Dbg( p_this, "using %s module \"%s\"",
618                  psz_capability, p_module->psz_object_name );
619     }
620     else if( p_first == NULL )
621     {
622         if( !strcmp( psz_capability, "access_demux" ) )
623         {
624             msg_Warn( p_this, "no %s module matched \"%s\"",
625                  psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
626         }
627         else
628         {
629             msg_Err( p_this, "no %s module matched \"%s\"",
630                  psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
631
632             msg_StackSet( VLC_EGENERIC, "no %s module matched \"%s\"",
633                  psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
634         }
635     }
636     else if( psz_name != NULL && *psz_name )
637     {
638         msg_Warn( p_this, "no %s module matching \"%s\" could be loaded",
639                   psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
640     }
641     else
642         msg_StackSet( VLC_EGENERIC, "no suitable %s module", psz_capability );
643
644     if( p_module && !p_this->psz_object_name )
645     {
646         /* This assumes that p_this is the object which will be using the
647          * module. That's not always the case ... but it is in most cases.
648          */
649         if( psz_alias )
650             p_this->psz_object_name = strdup( psz_alias );
651         else
652             p_this->psz_object_name = strdup( p_module->psz_object_name );
653     }
654
655     free( psz_shortcuts );
656     free( psz_var );
657
658     stats_TimerStop( p_this, STATS_TIMER_MODULE_NEED );
659     stats_TimerDump( p_this, STATS_TIMER_MODULE_NEED );
660     stats_TimerClean( p_this, STATS_TIMER_MODULE_NEED );
661
662     /* Don't forget that the module is still locked */
663     return p_module;
664 }
665
666 /**
667  * Module unneed
668  *
669  * This function must be called by the thread that called module_Need, to
670  * decrease the reference count and allow for hiding of modules.
671  * \param p_this vlc object structure
672  * \param p_module the module structure
673  * \return nothing
674  */
675 void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
676 {
677     /* Use the close method */
678     if( p_module->pf_deactivate )
679     {
680         p_module->pf_deactivate( p_this );
681     }
682
683     msg_Dbg( p_this, "removing module \"%s\"", p_module->psz_object_name );
684
685     vlc_object_release( p_module );
686
687     return;
688 }
689
690 /**
691  * Get a pointer to a module_t given it's name.
692  *
693  * \param p_this vlc object structure
694  * \param psz_name the name of the module
695  * \return a pointer to the module or NULL in case of a failure
696  */
697 module_t *__module_Find( vlc_object_t *p_this, const char * psz_name )
698 {
699     vlc_list_t *p_list;
700     int i;
701     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
702     for( i = 0 ; i < p_list->i_count; i++)
703     {
704         module_t *p_module = ((module_t *) p_list->p_values[i].p_object);
705         const char *psz_module_name = p_module->psz_object_name;
706         if( psz_module_name && !strcmp( psz_module_name, psz_name ) )
707         {
708             /* We can release the list, and return yes */
709             vlc_object_yield( p_module );
710             vlc_list_release( p_list );
711             return p_module;
712         }
713     }
714     vlc_list_release( p_list );
715     return NULL;
716 }
717
718
719 /**
720  * Release a module_t pointer from module_Find().
721  *
722  * \param module the module to release
723  * \return nothing
724  */
725 void module_Put( module_t *module )
726 {
727     vlc_object_release( module );
728 }
729
730
731 /**
732  * Tell if a module exists and release it in thic case
733  *
734  * \param p_this vlc object structure
735  * \param psz_name th name of the module
736  * \return TRUE if the module exists
737  */
738 bool __module_Exists( vlc_object_t *p_this, const char * psz_name )
739 {
740     module_t *p_module = __module_Find( p_this, psz_name );
741     if( p_module )
742     {
743         module_Put( p_module );
744         return true;
745     }
746     else
747     {
748         return false;
749     }
750 }
751
752 /**
753  * GetModuleNamesForCapability
754  *
755  * Return a NULL terminated array with the names of the modules
756  * that have a certain capability.
757  * Free after uses both the string and the table.
758  * \param p_this vlc object structure
759  * \param psz_capability the capability asked
760  * \param pppsz_longname an pointer to an array of string to contain
761     the long names of the modules. If set to NULL the function don't use it.
762  * \return the NULL terminated array
763  */
764 char ** __module_GetModulesNamesForCapability( vlc_object_t *p_this,
765                                                const char *psz_capability,
766                                                char ***pppsz_longname )
767 {
768     vlc_list_t *p_list;
769     int i, j, count = 0;
770     char **psz_ret;
771
772     /* Do it in two passes : count the number of modules before */
773     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
774     for( i = 0 ; i < p_list->i_count; i++)
775     {
776         module_t *p_module = ((module_t *) p_list->p_values[i].p_object);
777         const char *psz_module_capability = p_module->psz_capability;
778         if( psz_module_capability && !strcmp( psz_module_capability, psz_capability ) )
779             count++;
780     }
781
782     psz_ret = malloc( sizeof(char*) * (count+1) );
783     if( pppsz_longname )
784         *pppsz_longname = malloc( sizeof(char*) * (count+1) );
785     if( !psz_ret || ( pppsz_longname && *pppsz_longname == NULL ) )
786     {
787         free( psz_ret );
788         free( *pppsz_longname );
789         *pppsz_longname = NULL;
790         vlc_list_release( p_list );
791         return NULL;
792     }
793
794     j = 0;
795     for( i = 0 ; i < p_list->i_count; i++)
796     {
797         module_t *p_module = ((module_t *) p_list->p_values[i].p_object);
798         const char *psz_module_capability = p_module->psz_capability;
799         if( psz_module_capability && !strcmp( psz_module_capability, psz_capability ) )
800         {
801             int k = -1; /* hack to handle submodules properly */
802             if( p_module->b_submodule )
803             {
804                 while( p_module->pp_shortcuts[++k] != NULL );
805                 k--;
806             }
807             psz_ret[j] = strdup( k>=0?p_module->pp_shortcuts[k]
808                                      :p_module->psz_object_name );
809             if( pppsz_longname )
810                 (*pppsz_longname)[j] = strdup( module_GetName( p_module, true ) );
811             j++;
812         }
813     }
814     psz_ret[count] = NULL;
815
816     vlc_list_release( p_list );
817
818     return psz_ret;
819 }
820
821 /**
822  * Get the configuration of a module
823  *
824  * \param module the module
825  * \param psize the size of the configuration returned
826  * \return the configuration as an array
827  */
828 module_config_t *module_GetConfig( const module_t *module, unsigned *restrict psize )
829 {
830     unsigned i,j;
831     unsigned size = module->confsize;
832     module_config_t *config = malloc( size * sizeof( *config ) );
833
834     assert( psize != NULL );
835     *psize = 0;
836
837     if( !config )
838         return NULL;
839
840     for( i = 0, j = 0; i < size; i++ )
841     {
842         const module_config_t *item = module->p_config + i;
843         if( item->b_internal /* internal option */
844          || item->b_unsaveable /* non-modifiable option */
845          || item->b_removed /* removed option */ )
846             continue;
847
848         memcpy( config + j, item, sizeof( *config ) );
849         j++;
850     }
851     *psize = j;
852
853     return config;
854 }
855
856 /**
857  * Release the configuration
858  *
859  * \param the configuration
860  * \return nothing
861  */
862 void module_PutConfig( module_config_t *config )
863 {
864     free( config );
865 }
866
867 /*****************************************************************************
868  * Following functions are local.
869  *****************************************************************************/
870
871  /*****************************************************************************
872  * copy_next_paths_token: from a PATH_SEP_CHAR (a ':' or a ';') separated paths
873  * return first path.
874  *****************************************************************************/
875 static char * copy_next_paths_token( char * paths, char ** remaining_paths )
876 {
877     char * path;
878     int i, done;
879     bool escaped = false;
880
881     assert( paths );
882
883     /* Alloc a buffer to store the path */
884     path = malloc( strlen( paths ) + 1 );
885     if( !path ) return NULL;
886
887     /* Look for PATH_SEP_CHAR (a ':' or a ';') */
888     for( i = 0, done = 0 ; paths[i]; i++ ) {
889         /* Take care of \\ and \: or \; escapement */
890         if( escaped ) {
891             escaped = false;
892             path[done++] = paths[i];
893         }
894         else if( paths[i] == '\\' )
895             escaped = true;
896         else if( paths[i] == PATH_SEP_CHAR )
897             break;
898         else
899             path[done++] = paths[i];
900     }
901     path[done++] = 0;
902
903     /* Return the remaining paths */
904     if( remaining_paths ) {
905         *remaining_paths = paths[i] ? &paths[i]+1 : NULL;
906     }
907
908     return path;
909 }
910
911 /*****************************************************************************
912  * AllocateAllPlugins: load all plugin modules we can find.
913  *****************************************************************************/
914 #ifdef HAVE_DYNAMIC_PLUGINS
915 static void AllocateAllPlugins( vlc_object_t *p_this )
916 {
917     int count,i;
918     char * path;
919     vlc_array_t *arraypaths = vlc_array_new();
920
921     /* Contruct the special search path for system that have a relocatable
922      * executable. Set it to <vlc path>/modules and <vlc path>/plugins. */
923 #define RETURN_ENOMEM                               \
924     {                                               \
925         msg_Err( p_this, "Not enough memory" );     \
926         return;                                     \
927     }
928
929     vlc_array_append( arraypaths, strdup( "modules" ) );
930 #if defined( WIN32 ) || defined( UNDER_CE ) || defined( __APPLE__ ) || defined( SYS_BEOS )
931     if( asprintf( &path, "%s" DIR_SEP "modules",
932         vlc_global()->psz_vlcpath ) < 0 )
933         RETURN_ENOMEM
934     vlc_array_append( arraypaths, path );
935     if( asprintf( &path, "%s" DIR_SEP "plugins",
936         vlc_global()->psz_vlcpath ) < 0 )
937         RETURN_ENOMEM
938     vlc_array_append( arraypaths, path );
939 #if ! defined( WIN32 ) && ! defined( UNDER_CE )
940     if( asprintf( &path, "%s", PLUGIN_PATH ) < 0 )
941         RETURN_ENOMEM
942     vlc_array_append( arraypaths, path );
943 #endif
944 #else
945     vlc_array_append( arraypaths, strdup( PLUGIN_PATH ) );
946 #endif
947     vlc_array_append( arraypaths, strdup( "plugins" ) );
948
949     /* If the user provided a plugin path, we add it to the list */
950     char * userpaths = config_GetPsz( p_this, "plugin-path" );
951     char *paths_iter;
952
953     for( paths_iter = userpaths; paths_iter; )
954     {
955         path = copy_next_paths_token( paths_iter, &paths_iter );
956         if( !path )
957             RETURN_ENOMEM
958         vlc_array_append( arraypaths, strdup( path ) );
959     }
960
961     count = vlc_array_count( arraypaths );
962     for( i = 0 ; i < count ; i++ )
963     {
964         path = vlc_array_item_at_index( arraypaths, i );
965         if( !path )
966         {
967             continue;
968         }
969
970         msg_Dbg( p_this, "recursively browsing `%s'", path );
971
972         /* Don't go deeper than 5 subdirectories */
973         AllocatePluginDir( p_this, path, 5 );
974
975         free( path );
976     }
977
978     vlc_array_destroy( arraypaths );
979 #undef RETURN_ENOMEM
980 }
981
982 /*****************************************************************************
983  * AllocatePluginDir: recursively parse a directory to look for plugins
984  *****************************************************************************/
985 static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
986                                int i_maxdepth )
987 {
988 /* FIXME: Needs to be ported to wide char on ALL Windows builds */
989 #ifdef WIN32
990 # undef opendir
991 # undef closedir
992 # undef readdir
993 #endif
994 #if defined( UNDER_CE ) || defined( _MSC_VER )
995 #ifdef UNDER_CE
996     wchar_t psz_wpath[MAX_PATH + 256];
997     wchar_t psz_wdir[MAX_PATH];
998 #endif
999     char psz_path[MAX_PATH + 256];
1000     WIN32_FIND_DATA finddata;
1001     HANDLE handle;
1002     int rc;
1003 #else
1004     int    i_dirlen;
1005     DIR *  dir;
1006     struct dirent * file;
1007 #endif
1008     char * psz_file;
1009
1010     if( p_this->p_libvlc->b_die || i_maxdepth < 0 )
1011     {
1012         return;
1013     }
1014
1015 #if defined( UNDER_CE ) || defined( _MSC_VER )
1016 #ifdef UNDER_CE
1017     MultiByteToWideChar( CP_ACP, 0, psz_dir, -1, psz_wdir, MAX_PATH );
1018
1019     rc = GetFileAttributes( psz_wdir );
1020     if( rc<0 || !(rc&FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */
1021
1022     /* Parse all files in the directory */
1023     swprintf( psz_wpath, L"%ls\\*", psz_wdir );
1024 #else
1025     rc = GetFileAttributes( psz_dir );
1026     if( rc<0 || !(rc&FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */
1027 #endif
1028
1029     /* Parse all files in the directory */
1030     sprintf( psz_path, "%s\\*", psz_dir );
1031
1032 #ifdef UNDER_CE
1033     handle = FindFirstFile( psz_wpath, &finddata );
1034 #else
1035     handle = FindFirstFile( psz_path, &finddata );
1036 #endif
1037     if( handle == INVALID_HANDLE_VALUE )
1038     {
1039         /* Empty directory */
1040         return;
1041     }
1042
1043     /* Parse the directory and try to load all files it contains. */
1044     do
1045     {
1046 #ifdef UNDER_CE
1047         unsigned int i_len = wcslen( finddata.cFileName );
1048         swprintf( psz_wpath, L"%ls\\%ls", psz_wdir, finddata.cFileName );
1049         sprintf( psz_path, "%s\\%ls", psz_dir, finddata.cFileName );
1050 #else
1051         unsigned int i_len = strlen( finddata.cFileName );
1052         sprintf( psz_path, "%s\\%s", psz_dir, finddata.cFileName );
1053 #endif
1054
1055         /* Skip ".", ".." */
1056         if( !*finddata.cFileName || !strcmp( finddata.cFileName, "." )
1057          || !strcmp( finddata.cFileName, ".." ) )
1058         {
1059             if( !FindNextFile( handle, &finddata ) ) break;
1060             continue;
1061         }
1062
1063 #ifdef UNDER_CE
1064         if( GetFileAttributes( psz_wpath ) & FILE_ATTRIBUTE_DIRECTORY )
1065 #else
1066         if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY )
1067 #endif
1068         {
1069             AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 );
1070         }
1071         else if( i_len > strlen( LIBEXT )
1072                   /* We only load files ending with LIBEXT */
1073                   && !strncasecmp( psz_path + strlen( psz_path)
1074                                    - strlen( LIBEXT ),
1075                                    LIBEXT, strlen( LIBEXT ) ) )
1076         {
1077             WIN32_FILE_ATTRIBUTE_DATA attrbuf;
1078             int64_t i_time = 0, i_size = 0;
1079
1080 #ifdef UNDER_CE
1081             if( GetFileAttributesEx( psz_wpath, GetFileExInfoStandard,
1082                                      &attrbuf ) )
1083 #else
1084             if( GetFileAttributesEx( psz_path, GetFileExInfoStandard,
1085                                      &attrbuf ) )
1086 #endif
1087             {
1088                 i_time = attrbuf.ftLastWriteTime.dwHighDateTime;
1089                 i_time <<= 32;
1090                 i_time |= attrbuf.ftLastWriteTime.dwLowDateTime;
1091                 i_size = attrbuf.nFileSizeHigh;
1092                 i_size <<= 32;
1093                 i_size |= attrbuf.nFileSizeLow;
1094             }
1095             psz_file = psz_path;
1096
1097             AllocatePluginFile( p_this, psz_file, i_time, i_size );
1098         }
1099     }
1100     while( !p_this->p_libvlc->b_die && FindNextFile( handle, &finddata ) );
1101
1102     /* Close the directory */
1103     FindClose( handle );
1104
1105 #else
1106     dir = opendir( psz_dir );
1107     if( !dir )
1108     {
1109         return;
1110     }
1111
1112     i_dirlen = strlen( psz_dir );
1113
1114     /* Parse the directory and try to load all files it contains. */
1115     while( !p_this->p_libvlc->b_die && ( file = readdir( dir ) ) )
1116     {
1117         struct stat statbuf;
1118         unsigned int i_len;
1119         int i_stat;
1120
1121         /* Skip ".", ".." */
1122         if( !*file->d_name || !strcmp( file->d_name, "." )
1123          || !strcmp( file->d_name, ".." ) )
1124         {
1125             continue;
1126         }
1127
1128         i_len = strlen( file->d_name );
1129         psz_file = malloc( i_dirlen + 1 + i_len + 1 );
1130         sprintf( psz_file, "%s"DIR_SEP"%s", psz_dir, file->d_name );
1131
1132         i_stat = stat( psz_file, &statbuf );
1133         if( !i_stat && statbuf.st_mode & S_IFDIR )
1134         {
1135             AllocatePluginDir( p_this, psz_file, i_maxdepth - 1 );
1136         }
1137         else if( i_len > strlen( LIBEXT )
1138                   /* We only load files ending with LIBEXT */
1139                   && !strncasecmp( file->d_name + i_len - strlen( LIBEXT ),
1140                                    LIBEXT, strlen( LIBEXT ) ) )
1141         {
1142             int64_t i_time = 0, i_size = 0;
1143
1144             if( !i_stat )
1145             {
1146                 i_time = statbuf.st_mtime;
1147                 i_size = statbuf.st_size;
1148             }
1149
1150             AllocatePluginFile( p_this, psz_file, i_time, i_size );
1151         }
1152
1153         free( psz_file );
1154     }
1155
1156     /* Close the directory */
1157     closedir( dir );
1158
1159 #endif
1160 }
1161
1162 /*****************************************************************************
1163  * AllocatePluginFile: load a module into memory and initialize it.
1164  *****************************************************************************
1165  * This function loads a dynamically loadable module and allocates a structure
1166  * for its information data. The module can then be handled by module_Need
1167  * and module_Unneed. It can be removed by DeleteModule.
1168  *****************************************************************************/
1169 static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
1170                                int64_t i_file_time, int64_t i_file_size )
1171 {
1172     module_t * p_module = NULL;
1173     module_cache_t *p_cache_entry = NULL;
1174
1175     /*
1176      * Check our plugins cache first then load plugin if needed
1177      */
1178     p_cache_entry =
1179         CacheFind( psz_file, i_file_time, i_file_size );
1180
1181     if( !p_cache_entry )
1182     {
1183         p_module = AllocatePlugin( p_this, psz_file );
1184     }
1185     else
1186     {
1187         /* If junk dll, don't try to load it */
1188         if( p_cache_entry->b_junk )
1189         {
1190             p_module = NULL;
1191         }
1192         else
1193         {
1194             module_config_t *p_item = NULL, *p_end = NULL;
1195
1196             p_module = p_cache_entry->p_module;
1197             p_module->b_loaded = false;
1198
1199             /* For now we force loading if the module's config contains
1200              * callbacks or actions.
1201              * Could be optimized by adding an API call.*/
1202             for( p_item = p_module->p_config, p_end = p_item + p_module->confsize;
1203                  p_item < p_end; p_item++ )
1204             {
1205                 if( p_item->pf_callback || p_item->i_action )
1206                 {
1207                     p_module = AllocatePlugin( p_this, psz_file );
1208                     break;
1209                 }
1210             }
1211             if( p_module == p_cache_entry->p_module )
1212                 p_cache_entry->b_used = true;
1213         }
1214     }
1215
1216     if( p_module )
1217     {
1218         libvlc_global_data_t *p_libvlc_global = vlc_global();
1219
1220         /* Everything worked fine !
1221          * The module is ready to be added to the list. */
1222         p_module->b_builtin = false;
1223
1224         /* msg_Dbg( p_this, "plugin \"%s\", %s",
1225                     p_module->psz_object_name, p_module->psz_longname ); */
1226
1227         vlc_object_attach( p_module, p_libvlc_global->p_module_bank );
1228
1229         if( !p_libvlc_global->p_module_bank->b_cache )
1230             return 0;
1231
1232 #define p_bank p_libvlc_global->p_module_bank
1233         /* Add entry to cache */
1234         p_bank->pp_cache =
1235             realloc( p_bank->pp_cache, (p_bank->i_cache + 1) * sizeof(void *) );
1236         p_bank->pp_cache[p_bank->i_cache] = malloc( sizeof(module_cache_t) );
1237         if( !p_bank->pp_cache[p_bank->i_cache] )
1238             return -1;
1239         p_bank->pp_cache[p_bank->i_cache]->psz_file = strdup( psz_file );
1240         p_bank->pp_cache[p_bank->i_cache]->i_time = i_file_time;
1241         p_bank->pp_cache[p_bank->i_cache]->i_size = i_file_size;
1242         p_bank->pp_cache[p_bank->i_cache]->b_junk = p_module ? 0 : 1;
1243         p_bank->pp_cache[p_bank->i_cache]->b_used = true;
1244         p_bank->pp_cache[p_bank->i_cache]->p_module = p_module;
1245         p_bank->i_cache++;
1246     }
1247
1248     return p_module ? 0 : -1;
1249 }
1250
1251 /*****************************************************************************
1252  * AllocatePlugin: load a module into memory and initialize it.
1253  *****************************************************************************
1254  * This function loads a dynamically loadable module and allocates a structure
1255  * for its information data. The module can then be handled by module_Need
1256  * and module_Unneed. It can be removed by DeleteModule.
1257  *****************************************************************************/
1258 static module_t * AllocatePlugin( vlc_object_t * p_this, char * psz_file )
1259 {
1260     module_t * p_module = NULL;
1261     module_handle_t handle;
1262
1263     if( module_Load( p_this, psz_file, &handle ) )
1264         return NULL;
1265
1266     /* Now that we have successfully loaded the module, we can
1267      * allocate a structure for it */
1268     p_module = vlc_module_create( p_this );
1269     if( p_module == NULL )
1270     {
1271         msg_Err( p_this, "out of memory" );
1272         module_Unload( handle );
1273         return NULL;
1274     }
1275
1276     /* We need to fill these since they may be needed by module_Call() */
1277     p_module->psz_filename = psz_file;
1278     p_module->handle = handle;
1279     p_module->b_loaded = true;
1280
1281     /* Initialize the module: fill p_module, default config */
1282     if( module_Call( p_module ) != 0 )
1283     {
1284         /* We couldn't call module_init() */
1285         vlc_object_release( p_module );
1286         module_Unload( handle );
1287         return NULL;
1288     }
1289
1290     DupModule( p_module );
1291     p_module->psz_filename = strdup( p_module->psz_filename );
1292
1293     /* Everything worked fine ! The module is ready to be added to the list. */
1294     p_module->b_builtin = false;
1295
1296     return p_module;
1297 }
1298
1299 /*****************************************************************************
1300  * DupModule: make a plugin module standalone.
1301  *****************************************************************************
1302  * This function duplicates all strings in the module, so that the dynamic
1303  * object can be unloaded. It acts recursively on submodules.
1304  *****************************************************************************/
1305 static void DupModule( module_t *p_module )
1306 {
1307     char **pp_shortcut;
1308     int i_submodule;
1309
1310     for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
1311     {
1312         *pp_shortcut = strdup( *pp_shortcut );
1313     }
1314
1315     /* We strdup() these entries so that they are still valid when the
1316      * module is unloaded. */
1317     /* This one is a (const char *) that will never get freed. */
1318     p_module->psz_object_name = strdup( p_module->psz_object_name );
1319     p_module->psz_capability = strdup( p_module->psz_capability );
1320     p_module->psz_shortname = p_module->psz_shortname ?
1321                                  strdup( p_module->psz_shortname ) : NULL;
1322     p_module->psz_longname = strdup( p_module->psz_longname );
1323     p_module->psz_help = p_module->psz_help ? strdup( p_module->psz_help )
1324                                             : NULL;
1325
1326     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
1327     {
1328         DupModule( (module_t*)p_module->pp_children[ i_submodule ] );
1329     }
1330 }
1331
1332 /*****************************************************************************
1333  * UndupModule: free a duplicated module.
1334  *****************************************************************************
1335  * This function frees the allocations done in DupModule().
1336  *****************************************************************************/
1337 static void UndupModule( module_t *p_module )
1338 {
1339     char **pp_shortcut;
1340     int i_submodule;
1341
1342     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
1343     {
1344         UndupModule( (module_t*)p_module->pp_children[ i_submodule ] );
1345     }
1346
1347     for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
1348     {
1349         free( *pp_shortcut );
1350     }
1351
1352     free( p_module->psz_object_name );
1353     free( p_module->psz_capability );
1354     free( p_module->psz_shortname );
1355     free( p_module->psz_longname );
1356     free( p_module->psz_help );
1357 }
1358
1359 #endif /* HAVE_DYNAMIC_PLUGINS */
1360
1361 /*****************************************************************************
1362  * AllocateBuiltinModule: initialize a builtin module.
1363  *****************************************************************************
1364  * This function registers a builtin module and allocates a structure
1365  * for its information data. The module can then be handled by module_Need
1366  * and module_Unneed. It can be removed by DeleteModule.
1367  *****************************************************************************/
1368 static int AllocateBuiltinModule( vlc_object_t * p_this,
1369                                   int ( *pf_entry ) ( module_t * ) )
1370 {
1371     module_t * p_module;
1372
1373     /* Now that we have successfully loaded the module, we can
1374      * allocate a structure for it */
1375     p_module = vlc_module_create( p_this );
1376     if( p_module == NULL )
1377     {
1378         msg_Err( p_this, "out of memory" );
1379         return -1;
1380     }
1381
1382     /* Initialize the module : fill p_module->psz_object_name, etc. */
1383     if( pf_entry( p_module ) != 0 )
1384     {
1385         /* With a well-written module we shouldn't have to print an
1386          * additional error message here, but just make sure. */
1387         msg_Err( p_this, "failed calling entry point in builtin module" );
1388         vlc_object_release( p_module );
1389         return -1;
1390     }
1391
1392     /* Everything worked fine ! The module is ready to be added to the list. */
1393     p_module->b_builtin = true;
1394
1395     /* msg_Dbg( p_this, "builtin \"%s\", %s",
1396                 p_module->psz_object_name, p_module->psz_longname ); */
1397
1398     vlc_object_attach( p_module, vlc_global()->p_module_bank );
1399
1400     return 0;
1401 }
1402
1403 /*****************************************************************************
1404  * DeleteModule: delete a module and its structure.
1405  *****************************************************************************
1406  * This function can only be called if the module isn't being used.
1407  *****************************************************************************/
1408 static int DeleteModule( module_t * p_module, bool b_detach )
1409 {
1410     if( !p_module ) return VLC_EGENERIC;
1411     if( b_detach )
1412         vlc_object_detach( p_module );
1413
1414     /* We free the structures that we strdup()ed in Allocate*Module(). */
1415 #ifdef HAVE_DYNAMIC_PLUGINS
1416     if( !p_module->b_builtin )
1417     {
1418         if( p_module->b_loaded && p_module->b_unloadable )
1419         {
1420             module_Unload( p_module->handle );
1421         }
1422         UndupModule( p_module );
1423         free( p_module->psz_filename );
1424     }
1425 #endif
1426
1427     /* Free and detach the object's children */
1428     while( p_module->i_children )
1429     {
1430         vlc_object_t *p_this = p_module->pp_children[0];
1431         vlc_object_detach( p_this );
1432         vlc_object_release( p_this );
1433     }
1434
1435     config_Free( p_module );
1436     vlc_object_release( p_module );
1437     p_module = NULL;
1438     return 0;
1439 }