Commit 269d8af1 authored by Sam Hocevar's avatar Sam Hocevar

* ./modules/access/http.c, ./modules/misc/network/ipv4.c: http and ipv4

    plugins compile for WinCE. Couldn't test yet though.
parent f6cf9ef8
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* http.c: HTTP access plug-in * http.c: HTTP access plug-in
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: http.c,v 1.10 2002/11/15 14:41:49 gbazin Exp $ * $Id: http.c,v 1.11 2002/11/23 04:40:53 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -25,22 +25,26 @@ ...@@ -25,22 +25,26 @@
* Preamble * Preamble
*****************************************************************************/ *****************************************************************************/
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/input.h> #include <vlc/input.h>
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#elif defined( _MSC_VER ) && defined( _WIN32 ) #elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
# include <io.h> # include <io.h>
#endif #endif
#ifdef WIN32 #if defined( UNDER_CE )
# include <winsock.h>
#elif defined( WIN32 )
# include <winsock2.h> # include <winsock2.h>
# include <ws2tcpip.h> # include <ws2tcpip.h>
# ifndef IN_MULTICAST # ifndef IN_MULTICAST
...@@ -142,7 +146,11 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -142,7 +146,11 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
if( send( p_access_data->_socket.i_handle, psz_buffer, if( send( p_access_data->_socket.i_handle, psz_buffer,
strlen( psz_buffer ), 0 ) == (-1) ) strlen( psz_buffer ), 0 ) == (-1) )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_input, "cannot send request (%s)", strerror(errno) ); msg_Err( p_input, "cannot send request (%s)", strerror(errno) );
#else
msg_Err( p_input, "cannot send request" );
#endif
Close( VLC_OBJECT(p_input) ); Close( VLC_OBJECT(p_input) );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -549,9 +557,7 @@ static void Close( vlc_object_t *p_this ) ...@@ -549,9 +557,7 @@ static void Close( vlc_object_t *p_this )
msg_Info( p_input, "closing HTTP target `%s'", p_input->psz_source ); msg_Info( p_input, "closing HTTP target `%s'", p_input->psz_source );
#ifdef UNDER_CE #if defined( WIN32 ) || defined( UNDER_CE )
CloseHandle( (HANDLE)i_handle );
#elif defined( WIN32 )
closesocket( i_handle ); closesocket( i_handle );
#else #else
close( i_handle ); close( i_handle );
...@@ -575,9 +581,7 @@ static int SetProgram( input_thread_t * p_input, ...@@ -575,9 +581,7 @@ static int SetProgram( input_thread_t * p_input,
static void Seek( input_thread_t * p_input, off_t i_pos ) static void Seek( input_thread_t * p_input, off_t i_pos )
{ {
_input_socket_t *p_access_data = (_input_socket_t*)p_input->p_access_data; _input_socket_t *p_access_data = (_input_socket_t*)p_input->p_access_data;
#ifdef UNDER_CE #if defined( WIN32 ) || defined( UNDER_CE )
CloseHandle( (HANDLE)p_access_data->_socket.i_handle );
#elif defined( WIN32 )
closesocket( p_access_data->_socket.i_handle ); closesocket( p_access_data->_socket.i_handle );
#else #else
close( p_access_data->_socket.i_handle ); close( p_access_data->_socket.i_handle );
...@@ -591,10 +595,6 @@ static void Seek( input_thread_t * p_input, off_t i_pos ) ...@@ -591,10 +595,6 @@ static void Seek( input_thread_t * p_input, off_t i_pos )
*****************************************************************************/ *****************************************************************************/
static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len ) static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
{ {
#ifdef UNDER_CE
return -1;
#else
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data; input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
struct timeval timeout; struct timeval timeout;
fd_set fds; fd_set fds;
...@@ -612,10 +612,17 @@ static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len ) ...@@ -612,10 +612,17 @@ static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
i_ret = select( p_access_data->i_handle + 1, &fds, i_ret = select( p_access_data->i_handle + 1, &fds,
NULL, NULL, &timeout ); NULL, NULL, &timeout );
#ifdef HAVE_ERRNO_H
if( i_ret == -1 && errno != EINTR ) if( i_ret == -1 && errno != EINTR )
{ {
msg_Err( p_input, "network select error (%s)", strerror(errno) ); msg_Err( p_input, "network select error (%s)", strerror(errno) );
} }
#else
if( i_ret == -1 )
{
msg_Err( p_input, "network select error" );
}
#endif
else if( i_ret > 0 ) else if( i_ret > 0 )
{ {
ssize_t i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 ); ssize_t i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
...@@ -629,13 +636,15 @@ static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len ) ...@@ -629,13 +636,15 @@ static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
if( i_recv < 0 ) if( i_recv < 0 )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_input, "recv failed (%s)", strerror(errno) ); msg_Err( p_input, "recv failed (%s)", strerror(errno) );
#else
msg_Err( p_input, "recv failed" );
#endif
} }
return i_recv; return i_recv;
} }
return 0; return 0;
#endif
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ipv4.c: IPv4 network abstraction layer * ipv4.c: IPv4 network abstraction layer
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: ipv4.c,v 1.5 2002/11/14 22:38:48 massiot Exp $ * $Id: ipv4.c,v 1.6 2002/11/23 04:40:53 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* Mathias Kretschmer <mathias@research.att.com> * Mathias Kretschmer <mathias@research.att.com>
...@@ -26,21 +26,31 @@ ...@@ -26,21 +26,31 @@
* Preamble * Preamble
*****************************************************************************/ *****************************************************************************/
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#elif defined( _MSC_VER ) && defined( _WIN32 ) #elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
# include <io.h> # include <io.h>
#endif #endif
#ifdef WIN32 #if defined( UNDER_CE )
# include <winsock.h>
#elif defined( WIN32 )
# include <winsock2.h> # include <winsock2.h>
# include <ws2tcpip.h> # include <ws2tcpip.h>
# ifndef IN_MULTICAST # ifndef IN_MULTICAST
...@@ -80,7 +90,7 @@ static int BuildAddr( struct sockaddr_in * p_socket, ...@@ -80,7 +90,7 @@ static int BuildAddr( struct sockaddr_in * p_socket,
/* Reset struct */ /* Reset struct */
memset( p_socket, 0, sizeof( struct sockaddr_in ) ); memset( p_socket, 0, sizeof( struct sockaddr_in ) );
p_socket->sin_family = AF_INET; /* family */ p_socket->sin_family = AF_INET; /* family */
p_socket->sin_port = htons( i_port ); p_socket->sin_port = htons( (uint16_t)i_port );
if( !*psz_address ) if( !*psz_address )
{ {
p_socket->sin_addr.s_addr = INADDR_ANY; p_socket->sin_addr.s_addr = INADDR_ANY;
...@@ -130,7 +140,7 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -130,7 +140,7 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
int i_bind_port = p_socket->i_bind_port; int i_bind_port = p_socket->i_bind_port;
char * psz_server_addr = p_socket->psz_server_addr; char * psz_server_addr = p_socket->psz_server_addr;
int i_server_port = p_socket->i_server_port; int i_server_port = p_socket->i_server_port;
#ifdef WIN32 #if defined( WIN32 ) && !defined( UNDER_CE )
char * psz_bind_win32; /* WIN32 multicast kludge */ char * psz_bind_win32; /* WIN32 multicast kludge */
#endif #endif
...@@ -147,7 +157,11 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -147,7 +157,11 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
* protocol */ * protocol */
if( (i_handle = socket( AF_INET, SOCK_DGRAM, 0 )) == -1 ) if( (i_handle = socket( AF_INET, SOCK_DGRAM, 0 )) == -1 )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_this, "cannot create socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot create socket (%s)", strerror(errno) );
#else
msg_Err( p_this, "cannot create socket" );
#endif
return( -1 ); return( -1 );
} }
...@@ -156,9 +170,17 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -156,9 +170,17 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR, if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR,
(void *) &i_opt, sizeof( i_opt ) ) == -1 ) (void *) &i_opt, sizeof( i_opt ) ) == -1 )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_this, "cannot configure socket (SO_REUSEADDR: %s)", msg_Err( p_this, "cannot configure socket (SO_REUSEADDR: %s)",
strerror(errno)); strerror(errno));
#else
msg_Err( p_this, "cannot configure socket (SO_REUSEADDR)" );
#endif
#if defined( WIN32 ) || defined( UNDER_CE )
closesocket( i_handle );
#else
close( i_handle ); close( i_handle );
#endif
return( -1 ); return( -1 );
} }
...@@ -168,8 +190,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -168,8 +190,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( setsockopt( i_handle, SOL_SOCKET, SO_RCVBUF, if( setsockopt( i_handle, SOL_SOCKET, SO_RCVBUF,
(void *) &i_opt, sizeof( i_opt ) ) == -1 ) (void *) &i_opt, sizeof( i_opt ) ) == -1 )
{ {
#ifdef HAVE_ERRNO_H
msg_Warn( p_this, "cannot configure socket (SO_RCVBUF: %s)", msg_Warn( p_this, "cannot configure socket (SO_RCVBUF: %s)",
strerror(errno)); strerror(errno));
#else
msg_Warn( p_this, "cannot configure socket (SO_RCVBUF)" );
#endif
} }
/* Check if we really got what we have asked for, because Linux, etc. /* Check if we really got what we have asked for, because Linux, etc.
...@@ -180,8 +206,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -180,8 +206,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( getsockopt( i_handle, SOL_SOCKET, SO_RCVBUF, if( getsockopt( i_handle, SOL_SOCKET, SO_RCVBUF,
(void*) &i_opt, &i_opt_size ) == -1 ) (void*) &i_opt, &i_opt_size ) == -1 )
{ {
#ifdef HAVE_ERRNO_H
msg_Warn( p_this, "cannot query socket (SO_RCVBUF: %s)", msg_Warn( p_this, "cannot query socket (SO_RCVBUF: %s)",
strerror(errno) ); strerror(errno) );
#else
msg_Warn( p_this, "cannot query socket (SO_RCVBUF)" );
#endif
} }
else if( i_opt < 0x80000 ) else if( i_opt < 0x80000 )
{ {
...@@ -192,7 +222,7 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -192,7 +222,7 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
/* Build the local socket */ /* Build the local socket */
#ifdef WIN32 #if defined( WIN32 ) && !defined( UNDER_CE )
/* Under Win32 and for the multicast, we bind on INADDR_ANY, /* Under Win32 and for the multicast, we bind on INADDR_ANY,
* so let's call BuildAddr with "" instead of psz_bind_addr */ * so let's call BuildAddr with "" instead of psz_bind_addr */
psz_bind_win32 = psz_bind_addr ; psz_bind_win32 = psz_bind_addr ;
...@@ -207,15 +237,28 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -207,15 +237,28 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if ( BuildAddr( &sock, psz_bind_addr, i_bind_port ) == -1 ) if ( BuildAddr( &sock, psz_bind_addr, i_bind_port ) == -1 )
#endif #endif
{ {
msg_Dbg( p_this, "could not build local address" );
#if defined( WIN32 ) || defined( UNDER_CE )
closesocket( i_handle );
#else
close( i_handle ); close( i_handle );
#endif
return( -1 ); return( -1 );
} }
/* Bind it */ /* Bind it */
if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 ) if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_this, "cannot bind socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot bind socket (%s)", strerror(errno) );
#else
msg_Err( p_this, "cannot bind socket" );
#endif
#if defined( WIN32 ) || defined( UNDER_CE )
closesocket( i_handle );
#else
close( i_handle ); close( i_handle );
#endif
return( -1 ); return( -1 );
} }
...@@ -226,11 +269,16 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -226,11 +269,16 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( setsockopt( i_handle, SOL_SOCKET, SO_BROADCAST, if( setsockopt( i_handle, SOL_SOCKET, SO_BROADCAST,
(void*) &i_opt, sizeof( i_opt ) ) == -1 ) (void*) &i_opt, sizeof( i_opt ) ) == -1 )
{ {
#ifdef HAVE_ERRNO_H
msg_Warn( p_this, "cannot configure socket (SO_BROADCAST: %s)", msg_Warn( p_this, "cannot configure socket (SO_BROADCAST: %s)",
strerror(errno) ); strerror(errno) );
#else
msg_Warn( p_this, "cannot configure socket (SO_BROADCAST)" );
#endif
} }
} }
#ifndef UNDER_CE
/* Join the multicast group if the socket is a multicast address */ /* Join the multicast group if the socket is a multicast address */
#ifndef IN_MULTICAST #ifndef IN_MULTICAST
# define IN_MULTICAST(a) IN_CLASSD(a) # define IN_MULTICAST(a) IN_CLASSD(a)
...@@ -263,12 +311,21 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -263,12 +311,21 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( setsockopt( i_handle, IPPROTO_IP, IP_ADD_MEMBERSHIP, if( setsockopt( i_handle, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char*)&imr, sizeof(struct ip_mreq) ) == -1 ) (char*)&imr, sizeof(struct ip_mreq) ) == -1 )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_this, "failed to join IP multicast group (%s)", msg_Err( p_this, "failed to join IP multicast group (%s)",
strerror(errno) ); strerror(errno) );
#else
msg_Err( p_this, "failed to join IP multicast group" );
#endif
#if defined( WIN32 ) || defined( UNDER_CE )
closesocket( i_handle );
#else
close( i_handle ); close( i_handle );
#endif
return( -1 ); return( -1 );
} }
} }
#endif /* UNDER_CE */
if( *psz_server_addr ) if( *psz_server_addr )
{ {
...@@ -276,7 +333,11 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -276,7 +333,11 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if ( BuildAddr( &sock, psz_server_addr, i_server_port ) == -1 ) if ( BuildAddr( &sock, psz_server_addr, i_server_port ) == -1 )
{ {
msg_Err( p_this, "cannot build remote address" ); msg_Err( p_this, "cannot build remote address" );
#if defined( WIN32 ) || defined( UNDER_CE )
closesocket( i_handle );
#else
close( i_handle ); close( i_handle );
#endif
return( -1 ); return( -1 );
} }
...@@ -284,8 +345,16 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -284,8 +345,16 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( connect( i_handle, (struct sockaddr *) &sock, if( connect( i_handle, (struct sockaddr *) &sock,
sizeof( sock ) ) == (-1) ) sizeof( sock ) ) == (-1) )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_this, "cannot connect socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot connect socket (%s)", strerror(errno) );
#else
msg_Err( p_this, "cannot connect socket" );
#endif
#if defined( WIN32 ) || defined( UNDER_CE )
closesocket( i_handle );
#else
close( i_handle ); close( i_handle );
#endif
return( -1 ); return( -1 );
} }
} }
...@@ -320,14 +389,23 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -320,14 +389,23 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket )
* protocol */ * protocol */
if( (i_handle = socket( AF_INET, SOCK_STREAM, 0 )) == -1 ) if( (i_handle = socket( AF_INET, SOCK_STREAM, 0 )) == -1 )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_this, "cannot create socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot create socket (%s)", strerror(errno) );
#else
msg_Err( p_this, "cannot create socket" );
#endif
return( -1 ); return( -1 );
} }
/* Build remote address */ /* Build remote address */
if ( BuildAddr( &sock, psz_server_addr, i_server_port ) == -1 ) if ( BuildAddr( &sock, psz_server_addr, i_server_port ) == -1 )
{ {
msg_Dbg( p_this, "could not build local address" );
#if defined( WIN32 ) || defined( UNDER_CE )
closesocket( i_handle );
#else
close( i_handle ); close( i_handle );
#endif
return( -1 ); return( -1 );
} }
...@@ -335,8 +413,16 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -335,8 +413,16 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket )
if( connect( i_handle, (struct sockaddr *) &sock, if( connect( i_handle, (struct sockaddr *) &sock,
sizeof( sock ) ) == (-1) ) sizeof( sock ) ) == (-1) )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_this, "cannot connect socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot connect socket (%s)", strerror(errno) );
#else
msg_Err( p_this, "cannot connect socket" );
#endif
#if defined( WIN32 ) || defined( UNDER_CE )
closesocket( i_handle );
#else
close( i_handle ); close( i_handle );
#endif
return( -1 ); return( -1 );
} }
......
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