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_description( _("HTTP remote control interface") );
93 set_category( CAT_INTERFACE );
94 set_subcategory( SUBCAT_INTERFACE_GENERAL );
95 add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
96 add_string ( "http-src", NULL, NULL, SRC_TEXT, SRC_LONGTEXT, VLC_TRUE );
97 add_string ( "http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT, VLC_TRUE );
98 add_string ( "http-intf-key", NULL, NULL, KEY_TEXT, KEY_LONGTEXT, VLC_TRUE );
99 add_string ( "http-intf-ca", NULL, NULL, CA_TEXT, CA_LONGTEXT, VLC_TRUE );
100 add_string ( "http-intf-crl", NULL, NULL, CRL_TEXT, CRL_LONGTEXT, VLC_TRUE );
101 set_capability( "interface", 0 );
102 set_callbacks( Open, Close );
106 /*****************************************************************************
108 *****************************************************************************/
109 static void Run ( intf_thread_t *p_intf );
111 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
114 static int DirectoryCheck( char *psz_dir )
118 #ifdef HAVE_SYS_STAT_H
119 struct stat stat_info;
121 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
127 if( ( p_dir = opendir( psz_dir ) ) == NULL )
136 static int HttpCallback( httpd_file_sys_t *p_args,
139 uint8_t **pp_data, int *pi_data );
141 static char *uri_extract_value( char *psz_uri, const char *psz_name,
142 char *psz_value, int i_value_max );
143 static int uri_test_param( char *psz_uri, const char *psz_name );
145 static void uri_decode_url_encoded( char *psz );
147 static char *Find_end_MRL( char *psz );
149 static playlist_item_t * parse_MRL( intf_thread_t * , char *psz );
151 /*****************************************************************************
153 *****************************************************************************/
154 typedef struct mvar_s
160 struct mvar_s **field;
163 #define STACK_MAX 100
166 char *stack[STACK_MAX];
170 struct httpd_file_sys_t
172 intf_thread_t *p_intf;
173 httpd_file_t *p_file;
174 httpd_redirect_t *p_redir;
175 httpd_redirect_t *p_redir2;
182 /* inited for each access */
189 httpd_host_t *p_httpd_host;
192 httpd_file_sys_t **pp_files;
194 playlist_t *p_playlist;
195 input_thread_t *p_input;
201 /*****************************************************************************
202 * Activate: initialize and create stuff
203 *****************************************************************************/
204 static int Open( vlc_object_t *p_this )
206 intf_thread_t *p_intf = (intf_thread_t*)p_this;
209 char *psz_address = "";
210 const char *psz_cert;
215 psz_host = config_GetPsz( p_intf, "http-host" );
219 psz_address = psz_host;
221 psz_parser = strchr( psz_host, ':' );
224 *psz_parser++ = '\0';
225 i_port = atoi( psz_parser );
229 p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
232 return( VLC_ENOMEM );
234 p_sys->p_playlist = NULL;
235 p_sys->p_input = NULL;
238 psz_cert = config_GetPsz( p_intf, "http-intf-cert" );
239 if ( psz_cert != NULL )
243 msg_Dbg( p_intf, "enablind TLS for HTTP interface (cert file: %s)",
245 psz_pem = config_GetPsz( p_intf, "http-intf-key" );
247 p_tls = tls_ServerCreate( p_this, psz_cert, psz_pem );
250 msg_Err( p_intf, "TLS initialization error" );
255 psz_pem = config_GetPsz( p_intf, "http-intf-ca" );
256 if ( ( psz_pem != NULL) && tls_ServerAddCA( p_tls, psz_pem ) )
258 msg_Err( p_intf, "TLS CA error" );
259 tls_ServerDelete( p_tls );
264 psz_pem = config_GetPsz( p_intf, "http-intf-crl" );
265 if ( ( psz_pem != NULL) && tls_ServerAddCRL( p_tls, psz_pem ) )
267 msg_Err( p_intf, "TLS CRL error" );
268 tls_ServerDelete( p_tls );
283 msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
285 p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
287 if( p_sys->p_httpd_host == NULL )
289 msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
291 tls_ServerDelete( p_tls );
302 p_sys->pp_files = NULL;
304 #if defined(SYS_DARWIN) || defined(SYS_BEOS) || defined(WIN32)
305 if ( ( psz_src = config_GetPsz( p_intf, "http-src" )) == NULL )
307 char * psz_vlcpath = p_intf->p_libvlc->psz_vlcpath;
308 psz_src = malloc( strlen(psz_vlcpath) + strlen("/share/http" ) + 1 );
309 if( !psz_src ) return VLC_ENOMEM;
311 sprintf( psz_src, "%s/http", psz_vlcpath);
313 sprintf( psz_src, "%s/share/http", psz_vlcpath);
317 psz_src = config_GetPsz( p_intf, "http-src" );
319 if( !psz_src || *psz_src == '\0' )
321 if( !DirectoryCheck( "share/http" ) )
323 psz_src = strdup( "share/http" );
325 else if( !DirectoryCheck( DATA_PATH "/http" ) )
327 psz_src = strdup( DATA_PATH "/http" );
332 if( !psz_src || *psz_src == '\0' )
334 msg_Err( p_intf, "invalid src dir" );
338 /* remove trainling \ or / */
339 if( psz_src[strlen( psz_src ) - 1] == '\\' ||
340 psz_src[strlen( psz_src ) - 1] == '/' )
342 psz_src[strlen( psz_src ) - 1] = '\0';
345 ParseDirectory( p_intf, psz_src, psz_src );
348 if( p_sys->i_files <= 0 )
350 msg_Err( p_intf, "cannot find any files (%s)", psz_src );
353 p_intf->pf_run = Run;
359 if( psz_src ) free( psz_src );
360 if( p_sys->pp_files )
362 free( p_sys->pp_files );
364 httpd_HostDelete( p_sys->p_httpd_host );
369 /*****************************************************************************
370 * CloseIntf: destroy interface
371 *****************************************************************************/
372 void Close ( vlc_object_t *p_this )
374 intf_thread_t *p_intf = (intf_thread_t *)p_this;
375 intf_sys_t *p_sys = p_intf->p_sys;
381 vlm_Delete( p_sys->p_vlm );
383 for( i = 0; i < p_sys->i_files; i++ )
385 httpd_FileDelete( p_sys->pp_files[i]->p_file );
386 if( p_sys->pp_files[i]->p_redir )
387 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir );
388 if( p_sys->pp_files[i]->p_redir2 )
389 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir2 );
391 free( p_sys->pp_files[i]->file );
392 free( p_sys->pp_files[i]->name );
393 free( p_sys->pp_files[i] );
395 if( p_sys->pp_files )
397 free( p_sys->pp_files );
399 httpd_HostDelete( p_sys->p_httpd_host );
404 /*****************************************************************************
405 * Run: http interface thread
406 *****************************************************************************/
407 static void Run( intf_thread_t *p_intf )
409 intf_sys_t *p_sys = p_intf->p_sys;
411 while( !p_intf->b_die )
413 /* get the playlist */
414 if( p_sys->p_playlist == NULL )
416 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
419 /* Manage the input part */
420 if( p_sys->p_input == NULL )
422 if( p_sys->p_playlist )
425 vlc_object_find( p_sys->p_playlist,
430 else if( p_sys->p_input->b_dead )
432 vlc_object_release( p_sys->p_input );
433 p_sys->p_input = NULL;
438 msleep( INTF_IDLE_SLEEP );
443 vlc_object_release( p_sys->p_input );
444 p_sys->p_input = NULL;
447 if( p_sys->p_playlist )
449 vlc_object_release( p_sys->p_playlist );
450 p_sys->p_playlist = NULL;
455 /*****************************************************************************
457 *****************************************************************************/
458 #define MAX_DIR_SIZE 10240
460 /****************************************************************************
461 * FileToUrl: create a good name for an url from filename
462 ****************************************************************************/
463 static char *FileToUrl( char *name, vlc_bool_t *pb_index )
467 url = p = malloc( strlen( name ) + 1 );
475 while( *name == '\\' || *name == '/' )
477 while( *name == '/' )
487 /* convert '\\' into '/' */
499 *pb_index = VLC_FALSE;
501 if( ( p = strrchr( url, '/' ) ) != NULL )
503 if( !strncmp( p, "/index.", 7 ) )
506 *pb_index = VLC_TRUE;
512 /****************************************************************************
513 * ParseDirectory: parse recursively a directory, adding each file
514 ****************************************************************************/
515 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
518 intf_sys_t *p_sys = p_intf->p_sys;
519 char dir[MAX_DIR_SIZE];
520 #ifdef HAVE_SYS_STAT_H
521 struct stat stat_info;
524 struct dirent *p_dir_content;
528 char *password = NULL;
530 #ifdef HAVE_SYS_STAT_H
531 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
537 if( ( p_dir = opendir( psz_dir ) ) == NULL )
539 msg_Err( p_intf, "cannot open dir (%s)", psz_dir );
543 msg_Dbg( p_intf, "dir=%s", psz_dir );
545 sprintf( dir, "%s/.access", psz_dir );
546 if( ( file = fopen( dir, "r" ) ) != NULL )
551 msg_Dbg( p_intf, "find .access in dir=%s", psz_dir );
553 i_size = fread( line, 1, 1023, file );
557 while( i_size > 0 && ( line[i_size-1] == '\n' ||
558 line[i_size-1] == '\r' ) )
565 p = strchr( line, ':' );
569 user = strdup( line );
570 password = strdup( p );
573 msg_Dbg( p_intf, "using user=%s password=%s (read=%d)",
574 user, password, i_size );
581 /* parse psz_src dir */
582 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
587 if( p_dir_content->d_name[0] == '.' )
591 sprintf( dir, "%s/%s", psz_dir, p_dir_content->d_name );
592 if( ParseDirectory( p_intf, psz_root, dir ) )
594 httpd_file_sys_t *f = malloc( sizeof( httpd_file_sys_t ) );
601 f->file = strdup( dir );
602 f->name = FileToUrl( &dir[strlen( psz_root )], &b_index );
603 f->b_html = strstr( &dir[strlen( psz_root )], ".htm" ) ? VLC_TRUE : VLC_FALSE;
607 msg_Err( p_intf , "unable to parse directory" );
610 return( VLC_ENOMEM );
612 msg_Dbg( p_intf, "file=%s (url=%s)",
615 f->p_file = httpd_FileNew( p_sys->p_httpd_host,
616 f->name, f->b_html ? "text/html" : NULL,
622 TAB_APPEND( p_sys->i_files, p_sys->pp_files, f );
624 /* for url that ends by / add
625 * - a redirect from rep to rep/
626 * - in case of index.* rep/index.html to rep/ */
627 if( f && f->name[strlen(f->name) - 1] == '/' )
629 char *psz_redir = strdup( f->name );
631 psz_redir[strlen( psz_redir ) - 1] = '\0';
633 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
634 f->p_redir = httpd_RedirectNew( p_sys->p_httpd_host, f->name, psz_redir );
637 if( b_index && ( p = strstr( f->file, "index." ) ) )
639 asprintf( &psz_redir, "%s%s", f->name, p );
641 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
642 f->p_redir2 = httpd_RedirectNew( p_sys->p_httpd_host,
643 f->name, psz_redir );
665 /****************************************************************************
666 * var and set handling
667 ****************************************************************************/
669 static mvar_t *mvar_New( char *name, char *value )
671 mvar_t *v = malloc( sizeof( mvar_t ) );
673 if( !v ) return NULL;
674 v->name = strdup( name );
675 v->value = strdup( value ? value : "" );
678 v->field = malloc( sizeof( mvar_t * ) );
684 static void mvar_Delete( mvar_t *v )
691 for( i = 0; i < v->i_field; i++ )
693 mvar_Delete( v->field[i] );
699 static void mvar_AppendVar( mvar_t *v, mvar_t *f )
701 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
702 v->field[v->i_field] = f;
706 static mvar_t *mvar_Duplicate( mvar_t *v )
711 n = mvar_New( v->name, v->value );
712 for( i = 0; i < v->i_field; i++ )
714 mvar_AppendVar( n, mvar_Duplicate( v->field[i] ) );
720 static void mvar_PushVar( mvar_t *v, mvar_t *f )
722 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
725 memmove( &v->field[1], &v->field[0], sizeof( mvar_t * ) * v->i_field );
731 static void mvar_RemoveVar( mvar_t *v, mvar_t *f )
734 for( i = 0; i < v->i_field; i++ )
736 if( v->field[i] == f )
741 if( i >= v->i_field )
746 if( i + 1 < v->i_field )
748 memmove( &v->field[i], &v->field[i+1], sizeof( mvar_t * ) * ( v->i_field - i - 1 ) );
751 /* FIXME should do a realloc */
754 static mvar_t *mvar_GetVar( mvar_t *s, char *name )
757 char base[512], *field, *p;
760 /* format: name[index].field */
762 field = strchr( name, '.' );
765 int i = field - name;
766 strncpy( base, name, i );
772 strcpy( base, name );
775 if( ( p = strchr( base, '[' ) ) )
778 sscanf( p, "%d]", &i_index );
789 for( i = 0; i < s->i_field; i++ )
791 if( !strcmp( s->field[i]->name, base ) )
801 return mvar_GetVar( s->field[i], field );
815 static char *mvar_GetValue( mvar_t *v, char *field )
823 mvar_t *f = mvar_GetVar( v, field );
835 static void mvar_PushNewVar( mvar_t *vars, char *name, char *value )
837 mvar_t *f = mvar_New( name, value );
838 mvar_PushVar( vars, f );
841 static void mvar_AppendNewVar( mvar_t *vars, char *name, char *value )
843 mvar_t *f = mvar_New( name, value );
844 mvar_AppendVar( vars, f );
848 /* arg= start[:stop[:step]],.. */
849 static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
851 char *dup = strdup( arg );
853 mvar_t *s = mvar_New( name, "set" );
855 fprintf( stderr," mvar_IntegerSetNew: name=`%s' arg=`%s'\n", name, str );
860 int i_start,i_stop,i_step;
863 p = strchr( str, ',' );
870 i_match = sscanf( str, "%d:%d:%d", &i_start, &i_stop, &i_step );
871 fprintf( stderr," mvar_IntegerSetNew: m=%d start=%d stop=%d step=%d\n", i_match, i_start, i_stop, i_step );
878 else if( i_match == 2 )
880 i_step = i_start < i_stop ? 1 : -1;
887 if( ( i_start <= i_stop && i_step > 0 ) ||
888 ( i_start >= i_stop && i_step < 0 ) )
890 for( i = i_start; ; i += i_step )
894 if( ( i_step > 0 && i > i_stop ) ||
895 ( i_step < 0 && i < i_stop ) )
900 fprintf( stderr," mvar_IntegerSetNew: adding %d\n", i );
901 sprintf( value, "%d", i );
903 mvar_PushNewVar( s, name, value );
914 void PlaylistListNode( playlist_t *p_pl, playlist_item_t *p_node,
915 char *name, mvar_t *s, int i_depth )
919 if (p_node->i_children == -1)
922 mvar_t *itm = mvar_New( name, "set" );
924 sprintf( value, "%d", ( p_pl->status.p_item == p_node )? 1 : 0 );
925 mvar_AppendNewVar( itm, "current", value );
927 sprintf( value, "%d", p_node->input.i_id );
928 mvar_AppendNewVar( itm, "index", value );
930 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
932 mvar_AppendNewVar( itm, "uri", p_node->input.psz_uri );
934 sprintf( value, "Item");
935 mvar_AppendNewVar( itm, "type", value );
937 sprintf( value, "%d", i_depth );
938 mvar_AppendNewVar( itm, "depth", value );
940 mvar_AppendVar( s, itm );
946 mvar_t *itm = mvar_New( name, "set" );
947 mvar_t *itm_end = mvar_New( name, "set" );
949 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
950 mvar_AppendNewVar( itm, "uri", p_node->input.psz_name );
952 sprintf( value, "Node" );
953 mvar_AppendNewVar( itm, "type", value );
955 sprintf( value, "%d", p_node->input.i_id );
956 mvar_AppendNewVar( itm, "index", value );
958 sprintf( value, "%d", p_node->i_children);
959 mvar_AppendNewVar( itm, "i_children", value );
961 sprintf( value, "%d", i_depth );
962 mvar_AppendNewVar( itm, "depth", value );
964 mvar_AppendVar( s, itm );
966 for (i_child = 0 ; i_child < p_node->i_children ; i_child++)
967 PlaylistListNode( p_pl, p_node->pp_children[i_child], name, s, i_depth + 1);
973 static mvar_t *mvar_PlaylistSetNew( char *name, playlist_t *p_pl )
975 playlist_view_t *p_view;
976 mvar_t *s = mvar_New( name, "set" );
978 fprintf( stderr," mvar_PlaylistSetNew: name=`%s'\n", name );
980 vlc_mutex_lock( &p_pl->object_lock );
982 p_view = playlist_ViewFind( p_pl, VIEW_CATEGORY ); /* FIXME */
985 PlaylistListNode( p_pl, p_view->p_root, name, s, 0 );
987 vlc_mutex_unlock( &p_pl->object_lock );
992 static mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input )
994 mvar_t *s = mvar_New( name, "set" );
997 fprintf( stderr," mvar_InfoSetNew: name=`%s'\n", name );
998 if( p_input == NULL )
1003 vlc_mutex_lock( &p_input->input.p_item->lock );
1004 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
1006 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1007 mvar_t *cat = mvar_New( name, "set" );
1008 mvar_t *iset = mvar_New( "info", "set" );
1010 mvar_AppendNewVar( cat, "name", p_category->psz_name );
1011 mvar_AppendVar( cat, iset );
1013 for ( j = 0; j < p_category->i_infos; j++ )
1015 info_t *p_info = p_category->pp_infos[j];
1016 mvar_t *info = mvar_New( "info", "" );
1018 msg_Dbg( p_input, "adding info name=%s value=%s",
1019 p_info->psz_name, p_info->psz_value );
1020 mvar_AppendNewVar( info, "name", p_info->psz_name );
1021 mvar_AppendNewVar( info, "value", p_info->psz_value );
1022 mvar_AppendVar( iset, info );
1024 mvar_AppendVar( s, cat );
1026 vlc_mutex_unlock( &p_input->input.p_item->lock );
1031 static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
1033 mvar_t *s = mvar_New( name, "set" );
1037 fprintf( stderr," mvar_HttpdInfoSetNew: name=`%s'\n", name );
1038 if( !p_httpd->pf_control( p_httpd, i_type, &info, NULL ) )
1040 for( i= 0; i < info.i_count; )
1044 inf = mvar_New( name, "set" );
1047 /* fprintf( stderr," mvar_HttpdInfoSetNew: append name=`%s' value=`%s'\n",
1048 info.info[i].psz_name, info.info[i].psz_value ); */
1049 mvar_AppendNewVar( inf,
1050 info.info[i].psz_name,
1051 info.info[i].psz_value );
1053 } while( i < info.i_count && strcmp( info.info[i].psz_name, "id" ) );
1054 mvar_AppendVar( s, inf );
1059 for( i = 0; i < info.i_count; i++ )
1061 free( info.info[i].psz_name );
1062 free( info.info[i].psz_value );
1064 if( info.i_count > 0 )
1073 static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
1075 mvar_t *s = mvar_New( name, "set" );
1076 char tmp[MAX_DIR_SIZE], *p, *src;
1077 #ifdef HAVE_SYS_STAT_H
1078 struct stat stat_info;
1081 struct dirent *p_dir_content;
1084 /* convert all / to native separator */
1085 #if defined( WIN32 )
1086 while( (p = strchr( psz_dir, '/' )) )
1095 /* remove trailling separator */
1096 while( strlen( psz_dir ) > 1 &&
1097 #if defined( WIN32 )
1098 !( strlen(psz_dir)==3 && psz_dir[1]==':' && psz_dir[2]==sep ) &&
1100 psz_dir[strlen( psz_dir ) -1 ] == sep )
1102 psz_dir[strlen( psz_dir ) -1 ] ='\0';
1104 /* remove double separator */
1105 for( p = src = psz_dir; *src != '\0'; src++, p++ )
1107 if( src[0] == sep && src[1] == sep )
1115 if( *psz_dir == '\0' )
1119 /* first fix all .. dir */
1123 if( src[0] == '.' && src[1] == '.' )
1126 if( p <= &psz_dir[1] )
1133 while( p > &psz_dir[1] && *p != sep )
1138 else if( *src == sep )
1140 if( p > psz_dir && p[-1] == sep )
1154 } while( *src && *src != sep );
1159 fprintf( stderr," mvar_FileSetNew: name=`%s' dir=`%s'\n", name, psz_dir );
1161 #ifdef HAVE_SYS_STAT_H
1162 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
1168 if( ( p_dir = opendir( psz_dir ) ) == NULL )
1170 fprintf( stderr, "cannot open dir (%s)", psz_dir );
1174 /* remove traling / or \ */
1175 for( p = &psz_dir[strlen( psz_dir) - 1];
1176 p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- )
1185 /* parse psz_src dir */
1186 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
1190 if( !strcmp( p_dir_content->d_name, "." ) )
1195 sprintf( tmp, "%s/%s", psz_dir, p_dir_content->d_name );
1197 #ifdef HAVE_SYS_STAT_H
1198 if( stat( tmp, &stat_info ) == -1 )
1203 f = mvar_New( name, "set" );
1204 mvar_AppendNewVar( f, "name", tmp );
1206 #ifdef HAVE_SYS_STAT_H
1207 if( S_ISDIR( stat_info.st_mode ) )
1209 mvar_AppendNewVar( f, "type", "directory" );
1211 else if( S_ISREG( stat_info.st_mode ) )
1213 mvar_AppendNewVar( f, "type", "file" );
1217 mvar_AppendNewVar( f, "type", "unknown" );
1220 sprintf( tmp, I64Fd, (int64_t)stat_info.st_size );
1221 mvar_AppendNewVar( f, "size", tmp );
1223 /* FIXME memory leak FIXME */
1225 ctime_r( &stat_info.st_mtime, tmp );
1226 mvar_AppendNewVar( f, "date", tmp );
1228 mvar_AppendNewVar( f, "date", ctime( &stat_info.st_mtime ) );
1232 mvar_AppendNewVar( f, "type", "unknown" );
1233 mvar_AppendNewVar( f, "size", "unknown" );
1234 mvar_AppendNewVar( f, "date", "unknown" );
1236 mvar_AppendVar( s, f );
1242 static mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm )
1244 mvar_t *s = mvar_New( name, "set" );
1248 /* fprintf( stderr," mvar_VlmSetNew: name=`%s'\n", name ); */
1249 if( vlm == NULL ) return s;
1251 if( vlm_ExecuteCommand( vlm, "show", &msg ) )
1256 for( i = 0; i < msg->i_child; i++ )
1258 /* Over media, schedule */
1259 vlm_message_t *ch = msg->child[i];
1262 for( j = 0; j < ch->i_child; j++ )
1265 vlm_message_t *el = ch->child[j];
1266 vlm_message_t *inf, *desc;
1271 sprintf( psz, "show %s", el->psz_name );
1272 if( vlm_ExecuteCommand( vlm, psz, &inf ) )
1274 desc = inf->child[0];
1276 /* Add a node with name and info */
1277 set = mvar_New( name, "set" );
1278 mvar_AppendNewVar( set, "name", el->psz_name );
1280 /* fprintf( stderr, "#### name=%s\n", el->psz_name ); */
1282 for( k = 0; k < desc->i_child; k++ )
1284 vlm_message_t *ch = desc->child[k];
1285 if( ch->i_child > 0 )
1288 mvar_t *n = mvar_New( ch->psz_name, "set" );
1290 /* fprintf( stderr, " child=%s [%d]\n", ch->psz_name, ch->i_child ); */
1291 for( c = 0; c < ch->i_child; c++ )
1293 mvar_t *in = mvar_New( ch->psz_name, ch->child[c]->psz_name );
1294 mvar_AppendVar( n, in );
1296 /* fprintf( stderr, " sub=%s\n", ch->child[c]->psz_name );*/
1298 mvar_AppendVar( set, n );
1302 /* fprintf( stderr, " child=%s->%s\n", ch->psz_name, ch->psz_value ); */
1303 mvar_AppendNewVar( set, ch->psz_name, ch->psz_value );
1306 vlm_MessageDelete( inf );
1308 mvar_AppendVar( s, set );
1311 vlm_MessageDelete( msg );
1317 static void SSInit( rpn_stack_t * );
1318 static void SSClean( rpn_stack_t * );
1319 static void EvaluateRPN( mvar_t *, rpn_stack_t *, char * );
1321 static void SSPush ( rpn_stack_t *, char * );
1322 static char *SSPop ( rpn_stack_t * );
1324 static void SSPushN ( rpn_stack_t *, int );
1325 static int SSPopN ( rpn_stack_t *, mvar_t * );
1328 /****************************************************************************
1330 ****************************************************************************/
1338 static int FileLoad( FILE *f, uint8_t **pp_data, int *pi_data )
1342 /* just load the file */
1344 *pp_data = malloc( 1025 ); /* +1 for \0 */
1345 while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 )
1348 *pp_data = realloc( *pp_data, *pi_data + 1025 );
1354 (*pp_data)[*pi_data] = '\0';
1359 static int MacroParse( macro_t *m, uint8_t *psz_src )
1361 uint8_t *dup = strdup( psz_src );
1366 #define EXTRACT( name, l ) \
1368 p = strchr( src, '"' ); \
1373 m->name = strdup( src ); \
1394 if( !strncmp( src, "id=\"", 4 ) )
1398 else if( !strncmp( src, "param1=\"", 8 ) )
1400 EXTRACT( param1, 8 );
1402 else if( !strncmp( src, "param2=\"", 8 ) )
1404 EXTRACT( param2, 8 );
1411 if( strstr( src, "/>" ) )
1413 src = strstr( src, "/>" ) + 2;
1417 src += strlen( src );
1422 m->id = strdup( "" );
1424 if( m->param1 == NULL )
1426 m->param1 = strdup( "" );
1428 if( m->param2 == NULL )
1430 m->param2 = strdup( "" );
1439 static void MacroClean( macro_t *m )
1498 StrToMacroTypeTab [] =
1500 { "control", MVLC_CONTROL },
1501 /* player control */
1502 { "play", MVLC_PLAY },
1503 { "stop", MVLC_STOP },
1504 { "pause", MVLC_PAUSE },
1505 { "next", MVLC_NEXT },
1506 { "previous", MVLC_PREVIOUS },
1507 { "seek", MVLC_SEEK },
1508 { "keep", MVLC_KEEP },
1509 { "fullscreen", MVLC_FULLSCREEN },
1510 { "volume", MVLC_VOLUME },
1512 /* playlist management */
1513 { "add", MVLC_ADD },
1514 { "delete", MVLC_DEL },
1515 { "empty", MVLC_EMPTY },
1516 { "sort", MVLC_SORT },
1517 { "move", MVLC_MOVE },
1520 { "close", MVLC_CLOSE },
1521 { "shutdown", MVLC_SHUTDOWN },
1524 { "vlm_new", MVLC_VLM_NEW },
1525 { "vlm_setup", MVLC_VLM_SETUP },
1526 { "vlm_del", MVLC_VLM_DEL },
1527 { "vlm_play", MVLC_VLM_PLAY },
1528 { "vlm_pause", MVLC_VLM_PAUSE },
1529 { "vlm_stop", MVLC_VLM_STOP },
1530 { "vlm_seek", MVLC_VLM_SEEK },
1531 { "vlm_load", MVLC_VLM_LOAD },
1532 { "vlm_save", MVLC_VLM_SAVE },
1534 { "rpn", MVLC_RPN },
1535 { "stack", MVLC_STACK },
1537 { "foreach", MVLC_FOREACH },
1538 { "value", MVLC_VALUE },
1541 { "else", MVLC_ELSE },
1542 { "end", MVLC_END },
1543 { "get", MVLC_GET },
1544 { "set", MVLC_SET },
1545 { "int", MVLC_INT },
1546 { "float", MVLC_FLOAT },
1547 { "string", MVLC_STRING },
1550 { NULL, MVLC_UNKNOWN }
1553 static int StrToMacroType( char *name )
1557 if( !name || *name == '\0')
1559 return MVLC_UNKNOWN;
1561 for( i = 0; StrToMacroTypeTab[i].psz_name != NULL; i++ )
1563 if( !strcmp( name, StrToMacroTypeTab[i].psz_name ) )
1565 return StrToMacroTypeTab[i].i_type;
1568 return MVLC_UNKNOWN;
1571 static void MacroDo( httpd_file_sys_t *p_args,
1573 uint8_t *p_request, int i_request,
1574 uint8_t **pp_data, int *pi_data,
1577 intf_thread_t *p_intf = p_args->p_intf;
1578 intf_sys_t *p_sys = p_args->p_intf->p_sys;
1581 #define ALLOC( l ) \
1583 int __i__ = *pp_dst - *pp_data; \
1585 *pp_data = realloc( *pp_data, *pi_data ); \
1586 *pp_dst = (*pp_data) + __i__; \
1588 #define PRINT( str ) \
1589 ALLOC( strlen( str ) + 1 ); \
1590 *pp_dst += sprintf( *pp_dst, str );
1592 #define PRINTS( str, s ) \
1593 ALLOC( strlen( str ) + strlen( s ) + 1 ); \
1595 char * psz_cur = *pp_dst; \
1596 *pp_dst += sprintf( *pp_dst, str, s ); \
1597 while( psz_cur && *psz_cur ) \
1599 /* Prevent script injection */ \
1600 if( *psz_cur == '<' ) *psz_cur = '*'; \
1601 if( *psz_cur == '>' ) *psz_cur = '*'; \
1606 switch( StrToMacroType( m->id ) )
1609 if( i_request <= 0 )
1613 uri_extract_value( p_request, "control", control, 512 );
1614 if( *m->param1 && !strstr( m->param1, control ) )
1616 msg_Warn( p_intf, "unauthorized control=%s", control );
1619 switch( StrToMacroType( control ) )
1626 uri_extract_value( p_request, "item", item, 512 );
1627 i_item = atoi( item );
1628 playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
1629 playlist_ItemGetById( p_sys->p_playlist,
1631 msg_Dbg( p_intf, "requested playlist item: %i", i_item );
1635 playlist_Control( p_sys->p_playlist, PLAYLIST_STOP);
1636 msg_Dbg( p_intf, "requested playlist stop" );
1639 playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
1640 msg_Dbg( p_intf, "requested playlist pause" );
1643 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
1644 msg_Dbg( p_intf, "requested playlist next" );
1647 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1);
1648 msg_Dbg( p_intf, "requested playlist next" );
1650 case MVLC_FULLSCREEN:
1652 if( p_sys->p_input )
1654 vout_thread_t *p_vout;
1655 p_vout = vlc_object_find( p_sys->p_input,
1656 VLC_OBJECT_VOUT, FIND_CHILD );
1660 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1661 vlc_object_release( p_vout );
1662 msg_Dbg( p_intf, "requested fullscreen toggle" );
1676 #define POSITION_ABSOLUTE 12
1677 #define POSITION_REL_FOR 13
1678 #define POSITION_REL_BACK 11
1679 #define VL_TIME_ABSOLUTE 0
1680 #define VL_TIME_REL_FOR 1
1681 #define VL_TIME_REL_BACK -1
1682 if( p_sys->p_input )
1684 uri_extract_value( p_request, "seek_value", value, 20 );
1685 uri_decode_url_encoded( value );
1687 var_Get( p_sys->p_input, "length", &val);
1688 i_length = val.i_time;
1690 while( p_value[0] != '\0' )
1696 i_relative = VL_TIME_REL_FOR;
1702 i_relative = VL_TIME_REL_BACK;
1706 case '0': case '1': case '2': case '3': case '4':
1707 case '5': case '6': case '7': case '8': case '9':
1709 i_stock = strtol( p_value , &p_value , 10 );
1712 case '%': /* for percentage ie position */
1714 i_relative += POSITION_ABSOLUTE;
1722 i_value = 60 * (i_value + i_stock) ;
1727 case 'h': case 'H': /* hours */
1729 i_value += 3600 * i_stock;
1731 /* other characters which are not numbers are not important */
1732 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1738 case 'm': case 'M': case '\'': /* minutes */
1740 i_value += 60 * i_stock;
1743 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1749 case 's': case 'S': case '"': /* seconds */
1753 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1767 /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
1772 case VL_TIME_ABSOLUTE:
1774 if( (uint64_t)( i_value ) * 1000000 <= i_length )
1775 val.i_time = (uint64_t)( i_value ) * 1000000;
1777 val.i_time = i_length;
1779 var_Set( p_sys->p_input, "time", val );
1780 msg_Dbg( p_intf, "requested seek position: %dsec", i_value );
1783 case VL_TIME_REL_FOR:
1785 var_Get( p_sys->p_input, "time", &val );
1786 if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
1788 val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
1791 val.i_time = i_length;
1793 var_Set( p_sys->p_input, "time", val );
1794 msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );
1797 case VL_TIME_REL_BACK:
1799 var_Get( p_sys->p_input, "time", &val );
1800 if( (int64_t)( i_value ) * 1000000 > val.i_time )
1805 val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);
1807 var_Set( p_sys->p_input, "time", val );
1808 msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );
1811 case POSITION_ABSOLUTE:
1813 val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1814 var_Set( p_sys->p_input, "position", val );
1815 msg_Dbg( p_intf, "requested seek percent: %d", i_value );
1818 case POSITION_REL_FOR:
1820 var_Get( p_sys->p_input, "position", &val );
1821 val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1822 var_Set( p_sys->p_input, "position", val );
1823 msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
1826 case POSITION_REL_BACK:
1828 var_Get( p_sys->p_input, "position", &val );
1829 val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1830 var_Set( p_sys->p_input, "position", val );
1831 msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
1836 msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
1841 #undef POSITION_ABSOLUTE
1842 #undef POSITION_REL_FOR
1843 #undef POSITION_REL_BACK
1844 #undef VL_TIME_ABSOLUTE
1845 #undef VL_TIME_REL_FOR
1846 #undef VL_TIME_REL_BACK
1852 audio_volume_t i_volume;
1855 uri_extract_value( p_request, "value", vol, 8 );
1856 aout_VolumeGet( p_intf, &i_volume );
1857 uri_decode_url_encoded( vol );
1861 i_value = atoi( vol + 1 );
1862 if( (i_volume + i_value) > AOUT_VOLUME_MAX )
1864 aout_VolumeSet( p_intf , AOUT_VOLUME_MAX );
1865 msg_Dbg( p_intf, "requested volume set: max" );
1868 aout_VolumeSet( p_intf , (i_volume + i_value) );
1869 msg_Dbg( p_intf, "requested volume set: +%i", (i_volume + i_value) );
1874 i_value = atoi( vol + 1 );
1875 if( (i_volume - i_value) < AOUT_VOLUME_MIN )
1877 aout_VolumeSet( p_intf , AOUT_VOLUME_MIN );
1878 msg_Dbg( p_intf, "requested volume set: min" );
1881 aout_VolumeSet( p_intf , (i_volume - i_value) );
1882 msg_Dbg( p_intf, "requested volume set: -%i", (i_volume - i_value) );
1885 if( strstr(vol, "%") != NULL )
1887 i_value = atoi( vol );
1888 if( (i_value <= 100) && (i_value>=0) ){
1889 aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/100+AOUT_VOLUME_MIN);
1890 msg_Dbg( p_intf, "requested volume set: %i%%", atoi( vol ));
1894 i_value = atoi( vol );
1895 if( ( i_value <= AOUT_VOLUME_MAX ) && ( i_value >= AOUT_VOLUME_MIN ) )
1897 aout_VolumeSet( p_intf , atoi( vol ) );
1898 msg_Dbg( p_intf, "requested volume set: %i", atoi( vol ) );
1904 /* playlist management */
1908 playlist_item_t * p_item;
1910 uri_extract_value( p_request, "mrl", mrl, 512 );
1911 uri_decode_url_encoded( mrl );
1912 p_item = parse_MRL( p_intf, mrl );
1914 if( !p_item || !p_item->input.psz_uri ||
1915 !*p_item->input.psz_uri )
1917 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
1920 playlist_AddItem( p_sys->p_playlist , p_item ,
1921 PLAYLIST_APPEND, PLAYLIST_END );
1922 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
1929 int i_item, *p_items = NULL, i_nb_items = 0;
1930 char item[512], *p_parser = p_request;
1932 /* Get the list of items to delete */
1934 uri_extract_value( p_parser, "item", item, 512 )) )
1936 if( !*item ) continue;
1938 i_item = atoi( item );
1939 p_items = realloc( p_items, (i_nb_items + 1) *
1941 p_items[i_nb_items] = i_item;
1948 for( i = 0; i < i_nb_items; i++ )
1950 playlist_LockDelete( p_sys->p_playlist, p_items[i] );
1951 msg_Dbg( p_intf, "requested playlist delete: %d",
1957 if( p_items ) free( p_items );
1962 int i_item, *p_items = NULL, i_nb_items = 0;
1963 char item[512], *p_parser = p_request;
1966 /* Get the list of items to keep */
1968 uri_extract_value( p_parser, "item", item, 512 )) )
1970 if( !*item ) continue;
1972 i_item = atoi( item );
1973 p_items = realloc( p_items, (i_nb_items + 1) *
1975 p_items[i_nb_items] = i_item;
1979 for( i = p_sys->p_playlist->i_size - 1 ; i >= 0; i-- )
1981 /* Check if the item is in the keep list */
1982 for( j = 0 ; j < i_nb_items ; j++ )
1985 p_sys->p_playlist->pp_items[i]->input.i_id ) break;
1987 if( j == i_nb_items )
1989 playlist_LockDelete( p_sys->p_playlist, p_sys->p_playlist->pp_items[i]->input.i_id );
1990 msg_Dbg( p_intf, "requested playlist delete: %d",
1995 if( p_items ) free( p_items );
2000 playlist_LockClear( p_sys->p_playlist );
2001 msg_Dbg( p_intf, "requested playlist empty" );
2012 uri_extract_value( p_request, "type", type, 12 );
2013 uri_extract_value( p_request, "order", order, 2 );
2014 uri_extract_value( p_request, "item", item, 512 );
2015 i_item = atoi( item );
2017 if( order[0] == '0' ) i_order = ORDER_NORMAL;
2018 else i_order = ORDER_REVERSE;
2020 if( !strcmp( type , "title" ) )
2022 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2023 p_sys->p_playlist->pp_views[0]->p_root,
2024 SORT_TITLE_NODES_FIRST,
2025 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2026 msg_Dbg( p_intf, "requested playlist sort by title (%d)" , i_order );
2027 } else if( !strcmp( type , "author" ) )
2029 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2030 p_sys->p_playlist->pp_views[0]->p_root,
2032 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2033 msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
2034 } else if( !strcmp( type , "shuffle" ) )
2036 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2037 p_sys->p_playlist->pp_views[0]->p_root,
2039 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2040 msg_Dbg( p_intf, "requested playlist shuffle");
2051 uri_extract_value( p_request, "psz_pos", psz_pos, 6 );
2052 uri_extract_value( p_request, "psz_newpos", psz_newpos, 6 );
2053 i_pos = atoi( psz_pos );
2054 i_newpos = atoi( psz_newpos );
2055 if ( i_pos < i_newpos )
2057 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
2059 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
2061 msg_Dbg( p_intf, "requested move playlist item %d to %d", i_pos, i_newpos);
2065 /* admin function */
2069 uri_extract_value( p_request, "id", id, 512 );
2070 msg_Dbg( p_intf, "requested close id=%s", id );
2072 if( p_sys->p_httpd->pf_control( p_sys->p_httpd, HTTPD_SET_CLOSE, id, NULL ) )
2074 msg_Warn( p_intf, "close failed for id=%s", id );
2081 msg_Dbg( p_intf, "requested shutdown" );
2082 p_intf->p_vlc->b_die = VLC_TRUE;
2087 case MVLC_VLM_SETUP:
2089 static const char *vlm_properties[11] =
2092 "enabled", "disabled", "loop", "unloop",
2094 "input", "output", "option", "date", "period", "repeat", "append",
2096 vlm_message_t *vlm_answer;
2098 char *psz = malloc( strlen( p_request ) + 1000 );
2103 if( p_intf->p_sys->p_vlm == NULL )
2104 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2106 if( p_intf->p_sys->p_vlm == NULL ) break;
2108 uri_extract_value( p_request, "name", name, 512 );
2109 if( StrToMacroType( control ) == MVLC_VLM_NEW )
2112 uri_extract_value( p_request, "type", type, 20 );
2113 p += sprintf( psz, "new %s %s", name, type );
2117 p += sprintf( psz, "setup %s", name );
2119 /* Parse the request */
2120 for( i = 0; i < 11; i++ )
2123 uri_extract_value( p_request, vlm_properties[i], val, 512 );
2124 uri_decode_url_encoded( val );
2125 if( strlen( val ) > 0 && i >= 4 )
2127 p += sprintf( p, " %s %s", vlm_properties[i], val );
2129 else if( uri_test_param( p_request, vlm_properties[i] ) && i < 4 )
2131 p += sprintf( p, " %s", vlm_properties[i] );
2134 fprintf( stderr, "vlm_ExecuteCommand: %s\n", psz );
2135 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2136 if( vlm_answer->psz_value == NULL ) /* there is no error */
2138 vlm_error = strdup( "" );
2142 vlm_error = malloc( strlen(vlm_answer->psz_name) +
2143 strlen(vlm_answer->psz_value) +
2144 strlen( " : ") + 1 );
2145 sprintf( vlm_error , "%s : %s" , vlm_answer->psz_name,
2146 vlm_answer->psz_value );
2149 mvar_AppendNewVar( p_args->vars, "vlm_error", vlm_error );
2151 vlm_MessageDelete( vlm_answer );
2159 vlm_message_t *vlm_answer;
2162 if( p_intf->p_sys->p_vlm == NULL )
2163 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2165 if( p_intf->p_sys->p_vlm == NULL ) break;
2167 uri_extract_value( p_request, "name", name, 512 );
2168 sprintf( psz, "del %s", name );
2170 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2171 /* FIXME do a vlm_answer -> var stack conversion */
2172 vlm_MessageDelete( vlm_answer );
2177 case MVLC_VLM_PAUSE:
2181 vlm_message_t *vlm_answer;
2184 if( p_intf->p_sys->p_vlm == NULL )
2185 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2187 if( p_intf->p_sys->p_vlm == NULL ) break;
2189 uri_extract_value( p_request, "name", name, 512 );
2190 if( StrToMacroType( control ) == MVLC_VLM_PLAY )
2191 sprintf( psz, "control %s play", name );
2192 else if( StrToMacroType( control ) == MVLC_VLM_PAUSE )
2193 sprintf( psz, "control %s pause", name );
2194 else if( StrToMacroType( control ) == MVLC_VLM_STOP )
2195 sprintf( psz, "control %s stop", name );
2196 else if( StrToMacroType( control ) == MVLC_VLM_SEEK )
2199 uri_extract_value( p_request, "percent", percent, 512 );
2200 sprintf( psz, "control %s seek %s", name, percent );
2203 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2204 /* FIXME do a vlm_answer -> var stack conversion */
2205 vlm_MessageDelete( vlm_answer );
2211 vlm_message_t *vlm_answer;
2215 if( p_intf->p_sys->p_vlm == NULL )
2216 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2218 if( p_intf->p_sys->p_vlm == NULL ) break;
2220 uri_extract_value( p_request, "file", file, 512 );
2221 uri_decode_url_encoded( file );
2223 if( StrToMacroType( control ) == MVLC_VLM_LOAD )
2224 sprintf( psz, "load %s", file );
2226 sprintf( psz, "save %s", file );
2228 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2229 /* FIXME do a vlm_answer -> var stack conversion */
2230 vlm_MessageDelete( vlm_answer );
2237 PRINTS( "<!-- control param(%s) unsuported -->", control );
2249 if( i_request <= 0 ||
2250 *m->param1 == '\0' ||
2251 strstr( p_request, m->param1 ) == NULL )
2255 uri_extract_value( p_request, m->param1, value, 512 );
2256 uri_decode_url_encoded( value );
2258 switch( StrToMacroType( m->param2 ) )
2262 config_PutInt( p_intf, m->param1, i );
2266 config_PutFloat( p_intf, m->param1, f );
2269 config_PutPsz( p_intf, m->param1, value );
2272 PRINTS( "<!-- invalid type(%s) in set -->", m->param2 )
2283 if( *m->param1 == '\0' )
2288 switch( StrToMacroType( m->param2 ) )
2291 i = config_GetInt( p_intf, m->param1 );
2292 sprintf( value, "%i", i );
2295 f = config_GetFloat( p_intf, m->param1 );
2296 sprintf( value, "%f", f );
2299 psz = config_GetPsz( p_intf, m->param1 );
2300 sprintf( value, "%s", psz ? psz : "" );
2301 if( psz ) free( psz );
2304 sprintf( value, "invalid type(%s) in set", m->param2 );
2307 msg_Dbg( p_intf, "get name=%s value=%s type=%s", m->param1, value, m->param2 );
2308 PRINTS( "%s", value );
2317 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2318 s = SSPop( &p_args->stack );
2319 v = mvar_GetValue( p_args->vars, s );
2323 v = s = SSPop( &p_args->stack );
2331 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2334 /* Usefull for learning stack management */
2338 msg_Dbg( p_intf, "stack" );
2339 for (i=0;i<(&p_args->stack)->i_stack;i++)
2340 msg_Dbg( p_intf, "%d -> %s", i, (&p_args->stack)->stack[i] );
2346 PRINTS( "<!-- invalid macro id=`%s' -->", m->id );
2347 msg_Dbg( p_intf, "invalid macro id=`%s'", m->id );
2355 static uint8_t *MacroSearch( uint8_t *src, uint8_t *end, int i_mvlc, vlc_bool_t b_after )
2362 if( src + 4 < end && !strncmp( src, "<vlc", 4 ) )
2367 i_skip = MacroParse( &m, src );
2369 i_id = StrToMacroType( m.id );
2386 if( ( i_mvlc == MVLC_END && i_level == -1 ) ||
2387 ( i_mvlc != MVLC_END && i_level == 0 && i_mvlc == i_id ) )
2389 return src + ( b_after ? i_skip : 0 );
2391 else if( i_level < 0 )
2407 static void Execute( httpd_file_sys_t *p_args,
2408 uint8_t *p_request, int i_request,
2409 uint8_t **pp_data, int *pi_data,
2411 uint8_t *_src, uint8_t *_end )
2413 intf_thread_t *p_intf = p_args->p_intf;
2415 uint8_t *src, *dup, *end;
2416 uint8_t *dst = *pp_dst;
2418 src = dup = malloc( _end - _src + 1 );
2419 end = src +( _end - _src );
2421 memcpy( src, _src, _end - _src );
2424 /* we parse searching <vlc */
2430 p = strstr( src, "<vlc" );
2431 if( p < end && p == src )
2435 src += MacroParse( &m, src );
2437 //msg_Dbg( p_intf, "macro_id=%s", m.id );
2439 switch( StrToMacroType( m.id ) )
2446 EvaluateRPN( p_args->vars, &p_args->stack, m.param1 );
2447 if( SSPopN( &p_args->stack, p_args->vars ) )
2455 endif = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2459 uint8_t *start = MacroSearch( src, endif, MVLC_ELSE, VLC_TRUE );
2463 uint8_t *stop = MacroSearch( start, endif, MVLC_END, VLC_FALSE );
2466 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2470 else if( i_test == 1 )
2473 if( ( stop = MacroSearch( src, endif, MVLC_ELSE, VLC_FALSE ) ) == NULL )
2475 stop = MacroSearch( src, endif, MVLC_END, VLC_FALSE );
2479 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, src, stop );
2488 uint8_t *endfor = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2489 uint8_t *start = src;
2490 uint8_t *stop = MacroSearch( src, end, MVLC_END, VLC_FALSE );
2497 if( !strcmp( m.param2, "integer" ) )
2499 char *arg = SSPop( &p_args->stack );
2500 index = mvar_IntegerSetNew( m.param1, arg );
2503 else if( !strcmp( m.param2, "directory" ) )
2505 char *arg = SSPop( &p_args->stack );
2506 index = mvar_FileSetNew( m.param1, arg );
2509 else if( !strcmp( m.param2, "playlist" ) )
2511 index = mvar_PlaylistSetNew( m.param1, p_intf->p_sys->p_playlist );
2513 else if( !strcmp( m.param2, "information" ) )
2515 index = mvar_InfoSetNew( m.param1, p_intf->p_sys->p_input );
2517 else if( !strcmp( m.param2, "vlm" ) )
2519 if( p_intf->p_sys->p_vlm == NULL )
2520 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2521 index = mvar_VlmSetNew( m.param1, p_intf->p_sys->p_vlm );
2524 else if( !strcmp( m.param2, "hosts" ) )
2526 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_HOSTS );
2528 else if( !strcmp( m.param2, "urls" ) )
2530 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_URLS );
2532 else if( !strcmp( m.param2, "connections" ) )
2534 index = mvar_HttpdInfoSetNew(m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_CONNECTIONS);
2537 else if( ( v = mvar_GetVar( p_args->vars, m.param2 ) ) )
2539 index = mvar_Duplicate( v );
2543 msg_Dbg( p_intf, "invalid index constructor (%s)", m.param2 );
2548 for( i_idx = 0; i_idx < index->i_field; i_idx++ )
2550 mvar_t *f = mvar_Duplicate( index->field[i_idx] );
2552 //msg_Dbg( p_intf, "foreach field[%d] name=%s value=%s", i_idx, f->name, f->value );
2555 f->name = strdup( m.param1 );
2558 mvar_PushVar( p_args->vars, f );
2559 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2560 mvar_RemoveVar( p_args->vars, f );
2564 mvar_Delete( index );
2571 MacroDo( p_args, &m, p_request, i_request, pp_data, pi_data, &dst );
2579 i_copy = ( (p == NULL || p > end ) ? end : p ) - src;
2582 int i_index = dst - *pp_data;
2585 *pp_data = realloc( *pp_data, *pi_data );
2586 dst = (*pp_data) + i_index;
2588 memcpy( dst, src, i_copy );
2598 /****************************************************************************
2600 ****************************************************************************
2601 * a file with b_html is parsed and all "macro" replaced
2602 * <vlc id="macro name" [param1="" [param2=""]] />
2605 ****************************************************************************/
2606 static int HttpCallback( httpd_file_sys_t *p_args,
2607 httpd_file_t *p_file,
2609 uint8_t **pp_data, int *pi_data )
2611 int i_request = p_request ? strlen( p_request ) : 0;
2615 if( ( f = fopen( p_args->file, "r" ) ) == NULL )
2617 p = *pp_data = malloc( 10240 );
2620 return VLC_EGENERIC;
2622 p += sprintf( p, "<html>\n" );
2623 p += sprintf( p, "<head>\n" );
2624 p += sprintf( p, "<title>Error loading %s</title>\n", p_args->file );
2625 p += sprintf( p, "</head>\n" );
2626 p += sprintf( p, "<body>\n" );
2627 p += sprintf( p, "<h1><center>Error loading %s for %s</center></h1>\n", p_args->file, p_args->name );
2628 p += sprintf( p, "<hr />\n" );
2629 p += sprintf( p, "<a href=\"http://www.videolan.org/\">VideoLAN</a>\n" );
2630 p += sprintf( p, "</body>\n" );
2631 p += sprintf( p, "</html>\n" );
2633 *pi_data = strlen( *pp_data );
2638 if( !p_args->b_html )
2640 FileLoad( f, pp_data, pi_data );
2648 char position[4]; /* percentage */
2649 char time[12]; /* in seconds */
2650 char length[12]; /* in seconds */
2651 audio_volume_t i_volume;
2655 #define p_sys p_args->p_intf->p_sys
2656 if( p_sys->p_input )
2658 var_Get( p_sys->p_input, "position", &val);
2659 sprintf( position, "%d" , (int)((val.f_float) * 100.0));
2660 var_Get( p_sys->p_input, "time", &val);
2661 sprintf( time, "%d" , (int)(val.i_time / 1000000) );
2662 var_Get( p_sys->p_input, "length", &val);
2663 sprintf( length, "%d" , (int)(val.i_time / 1000000) );
2665 var_Get( p_sys->p_input, "state", &val );
2666 if( val.i_int == PLAYING_S )
2668 sprintf( state, "playing" );
2669 } else if( val.i_int == PAUSE_S )
2671 sprintf( state, "paused" );
2674 sprintf( state, "stop" );
2678 sprintf( position, "%d", 0 );
2679 sprintf( time, "%d", 0 );
2680 sprintf( length, "%d", 0 );
2681 sprintf( state, "stop" );
2685 aout_VolumeGet( p_args->p_intf , &i_volume );
2686 sprintf( volume , "%d" , (int)i_volume );
2688 p_args->vars = mvar_New( "variables", "" );
2689 mvar_AppendNewVar( p_args->vars, "url_param", i_request > 0 ? "1" : "0" );
2690 mvar_AppendNewVar( p_args->vars, "url_value", p_request );
2691 mvar_AppendNewVar( p_args->vars, "version", VERSION_MESSAGE );
2692 mvar_AppendNewVar( p_args->vars, "copyright", COPYRIGHT_MESSAGE );
2693 mvar_AppendNewVar( p_args->vars, "stream_position", position );
2694 mvar_AppendNewVar( p_args->vars, "stream_time", time );
2695 mvar_AppendNewVar( p_args->vars, "stream_length", length );
2696 mvar_AppendNewVar( p_args->vars, "volume", volume );
2697 mvar_AppendNewVar( p_args->vars, "stream_state", state );
2699 SSInit( &p_args->stack );
2701 /* first we load in a temporary buffer */
2702 FileLoad( f, &p_buffer, &i_buffer );
2704 /* allocate output */
2705 *pi_data = i_buffer + 1000;
2706 dst = *pp_data = malloc( *pi_data );
2708 /* we parse executing all <vlc /> macros */
2709 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, &p_buffer[0], &p_buffer[i_buffer] );
2712 *pi_data = dst - *pp_data;
2714 SSClean( &p_args->stack );
2715 mvar_Delete( p_args->vars );
2724 /****************************************************************************
2726 ****************************************************************************/
2727 static int uri_test_param( char *psz_uri, const char *psz_name )
2731 while( (p = strstr( p, psz_name )) )
2733 /* Verify that we are dealing with a post/get argument */
2734 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2743 static char *uri_extract_value( char *psz_uri, const char *psz_name,
2744 char *psz_value, int i_value_max )
2748 while( (p = strstr( p, psz_name )) )
2750 /* Verify that we are dealing with a post/get argument */
2751 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2760 p += strlen( psz_name );
2761 if( *p == '=' ) p++;
2763 if( strchr( p, '&' ) )
2765 i_len = strchr( p, '&' ) - p;
2769 /* for POST method */
2770 if( strchr( p, '\n' ) )
2772 i_len = strchr( p, '\n' ) - p;
2773 if( i_len && *(p+i_len-1) == '\r' ) i_len--;
2777 i_len = strlen( p );
2780 i_len = __MIN( i_value_max - 1, i_len );
2783 strncpy( psz_value, p, i_len );
2784 psz_value[i_len] = '\0';
2788 strncpy( psz_value, "", i_value_max );
2794 strncpy( psz_value, "", i_value_max );
2800 static void uri_decode_url_encoded( char *psz )
2802 char *dup = strdup( psz );
2820 *psz++ = strtol( val, NULL, 16 );
2822 else if( *p == '+' )
2836 /****************************************************************************
2837 * Light RPN evaluator
2838 ****************************************************************************/
2839 static void SSInit( rpn_stack_t *st )
2844 static void SSClean( rpn_stack_t *st )
2846 while( st->i_stack > 0 )
2848 free( st->stack[--st->i_stack] );
2852 static void SSPush( rpn_stack_t *st, char *s )
2854 if( st->i_stack < STACK_MAX )
2856 st->stack[st->i_stack++] = strdup( s );
2860 static char * SSPop( rpn_stack_t *st )
2862 if( st->i_stack <= 0 )
2864 return strdup( "" );
2868 return st->stack[--st->i_stack];
2872 static int SSPopN( rpn_stack_t *st, mvar_t *vars )
2881 i = strtol( name, &end, 0 );
2884 value = mvar_GetValue( vars, name );
2892 static void SSPushN( rpn_stack_t *st, int i )
2896 sprintf( v, "%d", i );
2900 static void EvaluateRPN( mvar_t *vars, rpn_stack_t *st, char *exp )
2907 while( *exp == ' ' )
2914 /* extract string */
2917 while( *exp && *exp != '\'' )
2928 p = strchr( exp, ' ' );
2933 exp += strlen( exp );
2938 strncpy( s, exp, i );
2949 /* 1. Integer function */
2950 if( !strcmp( s, "!" ) )
2952 SSPushN( st, ~SSPopN( st, vars ) );
2954 else if( !strcmp( s, "^" ) )
2956 SSPushN( st, SSPopN( st, vars ) ^ SSPopN( st, vars ) );
2958 else if( !strcmp( s, "&" ) )
2960 SSPushN( st, SSPopN( st, vars ) & SSPopN( st, vars ) );
2962 else if( !strcmp( s, "|" ) )
2964 SSPushN( st, SSPopN( st, vars ) | SSPopN( st, vars ) );
2966 else if( !strcmp( s, "+" ) )
2968 SSPushN( st, SSPopN( st, vars ) + SSPopN( st, vars ) );
2970 else if( !strcmp( s, "-" ) )
2972 int j = SSPopN( st, vars );
2973 int i = SSPopN( st, vars );
2974 SSPushN( st, i - j );
2976 else if( !strcmp( s, "*" ) )
2978 SSPushN( st, SSPopN( st, vars ) * SSPopN( st, vars ) );
2980 else if( !strcmp( s, "/" ) )
2984 j = SSPopN( st, vars );
2985 i = SSPopN( st, vars );
2987 SSPushN( st, j != 0 ? i / j : 0 );
2989 else if( !strcmp( s, "%" ) )
2993 j = SSPopN( st, vars );
2994 i = SSPopN( st, vars );
2996 SSPushN( st, j != 0 ? i % j : 0 );
2998 /* 2. integer tests */
2999 else if( !strcmp( s, "=" ) )
3001 SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 );
3003 else if( !strcmp( s, "!=" ) )
3005 SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 );
3007 else if( !strcmp( s, "<" ) )
3009 int j = SSPopN( st, vars );
3010 int i = SSPopN( st, vars );
3012 SSPushN( st, i < j ? -1 : 0 );
3014 else if( !strcmp( s, ">" ) )
3016 int j = SSPopN( st, vars );
3017 int i = SSPopN( st, vars );
3019 SSPushN( st, i > j ? -1 : 0 );
3021 else if( !strcmp( s, "<=" ) )
3023 int j = SSPopN( st, vars );
3024 int i = SSPopN( st, vars );
3026 SSPushN( st, i <= j ? -1 : 0 );
3028 else if( !strcmp( s, ">=" ) )
3030 int j = SSPopN( st, vars );
3031 int i = SSPopN( st, vars );
3033 SSPushN( st, i >= j ? -1 : 0 );
3035 /* 3. string functions */
3036 else if( !strcmp( s, "strcat" ) )
3038 char *s2 = SSPop( st );
3039 char *s1 = SSPop( st );
3040 char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
3050 else if( !strcmp( s, "strcmp" ) )
3052 char *s2 = SSPop( st );
3053 char *s1 = SSPop( st );
3055 SSPushN( st, strcmp( s1, s2 ) );
3059 else if( !strcmp( s, "strncmp" ) )
3061 int n = SSPopN( st, vars );
3062 char *s2 = SSPop( st );
3063 char *s1 = SSPop( st );
3065 SSPushN( st, strncmp( s1, s2 , n ) );
3069 else if( !strcmp( s, "strsub" ) )
3071 int n = SSPopN( st, vars );
3072 int m = SSPopN( st, vars );
3074 char *s = SSPop( st );
3086 str = malloc( i_len + 1 );
3088 memcpy( str, s + m - 1, i_len );
3089 str[ i_len ] = '\0';
3095 else if( !strcmp( s, "strlen" ) )
3097 char *str = SSPop( st );
3099 SSPushN( st, strlen( str ) );
3102 /* 4. stack functions */
3103 else if( !strcmp( s, "dup" ) )
3105 char *str = SSPop( st );
3110 else if( !strcmp( s, "drop" ) )
3112 char *str = SSPop( st );
3115 else if( !strcmp( s, "swap" ) )
3117 char *s1 = SSPop( st );
3118 char *s2 = SSPop( st );
3125 else if( !strcmp( s, "flush" ) )
3130 else if( !strcmp( s, "store" ) )
3132 char *value = SSPop( st );
3133 char *name = SSPop( st );
3135 mvar_PushNewVar( vars, name, value );
3139 else if( !strcmp( s, "value" ) )
3141 char *name = SSPop( st );
3142 char *value = mvar_GetValue( vars, name );
3144 SSPush( st, value );
3148 else if( !strcmp( s, "url_extract" ) )
3150 char *url = mvar_GetValue( vars, "url_value" );
3151 char *name = SSPop( st );
3154 uri_extract_value( url, name, value, 512 );
3155 uri_decode_url_encoded( value );
3156 SSPush( st, value );
3165 /**********************************************************************
3166 * Find_end_MRL: Find the end of the sentence :
3167 * this function parses the string psz and find the end of the item
3168 * and/or option with detecting the " and ' problems.
3169 * returns NULL if an error is detected, otherwise, returns a pointer
3170 * of the end of the sentence (after the last character)
3171 **********************************************************************/
3172 static char *Find_end_MRL( char *psz )
3182 while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) )
3184 if( *s_sent == '\'' )
3186 s_sent = Find_end_MRL( s_sent );
3188 if( s_sent == NULL )
3198 if( *s_sent == '\"' )
3202 } else /* *s_sent == '\0' , which means the number of " is incorrect */
3212 while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) )
3214 if( *s_sent == '\"' )
3216 s_sent = Find_end_MRL( s_sent );
3218 if( s_sent == NULL )
3228 if( *s_sent == '\'' )
3232 } else /* *s_sent == '\0' , which means the number of ' is incorrect */
3238 default: /* now we can look for spaces */
3240 while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) )
3242 if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) )
3244 s_sent = Find_end_MRL( s_sent );
3255 /**********************************************************************
3256 * parse_MRL: parse the MRL, find the mrl string and the options,
3257 * create an item with all information in it, and return the item.
3258 * return NULL if there is an error.
3259 **********************************************************************/
3260 playlist_item_t * parse_MRL( intf_thread_t *p_intf, char *psz )
3262 char **ppsz_options = NULL;
3269 playlist_item_t * p_item = NULL;
3271 /* In case there is spaces before the mrl */
3272 while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
3277 /* extract the mrl */
3278 s_temp = strstr( s_mrl , " :" );
3279 if( s_temp == NULL )
3281 s_temp = s_mrl + strlen( s_mrl );
3284 while( (*s_temp == ' ') && (s_temp != s_mrl ) )
3291 /* if the mrl is between " or ', we must remove them */
3292 if( (*s_mrl == '\'') || (*s_mrl == '\"') )
3294 mrl = (char *)malloc( (s_temp - s_mrl - 1) * sizeof( char ) );
3295 strncpy( mrl , (s_mrl + 1) , s_temp - s_mrl - 2 );
3296 mrl[ s_temp - s_mrl - 2 ] = '\0';
3299 mrl = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) );
3300 strncpy( mrl , s_mrl , s_temp - s_mrl );
3301 mrl[ s_temp - s_mrl ] = '\0';
3306 /* now we can take care of the options */
3307 while( (*s_mrl != '\0') && (i_error == 0) )
3316 case ':': /* an option */
3318 s_temp = Find_end_MRL( s_mrl );
3320 if( s_temp == NULL )
3327 ppsz_options = realloc( ppsz_options , i_options *
3329 ppsz_options[ i_options - 1 ] =
3330 malloc( (s_temp - s_mrl + 1) * sizeof(char) );
3332 strncpy( ppsz_options[ i_options - 1 ] , s_mrl ,
3335 /* don't forget to finish the string with a '\0' */
3336 (ppsz_options[ i_options - 1 ])[ s_temp - s_mrl ] = '\0';
3356 /* now create an item */
3357 p_item = playlist_ItemNew( p_intf, mrl, mrl);
3358 for( i = 0 ; i< i_options ; i++ )
3360 playlist_ItemAddOption( p_item, ppsz_options[i] );
3364 for( i = 0 ; i < i_options ; i++ )
3366 free( ppsz_options[i] );
3368 free( ppsz_options );