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

📄 mvar.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * mvar.c : Variables handling for the HTTP Interface ***************************************************************************** * Copyright (C) 2001-2006 the VideoLAN team * $Id: mvar.c 16869 2006-09-26 21:07:43Z thresh $ * * 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. *****************************************************************************/#include "http.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 *E_(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 E_(mvar_Delete)( mvar_t *v ){    int i;    free( v->name );    free( v->value );    for( i = 0; i < v->i_field; i++ )    {        E_(mvar_Delete)( v->field[i] );    }    free( v->field );    free( v );}void E_(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 *E_(mvar_Duplicate)( const mvar_t *v ){    int i;    mvar_t *n;    n = E_(mvar_New)( v->name, v->value );    for( i = 0; i < v->i_field; i++ )    {        E_(mvar_AppendVar)( n, E_(mvar_Duplicate)( v->field[i] ) );    }    return n;}void E_(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 E_(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 *E_(mvar_GetVar)( mvar_t *s, const char *name ){    /* format: name[index].field */    char *field = strchr( name, '.' );    int i = 1 + ((field != NULL) ? (field - name) : strlen( name ));    char base[i];    char *p;    int i_index;    strlcpy( base, name, i );    if( field != NULL )        field++;    if( ( p = strchr( base, '[' ) ) != NULL )    {        *p++ = '\0';        sscanf( p, "%d]", &i_index );        if( i_index < 0 )        {            return NULL;        }    }    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 E_(mvar_GetVar)( s->field[i], field );                }                else                {                    return s->field[i];                }            }        }    }    return NULL;}char *E_(mvar_GetValue)( mvar_t *v, char *field ){    if( *field == '\0' )    {        return v->value;    }    else    {        mvar_t *f = E_(mvar_GetVar)( v, field );        if( f )        {            return f->value;        }        else        {            return field;        }    }}void E_(mvar_PushNewVar)( mvar_t *vars, const char *name,                          const char *value ){    mvar_t *f = E_(mvar_New)( name, value );    E_(mvar_PushVar)( vars, f );}void E_(mvar_AppendNewVar)( mvar_t *vars, const char *name,                            const char *value ){    mvar_t *f = E_(mvar_New)( name, value );    E_(mvar_AppendVar)( vars, f );}/* arg= start[:stop[:step]],.. */mvar_t *E_(mvar_IntegerSetNew)( const char *name, const char *arg ){    char *dup = strdup( arg );    char *str = dup;    mvar_t *s = E_(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 );                    E_(mvar_PushNewVar)( s, name, value );                }            }        }        str = p;    }    free( dup );    return s;}/******************************************************************** * Special sets handling ********************************************************************/mvar_t *E_(mvar_PlaylistSetNew)( intf_thread_t *p_intf, char *name,                                 playlist_t *p_pl ){    playlist_view_t *p_view;    mvar_t *s = E_(mvar_New)( name, "set" );    vlc_mutex_lock( &p_pl->object_lock );    p_view = playlist_ViewFind( p_pl, VIEW_CATEGORY ); /* FIXME */    if( p_view != NULL )        E_(PlaylistListNode)( p_intf, p_pl, p_view->p_root, name, s, 0 );    vlc_mutex_unlock( &p_pl->object_lock );    return s;}mvar_t *E_(mvar_InfoSetNew)( intf_thread_t *p_intf, char *name,                             input_thread_t *p_input ){    mvar_t *s = E_(mvar_New)( name, "set" );    int i, j;    if( p_input == NULL )    {        return s;    }    vlc_mutex_lock( &p_input->input.p_item->lock );    for ( i = 0; i < p_input->input.p_item->i_categories; i++ )    {        info_category_t *p_category = p_input->input.p_item->pp_categories[i];        char *psz;        mvar_t *cat  = E_(mvar_New)( name, "set" );        mvar_t *iset = E_(mvar_New)( "info", "set" );        psz = E_(FromUTF8)( p_intf, p_category->psz_name );        E_(mvar_AppendNewVar)( cat, "name", psz );        free( psz );        E_(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 = E_(mvar_New)( "info", "" );            char *psz_name = E_(FromUTF8)( p_intf, p_info->psz_name );            char *psz_value = E_(FromUTF8)( p_intf, p_info->psz_value );            /* msg_Dbg( p_input, "adding info name=%s value=%s",                     psz_name, psz_value ); */            E_(mvar_AppendNewVar)( info, "name",  psz_name );            E_(mvar_AppendNewVar)( info, "value", psz_value );            free( psz_name );            free( psz_value );            E_(mvar_AppendVar)( iset, info );        }        E_(mvar_AppendVar)( s, cat );    }    vlc_mutex_unlock( &p_input->input.p_item->lock );    return s;}mvar_t *E_(mvar_ObjectSetNew)( intf_thread_t *p_intf, char *psz_name,                               char *psz_capability ){    mvar_t *s = E_(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( !strcmp( p_parser->psz_capability, psz_capability ) )        {            mvar_t *sd = E_(mvar_New)( "sd", p_parser->psz_object_name );            E_(mvar_AppendNewVar)( sd, "name",                p_parser->psz_longname ? p_parser->psz_longname                : ( p_parser->psz_shortname ? p_parser->psz_shortname                : p_parser->psz_object_name ) );            E_(mvar_AppendVar)( s, sd );        }    }    vlc_list_release( p_list );    return s;}

⌨️ 快捷键说明

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