]> git.sesse.net Git - vlc/blob - src/misc/plugins.c
Bon. On ne rit pas, je m'�tais juste plant� dans l'en-t�te des
[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
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22 #include "defs.h"
23
24 #include <stdlib.h>                                      /* free(), strtol() */
25 #include <stdio.h>                                              /* sprintf() */
26
27 #if defined(HAVE_DLFCN_H)                                /* Linux, BSD, Hurd */
28 #include <dlfcn.h>                           /* dlopen(), dlsym(), dlclose() */
29
30 #elif defined(HAVE_IMAGE_H)                                          /* BeOS */
31 #include <image.h>
32
33 #else
34 #error no dynamic plugins available on your system !
35 #endif
36
37 #ifdef SYS_BEOS
38 #include "beos_specific.h"
39 #endif
40
41 #include "plugins.h"
42
43 #define PLUGIN_PATH_COUNT 5
44
45 int RequestPlugin ( plugin_id_t * p_plugin, char * psz_mask, char * psz_name )
46 {
47     int i_count, i_length;
48     char * psz_plugin;
49     char * psz_plugin_path[ PLUGIN_PATH_COUNT ] =
50     {
51         ".",
52         "plugins/aout", "plugins/vout", "plugins/intf", /* these ones should disappear */
53         PLUGIN_PATH
54     };
55
56     i_length = strlen( psz_mask ) + strlen( psz_name );
57
58     for ( i_count = 0 ; i_count < PLUGIN_PATH_COUNT ; i_count++ )
59     {
60 #ifdef SYS_BEOS
61         char * psz_program_path;
62         
63         psz_program_path = beos_GetProgramPath();
64         psz_plugin = malloc( strlen(psz_plugin_path[i_count]) + strlen(psz_program_path) + i_length + 6 );
65         sprintf( psz_plugin, "%s/%s/%s_%s.so", psz_program_path, psz_plugin_path[i_count], psz_mask, psz_name );        
66 #else
67         psz_plugin = malloc( strlen(psz_plugin_path[i_count]) + i_length + 6 );
68         sprintf( psz_plugin, "%s/%s_%s.so", psz_plugin_path[i_count], psz_mask, psz_name );
69 #endif
70
71 #if defined(HAVE_DLFCN_H)
72         *p_plugin = dlopen( psz_plugin, RTLD_NOW | RTLD_GLOBAL );
73 #elif defined(HAVE_IMAGE_H)
74         *p_plugin = load_add_on( psz_plugin );
75 #endif
76
77         free( psz_plugin );
78
79 #if defined(HAVE_DLFCN_H)
80         if( *p_plugin != NULL )
81             return( 0 );
82 #elif defined(HAVE_IMAGE_H)
83         if( *p_plugin >= 0 )
84             return( 0 );
85 #endif
86     }
87
88     return( -1 );
89 }
90
91 void TrashPlugin ( plugin_id_t plugin )
92 {
93 #if defined(HAVE_DLFCN_H)
94     dlclose( plugin );
95 #elif defined(HAVE_IMAGE_H)
96     unload_add_on( plugin );
97 #endif
98 }
99
100 void * GetPluginFunction ( plugin_id_t plugin, char *psz_name )
101 {
102 #if defined(HAVE_DLFCN_H)
103     return( dlsym(plugin, psz_name) );
104 #elif defined(HAVE_IMAGE_H)
105     void * p_func;   
106     if( get_image_symbol( plugin, psz_name, B_SYMBOL_TYPE_TEXT, &p_func ) )
107         return( NULL );
108     else
109         return( p_func );    
110 #endif
111 }
112