]> git.sesse.net Git - vlc/blob - src/misc/plugins.c
- �a compile sous FreeBSD (mais �a ne tourne pas)
[vlc] / src / misc / plugins.c
1 /*****************************************************************************
2  * plugins.c : Dynamic plugin management functions
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *****************************************************************************/
23
24 #include <stdlib.h>                                      /* free(), strtol() */
25 #include <stdio.h>                                              /* sprintf() */
26 #include <dlfcn.h>                           /* dlopen(), dlsym(), dlclose() */
27
28 #define PLUGIN_PATH_COUNT 5
29
30 void * RequestPlugin ( char * psz_mask, char * psz_name )
31 {
32     int i_count, i_length;
33     void * fd;
34     char * psz_plugin;
35     char * psz_plugin_path[ PLUGIN_PATH_COUNT ] =
36     {
37         ".",
38         PLUGIN_PATH,
39         /* these ones should disappear */
40         "./audio_output",
41         "./video_output",
42         "./interface"
43     };
44
45     i_length = strlen( psz_mask ) + strlen( psz_name );
46
47     for ( i_count = 0 ; i_count < PLUGIN_PATH_COUNT ; i_count++ )
48     {
49         psz_plugin = malloc( strlen(psz_plugin_path[i_count]) + i_length + 6 );
50         sprintf( psz_plugin, "%s/%s_%s.so", psz_plugin_path[i_count], psz_mask, psz_name );
51         fd = dlopen( psz_plugin, RTLD_NOW | RTLD_GLOBAL );
52         free( psz_plugin );
53
54         if( fd != NULL )
55             return( fd );
56     }
57
58     return( 0 );
59 }
60
61 void TrashPlugin ( void * p_plugin )
62 {
63     dlclose( p_plugin );
64 }
65
66 void *GetPluginFunction ( void *p_plugin, char *psz_name )
67 {
68     return( dlsym(p_plugin, psz_name) );
69 }
70