Commit f0cf58a8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix HTTP authentication.

Yes, some sites use empty usernames
parent db9ec109
...@@ -932,38 +932,42 @@ static int Request( access_t *p_access, int64_t i_tell ) ...@@ -932,38 +932,42 @@ static int Request( access_t *p_access, int64_t i_tell )
} }
/* Authentication */ /* Authentication */
if( p_sys->url.psz_username && *p_sys->url.psz_username ) if( p_sys->url.psz_username || p_sys->url.psz_password )
{ {
char *buf; char buf[strlen( p_sys->url.psz_username ?: "" )
+ strlen( p_sys->url.psz_password ?: "" ) + 2];
char *b64; char *b64;
asprintf( &buf, "%s:%s", p_sys->url.psz_username, snprintf( buf, sizeof( buf ), "%s:%s", p_sys->url.psz_username ?: "",
p_sys->url.psz_password ? p_sys->url.psz_password : "" ); p_sys->url.psz_password ?: "" );
b64 = vlc_b64_encode( buf ); b64 = vlc_b64_encode( buf );
free( buf );
if( b64 != NULL )
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs,
"Authorization: Basic %s\r\n", b64 ); "Authorization: Basic %s\r\n", b64 );
free( b64 ); free( b64 );
} }
}
/* Proxy Authentication */ /* Proxy Authentication */
if( p_sys->proxy.psz_username && *p_sys->proxy.psz_username ) if( p_sys->proxy.psz_username || p_sys->proxy.psz_password )
{ {
char *buf; char buf[strlen( p_sys->proxy.psz_username ?: "" )
+ strlen( p_sys->proxy.psz_password ?: "" )];
char *b64; char *b64;
asprintf( &buf, "%s:%s", p_sys->proxy.psz_username, snprintf( buf, sizeof( buf ), "%s:%s", p_sys->proxy.psz_username ?: "",
p_sys->proxy.psz_password ? p_sys->proxy.psz_password : "" ); p_sys->proxy.psz_password ?: "" );
b64 = vlc_b64_encode( buf ); b64 = vlc_b64_encode( buf );
free( buf );
if( b64 != NULL)
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs,
"Proxy-Authorization: Basic %s\r\n", b64 ); "Proxy-Authorization: Basic %s\r\n", b64 );
free( b64 ); free( b64 );
} }
}
/* ICY meta data request */ /* ICY meta data request */
net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "Icy-MetaData: 1\r\n" ); net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "Icy-MetaData: 1\r\n" );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment