Changeset cbc66ff62b56b1dea3ba99b9b0f1a28659773427

Show
Ignore:
Timestamp:
24/03/07 01:24:22 (2 years ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1174695862 +0000
git-parent:

[37b0b026bbe92b1bda266e6f30ec37c7ceee767d]

git-author:
Laurent Aimar <fenrir@videolan.org> 1174695862 +0000
Message:

Implemented http proxy for mmsh (close #629)
It uses --mmsh-proxy=xxx or http_proxy environment variable (basic
authentication has not been tested).
We may want to reuse --http-proxy from http instead (and so we will have to
move the option out of http.c)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/access/mms/mms.c

    rd3fe7f2 rcbc66ff  
    5858    "Select the stream with the maximum bitrate under that limit."  ) 
    5959 
     60#define PROXY_TEXT N_("HTTP proxy") 
     61#define PROXY_LONGTEXT N_( \ 
     62    "HTTP proxy to be used It must be of the form " \ 
     63    "http://[user[:pass]@]myproxy.mydomain:myport/ ; " \ 
     64    "if empty, the http_proxy environment variable will be tried." ) 
     65 
    6066vlc_module_begin(); 
    6167    set_shortname( "MMS" ); 
     
    7177    add_integer( "mms-maxbitrate", 0, NULL, BITRATE_TEXT, BITRATE_LONGTEXT , 
    7278                 VLC_FALSE ); 
     79    add_string( "mmsh-proxy", NULL, NULL, PROXY_TEXT, PROXY_LONGTEXT, 
     80                    VLC_FALSE ); 
    7381 
    7482    add_shortcut( "mms" ); 
  • modules/access/mms/mmsh.c

    r830641e rcbc66ff  
    2525 * Preamble 
    2626 *****************************************************************************/ 
     27#define _GNU_SOURCE 
    2728#include <stdlib.h> 
    2829 
     
    3031#include <vlc_access.h> 
    3132#include "vlc_playlist.h" 
     33#include "vlc_strings.h" 
    3234 
    3335#include <vlc_network.h> 
     
    7577    access_sys_t    *p_sys; 
    7678    char            *psz_location = NULL; 
     79    char            *psz_proxy; 
    7780 
    7881    /* init p_sys */ 
     
    9497    p_sys->fd     = -1; 
    9598    p_sys->i_start= 0; 
     99 
     100    /* Handle proxy */ 
     101    p_sys->b_proxy = VLC_FALSE; 
     102    memset( &p_sys->proxy, 0, sizeof(p_sys->proxy) ); 
     103 
     104    /* Check proxy */ 
     105    /* TODO reuse instead http-proxy from http access ? */ 
     106    psz_proxy = var_CreateGetString( p_access, "mmsh-proxy" ); 
     107    if( *psz_proxy ) 
     108    { 
     109        p_sys->b_proxy = VLC_TRUE; 
     110        vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 ); 
     111    } 
     112#ifdef HAVE_GETENV 
     113    else 
     114    { 
     115        char *psz_proxy = getenv( "http_proxy" ); 
     116        if( psz_proxy && *psz_proxy ) 
     117        { 
     118            p_sys->b_proxy = VLC_TRUE; 
     119            vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 ); 
     120        } 
     121    } 
     122#endif 
     123    free( psz_proxy ); 
     124 
     125    if( p_sys->b_proxy ) 
     126    { 
     127       if( p_sys->proxy.psz_host == NULL || *p_sys->proxy.psz_host == '\0' ) 
     128        { 
     129            msg_Warn( p_access, "invalid proxy host" ); 
     130            vlc_UrlClean( &p_sys->proxy ); 
     131            free( p_sys ); 
     132            return VLC_EGENERIC; 
     133        } 
     134        if( p_sys->proxy.i_port <= 0 ) 
     135            p_sys->proxy.i_port = 80; 
     136        msg_Dbg( p_access, "Using http proxy %s:%d", 
     137                 p_sys->proxy.psz_host, p_sys->proxy.i_port ); 
     138    } 
    96139 
    97140    /* open a tcp connection */ 
     
    434477    return 0; 
    435478} 
     479 
     480static int OpenConnection( access_t *p_access ) 
     481{ 
     482    access_sys_t *p_sys = p_access->p_sys; 
     483    vlc_url_t    srv = p_sys->b_proxy ? p_sys->proxy : p_sys->url; 
     484 
     485    if( ( p_sys->fd = net_ConnectTCP( p_access, 
     486                                      srv.psz_host, srv.i_port ) ) < 0 ) 
     487    { 
     488        msg_Err( p_access, "cannot connect to %s:%d", 
     489                 srv.psz_host, srv.i_port ); 
     490        return VLC_EGENERIC; 
     491    } 
     492 
     493    if( p_sys->b_proxy ) 
     494    { 
     495        net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, 
     496                    "GET http://%s:%d%s HTTP/1.0\r\n", 
     497                    p_sys->url.psz_host, p_sys->url.i_port, 
     498                    ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path ); 
     499 
     500        /* Proxy Authentication */ 
     501        if( p_sys->proxy.psz_username && *p_sys->proxy.psz_username ) 
     502        { 
     503            char *buf; 
     504            char *b64; 
     505 
     506            asprintf( &buf, "%s:%s", p_sys->proxy.psz_username, 
     507                       p_sys->proxy.psz_password ? p_sys->proxy.psz_password : "" ); 
     508 
     509            b64 = vlc_b64_encode( buf ); 
     510            free( buf ); 
     511 
     512            net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, 
     513                        "Proxy-Authorization: Basic %s\r\n", b64 ); 
     514            free( b64 ); 
     515        } 
     516    } 
     517    else 
     518    { 
     519        net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, 
     520                    "GET %s HTTP/1.0\r\n" 
     521                    "Host: %s:%d\r\n", 
     522                    ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path, 
     523                    p_sys->url.psz_host, p_sys->url.i_port ); 
     524    } 
     525    return VLC_SUCCESS; 
     526} 
     527 
    436528/***************************************************************************** 
    437529 * Describe: 
     
    453545    E_( GenerateGuid )( &p_sys->guid ); 
    454546 
    455     if( ( p_sys->fd = net_ConnectTCP( p_access, p_sys->url.psz_host, 
    456                                             p_sys->url.i_port ) ) < 0 ) 
    457     { 
    458         msg_Err( p_access, "cannot connect to %s:%d", p_sys->url.psz_host, 
    459                  p_sys->url.i_port ); 
    460         goto error; 
    461     } 
    462  
    463     /* send first request */ 
     547    OpenConnection( p_access ); 
     548 
    464549    net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, 
    465                 "GET %s HTTP/1.0\r\n" 
    466550                "Accept: */*\r\n" 
    467551                "User-Agent: "MMSH_USER_AGENT"\r\n" 
    468                 "Host: %s:%d\r\n" 
    469552                "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=%d,max-duration=0\r\n" 
    470553                "Pragma: xClientGUID={"GUID_FMT"}\r\n" 
    471554                "Connection: Close\r\n", 
    472                 ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path, 
    473                 p_sys->url.psz_host, p_sys->url.i_port, 
    474555                p_sys->i_request_context++, 
    475556                GUID_PRINT( p_sys->guid ) ); 
     
    647728    msg_Dbg( p_access, "starting stream" ); 
    648729 
    649     if( ( p_sys->fd = net_ConnectTCP( p_access, p_sys->url.psz_host, 
    650                                       p_sys->url.i_port ) ) < 0 ) 
    651     { 
    652         /* should not occur */ 
    653         msg_Err( p_access, "cannot connect to the server" ); 
    654         return VLC_EGENERIC; 
    655     } 
    656  
    657730    for( i = 1; i < 128; i++ ) 
    658731    { 
     
    663736            i_streams_selected++; 
    664737    } 
    665  
    666738    if( i_streams_selected <= 0 ) 
    667739    { 
     
    669741        return VLC_EGENERIC; 
    670742    } 
     743 
     744    OpenConnection( p_access ); 
     745 
    671746    net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, 
    672                 "GET %s HTTP/1.0\r\n" 
    673747                "Accept: */*\r\n" 
    674                 "User-Agent: "MMSH_USER_AGENT"\r\n" 
    675                 "Host: %s:%d\r\n", 
    676                 ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path, 
    677                 p_sys->url.psz_host, p_sys->url.i_port ); 
     748                "User-Agent: "MMSH_USER_AGENT"\r\n" ); 
    678749    if( p_sys->b_broadcast ) 
    679750    { 
  • modules/access/mms/mmsh.h

    r2cb472d rcbc66ff  
    4545    vlc_url_t       url; 
    4646 
     47    vlc_bool_t      b_proxy; 
     48    vlc_url_t       proxy; 
     49 
    4750    int             i_request_context; 
    4851