1 /*****************************************************************************
2 * http.c : http mini-server ;)
3 *****************************************************************************
4 * Copyright (C) 2001-2004 VideoLAN
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
8 * Laurent Aimar <fenrir@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
38 #include <vlc/vout.h> /* for fullscreen */
40 #include "vlc_httpd.h"
44 #ifdef HAVE_SYS_STAT_H
45 # include <sys/stat.h>
56 #elif defined( WIN32 ) && !defined( UNDER_CE )
64 /* stat() support for large files on win32 */
65 #if defined( WIN32 ) && !defined( UNDER_CE )
66 # define stat _stati64
69 /*****************************************************************************
71 *****************************************************************************/
72 static int Open ( vlc_object_t * );
73 static void Close( vlc_object_t * );
75 #define HOST_TEXT N_( "Host address" )
76 #define HOST_LONGTEXT N_( \
77 "You can set the address and port the http interface will bind to." )
78 #define SRC_TEXT N_( "Source directory" )
79 #define SRC_LONGTEXT N_( "Source directory" )
80 #define CERT_TEXT N_( "Certificate file" )
81 #define CERT_LONGTEXT N_( "HTTP interface x509 PEM certificate file " \
83 #define KEY_TEXT N_( "Private key file" )
84 #define KEY_LONGTEXT N_( "HTTP interface x509 PEM private key file" )
85 #define CA_TEXT N_( "Root CA file" )
86 #define CA_LONGTEXT N_( "HTTP interface x509 PEM trusted root CA " \
88 #define CRL_TEXT N_( "CRL file" )
89 #define CRL_LONGTEXT N_( "HTTP interace Certificates Revocation List file" )
92 set_shortname( _("HTTP"));
93 set_description( _("HTTP remote control interface") );
94 set_category( CAT_INTERFACE );
95 set_subcategory( SUBCAT_INTERFACE_GENERAL );
96 add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
97 add_string ( "http-src", NULL, NULL, SRC_TEXT, SRC_LONGTEXT, VLC_TRUE );
98 add_string ( "http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT, VLC_TRUE );
99 add_string ( "http-intf-key", NULL, NULL, KEY_TEXT, KEY_LONGTEXT, VLC_TRUE );
100 add_string ( "http-intf-ca", NULL, NULL, CA_TEXT, CA_LONGTEXT, VLC_TRUE );
101 add_string ( "http-intf-crl", NULL, NULL, CRL_TEXT, CRL_LONGTEXT, VLC_TRUE );
102 set_capability( "interface", 0 );
103 set_callbacks( Open, Close );
107 /*****************************************************************************
109 *****************************************************************************/
110 static void Run ( intf_thread_t *p_intf );
112 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
115 static int DirectoryCheck( char *psz_dir )
119 #ifdef HAVE_SYS_STAT_H
120 struct stat stat_info;
122 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
128 if( ( p_dir = opendir( psz_dir ) ) == NULL )
137 static int HttpCallback( httpd_file_sys_t *p_args,
140 uint8_t **pp_data, int *pi_data );
142 static char *uri_extract_value( char *psz_uri, const char *psz_name,
143 char *psz_value, int i_value_max );
144 static int uri_test_param( char *psz_uri, const char *psz_name );
146 static void uri_decode_url_encoded( char *psz );
148 static char *Find_end_MRL( char *psz );
150 static playlist_item_t * parse_MRL( intf_thread_t * , char *psz );
152 /*****************************************************************************
154 *****************************************************************************/
155 typedef struct mvar_s
161 struct mvar_s **field;
164 #define STACK_MAX 100
167 char *stack[STACK_MAX];
171 struct httpd_file_sys_t
173 intf_thread_t *p_intf;
174 httpd_file_t *p_file;
175 httpd_redirect_t *p_redir;
176 httpd_redirect_t *p_redir2;
183 /* inited for each access */
190 httpd_host_t *p_httpd_host;
193 httpd_file_sys_t **pp_files;
195 playlist_t *p_playlist;
196 input_thread_t *p_input;
202 /*****************************************************************************
203 * Activate: initialize and create stuff
204 *****************************************************************************/
205 static int Open( vlc_object_t *p_this )
207 intf_thread_t *p_intf = (intf_thread_t*)p_this;
210 char *psz_address = "";
211 const char *psz_cert;
216 psz_host = config_GetPsz( p_intf, "http-host" );
220 psz_address = psz_host;
222 psz_parser = strchr( psz_host, ':' );
225 *psz_parser++ = '\0';
226 i_port = atoi( psz_parser );
230 p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
233 return( VLC_ENOMEM );
235 p_sys->p_playlist = NULL;
236 p_sys->p_input = NULL;
239 psz_cert = config_GetPsz( p_intf, "http-intf-cert" );
240 if ( psz_cert != NULL )
244 msg_Dbg( p_intf, "enablind TLS for HTTP interface (cert file: %s)",
246 psz_pem = config_GetPsz( p_intf, "http-intf-key" );
248 p_tls = tls_ServerCreate( p_this, psz_cert, psz_pem );
251 msg_Err( p_intf, "TLS initialization error" );
256 psz_pem = config_GetPsz( p_intf, "http-intf-ca" );
257 if ( ( psz_pem != NULL) && tls_ServerAddCA( p_tls, psz_pem ) )
259 msg_Err( p_intf, "TLS CA error" );
260 tls_ServerDelete( p_tls );
265 psz_pem = config_GetPsz( p_intf, "http-intf-crl" );
266 if ( ( psz_pem != NULL) && tls_ServerAddCRL( p_tls, psz_pem ) )
268 msg_Err( p_intf, "TLS CRL error" );
269 tls_ServerDelete( p_tls );
284 msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
286 p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
288 if( p_sys->p_httpd_host == NULL )
290 msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
292 tls_ServerDelete( p_tls );
303 p_sys->pp_files = NULL;
305 #if defined(SYS_DARWIN) || defined(SYS_BEOS) || defined(WIN32)
306 if ( ( psz_src = config_GetPsz( p_intf, "http-src" )) == NULL )
308 char * psz_vlcpath = p_intf->p_libvlc->psz_vlcpath;
309 psz_src = malloc( strlen(psz_vlcpath) + strlen("/share/http" ) + 1 );
310 if( !psz_src ) return VLC_ENOMEM;
312 sprintf( psz_src, "%s/http", psz_vlcpath);
314 sprintf( psz_src, "%s/share/http", psz_vlcpath);
318 psz_src = config_GetPsz( p_intf, "http-src" );
320 if( !psz_src || *psz_src == '\0' )
322 if( !DirectoryCheck( "share/http" ) )
324 psz_src = strdup( "share/http" );
326 else if( !DirectoryCheck( DATA_PATH "/http" ) )
328 psz_src = strdup( DATA_PATH "/http" );
333 if( !psz_src || *psz_src == '\0' )
335 msg_Err( p_intf, "invalid src dir" );
339 /* remove trainling \ or / */
340 if( psz_src[strlen( psz_src ) - 1] == '\\' ||
341 psz_src[strlen( psz_src ) - 1] == '/' )
343 psz_src[strlen( psz_src ) - 1] = '\0';
346 ParseDirectory( p_intf, psz_src, psz_src );
349 if( p_sys->i_files <= 0 )
351 msg_Err( p_intf, "cannot find any files (%s)", psz_src );
354 p_intf->pf_run = Run;
360 if( psz_src ) free( psz_src );
361 if( p_sys->pp_files )
363 free( p_sys->pp_files );
365 httpd_HostDelete( p_sys->p_httpd_host );
370 /*****************************************************************************
371 * CloseIntf: destroy interface
372 *****************************************************************************/
373 void Close ( vlc_object_t *p_this )
375 intf_thread_t *p_intf = (intf_thread_t *)p_this;
376 intf_sys_t *p_sys = p_intf->p_sys;
382 vlm_Delete( p_sys->p_vlm );
384 for( i = 0; i < p_sys->i_files; i++ )
386 httpd_FileDelete( p_sys->pp_files[i]->p_file );
387 if( p_sys->pp_files[i]->p_redir )
388 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir );
389 if( p_sys->pp_files[i]->p_redir2 )
390 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir2 );
392 free( p_sys->pp_files[i]->file );
393 free( p_sys->pp_files[i]->name );
394 free( p_sys->pp_files[i] );
396 if( p_sys->pp_files )
398 free( p_sys->pp_files );
400 httpd_HostDelete( p_sys->p_httpd_host );
405 /*****************************************************************************
406 * Run: http interface thread
407 *****************************************************************************/
408 static void Run( intf_thread_t *p_intf )
410 intf_sys_t *p_sys = p_intf->p_sys;
412 while( !p_intf->b_die )
414 /* get the playlist */
415 if( p_sys->p_playlist == NULL )
417 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
420 /* Manage the input part */
421 if( p_sys->p_input == NULL )
423 if( p_sys->p_playlist )
426 vlc_object_find( p_sys->p_playlist,
431 else if( p_sys->p_input->b_dead )
433 vlc_object_release( p_sys->p_input );
434 p_sys->p_input = NULL;
439 msleep( INTF_IDLE_SLEEP );
444 vlc_object_release( p_sys->p_input );
445 p_sys->p_input = NULL;
448 if( p_sys->p_playlist )
450 vlc_object_release( p_sys->p_playlist );
451 p_sys->p_playlist = NULL;
456 /*****************************************************************************
458 *****************************************************************************/
459 #define MAX_DIR_SIZE 10240
461 /****************************************************************************
462 * FileToUrl: create a good name for an url from filename
463 ****************************************************************************/
464 static char *FileToUrl( char *name, vlc_bool_t *pb_index )
468 url = p = malloc( strlen( name ) + 1 );
476 while( *name == '\\' || *name == '/' )
478 while( *name == '/' )
488 /* convert '\\' into '/' */
500 *pb_index = VLC_FALSE;
502 if( ( p = strrchr( url, '/' ) ) != NULL )
504 if( !strncmp( p, "/index.", 7 ) )
507 *pb_index = VLC_TRUE;
513 /****************************************************************************
514 * ParseDirectory: parse recursively a directory, adding each file
515 ****************************************************************************/
516 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
519 intf_sys_t *p_sys = p_intf->p_sys;
520 char dir[MAX_DIR_SIZE];
521 #ifdef HAVE_SYS_STAT_H
522 struct stat stat_info;
525 struct dirent *p_dir_content;
529 char *password = NULL;
531 #ifdef HAVE_SYS_STAT_H
532 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
538 if( ( p_dir = opendir( psz_dir ) ) == NULL )
540 msg_Err( p_intf, "cannot open dir (%s)", psz_dir );
544 msg_Dbg( p_intf, "dir=%s", psz_dir );
546 sprintf( dir, "%s/.access", psz_dir );
547 if( ( file = fopen( dir, "r" ) ) != NULL )
552 msg_Dbg( p_intf, "find .access in dir=%s", psz_dir );
554 i_size = fread( line, 1, 1023, file );
558 while( i_size > 0 && ( line[i_size-1] == '\n' ||
559 line[i_size-1] == '\r' ) )
566 p = strchr( line, ':' );
570 user = strdup( line );
571 password = strdup( p );
574 msg_Dbg( p_intf, "using user=%s password=%s (read=%d)",
575 user, password, i_size );
582 /* parse psz_src dir */
583 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
588 if( p_dir_content->d_name[0] == '.' )
592 sprintf( dir, "%s/%s", psz_dir, p_dir_content->d_name );
593 if( ParseDirectory( p_intf, psz_root, dir ) )
595 httpd_file_sys_t *f = malloc( sizeof( httpd_file_sys_t ) );
602 f->file = strdup( dir );
603 f->name = FileToUrl( &dir[strlen( psz_root )], &b_index );
604 f->b_html = strstr( &dir[strlen( psz_root )], ".htm" ) ? VLC_TRUE : VLC_FALSE;
608 msg_Err( p_intf , "unable to parse directory" );
611 return( VLC_ENOMEM );
613 msg_Dbg( p_intf, "file=%s (url=%s)",
616 f->p_file = httpd_FileNew( p_sys->p_httpd_host,
617 f->name, f->b_html ? "text/html" : NULL,
623 TAB_APPEND( p_sys->i_files, p_sys->pp_files, f );
625 /* for url that ends by / add
626 * - a redirect from rep to rep/
627 * - in case of index.* rep/index.html to rep/ */
628 if( f && f->name[strlen(f->name) - 1] == '/' )
630 char *psz_redir = strdup( f->name );
632 psz_redir[strlen( psz_redir ) - 1] = '\0';
634 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
635 f->p_redir = httpd_RedirectNew( p_sys->p_httpd_host, f->name, psz_redir );
638 if( b_index && ( p = strstr( f->file, "index." ) ) )
640 asprintf( &psz_redir, "%s%s", f->name, p );
642 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
643 f->p_redir2 = httpd_RedirectNew( p_sys->p_httpd_host,
644 f->name, psz_redir );
666 /****************************************************************************
667 * var and set handling
668 ****************************************************************************/
670 static mvar_t *mvar_New( char *name, char *value )
672 mvar_t *v = malloc( sizeof( mvar_t ) );
674 if( !v ) return NULL;
675 v->name = strdup( name );
676 v->value = strdup( value ? value : "" );
679 v->field = malloc( sizeof( mvar_t * ) );
685 static void mvar_Delete( mvar_t *v )
692 for( i = 0; i < v->i_field; i++ )
694 mvar_Delete( v->field[i] );
700 static void mvar_AppendVar( mvar_t *v, mvar_t *f )
702 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
703 v->field[v->i_field] = f;
707 static mvar_t *mvar_Duplicate( mvar_t *v )
712 n = mvar_New( v->name, v->value );
713 for( i = 0; i < v->i_field; i++ )
715 mvar_AppendVar( n, mvar_Duplicate( v->field[i] ) );
721 static void mvar_PushVar( mvar_t *v, mvar_t *f )
723 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
726 memmove( &v->field[1], &v->field[0], sizeof( mvar_t * ) * v->i_field );
732 static void mvar_RemoveVar( mvar_t *v, mvar_t *f )
735 for( i = 0; i < v->i_field; i++ )
737 if( v->field[i] == f )
742 if( i >= v->i_field )
747 if( i + 1 < v->i_field )
749 memmove( &v->field[i], &v->field[i+1], sizeof( mvar_t * ) * ( v->i_field - i - 1 ) );
752 /* FIXME should do a realloc */
755 static mvar_t *mvar_GetVar( mvar_t *s, char *name )
758 char base[512], *field, *p;
761 /* format: name[index].field */
763 field = strchr( name, '.' );
766 int i = field - name;
767 strncpy( base, name, i );
773 strcpy( base, name );
776 if( ( p = strchr( base, '[' ) ) )
779 sscanf( p, "%d]", &i_index );
790 for( i = 0; i < s->i_field; i++ )
792 if( !strcmp( s->field[i]->name, base ) )
802 return mvar_GetVar( s->field[i], field );
816 static char *mvar_GetValue( mvar_t *v, char *field )
824 mvar_t *f = mvar_GetVar( v, field );
836 static void mvar_PushNewVar( mvar_t *vars, char *name, char *value )
838 mvar_t *f = mvar_New( name, value );
839 mvar_PushVar( vars, f );
842 static void mvar_AppendNewVar( mvar_t *vars, char *name, char *value )
844 mvar_t *f = mvar_New( name, value );
845 mvar_AppendVar( vars, f );
849 /* arg= start[:stop[:step]],.. */
850 static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
852 char *dup = strdup( arg );
854 mvar_t *s = mvar_New( name, "set" );
856 fprintf( stderr," mvar_IntegerSetNew: name=`%s' arg=`%s'\n", name, str );
861 int i_start,i_stop,i_step;
864 p = strchr( str, ',' );
871 i_match = sscanf( str, "%d:%d:%d", &i_start, &i_stop, &i_step );
872 fprintf( stderr," mvar_IntegerSetNew: m=%d start=%d stop=%d step=%d\n", i_match, i_start, i_stop, i_step );
879 else if( i_match == 2 )
881 i_step = i_start < i_stop ? 1 : -1;
888 if( ( i_start <= i_stop && i_step > 0 ) ||
889 ( i_start >= i_stop && i_step < 0 ) )
891 for( i = i_start; ; i += i_step )
895 if( ( i_step > 0 && i > i_stop ) ||
896 ( i_step < 0 && i < i_stop ) )
901 fprintf( stderr," mvar_IntegerSetNew: adding %d\n", i );
902 sprintf( value, "%d", i );
904 mvar_PushNewVar( s, name, value );
915 void PlaylistListNode( playlist_t *p_pl, playlist_item_t *p_node,
916 char *name, mvar_t *s, int i_depth )
920 if (p_node->i_children == -1)
923 mvar_t *itm = mvar_New( name, "set" );
925 sprintf( value, "%d", ( p_pl->status.p_item == p_node )? 1 : 0 );
926 mvar_AppendNewVar( itm, "current", value );
928 sprintf( value, "%d", p_node->input.i_id );
929 mvar_AppendNewVar( itm, "index", value );
931 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
933 mvar_AppendNewVar( itm, "uri", p_node->input.psz_uri );
935 sprintf( value, "Item");
936 mvar_AppendNewVar( itm, "type", value );
938 sprintf( value, "%d", i_depth );
939 mvar_AppendNewVar( itm, "depth", value );
941 mvar_AppendVar( s, itm );
947 mvar_t *itm = mvar_New( name, "set" );
948 mvar_t *itm_end = mvar_New( name, "set" );
950 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
951 mvar_AppendNewVar( itm, "uri", p_node->input.psz_name );
953 sprintf( value, "Node" );
954 mvar_AppendNewVar( itm, "type", value );
956 sprintf( value, "%d", p_node->input.i_id );
957 mvar_AppendNewVar( itm, "index", value );
959 sprintf( value, "%d", p_node->i_children);
960 mvar_AppendNewVar( itm, "i_children", value );
962 sprintf( value, "%d", i_depth );
963 mvar_AppendNewVar( itm, "depth", value );
965 mvar_AppendVar( s, itm );
967 for (i_child = 0 ; i_child < p_node->i_children ; i_child++)
968 PlaylistListNode( p_pl, p_node->pp_children[i_child], name, s, i_depth + 1);
974 static mvar_t *mvar_PlaylistSetNew( char *name, playlist_t *p_pl )
976 playlist_view_t *p_view;
977 mvar_t *s = mvar_New( name, "set" );
979 fprintf( stderr," mvar_PlaylistSetNew: name=`%s'\n", name );
981 vlc_mutex_lock( &p_pl->object_lock );
983 p_view = playlist_ViewFind( p_pl, VIEW_CATEGORY ); /* FIXME */
986 PlaylistListNode( p_pl, p_view->p_root, name, s, 0 );
988 vlc_mutex_unlock( &p_pl->object_lock );
993 static mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input )
995 mvar_t *s = mvar_New( name, "set" );
998 fprintf( stderr," mvar_InfoSetNew: name=`%s'\n", name );
999 if( p_input == NULL )
1004 vlc_mutex_lock( &p_input->input.p_item->lock );
1005 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
1007 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1008 mvar_t *cat = mvar_New( name, "set" );
1009 mvar_t *iset = mvar_New( "info", "set" );
1011 mvar_AppendNewVar( cat, "name", p_category->psz_name );
1012 mvar_AppendVar( cat, iset );
1014 for ( j = 0; j < p_category->i_infos; j++ )
1016 info_t *p_info = p_category->pp_infos[j];
1017 mvar_t *info = mvar_New( "info", "" );
1019 msg_Dbg( p_input, "adding info name=%s value=%s",
1020 p_info->psz_name, p_info->psz_value );
1021 mvar_AppendNewVar( info, "name", p_info->psz_name );
1022 mvar_AppendNewVar( info, "value", p_info->psz_value );
1023 mvar_AppendVar( iset, info );
1025 mvar_AppendVar( s, cat );
1027 vlc_mutex_unlock( &p_input->input.p_item->lock );
1032 static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
1034 mvar_t *s = mvar_New( name, "set" );
1038 fprintf( stderr," mvar_HttpdInfoSetNew: name=`%s'\n", name );
1039 if( !p_httpd->pf_control( p_httpd, i_type, &info, NULL ) )
1041 for( i= 0; i < info.i_count; )
1045 inf = mvar_New( name, "set" );
1048 /* fprintf( stderr," mvar_HttpdInfoSetNew: append name=`%s' value=`%s'\n",
1049 info.info[i].psz_name, info.info[i].psz_value ); */
1050 mvar_AppendNewVar( inf,
1051 info.info[i].psz_name,
1052 info.info[i].psz_value );
1054 } while( i < info.i_count && strcmp( info.info[i].psz_name, "id" ) );
1055 mvar_AppendVar( s, inf );
1060 for( i = 0; i < info.i_count; i++ )
1062 free( info.info[i].psz_name );
1063 free( info.info[i].psz_value );
1065 if( info.i_count > 0 )
1074 static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
1076 mvar_t *s = mvar_New( name, "set" );
1077 char tmp[MAX_DIR_SIZE], *p, *src;
1078 #ifdef HAVE_SYS_STAT_H
1079 struct stat stat_info;
1082 struct dirent *p_dir_content;
1085 /* convert all / to native separator */
1086 #if defined( WIN32 )
1087 while( (p = strchr( psz_dir, '/' )) )
1096 /* remove trailling separator */
1097 while( strlen( psz_dir ) > 1 &&
1098 #if defined( WIN32 )
1099 !( strlen(psz_dir)==3 && psz_dir[1]==':' && psz_dir[2]==sep ) &&
1101 psz_dir[strlen( psz_dir ) -1 ] == sep )
1103 psz_dir[strlen( psz_dir ) -1 ] ='\0';
1105 /* remove double separator */
1106 for( p = src = psz_dir; *src != '\0'; src++, p++ )
1108 if( src[0] == sep && src[1] == sep )
1116 if( *psz_dir == '\0' )
1120 /* first fix all .. dir */
1124 if( src[0] == '.' && src[1] == '.' )
1127 if( p <= &psz_dir[1] )
1134 while( p > &psz_dir[1] && *p != sep )
1139 else if( *src == sep )
1141 if( p > psz_dir && p[-1] == sep )
1155 } while( *src && *src != sep );
1160 fprintf( stderr," mvar_FileSetNew: name=`%s' dir=`%s'\n", name, psz_dir );
1162 #ifdef HAVE_SYS_STAT_H
1163 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
1169 if( ( p_dir = opendir( psz_dir ) ) == NULL )
1171 fprintf( stderr, "cannot open dir (%s)", psz_dir );
1175 /* remove traling / or \ */
1176 for( p = &psz_dir[strlen( psz_dir) - 1];
1177 p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- )
1186 /* parse psz_src dir */
1187 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
1191 if( !strcmp( p_dir_content->d_name, "." ) )
1196 sprintf( tmp, "%s/%s", psz_dir, p_dir_content->d_name );
1198 #ifdef HAVE_SYS_STAT_H
1199 if( stat( tmp, &stat_info ) == -1 )
1204 f = mvar_New( name, "set" );
1205 mvar_AppendNewVar( f, "name", tmp );
1207 #ifdef HAVE_SYS_STAT_H
1208 if( S_ISDIR( stat_info.st_mode ) )
1210 mvar_AppendNewVar( f, "type", "directory" );
1212 else if( S_ISREG( stat_info.st_mode ) )
1214 mvar_AppendNewVar( f, "type", "file" );
1218 mvar_AppendNewVar( f, "type", "unknown" );
1221 sprintf( tmp, I64Fd, (int64_t)stat_info.st_size );
1222 mvar_AppendNewVar( f, "size", tmp );
1224 /* FIXME memory leak FIXME */
1226 ctime_r( &stat_info.st_mtime, tmp );
1227 mvar_AppendNewVar( f, "date", tmp );
1229 mvar_AppendNewVar( f, "date", ctime( &stat_info.st_mtime ) );
1233 mvar_AppendNewVar( f, "type", "unknown" );
1234 mvar_AppendNewVar( f, "size", "unknown" );
1235 mvar_AppendNewVar( f, "date", "unknown" );
1237 mvar_AppendVar( s, f );
1243 static mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm )
1245 mvar_t *s = mvar_New( name, "set" );
1249 /* fprintf( stderr," mvar_VlmSetNew: name=`%s'\n", name ); */
1250 if( vlm == NULL ) return s;
1252 if( vlm_ExecuteCommand( vlm, "show", &msg ) )
1257 for( i = 0; i < msg->i_child; i++ )
1259 /* Over media, schedule */
1260 vlm_message_t *ch = msg->child[i];
1263 for( j = 0; j < ch->i_child; j++ )
1266 vlm_message_t *el = ch->child[j];
1267 vlm_message_t *inf, *desc;
1272 sprintf( psz, "show %s", el->psz_name );
1273 if( vlm_ExecuteCommand( vlm, psz, &inf ) )
1275 desc = inf->child[0];
1277 /* Add a node with name and info */
1278 set = mvar_New( name, "set" );
1279 mvar_AppendNewVar( set, "name", el->psz_name );
1281 /* fprintf( stderr, "#### name=%s\n", el->psz_name ); */
1283 for( k = 0; k < desc->i_child; k++ )
1285 vlm_message_t *ch = desc->child[k];
1286 if( ch->i_child > 0 )
1289 mvar_t *n = mvar_New( ch->psz_name, "set" );
1291 /* fprintf( stderr, " child=%s [%d]\n", ch->psz_name, ch->i_child ); */
1292 for( c = 0; c < ch->i_child; c++ )
1294 mvar_t *in = mvar_New( ch->psz_name, ch->child[c]->psz_name );
1295 mvar_AppendVar( n, in );
1297 /* fprintf( stderr, " sub=%s\n", ch->child[c]->psz_name );*/
1299 mvar_AppendVar( set, n );
1303 /* fprintf( stderr, " child=%s->%s\n", ch->psz_name, ch->psz_value ); */
1304 mvar_AppendNewVar( set, ch->psz_name, ch->psz_value );
1307 vlm_MessageDelete( inf );
1309 mvar_AppendVar( s, set );
1312 vlm_MessageDelete( msg );
1318 static void SSInit( rpn_stack_t * );
1319 static void SSClean( rpn_stack_t * );
1320 static void EvaluateRPN( mvar_t *, rpn_stack_t *, char * );
1322 static void SSPush ( rpn_stack_t *, char * );
1323 static char *SSPop ( rpn_stack_t * );
1325 static void SSPushN ( rpn_stack_t *, int );
1326 static int SSPopN ( rpn_stack_t *, mvar_t * );
1329 /****************************************************************************
1331 ****************************************************************************/
1339 static int FileLoad( FILE *f, uint8_t **pp_data, int *pi_data )
1343 /* just load the file */
1345 *pp_data = malloc( 1025 ); /* +1 for \0 */
1346 while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 )
1349 *pp_data = realloc( *pp_data, *pi_data + 1025 );
1355 (*pp_data)[*pi_data] = '\0';
1360 static int MacroParse( macro_t *m, uint8_t *psz_src )
1362 uint8_t *dup = strdup( psz_src );
1367 #define EXTRACT( name, l ) \
1369 p = strchr( src, '"' ); \
1374 m->name = strdup( src ); \
1395 if( !strncmp( src, "id=\"", 4 ) )
1399 else if( !strncmp( src, "param1=\"", 8 ) )
1401 EXTRACT( param1, 8 );
1403 else if( !strncmp( src, "param2=\"", 8 ) )
1405 EXTRACT( param2, 8 );
1412 if( strstr( src, "/>" ) )
1414 src = strstr( src, "/>" ) + 2;
1418 src += strlen( src );
1423 m->id = strdup( "" );
1425 if( m->param1 == NULL )
1427 m->param1 = strdup( "" );
1429 if( m->param2 == NULL )
1431 m->param2 = strdup( "" );
1440 static void MacroClean( macro_t *m )
1499 StrToMacroTypeTab [] =
1501 { "control", MVLC_CONTROL },
1502 /* player control */
1503 { "play", MVLC_PLAY },
1504 { "stop", MVLC_STOP },
1505 { "pause", MVLC_PAUSE },
1506 { "next", MVLC_NEXT },
1507 { "previous", MVLC_PREVIOUS },
1508 { "seek", MVLC_SEEK },
1509 { "keep", MVLC_KEEP },
1510 { "fullscreen", MVLC_FULLSCREEN },
1511 { "volume", MVLC_VOLUME },
1513 /* playlist management */
1514 { "add", MVLC_ADD },
1515 { "delete", MVLC_DEL },
1516 { "empty", MVLC_EMPTY },
1517 { "sort", MVLC_SORT },
1518 { "move", MVLC_MOVE },
1521 { "close", MVLC_CLOSE },
1522 { "shutdown", MVLC_SHUTDOWN },
1525 { "vlm_new", MVLC_VLM_NEW },
1526 { "vlm_setup", MVLC_VLM_SETUP },
1527 { "vlm_del", MVLC_VLM_DEL },
1528 { "vlm_play", MVLC_VLM_PLAY },
1529 { "vlm_pause", MVLC_VLM_PAUSE },
1530 { "vlm_stop", MVLC_VLM_STOP },
1531 { "vlm_seek", MVLC_VLM_SEEK },
1532 { "vlm_load", MVLC_VLM_LOAD },
1533 { "vlm_save", MVLC_VLM_SAVE },
1535 { "rpn", MVLC_RPN },
1536 { "stack", MVLC_STACK },
1538 { "foreach", MVLC_FOREACH },
1539 { "value", MVLC_VALUE },
1542 { "else", MVLC_ELSE },
1543 { "end", MVLC_END },
1544 { "get", MVLC_GET },
1545 { "set", MVLC_SET },
1546 { "int", MVLC_INT },
1547 { "float", MVLC_FLOAT },
1548 { "string", MVLC_STRING },
1551 { NULL, MVLC_UNKNOWN }
1554 static int StrToMacroType( char *name )
1558 if( !name || *name == '\0')
1560 return MVLC_UNKNOWN;
1562 for( i = 0; StrToMacroTypeTab[i].psz_name != NULL; i++ )
1564 if( !strcmp( name, StrToMacroTypeTab[i].psz_name ) )
1566 return StrToMacroTypeTab[i].i_type;
1569 return MVLC_UNKNOWN;
1572 static void MacroDo( httpd_file_sys_t *p_args,
1574 uint8_t *p_request, int i_request,
1575 uint8_t **pp_data, int *pi_data,
1578 intf_thread_t *p_intf = p_args->p_intf;
1579 intf_sys_t *p_sys = p_args->p_intf->p_sys;
1582 #define ALLOC( l ) \
1584 int __i__ = *pp_dst - *pp_data; \
1586 *pp_data = realloc( *pp_data, *pi_data ); \
1587 *pp_dst = (*pp_data) + __i__; \
1589 #define PRINT( str ) \
1590 ALLOC( strlen( str ) + 1 ); \
1591 *pp_dst += sprintf( *pp_dst, str );
1593 #define PRINTS( str, s ) \
1594 ALLOC( strlen( str ) + strlen( s ) + 1 ); \
1596 char * psz_cur = *pp_dst; \
1597 *pp_dst += sprintf( *pp_dst, str, s ); \
1598 while( psz_cur && *psz_cur ) \
1600 /* Prevent script injection */ \
1601 if( *psz_cur == '<' ) *psz_cur = '*'; \
1602 if( *psz_cur == '>' ) *psz_cur = '*'; \
1607 switch( StrToMacroType( m->id ) )
1610 if( i_request <= 0 )
1614 uri_extract_value( p_request, "control", control, 512 );
1615 if( *m->param1 && !strstr( m->param1, control ) )
1617 msg_Warn( p_intf, "unauthorized control=%s", control );
1620 switch( StrToMacroType( control ) )
1627 uri_extract_value( p_request, "item", item, 512 );
1628 i_item = atoi( item );
1629 playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
1630 playlist_ItemGetById( p_sys->p_playlist,
1632 msg_Dbg( p_intf, "requested playlist item: %i", i_item );
1636 playlist_Control( p_sys->p_playlist, PLAYLIST_STOP);
1637 msg_Dbg( p_intf, "requested playlist stop" );
1640 playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
1641 msg_Dbg( p_intf, "requested playlist pause" );
1644 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
1645 msg_Dbg( p_intf, "requested playlist next" );
1648 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1);
1649 msg_Dbg( p_intf, "requested playlist next" );
1651 case MVLC_FULLSCREEN:
1653 if( p_sys->p_input )
1655 vout_thread_t *p_vout;
1656 p_vout = vlc_object_find( p_sys->p_input,
1657 VLC_OBJECT_VOUT, FIND_CHILD );
1661 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1662 vlc_object_release( p_vout );
1663 msg_Dbg( p_intf, "requested fullscreen toggle" );
1677 #define POSITION_ABSOLUTE 12
1678 #define POSITION_REL_FOR 13
1679 #define POSITION_REL_BACK 11
1680 #define VL_TIME_ABSOLUTE 0
1681 #define VL_TIME_REL_FOR 1
1682 #define VL_TIME_REL_BACK -1
1683 if( p_sys->p_input )
1685 uri_extract_value( p_request, "seek_value", value, 20 );
1686 uri_decode_url_encoded( value );
1688 var_Get( p_sys->p_input, "length", &val);
1689 i_length = val.i_time;
1691 while( p_value[0] != '\0' )
1697 i_relative = VL_TIME_REL_FOR;
1703 i_relative = VL_TIME_REL_BACK;
1707 case '0': case '1': case '2': case '3': case '4':
1708 case '5': case '6': case '7': case '8': case '9':
1710 i_stock = strtol( p_value , &p_value , 10 );
1713 case '%': /* for percentage ie position */
1715 i_relative += POSITION_ABSOLUTE;
1723 i_value = 60 * (i_value + i_stock) ;
1728 case 'h': case 'H': /* hours */
1730 i_value += 3600 * i_stock;
1732 /* other characters which are not numbers are not important */
1733 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1739 case 'm': case 'M': case '\'': /* minutes */
1741 i_value += 60 * i_stock;
1744 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1750 case 's': case 'S': case '"': /* seconds */
1754 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1768 /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
1773 case VL_TIME_ABSOLUTE:
1775 if( (uint64_t)( i_value ) * 1000000 <= i_length )
1776 val.i_time = (uint64_t)( i_value ) * 1000000;
1778 val.i_time = i_length;
1780 var_Set( p_sys->p_input, "time", val );
1781 msg_Dbg( p_intf, "requested seek position: %dsec", i_value );
1784 case VL_TIME_REL_FOR:
1786 var_Get( p_sys->p_input, "time", &val );
1787 if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
1789 val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
1792 val.i_time = i_length;
1794 var_Set( p_sys->p_input, "time", val );
1795 msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );
1798 case VL_TIME_REL_BACK:
1800 var_Get( p_sys->p_input, "time", &val );
1801 if( (int64_t)( i_value ) * 1000000 > val.i_time )
1806 val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);
1808 var_Set( p_sys->p_input, "time", val );
1809 msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );
1812 case POSITION_ABSOLUTE:
1814 val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1815 var_Set( p_sys->p_input, "position", val );
1816 msg_Dbg( p_intf, "requested seek percent: %d", i_value );
1819 case POSITION_REL_FOR:
1821 var_Get( p_sys->p_input, "position", &val );
1822 val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1823 var_Set( p_sys->p_input, "position", val );
1824 msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
1827 case POSITION_REL_BACK:
1829 var_Get( p_sys->p_input, "position", &val );
1830 val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1831 var_Set( p_sys->p_input, "position", val );
1832 msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
1837 msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
1842 #undef POSITION_ABSOLUTE
1843 #undef POSITION_REL_FOR
1844 #undef POSITION_REL_BACK
1845 #undef VL_TIME_ABSOLUTE
1846 #undef VL_TIME_REL_FOR
1847 #undef VL_TIME_REL_BACK
1853 audio_volume_t i_volume;
1856 uri_extract_value( p_request, "value", vol, 8 );
1857 aout_VolumeGet( p_intf, &i_volume );
1858 uri_decode_url_encoded( vol );
1862 i_value = atoi( vol + 1 );
1863 if( (i_volume + i_value) > AOUT_VOLUME_MAX )
1865 aout_VolumeSet( p_intf , AOUT_VOLUME_MAX );
1866 msg_Dbg( p_intf, "requested volume set: max" );
1869 aout_VolumeSet( p_intf , (i_volume + i_value) );
1870 msg_Dbg( p_intf, "requested volume set: +%i", (i_volume + i_value) );
1875 i_value = atoi( vol + 1 );
1876 if( (i_volume - i_value) < AOUT_VOLUME_MIN )
1878 aout_VolumeSet( p_intf , AOUT_VOLUME_MIN );
1879 msg_Dbg( p_intf, "requested volume set: min" );
1882 aout_VolumeSet( p_intf , (i_volume - i_value) );
1883 msg_Dbg( p_intf, "requested volume set: -%i", (i_volume - i_value) );
1886 if( strstr(vol, "%") != NULL )
1888 i_value = atoi( vol );
1889 if( (i_value <= 100) && (i_value>=0) ){
1890 aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/100+AOUT_VOLUME_MIN);
1891 msg_Dbg( p_intf, "requested volume set: %i%%", atoi( vol ));
1895 i_value = atoi( vol );
1896 if( ( i_value <= AOUT_VOLUME_MAX ) && ( i_value >= AOUT_VOLUME_MIN ) )
1898 aout_VolumeSet( p_intf , atoi( vol ) );
1899 msg_Dbg( p_intf, "requested volume set: %i", atoi( vol ) );
1905 /* playlist management */
1909 playlist_item_t * p_item;
1911 uri_extract_value( p_request, "mrl", mrl, 512 );
1912 uri_decode_url_encoded( mrl );
1913 p_item = parse_MRL( p_intf, mrl );
1915 if( !p_item || !p_item->input.psz_uri ||
1916 !*p_item->input.psz_uri )
1918 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
1921 playlist_AddItem( p_sys->p_playlist , p_item ,
1922 PLAYLIST_APPEND, PLAYLIST_END );
1923 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
1930 int i_item, *p_items = NULL, i_nb_items = 0;
1931 char item[512], *p_parser = p_request;
1933 /* Get the list of items to delete */
1935 uri_extract_value( p_parser, "item", item, 512 )) )
1937 if( !*item ) continue;
1939 i_item = atoi( item );
1940 p_items = realloc( p_items, (i_nb_items + 1) *
1942 p_items[i_nb_items] = i_item;
1949 for( i = 0; i < i_nb_items; i++ )
1951 playlist_LockDelete( p_sys->p_playlist, p_items[i] );
1952 msg_Dbg( p_intf, "requested playlist delete: %d",
1958 if( p_items ) free( p_items );
1963 int i_item, *p_items = NULL, i_nb_items = 0;
1964 char item[512], *p_parser = p_request;
1967 /* Get the list of items to keep */
1969 uri_extract_value( p_parser, "item", item, 512 )) )
1971 if( !*item ) continue;
1973 i_item = atoi( item );
1974 p_items = realloc( p_items, (i_nb_items + 1) *
1976 p_items[i_nb_items] = i_item;
1980 for( i = p_sys->p_playlist->i_size - 1 ; i >= 0; i-- )
1982 /* Check if the item is in the keep list */
1983 for( j = 0 ; j < i_nb_items ; j++ )
1986 p_sys->p_playlist->pp_items[i]->input.i_id ) break;
1988 if( j == i_nb_items )
1990 playlist_LockDelete( p_sys->p_playlist, p_sys->p_playlist->pp_items[i]->input.i_id );
1991 msg_Dbg( p_intf, "requested playlist delete: %d",
1996 if( p_items ) free( p_items );
2001 playlist_LockClear( p_sys->p_playlist );
2002 msg_Dbg( p_intf, "requested playlist empty" );
2013 uri_extract_value( p_request, "type", type, 12 );
2014 uri_extract_value( p_request, "order", order, 2 );
2015 uri_extract_value( p_request, "item", item, 512 );
2016 i_item = atoi( item );
2018 if( order[0] == '0' ) i_order = ORDER_NORMAL;
2019 else i_order = ORDER_REVERSE;
2021 if( !strcmp( type , "title" ) )
2023 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2024 p_sys->p_playlist->pp_views[0]->p_root,
2025 SORT_TITLE_NODES_FIRST,
2026 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2027 msg_Dbg( p_intf, "requested playlist sort by title (%d)" , i_order );
2028 } else if( !strcmp( type , "author" ) )
2030 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2031 p_sys->p_playlist->pp_views[0]->p_root,
2033 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2034 msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
2035 } else if( !strcmp( type , "shuffle" ) )
2037 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2038 p_sys->p_playlist->pp_views[0]->p_root,
2040 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2041 msg_Dbg( p_intf, "requested playlist shuffle");
2052 uri_extract_value( p_request, "psz_pos", psz_pos, 6 );
2053 uri_extract_value( p_request, "psz_newpos", psz_newpos, 6 );
2054 i_pos = atoi( psz_pos );
2055 i_newpos = atoi( psz_newpos );
2056 if ( i_pos < i_newpos )
2058 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
2060 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
2062 msg_Dbg( p_intf, "requested move playlist item %d to %d", i_pos, i_newpos);
2066 /* admin function */
2070 uri_extract_value( p_request, "id", id, 512 );
2071 msg_Dbg( p_intf, "requested close id=%s", id );
2073 if( p_sys->p_httpd->pf_control( p_sys->p_httpd, HTTPD_SET_CLOSE, id, NULL ) )
2075 msg_Warn( p_intf, "close failed for id=%s", id );
2082 msg_Dbg( p_intf, "requested shutdown" );
2083 p_intf->p_vlc->b_die = VLC_TRUE;
2088 case MVLC_VLM_SETUP:
2090 static const char *vlm_properties[11] =
2093 "enabled", "disabled", "loop", "unloop",
2095 "input", "output", "option", "date", "period", "repeat", "append",
2097 vlm_message_t *vlm_answer;
2099 char *psz = malloc( strlen( p_request ) + 1000 );
2104 if( p_intf->p_sys->p_vlm == NULL )
2105 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2107 if( p_intf->p_sys->p_vlm == NULL ) break;
2109 uri_extract_value( p_request, "name", name, 512 );
2110 if( StrToMacroType( control ) == MVLC_VLM_NEW )
2113 uri_extract_value( p_request, "type", type, 20 );
2114 p += sprintf( psz, "new %s %s", name, type );
2118 p += sprintf( psz, "setup %s", name );
2120 /* Parse the request */
2121 for( i = 0; i < 11; i++ )
2124 uri_extract_value( p_request, vlm_properties[i], val, 512 );
2125 uri_decode_url_encoded( val );
2126 if( strlen( val ) > 0 && i >= 4 )
2128 p += sprintf( p, " %s %s", vlm_properties[i], val );
2130 else if( uri_test_param( p_request, vlm_properties[i] ) && i < 4 )
2132 p += sprintf( p, " %s", vlm_properties[i] );
2135 fprintf( stderr, "vlm_ExecuteCommand: %s\n", psz );
2136 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2137 if( vlm_answer->psz_value == NULL ) /* there is no error */
2139 vlm_error = strdup( "" );
2143 vlm_error = malloc( strlen(vlm_answer->psz_name) +
2144 strlen(vlm_answer->psz_value) +
2145 strlen( " : ") + 1 );
2146 sprintf( vlm_error , "%s : %s" , vlm_answer->psz_name,
2147 vlm_answer->psz_value );
2150 mvar_AppendNewVar( p_args->vars, "vlm_error", vlm_error );
2152 vlm_MessageDelete( vlm_answer );
2160 vlm_message_t *vlm_answer;
2163 if( p_intf->p_sys->p_vlm == NULL )
2164 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2166 if( p_intf->p_sys->p_vlm == NULL ) break;
2168 uri_extract_value( p_request, "name", name, 512 );
2169 sprintf( psz, "del %s", name );
2171 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2172 /* FIXME do a vlm_answer -> var stack conversion */
2173 vlm_MessageDelete( vlm_answer );
2178 case MVLC_VLM_PAUSE:
2182 vlm_message_t *vlm_answer;
2185 if( p_intf->p_sys->p_vlm == NULL )
2186 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2188 if( p_intf->p_sys->p_vlm == NULL ) break;
2190 uri_extract_value( p_request, "name", name, 512 );
2191 if( StrToMacroType( control ) == MVLC_VLM_PLAY )
2192 sprintf( psz, "control %s play", name );
2193 else if( StrToMacroType( control ) == MVLC_VLM_PAUSE )
2194 sprintf( psz, "control %s pause", name );
2195 else if( StrToMacroType( control ) == MVLC_VLM_STOP )
2196 sprintf( psz, "control %s stop", name );
2197 else if( StrToMacroType( control ) == MVLC_VLM_SEEK )
2200 uri_extract_value( p_request, "percent", percent, 512 );
2201 sprintf( psz, "control %s seek %s", name, percent );
2204 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2205 /* FIXME do a vlm_answer -> var stack conversion */
2206 vlm_MessageDelete( vlm_answer );
2212 vlm_message_t *vlm_answer;
2216 if( p_intf->p_sys->p_vlm == NULL )
2217 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2219 if( p_intf->p_sys->p_vlm == NULL ) break;
2221 uri_extract_value( p_request, "file", file, 512 );
2222 uri_decode_url_encoded( file );
2224 if( StrToMacroType( control ) == MVLC_VLM_LOAD )
2225 sprintf( psz, "load %s", file );
2227 sprintf( psz, "save %s", file );
2229 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2230 /* FIXME do a vlm_answer -> var stack conversion */
2231 vlm_MessageDelete( vlm_answer );
2238 PRINTS( "<!-- control param(%s) unsuported -->", control );
2250 if( i_request <= 0 ||
2251 *m->param1 == '\0' ||
2252 strstr( p_request, m->param1 ) == NULL )
2256 uri_extract_value( p_request, m->param1, value, 512 );
2257 uri_decode_url_encoded( value );
2259 switch( StrToMacroType( m->param2 ) )
2263 config_PutInt( p_intf, m->param1, i );
2267 config_PutFloat( p_intf, m->param1, f );
2270 config_PutPsz( p_intf, m->param1, value );
2273 PRINTS( "<!-- invalid type(%s) in set -->", m->param2 )
2284 if( *m->param1 == '\0' )
2289 switch( StrToMacroType( m->param2 ) )
2292 i = config_GetInt( p_intf, m->param1 );
2293 sprintf( value, "%i", i );
2296 f = config_GetFloat( p_intf, m->param1 );
2297 sprintf( value, "%f", f );
2300 psz = config_GetPsz( p_intf, m->param1 );
2301 sprintf( value, "%s", psz ? psz : "" );
2302 if( psz ) free( psz );
2305 sprintf( value, "invalid type(%s) in set", m->param2 );
2308 msg_Dbg( p_intf, "get name=%s value=%s type=%s", m->param1, value, m->param2 );
2309 PRINTS( "%s", value );
2318 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2319 s = SSPop( &p_args->stack );
2320 v = mvar_GetValue( p_args->vars, s );
2324 v = s = SSPop( &p_args->stack );
2332 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2335 /* Usefull for learning stack management */
2339 msg_Dbg( p_intf, "stack" );
2340 for (i=0;i<(&p_args->stack)->i_stack;i++)
2341 msg_Dbg( p_intf, "%d -> %s", i, (&p_args->stack)->stack[i] );
2347 PRINTS( "<!-- invalid macro id=`%s' -->", m->id );
2348 msg_Dbg( p_intf, "invalid macro id=`%s'", m->id );
2356 static uint8_t *MacroSearch( uint8_t *src, uint8_t *end, int i_mvlc, vlc_bool_t b_after )
2363 if( src + 4 < end && !strncmp( src, "<vlc", 4 ) )
2368 i_skip = MacroParse( &m, src );
2370 i_id = StrToMacroType( m.id );
2387 if( ( i_mvlc == MVLC_END && i_level == -1 ) ||
2388 ( i_mvlc != MVLC_END && i_level == 0 && i_mvlc == i_id ) )
2390 return src + ( b_after ? i_skip : 0 );
2392 else if( i_level < 0 )
2408 static void Execute( httpd_file_sys_t *p_args,
2409 uint8_t *p_request, int i_request,
2410 uint8_t **pp_data, int *pi_data,
2412 uint8_t *_src, uint8_t *_end )
2414 intf_thread_t *p_intf = p_args->p_intf;
2416 uint8_t *src, *dup, *end;
2417 uint8_t *dst = *pp_dst;
2419 src = dup = malloc( _end - _src + 1 );
2420 end = src +( _end - _src );
2422 memcpy( src, _src, _end - _src );
2425 /* we parse searching <vlc */
2431 p = strstr( src, "<vlc" );
2432 if( p < end && p == src )
2436 src += MacroParse( &m, src );
2438 //msg_Dbg( p_intf, "macro_id=%s", m.id );
2440 switch( StrToMacroType( m.id ) )
2447 EvaluateRPN( p_args->vars, &p_args->stack, m.param1 );
2448 if( SSPopN( &p_args->stack, p_args->vars ) )
2456 endif = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2460 uint8_t *start = MacroSearch( src, endif, MVLC_ELSE, VLC_TRUE );
2464 uint8_t *stop = MacroSearch( start, endif, MVLC_END, VLC_FALSE );
2467 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2471 else if( i_test == 1 )
2474 if( ( stop = MacroSearch( src, endif, MVLC_ELSE, VLC_FALSE ) ) == NULL )
2476 stop = MacroSearch( src, endif, MVLC_END, VLC_FALSE );
2480 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, src, stop );
2489 uint8_t *endfor = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2490 uint8_t *start = src;
2491 uint8_t *stop = MacroSearch( src, end, MVLC_END, VLC_FALSE );
2498 if( !strcmp( m.param2, "integer" ) )
2500 char *arg = SSPop( &p_args->stack );
2501 index = mvar_IntegerSetNew( m.param1, arg );
2504 else if( !strcmp( m.param2, "directory" ) )
2506 char *arg = SSPop( &p_args->stack );
2507 index = mvar_FileSetNew( m.param1, arg );
2510 else if( !strcmp( m.param2, "playlist" ) )
2512 index = mvar_PlaylistSetNew( m.param1, p_intf->p_sys->p_playlist );
2514 else if( !strcmp( m.param2, "information" ) )
2516 index = mvar_InfoSetNew( m.param1, p_intf->p_sys->p_input );
2518 else if( !strcmp( m.param2, "vlm" ) )
2520 if( p_intf->p_sys->p_vlm == NULL )
2521 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2522 index = mvar_VlmSetNew( m.param1, p_intf->p_sys->p_vlm );
2525 else if( !strcmp( m.param2, "hosts" ) )
2527 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_HOSTS );
2529 else if( !strcmp( m.param2, "urls" ) )
2531 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_URLS );
2533 else if( !strcmp( m.param2, "connections" ) )
2535 index = mvar_HttpdInfoSetNew(m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_CONNECTIONS);
2538 else if( ( v = mvar_GetVar( p_args->vars, m.param2 ) ) )
2540 index = mvar_Duplicate( v );
2544 msg_Dbg( p_intf, "invalid index constructor (%s)", m.param2 );
2549 for( i_idx = 0; i_idx < index->i_field; i_idx++ )
2551 mvar_t *f = mvar_Duplicate( index->field[i_idx] );
2553 //msg_Dbg( p_intf, "foreach field[%d] name=%s value=%s", i_idx, f->name, f->value );
2556 f->name = strdup( m.param1 );
2559 mvar_PushVar( p_args->vars, f );
2560 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2561 mvar_RemoveVar( p_args->vars, f );
2565 mvar_Delete( index );
2572 MacroDo( p_args, &m, p_request, i_request, pp_data, pi_data, &dst );
2580 i_copy = ( (p == NULL || p > end ) ? end : p ) - src;
2583 int i_index = dst - *pp_data;
2586 *pp_data = realloc( *pp_data, *pi_data );
2587 dst = (*pp_data) + i_index;
2589 memcpy( dst, src, i_copy );
2599 /****************************************************************************
2601 ****************************************************************************
2602 * a file with b_html is parsed and all "macro" replaced
2603 * <vlc id="macro name" [param1="" [param2=""]] />
2606 ****************************************************************************/
2607 static int HttpCallback( httpd_file_sys_t *p_args,
2608 httpd_file_t *p_file,
2610 uint8_t **pp_data, int *pi_data )
2612 int i_request = p_request ? strlen( p_request ) : 0;
2616 if( ( f = fopen( p_args->file, "r" ) ) == NULL )
2618 p = *pp_data = malloc( 10240 );
2621 return VLC_EGENERIC;
2623 p += sprintf( p, "<html>\n" );
2624 p += sprintf( p, "<head>\n" );
2625 p += sprintf( p, "<title>Error loading %s</title>\n", p_args->file );
2626 p += sprintf( p, "</head>\n" );
2627 p += sprintf( p, "<body>\n" );
2628 p += sprintf( p, "<h1><center>Error loading %s for %s</center></h1>\n", p_args->file, p_args->name );
2629 p += sprintf( p, "<hr />\n" );
2630 p += sprintf( p, "<a href=\"http://www.videolan.org/\">VideoLAN</a>\n" );
2631 p += sprintf( p, "</body>\n" );
2632 p += sprintf( p, "</html>\n" );
2634 *pi_data = strlen( *pp_data );
2639 if( !p_args->b_html )
2641 FileLoad( f, pp_data, pi_data );
2649 char position[4]; /* percentage */
2650 char time[12]; /* in seconds */
2651 char length[12]; /* in seconds */
2652 audio_volume_t i_volume;
2656 #define p_sys p_args->p_intf->p_sys
2657 if( p_sys->p_input )
2659 var_Get( p_sys->p_input, "position", &val);
2660 sprintf( position, "%d" , (int)((val.f_float) * 100.0));
2661 var_Get( p_sys->p_input, "time", &val);
2662 sprintf( time, "%d" , (int)(val.i_time / 1000000) );
2663 var_Get( p_sys->p_input, "length", &val);
2664 sprintf( length, "%d" , (int)(val.i_time / 1000000) );
2666 var_Get( p_sys->p_input, "state", &val );
2667 if( val.i_int == PLAYING_S )
2669 sprintf( state, "playing" );
2670 } else if( val.i_int == PAUSE_S )
2672 sprintf( state, "paused" );
2675 sprintf( state, "stop" );
2679 sprintf( position, "%d", 0 );
2680 sprintf( time, "%d", 0 );
2681 sprintf( length, "%d", 0 );
2682 sprintf( state, "stop" );
2686 aout_VolumeGet( p_args->p_intf , &i_volume );
2687 sprintf( volume , "%d" , (int)i_volume );
2689 p_args->vars = mvar_New( "variables", "" );
2690 mvar_AppendNewVar( p_args->vars, "url_param", i_request > 0 ? "1" : "0" );
2691 mvar_AppendNewVar( p_args->vars, "url_value", p_request );
2692 mvar_AppendNewVar( p_args->vars, "version", VERSION_MESSAGE );
2693 mvar_AppendNewVar( p_args->vars, "copyright", COPYRIGHT_MESSAGE );
2694 mvar_AppendNewVar( p_args->vars, "stream_position", position );
2695 mvar_AppendNewVar( p_args->vars, "stream_time", time );
2696 mvar_AppendNewVar( p_args->vars, "stream_length", length );
2697 mvar_AppendNewVar( p_args->vars, "volume", volume );
2698 mvar_AppendNewVar( p_args->vars, "stream_state", state );
2700 SSInit( &p_args->stack );
2702 /* first we load in a temporary buffer */
2703 FileLoad( f, &p_buffer, &i_buffer );
2705 /* allocate output */
2706 *pi_data = i_buffer + 1000;
2707 dst = *pp_data = malloc( *pi_data );
2709 /* we parse executing all <vlc /> macros */
2710 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, &p_buffer[0], &p_buffer[i_buffer] );
2713 *pi_data = dst - *pp_data;
2715 SSClean( &p_args->stack );
2716 mvar_Delete( p_args->vars );
2725 /****************************************************************************
2727 ****************************************************************************/
2728 static int uri_test_param( char *psz_uri, const char *psz_name )
2732 while( (p = strstr( p, psz_name )) )
2734 /* Verify that we are dealing with a post/get argument */
2735 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2744 static char *uri_extract_value( char *psz_uri, const char *psz_name,
2745 char *psz_value, int i_value_max )
2749 while( (p = strstr( p, psz_name )) )
2751 /* Verify that we are dealing with a post/get argument */
2752 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2761 p += strlen( psz_name );
2762 if( *p == '=' ) p++;
2764 if( strchr( p, '&' ) )
2766 i_len = strchr( p, '&' ) - p;
2770 /* for POST method */
2771 if( strchr( p, '\n' ) )
2773 i_len = strchr( p, '\n' ) - p;
2774 if( i_len && *(p+i_len-1) == '\r' ) i_len--;
2778 i_len = strlen( p );
2781 i_len = __MIN( i_value_max - 1, i_len );
2784 strncpy( psz_value, p, i_len );
2785 psz_value[i_len] = '\0';
2789 strncpy( psz_value, "", i_value_max );
2795 strncpy( psz_value, "", i_value_max );
2801 static void uri_decode_url_encoded( char *psz )
2803 char *dup = strdup( psz );
2821 *psz++ = strtol( val, NULL, 16 );
2823 else if( *p == '+' )
2837 /****************************************************************************
2838 * Light RPN evaluator
2839 ****************************************************************************/
2840 static void SSInit( rpn_stack_t *st )
2845 static void SSClean( rpn_stack_t *st )
2847 while( st->i_stack > 0 )
2849 free( st->stack[--st->i_stack] );
2853 static void SSPush( rpn_stack_t *st, char *s )
2855 if( st->i_stack < STACK_MAX )
2857 st->stack[st->i_stack++] = strdup( s );
2861 static char * SSPop( rpn_stack_t *st )
2863 if( st->i_stack <= 0 )
2865 return strdup( "" );
2869 return st->stack[--st->i_stack];
2873 static int SSPopN( rpn_stack_t *st, mvar_t *vars )
2882 i = strtol( name, &end, 0 );
2885 value = mvar_GetValue( vars, name );
2893 static void SSPushN( rpn_stack_t *st, int i )
2897 sprintf( v, "%d", i );
2901 static void EvaluateRPN( mvar_t *vars, rpn_stack_t *st, char *exp )
2908 while( *exp == ' ' )
2915 /* extract string */
2918 while( *exp && *exp != '\'' )
2929 p = strchr( exp, ' ' );
2934 exp += strlen( exp );
2939 strncpy( s, exp, i );
2950 /* 1. Integer function */
2951 if( !strcmp( s, "!" ) )
2953 SSPushN( st, ~SSPopN( st, vars ) );
2955 else if( !strcmp( s, "^" ) )
2957 SSPushN( st, SSPopN( st, vars ) ^ SSPopN( st, vars ) );
2959 else if( !strcmp( s, "&" ) )
2961 SSPushN( st, SSPopN( st, vars ) & SSPopN( st, vars ) );
2963 else if( !strcmp( s, "|" ) )
2965 SSPushN( st, SSPopN( st, vars ) | SSPopN( st, vars ) );
2967 else if( !strcmp( s, "+" ) )
2969 SSPushN( st, SSPopN( st, vars ) + SSPopN( st, vars ) );
2971 else if( !strcmp( s, "-" ) )
2973 int j = SSPopN( st, vars );
2974 int i = SSPopN( st, vars );
2975 SSPushN( st, i - j );
2977 else if( !strcmp( s, "*" ) )
2979 SSPushN( st, SSPopN( st, vars ) * SSPopN( st, vars ) );
2981 else if( !strcmp( s, "/" ) )
2985 j = SSPopN( st, vars );
2986 i = SSPopN( st, vars );
2988 SSPushN( st, j != 0 ? i / j : 0 );
2990 else if( !strcmp( s, "%" ) )
2994 j = SSPopN( st, vars );
2995 i = SSPopN( st, vars );
2997 SSPushN( st, j != 0 ? i % j : 0 );
2999 /* 2. integer tests */
3000 else if( !strcmp( s, "=" ) )
3002 SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 );
3004 else if( !strcmp( s, "!=" ) )
3006 SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 );
3008 else if( !strcmp( s, "<" ) )
3010 int j = SSPopN( st, vars );
3011 int i = SSPopN( st, vars );
3013 SSPushN( st, i < j ? -1 : 0 );
3015 else if( !strcmp( s, ">" ) )
3017 int j = SSPopN( st, vars );
3018 int i = SSPopN( st, vars );
3020 SSPushN( st, i > j ? -1 : 0 );
3022 else if( !strcmp( s, "<=" ) )
3024 int j = SSPopN( st, vars );
3025 int i = SSPopN( st, vars );
3027 SSPushN( st, i <= j ? -1 : 0 );
3029 else if( !strcmp( s, ">=" ) )
3031 int j = SSPopN( st, vars );
3032 int i = SSPopN( st, vars );
3034 SSPushN( st, i >= j ? -1 : 0 );
3036 /* 3. string functions */
3037 else if( !strcmp( s, "strcat" ) )
3039 char *s2 = SSPop( st );
3040 char *s1 = SSPop( st );
3041 char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
3051 else if( !strcmp( s, "strcmp" ) )
3053 char *s2 = SSPop( st );
3054 char *s1 = SSPop( st );
3056 SSPushN( st, strcmp( s1, s2 ) );
3060 else if( !strcmp( s, "strncmp" ) )
3062 int n = SSPopN( st, vars );
3063 char *s2 = SSPop( st );
3064 char *s1 = SSPop( st );
3066 SSPushN( st, strncmp( s1, s2 , n ) );
3070 else if( !strcmp( s, "strsub" ) )
3072 int n = SSPopN( st, vars );
3073 int m = SSPopN( st, vars );
3075 char *s = SSPop( st );
3087 str = malloc( i_len + 1 );
3089 memcpy( str, s + m - 1, i_len );
3090 str[ i_len ] = '\0';
3096 else if( !strcmp( s, "strlen" ) )
3098 char *str = SSPop( st );
3100 SSPushN( st, strlen( str ) );
3103 /* 4. stack functions */
3104 else if( !strcmp( s, "dup" ) )
3106 char *str = SSPop( st );
3111 else if( !strcmp( s, "drop" ) )
3113 char *str = SSPop( st );
3116 else if( !strcmp( s, "swap" ) )
3118 char *s1 = SSPop( st );
3119 char *s2 = SSPop( st );
3126 else if( !strcmp( s, "flush" ) )
3131 else if( !strcmp( s, "store" ) )
3133 char *value = SSPop( st );
3134 char *name = SSPop( st );
3136 mvar_PushNewVar( vars, name, value );
3140 else if( !strcmp( s, "value" ) )
3142 char *name = SSPop( st );
3143 char *value = mvar_GetValue( vars, name );
3145 SSPush( st, value );
3149 else if( !strcmp( s, "url_extract" ) )
3151 char *url = mvar_GetValue( vars, "url_value" );
3152 char *name = SSPop( st );
3155 uri_extract_value( url, name, value, 512 );
3156 uri_decode_url_encoded( value );
3157 SSPush( st, value );
3166 /**********************************************************************
3167 * Find_end_MRL: Find the end of the sentence :
3168 * this function parses the string psz and find the end of the item
3169 * and/or option with detecting the " and ' problems.
3170 * returns NULL if an error is detected, otherwise, returns a pointer
3171 * of the end of the sentence (after the last character)
3172 **********************************************************************/
3173 static char *Find_end_MRL( char *psz )
3183 while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) )
3185 if( *s_sent == '\'' )
3187 s_sent = Find_end_MRL( s_sent );
3189 if( s_sent == NULL )
3199 if( *s_sent == '\"' )
3203 } else /* *s_sent == '\0' , which means the number of " is incorrect */
3213 while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) )
3215 if( *s_sent == '\"' )
3217 s_sent = Find_end_MRL( s_sent );
3219 if( s_sent == NULL )
3229 if( *s_sent == '\'' )
3233 } else /* *s_sent == '\0' , which means the number of ' is incorrect */
3239 default: /* now we can look for spaces */
3241 while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) )
3243 if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) )
3245 s_sent = Find_end_MRL( s_sent );
3256 /**********************************************************************
3257 * parse_MRL: parse the MRL, find the mrl string and the options,
3258 * create an item with all information in it, and return the item.
3259 * return NULL if there is an error.
3260 **********************************************************************/
3261 playlist_item_t * parse_MRL( intf_thread_t *p_intf, char *psz )
3263 char **ppsz_options = NULL;
3270 playlist_item_t * p_item = NULL;
3272 /* In case there is spaces before the mrl */
3273 while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
3278 /* extract the mrl */
3279 s_temp = strstr( s_mrl , " :" );
3280 if( s_temp == NULL )
3282 s_temp = s_mrl + strlen( s_mrl );
3285 while( (*s_temp == ' ') && (s_temp != s_mrl ) )
3292 /* if the mrl is between " or ', we must remove them */
3293 if( (*s_mrl == '\'') || (*s_mrl == '\"') )
3295 mrl = (char *)malloc( (s_temp - s_mrl - 1) * sizeof( char ) );
3296 strncpy( mrl , (s_mrl + 1) , s_temp - s_mrl - 2 );
3297 mrl[ s_temp - s_mrl - 2 ] = '\0';
3300 mrl = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) );
3301 strncpy( mrl , s_mrl , s_temp - s_mrl );
3302 mrl[ s_temp - s_mrl ] = '\0';
3307 /* now we can take care of the options */
3308 while( (*s_mrl != '\0') && (i_error == 0) )
3317 case ':': /* an option */
3319 s_temp = Find_end_MRL( s_mrl );
3321 if( s_temp == NULL )
3328 ppsz_options = realloc( ppsz_options , i_options *
3330 ppsz_options[ i_options - 1 ] =
3331 malloc( (s_temp - s_mrl + 1) * sizeof(char) );
3333 strncpy( ppsz_options[ i_options - 1 ] , s_mrl ,
3336 /* don't forget to finish the string with a '\0' */
3337 (ppsz_options[ i_options - 1 ])[ s_temp - s_mrl ] = '\0';
3357 /* now create an item */
3358 p_item = playlist_ItemNew( p_intf, mrl, mrl);
3359 for( i = 0 ; i< i_options ; i++ )
3361 playlist_ItemAddOption( p_item, ppsz_options[i] );
3365 for( i = 0 ; i < i_options ; i++ )
3367 free( ppsz_options[i] );
3369 free( ppsz_options );