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

net_* API update for encryption (recv / send virtualization)

parent 211bbb87
...@@ -209,6 +209,8 @@ static inline char *vlc_b64_encode( unsigned char *src ) ...@@ -209,6 +209,8 @@ static inline char *vlc_b64_encode( unsigned char *src )
return ret; return ret;
} }
/* Portable networking layer communication */
#define net_OpenTCP(a, b, c) __net_OpenTCP(VLC_OBJECT(a), b, c) #define net_OpenTCP(a, b, c) __net_OpenTCP(VLC_OBJECT(a), b, c)
VLC_EXPORT( int, __net_OpenTCP, ( vlc_object_t *p_this, const char *psz_host, int i_port ) ); VLC_EXPORT( int, __net_OpenTCP, ( vlc_object_t *p_this, const char *psz_host, int i_port ) );
...@@ -223,23 +225,31 @@ VLC_EXPORT( int, __net_OpenUDP, ( vlc_object_t *p_this, char *psz_bind, int i_bi ...@@ -223,23 +225,31 @@ VLC_EXPORT( int, __net_OpenUDP, ( vlc_object_t *p_this, char *psz_bind, int i_bi
VLC_EXPORT( void, net_Close, ( int fd ) ); VLC_EXPORT( void, net_Close, ( int fd ) );
#define net_Read(a,b,c,d,e) __net_Read(VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __net_Read, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, vlc_bool_t b_retry ) );
#define net_ReadNonBlock(a,b,c,d,e) __net_ReadNonBlock(VLC_OBJECT(a),b,c,d,e) /* Functions to read from or write to the networking layer */
VLC_EXPORT( int, __net_ReadNonBlock, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, mtime_t i_wait ) ); struct virtual_socket_t
{
void *p_sys;
int (*pf_recv) ( void *, void *, int );
int (*pf_send) ( void *, const void *, int );
};
#define net_Read(a,b,c,d,e,f) __net_Read(VLC_OBJECT(a),b,c,d,e,f)
VLC_EXPORT( int, __net_Read, ( vlc_object_t *p_this, int fd, v_socket_t *, uint8_t *p_data, int i_data, vlc_bool_t b_retry ) );
#define net_Select(a,b,c,d,e,f) __net_Select(VLC_OBJECT(a),b,c,d,e,f) #define net_ReadNonBlock(a,b,c,d,e,f) __net_ReadNonBlock(VLC_OBJECT(a),b,c,d,e,f)
VLC_EXPORT( int, __net_Select, ( vlc_object_t *p_this, int *pi_fd, int i_fd,uint8_t *p_data, int i_data, mtime_t i_wait ) ); VLC_EXPORT( int, __net_ReadNonBlock, ( vlc_object_t *p_this, int fd, v_socket_t *, uint8_t *p_data, int i_data, mtime_t i_wait ) );
#define net_Select(a,b,c,d,e,f,g) __net_Select(VLC_OBJECT(a),b,c,d,e,f,g)
VLC_EXPORT( int, __net_Select, ( vlc_object_t *p_this, int *pi_fd, v_socket_t **, int i_fd, uint8_t *p_data, int i_data, mtime_t i_wait ) );
#define net_Write(a,b,c,d) __net_Write(VLC_OBJECT(a),b,c,d) #define net_Write(a,b,c,d,e) __net_Write(VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __net_Write, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data ) ); VLC_EXPORT( int, __net_Write, ( vlc_object_t *p_this, int fd, v_socket_t *, uint8_t *p_data, int i_data ) );
#define net_Gets(a,b) __net_Gets(VLC_OBJECT(a),b) #define net_Gets(a,b,c) __net_Gets(VLC_OBJECT(a),b,c)
VLC_EXPORT( char *, __net_Gets, ( vlc_object_t *p_this, int fd ) ); VLC_EXPORT( char *, __net_Gets, ( vlc_object_t *p_this, int fd, v_socket_t * ) );
VLC_EXPORT( int, net_Printf, ( vlc_object_t *p_this, int fd, const char *psz_fmt, ... ) ); VLC_EXPORT( int, net_Printf, ( vlc_object_t *p_this, int fd, v_socket_t *, const char *psz_fmt, ... ) );
#define net_vaPrintf(a,b,c,d) __net_vaPrintf(VLC_OBJECT(a),b,c,d) #define net_vaPrintf(a,b,c,d,e) __net_vaPrintf(VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __net_vaPrintf, ( vlc_object_t *p_this, int fd, const char *psz_fmt, va_list args ) ); VLC_EXPORT( int, __net_vaPrintf, ( vlc_object_t *p_this, int fd, v_socket_t *, const char *psz_fmt, va_list args ) );
...@@ -340,6 +340,7 @@ typedef struct data_buffer_t data_buffer_t; ...@@ -340,6 +340,7 @@ typedef struct data_buffer_t data_buffer_t;
typedef struct stream_ctrl_t stream_ctrl_t; typedef struct stream_ctrl_t stream_ctrl_t;
typedef struct pes_packet_t pes_packet_t; typedef struct pes_packet_t pes_packet_t;
typedef struct network_socket_t network_socket_t; typedef struct network_socket_t network_socket_t;
typedef struct virtual_socket_t v_socket_t;
typedef struct iso639_lang_t iso639_lang_t; typedef struct iso639_lang_t iso639_lang_t;
/* block */ /* block */
......
...@@ -319,7 +319,8 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ) ...@@ -319,7 +319,8 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
if( p_access->info.b_eof ) if( p_access->info.b_eof )
return 0; return 0;
i_read = net_Read( p_access, p_sys->fd_data, p_buffer, i_len, VLC_FALSE ); i_read = net_Read( p_access, p_sys->fd_data, NULL, p_buffer, i_len,
VLC_FALSE );
if( i_read == 0 ) if( i_read == 0 )
p_access->info.b_eof = VLC_TRUE; p_access->info.b_eof = VLC_TRUE;
else if( i_read > 0 ) else if( i_read > 0 )
...@@ -404,10 +405,11 @@ static int ftp_SendCommand( access_t *p_access, char *psz_fmt, ... ) ...@@ -404,10 +405,11 @@ static int ftp_SendCommand( access_t *p_access, char *psz_fmt, ... )
va_end( args ); va_end( args );
msg_Dbg( p_access, "ftp_SendCommand:\"%s\"", psz_cmd); msg_Dbg( p_access, "ftp_SendCommand:\"%s\"", psz_cmd);
if( ( i_ret = net_Printf( VLC_OBJECT(p_access), p_sys->fd_cmd, if( ( i_ret = net_Printf( VLC_OBJECT(p_access), p_sys->fd_cmd, NULL,
"%s", psz_cmd ) ) > 0 ) "%s", psz_cmd ) ) > 0 )
{ {
i_ret = net_Printf( VLC_OBJECT(p_access), p_sys->fd_cmd, "\r\n" ); i_ret = net_Printf( VLC_OBJECT(p_access), p_sys->fd_cmd, NULL,
"\r\n" );
} }
if( i_ret < 0 ) if( i_ret < 0 )
...@@ -440,7 +442,7 @@ static int ftp_ReadCommand( access_t *p_access, ...@@ -440,7 +442,7 @@ static int ftp_ReadCommand( access_t *p_access,
char *psz_line; char *psz_line;
int i_answer; int i_answer;
psz_line = net_Gets( p_access, p_sys->fd_cmd ); psz_line = net_Gets( p_access, p_sys->fd_cmd, NULL );
msg_Dbg( p_access, "answer=%s", psz_line ); msg_Dbg( p_access, "answer=%s", psz_line );
if( psz_line == NULL || strlen( psz_line ) < 3 ) if( psz_line == NULL || strlen( psz_line ) < 3 )
{ {
...@@ -460,7 +462,7 @@ static int ftp_ReadCommand( access_t *p_access, ...@@ -460,7 +462,7 @@ static int ftp_ReadCommand( access_t *p_access,
for( ;; ) for( ;; )
{ {
char *psz_tmp = net_Gets( p_access, p_sys->fd_cmd ); char *psz_tmp = net_Gets( p_access, p_sys->fd_cmd, NULL );
if( psz_tmp == NULL ) /* Error */ if( psz_tmp == NULL ) /* Error */
break; break;
......
...@@ -415,7 +415,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ) ...@@ -415,7 +415,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
if( p_sys->i_chunk <= 0 ) if( p_sys->i_chunk <= 0 )
{ {
char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ); char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
/* read the chunk header */ /* read the chunk header */
if( psz == NULL ) if( psz == NULL )
{ {
...@@ -440,7 +440,8 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ) ...@@ -440,7 +440,8 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
} }
i_read = net_Read( p_access, p_sys->fd, p_buffer, i_len, VLC_FALSE ); i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
VLC_FALSE );
if( i_read > 0 ) if( i_read > 0 )
{ {
p_access->info.i_pos += i_read; p_access->info.i_pos += i_read;
...@@ -451,7 +452,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ) ...@@ -451,7 +452,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
if( p_sys->i_chunk <= 0 ) if( p_sys->i_chunk <= 0 )
{ {
/* read the empty line */ /* read the empty line */
char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ); char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
if( psz ) free( psz ); if( psz ) free( psz );
} }
} }
...@@ -642,14 +643,14 @@ static int Connect( access_t *p_access, int64_t i_tell ) ...@@ -642,14 +643,14 @@ static int Connect( access_t *p_access, int64_t i_tell )
{ {
if( p_sys->url.psz_path ) if( p_sys->url.psz_path )
{ {
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET http://%s:%d%s HTTP/1.%d\r\n", "GET http://%s:%d%s HTTP/1.%d\r\n",
p_sys->url.psz_host, p_sys->url.i_port, p_sys->url.psz_host, p_sys->url.i_port,
p_sys->url.psz_path, p_sys->i_version ); p_sys->url.psz_path, p_sys->i_version );
} }
else else
{ {
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET http://%s:%d/ HTTP/1.%d\r\n", "GET http://%s:%d/ HTTP/1.%d\r\n",
p_sys->url.psz_host, p_sys->url.i_port, p_sys->url.psz_host, p_sys->url.i_port,
p_sys->i_version ); p_sys->i_version );
...@@ -664,25 +665,25 @@ static int Connect( access_t *p_access, int64_t i_tell ) ...@@ -664,25 +665,25 @@ static int Connect( access_t *p_access, int64_t i_tell )
} }
if( p_sys->url.i_port != 80) if( p_sys->url.i_port != 80)
{ {
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET %s HTTP/1.%d\r\nHost: %s:%d\r\n", "GET %s HTTP/1.%d\r\nHost: %s:%d\r\n",
psz_path, p_sys->i_version, p_sys->url.psz_host, psz_path, p_sys->i_version, p_sys->url.psz_host,
p_sys->url.i_port ); p_sys->url.i_port );
} }
else else
{ {
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET %s HTTP/1.%d\r\nHost: %s\r\n", "GET %s HTTP/1.%d\r\nHost: %s\r\n",
psz_path, p_sys->i_version, p_sys->url.psz_host ); psz_path, p_sys->i_version, p_sys->url.psz_host );
} }
} }
/* User Agent */ /* User Agent */
net_Printf( VLC_OBJECT(p_access), p_sys->fd, "User-Agent: %s\r\n", net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "User-Agent: %s\r\n",
p_sys->psz_user_agent ); p_sys->psz_user_agent );
/* Offset */ /* Offset */
if( p_sys->i_version == 1 ) if( p_sys->i_version == 1 )
{ {
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Range: bytes="I64Fd"-\r\n", i_tell ); "Range: bytes="I64Fd"-\r\n", i_tell );
} }
/* Authentification */ /* Authentification */
...@@ -696,13 +697,14 @@ static int Connect( access_t *p_access, int64_t i_tell ) ...@@ -696,13 +697,14 @@ static int Connect( access_t *p_access, int64_t i_tell )
b64 = vlc_b64_encode( buf ); b64 = vlc_b64_encode( buf );
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Authorization: Basic %s\r\n", b64 ); "Authorization: Basic %s\r\n", b64 );
free( b64 ); free( b64 );
} }
net_Printf( VLC_OBJECT(p_access), p_sys->fd, "Connection: Close\r\n" ); net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Connection: Close\r\n" );
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" ) < 0 ) if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
{ {
msg_Err( p_access, "failed to send request" ); msg_Err( p_access, "failed to send request" );
net_Close( p_sys->fd ); p_sys->fd = -1; net_Close( p_sys->fd ); p_sys->fd = -1;
...@@ -710,7 +712,7 @@ static int Connect( access_t *p_access, int64_t i_tell ) ...@@ -710,7 +712,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
} }
/* Read Answer */ /* Read Answer */
if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ) ) == NULL ) if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
{ {
msg_Err( p_access, "failed to read answer" ); msg_Err( p_access, "failed to read answer" );
goto error; goto error;
...@@ -752,7 +754,7 @@ static int Connect( access_t *p_access, int64_t i_tell ) ...@@ -752,7 +754,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
for( ;; ) for( ;; )
{ {
char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ); char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
char *p; char *p;
if( psz == NULL ) if( psz == NULL )
......
...@@ -374,7 +374,7 @@ static int Describe( access_t *p_access, char **ppsz_location ) ...@@ -374,7 +374,7 @@ static int Describe( access_t *p_access, char **ppsz_location )
} }
/* send first request */ /* send first request */
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET %s HTTP/1.0\r\n" "GET %s HTTP/1.0\r\n"
"Accept: */*\r\n" "Accept: */*\r\n"
"User-Agent: NSPlayer/4.1.0.3856\r\n" "User-Agent: NSPlayer/4.1.0.3856\r\n"
...@@ -387,14 +387,14 @@ static int Describe( access_t *p_access, char **ppsz_location ) ...@@ -387,14 +387,14 @@ static int Describe( access_t *p_access, char **ppsz_location )
p_sys->i_request_context++, p_sys->i_request_context++,
GUID_PRINT( p_sys->guid ) ); GUID_PRINT( p_sys->guid ) );
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" ) < 0 ) if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
{ {
msg_Err( p_access, "failed to send request" ); msg_Err( p_access, "failed to send request" );
goto error; goto error;
} }
/* Receive the http header */ /* Receive the http header */
if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ) ) == NULL ) if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
{ {
msg_Err( p_access, "failed to read answer" ); msg_Err( p_access, "failed to read answer" );
goto error; goto error;
...@@ -417,7 +417,7 @@ static int Describe( access_t *p_access, char **ppsz_location ) ...@@ -417,7 +417,7 @@ static int Describe( access_t *p_access, char **ppsz_location )
free( psz ); free( psz );
for( ;; ) for( ;; )
{ {
char *psz = net_Gets( p_access, p_sys->fd ); char *psz = net_Gets( p_access, p_sys->fd, NULL );
char *p; char *p;
if( psz == NULL ) if( psz == NULL )
...@@ -575,7 +575,7 @@ static int Start( access_t *p_access, off_t i_pos ) ...@@ -575,7 +575,7 @@ static int Start( access_t *p_access, off_t i_pos )
msg_Err( p_access, "no stream selected" ); msg_Err( p_access, "no stream selected" );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET %s HTTP/1.0\r\n" "GET %s HTTP/1.0\r\n"
"Accept: */*\r\n" "Accept: */*\r\n"
"User-Agent: NSPlayer/4.1.0.3856\r\n" "User-Agent: NSPlayer/4.1.0.3856\r\n"
...@@ -584,19 +584,19 @@ static int Start( access_t *p_access, off_t i_pos ) ...@@ -584,19 +584,19 @@ static int Start( access_t *p_access, off_t i_pos )
p_sys->url.psz_host, p_sys->url.i_port ); p_sys->url.psz_host, p_sys->url.i_port );
if( p_sys->b_broadcast ) if( p_sys->b_broadcast )
{ {
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Pragma: no-cache,rate=1.000000,request-context=%d\r\n", "Pragma: no-cache,rate=1.000000,request-context=%d\r\n",
p_sys->i_request_context++ ); p_sys->i_request_context++ );
} }
else else
{ {
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n", "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n",
(uint32_t)((i_pos >> 32)&0xffffffff), (uint32_t)((i_pos >> 32)&0xffffffff),
(uint32_t)(i_pos&0xffffffff), (uint32_t)(i_pos&0xffffffff),
p_sys->i_request_context++ ); p_sys->i_request_context++ );
} }
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Pragma: xPlayStrm=1\r\n" "Pragma: xPlayStrm=1\r\n"
"Pragma: xClientGUID={"GUID_FMT"}\r\n" "Pragma: xClientGUID={"GUID_FMT"}\r\n"
"Pragma: stream-switch-count=%d\r\n" "Pragma: stream-switch-count=%d\r\n"
...@@ -614,20 +614,21 @@ static int Start( access_t *p_access, off_t i_pos ) ...@@ -614,20 +614,21 @@ static int Start( access_t *p_access, off_t i_pos )
i_select = 0; i_select = 0;
} }
net_Printf( VLC_OBJECT(p_access), p_sys->fd, net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"ffff:%d:%d ", i, i_select ); "ffff:%d:%d ", i, i_select );
} }
} }
net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" ); net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" );
net_Printf( VLC_OBJECT(p_access), p_sys->fd, "Connection: Close\r\n" ); net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Connection: Close\r\n" );
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" ) < 0 ) if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
{ {
msg_Err( p_access, "failed to send request" ); msg_Err( p_access, "failed to send request" );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ) ) == NULL ) if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
{ {
msg_Err( p_access, "cannot read data" ); msg_Err( p_access, "cannot read data" );
return VLC_EGENERIC; return VLC_EGENERIC;
...@@ -644,7 +645,7 @@ static int Start( access_t *p_access, off_t i_pos ) ...@@ -644,7 +645,7 @@ static int Start( access_t *p_access, off_t i_pos )
/* FIXME check HTTP code */ /* FIXME check HTTP code */
for( ;; ) for( ;; )
{ {
char *psz = net_Gets( p_access, p_sys->fd ); char *psz = net_Gets( p_access, p_sys->fd, NULL );
if( psz == NULL ) if( psz == NULL )
{ {
msg_Err( p_access, "cannot read data" ); msg_Err( p_access, "cannot read data" );
...@@ -691,7 +692,7 @@ static int GetPacket( access_t * p_access, chunk_t *p_ck ) ...@@ -691,7 +692,7 @@ static int GetPacket( access_t * p_access, chunk_t *p_ck )
memset( p_ck, 0, sizeof( chunk_t ) ); memset( p_ck, 0, sizeof( chunk_t ) );
/* Read the chunk header */ /* Read the chunk header */
if( net_Read( p_access, p_sys->fd, p_sys->buffer, 12, VLC_TRUE ) < 12 ) if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer, 12, VLC_TRUE ) < 12 )
{ {
/* msg_Err( p_access, "cannot read data" ); */ /* msg_Err( p_access, "cannot read data" ); */
return VLC_EGENERIC; return VLC_EGENERIC;
...@@ -725,7 +726,7 @@ static int GetPacket( access_t * p_access, chunk_t *p_ck ) ...@@ -725,7 +726,7 @@ static int GetPacket( access_t * p_access, chunk_t *p_ck )
} }
if( p_ck->i_data > 0 && if( p_ck->i_data > 0 &&
net_Read( p_access, p_sys->fd, &p_sys->buffer[12], p_ck->i_data, VLC_TRUE ) < p_ck->i_data ) net_Read( p_access, p_sys->fd, NULL, &p_sys->buffer[12], p_ck->i_data, VLC_TRUE ) < p_ck->i_data )
{ {
msg_Err( p_access, "cannot read data" ); msg_Err( p_access, "cannot read data" );
return VLC_EGENERIC; return VLC_EGENERIC;
......
...@@ -155,7 +155,8 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ) ...@@ -155,7 +155,8 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
if( p_access->info.b_eof ) if( p_access->info.b_eof )
return 0; return 0;
i_read = net_Read( p_access, p_sys->fd, p_buffer, i_len, VLC_FALSE ); i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
VLC_FALSE );
if( i_read == 0 ) if( i_read == 0 )
p_access->info.b_eof = VLC_TRUE; p_access->info.b_eof = VLC_TRUE;
else if( i_read > 0 ) else if( i_read > 0 )
......
...@@ -313,7 +313,9 @@ static block_t *BlockUDP( access_t *p_access ) ...@@ -313,7 +313,9 @@ static block_t *BlockUDP( access_t *p_access )
/* Read data */ /* Read data */
p_block = block_New( p_access, p_sys->i_mtu ); p_block = block_New( p_access, p_sys->i_mtu );
p_block->i_buffer = net_Read( p_access, p_sys->fd, p_block->p_buffer, p_sys->i_mtu, VLC_FALSE ); p_block->i_buffer = net_Read( p_access, p_sys->fd, NULL,
p_block->p_buffer, p_sys->i_mtu,
VLC_FALSE );
if( p_block->i_buffer <= 0 ) if( p_block->i_buffer <= 0 )
{ {
block_Release( p_block ); block_Release( p_block );
......
...@@ -112,8 +112,8 @@ void Printf( intf_thread_t *p_intf, const char *psz_fmt, ... ) ...@@ -112,8 +112,8 @@ void Printf( intf_thread_t *p_intf, const char *psz_fmt, ... )
va_start( args, psz_fmt ); va_start( args, psz_fmt );
if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args ); if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args );
else else
{ net_vaPrintf( p_intf, p_intf->p_sys->i_socket, psz_fmt, args ); { net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
net_Printf( VLC_OBJECT(p_intf), p_intf->p_sys->i_socket, "\r" ); } net_Printf( VLC_OBJECT(p_intf), p_intf->p_sys->i_socket, NULL, "\r" ); }
va_end( args ); va_end( args );
} }
...@@ -1167,7 +1167,7 @@ vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size ) ...@@ -1167,7 +1167,7 @@ vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH && while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
(i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ? (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 ) p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
{ {
if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' ) if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
......
...@@ -769,7 +769,7 @@ static int Demux( demux_t *p_demux ) ...@@ -769,7 +769,7 @@ static int Demux( demux_t *p_demux )
if( p_sys->b_udp_out ) if( p_sys->b_udp_out )
{ {
/* Send the complete block */ /* Send the complete block */
net_Write( p_demux, p_sys->fd, p_sys->buffer, net_Write( p_demux, p_sys->fd, NULL, p_sys->buffer,
p_sys->i_ts_read * p_sys->i_packet_size ); p_sys->i_ts_read * p_sys->i_packet_size );
} }
......
...@@ -377,7 +377,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -377,7 +377,7 @@ static void Run( intf_thread_t *p_intf )
continue; continue;
} }
int i_read = net_Select( p_intf, p_intf->p_sys->pi_fd, int i_read = net_Select( p_intf, p_intf->p_sys->pi_fd, NULL,
p_intf->p_sys->i_fd, p_buffer, p_intf->p_sys->i_fd, p_buffer,
MAX_SAP_BUFFER, 500000 ); MAX_SAP_BUFFER, 500000 );
#if 0 #if 0
......
...@@ -296,8 +296,8 @@ void net_Close( int fd ) ...@@ -296,8 +296,8 @@ void net_Close( int fd )
* If b_rety is true, then we repeat until we have read the right amount of * If b_rety is true, then we repeat until we have read the right amount of
* data * data
*****************************************************************************/ *****************************************************************************/
int __net_Read( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, int __net_Read( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
vlc_bool_t b_retry ) uint8_t *p_data, int i_data, vlc_bool_t b_retry )
{ {
struct timeval timeout; struct timeval timeout;
fd_set fds_r, fds_e; fd_set fds_r, fds_e;
...@@ -338,7 +338,9 @@ int __net_Read( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, ...@@ -338,7 +338,9 @@ int __net_Read( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data,
return i_total > 0 ? i_total : -1; return i_total > 0 ? i_total : -1;
} }
if( ( i_recv = recv( fd, p_data, i_data, 0 ) ) < 0 ) if( ( i_recv = (p_vs != NULL)
? p_vs->pf_recv( p_vs->p_sys, p_data, i_data )
: recv( fd, p_data, i_data, 0 ) ) < 0 )
{ {
#if defined(WIN32) || defined(UNDER_CE) #if defined(WIN32) || defined(UNDER_CE)
/* For udp only */ /* For udp only */
...@@ -380,8 +382,8 @@ int __net_Read( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, ...@@ -380,8 +382,8 @@ int __net_Read( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data,
***************************************************************************** *****************************************************************************
* Read from a network socket, non blocking mode (with timeout) * Read from a network socket, non blocking mode (with timeout)
*****************************************************************************/ *****************************************************************************/
int __net_ReadNonBlock( vlc_object_t *p_this, int fd, uint8_t *p_data, int __net_ReadNonBlock( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
int i_data, mtime_t i_wait) uint8_t *p_data, int i_data, mtime_t i_wait)
{ {
struct timeval timeout; struct timeval timeout;
fd_set fds_r, fds_e; fd_set fds_r, fds_e;
...@@ -421,7 +423,9 @@ int __net_ReadNonBlock( vlc_object_t *p_this, int fd, uint8_t *p_data, ...@@ -421,7 +423,9 @@ int __net_ReadNonBlock( vlc_object_t *p_this, int fd, uint8_t *p_data,
#if !defined(UNDER_CE) #if !defined(UNDER_CE)
if( fd == 0/*STDIN_FILENO*/ ) i_recv = read( fd, p_data, i_data ); else if( fd == 0/*STDIN_FILENO*/ ) i_recv = read( fd, p_data, i_data ); else
#endif #endif
if( ( i_recv = recv( fd, p_data, i_data, 0 ) ) <= 0 ) if( ( i_recv = (p_vs != NULL)
? p_vs->pf_recv( p_vs->p_sys, p_data, i_data )
: recv( fd, p_data, i_data, 0 ) ) <= 0 )
{ {
#if defined(WIN32) || defined(UNDER_CE) #if defined(WIN32) || defined(UNDER_CE)
/* For udp only */ /* For udp only */
...@@ -454,8 +458,8 @@ int __net_ReadNonBlock( vlc_object_t *p_this, int fd, uint8_t *p_data, ...@@ -454,8 +458,8 @@ int __net_ReadNonBlock( vlc_object_t *p_this, int fd, uint8_t *p_data,
* Read from several sockets (with timeout). Takes data from the first socket * Read from several sockets (with timeout). Takes data from the first socket
* that has some. * that has some.
*****************************************************************************/ *****************************************************************************/
int __net_Select( vlc_object_t *p_this, int *pi_fd, int i_fd, uint8_t *p_data, int __net_Select( vlc_object_t *p_this, int *pi_fd, v_socket_t **pp_vs,
int i_data, mtime_t i_wait ) int i_fd, uint8_t *p_data, int i_data, mtime_t i_wait )
{ {
struct timeval timeout; struct timeval timeout;
fd_set fds_r, fds_e; fd_set fds_r, fds_e;
...@@ -499,7 +503,9 @@ int __net_Select( vlc_object_t *p_this, int *pi_fd, int i_fd, uint8_t *p_data, ...@@ -499,7 +503,9 @@ int __net_Select( vlc_object_t *p_this, int *pi_fd, int i_fd, uint8_t *p_data,
{ {
if( FD_ISSET( pi_fd[i], &fds_r ) ) if( FD_ISSET( pi_fd[i], &fds_r ) )
{ {
i_recv = recv( pi_fd[i], p_data, i_data, 0 ); i_recv = ((pp_vs != NULL) && (pp_vs[i] != NULL))
? pp_vs[i]->pf_recv( pp_vs[i]->p_sys, p_data, i_data )
: recv( pi_fd[i], p_data, i_data, 0 );
if( i_recv <= 0 ) if( i_recv <= 0 )
{ {
#ifdef WIN32 #ifdef WIN32
...@@ -532,7 +538,8 @@ int __net_Select( vlc_object_t *p_this, int *pi_fd, int i_fd, uint8_t *p_data, ...@@ -532,7 +538,8 @@ int __net_Select( vlc_object_t *p_this, int *pi_fd, int i_fd, uint8_t *p_data,
/* Write exact amount requested */ /* Write exact amount requested */
int __net_Write( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data ) int __net_Write( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
uint8_t *p_data, int i_data )
{ {
struct timeval timeout; struct timeval timeout;
fd_set fds_w, fds_e; fd_set fds_w, fds_e;
...@@ -574,7 +581,9 @@ int __net_Write( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data ) ...@@ -574,7 +581,9 @@ int __net_Write( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data )
return i_total > 0 ? i_total : -1; return i_total > 0 ? i_total : -1;
} }
if( ( i_send = send( fd, p_data, i_data, 0 ) ) < 0 ) if( ( i_send = (p_vs != NULL)
? p_vs->pf_send( p_vs->p_sys, p_data, i_data )
: send( fd, p_data, i_data, 0 ) ) < 0 )
{ {
/* XXX With udp for example, it will issue a message if the host /* XXX With udp for example, it will issue a message if the host
* isn't listening */ * isn't listening */
...@@ -589,7 +598,7 @@ int __net_Write( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data ) ...@@ -589,7 +598,7 @@ int __net_Write( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data )
return i_total; return i_total;
} }
char *__net_Gets( vlc_object_t *p_this, int fd ) char *__net_Gets( vlc_object_t *p_this, int fd, v_socket_t *p_vs )
{ {
char *psz_line = malloc( 1024 ); char *psz_line = malloc( 1024 );
int i_line = 0; int i_line = 0;
...@@ -598,7 +607,7 @@ char *__net_Gets( vlc_object_t *p_this, int fd ) ...@@ -598,7 +607,7 @@ char *__net_Gets( vlc_object_t *p_this, int fd )
for( ;; ) for( ;; )
{ {
if( net_Read( p_this, fd, &psz_line[i_line], 1, VLC_TRUE ) != 1 ) if( net_Read( p_this, fd, p_vs, &psz_line[i_line], 1, VLC_TRUE ) != 1 )
{ {
psz_line[i_line] = '\0'; psz_line[i_line] = '\0';
break; break;
...@@ -633,26 +642,27 @@ char *__net_Gets( vlc_object_t *p_this, int fd ) ...@@ -633,26 +642,27 @@ char *__net_Gets( vlc_object_t *p_this, int fd )
return psz_line; return psz_line;
} }
int net_Printf( vlc_object_t *p_this, int fd, const char *psz_fmt, ... ) int net_Printf( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
const char *psz_fmt, ... )
{ {
int i_ret; int i_ret;
va_list args; va_list args;
va_start( args, psz_fmt ); va_start( args, psz_fmt );
i_ret = net_vaPrintf( p_this, fd, psz_fmt, args ); i_ret = net_vaPrintf( p_this, fd, p_vs, psz_fmt, args );
va_end( args ); va_end( args );
return i_ret; return i_ret;
} }
int __net_vaPrintf( vlc_object_t *p_this, int fd, const char *psz_fmt, int __net_vaPrintf( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
va_list args ) const char *psz_fmt, va_list args )
{ {
char *psz; char *psz;
int i_size, i_ret; int i_size, i_ret;
vasprintf( &psz, psz_fmt, args ); vasprintf( &psz, psz_fmt, args );
i_size = strlen( psz ); i_size = strlen( psz );
i_ret = __net_Write( p_this, fd, psz, i_size ) < i_size ? -1 : i_size; i_ret = __net_Write( p_this, fd, p_vs, psz, i_size ) < i_size ? -1 : i_size;
free( psz ); free( psz );
return i_ret; return i_ret;
......
...@@ -454,7 +454,7 @@ static int announce_SendSAPAnnounce( sap_handler_t *p_sap, ...@@ -454,7 +454,7 @@ static int announce_SendSAPAnnounce( sap_handler_t *p_sap,
#ifdef EXTRA_DEBUG #ifdef EXTRA_DEBUG
msg_Dbg( p_sap, "Sending announce"); msg_Dbg( p_sap, "Sending announce");
#endif #endif
i_ret = net_Write( p_sap, p_session->p_address->i_wfd, i_ret = net_Write( p_sap, p_session->p_address->i_wfd, NULL,
p_session->psz_data, p_session->psz_data,
p_session->i_length ); p_session->i_length );
if( i_ret != p_session->i_length ) if( i_ret != p_session->i_length )
...@@ -541,7 +541,7 @@ static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address ) ...@@ -541,7 +541,7 @@ static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address )
do do
{ {
/* Might be too slow if we have huge data */ /* Might be too slow if we have huge data */
i_read = net_ReadNonBlock( p_sap, p_address->i_rfd, buffer, i_read = net_ReadNonBlock( p_sap, p_address->i_rfd, NULL, buffer,
SAP_MAX_BUFFER, 0 ); SAP_MAX_BUFFER, 0 );
i_tot += i_read; i_tot += i_read;
} while( i_read > 0 && i_tot < SAP_MAX_BUFFER ); } while( i_read > 0 && i_tot < SAP_MAX_BUFFER );
......
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