]> git.sesse.net Git - vlc/blobdiff - src/modules/modules.c
Removes trailing spaces. Removes tabs.
[vlc] / src / modules / modules.c
index a31840f7e38c06b0fc05fa1f5b482409c2dfead6..ec3b393b6badab1373d9963581fc7651cc8a5686 100644 (file)
@@ -25,6 +25,7 @@
  *****************************************************************************/
 
 #include <vlc/vlc.h>
+#include "../libvlc.h"
 
 /* Some faulty libcs have a broken struct dirent when _FILE_OFFSET_BITS
  * is set to 64. Don't try to be cleverer. */
 #include "modules/configuration.h"
 #include "libvlc.h"
 
-#include "vlc_interface.h"
-#include "vlc_playlist.h"
-
-#include "vlc_stream.h"
-#include "vlc_access.h"
-#include "vlc_demux.h"
-
-#include "vlc_vout.h"
-#include "vlc_vout_synchro.h"
-
-#include "vlc_aout.h"
-
-#include "vlc_sout.h"
-#include "vlc_httpd.h"
-#include "vlc_acl.h"
-#include "vlc_tls.h"
-#include "vlc_md5.h"
-#include "vlc_xml.h"
-#include "vlc_url.h"
-
-#include "iso_lang.h"
 #include "vlc_charset.h"
 
-#include "vlc_block.h"
-
-#include "vlc_vlm.h"
-
-#include "vlc_image.h"
-#include "vlc_osd.h"
-
-#include "vlc_update.h"
-#include "vlc_strings.h"
-#include "vlc_streaming.h"
-
 #include "modules/modules.h"
 #include "modules/builtin.h"
 
-#include "vlc_network.h"
-
 #if defined( WIN32 ) || defined( UNDER_CE )
     /* Avoid name collisions */
 #   define LoadModule(a,b,c) LoadVlcModule(a,b,c)
@@ -169,7 +136,7 @@ void __module_InitBank( vlc_object_t *p_this )
 {
     module_bank_t *p_bank = NULL;
     vlc_value_t  lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -194,13 +161,6 @@ void __module_InitBank( vlc_object_t *p_this )
     p_bank->b_cache = p_bank->b_cache_dirty =
         p_bank->b_cache_delete = VLC_FALSE;
 
-    /*
-     * Store the symbols to be exported
-     */
-#if defined (HAVE_DYNAMIC_PLUGINS) && !defined (HAVE_SHARED_LIBVLC)
-    STORE_SYMBOLS( &p_bank->symbols );
-#endif
-
     /* Everything worked, attach the object */
     p_libvlc_global->p_module_bank = p_bank;
     vlc_object_attach( p_bank, p_libvlc_global );
@@ -219,7 +179,7 @@ void __module_EndBank( vlc_object_t *p_this )
 {
     module_t * p_next = NULL;
     vlc_value_t lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -307,7 +267,7 @@ void __module_EndBank( vlc_object_t *p_this )
 static void module_LoadMain( vlc_object_t *p_this )
 {
     vlc_value_t lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -333,7 +293,7 @@ static void module_LoadMain( vlc_object_t *p_this )
 void __module_LoadBuiltins( vlc_object_t * p_this )
 {
     vlc_value_t lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -361,7 +321,7 @@ void __module_LoadPlugins( vlc_object_t * p_this )
 {
 #ifdef HAVE_DYNAMIC_PLUGINS
     vlc_value_t lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -388,6 +348,38 @@ void __module_LoadPlugins( vlc_object_t * p_this )
 #endif
 }
 
+/*****************************************************************************
+ * module_IsCapable: checks whether a module implements a capability.
+ *****************************************************************************/
+vlc_bool_t module_IsCapable( const module_t *m, const char *cap )
+{
+    return !strcmp( m->psz_capability, cap );
+}
+
+/*****************************************************************************
+ * module_GetObjName: internal name of a module.
+ *****************************************************************************/
+const char *module_GetObjName( const module_t *m )
+{
+    return m->psz_object_name;
+}
+
+/*****************************************************************************
+ * module_GetName: human-friendly name of a module.
+ *****************************************************************************/
+const char *module_GetName( const module_t *m, vlc_bool_t long_name )
+{
+    if( long_name && ( m->psz_longname != NULL) )
+        return m->psz_longname;
+    return m->psz_shortname ?: m->psz_object_name;
+}
+
+const char *module_GetHelp( const module_t *m )
+{
+    return m->psz_help;
+}
+
 /*****************************************************************************
  * module_Need: return the best module function, given a capability list.
  *****************************************************************************
@@ -484,7 +476,7 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
         p_module = (module_t *)p_all->p_values[i_which_module].p_object;
 
         /* Test that this module can do what we need */
-        if( strcmp( p_module->psz_capability, psz_capability ) )
+        if( !module_IsCapable( p_module, psz_capability ) )
         {
             /* Don't recurse through the sub-modules because vlc_list_find()
              * will list them anyway. */
@@ -739,27 +731,82 @@ void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
 }
 
 /*****************************************************************************
- * module_Exists: tell if a module exists.
- *****************************************************************************
- * This function is a boolean function that tells if a module exist or not.
+ * module_FindName: get a pointer to a module_t given it's name.
  *****************************************************************************/
-
-vlc_bool_t __module_Exists(  vlc_object_t *p_this, const char * psz_name )
+module_t *__module_FindName( vlc_object_t *p_this, const char * psz_name )
 {
     vlc_list_t *p_list;
     int i;
     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
     for( i = 0 ; i < p_list->i_count; i++)
     {
-        const char *psz_module_name =
-            ((module_t *) p_list->p_values[i].p_object)->psz_shortname;
+        module_t *p_module = ((module_t *) p_list->p_values[i].p_object);
+        const char *psz_module_name = p_module->psz_object_name;
         if( psz_module_name && !strcmp( psz_module_name, psz_name ) )
         {
             /* We can release the list, and return yes */
-            vlc_list_release( p_list ); return VLC_TRUE;
+            vlc_object_yield( p_module );
+            vlc_list_release( p_list );
+            return p_module;
         }
     }
-    vlc_list_release( p_list ); return VLC_FALSE;
+    vlc_list_release( p_list );
+    return NULL;
+}
+
+/*****************************************************************************
+ * module_Exists: tell if a module exists.
+ *****************************************************************************
+ * This function is a boolean function that tells if a module exist or not.
+ *****************************************************************************/
+vlc_bool_t __module_Exists(  vlc_object_t *p_this, const char * psz_name )
+{
+    module_t *p_module = __module_FindName( p_this, psz_name );
+    if( p_module )
+    {
+        vlc_object_release( p_module );
+        return VLC_TRUE;
+    }
+    else
+    {
+        return VLC_FALSE;
+    }
+}
+
+/*****************************************************************************
+ * module_GetModuleNamesForCapability: Return a NULL terminated array with the
+ * names of the modules that have a certain capability.
+ * Free after uses both the string and the table.
+ *****************************************************************************/
+char ** __module_GetModulesNamesForCapability( vlc_object_t *p_this,
+                                               const char * psz_capability )
+{
+    vlc_list_t *p_list;
+    int i, count = 0;
+    char ** psz_ret;
+
+    /* Do it in two passes */
+    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    for( i = 0 ; i < p_list->i_count; i++)
+    {
+        module_t *p_module = ((module_t *) p_list->p_values[i].p_object);
+        const char *psz_module_capability = p_module->psz_capability;
+        if( psz_module_capability && !strcmp( psz_module_capability, psz_capability ) )
+            count++;
+    }
+    psz_ret = malloc( sizeof(char**) * (count+1) );
+    for( i = 0 ; i < p_list->i_count; i++)
+    {
+        module_t *p_module = ((module_t *) p_list->p_values[i].p_object);
+        const char *psz_module_capability = p_module->psz_capability;
+        if( psz_module_capability && !strcmp( psz_module_capability, psz_capability ) )
+            psz_ret[i] = strdup( p_module->psz_object_name );
+    }
+    psz_ret[count] = NULL;
+
+    vlc_list_release( p_list );
+    return psz_ret;
 }
 
 
@@ -803,7 +850,7 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
 #endif
         {
             if( 0>= asprintf( &psz_fullpath, "%s"DIR_SEP"%s",
-                              vlc_global( p_this )->psz_vlcpath, *ppsz_path) )
+                              vlc_global()->psz_vlcpath, *ppsz_path) )
                 psz_fullpath = NULL;
         }
         else
@@ -1065,7 +1112,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
 
     if( p_module )
     {
-        libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+        libvlc_global_data_t *p_libvlc_global = vlc_global();
 
         /* Everything worked fine !
          * The module is ready to be added to the list. */
@@ -1204,7 +1251,7 @@ static void UndupModule( module_t *p_module )
     }
 
     free( (void*)p_module->psz_object_name );
-    free( (void*)p_module->psz_capability );
+    free( p_module->psz_capability );
     free( (void*)p_module->psz_shortname );
     free( (void*)p_module->psz_longname );
     free( (void*)p_module->psz_help );
@@ -1250,7 +1297,7 @@ static int AllocateBuiltinModule( vlc_object_t * p_this,
     /* msg_Dbg( p_this, "builtin \"%s\", %s",
                 p_module->psz_object_name, p_module->psz_longname ); */
 
-    vlc_object_attach( p_module, vlc_global( p_this )->p_module_bank );
+    vlc_object_attach( p_module, vlc_global()->p_module_bank );
 
     return 0;
 }
@@ -1618,7 +1665,7 @@ static char * GetWindowsError( void )
  *****************************************************************************/
 static void CacheLoad( vlc_object_t *p_this )
 {
-    char *psz_filename, *psz_homedir;
+    char *psz_filename, *psz_cachedir;
     FILE *file;
     int i, j, i_size, i_read;
     char p_cachestring[sizeof(PLUGINSCACHE_DIR COPYRIGHT_MESSAGE)];
@@ -1626,17 +1673,17 @@ static void CacheLoad( vlc_object_t *p_this )
     int i_cache;
     module_cache_t **pp_cache = 0;
     int32_t i_file_size, i_marker;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    psz_homedir = p_this->p_libvlc->psz_homedir;
-    if( !psz_homedir )
+    psz_cachedir = p_this->p_libvlc->psz_cachedir;
+    if( !psz_cachedir ) /* XXX: this should never happen */
     {
-        msg_Err( p_this, "psz_homedir is null" );
+        msg_Err( p_this, "Unable to get cache directory" );
         return;
     }
 
-    i_size = asprintf( &psz_filename, "%s/%s/%s/%s", psz_homedir, CONFIG_DIR,
-                       PLUGINSCACHE_DIR, CacheName() );
+    i_size = asprintf( &psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s",
+            psz_cachedir, PLUGINSCACHE_DIR, CacheName() );
     if( i_size <= 0 )
     {
         msg_Err( p_this, "out of memory" );
@@ -1975,22 +2022,23 @@ static void CacheSave( vlc_object_t *p_this )
         "# For information about cache directory tags, see:\r\n"
         "#   http://www.brynosaurus.com/cachedir/\r\n";
 
-    char *psz_filename, *psz_homedir;
+    char *psz_filename, *psz_cachedir;
     FILE *file;
     int i, j, i_cache;
     module_cache_t **pp_cache;
     int32_t i_file_size = 0;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    psz_homedir = p_this->p_libvlc->psz_homedir;
-    if( !psz_homedir )
+    psz_cachedir = p_this->p_libvlc->psz_cachedir;
+    if( !psz_cachedir ) /* XXX: this should never happen */
     {
-        msg_Err( p_this, "psz_homedir is null" );
+        msg_Err( p_this, "Unable to get cache directory" );
         return;
     }
+
     psz_filename =
-       (char *)malloc( sizeof("/" CONFIG_DIR "/" PLUGINSCACHE_DIR "/" ) +
-                       strlen(psz_homedir) + strlen(CacheName()) );
+       (char *)malloc( sizeof(DIR_SEP PLUGINSCACHE_DIR DIR_SEP ) +
+                       strlen(psz_cachedir) + strlen(CacheName()) );
 
     if( !psz_filename )
     {
@@ -1998,15 +2046,15 @@ static void CacheSave( vlc_object_t *p_this )
         return;
     }
 
-    sprintf( psz_filename, "%s/%s", psz_homedir, CONFIG_DIR );
+    sprintf( psz_filename, "%s", psz_cachedir );
 
     config_CreateDir( p_this, psz_filename );
 
-    strcat( psz_filename, "/" PLUGINSCACHE_DIR );
+    strcat( psz_filename, DIR_SEP PLUGINSCACHE_DIR );
 
     config_CreateDir( p_this, psz_filename );
 
-    strcat( psz_filename, "/CACHEDIR.TAG" );
+    strcat( psz_filename, DIR_SEP"CACHEDIR.TAG" );
 
     file = utf8_fopen( psz_filename, "wb" );
     if( file )
@@ -2015,7 +2063,7 @@ static void CacheSave( vlc_object_t *p_this )
         fclose( file );
     }
 
-    sprintf( psz_filename, "%s/%s/%s/%s", psz_homedir, CONFIG_DIR,
+    sprintf( psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s", psz_cachedir,
              PLUGINSCACHE_DIR, CacheName() );
 
     msg_Dbg( p_this, "saving plugins cache file %s", psz_filename );
@@ -2205,9 +2253,6 @@ static void CacheMerge( vlc_object_t *p_this, module_t *p_cache,
 
     p_cache->pf_activate = p_module->pf_activate;
     p_cache->pf_deactivate = p_module->pf_deactivate;
-#ifndef HAVE_SHARED_LIBVLC
-    p_cache->p_symbols = p_module->p_symbols;
-#endif
     p_cache->handle = p_module->handle;
 
     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
@@ -2216,9 +2261,6 @@ static void CacheMerge( vlc_object_t *p_this, module_t *p_cache,
         module_t *p_cchild = (module_t*)p_cache->pp_children[i_submodule];
         p_cchild->pf_activate = p_child->pf_activate;
         p_cchild->pf_deactivate = p_child->pf_deactivate;
-#ifndef HAVE_SHARED_LIBVLC
-        p_cchild->p_symbols = p_child->p_symbols;
-#endif
     }
 
     p_cache->b_loaded = VLC_TRUE;
@@ -2233,7 +2275,7 @@ static module_cache_t *CacheFind( vlc_object_t *p_this, char *psz_file,
 {
     module_cache_t **pp_cache;
     int i_cache, i;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     pp_cache = p_libvlc_global->p_module_bank->pp_loaded_cache;
     i_cache = p_libvlc_global->p_module_bank->i_loaded_cache;