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

📄 mvar.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * mvar.c : Variables handling for the HTTP Interface ***************************************************************************** * Copyright (C) 2001-2007 the VideoLAN team * $Id: e5252fffba260ba728abe4ecaabf3da79cd508b9 $ * * 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 <limits.h>#include <assert.h>/* Utility function for scandir */static int Filter( const char *foo ){    return strcmp( foo, "." );};static int InsensitiveAlphasort( const char **foo1,                                 const char **foo2 ){    return strcasecmp( *foo1, *foo2 );};mvar_t *mvar_New( const char *name, const char *value ){    mvar_t *v = malloc( sizeof( mvar_t ) );    if( !v ) return NULL;    v->name = strdup( name );    v->value = strdup( value ? value : "" );    v->i_field = 0;    v->field = malloc( sizeof( mvar_t * ) );    v->field[0] = NULL;    return v;}void mvar_Delete( mvar_t *v ){    int i;    free( v->name );    free( v->value );    for( i = 0; i < v->i_field; i++ )    {        mvar_Delete( v->field[i] );    }    free( v->field );    free( v );}void mvar_AppendVar( mvar_t *v, mvar_t *f ){    v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );    v->field[v->i_field] = f;    v->i_field++;}mvar_t *mvar_Duplicate( const mvar_t *v ){    int i;    mvar_t *n;    n = mvar_New( v->name, v->value );    for( i = 0; i < v->i_field; i++ )    {        mvar_AppendVar( n, mvar_Duplicate( v->field[i] ) );    }    return n;}void mvar_PushVar( mvar_t *v, mvar_t *f ){    v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );    if( v->i_field > 0 )    {        memmove( &v->field[1], &v->field[0], sizeof( mvar_t * ) * v->i_field );    }    v->field[0] = f;    v->i_field++;}void mvar_RemoveVar( mvar_t *v, mvar_t *f ){    int i;    for( i = 0; i < v->i_field; i++ )    {        if( v->field[i] == f )        {            break;        }    }    if( i >= v->i_field )    {        return;    }    if( i + 1 < v->i_field )    {        memmove( &v->field[i], &v->field[i+1], sizeof( mvar_t * ) * ( v->i_field - i - 1 ) );    }    v->i_field--;    /* FIXME should do a realloc */}mvar_t *mvar_GetVar( mvar_t *s, const char *name ){    /* format: name[index].field */    const char *field = strchr( name, '.' );    char base[1 + (field ? (size_t)(field - name) : strlen( name ))];    char *p;    int i_index, i;    strlcpy( base, name, sizeof (base) );    if( field != NULL )        field++;    if( ( p = strchr( base, '[' ) ) != NULL )    {        char *end;        unsigned long l = strtoul( p, &end, 0 );        if( ( l > INT_MAX ) || strcmp( "]", end ) )            return NULL;        *p++ = '\0';        i_index = (int)l;    }    else    {        i_index = 0;    }    for( i = 0; i < s->i_field; i++ )    {        if( !strcmp( s->field[i]->name, base ) )        {            if( i_index > 0 )            {                i_index--;            }            else            {                if( field )                {                    return mvar_GetVar( s->field[i], field );                }                else                {                    return s->field[i];                }            }        }    }    return NULL;}char *mvar_GetValue( mvar_t *v, char *field ){    if( *field == '\0' )    {        return v->value;    }    else    {        mvar_t *f = mvar_GetVar( v, field );        if( f )        {            return f->value;        }        else        {            return field;        }    }}void mvar_PushNewVar( mvar_t *vars, const char *name,                          const char *value ){    mvar_t *f = mvar_New( name, value );    mvar_PushVar( vars, f );}void mvar_AppendNewVar( mvar_t *vars, const char *name,                            const char *value ){    mvar_t *f = mvar_New( name, value );    mvar_AppendVar( vars, f );}/* arg= start[:stop[:step]],.. */mvar_t *mvar_IntegerSetNew( const char *name, const char *arg ){    char *dup = strdup( arg );    char *str = dup;    mvar_t *s = mvar_New( name, "set" );    while( str )    {        char *p;        int  i_start,i_stop,i_step;        int  i_match;        p = strchr( str, ',' );        if( p )        {            *p++ = '\0';        }        i_step = 0;        i_match = sscanf( str, "%d:%d:%d", &i_start, &i_stop, &i_step );        if( i_match == 1 )        {            i_stop = i_start;            i_step = 1;        }        else if( i_match == 2 )        {            i_step = i_start < i_stop ? 1 : -1;        }        if( i_match >= 1 )        {            int i;            if( ( i_start <= i_stop && i_step > 0 ) ||                ( i_start >= i_stop && i_step < 0 ) )            {                for( i = i_start; ; i += i_step )                {                    char   value[79];                    if( ( i_step > 0 && i > i_stop ) ||                        ( i_step < 0 && i < i_stop ) )                    {                        break;                    }                    sprintf( value, "%d", i );                    mvar_PushNewVar( s, name, value );                }            }        }        str = p;    }    free( dup );    return s;}/******************************************************************** * Special sets handling ********************************************************************/mvar_t *mvar_PlaylistSetNew( intf_thread_t *p_intf, char *name,                                 playlist_t *p_pl ){    mvar_t *s = mvar_New( name, "set" );    vlc_object_lock( p_pl );    PlaylistListNode( p_intf, p_pl, p_pl->p_root_category , name, s, 0 );    vlc_object_unlock( p_pl );    return s;}mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input ){    mvar_t *s = mvar_New( name, "set" );    int i, j;    if( p_input == NULL || p_input->p == NULL /* workarround assert in input_GetItem */ )    {        return s;    }    vlc_mutex_lock( &input_GetItem(p_input)->lock );    for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )    {        info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];        mvar_t *cat  = mvar_New( name, "set" );        mvar_t *iset = mvar_New( "info", "set" );        mvar_AppendNewVar( cat, "name", p_category->psz_name );        mvar_AppendVar( cat, iset );        for ( j = 0; j < p_category->i_infos; j++ )        {            info_t *p_info = p_category->pp_infos[j];            mvar_t *info = mvar_New( "info", "" );            /* msg_Dbg( p_input, "adding info name=%s value=%s",                     psz_name, psz_value ); */            mvar_AppendNewVar( info, "name",  p_info->psz_name );            mvar_AppendNewVar( info, "value", p_info->psz_value );            mvar_AppendVar( iset, info );        }        mvar_AppendVar( s, cat );    }    vlc_mutex_unlock( &input_GetItem(p_input)->lock );    return s;}mvar_t *mvar_ObjectSetNew( intf_thread_t *p_intf, char *psz_name,                               const char *psz_capability ){    mvar_t *s = mvar_New( psz_name, "set" );    int i;    vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,                                        FIND_ANYWHERE );    for( i = 0; i < p_list->i_count; i++ )    {        module_t *p_parser = (module_t *)p_list->p_values[i].p_object;        if( module_IsCapable( p_parser, psz_capability ) )        {            mvar_t *sd = mvar_New( "sd", module_GetObjName( p_parser ) );            mvar_AppendNewVar( sd, "name",

⌨️ 快捷键说明

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