]> git.sesse.net Git - vlc/blobdiff - src/modules/modules.c
libvlc: use vlc_common.h (libvlccore) instead of vlc/vlc.h
[vlc] / src / modules / modules.c
index 0b6b26c16cec76d0e8e36952c02163605cb182a3..0e25c855c021cb87ab2b8d38cd763d631485cf47 100644 (file)
@@ -28,7 +28,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include "libvlc.h"
 
 /* Some faulty libcs have a broken struct dirent when _FILE_OFFSET_BITS
@@ -99,7 +100,7 @@ static int  AllocatePluginFile  ( vlc_object_t *, char *, int64_t, int64_t );
 static module_t * AllocatePlugin( vlc_object_t *, char * );
 #endif
 static int  AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
-static int  DeleteModule ( module_t *, bool );
+static void DeleteModule ( module_t *, bool );
 #ifdef HAVE_DYNAMIC_PLUGINS
 static void   DupModule        ( module_t * );
 static void   UndupModule      ( module_t * );
@@ -122,8 +123,8 @@ void __module_InitBank( vlc_object_t *p_this )
 
     if( p_libvlc_global->p_module_bank == NULL )
     {
-        p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
-        p_bank->psz_object_name = "module bank";
+        p_bank = vlc_custom_create( p_this, sizeof(module_bank_t),
+                                    VLC_OBJECT_GENERIC, "module bank");
         p_bank->i_usage = 1;
         p_bank->i_cache = p_bank->i_loaded_cache = 0;
         p_bank->pp_cache = p_bank->pp_loaded_cache = NULL;
@@ -213,20 +214,10 @@ void __module_EndBank( vlc_object_t *p_this )
 
     vlc_object_detach( p_libvlc_global->p_module_bank );
 
-    while( p_libvlc_global->p_module_bank->i_children )
+    while( vlc_internals( p_libvlc_global->p_module_bank )->i_children )
     {
-        p_next = (module_t *)p_libvlc_global->p_module_bank->pp_children[0];
-
-        if( DeleteModule( p_next, true ) )
-        {
-            /* Module deletion failed */
-            msg_Err( p_this, "module \"%s\" can't be removed, trying harder",
-                     p_next->psz_object_name );
-
-            /* We just free the module by hand. Niahahahahaha. */
-            vlc_object_detach( p_next );
-            vlc_object_release( p_next );
-        }
+        p_next = (module_t *)vlc_internals( p_libvlc_global->p_module_bank )->pp_children[0];
+        DeleteModule( p_next, true );
     }
 
     vlc_object_release( p_libvlc_global->p_module_bank );
@@ -646,7 +637,10 @@ found_shortcut:
         /* This assumes that p_this is the object which will be using the
          * module. That's not always the case ... but it is in most cases.
          */
-        p_this->psz_object_name = p_module->psz_object_name;
+        if( psz_alias )
+            p_this->psz_object_name = strdup( psz_alias );
+        else
+            p_this->psz_object_name = strdup( p_module->psz_object_name );
     }
 
     free( psz_shortcuts );
@@ -680,8 +674,6 @@ void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
     msg_Dbg( p_this, "removing module \"%s\"", p_module->psz_object_name );
 
     vlc_object_release( p_module );
-
-    return;
 }
 
 /**
@@ -911,37 +903,21 @@ static char * copy_next_paths_token( char * paths, char ** remaining_paths )
 #ifdef HAVE_DYNAMIC_PLUGINS
 static void AllocateAllPlugins( vlc_object_t *p_this )
 {
+    const char *vlcpath = vlc_global()->psz_vlcpath;
     int count,i;
     char * path;
     vlc_array_t *arraypaths = vlc_array_new();
 
     /* Contruct the special search path for system that have a relocatable
      * executable. Set it to <vlc path>/modules and <vlc path>/plugins. */
-#define RETURN_ENOMEM                               \
-    {                                               \
-        msg_Err( p_this, "Not enough memory" );     \
-        return;                                     \
-    }
 
-    vlc_array_append( arraypaths, strdup( "modules" ) );
-#if defined( WIN32 ) || defined( UNDER_CE ) || defined( __APPLE__ ) || defined( SYS_BEOS )
-    if( asprintf( &path, "%s" DIR_SEP "modules",
-        vlc_global()->psz_vlcpath ) < 0 )
-        RETURN_ENOMEM
-    vlc_array_append( arraypaths, path );
-    if( asprintf( &path, "%s" DIR_SEP "plugins",
-        vlc_global()->psz_vlcpath ) < 0 )
-        RETURN_ENOMEM
-    vlc_array_append( arraypaths, path );
-#if ! defined( WIN32 ) && ! defined( UNDER_CE )
-    if( asprintf( &path, "%s", PLUGIN_PATH ) < 0 )
-        RETURN_ENOMEM
-    vlc_array_append( arraypaths, path );
-#endif
-#else
+    if( vlcpath && asprintf( &path, "%s" DIR_SEP "modules", vlcpath ) != -1 )
+        vlc_array_append( arraypaths, path );
+    if( vlcpath && asprintf( &path, "%s" DIR_SEP "plugins", vlcpath ) != -1 )
+        vlc_array_append( arraypaths, path );
+#ifndef WIN32
     vlc_array_append( arraypaths, strdup( PLUGIN_PATH ) );
 #endif
-    vlc_array_append( arraypaths, strdup( "plugins" ) );
 
     /* If the user provided a plugin path, we add it to the list */
     char * userpaths = config_GetPsz( p_this, "plugin-path" );
@@ -950,9 +926,8 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
     for( paths_iter = userpaths; paths_iter; )
     {
         path = copy_next_paths_token( paths_iter, &paths_iter );
-        if( !path )
-            RETURN_ENOMEM
-        vlc_array_append( arraypaths, strdup( path ) );
+        if( path )
+            vlc_array_append( arraypaths, strdup( path ) );
     }
 
     count = vlc_array_count( arraypaths );
@@ -960,9 +935,7 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
     {
         path = vlc_array_item_at_index( arraypaths, i );
         if( !path )
-        {
             continue;
-        }
 
         msg_Dbg( p_this, "recursively browsing `%s'", path );
 
@@ -973,7 +946,6 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
     }
 
     vlc_array_destroy( arraypaths );
-#undef RETURN_ENOMEM
 }
 
 /*****************************************************************************
@@ -1311,8 +1283,6 @@ static void DupModule( module_t *p_module )
 
     /* We strdup() these entries so that they are still valid when the
      * module is unloaded. */
-    /* This one is a (const char *) that will never get freed. */
-    p_module->psz_object_name = strdup( p_module->psz_object_name );
     p_module->psz_capability = strdup( p_module->psz_capability );
     p_module->psz_shortname = p_module->psz_shortname ?
                                  strdup( p_module->psz_shortname ) : NULL;
@@ -1320,9 +1290,9 @@ static void DupModule( module_t *p_module )
     p_module->psz_help = p_module->psz_help ? strdup( p_module->psz_help )
                                             : NULL;
 
-    for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
+    for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ )
     {
-        DupModule( (module_t*)p_module->pp_children[ i_submodule ] );
+        DupModule( (module_t*)vlc_internals( p_module )->pp_children[ i_submodule ] );
     }
 }
 
@@ -1336,9 +1306,9 @@ static void UndupModule( module_t *p_module )
     char **pp_shortcut;
     int i_submodule;
 
-    for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
+    for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ )
     {
-        UndupModule( (module_t*)p_module->pp_children[ i_submodule ] );
+        UndupModule( (module_t*)vlc_internals( p_module )->pp_children[ i_submodule ] );
     }
 
     for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
@@ -1346,7 +1316,7 @@ static void UndupModule( module_t *p_module )
         free( *pp_shortcut );
     }
 
-    free( p_module->psz_object_name );
+    FREENULL( p_module->psz_object_name );
     free( p_module->psz_capability );
     free( p_module->psz_shortname );
     free( p_module->psz_longname );
@@ -1402,9 +1372,10 @@ static int AllocateBuiltinModule( vlc_object_t * p_this,
  *****************************************************************************
  * This function can only be called if the module isn't being used.
  *****************************************************************************/
-static int DeleteModule( module_t * p_module, bool b_detach )
+static void DeleteModule( module_t * p_module, bool b_detach )
 {
-    if( !p_module ) return VLC_EGENERIC;
+    assert( p_module );
+
     if( b_detach )
         vlc_object_detach( p_module );
 
@@ -1422,15 +1393,13 @@ static int DeleteModule( module_t * p_module, bool b_detach )
 #endif
 
     /* Free and detach the object's children */
-    while( p_module->i_children )
+    while( vlc_internals( p_module )->i_children )
     {
-        vlc_object_t *p_this = p_module->pp_children[0];
+        vlc_object_t *p_this = vlc_internals( p_module )->pp_children[0];
         vlc_object_detach( p_this );
         vlc_object_release( p_this );
     }
 
     config_Free( p_module );
     vlc_object_release( p_module );
-    p_module = NULL;
-    return 0;
 }