]> git.sesse.net Git - vlc/commitdiff
Request authentication if we get a 401 error
authorClément Stenac <zorglub@videolan.org>
Sun, 11 Dec 2005 16:07:51 +0000 (16:07 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 11 Dec 2005 16:07:51 +0000 (16:07 +0000)
modules/access/http.c

index 72d0cd6d3805c700b2ec0510e44f5230157ff2a8..0749103bd5544f21876862cfd5d704d42bad7ac2 100644 (file)
@@ -31,6 +31,7 @@
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 
+#include "vlc_interaction.h"
 #include "vlc_playlist.h"
 #include "vlc_meta.h"
 #include "network.h"
@@ -189,6 +190,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->psz_icy_title = NULL;
     p_sys->i_remaining = 0;
 
+
     /* Parse URI - remove spaces */
     p = psz = strdup( p_access->psz_path );
     while( (p = strchr( p, ' ' )) != NULL )
@@ -266,6 +268,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->b_reconnect = var_CreateGetBool( p_access, "http-reconnect" );
     p_sys->b_continuous = var_CreateGetBool( p_access, "http-continuous" );
 
+connect:
     /* Connect */
     if( Connect( p_access, 0 ) )
     {
@@ -279,6 +282,31 @@ static int Open( vlc_object_t *p_this )
         }
     }
 
+    if( p_sys->i_code == 401 )
+    {
+        char *psz_login = NULL; char *psz_password = NULL;
+        int i_ret;
+        msg_Dbg( p_access, "Authentication failed" );
+        i_ret = intf_UserLoginPassword( p_access, "HTTP authentication",
+                         "Authentication failed", &psz_login, &psz_password );
+        if( i_ret == DIALOG_OK_YES )
+        {
+            msg_Dbg( p_access, "retrying with user=%s, pwd=%s",
+                        psz_login, psz_password );
+            if( psz_login ) p_sys->url.psz_username = strdup( psz_login );
+            if( psz_password ) p_sys->url.psz_password = strdup( psz_password );
+            if( psz_login ) free( psz_login );
+            if( psz_password ) free( psz_password );
+            goto connect;
+        }
+        else
+        {
+            if( psz_login ) free( psz_login );
+            if( psz_password ) free( psz_password );
+            goto error;
+        }
+    }
+
     if( ( p_sys->i_code == 301 || p_sys->i_code == 302 ||
           p_sys->i_code == 303 || p_sys->i_code == 307 ) &&
         p_sys->psz_location && *p_sys->psz_location )
@@ -988,7 +1016,13 @@ static int Request( access_t *p_access, int64_t i_tell )
     {
         p_sys->b_seekable = VLC_FALSE;
     }
-    if( p_sys->i_code >= 400 )
+    /* Authentication error - We'll have to display the dialog */
+    if( p_sys->i_code == 401 )
+    {
+
+    }
+    /* Other fatal error */
+    else if( p_sys->i_code >= 400 )
     {
         msg_Err( p_access, "error: %s", psz );
         free( psz );