Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

rpn.c

00001 /*****************************************************************************
00002  * rpn.c : RPN evaluator for the HTTP Interface
00003  *****************************************************************************
00004  * Copyright (C) 2001-2005 the VideoLAN team
00005  * $Id: http.c 12225 2005-08-18 10:01:30Z massiot $
00006  *
00007  * Authors: Gildas Bazin <[email protected]>
00008  *          Laurent Aimar <[email protected]>
00009  *          Christophe Massiot <[email protected]>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00024  *****************************************************************************/
00025 
00026 #include "http.h"
00027 
00028 static vlc_object_t *GetVLCObject( intf_thread_t *p_intf,
00029                                    const char *psz_object,
00030                                    vlc_bool_t *pb_need_release )
00031 {
00032     intf_sys_t    *p_sys = p_intf->p_sys;
00033     int i_object_type = 0;
00034     vlc_object_t *p_object = NULL;
00035     *pb_need_release = VLC_FALSE;
00036 
00037     if( !strcmp( psz_object, "VLC_OBJECT_ROOT" ) )
00038         i_object_type = VLC_OBJECT_ROOT;
00039     else if( !strcmp( psz_object, "VLC_OBJECT_VLC" ) )
00040         p_object = VLC_OBJECT(p_intf->p_vlc);
00041     else if( !strcmp( psz_object, "VLC_OBJECT_INTF" ) )
00042         p_object = VLC_OBJECT(p_intf);
00043     else if( !strcmp( psz_object, "VLC_OBJECT_PLAYLIST" ) )
00044         p_object = VLC_OBJECT(p_sys->p_playlist);
00045     else if( !strcmp( psz_object, "VLC_OBJECT_INPUT" ) )
00046         p_object = VLC_OBJECT(p_sys->p_input);
00047     else if( !strcmp( psz_object, "VLC_OBJECT_VOUT" ) )
00048         i_object_type = VLC_OBJECT_VOUT;
00049     else if( !strcmp( psz_object, "VLC_OBJECT_AOUT" ) )
00050         i_object_type = VLC_OBJECT_AOUT;
00051     else if( !strcmp( psz_object, "VLC_OBJECT_SOUT" ) )
00052         i_object_type = VLC_OBJECT_SOUT;
00053     else
00054         msg_Warn( p_intf, "unknown object type (%s)", psz_object );
00055 
00056     if( p_object == NULL && i_object_type )
00057     {
00058         *pb_need_release = VLC_TRUE;
00059         p_object = vlc_object_find( p_intf, i_object_type, FIND_ANYWHERE );
00060     }
00061 
00062     return p_object;
00063 }
00064 
00065 void E_(SSInit)( rpn_stack_t *st )
00066 {
00067     st->i_stack = 0;
00068 }
00069 
00070 void E_(SSClean)( rpn_stack_t *st )
00071 {
00072     while( st->i_stack > 0 )
00073     {
00074         free( st->stack[--st->i_stack] );
00075     }
00076 }
00077 
00078 void E_(SSPush)( rpn_stack_t *st, const char *s )
00079 {
00080     if( st->i_stack < STACK_MAX )
00081     {
00082         st->stack[st->i_stack++] = strdup( s );
00083     }
00084 }
00085 
00086 char *E_(SSPop)( rpn_stack_t *st )
00087 {
00088     if( st->i_stack <= 0 )
00089     {
00090         return strdup( "" );
00091     }
00092     else
00093     {
00094         return st->stack[--st->i_stack];
00095     }
00096 }
00097 
00098 int E_(SSPopN)( rpn_stack_t *st, mvar_t  *vars )
00099 {
00100     char *name;
00101     char *value;
00102 
00103     char *end;
00104     int  i;
00105 
00106     name = E_(SSPop)( st );
00107     i = strtol( name, &end, 0 );
00108     if( end == name )
00109     {
00110         value = E_(mvar_GetValue)( vars, name );
00111         i = atoi( value );
00112     }
00113     free( name );
00114 
00115     return( i );
00116 }
00117 
00118 void E_(SSPushN)( rpn_stack_t *st, int i )
00119 {
00120     char v[512];
00121 
00122     sprintf( v, "%d", i );
00123     E_(SSPush)( st, v );
00124 }
00125 
00126 void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
00127                       rpn_stack_t *st, char *exp )
00128 {
00129     intf_sys_t    *p_sys = p_intf->p_sys;
00130 
00131     while( exp != NULL && *exp != '\0' )
00132     {
00133         char *p, *s;
00134 
00135         /* skip space */
00136         while( *exp == ' ' )
00137         {
00138             exp++;
00139         }
00140 
00141         if( *exp == '\'' )
00142         {
00143             /* extract string */
00144             p = E_(FirstWord)( exp, exp );
00145             E_(SSPush)( st, exp );
00146             exp = p;
00147             continue;
00148         }
00149 
00150         /* extract token */
00151         p = E_(FirstWord)( exp, exp );
00152         s = exp;
00153         if( p == NULL )
00154         {
00155             exp += strlen( exp );
00156         }
00157         else
00158         {
00159             exp = p;
00160         }
00161 
00162         if( *s == '\0' )
00163         {
00164             break;
00165         }
00166 
00167         /* 1. Integer function */
00168         if( !strcmp( s, "!" ) )
00169         {
00170             E_(SSPushN)( st, ~E_(SSPopN)( st, vars ) );
00171         }
00172         else if( !strcmp( s, "^" ) )
00173         {
00174             E_(SSPushN)( st, E_(SSPopN)( st, vars ) ^ E_(SSPopN)( st, vars ) );
00175         }
00176         else if( !strcmp( s, "&" ) )
00177         {
00178             E_(SSPushN)( st, E_(SSPopN)( st, vars ) & E_(SSPopN)( st, vars ) );
00179         }
00180         else if( !strcmp( s, "|" ) )
00181         {
00182             E_(SSPushN)( st, E_(SSPopN)( st, vars ) | E_(SSPopN)( st, vars ) );
00183         }
00184         else if( !strcmp( s, "+" ) )
00185         {
00186             E_(SSPushN)( st, E_(SSPopN)( st, vars ) + E_(SSPopN)( st, vars ) );
00187         }
00188         else if( !strcmp( s, "-" ) )
00189         {
00190             int j = E_(SSPopN)( st, vars );
00191             int i = E_(SSPopN)( st, vars );
00192             E_(SSPushN)( st, i - j );
00193         }
00194         else if( !strcmp( s, "*" ) )
00195         {
00196             E_(SSPushN)( st, E_(SSPopN)( st, vars ) * E_(SSPopN)( st, vars ) );
00197         }
00198         else if( !strcmp( s, "/" ) )
00199         {
00200             int i, j;
00201 
00202             j = E_(SSPopN)( st, vars );
00203             i = E_(SSPopN)( st, vars );
00204 
00205             E_(SSPushN)( st, j != 0 ? i / j : 0 );
00206         }
00207         else if( !strcmp( s, "%" ) )
00208         {
00209             int i, j;
00210 
00211             j = E_(SSPopN)( st, vars );
00212             i = E_(SSPopN)( st, vars );
00213 
00214             E_(SSPushN)( st, j != 0 ? i % j : 0 );
00215         }
00216         /* 2. integer tests */
00217         else if( !strcmp( s, "=" ) )
00218         {
00219             E_(SSPushN)( st, E_(SSPopN)( st, vars ) == E_(SSPopN)( st, vars ) ? -1 : 0 );
00220         }
00221         else if( !strcmp( s, "!=" ) )
00222         {
00223             E_(SSPushN)( st, E_(SSPopN)( st, vars ) != E_(SSPopN)( st, vars ) ? -1 : 0 );
00224         }
00225         else if( !strcmp( s, "<" ) )
00226         {
00227             int j = E_(SSPopN)( st, vars );
00228             int i = E_(SSPopN)( st, vars );
00229 
00230             E_(SSPushN)( st, i < j ? -1 : 0 );
00231         }
00232         else if( !strcmp( s, ">" ) )
00233         {
00234             int j = E_(SSPopN)( st, vars );
00235             int i = E_(SSPopN)( st, vars );
00236 
00237             E_(SSPushN)( st, i > j ? -1 : 0 );
00238         }
00239         else if( !strcmp( s, "<=" ) )
00240         {
00241             int j = E_(SSPopN)( st, vars );
00242             int i = E_(SSPopN)( st, vars );
00243 
00244             E_(SSPushN)( st, i <= j ? -1 : 0 );
00245         }
00246         else if( !strcmp( s, ">=" ) )
00247         {
00248             int j = E_(SSPopN)( st, vars );
00249             int i = E_(SSPopN)( st, vars );
00250 
00251             E_(SSPushN)( st, i >= j ? -1 : 0 );
00252         }
00253         /* 3. string functions */
00254         else if( !strcmp( s, "strcat" ) )
00255         {
00256             char *s2 = E_(SSPop)( st );
00257             char *s1 = E_(SSPop)( st );
00258             char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
00259 
00260             strcpy( str, s1 );
00261             strcat( str, s2 );
00262 
00263             E_(SSPush)( st, str );
00264             free( s1 );
00265             free( s2 );
00266             free( str );
00267         }
00268         else if( !strcmp( s, "strcmp" ) )
00269         {
00270             char *s2 = E_(SSPop)( st );
00271             char *s1 = E_(SSPop)( st );
00272 
00273             E_(SSPushN)( st, strcmp( s1, s2 ) );
00274             free( s1 );
00275             free( s2 );
00276         }
00277         else if( !strcmp( s, "strncmp" ) )
00278         {
00279             int n = E_(SSPopN)( st, vars );
00280             char *s2 = E_(SSPop)( st );
00281             char *s1 = E_(SSPop)( st );
00282 
00283             E_(SSPushN)( st, strncmp( s1, s2 , n ) );
00284             free( s1 );
00285             free( s2 );
00286         }
00287         else if( !strcmp( s, "strsub" ) )
00288         {
00289             int n = E_(SSPopN)( st, vars );
00290             int m = E_(SSPopN)( st, vars );
00291             int i_len;
00292             char *s = E_(SSPop)( st );
00293             char *str;
00294 
00295             if( n >= m )
00296             {
00297                 i_len = n - m + 1;
00298             }
00299             else
00300             {
00301                 i_len = 0;
00302             }
00303 
00304             str = malloc( i_len + 1 );
00305 
00306             memcpy( str, s + m - 1, i_len );
00307             str[ i_len ] = '\0';
00308 
00309             E_(SSPush)( st, str );
00310             free( s );
00311             free( str );
00312         }
00313         else if( !strcmp( s, "strlen" ) )
00314         {
00315             char *str = E_(SSPop)( st );
00316 
00317             E_(SSPushN)( st, strlen( str ) );
00318             free( str );
00319         }
00320         else if( !strcmp( s, "str_replace" ) )
00321         {
00322             char *psz_to = E_(SSPop)( st );
00323             char *psz_from = E_(SSPop)( st );
00324             char *psz_in = E_(SSPop)( st );
00325             char *psz_in_current = psz_in;
00326             char *psz_out = malloc( strlen(psz_in) * strlen(psz_to) + 1 );
00327             char *psz_out_current = psz_out;
00328 
00329             while( (p = strstr( psz_in_current, psz_from )) != NULL )
00330             {
00331                 memcpy( psz_out_current, psz_in_current, p - psz_in_current );
00332                 psz_out_current += p - psz_in_current;
00333                 strcpy( psz_out_current, psz_to );
00334                 psz_out_current += strlen(psz_to);
00335                 psz_in_current = p + strlen(psz_from);
00336             }
00337             strcpy( psz_out_current, psz_in_current );
00338             psz_out_current += strlen(psz_in_current);
00339             *psz_out_current = '\0';
00340 
00341             E_(SSPush)( st, psz_out );
00342             free( psz_to );
00343             free( psz_from );
00344             free( psz_in );
00345             free( psz_out );
00346         }
00347         else if( !strcmp( s, "url_extract" ) )
00348         {
00349             char *url = E_(mvar_GetValue)( vars, "url_value" );
00350             char *name = E_(SSPop)( st );
00351             char value[512];
00352             char *tmp;
00353 
00354             E_(ExtractURIValue)( url, name, value, 512 );
00355             E_(DecodeEncodedURI)( value );
00356             tmp = E_(FromUTF8)( p_intf, value );
00357             E_(SSPush)( st, tmp );
00358             free( tmp );
00359             free( name );
00360         }
00361         else if( !strcmp( s, "url_encode" ) )
00362         {
00363             char *url = E_(SSPop)( st );
00364             char *value;
00365 
00366             value = E_(ToUTF8)( p_intf, url );
00367             free( url );
00368             url = value;
00369             value = vlc_UrlEncode( url );
00370             free( url );
00371             E_(SSPush)( st, value );
00372             free( value );
00373         }
00374         else if( !strcmp( s, "addslashes" ) )
00375         {
00376             char *psz_src = E_(SSPop)( st );
00377             char *psz_dest;
00378             char *str = psz_src;
00379 
00380             p = psz_dest = malloc( strlen( str ) * 2 + 1 );
00381 
00382             while( *str != '\0' )
00383             {
00384                 if( *str == '"' || *str == '\'' || *str == '\\' )
00385                 {
00386                     *p++ = '\\';
00387                 }
00388                 *p++ = *str;
00389                 str++;
00390             }
00391             *p = '\0';
00392 
00393             E_(SSPush)( st, psz_dest );
00394             free( psz_src );
00395             free( psz_dest );
00396         }
00397         else if( !strcmp( s, "stripslashes" ) )
00398         {
00399             char *psz_src = E_(SSPop)( st );
00400             char *psz_dest;
00401 
00402             p = psz_dest = strdup( psz_src );
00403 
00404             while( *psz_src )
00405             {
00406                 if( *psz_src == '\\' && *(psz_src + 1) )
00407                 {
00408                     psz_src++;
00409                 }
00410                 *p++ = *psz_src++;
00411             }
00412             *p = '\0';
00413 
00414             E_(SSPush)( st, psz_dest );
00415             free( psz_src );
00416             free( psz_dest );
00417         }
00418         else if( !strcmp( s, "htmlspecialchars" ) )
00419         {
00420             char *psz_src = E_(SSPop)( st );
00421             char *psz_dest;
00422             char *str = psz_src;
00423 
00424             p = psz_dest = malloc( strlen( str ) * 6 + 1 );
00425 
00426             while( *str != '\0' )
00427             {
00428                 if( *str == '&' )
00429                 {
00430                     strcpy( p, "&amp;" );
00431                     p += 5;
00432                 }
00433                 else if( *str == '\"' )
00434                 {
00435                     strcpy( p, "&quot;" );
00436                     p += 6;
00437                 }
00438                 else if( *str == '\'' )
00439                 {
00440                     strcpy( p, "&#039;" );
00441                     p += 6;
00442                 }
00443                 else if( *str == '<' )
00444                 {
00445                     strcpy( p, "&lt;" );
00446                     p += 4;
00447                 }
00448                 else if( *str == '>' )
00449                 {
00450                     strcpy( p, "&gt;" );
00451                     p += 4;
00452                 }
00453                 else
00454                 {
00455                     *p++ = *str;
00456                 }
00457                 str++;
00458             }
00459             *p = '\0';
00460 
00461             E_(SSPush)( st, psz_dest );
00462             free( psz_src );
00463             free( psz_dest );
00464         }
00465         else if( !strcmp( s, "realpath" ) )
00466         {
00467             char *psz_src = E_(SSPop)( st );
00468             char *psz_dir = E_(RealPath)( p_intf, psz_src );
00469 
00470             E_(SSPush)( st, psz_dir );
00471             free( psz_src );
00472             free( psz_dir );
00473         }
00474         /* 4. stack functions */
00475         else if( !strcmp( s, "dup" ) )
00476         {
00477             char *str = E_(SSPop)( st );
00478             E_(SSPush)( st, str );
00479             E_(SSPush)( st, str );
00480             free( str );
00481         }
00482         else if( !strcmp( s, "drop" ) )
00483         {
00484             char *str = E_(SSPop)( st );
00485             free( str );
00486         }
00487         else if( !strcmp( s, "swap" ) )
00488         {
00489             char *s1 = E_(SSPop)( st );
00490             char *s2 = E_(SSPop)( st );
00491 
00492             E_(SSPush)( st, s1 );
00493             E_(SSPush)( st, s2 );
00494             free( s1 );
00495             free( s2 );
00496         }
00497         else if( !strcmp( s, "flush" ) )
00498         {
00499             E_(SSClean)( st );
00500             E_(SSInit)( st );
00501         }
00502         else if( !strcmp( s, "store" ) )
00503         {
00504             char *value = E_(SSPop)( st );
00505             char *name  = E_(SSPop)( st );
00506 
00507             E_(mvar_PushNewVar)( vars, name, value );
00508             free( name );
00509             free( value );
00510         }
00511         else if( !strcmp( s, "value" ) )
00512         {
00513             char *name  = E_(SSPop)( st );
00514             char *value = E_(mvar_GetValue)( vars, name );
00515 
00516             E_(SSPush)( st, value );
00517 
00518             free( name );
00519         }
00520         /* 5. player control */
00521         else if( !strcmp( s, "vlc_play" ) )
00522         {
00523             int i_id = E_(SSPopN)( st, vars );
00524             int i_ret;
00525 
00526             i_ret = playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
00527                                       playlist_ItemGetById( p_sys->p_playlist,
00528                                       i_id ) );
00529             msg_Dbg( p_intf, "requested playlist item: %i", i_id );
00530             E_(SSPushN)( st, i_ret );
00531         }
00532         else if( !strcmp( s, "vlc_stop" ) )
00533         {
00534             playlist_Control( p_sys->p_playlist, PLAYLIST_STOP );
00535             msg_Dbg( p_intf, "requested playlist stop" );
00536         }
00537         else if( !strcmp( s, "vlc_pause" ) )
00538         {
00539             playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
00540             msg_Dbg( p_intf, "requested playlist pause" );
00541         }
00542         else if( !strcmp( s, "vlc_next" ) )
00543         {
00544             playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
00545             msg_Dbg( p_intf, "requested playlist next" );
00546         }
00547         else if( !strcmp( s, "vlc_previous" ) )
00548         {
00549             playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1 );
00550             msg_Dbg( p_intf, "requested playlist previous" );
00551         }
00552         else if( !strcmp( s, "vlc_seek" ) )
00553         {
00554             char *psz_value = E_(SSPop)( st );
00555             E_(HandleSeek)( p_intf, psz_value );
00556             msg_Dbg( p_intf, "requested playlist seek: %s", psz_value );
00557             free( psz_value );
00558         }
00559         else if( !strcmp( s, "vlc_var_type" )
00560                   || !strcmp( s, "vlc_config_type" ) )
00561         {
00562             vlc_object_t *p_object;
00563             const char *psz_type = NULL;
00564             int i_type = 0;
00565 
00566             if( !strcmp( s, "vlc_var_type" ) )
00567             {
00568                 char *psz_object = E_(SSPop)( st );
00569                 char *psz_variable = E_(SSPop)( st );
00570                 vlc_bool_t b_need_release;
00571 
00572                 p_object = GetVLCObject( p_intf, psz_object, &b_need_release );
00573 
00574                 if( p_object != NULL )
00575                     i_type = var_Type( p_object, psz_variable );
00576                 free( psz_variable );
00577                 free( psz_object );
00578                 if( b_need_release && p_object != NULL )
00579                     vlc_object_release( p_object );
00580             }
00581             else
00582             {
00583                 char *psz_variable = E_(SSPop)( st );
00584                 p_object = VLC_OBJECT(p_intf);
00585                 i_type = config_GetType( p_object, psz_variable );
00586                 free( psz_variable );
00587             }
00588 
00589             if( p_object != NULL )
00590             {
00591                 switch( i_type & VLC_VAR_TYPE )
00592                 {
00593                 case VLC_VAR_BOOL:
00594                     psz_type = "VLC_VAR_BOOL";
00595                     break;
00596                 case VLC_VAR_INTEGER:
00597                     psz_type = "VLC_VAR_INTEGER";
00598                     break;
00599                 case VLC_VAR_HOTKEY:
00600                     psz_type = "VLC_VAR_HOTKEY";
00601                     break;
00602                 case VLC_VAR_STRING:
00603                     psz_type = "VLC_VAR_STRING";
00604                     break;
00605                 case VLC_VAR_MODULE:
00606                     psz_type = "VLC_VAR_MODULE";
00607                     break;
00608                 case VLC_VAR_FILE:
00609                     psz_type = "VLC_VAR_FILE";
00610                     break;
00611                 case VLC_VAR_DIRECTORY:
00612                     psz_type = "VLC_VAR_DIRECTORY";
00613                     break;
00614                 case VLC_VAR_VARIABLE:
00615                     psz_type = "VLC_VAR_VARIABLE";
00616                     break;
00617                 case VLC_VAR_FLOAT:
00618                     psz_type = "VLC_VAR_FLOAT";
00619                     break;
00620                 default:
00621                     psz_type = "UNDEFINED";
00622                 }
00623             }
00624             else
00625                 psz_type = "INVALID";
00626 
00627             E_(SSPush)( st, psz_type );
00628         }
00629         else if( !strcmp( s, "vlc_var_set" ) )
00630         {
00631             char *psz_object = E_(SSPop)( st );
00632             char *psz_variable = E_(SSPop)( st );
00633             vlc_bool_t b_need_release;
00634 
00635             vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
00636                                                    &b_need_release );
00637 
00638             if( p_object != NULL )
00639             {
00640                 vlc_bool_t b_error = VLC_FALSE;
00641                 char *psz_value = NULL;
00642                 vlc_value_t val;
00643                 int i_type;
00644 
00645                 i_type = var_Type( p_object, psz_variable );
00646 
00647                 switch( i_type & VLC_VAR_TYPE )
00648                 {
00649                 case VLC_VAR_BOOL:
00650                     val.b_bool = E_(SSPopN)( st, vars );
00651                     msg_Dbg( p_intf, "requested %s var change: %s->%d",
00652                              psz_object, psz_variable, val.b_bool );
00653                     break;
00654                 case VLC_VAR_INTEGER:
00655                 case VLC_VAR_HOTKEY:
00656                     val.i_int = E_(SSPopN)( st, vars );
00657                     msg_Dbg( p_intf, "requested %s var change: %s->%d",
00658                              psz_object, psz_variable, val.i_int );
00659                     break;
00660                 case VLC_VAR_STRING:
00661                 case VLC_VAR_MODULE:
00662                 case VLC_VAR_FILE:
00663                 case VLC_VAR_DIRECTORY:
00664                 case VLC_VAR_VARIABLE:
00665                     val.psz_string = psz_value = E_(SSPop)( st );
00666                     msg_Dbg( p_intf, "requested %s var change: %s->%s",
00667                              psz_object, psz_variable, psz_value );
00668                     break;
00669                 case VLC_VAR_FLOAT:
00670                     psz_value = E_(SSPop)( st );
00671                     val.f_float = atof( psz_value );
00672                     msg_Dbg( p_intf, "requested %s var change: %s->%f",
00673                              psz_object, psz_variable, val.f_float );
00674                     break;
00675                 default:
00676                     E_(SSPopN)( st, vars );
00677                     msg_Warn( p_intf, "invalid %s variable type %d (%s)",
00678                               psz_object, i_type & VLC_VAR_TYPE, psz_variable );
00679                     b_error = VLC_TRUE;
00680                 }
00681 
00682                 if( !b_error )
00683                     var_Set( p_object, psz_variable, val );
00684                 if( psz_value != NULL )
00685                     free( psz_value );
00686             }
00687             else
00688                 msg_Warn( p_intf, "vlc_var_set called without an object" );
00689             free( psz_variable );
00690             free( psz_object );
00691 
00692             if( b_need_release && p_object != NULL )
00693                 vlc_object_release( p_object );
00694         }
00695         else if( !strcmp( s, "vlc_var_get" ) )
00696         {
00697             char *psz_object = E_(SSPop)( st );
00698             char *psz_variable = E_(SSPop)( st );
00699             vlc_bool_t b_need_release;
00700 
00701             vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
00702                                                    &b_need_release );
00703 
00704             if( p_object != NULL )
00705             {
00706                 vlc_value_t val;
00707                 int i_type;
00708 
00709                 i_type = var_Type( p_object, psz_variable );
00710                 var_Get( p_object, psz_variable, &val );
00711 
00712                 switch( i_type & VLC_VAR_TYPE )
00713                 {
00714                 case VLC_VAR_BOOL:
00715                     E_(SSPushN)( st, val.b_bool );
00716                     break;
00717                 case VLC_VAR_INTEGER:
00718                 case VLC_VAR_HOTKEY:
00719                     E_(SSPushN)( st, val.i_int );
00720                     break;
00721                 case VLC_VAR_STRING:
00722                 case VLC_VAR_MODULE:
00723                 case VLC_VAR_FILE:
00724                 case VLC_VAR_DIRECTORY:
00725                 case VLC_VAR_VARIABLE:
00726                     E_(SSPush)( st, val.psz_string );
00727                     free( val.psz_string );
00728                     break;
00729                 case VLC_VAR_FLOAT:
00730                 {
00731                     char psz_value[20];
00732                     snprintf( psz_value, sizeof(psz_value), "%f", val.f_float );
00733                     E_(SSPush)( st, psz_value );
00734                     break;
00735                 }
00736                 default:
00737                     msg_Warn( p_intf, "invalid %s variable type %d (%s)",
00738                               psz_object, i_type & VLC_VAR_TYPE, psz_variable );
00739                     E_(SSPush)( st, "" );
00740                 }
00741             }
00742             else
00743             {
00744                 msg_Warn( p_intf, "vlc_var_get called without an object" );
00745                 E_(SSPush)( st, "" );
00746             }
00747             free( psz_variable );
00748             free( psz_object );
00749 
00750             if( b_need_release && p_object != NULL )
00751                 vlc_object_release( p_object );
00752         }
00753         else if( !strcmp( s, "vlc_config_set" ) )
00754         {
00755             char *psz_variable = E_(SSPop)( st );
00756             int i_type = config_GetType( p_intf, psz_variable );
00757 
00758             switch( i_type & VLC_VAR_TYPE )
00759             {
00760             case VLC_VAR_BOOL:
00761             case VLC_VAR_INTEGER:
00762                 config_PutInt( p_intf, psz_variable, E_(SSPopN)( st, vars ) );
00763                 break;
00764             case VLC_VAR_STRING:
00765             case VLC_VAR_MODULE:
00766             case VLC_VAR_FILE:
00767             case VLC_VAR_DIRECTORY:
00768             {
00769                 char *psz_string = E_(SSPop)( st );
00770                 config_PutPsz( p_intf, psz_variable, psz_string );
00771                 free( psz_string );
00772                 break;
00773             }
00774             case VLC_VAR_FLOAT:
00775             {
00776                 char *psz_string = E_(SSPop)( st );
00777                 config_PutFloat( p_intf, psz_variable, atof(psz_string) );
00778                 free( psz_string );
00779                 break;
00780             }
00781             default:
00782                 msg_Warn( p_intf, "vlc_config_set called on unknown var (%s)",
00783                           psz_variable );
00784             }
00785             free( psz_variable );
00786         }
00787         else if( !strcmp( s, "vlc_config_get" ) )
00788         {
00789             char *psz_variable = E_(SSPop)( st );
00790             int i_type = config_GetType( p_intf, psz_variable );
00791 
00792             switch( i_type & VLC_VAR_TYPE )
00793             {
00794             case VLC_VAR_BOOL:
00795             case VLC_VAR_INTEGER:
00796                 E_(SSPushN)( st, config_GetInt( p_intf, psz_variable ) );
00797                 break;
00798             case VLC_VAR_STRING:
00799             case VLC_VAR_MODULE:
00800             case VLC_VAR_FILE:
00801             case VLC_VAR_DIRECTORY:
00802             {
00803                 char *psz_string = config_GetPsz( p_intf, psz_variable );
00804                 E_(SSPush)( st, psz_string );
00805                 free( psz_string );
00806                 break;
00807             }
00808             case VLC_VAR_FLOAT:
00809             {
00810                 char psz_string[20];
00811                 snprintf( psz_string, sizeof(psz_string), "%f",
00812                           config_GetFloat( p_intf, psz_variable ) );
00813                 E_(SSPush)( st, psz_string );
00814                 break;
00815             }
00816             default:
00817                 msg_Warn( p_intf, "vlc_config_get called on unknown var (%s)",
00818                           psz_variable );
00819             }
00820             free( psz_variable );
00821         }
00822         else if( !strcmp( s, "vlc_config_save" ) )
00823         {
00824             char *psz_module = E_(SSPop)( st );
00825             int i_result;
00826 
00827             if( !*psz_module )
00828             {
00829                 free( psz_module );
00830                 psz_module = NULL;
00831             }
00832             i_result = config_SaveConfigFile( p_intf, psz_module );
00833 
00834             if( psz_module != NULL )
00835                 free( psz_module );
00836             E_(SSPushN)( st, i_result );
00837         }
00838         else if( !strcmp( s, "vlc_config_reset" ) )
00839         {
00840             config_ResetAll( p_intf );
00841         }
00842         /* 6. playlist functions */
00843         else if( !strcmp( s, "playlist_add" ) )
00844         {
00845             char *psz_name = E_(SSPop)( st );
00846             char *mrl = E_(SSPop)( st );
00847             char *tmp;
00848             playlist_item_t *p_item;
00849             int i_id;
00850 
00851             tmp = E_(ToUTF8)( p_intf, psz_name );
00852             free( psz_name );
00853             psz_name = tmp;
00854             tmp = E_(ToUTF8)( p_intf, mrl );
00855             free( mrl );
00856             mrl = tmp;
00857 
00858             if( !*psz_name )
00859             {
00860                 p_item = E_(MRLParse)( p_intf, mrl, mrl );
00861             }
00862             else
00863             {
00864                 p_item = E_(MRLParse)( p_intf, mrl, psz_name );
00865             }
00866 
00867             if( p_item == NULL || p_item->input.psz_uri == NULL ||
00868                  !*p_item->input.psz_uri )
00869             {
00870                 i_id = VLC_EGENERIC;
00871                 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
00872             }
00873             else
00874             {
00875                 i_id = playlist_AddItem( p_sys->p_playlist, p_item,
00876                                          PLAYLIST_APPEND, PLAYLIST_END );
00877                 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
00878             }
00879             E_(SSPushN)( st, i_id );
00880 
00881             free( mrl );
00882             free( psz_name );
00883         }
00884         else if( !strcmp( s, "playlist_empty" ) )
00885         {
00886             playlist_LockClear( p_sys->p_playlist );
00887             msg_Dbg( p_intf, "requested playlist empty" );
00888         }
00889         else if( !strcmp( s, "playlist_delete" ) )
00890         {
00891             int i_id = E_(SSPopN)( st, vars );
00892             playlist_LockDelete( p_sys->p_playlist, i_id );
00893             msg_Dbg( p_intf, "requested playlist delete: %d", i_id );
00894         }
00895         else if( !strcmp( s, "playlist_move" ) )
00896         {
00897             int i_newpos = E_(SSPopN)( st, vars );
00898             int i_pos = E_(SSPopN)( st, vars );
00899             if ( i_pos < i_newpos )
00900             {
00901                 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
00902             }
00903             else
00904             {
00905                 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
00906             }
00907             msg_Dbg( p_intf, "requested to move playlist item %d to %d",
00908                      i_pos, i_newpos);
00909         }
00910         else
00911         {
00912             E_(SSPush)( st, s );
00913         }
00914     }
00915 }

Generated on Tue Dec 20 10:14:31 2005 for vlc-0.8.4a by  doxygen 1.4.2