⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * http.c: HTTP input module ***************************************************************************** * Copyright (C) 2001-2005 the VideoLAN team * $Id: http.c 16774 2006-09-21 19:29:10Z hartman $ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> *          Christophe Massiot <massiot@via.ecp.fr> *          Rémi Denis-Courmont <rem # videolan.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h>#include <vlc/vlc.h>#include <vlc/input.h>#include "vlc_interaction.h"#include "vlc_playlist.h"#include "vlc_meta.h"#include "network.h"#include "vlc_url.h"#include "vlc_tls.h"/***************************************************************************** * Module descriptor *****************************************************************************/static int  Open ( vlc_object_t * );static void Close( vlc_object_t * );#define PROXY_TEXT N_("HTTP proxy")#define PROXY_LONGTEXT N_( \    "HTTP proxy to be usesd It must be of the form " \    "http://[user[:pass]@]myproxy.mydomain:myport/ ; " \    "if empty, the http_proxy environment variable will be tried." )#define CACHING_TEXT N_("Caching value in ms")#define CACHING_LONGTEXT N_( \    "Caching value for HTTP streams. This " \    "value should be set in milliseconds." )#define AGENT_TEXT N_("HTTP user agent")#define AGENT_LONGTEXT N_("User agent that will be " \    "used for the connection.")#define RECONNECT_TEXT N_("Auto re-connect")#define RECONNECT_LONGTEXT N_( \    "Automatically try to reconnect to the stream in case of a sudden " \    "disconnect." )/// \bug missing space before you should#define CONTINUOUS_TEXT N_("Continuous stream")#define CONTINUOUS_LONGTEXT N_("Read a file that is " \    "being constantly updated (for example, a JPG file on a server)." \    "You should not globally enable this option as it will break all other " \    "types of HTTP streams." )vlc_module_begin();    set_description( _("HTTP input") );    set_capability( "access2", 0 );    set_shortname( _( "HTTP(S)" ) );    set_category( CAT_INPUT );    set_subcategory( SUBCAT_INPUT_ACCESS );    add_string( "http-proxy", NULL, NULL, PROXY_TEXT, PROXY_LONGTEXT,                VLC_FALSE );    add_integer( "http-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,                 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );    add_string( "http-user-agent", COPYRIGHT_MESSAGE , NULL, AGENT_TEXT,                AGENT_LONGTEXT, VLC_TRUE );    add_bool( "http-reconnect", 0, NULL, RECONNECT_TEXT,              RECONNECT_LONGTEXT, VLC_TRUE );    add_bool( "http-continuous", 0, NULL, CONTINUOUS_TEXT,              CONTINUOUS_LONGTEXT, VLC_TRUE );    add_suppressed_string("http-user");    add_suppressed_string("http-pwd");    add_shortcut( "http" );    add_shortcut( "https" );    add_shortcut( "unsv" );    set_callbacks( Open, Close );vlc_module_end();/***************************************************************************** * Local prototypes *****************************************************************************/struct access_sys_t{    int fd;    tls_session_t *p_tls;    v_socket_t    *p_vs;    /* From uri */    vlc_url_t url;    char    *psz_user_agent;    /* Proxy */    vlc_bool_t b_proxy;    vlc_url_t  proxy;    /* */    int        i_code;    char       *psz_protocol;    int        i_version;    char       *psz_mime;    char       *psz_pragma;    char       *psz_location;    vlc_bool_t b_mms;    vlc_bool_t b_icecast;    vlc_bool_t b_ssl;    vlc_bool_t b_chunked;    int64_t    i_chunk;    int        i_icy_meta;    char       *psz_icy_name;    char       *psz_icy_genre;    char       *psz_icy_title;    int i_remaining;    vlc_bool_t b_seekable;    vlc_bool_t b_reconnect;    vlc_bool_t b_continuous;    vlc_bool_t b_pace_control;};/* */static int Read( access_t *, uint8_t *, int );static int Seek( access_t *, int64_t );static int Control( access_t *, int, va_list );/* */static int Connect( access_t *, int64_t );static int Request( access_t *p_access, int64_t i_tell );static void Disconnect( access_t * );/***************************************************************************** * Open: *****************************************************************************/static int Open( vlc_object_t *p_this ){    access_t     *p_access = (access_t*)p_this;    access_sys_t *p_sys;    char         *psz, *p;    /* Set up p_access */    p_access->pf_read = Read;    p_access->pf_block = NULL;    p_access->pf_control = Control;    p_access->pf_seek = Seek;    p_access->info.i_update = 0;    p_access->info.i_size = 0;    p_access->info.i_pos = 0;    p_access->info.b_eof = VLC_FALSE;    p_access->info.i_title = 0;    p_access->info.i_seekpoint = 0;    p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );    memset( p_sys, 0, sizeof( access_sys_t ) );    p_sys->fd = -1;    p_sys->b_proxy = VLC_FALSE;    p_sys->i_version = 1;    p_sys->b_seekable = VLC_TRUE;    p_sys->psz_mime = NULL;    p_sys->psz_pragma = NULL;    p_sys->b_mms = VLC_FALSE;    p_sys->b_icecast = VLC_FALSE;    p_sys->psz_location = NULL;    p_sys->psz_user_agent = NULL;    p_sys->b_pace_control = VLC_TRUE;    p_sys->b_ssl = VLC_FALSE;    p_sys->p_tls = NULL;    p_sys->p_vs = NULL;    p_sys->i_icy_meta = 0;    p_sys->psz_icy_name = NULL;    p_sys->psz_icy_genre = NULL;    p_sys->psz_icy_title = NULL;    p_sys->i_remaining = 0;    /* Parse URI - remove spaces */    p = psz = strdup( p_access->psz_path );    while( (p = strchr( p, ' ' )) != NULL )        *p = '+';    vlc_UrlParse( &p_sys->url, psz, 0 );    free( psz );    if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' )    {        msg_Warn( p_access, "invalid host" );        goto error;    }    if( !strncmp( p_access->psz_access, "https", 5 ) )    {        /* HTTP over SSL */        p_sys->b_ssl = VLC_TRUE;        if( p_sys->url.i_port <= 0 )            p_sys->url.i_port = 443;    }    else    {        if( p_sys->url.i_port <= 0 )            p_sys->url.i_port = 80;    }    /* Do user agent */    p_sys->psz_user_agent = var_CreateGetString( p_access, "http-user-agent" );    /* Check proxy */    psz = var_CreateGetString( p_access, "http-proxy" );    if( *psz )    {        p_sys->b_proxy = VLC_TRUE;        vlc_UrlParse( &p_sys->proxy, psz, 0 );    }#ifdef HAVE_GETENV    else    {        char *psz_proxy = getenv( "http_proxy" );        if( psz_proxy && *psz_proxy )        {            p_sys->b_proxy = VLC_TRUE;            vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );        }    }#endif    free( psz );    if( p_sys->b_proxy )    {        if( p_sys->proxy.psz_host == NULL || *p_sys->proxy.psz_host == '\0' )        {            msg_Warn( p_access, "invalid proxy host" );            goto error;        }        if( p_sys->proxy.i_port <= 0 )        {            p_sys->proxy.i_port = 80;        }    }    msg_Dbg( p_access, "http: server='%s' port=%d file='%s",             p_sys->url.psz_host, p_sys->url.i_port, p_sys->url.psz_path );    if( p_sys->b_proxy )    {        msg_Dbg( p_access, "      proxy %s:%d", p_sys->proxy.psz_host,                 p_sys->proxy.i_port );    }    if( p_sys->url.psz_username && *p_sys->url.psz_username )    {        msg_Dbg( p_access, "      user='%s', pwd='%s'",                 p_sys->url.psz_username, p_sys->url.psz_password );    }    p_sys->b_reconnect = var_CreateGetBool( p_access, "http-reconnect" );    p_sys->b_continuous = var_CreateGetBool( p_access, "http-continuous" );connect:    /* Connect */    if( Connect( p_access, 0 ) )    {        /* Retry with http 1.0 */        msg_Dbg( p_access, "switching to HTTP version 1.0" );        p_sys->i_version = 0;        p_sys->b_seekable = VLC_FALSE;        if( p_access->b_die ||            Connect( p_access, 0 ) )        {            goto error;        }    }    if( p_sys->i_code == 401 )    {        char *psz_login = NULL; char *psz_password = NULL;        int i_ret;        msg_Dbg( p_access, "authentication failed" );        i_ret = intf_UserLoginPassword( p_access, "HTTP authentication",                         "Please enter a valid login and password.", &psz_login, &psz_password );        if( i_ret == DIALOG_OK_YES )        {            msg_Dbg( p_access, "retrying with user=%s, pwd=%s",                        psz_login, psz_password );            if( psz_login ) p_sys->url.psz_username = strdup( psz_login );            if( psz_password ) p_sys->url.psz_password = strdup( psz_password );            if( psz_login ) free( psz_login );            if( psz_password ) free( psz_password );            goto connect;        }        else        {            if( psz_login ) free( psz_login );            if( psz_password ) free( psz_password );            goto error;        }    }    if( ( p_sys->i_code == 301 || p_sys->i_code == 302 ||          p_sys->i_code == 303 || p_sys->i_code == 307 ) &&        p_sys->psz_location && *p_sys->psz_location )    {        playlist_t * p_playlist;        input_item_t *p_input_item;        msg_Dbg( p_access, "redirection to %s", p_sys->psz_location );        /* Do not accept redirection outside of HTTP works */        if( strncmp( p_sys->psz_location, "http", 4 )         || ( ( p_sys->psz_location[4] != ':' ) /* HTTP */           && strncmp( p_sys->psz_location + 4, "s:", 2 ) /* HTTP/SSL */ ) )        {            msg_Err( p_access, "insecure redirection ignored" );            goto error;        }        p_playlist = vlc_object_find( p_access, VLC_OBJECT_PLAYLIST,                                      FIND_ANYWHERE );        if( !p_playlist )        {            msg_Err( p_access, "redirection failed: can't find playlist" );            goto error;        }        /* Change the uri */        vlc_mutex_lock( &p_playlist->object_lock );        p_input_item = &p_playlist->status.p_item->input;        vlc_mutex_lock( &p_input_item->lock );        free( p_input_item->psz_uri );        free( p_access->psz_path );        p_input_item->psz_uri = strdup( p_sys->psz_location );        p_access->psz_path = strdup( p_sys->psz_location );        vlc_mutex_unlock( &p_input_item->lock );        vlc_mutex_unlock( &p_playlist->object_lock );        vlc_object_release( p_playlist );        /* Clean up current Open() run */        vlc_UrlClean( &p_sys->url );        vlc_UrlClean( &p_sys->proxy );        if( p_sys->psz_mime ) free( p_sys->psz_mime );        if( p_sys->psz_pragma ) free( p_sys->psz_pragma );        if( p_sys->psz_location ) free( p_sys->psz_location );        if( p_sys->psz_user_agent ) free( p_sys->psz_user_agent );        Disconnect( p_access );        free( p_sys );        /* Do new Open() run with new data */        return Open( p_this );    }    if( p_sys->b_mms )    {        msg_Dbg( p_access, "this is actually a live mms server, BAIL" );        goto error;    }    if( !strcmp( p_sys->psz_protocol, "ICY" ) || p_sys->b_icecast )    {        if( p_sys->psz_mime && strcasecmp( p_sys->psz_mime, "application/ogg" ) )        {            if( !strcasecmp( p_sys->psz_mime, "video/nsv" ) ||                !strcasecmp( p_sys->psz_mime, "video/nsa" ) )                p_access->psz_demux = strdup( "nsv" );            else if( !strcasecmp( p_sys->psz_mime, "audio/aac" ) ||                     !strcasecmp( p_sys->psz_mime, "audio/aacp" ) )                p_access->psz_demux = strdup( "m4a" );            else if( !strcasecmp( p_sys->psz_mime, "audio/mpeg" ) )                p_access->psz_demux = strdup( "mp3" );            msg_Info( p_access, "Raw-audio server found, %s demuxer selected",                      p_access->psz_demux );#if 0       /* Doesn't work really well because of the pre-buffering in             * shoutcast servers (the buffer content will be sent as fast as             * possible). */            p_sys->b_pace_control = VLC_FALSE;#endif        }        else if( !p_sys->psz_mime )        {             /* Shoutcast */             p_access->psz_demux = strdup( "mp3" );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -