]> git.sesse.net Git - vlc/blobdiff - src/modules/modules.c
Removes trailing spaces. Removes tabs.
[vlc] / src / modules / modules.c
index fdf123683371be952f0d51c70fcf6461585e64c9..ec3b393b6badab1373d9963581fc7651cc8a5686 100644 (file)
 #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_codec.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)
@@ -171,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 );
@@ -214,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 );
@@ -302,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 );
@@ -328,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 );
@@ -356,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 );
@@ -391,6 +356,30 @@ 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.
  *****************************************************************************
@@ -742,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;
 }
 
 
@@ -806,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
@@ -1068,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. */
@@ -1253,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;
 }
@@ -1621,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)];
@@ -1629,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" );
@@ -1978,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 )
     {
@@ -2001,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 )
@@ -2018,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 );
@@ -2230,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;