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

📄 macro.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * macro.c : Custom <vlc> macro handling ***************************************************************************** * Copyright (C) 2001-2005 the VideoLAN team * $Id: 7dde365b198104b2f8af2ccb12716aaa7de90db6 $ * * Authors: Gildas Bazin <gbazin@netcourrier.com> *          Laurent Aimar <fenrir@via.ecp.fr> *          Christophe Massiot <massiot@via.ecp.fr> * * 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. *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include "http.h"#include "macros.h"#include "vlc_url.h"static int MacroParse( macro_t *m, char *psz_src ){    char *dup = strdup( (char *)psz_src );    char *src = dup;    char *p;    int     i_skip;#define EXTRACT( name, l ) \        src += l;    \        p = strchr( src, '"' );             \        if( p )                             \        {                                   \            *p++ = '\0';                    \        }                                   \        m->name = strdup( src );            \        if( !p )                            \        {                                   \            break;                          \        }                                   \        src = p;    /* init m */    m->id = NULL;    m->param1 = NULL;    m->param2 = NULL;    /* parse */    src += 4;    while( *src )    {        while( *src == ' ')        {            src++;        }        if( !strncmp( src, "id=\"", 4 ) )        {            EXTRACT( id, 4 );        }        else if( !strncmp( src, "param1=\"", 8 ) )        {            EXTRACT( param1, 8 );        }        else if( !strncmp( src, "param2=\"", 8 ) )        {            EXTRACT( param2, 8 );        }        else        {            break;        }    }    if( strstr( src, "/>" ) )    {        src = strstr( src, "/>" ) + 2;    }    else    {        src += strlen( src );    }    if( m->id == NULL )    {        m->id = strdup( "" );    }    if( m->param1 == NULL )    {        m->param1 = strdup( "" );    }    if( m->param2 == NULL )    {        m->param2 = strdup( "" );    }    i_skip = src - dup;    free( dup );    return i_skip;#undef EXTRACT}static void MacroClean( macro_t *m ){    free( m->id );    free( m->param1 );    free( m->param2 );}static int StrToMacroType( const char *name ){    int i;    if( !name || *name == '\0')    {        return MVLC_UNKNOWN;    }    for( i = 0; StrToMacroTypeTab[i].psz_name != NULL; i++ )    {        if( !strcmp( name, StrToMacroTypeTab[i].psz_name ) )        {            return StrToMacroTypeTab[i].i_type;        }    }    return MVLC_UNKNOWN;}static void MacroDo( httpd_file_sys_t *p_args,                     macro_t *m,                     char *p_request, int i_request,                     char **pp_data,  int *pi_data,                     char **pp_dst ){    intf_thread_t  *p_intf = p_args->p_intf;    intf_sys_t     *p_sys = p_args->p_intf->p_sys;    char control[512];#define ALLOC( l ) \    {               \        int __i__ = *pp_dst - *pp_data; \        *pi_data += (l);                  \        *pp_data = realloc( *pp_data, *pi_data );   \        *pp_dst = (*pp_data) + __i__;   \    }#define PRINT( str ) \    ALLOC( strlen( str ) + 1 ); \    *pp_dst += sprintf( *pp_dst, "%s", str );#define PRINTS( str, s ) \    ALLOC( strlen( str ) + strlen( s ) + 1 ); \    { \        char * psz_cur = *pp_dst; \        *pp_dst += sprintf( *pp_dst, str, s ); \        while( psz_cur && *psz_cur ) \        {  \            /* Prevent script injection */ \            if( *psz_cur == '<' ) *psz_cur = '*'; \            if( *psz_cur == '>' ) *psz_cur = '*'; \            psz_cur++ ; \        } \    }    switch( StrToMacroType( m->id ) )    {        case MVLC_CONTROL:            if( i_request <= 0 )            {                break;            }            ExtractURIValue( p_request, "control", control, 512 );            if( *m->param1 && !strstr( m->param1, control ) )            {                msg_Warn( p_intf, "unauthorized control=%s", control );                break;            }            switch( StrToMacroType( control ) )            {                case MVLC_PLAY:                {                    int i_item;                    char item[512];                    ExtractURIValue( p_request, "item", item, 512 );                    i_item = atoi( item );                    /* id = 0 : simply ask playlist to play */                    if( i_item == 0 )                    {                        playlist_Play( p_sys->p_playlist );                        msg_Dbg( p_intf, "requested playlist play" );                        break;                    }                    playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,                                      true, NULL,                                      playlist_ItemGetById( p_sys->p_playlist,                                      i_item, true ) );                    msg_Dbg( p_intf, "requested playlist item: %i", i_item );                    break;                }                case MVLC_STOP:                    playlist_Control( p_sys->p_playlist, PLAYLIST_STOP,                                      true );                    msg_Dbg( p_intf, "requested playlist stop" );                    break;                case MVLC_PAUSE:                    playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE,                                      true );                    msg_Dbg( p_intf, "requested playlist pause" );                    break;                case MVLC_NEXT:                    playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP,                                      true, 1 );                    msg_Dbg( p_intf, "requested playlist next" );                    break;                case MVLC_PREVIOUS:                    playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP,                                      true, -1 );                    msg_Dbg( p_intf, "requested playlist previous" );                    break;                case MVLC_FULLSCREEN:                    if( p_sys->p_input )                    {                        vout_thread_t *p_vout;                        p_vout = vlc_object_find( p_sys->p_input,                                                  VLC_OBJECT_VOUT, FIND_CHILD );                        if( p_vout )                        {                            p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;                            vlc_object_release( p_vout );                            msg_Dbg( p_intf, "requested fullscreen toggle" );                        }                    }                    break;                case MVLC_SEEK:                {                    char value[30];                    ExtractURIValue( p_request, "seek_value", value, 30 );                    decode_URI( value );                    HandleSeek( p_intf, value );                    break;                }                case MVLC_VOLUME:                {                    char vol[8];                    audio_volume_t i_volume;                    int i_value;                    ExtractURIValue( p_request, "value", vol, 8 );                    aout_VolumeGet( p_intf, &i_volume );                    decode_URI( vol );                    if( vol[0] == '+' )                    {                        i_value = atoi( vol + 1 );                        if( (i_volume + i_value) > AOUT_VOLUME_MAX )                        {                            aout_VolumeSet( p_intf , AOUT_VOLUME_MAX );                            msg_Dbg( p_intf, "requested volume set: max" );                        }                        else                        {                            aout_VolumeSet( p_intf , (i_volume + i_value) );                            msg_Dbg( p_intf, "requested volume set: +%i", (i_volume + i_value) );                        }                    }                    else if( vol[0] == '-' )                    {                        i_value = atoi( vol + 1 );                        if( (i_volume - i_value) < AOUT_VOLUME_MIN )                        {                            aout_VolumeSet( p_intf , AOUT_VOLUME_MIN );                            msg_Dbg( p_intf, "requested volume set: min" );                        }                        else                        {                            aout_VolumeSet( p_intf , (i_volume - i_value) );                            msg_Dbg( p_intf, "requested volume set: -%i", (i_volume - i_value) );                        }                    }                    else if( strstr(vol, "%") != NULL )                    {                        i_value = atoi( vol );                        if( (i_value <= 400) && (i_value>=0) ){                            aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/400+AOUT_VOLUME_MIN);                            msg_Dbg( p_intf, "requested volume set: %i%%", atoi( vol ));                        }                    }                    else                    {                        i_value = atoi( vol );                        if( ( i_value <= AOUT_VOLUME_MAX ) && ( i_value >= AOUT_VOLUME_MIN ) )                        {                            aout_VolumeSet( p_intf , atoi( vol ) );                            msg_Dbg( p_intf, "requested volume set: %i", atoi( vol ) );                        }                    }                    break;                }                /* playlist management */                case MVLC_ADD:                {                    char mrl[1024], psz_name[1024], tmp[1024];                    char *p, *str;                    input_item_t *p_input;                    ExtractURIValue( p_request, "mrl", tmp, 1024 );                    decode_URI( tmp );                    ExtractURIValue( p_request, "name", psz_name, 1024 );                    decode_URI( psz_name );                    if( !*psz_name )                    {                        memcpy( psz_name, tmp, 1024 );                    }                    /* addslashes for backward compatibility with the old                     * http intf */                    p = mrl; str = tmp;                    while( *str != '\0' )                    {                        if( *str == '"' || *str == '\'' || *str == '\\' )                        {                            *p++ = '\\';                        }                        *p++ = *str;                        str++;                    }                    *p = '\0';                    p_input = MRLParse( p_intf, mrl, psz_name );                    char *psz_uri = input_item_GetURI( p_input );                    if( !p_input || !psz_uri || !*psz_uri )                    {                        msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );                    }                    else                    {                        int i_ret = playlist_AddInput( p_sys->p_playlist,                                     p_input,                                     PLAYLIST_APPEND, PLAYLIST_END, true,                                     false);                        vlc_gc_decref( p_input );                        if( i_ret == VLC_SUCCESS )                            msg_Dbg( p_intf, "requested mrl add: %s", mrl );                        else                            msg_Warn( p_intf, "adding mrl %s failed", mrl );                    }                    free( psz_uri );                    break;                }                case MVLC_DEL:                {                    int i_item, *p_items = NULL, i_nb_items = 0;                    char item[512], *p_parser = p_request;                    /* Get the list of items to delete */                    while( (p_parser =                            ExtractURIValue( p_parser, "item", item, 512 )) )                    {                        if( !*item ) continue;                        i_item = atoi( item );                        p_items = realloc( p_items, (i_nb_items + 1) *                                           sizeof(int) );                        p_items[i_nb_items] = i_item;                        i_nb_items++;

⌨️ 快捷键说明

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