]> git.sesse.net Git - vlc/blobdiff - src/misc/modules.c
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / src / misc / modules.c
index 47a6a506da4827fabd2e7404cce5a51e0a364d2f..307ea544345f3fb8e7271232c8019a69f06edc9a 100644 (file)
 
 #include "config.h"
 
+/* Some faulty libcs have a broken struct dirent when _FILE_OFFSET_BITS
+ * is set to 64. Don't try to be cleverer. */
+#ifdef _FILE_OFFSET_BITS
+#undef _FILE_OFFSET_BITS
+#endif
+
 #include <stdlib.h>                                      /* free(), strtol() */
 #include <stdio.h>                                              /* sprintf() */
 #include <string.h>                                              /* strdup() */
@@ -81,13 +87,15 @@ module_bank_t * module_CreateBank( void )
  *****************************************************************************/
 void module_InitBank( module_bank_t * p_bank )
 {
-    static char * path[] = { ".", "lib", PLUGIN_PATH, NULL } ;
+    static char * path[] = { ".", "lib", PLUGIN_PATH, NULL };
 
     char **         ppsz_path = path;
+    char *          psz_fullpath;
     char *          psz_file;
 #ifdef SYS_BEOS
-    char *          psz_program_path = beos_GetProgramPath();
-    int             i_programlen = strlen( psz_program_path );
+    char *          psz_vlcpath = beos_GetProgramPath();
+    int             i_vlclen = strlen( psz_vlcpath );
+    boolean_t       b_notinroot;
 #endif
     DIR *           dir;
     struct dirent * file;
@@ -95,15 +103,39 @@ void module_InitBank( module_bank_t * p_bank )
     p_bank->first = NULL;
     vlc_mutex_init( &p_bank->lock );
 
-    intf_Msg( "module: module bank initialized" );
+    intf_WarnMsg( 1, "module: module bank initialized" );
 
     for( ; *ppsz_path != NULL ; ppsz_path++ )
     {
-        if( (dir = opendir( *ppsz_path )) )
+        /* Store strlen(*ppsz_path) for later use. */
+        int i_dirlen = strlen( *ppsz_path );
+
+#ifdef SYS_BEOS
+        b_notinroot = 0;
+        /* Under BeOS, we need to add beos_GetProgramPath() to access
+         * files under the current directory */
+        if( ( i_dirlen > 1 ) && strncmp( *ppsz_path, "/", 1 ) )
+        {
+            i_dirlen += i_vlclen + 2;
+            b_notinroot = 1;
+
+            psz_fullpath = malloc( i_dirlen );
+            if( psz_fullpath == NULL )
+            {
+                continue;
+            }
+            sprintf( psz_fullpath, "%s/%s", psz_vlcpath, *ppsz_path );
+        }
+        else
+#endif
         {
-            /* Store strlen(*ppsz_path) for later use. */
-            int i_dirlen = strlen( *ppsz_path );
+            psz_fullpath = *ppsz_path;
+        }
 
+        intf_WarnMsgImm( 2, "module: browsing %s", psz_fullpath );
+
+        if( (dir = opendir( psz_fullpath )) )
+        {
             /* Parse the directory and try to load all files it contains. */
             while( (file = readdir( dir )) )
             {
@@ -113,30 +145,13 @@ void module_InitBank( module_bank_t * p_bank )
                 if( i_filelen > 3
                         && !strncmp( file->d_name + i_filelen - 3, ".so", 3 ) )
                 {
-#ifdef SYS_BEOS
-                    /* Under BeOS, we need to add beos_GetProgramPath() to
-                     * access files under the current directory */
-                    if( strncmp( file->d_name, "/", 1 ) )
+                    psz_file = malloc( i_dirlen + i_filelen + 2 );
+                    if( psz_file == NULL )
                     {
-                        psz_file = malloc( i_programlen + i_dirlen
-                                               + i_filelen + 3 );
-                        if( psz_file == NULL )
-                        {
-                            continue;
-                        }
-                        sprintf( psz_file, "%s/%s/%s", psz_programlen,
-                                 *ppsz_path, file->d_name );
-                    }
-                    else
-#endif
-                    {
-                        psz_file = malloc( i_dirlen + i_filelen + 2 );
-                        if( psz_file == NULL )
-                        {
-                            continue;
-                        }
-                        sprintf( psz_file, "%s/%s", *ppsz_path, file->d_name );
+                        continue;
                     }
+                    sprintf( psz_file, "%s/%s", psz_fullpath, file->d_name );
+
                     /* We created a nice filename -- now we just try to load
                      * it as a dynamic module. */
                     AllocateDynModule( p_bank, psz_file );
@@ -145,7 +160,17 @@ void module_InitBank( module_bank_t * p_bank )
                     free( psz_file );
                 }
             }
+
+            /* Close the directory if successfully opened */
+            closedir( dir );
         }
+
+#ifdef SYS_BEOS
+        if( b_notinroot )
+        {
+            free( psz_fullpath );
+        }
+#endif
     }
 
     return;
@@ -224,8 +249,8 @@ void module_ManageBank( module_bank_t * p_bank )
             }
             else
             {
-                intf_Msg( "module: hiding unused module `%s'",
-                          p_module->psz_name );
+                intf_WarnMsg( 1, "module: hiding unused module `%s'",
+                              p_module->psz_name );
                 HideModule( p_module );
             }
         }
@@ -308,7 +333,11 @@ module_t * module_Need( module_bank_t *p_bank,
     /* We release the global lock */
     vlc_mutex_unlock( &p_bank->lock );
 
-    intf_Msg( "module: locking module `%s'", p_bestmodule->psz_name );
+    if( p_bestmodule != NULL )
+    {
+        intf_WarnMsg( 1, "module: locking module `%s'",
+                      p_bestmodule->psz_name );
+    }
 
     /* Don't forget that the module is still locked if bestmodule != NULL */
     return( p_bestmodule );
@@ -329,7 +358,7 @@ void module_Unneed( module_bank_t * p_bank, module_t * p_module )
      * so there is no need to check the return value. */
     UnlockModule( p_module );
 
-    intf_Msg( "module: unlocking module `%s'", p_module->psz_name );
+    intf_WarnMsg( 1, "module: unlocking module `%s'", p_module->psz_name );
 
     /* We release the global lock */
     vlc_mutex_unlock( &p_bank->lock );
@@ -357,8 +386,8 @@ static int AllocateDynModule( module_bank_t * p_bank, char * psz_filename )
     if( module_load( psz_filename, &handle ) )
     {
         /* The dynamic module couldn't be opened */
-        intf_DbgMsg( "module warning: cannot open %s (%s)",
-                     psz_filename, module_error() );
+        intf_WarnMsgImm( 1, "module warning: cannot open %s (%s)",
+                         psz_filename, module_error() );
         return( -1 );
     }
 
@@ -451,8 +480,9 @@ static int AllocateDynModule( module_bank_t * p_bank, char * psz_filename )
     p_module->prev = NULL;
     p_bank->first = p_module;
 
-    intf_Msg( "module: dynamic module `%s', %s",
-              p_module->psz_name, p_module->psz_longname );
+    /* Immediate message so that a slow module doesn't make the user wait */
+    intf_WarnMsgImm( 1, "module: dynamic module `%s', %s",
+                     p_module->psz_name, p_module->psz_longname );
 
     return( 0 );
 }
@@ -676,8 +706,9 @@ static int CallSymbol( module_t * p_module, char * psz_name )
     if( !p_symbol )
     {
         /* We couldn't load the symbol */
-        intf_DbgMsg( "module warning: cannot find symbol %s in module %s (%s)",
-                     psz_name, p_module->psz_filename, module_error() );
+        intf_WarnMsg( 1, "module warning: "
+                         "cannot find symbol %s in module %s (%s)",
+                         psz_name, p_module->psz_filename, module_error() );
         return( -1 );
     }