* http.c: HTTP access plug-in
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
- * $Id: http.c,v 1.3 2002/08/08 00:35:10 sam Exp $
+ * $Id: http.c,v 1.7 2002/11/08 10:26:52 gbazin Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
vlc_module_begin();
set_description( _("HTTP access module") );
set_capability( "access", 0 );
+ add_shortcut( "http" );
add_shortcut( "http4" );
add_shortcut( "http6" );
set_callbacks( Open, Close );
module_t * p_network;
char psz_buffer[256];
byte_t * psz_parser;
- int i_returncode, i;
+ int i_returncode, i, i_size;
char * psz_return_alpha;
/* Find an appropriate network module */
{
snprintf( psz_buffer, sizeof(psz_buffer),
"%s"
- "Range: bytes=%d%d-\r\n"
+ "Range: bytes="I64Fd"-\r\n"
HTTP_USERAGENT HTTP_END,
- p_access_data->psz_buffer,
- (u32)(i_tell>>32), (u32)i_tell );
+ p_access_data->psz_buffer, i_tell );
}
else
{
#define MAX_LINE 1024
/* get the returncode */
- if( input_Peek( p_input, &psz_parser, MAX_LINE ) <= 0 )
+ if( (i_size = input_Peek( p_input, &psz_parser, MAX_LINE )) <= 0 )
{
msg_Err( p_input, "not enough data" );
input_FDNetworkClose( p_input );
return( -1 );
}
- if( !strncmp( psz_parser, "HTTP/1.",
- strlen("HTTP/1.") ) )
+ if( (i_size >= sizeof("HTTP/1.") + 1 ) &&
+ !strncmp( psz_parser, "HTTP/1.", sizeof("HTTP/1.") - 1 ) )
{
- psz_parser += strlen("HTTP 1.") + 2;
+ psz_parser += sizeof("HTTP/1.") + 1;
i_returncode = atoi( (char*)psz_parser );
msg_Dbg( p_input, "HTTP server replied: %i", i_returncode );
psz_parser += 4;
- for ( i = 0; psz_parser[i] != '\r' || psz_parser[i+1] != '\n'; i++ )
+ i_size -= (sizeof("HTTP/1.") + 5);
+ for ( i = 0; (i < i_size -1) && ((psz_parser[i] != '\r') ||
+ (psz_parser[i+1] != '\n')); i++ )
{
;
}
+ /* check we actually parsed something */
+ if ( (i == i_size - 1) && (psz_parser[i+1] != '\n') )
+ {
+ msg_Err( p_input, "stream not compliant with HTTP/1.x" );
+ return -1;
+ }
+
psz_return_alpha = malloc( i + 1 );
memcpy( psz_return_alpha, psz_parser, i );
psz_return_alpha[i] = '\0';
msg_Err( p_input, "invalid http reply" );
return -1;
}
-
+
if ( i_returncode >= 400 ) /* something is wrong */
{
msg_Err( p_input, "%i %s", i_returncode,
{
_input_socket_t *p_access_data = (_input_socket_t*)p_input->p_access_data;
close( p_access_data->_socket.i_handle );
- msg_Dbg( p_input, "seeking to position %lld", i_pos );
+ msg_Dbg( p_input, "seeking to position "I64Fd, i_pos );
HTTPConnect( p_input, i_pos );
}