rpn.c 27.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*****************************************************************************
 * rpn.c : RPN evaluator for the HTTP Interface
 *****************************************************************************
 * Copyright (C) 2001-2005 the VideoLAN team
 * $Id: http.c 12225 2005-08-18 10:01:30Z massiot $
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#include "http.h"

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
static vlc_object_t *GetVLCObject( intf_thread_t *p_intf,
                                   const char *psz_object,
                                   vlc_bool_t *pb_need_release )
{
    intf_sys_t    *p_sys = p_intf->p_sys;
    int i_object_type = 0;
    vlc_object_t *p_object = NULL;
    *pb_need_release = VLC_FALSE;

    if( !strcmp( psz_object, "VLC_OBJECT_ROOT" ) )
        i_object_type = VLC_OBJECT_ROOT;
    else if( !strcmp( psz_object, "VLC_OBJECT_VLC" ) )
        p_object = VLC_OBJECT(p_intf->p_vlc);
    else if( !strcmp( psz_object, "VLC_OBJECT_INTF" ) )
        p_object = VLC_OBJECT(p_intf);
    else if( !strcmp( psz_object, "VLC_OBJECT_PLAYLIST" ) )
        p_object = VLC_OBJECT(p_sys->p_playlist);
    else if( !strcmp( psz_object, "VLC_OBJECT_INPUT" ) )
        p_object = VLC_OBJECT(p_sys->p_input);
    else if( !strcmp( psz_object, "VLC_OBJECT_VOUT" ) )
        i_object_type = VLC_OBJECT_VOUT;
    else if( !strcmp( psz_object, "VLC_OBJECT_AOUT" ) )
        i_object_type = VLC_OBJECT_AOUT;
    else if( !strcmp( psz_object, "VLC_OBJECT_SOUT" ) )
        i_object_type = VLC_OBJECT_SOUT;
    else
        msg_Warn( p_intf, "unknown object type (%s)", psz_object );

    if( p_object == NULL && i_object_type )
    {
        *pb_need_release = VLC_TRUE;
        p_object = vlc_object_find( p_intf, i_object_type, FIND_ANYWHERE );
    }

    return p_object;
}

65
void E_(SSInit)( rpn_stack_t *st )
66 67 68 69
{
    st->i_stack = 0;
}

70
void E_(SSClean)( rpn_stack_t *st )
71 72 73 74 75 76 77
{
    while( st->i_stack > 0 )
    {
        free( st->stack[--st->i_stack] );
    }
}

78
void E_(SSPush)( rpn_stack_t *st, const char *s )
79 80 81 82 83 84 85
{
    if( st->i_stack < STACK_MAX )
    {
        st->stack[st->i_stack++] = strdup( s );
    }
}

86
char *E_(SSPop)( rpn_stack_t *st )
87 88 89 90 91 92 93 94 95 96 97
{
    if( st->i_stack <= 0 )
    {
        return strdup( "" );
    }
    else
    {
        return st->stack[--st->i_stack];
    }
}

98
int E_(SSPopN)( rpn_stack_t *st, mvar_t  *vars )
99 100 101 102 103 104 105
{
    char *name;
    char *value;

    char *end;
    int  i;

106
    name = E_(SSPop)( st );
107 108 109
    i = strtol( name, &end, 0 );
    if( end == name )
    {
110
        value = E_(mvar_GetValue)( vars, name );
111 112 113 114 115 116 117
        i = atoi( value );
    }
    free( name );

    return( i );
}

118
void E_(SSPushN)( rpn_stack_t *st, int i )
119 120 121 122
{
    char v[512];

    sprintf( v, "%d", i );
123
    E_(SSPush)( st, v );
124 125
}

126 127
void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
                      rpn_stack_t *st, char *exp )
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
{
    intf_sys_t    *p_sys = p_intf->p_sys;

    while( exp != NULL && *exp != '\0' )
    {
        char *p, *s;

        /* skip space */
        while( *exp == ' ' )
        {
            exp++;
        }

        if( *exp == '\'' )
        {
            /* extract string */
            p = E_(FirstWord)( exp, exp );
145
            E_(SSPush)( st, exp );
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
            exp = p;
            continue;
        }

        /* extract token */
        p = E_(FirstWord)( exp, exp );
        s = exp;
        if( p == NULL )
        {
            exp += strlen( exp );
        }
        else
        {
            exp = p;
        }

        if( *s == '\0' )
        {
            break;
        }

        /* 1. Integer function */
        if( !strcmp( s, "!" ) )
        {
170
            E_(SSPushN)( st, ~E_(SSPopN)( st, vars ) );
171 172 173
        }
        else if( !strcmp( s, "^" ) )
        {
174
            E_(SSPushN)( st, E_(SSPopN)( st, vars ) ^ E_(SSPopN)( st, vars ) );
175 176 177
        }
        else if( !strcmp( s, "&" ) )
        {
178
            E_(SSPushN)( st, E_(SSPopN)( st, vars ) & E_(SSPopN)( st, vars ) );
179 180 181
        }
        else if( !strcmp( s, "|" ) )
        {
182
            E_(SSPushN)( st, E_(SSPopN)( st, vars ) | E_(SSPopN)( st, vars ) );
183 184 185
        }
        else if( !strcmp( s, "+" ) )
        {
186
            E_(SSPushN)( st, E_(SSPopN)( st, vars ) + E_(SSPopN)( st, vars ) );
187 188 189
        }
        else if( !strcmp( s, "-" ) )
        {
190 191 192
            int j = E_(SSPopN)( st, vars );
            int i = E_(SSPopN)( st, vars );
            E_(SSPushN)( st, i - j );
193 194 195
        }
        else if( !strcmp( s, "*" ) )
        {
196
            E_(SSPushN)( st, E_(SSPopN)( st, vars ) * E_(SSPopN)( st, vars ) );
197 198 199 200 201
        }
        else if( !strcmp( s, "/" ) )
        {
            int i, j;

202 203
            j = E_(SSPopN)( st, vars );
            i = E_(SSPopN)( st, vars );
204

205
            E_(SSPushN)( st, j != 0 ? i / j : 0 );
206 207 208 209 210
        }
        else if( !strcmp( s, "%" ) )
        {
            int i, j;

211 212
            j = E_(SSPopN)( st, vars );
            i = E_(SSPopN)( st, vars );
213

214
            E_(SSPushN)( st, j != 0 ? i % j : 0 );
215 216 217 218
        }
        /* 2. integer tests */
        else if( !strcmp( s, "=" ) )
        {
219
            E_(SSPushN)( st, E_(SSPopN)( st, vars ) == E_(SSPopN)( st, vars ) ? -1 : 0 );
220 221 222
        }
        else if( !strcmp( s, "!=" ) )
        {
223
            E_(SSPushN)( st, E_(SSPopN)( st, vars ) != E_(SSPopN)( st, vars ) ? -1 : 0 );
224 225 226
        }
        else if( !strcmp( s, "<" ) )
        {
227 228
            int j = E_(SSPopN)( st, vars );
            int i = E_(SSPopN)( st, vars );
229

230
            E_(SSPushN)( st, i < j ? -1 : 0 );
231 232 233
        }
        else if( !strcmp( s, ">" ) )
        {
234 235
            int j = E_(SSPopN)( st, vars );
            int i = E_(SSPopN)( st, vars );
236

237
            E_(SSPushN)( st, i > j ? -1 : 0 );
238 239 240
        }
        else if( !strcmp( s, "<=" ) )
        {
241 242
            int j = E_(SSPopN)( st, vars );
            int i = E_(SSPopN)( st, vars );
243

244
            E_(SSPushN)( st, i <= j ? -1 : 0 );
245 246 247
        }
        else if( !strcmp( s, ">=" ) )
        {
248 249
            int j = E_(SSPopN)( st, vars );
            int i = E_(SSPopN)( st, vars );
250

251
            E_(SSPushN)( st, i >= j ? -1 : 0 );
252 253 254 255
        }
        /* 3. string functions */
        else if( !strcmp( s, "strcat" ) )
        {
256 257
            char *s2 = E_(SSPop)( st );
            char *s1 = E_(SSPop)( st );
258 259 260 261 262
            char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );

            strcpy( str, s1 );
            strcat( str, s2 );

263
            E_(SSPush)( st, str );
264 265 266 267 268 269
            free( s1 );
            free( s2 );
            free( str );
        }
        else if( !strcmp( s, "strcmp" ) )
        {
270 271
            char *s2 = E_(SSPop)( st );
            char *s1 = E_(SSPop)( st );
272

273
            E_(SSPushN)( st, strcmp( s1, s2 ) );
274 275 276 277 278
            free( s1 );
            free( s2 );
        }
        else if( !strcmp( s, "strncmp" ) )
        {
279 280 281
            int n = E_(SSPopN)( st, vars );
            char *s2 = E_(SSPop)( st );
            char *s1 = E_(SSPop)( st );
282

283
            E_(SSPushN)( st, strncmp( s1, s2 , n ) );
284 285 286 287 288
            free( s1 );
            free( s2 );
        }
        else if( !strcmp( s, "strsub" ) )
        {
289 290
            int n = E_(SSPopN)( st, vars );
            int m = E_(SSPopN)( st, vars );
291
            int i_len;
292
            char *s = E_(SSPop)( st );
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
            char *str;

            if( n >= m )
            {
                i_len = n - m + 1;
            }
            else
            {
                i_len = 0;
            }

            str = malloc( i_len + 1 );

            memcpy( str, s + m - 1, i_len );
            str[ i_len ] = '\0';

309
            E_(SSPush)( st, str );
310 311 312 313 314
            free( s );
            free( str );
        }
        else if( !strcmp( s, "strlen" ) )
        {
315
            char *str = E_(SSPop)( st );
316

317
            E_(SSPushN)( st, strlen( str ) );
318 319 320 321
            free( str );
        }
        else if( !strcmp( s, "str_replace" ) )
        {
322 323 324
            char *psz_to = E_(SSPop)( st );
            char *psz_from = E_(SSPop)( st );
            char *psz_in = E_(SSPop)( st );
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
            char *psz_in_current = psz_in;
            char *psz_out = malloc( strlen(psz_in) * strlen(psz_to) + 1 );
            char *psz_out_current = psz_out;

            while( (p = strstr( psz_in_current, psz_from )) != NULL )
            {
                memcpy( psz_out_current, psz_in_current, p - psz_in_current );
                psz_out_current += p - psz_in_current;
                strcpy( psz_out_current, psz_to );
                psz_out_current += strlen(psz_to);
                psz_in_current = p + strlen(psz_from);
            }
            strcpy( psz_out_current, psz_in_current );
            psz_out_current += strlen(psz_in_current);
            *psz_out_current = '\0';

341
            E_(SSPush)( st, psz_out );
342 343 344 345 346 347 348
            free( psz_to );
            free( psz_from );
            free( psz_in );
            free( psz_out );
        }
        else if( !strcmp( s, "url_extract" ) )
        {
349 350
            char *url = E_(mvar_GetValue)( vars, "url_value" );
            char *name = E_(SSPop)( st );
351 352 353
            char value[512];
            char *tmp;

354 355
            E_(ExtractURIValue)( url, name, value, 512 );
            E_(DecodeEncodedURI)( value );
356
            tmp = E_(FromUTF8)( p_intf, value );
357
            E_(SSPush)( st, tmp );
358 359 360 361 362
            free( tmp );
            free( name );
        }
        else if( !strcmp( s, "url_encode" ) )
        {
363
            char *url = E_(SSPop)( st );
364 365 366 367 368 369 370
            char *value;

            value = E_(ToUTF8)( p_intf, url );
            free( url );
            url = value;
            value = vlc_UrlEncode( url );
            free( url );
371
            E_(SSPush)( st, value );
372 373 374 375
            free( value );
        }
        else if( !strcmp( s, "addslashes" ) )
        {
376
            char *psz_src = E_(SSPop)( st );
377 378 379 380 381 382 383
            char *psz_dest;
            char *str = psz_src;

            p = psz_dest = malloc( strlen( str ) * 2 + 1 );

            while( *str != '\0' )
            {
384
                if( *str == '"' || *str == '\'' || *str == '\\' )
385 386 387 388 389 390 391 392
                {
                    *p++ = '\\';
                }
                *p++ = *str;
                str++;
            }
            *p = '\0';

393
            E_(SSPush)( st, psz_dest );
394 395 396 397 398
            free( psz_src );
            free( psz_dest );
        }
        else if( !strcmp( s, "stripslashes" ) )
        {
399
            char *psz_src = E_(SSPop)( st );
400 401 402 403
            char *psz_dest;

            p = psz_dest = strdup( psz_src );

404
            while( *psz_src )
405
            {
406
                if( *psz_src == '\\' && *(psz_src + 1) )
407
                {
408
                    psz_src++;
409
                }
410
                *p++ = *psz_src++;
411 412 413
            }
            *p = '\0';

414
            E_(SSPush)( st, psz_dest );
415 416 417 418 419
            free( psz_src );
            free( psz_dest );
        }
        else if( !strcmp( s, "htmlspecialchars" ) )
        {
420
            char *psz_src = E_(SSPop)( st );
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
            char *psz_dest;
            char *str = psz_src;

            p = psz_dest = malloc( strlen( str ) * 6 + 1 );

            while( *str != '\0' )
            {
                if( *str == '&' )
                {
                    strcpy( p, "&amp;" );
                    p += 5;
                }
                else if( *str == '\"' )
                {
                    strcpy( p, "&quot;" );
                    p += 6;
                }
                else if( *str == '\'' )
                {
                    strcpy( p, "&#039;" );
                    p += 6;
                }
                else if( *str == '<' )
                {
                    strcpy( p, "&lt;" );
                    p += 4;
                }
                else if( *str == '>' )
                {
                    strcpy( p, "&gt;" );
                    p += 4;
                }
                else
                {
                    *p++ = *str;
                }
                str++;
            }
            *p = '\0';

461
            E_(SSPush)( st, psz_dest );
462 463 464 465 466
            free( psz_src );
            free( psz_dest );
        }
        else if( !strcmp( s, "realpath" ) )
        {
467
            char *psz_src = E_(SSPop)( st );
468
            char *psz_dir = E_(RealPath)( p_intf, psz_src );
469

470
            E_(SSPush)( st, psz_dir );
471
            free( psz_src );
472
            free( psz_dir );
473 474 475 476
        }
        /* 4. stack functions */
        else if( !strcmp( s, "dup" ) )
        {
477 478 479
            char *str = E_(SSPop)( st );
            E_(SSPush)( st, str );
            E_(SSPush)( st, str );
480 481 482 483
            free( str );
        }
        else if( !strcmp( s, "drop" ) )
        {
484
            char *str = E_(SSPop)( st );
485 486 487 488
            free( str );
        }
        else if( !strcmp( s, "swap" ) )
        {
489 490
            char *s1 = E_(SSPop)( st );
            char *s2 = E_(SSPop)( st );
491

492 493
            E_(SSPush)( st, s1 );
            E_(SSPush)( st, s2 );
494 495 496 497 498
            free( s1 );
            free( s2 );
        }
        else if( !strcmp( s, "flush" ) )
        {
499 500
            E_(SSClean)( st );
            E_(SSInit)( st );
501 502 503
        }
        else if( !strcmp( s, "store" ) )
        {
504 505
            char *value = E_(SSPop)( st );
            char *name  = E_(SSPop)( st );
506

507
            E_(mvar_PushNewVar)( vars, name, value );
508 509 510 511 512
            free( name );
            free( value );
        }
        else if( !strcmp( s, "value" ) )
        {
513 514
            char *name  = E_(SSPop)( st );
            char *value = E_(mvar_GetValue)( vars, name );
515

516
            E_(SSPush)( st, value );
517 518 519 520 521 522

            free( name );
        }
        /* 5. player control */
        else if( !strcmp( s, "vlc_play" ) )
        {
523
            int i_id = E_(SSPopN)( st, vars );
524 525 526 527 528 529
            int i_ret;

            i_ret = playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
                                      playlist_ItemGetById( p_sys->p_playlist,
                                      i_id ) );
            msg_Dbg( p_intf, "requested playlist item: %i", i_id );
530
            E_(SSPushN)( st, i_ret );
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
        }
        else if( !strcmp( s, "vlc_stop" ) )
        {
            playlist_Control( p_sys->p_playlist, PLAYLIST_STOP );
            msg_Dbg( p_intf, "requested playlist stop" );
        }
        else if( !strcmp( s, "vlc_pause" ) )
        {
            playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
            msg_Dbg( p_intf, "requested playlist pause" );
        }
        else if( !strcmp( s, "vlc_next" ) )
        {
            playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
            msg_Dbg( p_intf, "requested playlist next" );
        }
        else if( !strcmp( s, "vlc_previous" ) )
        {
            playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1 );
            msg_Dbg( p_intf, "requested playlist previous" );
        }
        else if( !strcmp( s, "vlc_seek" ) )
        {
554
            char *psz_value = E_(SSPop)( st );
555
            E_(HandleSeek)( p_intf, psz_value );
556 557 558 559 560 561 562
            msg_Dbg( p_intf, "requested playlist seek: %s", psz_value );
            free( psz_value );
        }
        else if( !strcmp( s, "vlc_var_type" )
                  || !strcmp( s, "vlc_config_type" ) )
        {
            vlc_object_t *p_object;
563 564
            const char *psz_type = NULL;
            int i_type = 0;
565 566 567

            if( !strcmp( s, "vlc_var_type" ) )
            {
568 569
                char *psz_object = E_(SSPop)( st );
                char *psz_variable = E_(SSPop)( st );
570 571 572 573
                vlc_bool_t b_need_release;

                p_object = GetVLCObject( p_intf, psz_object, &b_need_release );

574 575
                if( p_object != NULL )
                    i_type = var_Type( p_object, psz_variable );
576 577 578 579
                free( psz_variable );
                free( psz_object );
                if( b_need_release && p_object != NULL )
                    vlc_object_release( p_object );
580 581 582
            }
            else
            {
583
                char *psz_variable = E_(SSPop)( st );
584 585
                p_object = VLC_OBJECT(p_intf);
                i_type = config_GetType( p_object, psz_variable );
586
                free( psz_variable );
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
            }

            if( p_object != NULL )
            {
                switch( i_type & VLC_VAR_TYPE )
                {
                case VLC_VAR_BOOL:
                    psz_type = "VLC_VAR_BOOL";
                    break;
                case VLC_VAR_INTEGER:
                    psz_type = "VLC_VAR_INTEGER";
                    break;
                case VLC_VAR_HOTKEY:
                    psz_type = "VLC_VAR_HOTKEY";
                    break;
                case VLC_VAR_STRING:
                    psz_type = "VLC_VAR_STRING";
                    break;
                case VLC_VAR_MODULE:
                    psz_type = "VLC_VAR_MODULE";
                    break;
                case VLC_VAR_FILE:
                    psz_type = "VLC_VAR_FILE";
                    break;
                case VLC_VAR_DIRECTORY:
                    psz_type = "VLC_VAR_DIRECTORY";
                    break;
                case VLC_VAR_VARIABLE:
                    psz_type = "VLC_VAR_VARIABLE";
                    break;
                case VLC_VAR_FLOAT:
                    psz_type = "VLC_VAR_FLOAT";
                    break;
                default:
                    psz_type = "UNDEFINED";
                }
            }
            else
                psz_type = "INVALID";

627
            E_(SSPush)( st, psz_type );
628 629 630
        }
        else if( !strcmp( s, "vlc_var_set" ) )
        {
631 632
            char *psz_object = E_(SSPop)( st );
            char *psz_variable = E_(SSPop)( st );
633
            vlc_bool_t b_need_release;
634

635 636 637 638
            vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
                                                   &b_need_release );

            if( p_object != NULL )
639 640 641 642 643 644
            {
                vlc_bool_t b_error = VLC_FALSE;
                char *psz_value = NULL;
                vlc_value_t val;
                int i_type;

645
                i_type = var_Type( p_object, psz_variable );
646 647 648 649

                switch( i_type & VLC_VAR_TYPE )
                {
                case VLC_VAR_BOOL:
650
                    val.b_bool = E_(SSPopN)( st, vars );
651 652
                    msg_Dbg( p_intf, "requested %s var change: %s->%d",
                             psz_object, psz_variable, val.b_bool );
653 654 655
                    break;
                case VLC_VAR_INTEGER:
                case VLC_VAR_HOTKEY:
656
                    val.i_int = E_(SSPopN)( st, vars );
657 658
                    msg_Dbg( p_intf, "requested %s var change: %s->%d",
                             psz_object, psz_variable, val.i_int );
659 660 661 662 663 664
                    break;
                case VLC_VAR_STRING:
                case VLC_VAR_MODULE:
                case VLC_VAR_FILE:
                case VLC_VAR_DIRECTORY:
                case VLC_VAR_VARIABLE:
665
                    val.psz_string = psz_value = E_(SSPop)( st );
666 667
                    msg_Dbg( p_intf, "requested %s var change: %s->%s",
                             psz_object, psz_variable, psz_value );
668 669
                    break;
                case VLC_VAR_FLOAT:
670
                    psz_value = E_(SSPop)( st );
671
                    val.f_float = atof( psz_value );
672 673
                    msg_Dbg( p_intf, "requested %s var change: %s->%f",
                             psz_object, psz_variable, val.f_float );
674 675
                    break;
                default:
676
                    E_(SSPopN)( st, vars );
677 678
                    msg_Warn( p_intf, "invalid %s variable type %d (%s)",
                              psz_object, i_type & VLC_VAR_TYPE, psz_variable );
679 680 681 682
                    b_error = VLC_TRUE;
                }

                if( !b_error )
683
                    var_Set( p_object, psz_variable, val );
684 685 686 687
                if( psz_value != NULL )
                    free( psz_value );
            }
            else
688
                msg_Warn( p_intf, "vlc_var_set called without an object" );
689
            free( psz_variable );
690 691 692 693
            free( psz_object );

            if( b_need_release && p_object != NULL )
                vlc_object_release( p_object );
694 695 696
        }
        else if( !strcmp( s, "vlc_var_get" ) )
        {
697 698
            char *psz_object = E_(SSPop)( st );
            char *psz_variable = E_(SSPop)( st );
699 700 701 702
            vlc_bool_t b_need_release;

            vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
                                                   &b_need_release );
703

704
            if( p_object != NULL )
705 706 707 708
            {
                vlc_value_t val;
                int i_type;

709 710
                i_type = var_Type( p_object, psz_variable );
                var_Get( p_object, psz_variable, &val );
711 712 713 714

                switch( i_type & VLC_VAR_TYPE )
                {
                case VLC_VAR_BOOL:
715
                    E_(SSPushN)( st, val.b_bool );
716 717 718
                    break;
                case VLC_VAR_INTEGER:
                case VLC_VAR_HOTKEY:
719
                    E_(SSPushN)( st, val.i_int );
720 721 722 723 724 725
                    break;
                case VLC_VAR_STRING:
                case VLC_VAR_MODULE:
                case VLC_VAR_FILE:
                case VLC_VAR_DIRECTORY:
                case VLC_VAR_VARIABLE:
726
                    E_(SSPush)( st, val.psz_string );
727 728 729 730 731 732
                    free( val.psz_string );
                    break;
                case VLC_VAR_FLOAT:
                {
                    char psz_value[20];
                    snprintf( psz_value, sizeof(psz_value), "%f", val.f_float );
733
                    E_(SSPush)( st, psz_value );
734 735 736
                    break;
                }
                default:
737 738
                    msg_Warn( p_intf, "invalid %s variable type %d (%s)",
                              psz_object, i_type & VLC_VAR_TYPE, psz_variable );
739
                    E_(SSPush)( st, "" );
740 741 742 743
                }
            }
            else
            {
744
                msg_Warn( p_intf, "vlc_var_get called without an object" );
745
                E_(SSPush)( st, "" );
746 747
            }
            free( psz_variable );
748 749 750 751
            free( psz_object );

            if( b_need_release && p_object != NULL )
                vlc_object_release( p_object );
752 753 754
        }
        else if( !strcmp( s, "vlc_config_set" ) )
        {
755
            char *psz_variable = E_(SSPop)( st );
756 757 758 759 760 761
            int i_type = config_GetType( p_intf, psz_variable );

            switch( i_type & VLC_VAR_TYPE )
            {
            case VLC_VAR_BOOL:
            case VLC_VAR_INTEGER:
762
                config_PutInt( p_intf, psz_variable, E_(SSPopN)( st, vars ) );
763 764 765 766 767 768
                break;
            case VLC_VAR_STRING:
            case VLC_VAR_MODULE:
            case VLC_VAR_FILE:
            case VLC_VAR_DIRECTORY:
            {
769
                char *psz_string = E_(SSPop)( st );
770 771 772 773 774 775
                config_PutPsz( p_intf, psz_variable, psz_string );
                free( psz_string );
                break;
            }
            case VLC_VAR_FLOAT:
            {
776
                char *psz_string = E_(SSPop)( st );
777 778 779 780 781 782 783 784 785 786 787 788
                config_PutFloat( p_intf, psz_variable, atof(psz_string) );
                free( psz_string );
                break;
            }
            default:
                msg_Warn( p_intf, "vlc_config_set called on unknown var (%s)",
                          psz_variable );
            }
            free( psz_variable );
        }
        else if( !strcmp( s, "vlc_config_get" ) )
        {
789
            char *psz_variable = E_(SSPop)( st );
790 791 792 793 794 795
            int i_type = config_GetType( p_intf, psz_variable );

            switch( i_type & VLC_VAR_TYPE )
            {
            case VLC_VAR_BOOL:
            case VLC_VAR_INTEGER:
796
                E_(SSPushN)( st, config_GetInt( p_intf, psz_variable ) );
797 798 799 800 801 802 803
                break;
            case VLC_VAR_STRING:
            case VLC_VAR_MODULE:
            case VLC_VAR_FILE:
            case VLC_VAR_DIRECTORY:
            {
                char *psz_string = config_GetPsz( p_intf, psz_variable );
804
                E_(SSPush)( st, psz_string );
805 806 807 808 809 810 811 812
                free( psz_string );
                break;
            }
            case VLC_VAR_FLOAT:
            {
                char psz_string[20];
                snprintf( psz_string, sizeof(psz_string), "%f",
                          config_GetFloat( p_intf, psz_variable ) );
813
                E_(SSPush)( st, psz_string );
814 815 816 817 818 819 820 821 822 823
                break;
            }
            default:
                msg_Warn( p_intf, "vlc_config_get called on unknown var (%s)",
                          psz_variable );
            }
            free( psz_variable );
        }
        else if( !strcmp( s, "vlc_config_save" ) )
        {
824
            char *psz_module = E_(SSPop)( st );
825 826 827 828 829 830 831 832 833 834 835
            int i_result;

            if( !*psz_module )
            {
                free( psz_module );
                psz_module = NULL;
            }
            i_result = config_SaveConfigFile( p_intf, psz_module );

            if( psz_module != NULL )
                free( psz_module );
836
            E_(SSPushN)( st, i_result );
837 838 839 840 841 842 843 844
        }
        else if( !strcmp( s, "vlc_config_reset" ) )
        {
            config_ResetAll( p_intf );
        }
        /* 6. playlist functions */
        else if( !strcmp( s, "playlist_add" ) )
        {
845 846
            char *psz_name = E_(SSPop)( st );
            char *mrl = E_(SSPop)( st );
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
            char *tmp;
            playlist_item_t *p_item;
            int i_id;

            tmp = E_(ToUTF8)( p_intf, psz_name );
            free( psz_name );
            psz_name = tmp;
            tmp = E_(ToUTF8)( p_intf, mrl );
            free( mrl );
            mrl = tmp;

            if( !*psz_name )
            {
                p_item = E_(MRLParse)( p_intf, mrl, mrl );
            }
            else
            {
                p_item = E_(MRLParse)( p_intf, mrl, psz_name );
            }

            if( p_item == NULL || p_item->input.psz_uri == NULL ||
                 !*p_item->input.psz_uri )
            {
                i_id = VLC_EGENERIC;
                msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
            }
            else
            {
                i_id = playlist_AddItem( p_sys->p_playlist, p_item,
                                         PLAYLIST_APPEND, PLAYLIST_END );
                msg_Dbg( p_intf, "requested mrl add: %s", mrl );
            }
879
            E_(SSPushN)( st, i_id );
880 881 882 883 884 885 886 887 888 889 890

            free( mrl );
            free( psz_name );
        }
        else if( !strcmp( s, "playlist_empty" ) )
        {
            playlist_LockClear( p_sys->p_playlist );
            msg_Dbg( p_intf, "requested playlist empty" );
        }
        else if( !strcmp( s, "playlist_delete" ) )
        {
891
            int i_id = E_(SSPopN)( st, vars );
892 893 894 895 896
            playlist_LockDelete( p_sys->p_playlist, i_id );
            msg_Dbg( p_intf, "requested playlist delete: %d", i_id );
        }
        else if( !strcmp( s, "playlist_move" ) )
        {
897 898
            int i_newpos = E_(SSPopN)( st, vars );
            int i_pos = E_(SSPopN)( st, vars );
899 900 901 902 903 904 905 906 907 908 909 910 911
            if ( i_pos < i_newpos )
            {
                playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
            }
            else
            {
                playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
            }
            msg_Dbg( p_intf, "requested to move playlist item %d to %d",
                     i_pos, i_newpos);
        }
        else
        {
912
            E_(SSPush)( st, s );
913 914 915
        }
    }
}