[vlc-devel] [PATCH v3 06/11] crendential: add an option to force user interaction

Thomas Guillem thomas at gllm.fr
Mon Dec 21 17:54:31 UTC 2020


Will be used if the user want to try an other account.
---
 include/vlc_input_item.h  | 4 ++++
 include/vlc_keystore.h    | 4 ++++
 src/input/input.c         | 8 +++++++-
 src/input/var.c           | 3 +++
 src/misc/keystore.c       | 7 +++++++
 src/preparser/preparser.c | 4 +++-
 6 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 7ee699f6811..da74ef7b800 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -125,6 +125,9 @@ struct input_item_t
         INPUT_ITEM_PREPARSE_INTERACT_NONE,
         /** Preparsing can request an UI interaction from the user. */
         INPUT_ITEM_PREPARSE_INTERACT,
+        /** Always request a login dialog. In order to change the username of a
+         * previously saved browsing session */
+        INPUT_ITEM_PREPARSE_INTERACT_FORCED,
     } preparse_interact;
 
     void        *libvlc_owner;       /**< LibVLC private data, can only be set
@@ -475,6 +478,7 @@ typedef enum input_item_meta_request_option_t
     META_REQUEST_OPTION_FETCH_NETWORK = 0x08,
     META_REQUEST_OPTION_FETCH_ANY     = 0x0C,
     META_REQUEST_OPTION_DO_INTERACT   = 0x10,
+    META_REQUEST_OPTION_DO_INTERACT_FORCED = 0x20,
 } input_item_meta_request_option_t;
 
 /* status of the on_preparse_ended() callback */
diff --git a/include/vlc_keystore.h b/include/vlc_keystore.h
index a5c9e29faa2..e9118c9f619 100644
--- a/include/vlc_keystore.h
+++ b/include/vlc_keystore.h
@@ -174,6 +174,10 @@ struct vlc_credential
     const char *psz_username;
     /** valid only if vlc_credential_get() returned true */
     const char *psz_password;
+    /** true if credentials should come from the dialog, ie. guest or
+     * anonymous login should not be tried. Only valid after the first
+     * vlc_credential_get() call*/
+    bool b_interact_forced;
 
     /* internal */
     enum {
diff --git a/src/input/input.c b/src/input/input.c
index f3f957fae81..2a0477d5105 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -364,13 +364,16 @@ static input_thread_t *Create( vlc_object_t *p_parent,
     /* Make sure the interaction option is honored */
     if( !var_InheritBool( p_input, "interact" ) )
         p_input->obj.no_interact = true;
-    else if( p_item->preparse_interact == INPUT_ITEM_PREPARSE_INTERACT )
+    else if( p_item->preparse_interact == INPUT_ITEM_PREPARSE_INTERACT
+          || p_item->preparse_interact == INPUT_ITEM_PREPARSE_INTERACT_FORCED )
     {
         /* If true, this item was asked explicitly to interact with the user
          * (via libvlc_MetadataRequest). Sub items created from this input won't
          * have this flag and won't interact with the user */
         p_input->obj.no_interact = false;
     }
+    const bool interact_forced =
+        p_item->preparse_interact == INPUT_ITEM_PREPARSE_INTERACT_FORCED;
 
     vlc_mutex_unlock( &p_item->lock );
 
@@ -394,6 +397,9 @@ static input_thread_t *Create( vlc_object_t *p_parent,
     /* Create Object Variables for private use only */
     input_ConfigVarInit( p_input );
 
+    if( interact_forced )
+        var_SetBool( p_input, "interact-forced", true );
+
     priv->b_low_delay = var_InheritBool( p_input, "low-delay" );
     priv->i_jitter_max = VLC_TICK_FROM_MS(var_InheritInteger( p_input, "clock-jitter" ));
 
diff --git a/src/input/var.c b/src/input/var.c
index b5de58afb63..2fccb813bec 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -123,4 +123,7 @@ void input_ConfigVarInit ( input_thread_t *p_input )
 
     /* Inherited by demux/subtitle.c */
     var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
+
+    /* Used by vlc_credential */
+    var_Create( p_input, "interact-forced", VLC_VAR_BOOL );
 }
diff --git a/src/misc/keystore.c b/src/misc/keystore.c
index 93470ae3440..73e9e9d5c6f 100644
--- a/src/misc/keystore.c
+++ b/src/misc/keystore.c
@@ -405,6 +405,13 @@ vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
         return false;
     }
 
+    if (!p_parent->no_interact && p_credential->i_get_order == GET_FROM_INIT
+     && var_InheritBool(p_parent, "interact-forced"))
+    {
+        p_credential->i_get_order = GET_FROM_DIALOG;
+        p_credential->b_interact_forced = true;
+    }
+
     p_credential->b_from_keystore = false;
     /* Don't set username to NULL, we may want to use the last one set */
     p_credential->psz_password = NULL;
diff --git a/src/preparser/preparser.c b/src/preparser/preparser.c
index 211a7f1ae4f..f4266ad3ba2 100644
--- a/src/preparser/preparser.c
+++ b/src/preparser/preparser.c
@@ -344,7 +344,9 @@ int input_preparser_Push( input_preparser_t *preparser,
     vlc_mutex_lock( &item->lock );
     enum input_item_type_e i_type = item->i_type;
     int b_net = item->b_net;
-    if( i_options & META_REQUEST_OPTION_DO_INTERACT )
+    if( i_options & META_REQUEST_OPTION_DO_INTERACT_FORCED )
+        item->preparse_interact = INPUT_ITEM_PREPARSE_INTERACT_FORCED;
+    else if( i_options & META_REQUEST_OPTION_DO_INTERACT )
         item->preparse_interact = INPUT_ITEM_PREPARSE_INTERACT;
     vlc_mutex_unlock( &item->lock );
 
-- 
2.29.2



More information about the vlc-devel mailing list