[vlc-commits] tls client: use vlc_module_match() directly

Rémi Denis-Courmont git at videolan.org
Sat Sep 26 08:44:04 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Sep 24 22:45:29 2020 +0300| [aa71289f0438951ae2ed8ef9513c1a52947ec081] | committer: Rémi Denis-Courmont

tls client: use vlc_module_match() directly

This does not really save code but it avoids variable arguments.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=aa71289f0438951ae2ed8ef9513c1a52947ec081
---

 src/network/tls.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/network/tls.c b/src/network/tls.c
index 25e31f087e..27ec95e6f5 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -46,18 +46,6 @@
 
 /*** TLS credentials ***/
 
-static int tls_client_load(void *func, bool forced, va_list ap)
-{
-    int (*activate)(vlc_tls_client_t *) = func;
-    vlc_tls_client_t *crd = va_arg(ap, vlc_tls_client_t *);
-
-    int ret = activate (crd);
-    if (ret)
-        vlc_objres_clear(VLC_OBJECT(crd));
-    (void) forced;
-    return ret;
-}
-
 vlc_tls_server_t *
 vlc_tls_ServerCreate (vlc_object_t *obj, const char *cert_path,
                       const char *key_path)
@@ -112,15 +100,29 @@ vlc_tls_client_t *vlc_tls_ClientCreate(vlc_object_t *obj)
     if (unlikely(crd == NULL))
         return NULL;
 
-    if (vlc_module_load(crd, "tls client", NULL, false,
-                        tls_client_load, crd) == NULL)
-    {
-        msg_Err (crd, "TLS client plugin not available");
-        vlc_object_delete(crd);
+    module_t **mods;
+    ssize_t total = vlc_module_match("tls client", "any", false, &mods, NULL);
+
+    if (unlikely(total < 0))
         return NULL;
+
+    for (ssize_t i = 0; i < total; i++) {
+        int (*probe)(vlc_tls_client_t *);
+
+        probe = vlc_module_map(obj->logger, mods[i]);
+
+        if (probe != NULL && probe(crd) == VLC_SUCCESS) {
+            free(mods);
+            return crd;
+        }
+
+        vlc_objres_clear(VLC_OBJECT(crd));
     }
 
-    return crd;
+    free(mods);
+    msg_Err(crd, "TLS client plugin not available");
+    vlc_object_delete(crd);
+    return NULL;
 }
 
 void vlc_tls_ClientDelete(vlc_tls_client_t *crd)



More information about the vlc-commits mailing list