]> git.sesse.net Git - vlc/blobdiff - src/modules/bank.c
network: remove no-op continue
[vlc] / src / modules / bank.c
index 5d99a6e76100291da78e9f1eeaad0732d81fd83e..6655f006656adf205b37d4a5888bbacff5a7692d 100644 (file)
@@ -35,9 +35,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#ifdef HAVE_UNISTD_H
-#   include <unistd.h>
-#endif
+#include <unistd.h>
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
@@ -104,16 +102,14 @@ void module_InitBank (void)
 
     if (modules.usage == 0)
     {
-        /* Fills the module bank structure with the main module infos.
-         * This is very useful as it will allow us to consider the main
+        /* Fills the module bank structure with the core module infos.
+         * This is very useful as it will allow us to consider the core
          * library just as another module, and for instance the configuration
-         * options of main will be available in the module bank structure just
+         * options of core will be available in the module bank structure just
          * as for every other module. */
-        module_t *module = module_InitStatic (vlc_entry__main);
+        module_t *module = module_InitStatic (vlc_entry__core);
         if (likely(module != NULL))
             module_StoreBank (module);
-
-        module_InitStaticModules();
         config_SortConfig ();
     }
     modules.usage++;
@@ -121,7 +117,7 @@ void module_InitBank (void)
     /* We do retain the module bank lock until the plugins are loaded as well.
      * This is ugly, this staged loading approach is needed: LibVLC gets
      * some configuration parameters relevant to loading the plugins from
-     * the main (builtin) module. The module bank becomes shared read-only data
+     * the core (builtin) module. The module bank becomes shared read-only data
      * once it is ready, so we need to fully serialize initialization.
      * DO NOT UNCOMMENT the following line unless you managed to squeeze
      * module_LoadPlugins() before you unlock the mutex. */
@@ -180,15 +176,16 @@ size_t module_LoadPlugins (vlc_object_t *obj)
 {
     /*vlc_assert_locked (&modules.lock); not for static mutexes :( */
 
-#ifdef HAVE_DYNAMIC_PLUGINS
     if (modules.usage == 1)
     {
+        module_InitStaticModules ();
+#ifdef HAVE_DYNAMIC_PLUGINS
         msg_Dbg (obj, "searching plug-in modules");
         AllocateAllPlugins (obj);
+#endif
         config_UnsortConfig ();
         config_SortConfig ();
     }
-#endif
     vlc_mutex_unlock (&modules.lock);
 
     size_t count;
@@ -217,8 +214,6 @@ void module_list_free (module_t **list)
  */
 module_t **module_list_get (size_t *n)
 {
-    /* TODO: this whole module lookup is quite inefficient */
-    /* Remove this and improve module_need */
     module_t **tab = NULL;
     size_t i = 0;
 
@@ -244,6 +239,57 @@ module_t **module_list_get (size_t *n)
     return tab;
 }
 
+static int modulecmp (const void *a, const void *b)
+{
+    const module_t *const *ma = a, *const *mb = b;
+    /* Note that qsort() uses _ascending_ order,
+     * so the smallest module is the one with the biggest score. */
+    return (*mb)->i_score - (*ma)->i_score;
+}
+
+/**
+ * Builds a sorted list of all VLC modules with a given capability.
+ * The list is sorted from the highest module score to the lowest.
+ * @param list pointer to the table of modules [OUT]
+ * @param cap capability of modules to look for
+ * @return the number of matching found, or -1 on error (*list is then NULL).
+ * @note *list must be freed with module_list_free().
+ */
+ssize_t module_list_cap (module_t ***restrict list, const char *cap)
+{
+    /* TODO: This is quite inefficient. List should be sorted by capability. */
+    ssize_t n = 0;
+
+    assert (list != NULL);
+
+    for (module_t *mod = modules.head; mod != NULL; mod = mod->next)
+    {
+         if (module_provides (mod, cap))
+             n++;
+         for (module_t *subm = mod->submodule; subm != NULL; subm = subm->next)
+             if (module_provides (subm, cap))
+                 n++;
+    }
+
+    module_t **tab = malloc (sizeof (*tab) * n);
+    *list = tab;
+    if (unlikely(tab == NULL))
+        return -1;
+
+    for (module_t *mod = modules.head; mod != NULL; mod = mod->next)
+    {
+         if (module_provides (mod, cap))
+             *(tab++)= mod;
+         for (module_t *subm = mod->submodule; subm != NULL; subm = subm->next)
+             if (module_provides (subm, cap))
+                 *(tab++) = subm;
+    }
+
+    assert (tab == *list + n);
+    qsort (*list, n, sizeof (*tab), modulecmp);
+    return n;
+}
+
 #ifdef HAVE_DYNAMIC_PLUGINS
 typedef enum { CACHE_USE, CACHE_RESET, CACHE_IGNORE } cache_mode_t;
 
@@ -269,6 +315,10 @@ static void AllocateAllPlugins (vlc_object_t *p_this)
     else
         mode = CACHE_USE;
 
+#if VLC_WINSTORE_APP
+    /* Windows Store Apps can not load external plugins with absolute paths. */
+    AllocatePluginPath (p_this, "plugins", mode);
+#else
     /* Contruct the special search path for system that have a relocatable
      * executable. Set it to <vlc path>/plugins. */
     char *vlcpath = config_GetLibDir ();
@@ -279,6 +329,7 @@ static void AllocateAllPlugins (vlc_object_t *p_this)
         free( paths );
     }
     free (vlcpath);
+#endif /* VLC_WINSTORE_APP */
 
     /* If the user provided a plugin path, we add it to the list */
     paths = getenv( "VLC_PLUGIN_PATH" );
@@ -393,7 +444,7 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
 
         /* Skip ".", ".." */
         if (!strcmp (file, ".") || !strcmp (file, ".."))
-            goto skip;
+            continue;
 
         /* Compute path relative to plug-in base directory */
         if (reldir != NULL)
@@ -404,7 +455,7 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
         else
             relpath = strdup (file);
         if (unlikely(relpath == NULL))
-            goto skip;
+            continue;
 
         /* Compute absolute path */
         if (asprintf (&abspath, "%s"DIR_SEP"%s", bank->base, relpath) == -1)
@@ -442,7 +493,6 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
     skip:
         free (relpath);
         free (abspath);
-        free (file);
     }
     closedir (dh);
 }