[vlc-devel] [PATCH 2/5] keystore: parse keystore modules configuration

Maxime ... mmeisson at outlook.fr
Tue Jul 30 13:01:37 CEST 2019


Pass the configuration from the --keystore option to the keystore modules in
order to let them parse their own options.
---
 include/vlc_keystore.h    |  2 ++
 modules/keystore/file.c   | 23 ++++++++++++++---------
 modules/keystore/memory.c | 15 ++++++++++-----
 src/misc/keystore.c       | 24 ++++++++++++++++++++++--
 4 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/include/vlc_keystore.h b/include/vlc_keystore.h
index 80262987c2..b751bb0c8c 100644
--- a/include/vlc_keystore.h
+++ b/include/vlc_keystore.h
@@ -27,6 +27,8 @@ typedef struct vlc_keystore vlc_keystore;
 typedef struct vlc_keystore_entry vlc_keystore_entry;
 typedef struct vlc_credential vlc_credential;
 
+typedef int (*vlc_keystore_open)(vlc_keystore *, const config_chain_t *);
+
 /* Called from src/libvlc.c */
 int
 libvlc_InternalKeystoreInit(libvlc_int_t *p_libvlc);
diff --git a/modules/keystore/file.c b/modules/keystore/file.c
index b607185583..d5b1bc265c 100644
--- a/modules/keystore/file.c
+++ b/modules/keystore/file.c
@@ -42,10 +42,10 @@
 #include "file_crypt.h"
 #include "list_util.h"
 
-static int Open(vlc_object_t *);
+static int Open(vlc_keystore *, const config_chain_t *);
 static void Close(vlc_object_t *);
 #ifdef CRYPTFILE
-static int OpenCrypt(vlc_object_t *);
+static int OpenCrypt(vlc_keystore *, const config_chain_t *);
 static void CloseCrypt(vlc_object_t *);
 #endif
 
@@ -492,17 +492,23 @@ Close(vlc_object_t *p_this)
 }
 
 static int
-Open(vlc_object_t *p_this)
+Open(vlc_keystore *p_keystore, const config_chain_t *config)
 {
-    vlc_keystore *p_keystore = (vlc_keystore *)p_this;
-
     vlc_keystore_sys *p_sys = calloc(1, sizeof(vlc_keystore_sys));
+    const char *const ppsz_options[] = {
+        "file",
+        NULL,
+    };
+
     if (!p_sys)
         return VLC_EGENERIC;
 
-    char *psz_file = var_InheritString(p_this, "keystore-file");
+    config_ChainParse(p_keystore, "keystore-", ppsz_options, config);
+
+    char *psz_file = var_InheritString(p_keystore, "keystore-file");
     if (!psz_file)
     {
+        msg_Err(p_keystore, "Keystore did not receive file name, fallback to keystore-memory");
         free(p_sys);
         return VLC_EGENERIC;
     }
@@ -551,14 +557,13 @@ CloseCrypt(vlc_object_t *p_this)
 }
 
 static int
-OpenCrypt(vlc_object_t *p_this)
+OpenCrypt(vlc_keystore *p_keystore, const config_chain_t *config);
 {
-    int i_ret = Open(p_this);
+    int i_ret = Open(p_keystore, p_config);
 
     if (i_ret != VLC_SUCCESS)
         return i_ret;
 
-    vlc_keystore *p_keystore = (vlc_keystore *)p_this;
     vlc_keystore_sys *p_sys = p_keystore->p_sys;
 
     if (CryptInit(p_keystore, &p_sys->crypt) != VLC_SUCCESS)
diff --git a/modules/keystore/memory.c b/modules/keystore/memory.c
index 527433db9a..9a93f8f068 100644
--- a/modules/keystore/memory.c
+++ b/modules/keystore/memory.c
@@ -33,7 +33,7 @@
 
 #include "list_util.h"
 
-static int Open(vlc_object_t *);
+static int Open(vlc_keystore *, const config_chain_t *);
 static void Close(vlc_object_t *);
 
 vlc_module_begin()
@@ -152,12 +152,17 @@ Close(vlc_object_t *p_this)
 }
 
 static int
-Open(vlc_object_t *p_this)
+Open(vlc_keystore *p_keystore, const config_chain_t *config)
 {
-    vlc_keystore *p_keystore = (vlc_keystore *)p_this;
-    p_keystore->p_sys = calloc(1, sizeof(vlc_keystore_sys));
-    if (!p_keystore->p_sys)
+    vlc_keystore_sys *p_sys = calloc(1, sizeof(vlc_keystore_sys));
+    if (!p_sys)
         return VLC_EGENERIC;
+    p_keystore->p_sys = p_sys;
+
+    const char *const ppsz_options[] = {
+        NULL,
+    };
+    config_ChainParse(p_keystore, "keystore-", ppsz_options, config);
 
     vlc_mutex_init(&p_keystore->p_sys->lock);
     p_keystore->pf_store = Store;
diff --git a/src/misc/keystore.c b/src/misc/keystore.c
index 55b094350d..e00c4268f4 100644
--- a/src/misc/keystore.c
+++ b/src/misc/keystore.c
@@ -32,15 +32,35 @@
 #include <assert.h>
 #include <limits.h>
 
+static int
+keystore_start(void *func, bool forced, va_list ap)
+{
+    vlc_keystore_open   cb_entry = func;
+    vlc_keystore        *p_keystore = va_arg(ap, vlc_keystore *);
+    config_chain_t      *config = va_arg(ap, config_chain_t *);
+
+    p_keystore->obj.force = forced;
+    return cb_entry(p_keystore, config);
+}
+
 static vlc_keystore *
-keystore_create(vlc_object_t *p_parent, const char *psz_name)
+keystore_create(vlc_object_t *p_parent, const char *psz_modlist)
 {
+    char *psz_name = NULL;
+    config_chain_t *p_config = NULL;
+
+    char *next = config_ChainCreate(&psz_name, &p_config, psz_modlist);
+    if (next != NULL)
+        free(next);
+
     vlc_keystore *p_keystore = vlc_custom_create(p_parent, sizeof (*p_keystore),
                                                  "keystore");
     if (unlikely(p_keystore == NULL))
         return NULL;
 
-    p_keystore->p_module = module_need(p_keystore, "keystore", psz_name, true);
+    p_keystore->p_module = vlc_module_load(p_keystore, "keystore", psz_name, true,
+                                           keystore_start, p_keystore, p_config);
+    config_ChainDestroy(p_config);
     if (p_keystore->p_module == NULL)
     {
         vlc_object_delete(p_keystore);
-- 
2.17.1



More information about the vlc-devel mailing list