X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fhttp.c;h=d0a53d7a84af85189bd0e10fa55745a2ef97a1db;hb=69d7fdea2da6f773fd7993f78c2bea494eb2d819;hp=f052d246ee3a87b842ca3146efc602bf93754167;hpb=d58211076fb937d2374ef4191ec1252004d86d1f;p=vlc diff --git a/modules/access/http.c b/modules/access/http.c index f052d246ee..d0a53d7a84 100644 --- a/modules/access/http.c +++ b/modules/access/http.c @@ -123,8 +123,8 @@ vlc_module_begin () add_integer( "http-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, true ) change_safe() - add_string( "http-user-agent", COPYRIGHT_MESSAGE , NULL, AGENT_TEXT, - AGENT_LONGTEXT, true ) + add_string( "http-user-agent", PACKAGE_NAME" "PACKAGE_VERSION, NULL, + AGENT_TEXT, AGENT_LONGTEXT, true ) change_safe() add_bool( "http-reconnect", false, NULL, RECONNECT_TEXT, RECONNECT_LONGTEXT, true ) @@ -449,7 +449,7 @@ static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access, "in registry." ); } } -#elif HAVE_GETENV +#elif defined( HAVE_GETENV ) else { psz = getenv( "http_proxy" ); @@ -481,8 +481,9 @@ static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access, } } - msg_Dbg( p_access, "http: server='%s' port=%d file='%s", - p_sys->url.psz_host, p_sys->url.i_port, p_sys->url.psz_path ); + msg_Dbg( p_access, "http: server='%s' port=%d file='%s'", + p_sys->url.psz_host, p_sys->url.i_port, + p_sys->url.psz_path != NULL ? p_sys->url.psz_path : "" ); if( p_sys->b_proxy ) { msg_Dbg( p_access, " proxy %s:%d", p_sys->proxy.psz_host, @@ -761,14 +762,16 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) return 0; } - if( p_sys->b_has_size && - i_len + p_access->info.i_pos > p_access->info.i_size ) + if( p_sys->b_has_size ) { - if( ( i_len = p_access->info.i_size - p_access->info.i_pos ) == 0 ) - { - p_access->info.b_eof = true; - return 0; - } + /* Remaining bytes in the file */ + uint64_t remainder = p_access->info.i_size - p_access->info.i_pos; + if( remainder < i_len ) + i_len = remainder; + + /* Remaining bytes in the response */ + if( p_sys->i_remaining < i_len ) + i_len = p_sys->i_remaining; } if( p_sys->b_chunked ) @@ -801,19 +804,14 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) } if( i_len > p_sys->i_chunk ) - { i_len = p_sys->i_chunk; - } - } - else if( p_sys->b_has_size && i_len > p_sys->i_remaining) { - /* Only ask for the remaining length */ - i_len = p_sys->i_remaining; - if(i_len == 0) { - p_access->info.b_eof = true; - return 0; - } } + if( i_len == 0 ) + { + p_access->info.b_eof = true; + return 0; + } if( p_sys->i_icy_meta > 0 && p_access->info.i_pos-p_sys->i_icy_offset > 0 ) { @@ -836,8 +834,6 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) if( i_read > 0 ) { - p_access->info.i_pos += i_read; - if( p_sys->b_chunked ) { p_sys->i_chunk -= i_read; @@ -849,7 +845,7 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) } } } - else if( i_read <= 0 ) + else { /* * I very much doubt that this will work. @@ -877,18 +873,26 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) p_sys->b_reconnect = false; i_read = Read( p_access, p_buffer, i_len ); p_sys->b_reconnect = true; + + return i_read; } } - if( i_read == 0 ) + if( i_read <= 0 ) + { p_access->info.b_eof = true; - if( i_read < 0 ) - p_sys->b_error = true; + if( i_read < 0 ) + p_sys->b_error = true; + return 0; + } } + assert( i_read >= 0 ); + p_access->info.i_pos += i_read; if( p_sys->b_has_size ) { - assert( i_read <= p_sys->i_remaining ); + assert( p_access->info.i_pos <= p_access->info.i_size ); + assert( (unsigned)i_read <= p_sys->i_remaining ); p_sys->i_remaining -= i_read; } @@ -1164,7 +1168,7 @@ static int Connect( access_t *p_access, uint64_t i_tell ) return -1; } - net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, + net_Printf( p_access, p_sys->fd, NULL, "CONNECT %s:%d HTTP/1.%d\r\nHost: %s:%d\r\n\r\n", p_sys->url.psz_host, p_sys->url.i_port, p_sys->i_version, @@ -1240,14 +1244,14 @@ static int Request( access_t *p_access, uint64_t i_tell ) { if( p_sys->url.psz_path ) { - net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, + net_Printf( p_access, p_sys->fd, NULL, "GET http://%s:%d%s HTTP/1.%d\r\n", p_sys->url.psz_host, p_sys->url.i_port, p_sys->url.psz_path, p_sys->i_version ); } else { - net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, + net_Printf( p_access, p_sys->fd, NULL, "GET http://%s:%d/ HTTP/1.%d\r\n", p_sys->url.psz_host, p_sys->url.i_port, p_sys->i_version ); @@ -1262,26 +1266,26 @@ static int Request( access_t *p_access, uint64_t i_tell ) } if( p_sys->url.i_port != (pvs ? 443 : 80) ) { - net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, + net_Printf( p_access, p_sys->fd, pvs, "GET %s HTTP/1.%d\r\nHost: %s:%d\r\n", psz_path, p_sys->i_version, p_sys->url.psz_host, p_sys->url.i_port ); } else { - net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, + net_Printf( p_access, p_sys->fd, pvs, "GET %s HTTP/1.%d\r\nHost: %s\r\n", psz_path, p_sys->i_version, p_sys->url.psz_host ); } } /* User Agent */ - net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "User-Agent: %s\r\n", + net_Printf( p_access, p_sys->fd, pvs, "User-Agent: %s\r\n", p_sys->psz_user_agent ); /* Offset */ if( p_sys->i_version == 1 && ! p_sys->b_continuous ) { p_sys->b_persist = true; - net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, + net_Printf( p_access, p_sys->fd, pvs, "Range: bytes=%"PRIu64"-\r\n", i_tell ); } @@ -1303,7 +1307,7 @@ static int Request( access_t *p_access, uint64_t i_tell ) if( is_in_right_domain ) { msg_Dbg( p_access, "Sending Cookie %s", psz_cookie_content ); - if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "Cookie: %s\r\n", psz_cookie_content ) < 0 ) + if( net_Printf( p_access, p_sys->fd, pvs, "Cookie: %s\r\n", psz_cookie_content ) < 0 ) msg_Err( p_access, "failed to send Cookie" ); } free( psz_cookie_content ); @@ -1320,10 +1324,10 @@ static int Request( access_t *p_access, uint64_t i_tell ) AuthReply( p_access, "Proxy-", &p_sys->proxy, &p_sys->proxy_auth ); /* ICY meta data request */ - net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "Icy-MetaData: 1\r\n" ); + net_Printf( p_access, p_sys->fd, pvs, "Icy-MetaData: 1\r\n" ); - if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "\r\n" ) < 0 ) + if( net_Printf( p_access, p_sys->fd, pvs, "\r\n" ) < 0 ) { msg_Err( p_access, "failed to send request" ); Disconnect( p_access ); @@ -1426,6 +1430,7 @@ static int Request( access_t *p_access, uint64_t i_tell ) sscanf(p,"bytes %"SCNu64"-%"SCNu64"/%"SCNu64,&i_ntell,&i_nend,&i_nsize); if(i_nend > i_ntell ) { p_access->info.i_pos = i_ntell; + p_sys->i_icy_offset = i_ntell; p_sys->i_remaining = i_nend+1-i_ntell; int64_t i_size = (i_nsize > i_nend) ? i_nsize : (i_nend + 1); if(i_size > p_access->info.i_size) { @@ -1764,7 +1769,7 @@ static void AuthReply( access_t *p_access, const char *psz_prefix, if ( psz_value == NULL ) return; - net_Printf( VLC_OBJECT(p_access), p_sys->fd, p_sys->p_vs, + net_Printf( p_access, p_sys->fd, p_sys->p_vs, "%sAuthorization: %s\r\n", psz_prefix, psz_value ); free( psz_value ); }