1 /*****************************************************************************
2 * http.c: HTTP input module
3 *****************************************************************************
4 * Copyright (C) 2001-2008 VLC authors and VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * RĂ©mi Denis-Courmont <rem # videolan.org>
10 * Antoine Cellerier <dionoea at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation; either version 2.1 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
38 #include <vlc_access.h>
40 #include <vlc_dialog.h>
42 #include <vlc_network.h>
45 #include <vlc_strings.h>
46 #include <vlc_charset.h>
47 #include <vlc_input.h>
58 /*****************************************************************************
60 *****************************************************************************/
61 static int Open ( vlc_object_t * );
62 static void Close( vlc_object_t * );
64 #define PROXY_TEXT N_("HTTP proxy")
65 #define PROXY_LONGTEXT N_( \
66 "HTTP proxy to be used It must be of the form " \
67 "http://[user@]myproxy.mydomain:myport/ ; " \
68 "if empty, the http_proxy environment variable will be tried." )
70 #define PROXY_PASS_TEXT N_("HTTP proxy password")
71 #define PROXY_PASS_LONGTEXT N_( \
72 "If your HTTP proxy requires a password, set it here." )
74 #define RECONNECT_TEXT N_("Auto re-connect")
75 #define RECONNECT_LONGTEXT N_( \
76 "Automatically try to reconnect to the stream in case of a sudden " \
79 #define CONTINUOUS_TEXT N_("Continuous stream")
80 #define CONTINUOUS_LONGTEXT N_("Read a file that is " \
81 "being constantly updated (for example, a JPG file on a server). " \
82 "You should not globally enable this option as it will break all other " \
83 "types of HTTP streams." )
85 #define FORWARD_COOKIES_TEXT N_("Forward Cookies")
86 #define FORWARD_COOKIES_LONGTEXT N_("Forward Cookies across http redirections.")
88 #define REFERER_TEXT N_("HTTP referer value")
89 #define REFERER_LONGTEXT N_("Customize the HTTP referer, simulating a previous document")
91 #define UA_TEXT N_("User Agent")
92 #define UA_LONGTEXT N_("The name and version of the program will be " \
93 "provided to the HTTP server. They must be separated by a forward " \
94 "slash, e.g. FooBar/1.2.3. This option can only be specified per input " \
95 "item, not globally.")
98 set_description( N_("HTTP input") )
99 set_capability( "access", 0 )
100 set_shortname( N_( "HTTP(S)" ) )
101 set_category( CAT_INPUT )
102 set_subcategory( SUBCAT_INPUT_ACCESS )
104 add_string( "http-proxy", NULL, PROXY_TEXT, PROXY_LONGTEXT,
106 add_password( "http-proxy-pwd", NULL,
107 PROXY_PASS_TEXT, PROXY_PASS_LONGTEXT, false )
108 add_obsolete_bool( "http-use-IE-proxy" )
109 add_string( "http-referrer", NULL, REFERER_TEXT, REFERER_LONGTEXT, false )
111 add_string( "http-user-agent", NULL, UA_TEXT, UA_LONGTEXT, false )
114 add_bool( "http-reconnect", false, RECONNECT_TEXT,
115 RECONNECT_LONGTEXT, true )
116 add_bool( "http-continuous", false, CONTINUOUS_TEXT,
117 CONTINUOUS_LONGTEXT, true )
119 add_bool( "http-forward-cookies", true, FORWARD_COOKIES_TEXT,
120 FORWARD_COOKIES_LONGTEXT, true )
121 /* 'itpc' = iTunes Podcast */
122 add_shortcut( "http", "https", "unsv", "itpc", "icyx" )
123 set_callbacks( Open, Close )
126 /*****************************************************************************
128 *****************************************************************************/
134 vlc_tls_creds_t *p_creds;
140 char *psz_user_agent;
147 http_auth_t proxy_auth;
148 char *psz_proxy_passbuf;
152 const char *psz_protocol;
173 uint64_t i_icy_offset;
178 uint64_t i_remaining;
187 vlc_array_t * cookies;
191 static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
192 unsigned i_redirect, vlc_array_t *cookies );
195 static ssize_t Read( access_t *, uint8_t *, size_t );
196 static ssize_t ReadCompressed( access_t *, uint8_t *, size_t );
197 static int Seek( access_t *, uint64_t );
198 static int Control( access_t *, int, va_list );
201 static int Connect( access_t *, uint64_t );
202 static int Request( access_t *p_access, uint64_t i_tell );
203 static void Disconnect( access_t * );
205 /* Small Cookie utilities. Cookies support is partial. */
206 static char * cookie_get_content( const char * cookie );
207 static char * cookie_get_domain( const char * cookie );
208 static char * cookie_get_name( const char * cookie );
209 static void cookie_append( vlc_array_t * cookies, char * cookie );
212 static void AuthReply( access_t *p_acces, const char *psz_prefix,
213 vlc_url_t *p_url, http_auth_t *p_auth );
214 static int AuthCheckReply( access_t *p_access, const char *psz_header,
215 vlc_url_t *p_url, http_auth_t *p_auth );
217 /*****************************************************************************
219 *****************************************************************************/
220 static int Open( vlc_object_t *p_this )
222 access_t *p_access = (access_t*)p_this;
223 return OpenWithCookies( p_this, p_access->psz_access, 5, NULL );
227 * Open the given url using the given cookies
228 * @param p_this: the vlc object
229 * @psz_access: the acces to use (http, https, ...) (this value must be used
230 * instead of p_access->psz_access)
231 * @i_redirect: number of redirections remaining
232 * @cookies: the available cookies
233 * @return vlc error codes
235 static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
236 unsigned i_redirect, vlc_array_t *cookies )
238 access_t *p_access = (access_t*)p_this;
242 /* Only forward an store cookies if the corresponding option is activated */
243 bool b_forward_cookies = var_InheritBool( p_access, "http-forward-cookies" );
244 vlc_array_t * saved_cookies = b_forward_cookies ? (cookies ? cookies : vlc_array_new()) : NULL;
246 /* Set up p_access */
247 STANDARD_READ_ACCESS_INIT;
249 p_access->pf_read = ReadCompressed;
252 p_sys->b_proxy = false;
253 p_sys->psz_proxy_passbuf = NULL;
254 p_sys->i_version = 1;
255 p_sys->b_seekable = true;
256 p_sys->psz_mime = NULL;
257 p_sys->psz_pragma = NULL;
258 p_sys->b_mms = false;
259 p_sys->b_icecast = false;
260 p_sys->psz_location = NULL;
261 p_sys->psz_user_agent = NULL;
262 p_sys->psz_referrer = NULL;
263 p_sys->b_pace_control = true;
265 p_sys->b_compressed = false;
266 /* 15 is the max windowBits, +32 to enable optional gzip decoding */
267 if( inflateInit2( &p_sys->inflate.stream, 32+15 ) != Z_OK )
268 msg_Warn( p_access, "Error during zlib initialisation: %s",
269 p_sys->inflate.stream.msg );
270 if( zlibCompileFlags() & (1<<17) )
271 msg_Warn( p_access, "Your zlib was compiled without gzip support." );
272 p_sys->inflate.p_buffer = NULL;
276 p_sys->i_icy_meta = 0;
277 p_sys->i_icy_offset = 0;
278 p_sys->psz_icy_name = NULL;
279 p_sys->psz_icy_genre = NULL;
280 p_sys->psz_icy_title = NULL;
281 p_sys->i_remaining = 0;
282 p_sys->b_persist = false;
283 p_sys->b_has_size = false;
284 p_access->info.i_size = 0;
285 p_access->info.i_pos = 0;
286 p_access->info.b_eof = false;
288 p_sys->cookies = saved_cookies;
290 http_auth_Init( &p_sys->auth );
291 http_auth_Init( &p_sys->proxy_auth );
293 /* Parse URI - remove spaces */
294 p = psz = strdup( p_access->psz_location );
295 while( (p = strchr( p, ' ' )) != NULL )
297 vlc_UrlParse( &p_sys->url, psz, 0 );
300 if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' )
302 msg_Warn( p_access, "invalid host" );
305 if( !strncmp( psz_access, "https", 5 ) )
308 p_sys->p_creds = vlc_tls_ClientCreate( p_this );
309 if( p_sys->p_creds == NULL )
311 if( p_sys->url.i_port <= 0 )
312 p_sys->url.i_port = 443;
316 if( p_sys->url.i_port <= 0 )
317 p_sys->url.i_port = 80;
320 /* Determine the HTTP user agent */
321 /* See RFC2616 §2.2 token and comment definition, and §3.8 and
322 * §14.43 user-agent header */
323 p_sys->psz_user_agent = var_InheritString( p_access, "http-user-agent" );
324 if (p_sys->psz_user_agent)
326 unsigned comment_level = 0;
327 for( char *p = p_sys->psz_user_agent; *p; p++ )
330 if (comment_level == 0)
332 if( c < 32 || strchr( ")<>@,;:\\\"[]?={}", c ) )
333 *p = '_'; /* remove potentially harmful characters */
339 else if( c < 32 && strchr( "\t\r\n", c ) == NULL)
340 *p = '_'; /* remove potentially harmful characters */
344 if (comment_level == UINT_MAX)
349 /* truncate evil unclosed comments */
350 if (comment_level > 0)
352 char *p = strchr(p_sys->psz_user_agent, '(');
358 p_sys->psz_referrer = var_InheritString( p_access, "http-referrer" );
361 psz = var_InheritString( p_access, "http-proxy" );
366 if (likely(asprintf(&url, "%s://%s", psz_access,
367 p_access->psz_location) != -1))
369 msg_Dbg(p_access, "querying proxy for %s", url);
370 psz = vlc_getProxyUrl(url);
375 msg_Dbg(p_access, "proxy: %s", psz);
377 msg_Dbg(p_access, "no proxy");
381 p_sys->b_proxy = true;
382 vlc_UrlParse( &p_sys->proxy, psz, 0 );
385 psz = var_InheritString( p_access, "http-proxy-pwd" );
387 p_sys->proxy.psz_password = p_sys->psz_proxy_passbuf = psz;
389 if( p_sys->proxy.psz_host == NULL || *p_sys->proxy.psz_host == '\0' )
391 msg_Warn( p_access, "invalid proxy host" );
394 if( p_sys->proxy.i_port <= 0 )
396 p_sys->proxy.i_port = 80;
400 msg_Dbg( p_access, "http: server='%s' port=%d file='%s'",
401 p_sys->url.psz_host, p_sys->url.i_port,
402 p_sys->url.psz_path != NULL ? p_sys->url.psz_path : "" );
405 msg_Dbg( p_access, " proxy %s:%d", p_sys->proxy.psz_host,
406 p_sys->proxy.i_port );
408 if( p_sys->url.psz_username && *p_sys->url.psz_username )
410 msg_Dbg( p_access, " user='%s'", p_sys->url.psz_username );
413 p_sys->b_reconnect = var_InheritBool( p_access, "http-reconnect" );
414 p_sys->b_continuous = var_InheritBool( p_access, "http-continuous" );
418 switch( Connect( p_access, 0 ) )
424 /* Retry with http 1.0 */
425 msg_Dbg( p_access, "switching to HTTP version 1.0" );
426 p_sys->i_version = 0;
427 p_sys->b_seekable = false;
429 if( !vlc_object_alive (p_access) || Connect( p_access, 0 ) )
439 if( p_sys->i_code == 401 )
441 char *psz_login, *psz_password;
443 if( p_sys->url.psz_username && p_sys->url.psz_password &&
444 p_sys->auth.psz_nonce && p_sys->auth.i_nonce == 0 )
446 Disconnect( p_access );
449 msg_Dbg( p_access, "authentication failed for realm %s",
450 p_sys->auth.psz_realm );
451 dialog_Login( p_access, &psz_login, &psz_password,
452 _("HTTP authentication"),
453 _("Please enter a valid login name and a password for realm %s."),
454 p_sys->auth.psz_realm );
455 if( psz_login != NULL && psz_password != NULL )
457 msg_Dbg( p_access, "retrying with user=%s", psz_login );
458 p_sys->url.psz_username = psz_login;
459 p_sys->url.psz_password = psz_password;
460 Disconnect( p_access );
466 free( psz_password );
471 if( ( p_sys->i_code == 301 || p_sys->i_code == 302 ||
472 p_sys->i_code == 303 || p_sys->i_code == 307 ) &&
473 p_sys->psz_location && *p_sys->psz_location )
475 msg_Dbg( p_access, "redirection to %s", p_sys->psz_location );
477 /* Check the number of redirection already done */
478 if( i_redirect == 0 )
480 msg_Err( p_access, "Too many redirection: break potential infinite"
485 const char *psz_protocol;
486 if( !strncmp( p_sys->psz_location, "http://", 7 ) )
487 psz_protocol = "http";
488 else if( !strncmp( p_sys->psz_location, "https://", 8 ) )
489 psz_protocol = "https";
491 { /* Do not accept redirection outside of HTTP */
492 msg_Err( p_access, "unsupported redirection ignored" );
495 free( p_access->psz_location );
496 p_access->psz_location = strdup( p_sys->psz_location
497 + strlen( psz_protocol ) + 3 );
498 /* Clean up current Open() run */
499 vlc_UrlClean( &p_sys->url );
500 http_auth_Reset( &p_sys->auth );
501 vlc_UrlClean( &p_sys->proxy );
502 free( p_sys->psz_proxy_passbuf );
503 http_auth_Reset( &p_sys->proxy_auth );
504 free( p_sys->psz_mime );
505 free( p_sys->psz_pragma );
506 free( p_sys->psz_location );
507 free( p_sys->psz_user_agent );
508 free( p_sys->psz_referrer );
510 Disconnect( p_access );
511 vlc_tls_Delete( p_sys->p_creds );
512 cookies = p_sys->cookies;
514 inflateEnd( &p_sys->inflate.stream );
518 /* Do new Open() run with new data */
519 return OpenWithCookies( p_this, psz_protocol, i_redirect - 1,
525 msg_Dbg( p_access, "this is actually a live mms server, BAIL" );
529 if( !strcmp( p_sys->psz_protocol, "ICY" ) || p_sys->b_icecast )
531 if( p_sys->psz_mime && strcasecmp( p_sys->psz_mime, "application/ogg" ) )
533 if( !strcasecmp( p_sys->psz_mime, "video/nsv" ) ||
534 !strcasecmp( p_sys->psz_mime, "video/nsa" ) )
536 free( p_access->psz_demux );
537 p_access->psz_demux = strdup( "nsv" );
539 else if( !strcasecmp( p_sys->psz_mime, "audio/aac" ) ||
540 !strcasecmp( p_sys->psz_mime, "audio/aacp" ) )
542 free( p_access->psz_demux );
543 p_access->psz_demux = strdup( "m4a" );
545 else if( !strcasecmp( p_sys->psz_mime, "audio/mpeg" ) )
547 free( p_access->psz_demux );
548 p_access->psz_demux = strdup( "mp3" );
551 msg_Info( p_access, "Raw-audio server found, %s demuxer selected",
552 p_access->psz_demux );
554 #if 0 /* Doesn't work really well because of the pre-buffering in
555 * shoutcast servers (the buffer content will be sent as fast as
557 p_sys->b_pace_control = false;
560 else if( !p_sys->psz_mime )
562 free( p_access->psz_demux );
564 p_access->psz_demux = strdup( "mp3" );
566 /* else probably Ogg Vorbis */
568 else if( !strcasecmp( psz_access, "unsv" ) &&
570 !strcasecmp( p_sys->psz_mime, "misc/ultravox" ) )
572 free( p_access->psz_demux );
573 /* Grrrr! detect ultravox server and force NSV demuxer */
574 p_access->psz_demux = strdup( "nsv" );
576 else if( !strcmp( psz_access, "itpc" ) )
578 free( p_access->psz_demux );
579 p_access->psz_demux = strdup( "podcast" );
581 else if( p_sys->psz_mime &&
582 !strncasecmp( p_sys->psz_mime, "application/xspf+xml", 20 ) &&
583 ( memchr( " ;\t", p_sys->psz_mime[20], 4 ) != NULL ) )
585 free( p_access->psz_demux );
586 p_access->psz_demux = strdup( "xspf-open" );
589 if( p_sys->b_reconnect ) msg_Dbg( p_access, "auto re-connect enabled" );
594 vlc_UrlClean( &p_sys->url );
595 vlc_UrlClean( &p_sys->proxy );
596 free( p_sys->psz_proxy_passbuf );
597 free( p_sys->psz_mime );
598 free( p_sys->psz_pragma );
599 free( p_sys->psz_location );
600 free( p_sys->psz_user_agent );
601 free( p_sys->psz_referrer );
603 Disconnect( p_access );
604 vlc_tls_Delete( p_sys->p_creds );
609 for( i = 0; i < vlc_array_count( p_sys->cookies ); i++ )
610 free(vlc_array_item_at_index( p_sys->cookies, i ));
611 vlc_array_destroy( p_sys->cookies );
615 inflateEnd( &p_sys->inflate.stream );
621 /*****************************************************************************
623 *****************************************************************************/
624 static void Close( vlc_object_t *p_this )
626 access_t *p_access = (access_t*)p_this;
627 access_sys_t *p_sys = p_access->p_sys;
629 vlc_UrlClean( &p_sys->url );
630 http_auth_Reset( &p_sys->auth );
631 vlc_UrlClean( &p_sys->proxy );
632 http_auth_Reset( &p_sys->proxy_auth );
634 free( p_sys->psz_mime );
635 free( p_sys->psz_pragma );
636 free( p_sys->psz_location );
638 free( p_sys->psz_icy_name );
639 free( p_sys->psz_icy_genre );
640 free( p_sys->psz_icy_title );
642 free( p_sys->psz_user_agent );
643 free( p_sys->psz_referrer );
645 Disconnect( p_access );
646 vlc_tls_Delete( p_sys->p_creds );
651 for( i = 0; i < vlc_array_count( p_sys->cookies ); i++ )
652 free(vlc_array_item_at_index( p_sys->cookies, i ));
653 vlc_array_destroy( p_sys->cookies );
657 inflateEnd( &p_sys->inflate.stream );
658 free( p_sys->inflate.p_buffer );
664 /* Read data from the socket taking care of chunked transfer if needed */
665 static int ReadData( access_t *p_access, int *pi_read,
666 uint8_t *p_buffer, size_t i_len )
668 access_sys_t *p_sys = p_access->p_sys;
669 if( p_sys->b_chunked )
671 if( p_sys->i_chunk < 0 )
674 if( p_sys->i_chunk <= 0 )
676 char *psz = net_Gets( p_access, p_sys->fd, p_sys->p_vs );
677 /* read the chunk header */
680 /* fatal error - end of file */
681 msg_Dbg( p_access, "failed reading chunk-header line" );
684 p_sys->i_chunk = strtoll( psz, NULL, 16 );
687 if( p_sys->i_chunk <= 0 ) /* eof */
694 if( i_len > p_sys->i_chunk )
695 i_len = p_sys->i_chunk;
697 *pi_read = net_Read( p_access, p_sys->fd, p_sys->p_vs, p_buffer, i_len, false );
701 if( p_sys->b_chunked )
703 p_sys->i_chunk -= *pi_read;
704 if( p_sys->i_chunk <= 0 )
706 /* read the empty line */
707 char *psz = net_Gets( p_access, p_sys->fd, p_sys->p_vs );
714 /*****************************************************************************
715 * Read: Read up to i_len bytes from the http connection and place in
716 * p_buffer. Return the actual number of bytes read
717 *****************************************************************************/
718 static int ReadICYMeta( access_t *p_access );
719 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
721 access_sys_t *p_sys = p_access->p_sys;
724 if( p_sys->fd == -1 )
727 if( p_sys->b_has_size )
729 /* Remaining bytes in the file */
730 uint64_t remainder = p_access->info.i_size - p_access->info.i_pos;
731 if( remainder < i_len )
734 /* Remaining bytes in the response */
735 if( p_sys->i_remaining < i_len )
736 i_len = p_sys->i_remaining;
741 if( p_sys->i_icy_meta > 0 && p_access->info.i_pos - p_sys->i_icy_offset > 0 )
743 int64_t i_next = p_sys->i_icy_meta -
744 (p_access->info.i_pos - p_sys->i_icy_offset ) % p_sys->i_icy_meta;
746 if( i_next == p_sys->i_icy_meta )
748 if( ReadICYMeta( p_access ) )
755 if( ReadData( p_access, &i_read, p_buffer, i_len ) )
761 * I very much doubt that this will work.
762 * If i_read == 0, the connection *IS* dead, so the only
763 * sensible thing to do is Disconnect() and then retry.
764 * Otherwise, I got recv() completely wrong. -- Courmisch
766 if( p_sys->b_continuous )
768 Request( p_access, 0 );
769 p_sys->b_continuous = false;
770 i_read = Read( p_access, p_buffer, i_len );
771 p_sys->b_continuous = true;
773 Disconnect( p_access );
774 if( p_sys->b_reconnect && vlc_object_alive( p_access ) )
776 msg_Dbg( p_access, "got disconnected, trying to reconnect" );
777 if( Connect( p_access, p_access->info.i_pos ) )
779 msg_Dbg( p_access, "reconnection failed" );
783 p_sys->b_reconnect = false;
784 i_read = Read( p_access, p_buffer, i_len );
785 p_sys->b_reconnect = true;
794 p_sys->b_error = true;
799 assert( i_read >= 0 );
800 p_access->info.i_pos += i_read;
801 if( p_sys->b_has_size )
803 assert( p_access->info.i_pos <= p_access->info.i_size );
804 assert( (unsigned)i_read <= p_sys->i_remaining );
805 p_sys->i_remaining -= i_read;
811 p_access->info.b_eof = true;
815 static int ReadICYMeta( access_t *p_access )
817 access_sys_t *p_sys = p_access->p_sys;
823 /* Read meta data length */
824 if( ReadData( p_access, &i_read, &buffer, 1 ) )
828 const int i_size = buffer << 4;
829 /* msg_Dbg( p_access, "ICY meta size=%u", i_size); */
831 psz_meta = malloc( i_size + 1 );
832 for( i_read = 0; i_read < i_size; )
835 if( ReadData( p_access, &i_tmp, (uint8_t *)&psz_meta[i_read], i_size - i_read ) || i_tmp <= 0 )
842 psz_meta[i_read] = '\0'; /* Just in case */
844 /* msg_Dbg( p_access, "icy-meta=%s", psz_meta ); */
846 /* Now parse the meta */
847 /* Look for StreamTitle= */
848 p = strcasestr( (char *)psz_meta, "StreamTitle=" );
851 p += strlen( "StreamTitle=" );
852 if( *p == '\'' || *p == '"' )
854 char closing[] = { p[0], ';', '\0' };
855 char *psz = strstr( &p[1], closing );
857 psz = strchr( &p[1], ';' );
859 if( psz ) *psz = '\0';
863 char *psz = strchr( &p[1], ';' );
864 if( psz ) *psz = '\0';
867 if( !p_sys->psz_icy_title ||
868 strcmp( p_sys->psz_icy_title, &p[1] ) )
870 free( p_sys->psz_icy_title );
871 char *psz_tmp = strdup( &p[1] );
872 p_sys->psz_icy_title = EnsureUTF8( psz_tmp );
873 if( !p_sys->psz_icy_title )
875 p_access->info.i_update |= INPUT_UPDATE_META;
877 msg_Dbg( p_access, "New Title=%s", p_sys->psz_icy_title );
886 static ssize_t ReadCompressed( access_t *p_access, uint8_t *p_buffer,
889 access_sys_t *p_sys = p_access->p_sys;
891 if( p_sys->b_compressed )
895 if( !p_sys->inflate.p_buffer )
896 p_sys->inflate.p_buffer = malloc( 256 * 1024 );
898 if( p_sys->inflate.stream.avail_in == 0 )
900 ssize_t i_read = Read( p_access, p_sys->inflate.p_buffer, 256 * 1024 );
901 if( i_read <= 0 ) return i_read;
902 p_sys->inflate.stream.next_in = p_sys->inflate.p_buffer;
903 p_sys->inflate.stream.avail_in = i_read;
906 p_sys->inflate.stream.avail_out = i_len;
907 p_sys->inflate.stream.next_out = p_buffer;
909 i_ret = inflate( &p_sys->inflate.stream, Z_SYNC_FLUSH );
910 msg_Warn( p_access, "inflate return value: %d, %s", i_ret, p_sys->inflate.stream.msg );
912 return i_len - p_sys->inflate.stream.avail_out;
916 return Read( p_access, p_buffer, i_len );
921 /*****************************************************************************
922 * Seek: close and re-open a connection at the right place
923 *****************************************************************************/
924 static int Seek( access_t *p_access, uint64_t i_pos )
926 msg_Dbg( p_access, "trying to seek to %"PRId64, i_pos );
928 Disconnect( p_access );
930 if( p_access->info.i_size
931 && i_pos >= p_access->info.i_size ) {
932 msg_Err( p_access, "seek to far" );
933 int retval = Seek( p_access, p_access->info.i_size - 1 );
934 if( retval == VLC_SUCCESS ) {
936 Read( p_access, p_buffer, 1);
937 p_access->info.b_eof = false;
941 if( Connect( p_access, i_pos ) )
943 msg_Err( p_access, "seek failed" );
944 p_access->info.b_eof = true;
950 /*****************************************************************************
952 *****************************************************************************/
953 static int Control( access_t *p_access, int i_query, va_list args )
955 access_sys_t *p_sys = p_access->p_sys;
963 case ACCESS_CAN_SEEK:
964 pb_bool = (bool*)va_arg( args, bool* );
965 *pb_bool = p_sys->b_seekable;
967 case ACCESS_CAN_FASTSEEK:
968 pb_bool = (bool*)va_arg( args, bool* );
971 case ACCESS_CAN_PAUSE:
972 case ACCESS_CAN_CONTROL_PACE:
973 pb_bool = (bool*)va_arg( args, bool* );
975 #if 0 /* Disable for now until we have a clock synchro algo
976 * which works with something else than MPEG over UDP */
977 *pb_bool = p_sys->b_pace_control;
983 case ACCESS_GET_PTS_DELAY:
984 pi_64 = (int64_t*)va_arg( args, int64_t * );
985 *pi_64 = INT64_C(1000)
986 * var_InheritInteger( p_access, "network-caching" );
990 case ACCESS_SET_PAUSE_STATE:
993 case ACCESS_GET_META:
994 p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t* );
996 if( p_sys->psz_icy_name )
997 vlc_meta_Set( p_meta, vlc_meta_Title, p_sys->psz_icy_name );
998 if( p_sys->psz_icy_genre )
999 vlc_meta_Set( p_meta, vlc_meta_Genre, p_sys->psz_icy_genre );
1000 if( p_sys->psz_icy_title )
1001 vlc_meta_Set( p_meta, vlc_meta_NowPlaying, p_sys->psz_icy_title );
1004 case ACCESS_GET_CONTENT_TYPE:
1005 *va_arg( args, char ** ) =
1006 p_sys->psz_mime ? strdup( p_sys->psz_mime ) : NULL;
1009 case ACCESS_GET_TITLE_INFO:
1010 case ACCESS_SET_TITLE:
1011 case ACCESS_SET_SEEKPOINT:
1012 case ACCESS_SET_PRIVATE_ID_STATE:
1013 return VLC_EGENERIC;
1016 msg_Warn( p_access, "unimplemented query in control" );
1017 return VLC_EGENERIC;
1023 /*****************************************************************************
1025 *****************************************************************************/
1026 static int Connect( access_t *p_access, uint64_t i_tell )
1028 access_sys_t *p_sys = p_access->p_sys;
1029 vlc_url_t srv = p_sys->b_proxy ? p_sys->proxy : p_sys->url;
1032 free( p_sys->psz_location );
1033 free( p_sys->psz_mime );
1034 free( p_sys->psz_pragma );
1036 free( p_sys->psz_icy_genre );
1037 free( p_sys->psz_icy_name );
1038 free( p_sys->psz_icy_title );
1041 p_sys->psz_location = NULL;
1042 p_sys->psz_mime = NULL;
1043 p_sys->psz_pragma = NULL;
1044 p_sys->b_mms = false;
1045 p_sys->b_chunked = false;
1047 p_sys->i_icy_meta = 0;
1048 p_sys->i_icy_offset = i_tell;
1049 p_sys->psz_icy_name = NULL;
1050 p_sys->psz_icy_genre = NULL;
1051 p_sys->psz_icy_title = NULL;
1052 p_sys->i_remaining = 0;
1053 p_sys->b_persist = false;
1054 p_sys->b_has_size = false;
1055 p_access->info.i_size = 0;
1056 p_access->info.i_pos = i_tell;
1057 p_access->info.b_eof = false;
1059 /* Open connection */
1060 assert( p_sys->fd == -1 ); /* No open sockets (leaking fds is BAD) */
1061 p_sys->fd = net_ConnectTCP( p_access, srv.psz_host, srv.i_port );
1062 if( p_sys->fd == -1 )
1064 msg_Err( p_access, "cannot connect to %s:%d", srv.psz_host, srv.i_port );
1067 setsockopt (p_sys->fd, SOL_SOCKET, SO_KEEPALIVE, &(int){ 1 }, sizeof (int));
1069 /* Initialize TLS/SSL session */
1070 if( p_sys->p_creds != NULL )
1072 /* CONNECT to establish TLS tunnel through HTTP proxy */
1073 if( p_sys->b_proxy )
1076 unsigned i_status = 0;
1078 if( p_sys->i_version == 0 )
1080 /* CONNECT is not in HTTP/1.0 */
1081 Disconnect( p_access );
1085 net_Printf( p_access, p_sys->fd, NULL,
1086 "CONNECT %s:%d HTTP/1.%d\r\nHost: %s:%d\r\n\r\n",
1087 p_sys->url.psz_host, p_sys->url.i_port,
1089 p_sys->url.psz_host, p_sys->url.i_port);
1091 psz = net_Gets( p_access, p_sys->fd, NULL );
1094 msg_Err( p_access, "cannot establish HTTP/TLS tunnel" );
1095 Disconnect( p_access );
1099 sscanf( psz, "HTTP/%*u.%*u %3u", &i_status );
1102 if( ( i_status / 100 ) != 2 )
1104 msg_Err( p_access, "HTTP/TLS tunnel through proxy denied" );
1105 Disconnect( p_access );
1111 psz = net_Gets( p_access, p_sys->fd, NULL );
1114 msg_Err( p_access, "HTTP proxy connection failed" );
1115 Disconnect( p_access );
1124 if( !vlc_object_alive (p_access) || p_sys->b_error )
1126 Disconnect( p_access );
1133 /* TLS/SSL handshake */
1134 p_sys->p_tls = vlc_tls_ClientSessionCreate( p_sys->p_creds, p_sys->fd,
1135 p_sys->url.psz_host, "https" );
1136 if( p_sys->p_tls == NULL )
1138 msg_Err( p_access, "cannot establish HTTP/TLS session" );
1139 Disconnect( p_access );
1142 p_sys->p_vs = &p_sys->p_tls->sock;
1145 return Request( p_access, i_tell ) ? -2 : 0;
1149 static int Request( access_t *p_access, uint64_t i_tell )
1151 access_sys_t *p_sys = p_access->p_sys;
1153 v_socket_t *pvs = p_sys->p_vs;
1154 p_sys->b_persist = false;
1156 p_sys->i_remaining = 0;
1158 const char *psz_path = p_sys->url.psz_path;
1159 if( !psz_path || !*psz_path )
1161 if( p_sys->b_proxy && pvs == NULL )
1162 net_Printf( p_access, p_sys->fd, NULL,
1163 "GET http://%s:%d%s HTTP/1.%d\r\n",
1164 p_sys->url.psz_host, p_sys->url.i_port,
1165 psz_path, p_sys->i_version );
1167 net_Printf( p_access, p_sys->fd, pvs, "GET %s HTTP/1.%d\r\n",
1168 psz_path, p_sys->i_version );
1169 if( p_sys->url.i_port != (pvs ? 443 : 80) )
1170 net_Printf( p_access, p_sys->fd, pvs, "Host: %s:%d\r\n",
1171 p_sys->url.psz_host, p_sys->url.i_port );
1173 net_Printf( p_access, p_sys->fd, pvs, "Host: %s\r\n",
1174 p_sys->url.psz_host );
1176 net_Printf( p_access, p_sys->fd, pvs, "User-Agent: %s\r\n",
1177 p_sys->psz_user_agent );
1179 if (p_sys->psz_referrer)
1181 net_Printf( p_access, p_sys->fd, pvs, "Referer: %s\r\n",
1182 p_sys->psz_referrer);
1185 if( p_sys->i_version == 1 && ! p_sys->b_continuous )
1187 p_sys->b_persist = true;
1188 net_Printf( p_access, p_sys->fd, pvs,
1189 "Range: bytes=%"PRIu64"-\r\n", i_tell );
1190 net_Printf( p_access, p_sys->fd, pvs, "Connection: close\r\n" );
1194 if( p_sys->cookies )
1197 for( i = 0; i < vlc_array_count( p_sys->cookies ); i++ )
1199 const char * cookie = vlc_array_item_at_index( p_sys->cookies, i );
1200 char * psz_cookie_content = cookie_get_content( cookie );
1201 char * psz_cookie_domain = cookie_get_domain( cookie );
1203 assert( psz_cookie_content );
1205 /* FIXME: This is clearly not conforming to the rfc */
1206 bool is_in_right_domain = (!psz_cookie_domain || strstr( p_sys->url.psz_host, psz_cookie_domain ));
1208 if( is_in_right_domain )
1210 msg_Dbg( p_access, "Sending Cookie %s", psz_cookie_content );
1211 if( net_Printf( p_access, p_sys->fd, pvs, "Cookie: %s\r\n", psz_cookie_content ) < 0 )
1212 msg_Err( p_access, "failed to send Cookie" );
1214 free( psz_cookie_content );
1215 free( psz_cookie_domain );
1219 /* Authentication */
1220 if( p_sys->url.psz_username || p_sys->url.psz_password )
1221 AuthReply( p_access, "", &p_sys->url, &p_sys->auth );
1223 /* Proxy Authentication */
1224 if( p_sys->proxy.psz_username || p_sys->proxy.psz_password )
1225 AuthReply( p_access, "Proxy-", &p_sys->proxy, &p_sys->proxy_auth );
1227 /* ICY meta data request */
1228 net_Printf( p_access, p_sys->fd, pvs, "Icy-MetaData: 1\r\n" );
1231 if( net_Printf( p_access, p_sys->fd, pvs, "\r\n" ) < 0 )
1233 msg_Err( p_access, "failed to send request" );
1234 Disconnect( p_access );
1235 return VLC_EGENERIC;
1239 if( ( psz = net_Gets( p_access, p_sys->fd, pvs ) ) == NULL )
1241 msg_Err( p_access, "failed to read answer" );
1244 if( !strncmp( psz, "HTTP/1.", 7 ) )
1246 p_sys->psz_protocol = "HTTP";
1247 p_sys->i_code = atoi( &psz[9] );
1249 else if( !strncmp( psz, "ICY", 3 ) )
1251 p_sys->psz_protocol = "ICY";
1252 p_sys->i_code = atoi( &psz[4] );
1253 p_sys->b_reconnect = true;
1257 msg_Err( p_access, "invalid HTTP reply '%s'", psz );
1261 msg_Dbg( p_access, "protocol '%s' answer code %d",
1262 p_sys->psz_protocol, p_sys->i_code );
1263 if( !strcmp( p_sys->psz_protocol, "ICY" ) )
1265 p_sys->b_seekable = false;
1267 if( p_sys->i_code != 206 && p_sys->i_code != 401 )
1269 p_sys->b_seekable = false;
1271 /* Authentication error - We'll have to display the dialog */
1272 if( p_sys->i_code == 401 )
1276 /* Other fatal error */
1277 else if( p_sys->i_code >= 400 )
1279 msg_Err( p_access, "error: %s", psz );
1287 char *psz = net_Gets( p_access, p_sys->fd, pvs );
1293 msg_Err( p_access, "failed to read answer" );
1297 if( !vlc_object_alive (p_access) || p_sys->b_error )
1303 /* msg_Dbg( p_input, "Line=%s", psz ); */
1310 if( ( p = strchr( psz, ':' ) ) == NULL )
1312 msg_Err( p_access, "malformed header line: %s", psz );
1317 p += strspn( p, " \t" );
1319 /* trim trailing white space */
1320 p_trailing = p + strlen( p );
1321 if( p_trailing > p )
1324 while( ( *p_trailing == ' ' || *p_trailing == '\t' ) && p_trailing > p )
1331 if( !strcasecmp( psz, "Content-Length" ) )
1333 uint64_t i_size = i_tell + (p_sys->i_remaining = (uint64_t)atoll( p ));
1334 if(i_size > p_access->info.i_size) {
1335 p_sys->b_has_size = true;
1336 p_access->info.i_size = i_size;
1338 msg_Dbg( p_access, "this frame size=%"PRIu64, p_sys->i_remaining );
1340 else if( !strcasecmp( psz, "Content-Range" ) ) {
1341 uint64_t i_ntell = i_tell;
1342 uint64_t i_nend = (p_access->info.i_size > 0)?(p_access->info.i_size - 1):i_tell;
1343 uint64_t i_nsize = p_access->info.i_size;
1344 sscanf(p,"bytes %"SCNu64"-%"SCNu64"/%"SCNu64,&i_ntell,&i_nend,&i_nsize);
1345 if(i_nend > i_ntell ) {
1346 p_access->info.i_pos = i_ntell;
1347 p_sys->i_icy_offset = i_ntell;
1348 p_sys->i_remaining = i_nend+1-i_ntell;
1349 uint64_t i_size = (i_nsize > i_nend) ? i_nsize : (i_nend + 1);
1350 if(i_size > p_access->info.i_size) {
1351 p_sys->b_has_size = true;
1352 p_access->info.i_size = i_size;
1354 msg_Dbg( p_access, "stream size=%"PRIu64",pos=%"PRIu64",remaining=%"PRIu64,
1355 i_nsize, i_ntell, p_sys->i_remaining);
1358 else if( !strcasecmp( psz, "Connection" ) ) {
1359 msg_Dbg( p_access, "Connection: %s",p );
1361 sscanf(p, "close%n",&i);
1363 p_sys->b_persist = false;
1366 else if( !strcasecmp( psz, "Location" ) )
1370 /* This does not follow RFC 2068, but yet if the url is not absolute,
1371 * handle it as everyone does. */
1374 const char *psz_http_ext = p_sys->p_tls ? "s" : "" ;
1376 if( p_sys->url.i_port == ( p_sys->p_tls ? 443 : 80 ) )
1378 if( asprintf(&psz_new_loc, "http%s://%s%s", psz_http_ext,
1379 p_sys->url.psz_host, p) < 0 )
1384 if( asprintf(&psz_new_loc, "http%s://%s:%d%s", psz_http_ext,
1385 p_sys->url.psz_host, p_sys->url.i_port, p) < 0 )
1391 psz_new_loc = strdup( p );
1394 free( p_sys->psz_location );
1395 p_sys->psz_location = psz_new_loc;
1397 else if( !strcasecmp( psz, "Content-Type" ) )
1399 free( p_sys->psz_mime );
1400 p_sys->psz_mime = strdup( p );
1401 msg_Dbg( p_access, "Content-Type: %s", p_sys->psz_mime );
1403 else if( !strcasecmp( psz, "Content-Encoding" ) )
1405 msg_Dbg( p_access, "Content-Encoding: %s", p );
1406 if( !strcasecmp( p, "identity" ) )
1409 else if( !strcasecmp( p, "gzip" ) || !strcasecmp( p, "deflate" ) )
1410 p_sys->b_compressed = true;
1413 msg_Warn( p_access, "Unknown content coding: %s", p );
1415 else if( !strcasecmp( psz, "Pragma" ) )
1417 if( !strcasecmp( psz, "Pragma: features" ) )
1418 p_sys->b_mms = true;
1419 free( p_sys->psz_pragma );
1420 p_sys->psz_pragma = strdup( p );
1421 msg_Dbg( p_access, "Pragma: %s", p_sys->psz_pragma );
1423 else if( !strcasecmp( psz, "Server" ) )
1425 msg_Dbg( p_access, "Server: %s", p );
1426 if( !strncasecmp( p, "Icecast", 7 ) ||
1427 !strncasecmp( p, "Nanocaster", 10 ) )
1429 /* Remember if this is Icecast
1430 * we need to force demux in this case without breaking
1433 /* Let live 365 streams (nanocaster) piggyback on the icecast
1434 * routine. They look very similar */
1436 p_sys->b_reconnect = true;
1437 p_sys->b_pace_control = false;
1438 p_sys->b_icecast = true;
1441 else if( !strcasecmp( psz, "Transfer-Encoding" ) )
1443 msg_Dbg( p_access, "Transfer-Encoding: %s", p );
1444 if( !strncasecmp( p, "chunked", 7 ) )
1446 p_sys->b_chunked = true;
1449 else if( !strcasecmp( psz, "Icy-MetaInt" ) )
1451 msg_Dbg( p_access, "Icy-MetaInt: %s", p );
1452 p_sys->i_icy_meta = atoi( p );
1453 if( p_sys->i_icy_meta < 0 )
1454 p_sys->i_icy_meta = 0;
1455 if( p_sys->i_icy_meta > 0 )
1456 p_sys->b_icecast = true;
1458 msg_Warn( p_access, "ICY metaint=%d", p_sys->i_icy_meta );
1460 else if( !strcasecmp( psz, "Icy-Name" ) )
1462 free( p_sys->psz_icy_name );
1463 char *psz_tmp = strdup( p );
1464 p_sys->psz_icy_name = EnsureUTF8( psz_tmp );
1465 if( !p_sys->psz_icy_name )
1467 msg_Dbg( p_access, "Icy-Name: %s", p_sys->psz_icy_name );
1469 p_sys->b_icecast = true; /* be on the safeside. set it here as well. */
1470 p_sys->b_reconnect = true;
1471 p_sys->b_pace_control = false;
1473 else if( !strcasecmp( psz, "Icy-Genre" ) )
1475 free( p_sys->psz_icy_genre );
1476 char *psz_tmp = strdup( p );
1477 p_sys->psz_icy_genre = EnsureUTF8( psz_tmp );
1478 if( !p_sys->psz_icy_genre )
1480 msg_Dbg( p_access, "Icy-Genre: %s", p_sys->psz_icy_genre );
1482 else if( !strncasecmp( psz, "Icy-Notice", 10 ) )
1484 msg_Dbg( p_access, "Icy-Notice: %s", p );
1486 else if( !strncasecmp( psz, "icy-", 4 ) ||
1487 !strncasecmp( psz, "ice-", 4 ) ||
1488 !strncasecmp( psz, "x-audiocast", 11 ) )
1490 msg_Dbg( p_access, "Meta-Info: %s: %s", psz, p );
1492 else if( !strcasecmp( psz, "Set-Cookie" ) )
1494 if( p_sys->cookies )
1496 msg_Dbg( p_access, "Accepting Cookie: %s", p );
1497 cookie_append( p_sys->cookies, strdup(p) );
1500 msg_Dbg( p_access, "We have a Cookie we won't remember: %s", p );
1502 else if( !strcasecmp( psz, "www-authenticate" ) )
1504 msg_Dbg( p_access, "Authentication header: %s", p );
1505 http_auth_ParseWwwAuthenticateHeader( VLC_OBJECT(p_access),
1508 else if( !strcasecmp( psz, "proxy-authenticate" ) )
1510 msg_Dbg( p_access, "Proxy authentication header: %s", p );
1511 http_auth_ParseWwwAuthenticateHeader( VLC_OBJECT(p_access),
1512 &p_sys->proxy_auth, p );
1514 else if( !strcasecmp( psz, "authentication-info" ) )
1516 msg_Dbg( p_access, "Authentication Info header: %s", p );
1517 if( AuthCheckReply( p_access, p, &p_sys->url, &p_sys->auth ) )
1520 else if( !strcasecmp( psz, "proxy-authentication-info" ) )
1522 msg_Dbg( p_access, "Proxy Authentication Info header: %s", p );
1523 if( AuthCheckReply( p_access, p, &p_sys->proxy, &p_sys->proxy_auth ) )
1526 else if( !strcasecmp( psz, "Accept-Ranges" ) )
1528 if( !strcasecmp( p, "bytes" ) )
1529 p_sys->b_seekable = true;
1534 /* We close the stream for zero length data, unless of course the
1535 * server has already promised to do this for us.
1537 if( p_sys->b_has_size && p_sys->i_remaining == 0 && p_sys->b_persist ) {
1538 Disconnect( p_access );
1543 Disconnect( p_access );
1544 return VLC_EGENERIC;
1547 /*****************************************************************************
1549 *****************************************************************************/
1550 static void Disconnect( access_t *p_access )
1552 access_sys_t *p_sys = p_access->p_sys;
1554 if( p_sys->p_tls != NULL)
1556 vlc_tls_SessionDelete( p_sys->p_tls );
1557 p_sys->p_tls = NULL;
1560 if( p_sys->fd != -1)
1562 net_Close(p_sys->fd);
1568 /*****************************************************************************
1569 * Cookies (FIXME: we may want to rewrite that using a nice structure to hold
1570 * them) (FIXME: only support the "domain=" param)
1571 *****************************************************************************/
1573 /* Get the NAME=VALUE part of the Cookie */
1574 static char * cookie_get_content( const char * cookie )
1576 char * ret = strdup( cookie );
1577 if( !ret ) return NULL;
1579 /* Look for a ';' */
1580 while( *str && *str != ';' ) str++;
1581 /* Replace it by a end-char */
1582 if( *str == ';' ) *str = 0;
1586 /* Get the domain where the cookie is stored */
1587 static char * cookie_get_domain( const char * cookie )
1589 const char * str = cookie;
1590 static const char domain[] = "domain=";
1593 /* Look for a ';' */
1596 if( !strncmp( str, domain, sizeof(domain) - 1 /* minus \0 */ ) )
1598 str += sizeof(domain) - 1 /* minus \0 */;
1599 char * ret = strdup( str );
1600 /* Now remove the next ';' if present */
1601 char * ret_iter = ret;
1602 while( *ret_iter && *ret_iter != ';' ) ret_iter++;
1603 if( *ret_iter == ';' )
1607 /* Go to next ';' field */
1608 while( *str && *str != ';' ) str++;
1609 if( *str == ';' ) str++;
1611 while( *str && *str == ' ' ) str++;
1616 /* Get NAME in the NAME=VALUE field */
1617 static char * cookie_get_name( const char * cookie )
1619 char * ret = cookie_get_content( cookie ); /* NAME=VALUE */
1620 if( !ret ) return NULL;
1622 while( *str && *str != '=' ) str++;
1627 /* Add a cookie in cookies, checking to see how it should be added */
1628 static void cookie_append( vlc_array_t * cookies, char * cookie )
1635 char * cookie_name = cookie_get_name( cookie );
1637 /* Don't send invalid cookies */
1641 char * cookie_domain = cookie_get_domain( cookie );
1642 for( i = 0; i < vlc_array_count( cookies ); i++ )
1644 char * current_cookie = vlc_array_item_at_index( cookies, i );
1645 char * current_cookie_name = cookie_get_name( current_cookie );
1646 char * current_cookie_domain = cookie_get_domain( current_cookie );
1648 assert( current_cookie_name );
1650 bool is_domain_matching = (
1651 ( !cookie_domain && !current_cookie_domain ) ||
1652 ( cookie_domain && current_cookie_domain &&
1653 !strcmp( cookie_domain, current_cookie_domain ) ) );
1655 if( is_domain_matching && !strcmp( cookie_name, current_cookie_name ) )
1657 /* Remove previous value for this cookie */
1658 free( current_cookie );
1659 vlc_array_remove( cookies, i );
1662 free( current_cookie_name );
1663 free( current_cookie_domain );
1666 free( current_cookie_name );
1667 free( current_cookie_domain );
1669 free( cookie_name );
1670 free( cookie_domain );
1671 vlc_array_append( cookies, cookie );
1675 /*****************************************************************************
1676 * HTTP authentication
1677 *****************************************************************************/
1679 static void AuthReply( access_t *p_access, const char *psz_prefix,
1680 vlc_url_t *p_url, http_auth_t *p_auth )
1682 access_sys_t *p_sys = p_access->p_sys;
1686 http_auth_FormatAuthorizationHeader( VLC_OBJECT(p_access), p_auth,
1687 "GET", p_url->psz_path,
1688 p_url->psz_username,
1689 p_url->psz_password );
1690 if ( psz_value == NULL )
1693 net_Printf( p_access, p_sys->fd, p_sys->p_vs,
1694 "%sAuthorization: %s\r\n", psz_prefix, psz_value );
1698 static int AuthCheckReply( access_t *p_access, const char *psz_header,
1699 vlc_url_t *p_url, http_auth_t *p_auth )
1702 http_auth_ParseAuthenticationInfoHeader( VLC_OBJECT(p_access), p_auth,
1705 p_url->psz_username,
1706 p_url->psz_password );