Index: Gui/mplayer/gtk/url.c =================================================================== --- Gui/mplayer/gtk/url.c (revision 22200) +++ Gui/mplayer/gtk/url.c (working copy) @@ -67,6 +67,7 @@ if ( str ) { if ( strncmp( str,"http://",7 ) + && strncmp( str,"https://",8 ) && strncmp( str,"ftp://",6 ) && strncmp( str,"mms://",6 ) && strncmp( str,"pnm://",6 ) Index: stream/http.c =================================================================== --- stream/http.c (revision 22200) +++ stream/http.c (working copy) @@ -950,7 +950,11 @@ "Bertrand, Albeau, Reimar Doeffinger, Arpi?", "plain http", open_s1, - {"http", "http_proxy", "unsv", NULL}, + {"http", +#ifdef HAVE_SSL + "https", +#endif + "http_proxy", "unsv", NULL}, NULL, 0 // Urls are an option string }; @@ -961,7 +965,11 @@ "Bertrand, Albeu, Arpi? who?", "plain http, also used as fallback for many other protocols", open_s2, - {"http", "http_proxy", "pnm", "mms", "mmsu", "mmst", "rtsp", NULL}, //all the others as fallback + {"http", +#ifdef HAVE_SSL + "https", +#endif + "http_proxy", "pnm", "mms", "mmsu", "mmst", "rtsp", NULL}, //all the others as fallback NULL, 0 // Urls are an option string }; Index: stream/network.c =================================================================== --- stream/network.c (revision 22200) +++ stream/network.c (working copy) @@ -126,7 +126,11 @@ return url_out; } // Check if the http_proxy environment variable is set. - if( !strcasecmp(url->protocol, "http") ) { + if( !strcasecmp(url->protocol, "http") +#ifdef HAVE_SSL + || !strcasecmp(url->protocol, "https") +#endif + ) { char *proxy; proxy = getenv("http_proxy"); if( proxy!=NULL ) { @@ -184,6 +188,13 @@ int ret; int proxy = 0; // Boolean +#ifdef HAVE_SSL + int ssl = 0; // Boolean + + if( !strcasecmp(url->protocol, "https") ) + ssl = 1; +#endif + http_hdr = http_new_header(); if( !strcasecmp(url->protocol, "http_proxy") ) { @@ -229,12 +240,26 @@ url_free( server_url ); server_url = NULL; } else { - if( server_url->port==0 ) server_url->port = 80; // Default port for the web server + + if( server_url->port==0 ) +#ifdef HAVE_SSL + if(ssl) + server_url->port = 443; + else +#endif + server_url->port = 80; // Default port for the web server fd = connect2Server( server_url->hostname, server_url->port,1 ); } + +#ifdef HAVE_SSL + if(ssl) + fd = spawn_ssl_wrapper(fd); +#endif + if( fd<0 ) { goto err_out; } + mp_msg(MSGT_NETWORK,MSGL_DBG2,"Request: [%s]\n", http_hdr->buffer ); ret = send( fd, http_hdr->buffer, http_hdr->buffer_size, 0 ); Index: stream/Makefile =================================================================== --- stream/Makefile (revision 22200) +++ stream/Makefile (working copy) @@ -43,6 +43,8 @@ realrtsp/sdpplin.c \ realrtsp/xbuffer.c \ +SRCS-$(SSL) += ssl.c + SRCS-$(PVR) += stream_pvr.c SRCS-$(RADIO) += stream_radio.c SRCS-$(RADIO_CAPTURE) += audio_in.c Index: stream/ssl.c =================================================================== --- stream/ssl.c (revision 0) +++ stream/ssl.c (revision 0) @@ -0,0 +1,148 @@ +/* + * SSL Helper + * by Mark Glines + * Donated to MPlayer team. So, I guess, (C) 2007, MPlayer team. + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "config.h" + +#include "mp_msg.h" +#include "help_mp.h" + +#include "ssl.h" + +#ifdef HAVE_SSL + +#include +#include +#include +#include +#include + +static void ssl_byte_tosser(int mplayer, int sock) { + SSL_CTX *ctx; + SSL *ssl; + int flags, max = mplayer; + if(sock > max) + max = sock; + + fcntl(mplayer, F_GETFL, flags); + flags |= O_NONBLOCK; + fcntl(mplayer, F_SETFL, flags); + fcntl(sock, F_GETFL, flags); + flags |= O_NONBLOCK; + fcntl(sock, F_SETFL, flags); + + SSL_library_init(); + ctx = SSL_CTX_new(SSLv23_client_method()); + if(!ctx) + return; + ssl = SSL_new(ctx); + if(!ssl) + return; + SSL_set_fd(ssl, sock); + SSL_set_connect_state(ssl); + + max++; + + while(1) { + int rv; + fd_set infds, excfds; + FD_ZERO(&infds); + FD_SET(mplayer, &infds); + FD_SET(sock , &infds); + excfds = infds; + rv = select(max, &infds, NULL, &excfds, NULL); + if(FD_ISSET(mplayer, &excfds) || FD_ISSET(sock, &excfds)) + /* one side has probably crashed, exited, or fell off the net. + * exit gracefully. */ + goto gone; + + if(FD_ISSET(mplayer, &infds)) { + char buf[4096]; + int size = read(mplayer, buf, sizeof(buf)); + if(!size) + /* EOF; mplayer has closed the socket. */ + goto gone; + + if(size > 0) { + int sofar = 0; + while(sofar < size) { + rv = SSL_write(ssl, buf+sofar, size-sofar); + if(rv > 0) + sofar += rv; + if(rv < 0 && errno != EINTR && errno != EAGAIN) + /* server isn't accepting our data */ + goto gone; + } + } + } + if(FD_ISSET(sock, &infds)) { + char buf[4096]; + int size = SSL_read(ssl, buf, sizeof(buf)); + if(!size) + /* EOF; remote server has closed the socket. */ + goto gone; + + if(size > 0) { + int sofar = 0; + while(sofar < size) { + rv = write(mplayer, buf+sofar, size-sofar); + if(rv > 0) + sofar += rv; + if(rv < 0 && errno != EINTR && errno != EAGAIN) + /* mplayer isn't accepting our data */ + goto gone; + } + } + } + } +gone: + close(mplayer); + close(sock); + SSL_free(ssl); + exit(0); +} + +int spawn_ssl_wrapper(int fd) { + int fds[2], pid, rv; + if(fd < 0) + return fd; + rv = socketpair(AF_UNIX, SOCK_STREAM, PF_UNIX, fds); + if(rv) { + /* could not socketpair */ + close(fd); + return rv; + } + pid = fork(); + if(pid < 0) { + /* could not fork */ + close(fd); + close(fds[0]); + close(fds[1]); + return pid; + } + if(pid) { + /* parent process */ + close(fds[1]); + close(fd); + return fds[0]; + } + /* child process */ + close(fds[0]); + ssl_byte_tosser(fds[1], fd); + exit(0); +} + +#endif /* HAVE_SSL */ Index: stream/ssl.h =================================================================== --- stream/ssl.h (revision 0) +++ stream/ssl.h (revision 0) @@ -0,0 +1,16 @@ +/* + * SSL Helper + * by Mark Glines + * Donated to MPlayer team. So, I guess, (C) 2007, MPlayer team. + */ + +#ifndef __SSL_H +#define __SSL_H + +#include "config.h" + +#ifdef HAVE_SSL +int spawn_ssl_wrapper(int fd); +#endif + +#endif // __SSL_H Index: configure =================================================================== --- configure (revision 22200) +++ configure (working copy) @@ -585,6 +585,7 @@ _tv_bsdbt848=auto _pvr=auto _network=yes +_ssl=auto _winsock2=auto _smbsupport=auto _vidix_internal=auto @@ -945,6 +946,8 @@ --disable-fastmemcpy) _fastmemcpy=no ;; --enable-network) _network=yes ;; --disable-network) _network=no ;; + --enable-ssl) _ssl=yes ;; + --disable-ssl) _ssl=no ;; --enable-winsock2) _winsock2=yes ;; --disable-winsock2) _winsock2=no ;; --enable-smb) _smbsupport=yes ;; @@ -6096,6 +6099,24 @@ echores "$_live" +echocheck "SSL library" +if test "$_ssl" = auto && test "$_network" = yes; then +cat > $TMPC << EOF +#include +int main(void) { return 0; } +EOF +_ssl=no +cc_check -lssl -lcrypto && _ssl=yes +if test "$_ssl" = yes && test "$_network" = yes; then + _def_ssl='#define HAVE_SSL 1' + _ld_extra="$_ld_extra -lssl -lcrypto" +else + _def_ssl='#undef HAVE_SSL' +fi +fi +echores "$_ssl" + + echocheck "FFmpeg libavutil (static)" if test "$_libavutil" = auto ; then if test -d libavutil ; then @@ -7448,6 +7469,7 @@ EXESUF = $_exesuf MPLAYER_NETWORK = $_network +SSL = $_ssl FTP = $_ftp STREAMING_LIVE555 = $_live VSTREAM = $_vstream @@ -8220,6 +8242,9 @@ /* enable network */ $_def_network +/* enable ssl support */ +$_def_ssl + /* enable ftp support */ $_def_ftp