]> git.sesse.net Git - vlc/blobdiff - src/modules/modules.c
vlc_modules_macros.h -> vlc_plugin.h
[vlc] / src / modules / modules.c
index 94061803195f03aa120e4cfb7772c66fff1ffcde..01fe63cb960bcd896de7efa064cb19ea25647100 100644 (file)
@@ -29,6 +29,7 @@
 #endif
 
 #include <vlc/vlc.h>
+#include <vlc_plugin.h>
 #include "libvlc.h"
 
 /* Some faulty libcs have a broken struct dirent when _FILE_OFFSET_BITS
@@ -84,6 +85,7 @@
 #include "config/configuration.h"
 
 #include "vlc_charset.h"
+#include "vlc_arrays.h"
 
 #include "modules/modules.h"
 #include "modules/builtin.h"
@@ -122,7 +124,7 @@ 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->psz_object_name = strdup( "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;
@@ -354,6 +356,8 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
 {
     typedef struct module_list_t module_list_t;
 
+    stats_TimerStart( p_this, "module_Need()", STATS_TIMER_MODULE_NEED );
+
     struct module_list_t
     {
         module_t *p_module;
@@ -393,6 +397,9 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
         if( !strcmp( psz_name, "none" ) )
         {
             free( psz_var );
+            stats_TimerStop( p_this, STATS_TIMER_MODULE_NEED );
+            stats_TimerDump( p_this, STATS_TIMER_MODULE_NEED );
+            stats_TimerClean( p_this, STATS_TIMER_MODULE_NEED );
             return NULL;
         }
 
@@ -640,12 +647,19 @@ 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 );
     free( psz_var );
 
+    stats_TimerStop( p_this, STATS_TIMER_MODULE_NEED );
+    stats_TimerDump( p_this, STATS_TIMER_MODULE_NEED );
+    stats_TimerClean( p_this, STATS_TIMER_MODULE_NEED );
+
     /* Don't forget that the module is still locked */
     return p_module;
 }
@@ -670,8 +684,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;
 }
 
 /**
@@ -862,7 +874,7 @@ void module_PutConfig( module_config_t *config )
 static char * copy_next_paths_token( char * paths, char ** remaining_paths )
 {
     char * path;
-    int i;
+    int i, done;
     bool escaped = false;
 
     assert( paths );
@@ -872,20 +884,20 @@ static char * copy_next_paths_token( char * paths, char ** remaining_paths )
     if( !path ) return NULL;
 
     /* Look for PATH_SEP_CHAR (a ':' or a ';') */
-    for( i = 0; paths[i]; i++ ) {
+    for( i = 0, done = 0 ; paths[i]; i++ ) {
         /* Take care of \\ and \: or \; escapement */
         if( escaped ) {
             escaped = false;
-            path[i] = paths[i];
+            path[done++] = paths[i];
         }
         else if( paths[i] == '\\' )
             escaped = true;
         else if( paths[i] == PATH_SEP_CHAR )
             break;
         else
-            path[i] = paths[i];
+            path[done++] = paths[i];
     }
-    path[i] = 0;
+    path[done++] = 0;
 
     /* Return the remaining paths */
     if( remaining_paths ) {
@@ -901,59 +913,57 @@ static char * copy_next_paths_token( char * paths, char ** remaining_paths )
 #ifdef HAVE_DYNAMIC_PLUGINS
 static void AllocateAllPlugins( vlc_object_t *p_this )
 {
-    char *paths, *path, *paths_iter;
-    char * extra_path;
+    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. */
-#if defined( WIN32 ) || defined( UNDER_CE ) || defined( __APPLE__ ) || defined( SYS_BEOS )
-    if( asprintf( &extra_path,
-                    "%s" DIR_SEP "modules" PATH_SEP
-                    "%s" DIR_SEP "plugins"
-                    "%s",
-                    vlc_global()->psz_vlcpath,
-                    vlc_global()->psz_vlcpath,
-# if defined( WIN32 ) || defined( UNDER_CE )
-                    "" ) < 0 )
-# else
-                    PATH_SEP PLUGIN_PATH ) < 0 )
-# endif
-
-    {
-        msg_Err( p_this, "Not enough memory" );
-        return;
+#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
-    extra_path = strdup( PLUGIN_PATH );
+    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" );
+    char *paths_iter;
 
-    if( asprintf( &paths, "modules" PATH_SEP "%s" PATH_SEP "plugins%s%s",
-                    extra_path,
-                    userpaths ? PATH_SEP : "",
-                    userpaths ? userpaths : "" ) < 0 )
+    for( paths_iter = userpaths; paths_iter; )
     {
-        msg_Err( p_this, "Not enough memory" );
-        free( userpaths );
-        free( extra_path );
-        return;
+        path = copy_next_paths_token( paths_iter, &paths_iter );
+        if( !path )
+            RETURN_ENOMEM
+        vlc_array_append( arraypaths, strdup( path ) );
     }
 
-    /* Free plugin-path and extra path */
-    free( userpaths );
-    free( extra_path );
-
-    msg_Dbg( p_this, "We will be looking for modules in `%s'", paths );
-
-    for( paths_iter = paths; paths_iter; )
+    count = vlc_array_count( arraypaths );
+    for( i = 0 ; i < count ; i++ )
     {
-        path = copy_next_paths_token( paths_iter, &paths_iter );
+        path = vlc_array_item_at_index( arraypaths, i );
         if( !path )
         {
-            msg_Err( p_this, "Not enough memory" );
-            return;
+            continue;
         }
 
         msg_Dbg( p_this, "recursively browsing `%s'", path );
@@ -964,7 +974,8 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
         free( path );
     }
 
-    free( paths );
+    vlc_array_destroy( arraypaths );
+#undef RETURN_ENOMEM
 }
 
 /*****************************************************************************
@@ -1292,7 +1303,7 @@ static module_t * AllocatePlugin( vlc_object_t * p_this, char * psz_file )
  *****************************************************************************/
 static void DupModule( module_t *p_module )
 {
-    const char **pp_shortcut;
+    char **pp_shortcut;
     int i_submodule;
 
     for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
@@ -1302,7 +1313,6 @@ static void DupModule( module_t *p_module )
 
     /* We strdup() these entries so that they are still valid when the
      * module is unloaded. */
-    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;
@@ -1323,7 +1333,7 @@ static void DupModule( module_t *p_module )
  *****************************************************************************/
 static void UndupModule( module_t *p_module )
 {
-    const char **pp_shortcut;
+    char **pp_shortcut;
     int i_submodule;
 
     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
@@ -1333,14 +1343,14 @@ static void UndupModule( module_t *p_module )
 
     for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
     {
-        free( (void*)*pp_shortcut );
+        free( *pp_shortcut );
     }
 
-    free( (void*)p_module->psz_object_name );
+    FREENULL( p_module->psz_object_name );
     free( p_module->psz_capability );
-    free( (void*)p_module->psz_shortname );
-    free( (void*)p_module->psz_longname );
-    free( (void*)p_module->psz_help );
+    free( p_module->psz_shortname );
+    free( p_module->psz_longname );
+    free( p_module->psz_help );
 }
 
 #endif /* HAVE_DYNAMIC_PLUGINS */