1 /*****************************************************************************
2 * http.c : http mini-server ;)
3 *****************************************************************************
4 * Copyright (C) 2001-2005 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"
45 #ifdef HAVE_SYS_STAT_H
46 # include <sys/stat.h>
57 #elif defined( WIN32 ) && !defined( UNDER_CE )
65 /* stat() support for large files on win32 */
66 #if defined( WIN32 ) && !defined( UNDER_CE )
67 # define stat _stati64
70 /*****************************************************************************
72 *****************************************************************************/
73 static int Open ( vlc_object_t * );
74 static void Close( vlc_object_t * );
76 #define HOST_TEXT N_( "Host address" )
77 #define HOST_LONGTEXT N_( \
78 "You can set the address and port the http interface will bind to." )
79 #define SRC_TEXT N_( "Source directory" )
80 #define SRC_LONGTEXT N_( "Source directory" )
81 #define CERT_TEXT N_( "Certificate file" )
82 #define CERT_LONGTEXT N_( "HTTP interface x509 PEM certificate file " \
84 #define KEY_TEXT N_( "Private key file" )
85 #define KEY_LONGTEXT N_( "HTTP interface x509 PEM private key file" )
86 #define CA_TEXT N_( "Root CA file" )
87 #define CA_LONGTEXT N_( "HTTP interface x509 PEM trusted root CA " \
89 #define CRL_TEXT N_( "CRL file" )
90 #define CRL_LONGTEXT N_( "HTTP interace Certificates Revocation List file" )
93 set_shortname( _("HTTP"));
94 set_description( _("HTTP remote control interface") );
95 set_category( CAT_INTERFACE );
96 set_subcategory( SUBCAT_INTERFACE_GENERAL );
97 add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
98 add_string ( "http-src", NULL, NULL, SRC_TEXT, SRC_LONGTEXT, VLC_TRUE );
99 set_section( N_("HTTP SSL" ), 0 );
100 add_string ( "http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT, VLC_TRUE );
101 add_string ( "http-intf-key", NULL, NULL, KEY_TEXT, KEY_LONGTEXT, VLC_TRUE );
102 add_string ( "http-intf-ca", NULL, NULL, CA_TEXT, CA_LONGTEXT, VLC_TRUE );
103 add_string ( "http-intf-crl", NULL, NULL, CRL_TEXT, CRL_LONGTEXT, VLC_TRUE );
104 set_capability( "interface", 0 );
105 set_callbacks( Open, Close );
109 /*****************************************************************************
111 *****************************************************************************/
112 static void Run ( intf_thread_t *p_intf );
114 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
117 static int DirectoryCheck( char *psz_dir )
121 #ifdef HAVE_SYS_STAT_H
122 struct stat stat_info;
124 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
130 if( ( p_dir = opendir( psz_dir ) ) == NULL )
139 static int HttpCallback( httpd_file_sys_t *p_args,
142 uint8_t **pp_data, int *pi_data );
144 static char *uri_extract_value( char *psz_uri, const char *psz_name,
145 char *psz_value, int i_value_max );
146 static int uri_test_param( char *psz_uri, const char *psz_name );
148 static void uri_decode_url_encoded( char *psz );
150 static char *Find_end_MRL( char *psz );
151 static playlist_item_t *parse_MRL( intf_thread_t * , char *psz );
153 /*****************************************************************************
155 *****************************************************************************/
156 typedef struct mvar_s
162 struct mvar_s **field;
165 #define STACK_MAX 100
168 char *stack[STACK_MAX];
172 struct httpd_file_sys_t
174 intf_thread_t *p_intf;
175 httpd_file_t *p_file;
176 httpd_redirect_t *p_redir;
177 httpd_redirect_t *p_redir2;
184 /* inited for each access */
191 httpd_host_t *p_httpd_host;
194 httpd_file_sys_t **pp_files;
196 playlist_t *p_playlist;
197 input_thread_t *p_input;
204 /*****************************************************************************
205 * Activate: initialize and create stuff
206 *****************************************************************************/
207 static int Open( vlc_object_t *p_this )
209 intf_thread_t *p_intf = (intf_thread_t*)p_this;
212 char *psz_address = "";
213 const char *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL,
218 psz_host = config_GetPsz( p_intf, "http-host" );
222 psz_address = psz_host;
224 psz_parser = strchr( psz_host, ':' );
227 *psz_parser++ = '\0';
228 i_port = atoi( psz_parser );
232 p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
235 return( VLC_ENOMEM );
237 p_sys->p_playlist = NULL;
238 p_sys->p_input = NULL;
241 /* determine Content-Type value for HTML pages */
242 vlc_current_charset(&psz_src);
243 if( psz_src == NULL )
248 p_sys->psz_html_type = malloc( 20 + strlen( psz_src ) );
249 if( p_sys->psz_html_type == NULL )
255 sprintf( p_sys->psz_html_type, "text/html; charset=%s", psz_src );
258 /* determine SSL configuration */
259 psz_cert = config_GetPsz( p_intf, "http-intf-cert" );
260 if ( psz_cert != NULL )
262 msg_Dbg( p_intf, "enablind TLS for HTTP interface (cert file: %s)",
264 psz_key = config_GetPsz( p_intf, "http-intf-key" );
265 psz_ca = config_GetPsz( p_intf, "http-intf-ca" );
266 psz_crl = config_GetPsz( p_intf, "http-intf-crl" );
277 msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
279 p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
280 i_port, psz_cert, psz_key, psz_ca,
282 if( p_sys->p_httpd_host == NULL )
284 msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
285 free( p_sys->psz_html_type );
296 p_sys->pp_files = NULL;
298 #if defined(SYS_DARWIN) || defined(SYS_BEOS) || defined(WIN32)
299 if ( ( psz_src = config_GetPsz( p_intf, "http-src" )) == NULL )
301 char * psz_vlcpath = p_intf->p_libvlc->psz_vlcpath;
302 psz_src = malloc( strlen(psz_vlcpath) + strlen("/share/http" ) + 1 );
303 if( !psz_src ) return VLC_ENOMEM;
305 sprintf( psz_src, "%s/http", psz_vlcpath);
307 sprintf( psz_src, "%s/share/http", psz_vlcpath);
311 psz_src = config_GetPsz( p_intf, "http-src" );
313 if( !psz_src || *psz_src == '\0' )
315 if( !DirectoryCheck( "share/http" ) )
317 psz_src = strdup( "share/http" );
319 else if( !DirectoryCheck( DATA_PATH "/http" ) )
321 psz_src = strdup( DATA_PATH "/http" );
326 if( !psz_src || *psz_src == '\0' )
328 msg_Err( p_intf, "invalid src dir" );
332 /* remove trainling \ or / */
333 if( psz_src[strlen( psz_src ) - 1] == '\\' ||
334 psz_src[strlen( psz_src ) - 1] == '/' )
336 psz_src[strlen( psz_src ) - 1] = '\0';
339 ParseDirectory( p_intf, psz_src, psz_src );
342 if( p_sys->i_files <= 0 )
344 msg_Err( p_intf, "cannot find any files (%s)", psz_src );
347 p_intf->pf_run = Run;
353 if( psz_src ) free( psz_src );
354 if( p_sys->pp_files )
356 free( p_sys->pp_files );
358 httpd_HostDelete( p_sys->p_httpd_host );
359 free( p_sys->psz_html_type );
364 /*****************************************************************************
365 * CloseIntf: destroy interface
366 *****************************************************************************/
367 void Close ( vlc_object_t *p_this )
369 intf_thread_t *p_intf = (intf_thread_t *)p_this;
370 intf_sys_t *p_sys = p_intf->p_sys;
376 vlm_Delete( p_sys->p_vlm );
378 for( i = 0; i < p_sys->i_files; i++ )
380 httpd_FileDelete( p_sys->pp_files[i]->p_file );
381 if( p_sys->pp_files[i]->p_redir )
382 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir );
383 if( p_sys->pp_files[i]->p_redir2 )
384 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir2 );
386 free( p_sys->pp_files[i]->file );
387 free( p_sys->pp_files[i]->name );
388 free( p_sys->pp_files[i] );
390 if( p_sys->pp_files )
392 free( p_sys->pp_files );
394 httpd_HostDelete( p_sys->p_httpd_host );
396 free( p_sys->psz_html_type );
400 /*****************************************************************************
401 * Run: http interface thread
402 *****************************************************************************/
403 static void Run( intf_thread_t *p_intf )
405 intf_sys_t *p_sys = p_intf->p_sys;
407 while( !p_intf->b_die )
409 /* get the playlist */
410 if( p_sys->p_playlist == NULL )
412 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
415 /* Manage the input part */
416 if( p_sys->p_input == NULL )
418 if( p_sys->p_playlist )
421 vlc_object_find( p_sys->p_playlist,
426 else if( p_sys->p_input->b_dead )
428 vlc_object_release( p_sys->p_input );
429 p_sys->p_input = NULL;
434 msleep( INTF_IDLE_SLEEP );
439 vlc_object_release( p_sys->p_input );
440 p_sys->p_input = NULL;
443 if( p_sys->p_playlist )
445 vlc_object_release( p_sys->p_playlist );
446 p_sys->p_playlist = NULL;
451 /*****************************************************************************
453 *****************************************************************************/
454 #define MAX_DIR_SIZE 10240
456 /****************************************************************************
457 * FileToUrl: create a good name for an url from filename
458 ****************************************************************************/
459 static char *FileToUrl( char *name, vlc_bool_t *pb_index )
463 url = p = malloc( strlen( name ) + 1 );
471 while( *name == '\\' || *name == '/' )
473 while( *name == '/' )
483 /* convert '\\' into '/' */
495 *pb_index = VLC_FALSE;
497 if( ( p = strrchr( url, '/' ) ) != NULL )
499 if( !strncmp( p, "/index.", 7 ) )
502 *pb_index = VLC_TRUE;
508 /****************************************************************************
509 * ParseDirectory: parse recursively a directory, adding each file
510 ****************************************************************************/
511 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
514 intf_sys_t *p_sys = p_intf->p_sys;
515 char dir[MAX_DIR_SIZE];
516 #ifdef HAVE_SYS_STAT_H
517 struct stat stat_info;
520 struct dirent *p_dir_content;
524 char *password = NULL;
525 char **ppsz_hosts = 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 );
579 sprintf( dir, "%s/.hosts", psz_dir );
580 if( ( file = fopen( dir, "r" ) ) != NULL )
585 msg_Dbg( p_intf, "find .hosts in dir=%s", psz_dir );
587 while( !feof( file ) )
589 fgets( line, 1023, file );
590 i_size = strlen(line);
591 if( i_size > 0 && line[0] != '#' )
593 while( i_size > 0 && ( line[i_size-1] == '\n' ||
594 line[i_size-1] == '\r' ) )
598 if( !i_size ) continue;
602 msg_Dbg( p_intf, "restricted to %s (read=%d)",
604 TAB_APPEND( i_hosts, ppsz_hosts, strdup( line ) );
610 if( net_CheckIP( p_intf, "0.0.0.0", ppsz_hosts, i_hosts ) < 0 )
612 msg_Err( p_intf, ".hosts file is invalid in dir=%s", psz_dir );
618 /* parse psz_src dir */
619 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
624 if( p_dir_content->d_name[0] == '.' )
628 sprintf( dir, "%s/%s", psz_dir, p_dir_content->d_name );
629 if( ParseDirectory( p_intf, psz_root, dir ) )
631 httpd_file_sys_t *f = malloc( sizeof( httpd_file_sys_t ) );
638 f->file = strdup( dir );
639 f->name = FileToUrl( &dir[strlen( psz_root )], &b_index );
640 f->b_html = strstr( &dir[strlen( psz_root )], ".htm" ) ? VLC_TRUE : VLC_FALSE;
644 msg_Err( p_intf , "unable to parse directory" );
647 return( VLC_ENOMEM );
649 msg_Dbg( p_intf, "file=%s (url=%s)",
652 f->p_file = httpd_FileNew( p_sys->p_httpd_host,
654 f->b_html ? p_sys->psz_html_type : NULL,
655 user, password, ppsz_hosts, i_hosts,
660 TAB_APPEND( p_sys->i_files, p_sys->pp_files, f );
662 /* for url that ends by / add
663 * - a redirect from rep to rep/
664 * - in case of index.* rep/index.html to rep/ */
665 if( f && f->name[strlen(f->name) - 1] == '/' )
667 char *psz_redir = strdup( f->name );
669 psz_redir[strlen( psz_redir ) - 1] = '\0';
671 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
672 f->p_redir = httpd_RedirectNew( p_sys->p_httpd_host, f->name, psz_redir );
675 if( b_index && ( p = strstr( f->file, "index." ) ) )
677 asprintf( &psz_redir, "%s%s", f->name, p );
679 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
680 f->p_redir2 = httpd_RedirectNew( p_sys->p_httpd_host,
681 f->name, psz_redir );
697 for( i = 0; i < i_hosts; i++ )
699 TAB_REMOVE( i_hosts, ppsz_hosts, ppsz_hosts[0] );
707 /****************************************************************************
708 * var and set handling
709 ****************************************************************************/
711 static mvar_t *mvar_New( char *name, char *value )
713 mvar_t *v = malloc( sizeof( mvar_t ) );
715 if( !v ) return NULL;
716 v->name = strdup( name );
717 v->value = strdup( value ? value : "" );
720 v->field = malloc( sizeof( mvar_t * ) );
726 static void mvar_Delete( mvar_t *v )
733 for( i = 0; i < v->i_field; i++ )
735 mvar_Delete( v->field[i] );
741 static void mvar_AppendVar( mvar_t *v, mvar_t *f )
743 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
744 v->field[v->i_field] = f;
748 static mvar_t *mvar_Duplicate( mvar_t *v )
753 n = mvar_New( v->name, v->value );
754 for( i = 0; i < v->i_field; i++ )
756 mvar_AppendVar( n, mvar_Duplicate( v->field[i] ) );
762 static void mvar_PushVar( mvar_t *v, mvar_t *f )
764 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
767 memmove( &v->field[1], &v->field[0], sizeof( mvar_t * ) * v->i_field );
773 static void mvar_RemoveVar( mvar_t *v, mvar_t *f )
776 for( i = 0; i < v->i_field; i++ )
778 if( v->field[i] == f )
783 if( i >= v->i_field )
788 if( i + 1 < v->i_field )
790 memmove( &v->field[i], &v->field[i+1], sizeof( mvar_t * ) * ( v->i_field - i - 1 ) );
793 /* FIXME should do a realloc */
796 static mvar_t *mvar_GetVar( mvar_t *s, char *name )
799 char base[512], *field, *p;
802 /* format: name[index].field */
804 field = strchr( name, '.' );
807 int i = field - name;
808 strncpy( base, name, i );
814 strcpy( base, name );
817 if( ( p = strchr( base, '[' ) ) )
820 sscanf( p, "%d]", &i_index );
831 for( i = 0; i < s->i_field; i++ )
833 if( !strcmp( s->field[i]->name, base ) )
843 return mvar_GetVar( s->field[i], field );
857 static char *mvar_GetValue( mvar_t *v, char *field )
865 mvar_t *f = mvar_GetVar( v, field );
877 static void mvar_PushNewVar( mvar_t *vars, char *name, char *value )
879 mvar_t *f = mvar_New( name, value );
880 mvar_PushVar( vars, f );
883 static void mvar_AppendNewVar( mvar_t *vars, char *name, char *value )
885 mvar_t *f = mvar_New( name, value );
886 mvar_AppendVar( vars, f );
890 /* arg= start[:stop[:step]],.. */
891 static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
893 char *dup = strdup( arg );
895 mvar_t *s = mvar_New( name, "set" );
901 int i_start,i_stop,i_step;
904 p = strchr( str, ',' );
911 i_match = sscanf( str, "%d:%d:%d", &i_start, &i_stop, &i_step );
918 else if( i_match == 2 )
920 i_step = i_start < i_stop ? 1 : -1;
927 if( ( i_start <= i_stop && i_step > 0 ) ||
928 ( i_start >= i_stop && i_step < 0 ) )
930 for( i = i_start; ; i += i_step )
934 if( ( i_step > 0 && i > i_stop ) ||
935 ( i_step < 0 && i < i_stop ) )
940 sprintf( value, "%d", i );
942 mvar_PushNewVar( s, name, value );
953 void PlaylistListNode( playlist_t *p_pl, playlist_item_t *p_node,
954 char *name, mvar_t *s, int i_depth )
958 if (p_node->i_children == -1)
961 mvar_t *itm = mvar_New( name, "set" );
963 sprintf( value, "%d", ( p_pl->status.p_item == p_node )? 1 : 0 );
964 mvar_AppendNewVar( itm, "current", value );
966 sprintf( value, "%d", p_node->input.i_id );
967 mvar_AppendNewVar( itm, "index", value );
969 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
971 mvar_AppendNewVar( itm, "uri", p_node->input.psz_uri );
973 sprintf( value, "Item");
974 mvar_AppendNewVar( itm, "type", value );
976 sprintf( value, "%d", i_depth );
977 mvar_AppendNewVar( itm, "depth", value );
979 mvar_AppendVar( s, itm );
985 mvar_t *itm = mvar_New( name, "set" );
987 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
988 mvar_AppendNewVar( itm, "uri", p_node->input.psz_name );
990 sprintf( value, "Node" );
991 mvar_AppendNewVar( itm, "type", value );
993 sprintf( value, "%d", p_node->input.i_id );
994 mvar_AppendNewVar( itm, "index", value );
996 sprintf( value, "%d", p_node->i_children);
997 mvar_AppendNewVar( itm, "i_children", value );
999 sprintf( value, "%d", i_depth );
1000 mvar_AppendNewVar( itm, "depth", value );
1002 mvar_AppendVar( s, itm );
1004 for (i_child = 0 ; i_child < p_node->i_children ; i_child++)
1005 PlaylistListNode( p_pl, p_node->pp_children[i_child], name, s, i_depth + 1);
1011 static mvar_t *mvar_PlaylistSetNew( char *name, playlist_t *p_pl )
1013 playlist_view_t *p_view;
1014 mvar_t *s = mvar_New( name, "set" );
1017 vlc_mutex_lock( &p_pl->object_lock );
1019 p_view = playlist_ViewFind( p_pl, VIEW_CATEGORY ); /* FIXME */
1021 if( p_view != NULL )
1022 PlaylistListNode( p_pl, p_view->p_root, name, s, 0 );
1024 vlc_mutex_unlock( &p_pl->object_lock );
1029 static mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input )
1031 mvar_t *s = mvar_New( name, "set" );
1034 if( p_input == NULL )
1039 vlc_mutex_lock( &p_input->input.p_item->lock );
1040 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
1042 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1043 mvar_t *cat = mvar_New( name, "set" );
1044 mvar_t *iset = mvar_New( "info", "set" );
1046 mvar_AppendNewVar( cat, "name", p_category->psz_name );
1047 mvar_AppendVar( cat, iset );
1049 for ( j = 0; j < p_category->i_infos; j++ )
1051 info_t *p_info = p_category->pp_infos[j];
1052 mvar_t *info = mvar_New( "info", "" );
1054 msg_Dbg( p_input, "adding info name=%s value=%s",
1055 p_info->psz_name, p_info->psz_value );
1056 mvar_AppendNewVar( info, "name", p_info->psz_name );
1057 mvar_AppendNewVar( info, "value", p_info->psz_value );
1058 mvar_AppendVar( iset, info );
1060 mvar_AppendVar( s, cat );
1062 vlc_mutex_unlock( &p_input->input.p_item->lock );
1067 static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
1069 mvar_t *s = mvar_New( name, "set" );
1073 if( !p_httpd->pf_control( p_httpd, i_type, &info, NULL ) )
1075 for( i= 0; i < info.i_count; )
1079 inf = mvar_New( name, "set" );
1082 /* fprintf( stderr," mvar_HttpdInfoSetNew: append name=`%s' value=`%s'\n",
1083 info.info[i].psz_name, info.info[i].psz_value ); */
1084 mvar_AppendNewVar( inf,
1085 info.info[i].psz_name,
1086 info.info[i].psz_value );
1088 } while( i < info.i_count && strcmp( info.info[i].psz_name, "id" ) );
1089 mvar_AppendVar( s, inf );
1094 for( i = 0; i < info.i_count; i++ )
1096 free( info.info[i].psz_name );
1097 free( info.info[i].psz_value );
1099 if( info.i_count > 0 )
1108 static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
1110 mvar_t *s = mvar_New( name, "set" );
1111 char tmp[MAX_DIR_SIZE], *p, *src;
1112 #ifdef HAVE_SYS_STAT_H
1113 struct stat stat_info;
1116 struct dirent *p_dir_content;
1119 /* convert all / to native separator */
1120 #if defined( WIN32 )
1121 while( (p = strchr( psz_dir, '/' )) )
1130 /* remove trailling separator */
1131 while( strlen( psz_dir ) > 1 &&
1132 #if defined( WIN32 )
1133 !( strlen(psz_dir)==3 && psz_dir[1]==':' && psz_dir[2]==sep ) &&
1135 psz_dir[strlen( psz_dir ) -1 ] == sep )
1137 psz_dir[strlen( psz_dir ) -1 ] ='\0';
1139 /* remove double separator */
1140 for( p = src = psz_dir; *src != '\0'; src++, p++ )
1142 if( src[0] == sep && src[1] == sep )
1150 if( *psz_dir == '\0' )
1154 /* first fix all .. dir */
1158 if( src[0] == '.' && src[1] == '.' )
1161 if( p <= &psz_dir[1] )
1168 while( p > &psz_dir[1] && *p != sep )
1173 else if( *src == sep )
1175 if( p > psz_dir && p[-1] == sep )
1189 } while( *src && *src != sep );
1195 #ifdef HAVE_SYS_STAT_H
1196 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
1202 if( ( p_dir = opendir( psz_dir ) ) == NULL )
1204 fprintf( stderr, "cannot open dir (%s)", psz_dir );
1208 /* remove traling / or \ */
1209 for( p = &psz_dir[strlen( psz_dir) - 1];
1210 p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- )
1219 /* parse psz_src dir */
1220 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
1224 if( !strcmp( p_dir_content->d_name, "." ) )
1229 sprintf( tmp, "%s/%s", psz_dir, p_dir_content->d_name );
1231 #ifdef HAVE_SYS_STAT_H
1232 if( stat( tmp, &stat_info ) == -1 )
1237 f = mvar_New( name, "set" );
1238 mvar_AppendNewVar( f, "name", tmp );
1240 #ifdef HAVE_SYS_STAT_H
1241 if( S_ISDIR( stat_info.st_mode ) )
1243 mvar_AppendNewVar( f, "type", "directory" );
1245 else if( S_ISREG( stat_info.st_mode ) )
1247 mvar_AppendNewVar( f, "type", "file" );
1251 mvar_AppendNewVar( f, "type", "unknown" );
1254 sprintf( tmp, I64Fd, (int64_t)stat_info.st_size );
1255 mvar_AppendNewVar( f, "size", tmp );
1257 /* FIXME memory leak FIXME */
1259 ctime_r( &stat_info.st_mtime, tmp );
1260 mvar_AppendNewVar( f, "date", tmp );
1262 mvar_AppendNewVar( f, "date", ctime( &stat_info.st_mtime ) );
1266 mvar_AppendNewVar( f, "type", "unknown" );
1267 mvar_AppendNewVar( f, "size", "unknown" );
1268 mvar_AppendNewVar( f, "date", "unknown" );
1270 mvar_AppendVar( s, f );
1276 static mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm )
1278 mvar_t *s = mvar_New( name, "set" );
1282 if( vlm == NULL ) return s;
1284 if( vlm_ExecuteCommand( vlm, "show", &msg ) )
1289 for( i = 0; i < msg->i_child; i++ )
1291 /* Over media, schedule */
1292 vlm_message_t *ch = msg->child[i];
1295 for( j = 0; j < ch->i_child; j++ )
1298 vlm_message_t *el = ch->child[j];
1299 vlm_message_t *inf, *desc;
1304 sprintf( psz, "show %s", el->psz_name );
1305 if( vlm_ExecuteCommand( vlm, psz, &inf ) )
1307 desc = inf->child[0];
1309 /* Add a node with name and info */
1310 set = mvar_New( name, "set" );
1311 mvar_AppendNewVar( set, "name", el->psz_name );
1313 for( k = 0; k < desc->i_child; k++ )
1315 vlm_message_t *ch = desc->child[k];
1316 if( ch->i_child > 0 )
1319 mvar_t *n = mvar_New( ch->psz_name, "set" );
1321 for( c = 0; c < ch->i_child; c++ )
1323 if( ch->child[c]->psz_value )
1325 mvar_AppendNewVar( n, ch->child[c]->psz_name, ch->child[c]->psz_value );
1329 mvar_t *in = mvar_New( ch->psz_name, ch->child[c]->psz_name );
1330 mvar_AppendVar( n, in );
1333 mvar_AppendVar( set, n );
1337 mvar_AppendNewVar( set, ch->psz_name, ch->psz_value );
1340 vlm_MessageDelete( inf );
1342 mvar_AppendVar( s, set );
1345 vlm_MessageDelete( msg );
1351 static void SSInit( rpn_stack_t * );
1352 static void SSClean( rpn_stack_t * );
1353 static void EvaluateRPN( mvar_t *, rpn_stack_t *, char * );
1355 static void SSPush ( rpn_stack_t *, char * );
1356 static char *SSPop ( rpn_stack_t * );
1358 static void SSPushN ( rpn_stack_t *, int );
1359 static int SSPopN ( rpn_stack_t *, mvar_t * );
1362 /****************************************************************************
1364 ****************************************************************************/
1372 static int FileLoad( FILE *f, uint8_t **pp_data, int *pi_data )
1376 /* just load the file */
1378 *pp_data = malloc( 1025 ); /* +1 for \0 */
1379 while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 )
1382 *pp_data = realloc( *pp_data, *pi_data + 1025 );
1388 (*pp_data)[*pi_data] = '\0';
1393 static int MacroParse( macro_t *m, uint8_t *psz_src )
1395 uint8_t *dup = strdup( psz_src );
1400 #define EXTRACT( name, l ) \
1402 p = strchr( src, '"' ); \
1407 m->name = strdup( src ); \
1428 if( !strncmp( src, "id=\"", 4 ) )
1432 else if( !strncmp( src, "param1=\"", 8 ) )
1434 EXTRACT( param1, 8 );
1436 else if( !strncmp( src, "param2=\"", 8 ) )
1438 EXTRACT( param2, 8 );
1445 if( strstr( src, "/>" ) )
1447 src = strstr( src, "/>" ) + 2;
1451 src += strlen( src );
1456 m->id = strdup( "" );
1458 if( m->param1 == NULL )
1460 m->param1 = strdup( "" );
1462 if( m->param2 == NULL )
1464 m->param2 = strdup( "" );
1473 static void MacroClean( macro_t *m )
1532 StrToMacroTypeTab [] =
1534 { "control", MVLC_CONTROL },
1535 /* player control */
1536 { "play", MVLC_PLAY },
1537 { "stop", MVLC_STOP },
1538 { "pause", MVLC_PAUSE },
1539 { "next", MVLC_NEXT },
1540 { "previous", MVLC_PREVIOUS },
1541 { "seek", MVLC_SEEK },
1542 { "keep", MVLC_KEEP },
1543 { "fullscreen", MVLC_FULLSCREEN },
1544 { "volume", MVLC_VOLUME },
1546 /* playlist management */
1547 { "add", MVLC_ADD },
1548 { "delete", MVLC_DEL },
1549 { "empty", MVLC_EMPTY },
1550 { "sort", MVLC_SORT },
1551 { "move", MVLC_MOVE },
1554 { "close", MVLC_CLOSE },
1555 { "shutdown", MVLC_SHUTDOWN },
1558 { "vlm_new", MVLC_VLM_NEW },
1559 { "vlm_setup", MVLC_VLM_SETUP },
1560 { "vlm_del", MVLC_VLM_DEL },
1561 { "vlm_play", MVLC_VLM_PLAY },
1562 { "vlm_pause", MVLC_VLM_PAUSE },
1563 { "vlm_stop", MVLC_VLM_STOP },
1564 { "vlm_seek", MVLC_VLM_SEEK },
1565 { "vlm_load", MVLC_VLM_LOAD },
1566 { "vlm_save", MVLC_VLM_SAVE },
1568 { "rpn", MVLC_RPN },
1569 { "stack", MVLC_STACK },
1571 { "foreach", MVLC_FOREACH },
1572 { "value", MVLC_VALUE },
1575 { "else", MVLC_ELSE },
1576 { "end", MVLC_END },
1577 { "get", MVLC_GET },
1578 { "set", MVLC_SET },
1579 { "int", MVLC_INT },
1580 { "float", MVLC_FLOAT },
1581 { "string", MVLC_STRING },
1584 { NULL, MVLC_UNKNOWN }
1587 static int StrToMacroType( char *name )
1591 if( !name || *name == '\0')
1593 return MVLC_UNKNOWN;
1595 for( i = 0; StrToMacroTypeTab[i].psz_name != NULL; i++ )
1597 if( !strcmp( name, StrToMacroTypeTab[i].psz_name ) )
1599 return StrToMacroTypeTab[i].i_type;
1602 return MVLC_UNKNOWN;
1605 static void MacroDo( httpd_file_sys_t *p_args,
1607 uint8_t *p_request, int i_request,
1608 uint8_t **pp_data, int *pi_data,
1611 intf_thread_t *p_intf = p_args->p_intf;
1612 intf_sys_t *p_sys = p_args->p_intf->p_sys;
1615 #define ALLOC( l ) \
1617 int __i__ = *pp_dst - *pp_data; \
1619 *pp_data = realloc( *pp_data, *pi_data ); \
1620 *pp_dst = (*pp_data) + __i__; \
1622 #define PRINT( str ) \
1623 ALLOC( strlen( str ) + 1 ); \
1624 *pp_dst += sprintf( *pp_dst, str );
1626 #define PRINTS( str, s ) \
1627 ALLOC( strlen( str ) + strlen( s ) + 1 ); \
1629 char * psz_cur = *pp_dst; \
1630 *pp_dst += sprintf( *pp_dst, str, s ); \
1631 while( psz_cur && *psz_cur ) \
1633 /* Prevent script injection */ \
1634 if( *psz_cur == '<' ) *psz_cur = '*'; \
1635 if( *psz_cur == '>' ) *psz_cur = '*'; \
1640 switch( StrToMacroType( m->id ) )
1643 if( i_request <= 0 )
1647 uri_extract_value( p_request, "control", control, 512 );
1648 if( *m->param1 && !strstr( m->param1, control ) )
1650 msg_Warn( p_intf, "unauthorized control=%s", control );
1653 switch( StrToMacroType( control ) )
1660 uri_extract_value( p_request, "item", item, 512 );
1661 i_item = atoi( item );
1662 playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
1663 playlist_ItemGetById( p_sys->p_playlist,
1665 msg_Dbg( p_intf, "requested playlist item: %i", i_item );
1669 playlist_Control( p_sys->p_playlist, PLAYLIST_STOP);
1670 msg_Dbg( p_intf, "requested playlist stop" );
1673 playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
1674 msg_Dbg( p_intf, "requested playlist pause" );
1677 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
1678 msg_Dbg( p_intf, "requested playlist next" );
1681 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1);
1682 msg_Dbg( p_intf, "requested playlist next" );
1684 case MVLC_FULLSCREEN:
1686 if( p_sys->p_input )
1688 vout_thread_t *p_vout;
1689 p_vout = vlc_object_find( p_sys->p_input,
1690 VLC_OBJECT_VOUT, FIND_CHILD );
1694 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1695 vlc_object_release( p_vout );
1696 msg_Dbg( p_intf, "requested fullscreen toggle" );
1710 #define POSITION_ABSOLUTE 12
1711 #define POSITION_REL_FOR 13
1712 #define POSITION_REL_BACK 11
1713 #define VL_TIME_ABSOLUTE 0
1714 #define VL_TIME_REL_FOR 1
1715 #define VL_TIME_REL_BACK -1
1716 if( p_sys->p_input )
1718 uri_extract_value( p_request, "seek_value", value, 20 );
1719 uri_decode_url_encoded( value );
1721 var_Get( p_sys->p_input, "length", &val);
1722 i_length = val.i_time;
1724 while( p_value[0] != '\0' )
1730 i_relative = VL_TIME_REL_FOR;
1736 i_relative = VL_TIME_REL_BACK;
1740 case '0': case '1': case '2': case '3': case '4':
1741 case '5': case '6': case '7': case '8': case '9':
1743 i_stock = strtol( p_value , &p_value , 10 );
1746 case '%': /* for percentage ie position */
1748 i_relative += POSITION_ABSOLUTE;
1756 i_value = 60 * (i_value + i_stock) ;
1761 case 'h': case 'H': /* hours */
1763 i_value += 3600 * i_stock;
1765 /* other characters which are not numbers are not important */
1766 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1772 case 'm': case 'M': case '\'': /* minutes */
1774 i_value += 60 * i_stock;
1777 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1783 case 's': case 'S': case '"': /* seconds */
1787 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1801 /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
1806 case VL_TIME_ABSOLUTE:
1808 if( (uint64_t)( i_value ) * 1000000 <= i_length )
1809 val.i_time = (uint64_t)( i_value ) * 1000000;
1811 val.i_time = i_length;
1813 var_Set( p_sys->p_input, "time", val );
1814 msg_Dbg( p_intf, "requested seek position: %dsec", i_value );
1817 case VL_TIME_REL_FOR:
1819 var_Get( p_sys->p_input, "time", &val );
1820 if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
1822 val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
1825 val.i_time = i_length;
1827 var_Set( p_sys->p_input, "time", val );
1828 msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );
1831 case VL_TIME_REL_BACK:
1833 var_Get( p_sys->p_input, "time", &val );
1834 if( (int64_t)( i_value ) * 1000000 > val.i_time )
1839 val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);
1841 var_Set( p_sys->p_input, "time", val );
1842 msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );
1845 case POSITION_ABSOLUTE:
1847 val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1848 var_Set( p_sys->p_input, "position", val );
1849 msg_Dbg( p_intf, "requested seek percent: %d", i_value );
1852 case POSITION_REL_FOR:
1854 var_Get( p_sys->p_input, "position", &val );
1855 val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1856 var_Set( p_sys->p_input, "position", val );
1857 msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
1860 case POSITION_REL_BACK:
1862 var_Get( p_sys->p_input, "position", &val );
1863 val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1864 var_Set( p_sys->p_input, "position", val );
1865 msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
1870 msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
1875 #undef POSITION_ABSOLUTE
1876 #undef POSITION_REL_FOR
1877 #undef POSITION_REL_BACK
1878 #undef VL_TIME_ABSOLUTE
1879 #undef VL_TIME_REL_FOR
1880 #undef VL_TIME_REL_BACK
1886 audio_volume_t i_volume;
1889 uri_extract_value( p_request, "value", vol, 8 );
1890 aout_VolumeGet( p_intf, &i_volume );
1891 uri_decode_url_encoded( vol );
1895 i_value = atoi( vol + 1 );
1896 if( (i_volume + i_value) > AOUT_VOLUME_MAX )
1898 aout_VolumeSet( p_intf , AOUT_VOLUME_MAX );
1899 msg_Dbg( p_intf, "requested volume set: max" );
1902 aout_VolumeSet( p_intf , (i_volume + i_value) );
1903 msg_Dbg( p_intf, "requested volume set: +%i", (i_volume + i_value) );
1908 i_value = atoi( vol + 1 );
1909 if( (i_volume - i_value) < AOUT_VOLUME_MIN )
1911 aout_VolumeSet( p_intf , AOUT_VOLUME_MIN );
1912 msg_Dbg( p_intf, "requested volume set: min" );
1915 aout_VolumeSet( p_intf , (i_volume - i_value) );
1916 msg_Dbg( p_intf, "requested volume set: -%i", (i_volume - i_value) );
1919 if( strstr(vol, "%") != NULL )
1921 i_value = atoi( vol );
1922 if( (i_value <= 100) && (i_value>=0) ){
1923 aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/100+AOUT_VOLUME_MIN);
1924 msg_Dbg( p_intf, "requested volume set: %i%%", atoi( vol ));
1928 i_value = atoi( vol );
1929 if( ( i_value <= AOUT_VOLUME_MAX ) && ( i_value >= AOUT_VOLUME_MIN ) )
1931 aout_VolumeSet( p_intf , atoi( vol ) );
1932 msg_Dbg( p_intf, "requested volume set: %i", atoi( vol ) );
1938 /* playlist management */
1942 playlist_item_t * p_item;
1944 uri_extract_value( p_request, "mrl", mrl, 512 );
1945 uri_decode_url_encoded( mrl );
1946 p_item = parse_MRL( p_intf, mrl );
1948 if( !p_item || !p_item->input.psz_uri ||
1949 !*p_item->input.psz_uri )
1951 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
1954 playlist_AddItem( p_sys->p_playlist , p_item ,
1955 PLAYLIST_APPEND, PLAYLIST_END );
1956 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
1963 int i_item, *p_items = NULL, i_nb_items = 0;
1964 char item[512], *p_parser = p_request;
1966 /* Get the list of items to delete */
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;
1982 for( i = 0; i < i_nb_items; i++ )
1984 playlist_LockDelete( p_sys->p_playlist, p_items[i] );
1985 msg_Dbg( p_intf, "requested playlist delete: %d",
1991 if( p_items ) free( p_items );
1996 int i_item, *p_items = NULL, i_nb_items = 0;
1997 char item[512], *p_parser = p_request;
2000 /* Get the list of items to keep */
2002 uri_extract_value( p_parser, "item", item, 512 )) )
2004 if( !*item ) continue;
2006 i_item = atoi( item );
2007 p_items = realloc( p_items, (i_nb_items + 1) *
2009 p_items[i_nb_items] = i_item;
2013 for( i = p_sys->p_playlist->i_size - 1 ; i >= 0; i-- )
2015 /* Check if the item is in the keep list */
2016 for( j = 0 ; j < i_nb_items ; j++ )
2019 p_sys->p_playlist->pp_items[i]->input.i_id ) break;
2021 if( j == i_nb_items )
2023 playlist_LockDelete( p_sys->p_playlist, p_sys->p_playlist->pp_items[i]->input.i_id );
2024 msg_Dbg( p_intf, "requested playlist delete: %d",
2029 if( p_items ) free( p_items );
2034 playlist_LockClear( p_sys->p_playlist );
2035 msg_Dbg( p_intf, "requested playlist empty" );
2046 uri_extract_value( p_request, "type", type, 12 );
2047 uri_extract_value( p_request, "order", order, 2 );
2048 uri_extract_value( p_request, "item", item, 512 );
2049 i_item = atoi( item );
2051 if( order[0] == '0' ) i_order = ORDER_NORMAL;
2052 else i_order = ORDER_REVERSE;
2054 if( !strcmp( type , "title" ) )
2056 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2057 p_sys->p_playlist->pp_views[0]->p_root,
2058 SORT_TITLE_NODES_FIRST,
2059 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2060 msg_Dbg( p_intf, "requested playlist sort by title (%d)" , i_order );
2061 } else if( !strcmp( type , "author" ) )
2063 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2064 p_sys->p_playlist->pp_views[0]->p_root,
2066 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2067 msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
2068 } else if( !strcmp( type , "shuffle" ) )
2070 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2071 p_sys->p_playlist->pp_views[0]->p_root,
2073 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2074 msg_Dbg( p_intf, "requested playlist shuffle");
2085 uri_extract_value( p_request, "psz_pos", psz_pos, 6 );
2086 uri_extract_value( p_request, "psz_newpos", psz_newpos, 6 );
2087 i_pos = atoi( psz_pos );
2088 i_newpos = atoi( psz_newpos );
2089 if ( i_pos < i_newpos )
2091 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
2093 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
2095 msg_Dbg( p_intf, "requested move playlist item %d to %d", i_pos, i_newpos);
2099 /* admin function */
2103 uri_extract_value( p_request, "id", id, 512 );
2104 msg_Dbg( p_intf, "requested close id=%s", id );
2106 if( p_sys->p_httpd->pf_control( p_sys->p_httpd, HTTPD_SET_CLOSE, id, NULL ) )
2108 msg_Warn( p_intf, "close failed for id=%s", id );
2115 msg_Dbg( p_intf, "requested shutdown" );
2116 p_intf->p_vlc->b_die = VLC_TRUE;
2121 case MVLC_VLM_SETUP:
2123 static const char *vlm_properties[11] =
2126 "enabled", "disabled", "loop", "unloop",
2128 "input", "output", "option", "date", "period", "repeat", "append",
2130 vlm_message_t *vlm_answer;
2132 char *psz = malloc( strlen( p_request ) + 1000 );
2137 if( p_intf->p_sys->p_vlm == NULL )
2138 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2140 if( p_intf->p_sys->p_vlm == NULL ) break;
2142 uri_extract_value( p_request, "name", name, 512 );
2143 if( StrToMacroType( control ) == MVLC_VLM_NEW )
2146 uri_extract_value( p_request, "type", type, 20 );
2147 p += sprintf( psz, "new %s %s", name, type );
2151 p += sprintf( psz, "setup %s", name );
2153 /* Parse the request */
2154 for( i = 0; i < 11; i++ )
2157 uri_extract_value( p_request, vlm_properties[i], val, 512 );
2158 uri_decode_url_encoded( val );
2159 if( strlen( val ) > 0 && i >= 4 )
2161 p += sprintf( p, " %s %s", vlm_properties[i], val );
2163 else if( uri_test_param( p_request, vlm_properties[i] ) && i < 4 )
2165 p += sprintf( p, " %s", vlm_properties[i] );
2168 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2169 if( vlm_answer->psz_value == NULL ) /* there is no error */
2171 vlm_error = strdup( "" );
2175 vlm_error = malloc( strlen(vlm_answer->psz_name) +
2176 strlen(vlm_answer->psz_value) +
2177 strlen( " : ") + 1 );
2178 sprintf( vlm_error , "%s : %s" , vlm_answer->psz_name,
2179 vlm_answer->psz_value );
2182 mvar_AppendNewVar( p_args->vars, "vlm_error", vlm_error );
2184 vlm_MessageDelete( vlm_answer );
2192 vlm_message_t *vlm_answer;
2195 if( p_intf->p_sys->p_vlm == NULL )
2196 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2198 if( p_intf->p_sys->p_vlm == NULL ) break;
2200 uri_extract_value( p_request, "name", name, 512 );
2201 sprintf( psz, "del %s", name );
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 );
2210 case MVLC_VLM_PAUSE:
2214 vlm_message_t *vlm_answer;
2217 if( p_intf->p_sys->p_vlm == NULL )
2218 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2220 if( p_intf->p_sys->p_vlm == NULL ) break;
2222 uri_extract_value( p_request, "name", name, 512 );
2223 if( StrToMacroType( control ) == MVLC_VLM_PLAY )
2224 sprintf( psz, "control %s play", name );
2225 else if( StrToMacroType( control ) == MVLC_VLM_PAUSE )
2226 sprintf( psz, "control %s pause", name );
2227 else if( StrToMacroType( control ) == MVLC_VLM_STOP )
2228 sprintf( psz, "control %s stop", name );
2229 else if( StrToMacroType( control ) == MVLC_VLM_SEEK )
2232 uri_extract_value( p_request, "percent", percent, 512 );
2233 sprintf( psz, "control %s seek %s", name, percent );
2236 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2237 /* FIXME do a vlm_answer -> var stack conversion */
2238 vlm_MessageDelete( vlm_answer );
2244 vlm_message_t *vlm_answer;
2248 if( p_intf->p_sys->p_vlm == NULL )
2249 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2251 if( p_intf->p_sys->p_vlm == NULL ) break;
2253 uri_extract_value( p_request, "file", file, 512 );
2254 uri_decode_url_encoded( file );
2256 if( StrToMacroType( control ) == MVLC_VLM_LOAD )
2257 sprintf( psz, "load %s", file );
2259 sprintf( psz, "save %s", file );
2261 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2262 /* FIXME do a vlm_answer -> var stack conversion */
2263 vlm_MessageDelete( vlm_answer );
2270 PRINTS( "<!-- control param(%s) unsuported -->", control );
2282 if( i_request <= 0 ||
2283 *m->param1 == '\0' ||
2284 strstr( p_request, m->param1 ) == NULL )
2288 uri_extract_value( p_request, m->param1, value, 512 );
2289 uri_decode_url_encoded( value );
2291 switch( StrToMacroType( m->param2 ) )
2295 config_PutInt( p_intf, m->param1, i );
2299 config_PutFloat( p_intf, m->param1, f );
2302 config_PutPsz( p_intf, m->param1, value );
2305 PRINTS( "<!-- invalid type(%s) in set -->", m->param2 )
2316 if( *m->param1 == '\0' )
2321 switch( StrToMacroType( m->param2 ) )
2324 i = config_GetInt( p_intf, m->param1 );
2325 sprintf( value, "%i", i );
2328 f = config_GetFloat( p_intf, m->param1 );
2329 sprintf( value, "%f", f );
2332 psz = config_GetPsz( p_intf, m->param1 );
2333 sprintf( value, "%s", psz ? psz : "" );
2334 if( psz ) free( psz );
2337 sprintf( value, "invalid type(%s) in set", m->param2 );
2340 msg_Dbg( p_intf, "get name=%s value=%s type=%s", m->param1, value, m->param2 );
2341 PRINTS( "%s", value );
2350 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2351 s = SSPop( &p_args->stack );
2352 v = mvar_GetValue( p_args->vars, s );
2356 v = s = SSPop( &p_args->stack );
2364 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2367 /* Usefull for learning stack management */
2371 msg_Dbg( p_intf, "stack" );
2372 for (i=0;i<(&p_args->stack)->i_stack;i++)
2373 msg_Dbg( p_intf, "%d -> %s", i, (&p_args->stack)->stack[i] );
2379 PRINTS( "<!-- invalid macro id=`%s' -->", m->id );
2380 msg_Dbg( p_intf, "invalid macro id=`%s'", m->id );
2388 static uint8_t *MacroSearch( uint8_t *src, uint8_t *end, int i_mvlc, vlc_bool_t b_after )
2395 if( src + 4 < end && !strncmp( src, "<vlc", 4 ) )
2400 i_skip = MacroParse( &m, src );
2402 i_id = StrToMacroType( m.id );
2419 if( ( i_mvlc == MVLC_END && i_level == -1 ) ||
2420 ( i_mvlc != MVLC_END && i_level == 0 && i_mvlc == i_id ) )
2422 return src + ( b_after ? i_skip : 0 );
2424 else if( i_level < 0 )
2440 static void Execute( httpd_file_sys_t *p_args,
2441 uint8_t *p_request, int i_request,
2442 uint8_t **pp_data, int *pi_data,
2444 uint8_t *_src, uint8_t *_end )
2446 intf_thread_t *p_intf = p_args->p_intf;
2448 uint8_t *src, *dup, *end;
2449 uint8_t *dst = *pp_dst;
2451 src = dup = malloc( _end - _src + 1 );
2452 end = src +( _end - _src );
2454 memcpy( src, _src, _end - _src );
2457 /* we parse searching <vlc */
2463 p = strstr( src, "<vlc" );
2464 if( p < end && p == src )
2468 src += MacroParse( &m, src );
2470 //msg_Dbg( p_intf, "macro_id=%s", m.id );
2472 switch( StrToMacroType( m.id ) )
2479 EvaluateRPN( p_args->vars, &p_args->stack, m.param1 );
2480 if( SSPopN( &p_args->stack, p_args->vars ) )
2488 endif = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2492 uint8_t *start = MacroSearch( src, endif, MVLC_ELSE, VLC_TRUE );
2496 uint8_t *stop = MacroSearch( start, endif, MVLC_END, VLC_FALSE );
2499 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2503 else if( i_test == 1 )
2506 if( ( stop = MacroSearch( src, endif, MVLC_ELSE, VLC_FALSE ) ) == NULL )
2508 stop = MacroSearch( src, endif, MVLC_END, VLC_FALSE );
2512 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, src, stop );
2521 uint8_t *endfor = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2522 uint8_t *start = src;
2523 uint8_t *stop = MacroSearch( src, end, MVLC_END, VLC_FALSE );
2530 if( !strcmp( m.param2, "integer" ) )
2532 char *arg = SSPop( &p_args->stack );
2533 index = mvar_IntegerSetNew( m.param1, arg );
2536 else if( !strcmp( m.param2, "directory" ) )
2538 char *arg = SSPop( &p_args->stack );
2539 index = mvar_FileSetNew( m.param1, arg );
2542 else if( !strcmp( m.param2, "playlist" ) )
2544 index = mvar_PlaylistSetNew( m.param1, p_intf->p_sys->p_playlist );
2546 else if( !strcmp( m.param2, "information" ) )
2548 index = mvar_InfoSetNew( m.param1, p_intf->p_sys->p_input );
2550 else if( !strcmp( m.param2, "vlm" ) )
2552 if( p_intf->p_sys->p_vlm == NULL )
2553 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2554 index = mvar_VlmSetNew( m.param1, p_intf->p_sys->p_vlm );
2557 else if( !strcmp( m.param2, "hosts" ) )
2559 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_HOSTS );
2561 else if( !strcmp( m.param2, "urls" ) )
2563 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_URLS );
2565 else if( !strcmp( m.param2, "connections" ) )
2567 index = mvar_HttpdInfoSetNew(m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_CONNECTIONS);
2570 else if( ( v = mvar_GetVar( p_args->vars, m.param2 ) ) )
2572 index = mvar_Duplicate( v );
2576 msg_Dbg( p_intf, "invalid index constructor (%s)", m.param2 );
2581 for( i_idx = 0; i_idx < index->i_field; i_idx++ )
2583 mvar_t *f = mvar_Duplicate( index->field[i_idx] );
2585 //msg_Dbg( p_intf, "foreach field[%d] name=%s value=%s", i_idx, f->name, f->value );
2588 f->name = strdup( m.param1 );
2591 mvar_PushVar( p_args->vars, f );
2592 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2593 mvar_RemoveVar( p_args->vars, f );
2597 mvar_Delete( index );
2604 MacroDo( p_args, &m, p_request, i_request, pp_data, pi_data, &dst );
2612 i_copy = ( (p == NULL || p > end ) ? end : p ) - src;
2615 int i_index = dst - *pp_data;
2618 *pp_data = realloc( *pp_data, *pi_data );
2619 dst = (*pp_data) + i_index;
2621 memcpy( dst, src, i_copy );
2631 /****************************************************************************
2633 ****************************************************************************
2634 * a file with b_html is parsed and all "macro" replaced
2635 * <vlc id="macro name" [param1="" [param2=""]] />
2638 ****************************************************************************/
2639 static int HttpCallback( httpd_file_sys_t *p_args,
2640 httpd_file_t *p_file,
2642 uint8_t **pp_data, int *pi_data )
2644 int i_request = p_request ? strlen( p_request ) : 0;
2648 if( ( f = fopen( p_args->file, "r" ) ) == NULL )
2650 p = *pp_data = malloc( 10240 );
2653 return VLC_EGENERIC;
2655 p += sprintf( p, "<html>\n" );
2656 p += sprintf( p, "<head>\n" );
2657 p += sprintf( p, "<title>Error loading %s</title>\n", p_args->file );
2658 p += sprintf( p, "</head>\n" );
2659 p += sprintf( p, "<body>\n" );
2660 p += sprintf( p, "<h1><center>Error loading %s for %s</center></h1>\n", p_args->file, p_args->name );
2661 p += sprintf( p, "<hr />\n" );
2662 p += sprintf( p, "<a href=\"http://www.videolan.org/\">VideoLAN</a>\n" );
2663 p += sprintf( p, "</body>\n" );
2664 p += sprintf( p, "</html>\n" );
2666 *pi_data = strlen( *pp_data );
2671 if( !p_args->b_html )
2673 FileLoad( f, pp_data, pi_data );
2681 char position[4]; /* percentage */
2682 char time[12]; /* in seconds */
2683 char length[12]; /* in seconds */
2684 audio_volume_t i_volume;
2688 #define p_sys p_args->p_intf->p_sys
2689 if( p_sys->p_input )
2691 var_Get( p_sys->p_input, "position", &val);
2692 sprintf( position, "%d" , (int)((val.f_float) * 100.0));
2693 var_Get( p_sys->p_input, "time", &val);
2694 sprintf( time, "%d" , (int)(val.i_time / 1000000) );
2695 var_Get( p_sys->p_input, "length", &val);
2696 sprintf( length, "%d" , (int)(val.i_time / 1000000) );
2698 var_Get( p_sys->p_input, "state", &val );
2699 if( val.i_int == PLAYING_S )
2701 sprintf( state, "playing" );
2702 } else if( val.i_int == PAUSE_S )
2704 sprintf( state, "paused" );
2707 sprintf( state, "stop" );
2711 sprintf( position, "%d", 0 );
2712 sprintf( time, "%d", 0 );
2713 sprintf( length, "%d", 0 );
2714 sprintf( state, "stop" );
2718 aout_VolumeGet( p_args->p_intf , &i_volume );
2719 sprintf( volume , "%d" , (int)i_volume );
2721 p_args->vars = mvar_New( "variables", "" );
2722 mvar_AppendNewVar( p_args->vars, "url_param", i_request > 0 ? "1" : "0" );
2723 mvar_AppendNewVar( p_args->vars, "url_value", p_request );
2724 mvar_AppendNewVar( p_args->vars, "version", VERSION_MESSAGE );
2725 mvar_AppendNewVar( p_args->vars, "copyright", COPYRIGHT_MESSAGE );
2726 mvar_AppendNewVar( p_args->vars, "stream_position", position );
2727 mvar_AppendNewVar( p_args->vars, "stream_time", time );
2728 mvar_AppendNewVar( p_args->vars, "stream_length", length );
2729 mvar_AppendNewVar( p_args->vars, "volume", volume );
2730 mvar_AppendNewVar( p_args->vars, "stream_state", state );
2732 SSInit( &p_args->stack );
2734 /* first we load in a temporary buffer */
2735 FileLoad( f, &p_buffer, &i_buffer );
2737 /* allocate output */
2738 *pi_data = i_buffer + 1000;
2739 dst = *pp_data = malloc( *pi_data );
2741 /* we parse executing all <vlc /> macros */
2742 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, &p_buffer[0], &p_buffer[i_buffer] );
2745 *pi_data = dst - *pp_data;
2747 SSClean( &p_args->stack );
2748 mvar_Delete( p_args->vars );
2757 /****************************************************************************
2759 ****************************************************************************/
2760 static int uri_test_param( char *psz_uri, const char *psz_name )
2764 while( (p = strstr( p, psz_name )) )
2766 /* Verify that we are dealing with a post/get argument */
2767 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2776 static char *uri_extract_value( char *psz_uri, const char *psz_name,
2777 char *psz_value, int i_value_max )
2781 while( (p = strstr( p, psz_name )) )
2783 /* Verify that we are dealing with a post/get argument */
2784 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2793 p += strlen( psz_name );
2794 if( *p == '=' ) p++;
2796 if( strchr( p, '&' ) )
2798 i_len = strchr( p, '&' ) - p;
2802 /* for POST method */
2803 if( strchr( p, '\n' ) )
2805 i_len = strchr( p, '\n' ) - p;
2806 if( i_len && *(p+i_len-1) == '\r' ) i_len--;
2810 i_len = strlen( p );
2813 i_len = __MIN( i_value_max - 1, i_len );
2816 strncpy( psz_value, p, i_len );
2817 psz_value[i_len] = '\0';
2821 strncpy( psz_value, "", i_value_max );
2827 strncpy( psz_value, "", i_value_max );
2833 static void uri_decode_url_encoded( char *psz )
2835 char *dup = strdup( psz );
2853 *psz++ = strtol( val, NULL, 16 );
2855 else if( *p == '+' )
2869 /****************************************************************************
2870 * Light RPN evaluator
2871 ****************************************************************************/
2872 static void SSInit( rpn_stack_t *st )
2877 static void SSClean( rpn_stack_t *st )
2879 while( st->i_stack > 0 )
2881 free( st->stack[--st->i_stack] );
2885 static void SSPush( rpn_stack_t *st, char *s )
2887 if( st->i_stack < STACK_MAX )
2889 st->stack[st->i_stack++] = strdup( s );
2893 static char * SSPop( rpn_stack_t *st )
2895 if( st->i_stack <= 0 )
2897 return strdup( "" );
2901 return st->stack[--st->i_stack];
2905 static int SSPopN( rpn_stack_t *st, mvar_t *vars )
2914 i = strtol( name, &end, 0 );
2917 value = mvar_GetValue( vars, name );
2925 static void SSPushN( rpn_stack_t *st, int i )
2929 sprintf( v, "%d", i );
2933 static void EvaluateRPN( mvar_t *vars, rpn_stack_t *st, char *exp )
2940 while( *exp == ' ' )
2947 /* extract string */
2950 while( *exp && *exp != '\'' )
2961 p = strchr( exp, ' ' );
2966 exp += strlen( exp );
2971 strncpy( s, exp, i );
2982 /* 1. Integer function */
2983 if( !strcmp( s, "!" ) )
2985 SSPushN( st, ~SSPopN( st, vars ) );
2987 else if( !strcmp( s, "^" ) )
2989 SSPushN( st, SSPopN( st, vars ) ^ SSPopN( st, vars ) );
2991 else if( !strcmp( s, "&" ) )
2993 SSPushN( st, SSPopN( st, vars ) & SSPopN( st, vars ) );
2995 else if( !strcmp( s, "|" ) )
2997 SSPushN( st, SSPopN( st, vars ) | SSPopN( st, vars ) );
2999 else if( !strcmp( s, "+" ) )
3001 SSPushN( st, SSPopN( st, vars ) + SSPopN( st, vars ) );
3003 else if( !strcmp( s, "-" ) )
3005 int j = SSPopN( st, vars );
3006 int i = SSPopN( st, vars );
3007 SSPushN( st, i - j );
3009 else if( !strcmp( s, "*" ) )
3011 SSPushN( st, SSPopN( st, vars ) * SSPopN( st, vars ) );
3013 else if( !strcmp( s, "/" ) )
3017 j = SSPopN( st, vars );
3018 i = SSPopN( st, vars );
3020 SSPushN( st, j != 0 ? i / j : 0 );
3022 else if( !strcmp( s, "%" ) )
3026 j = SSPopN( st, vars );
3027 i = SSPopN( st, vars );
3029 SSPushN( st, j != 0 ? i % j : 0 );
3031 /* 2. integer tests */
3032 else if( !strcmp( s, "=" ) )
3034 SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 );
3036 else if( !strcmp( s, "!=" ) )
3038 SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 );
3040 else if( !strcmp( s, "<" ) )
3042 int j = SSPopN( st, vars );
3043 int i = SSPopN( st, vars );
3045 SSPushN( st, i < j ? -1 : 0 );
3047 else if( !strcmp( s, ">" ) )
3049 int j = SSPopN( st, vars );
3050 int i = SSPopN( st, vars );
3052 SSPushN( st, i > j ? -1 : 0 );
3054 else if( !strcmp( s, "<=" ) )
3056 int j = SSPopN( st, vars );
3057 int i = SSPopN( st, vars );
3059 SSPushN( st, i <= j ? -1 : 0 );
3061 else if( !strcmp( s, ">=" ) )
3063 int j = SSPopN( st, vars );
3064 int i = SSPopN( st, vars );
3066 SSPushN( st, i >= j ? -1 : 0 );
3068 /* 3. string functions */
3069 else if( !strcmp( s, "strcat" ) )
3071 char *s2 = SSPop( st );
3072 char *s1 = SSPop( st );
3073 char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
3083 else if( !strcmp( s, "strcmp" ) )
3085 char *s2 = SSPop( st );
3086 char *s1 = SSPop( st );
3088 SSPushN( st, strcmp( s1, s2 ) );
3092 else if( !strcmp( s, "strncmp" ) )
3094 int n = SSPopN( st, vars );
3095 char *s2 = SSPop( st );
3096 char *s1 = SSPop( st );
3098 SSPushN( st, strncmp( s1, s2 , n ) );
3102 else if( !strcmp( s, "strsub" ) )
3104 int n = SSPopN( st, vars );
3105 int m = SSPopN( st, vars );
3107 char *s = SSPop( st );
3119 str = malloc( i_len + 1 );
3121 memcpy( str, s + m - 1, i_len );
3122 str[ i_len ] = '\0';
3128 else if( !strcmp( s, "strlen" ) )
3130 char *str = SSPop( st );
3132 SSPushN( st, strlen( str ) );
3135 /* 4. stack functions */
3136 else if( !strcmp( s, "dup" ) )
3138 char *str = SSPop( st );
3143 else if( !strcmp( s, "drop" ) )
3145 char *str = SSPop( st );
3148 else if( !strcmp( s, "swap" ) )
3150 char *s1 = SSPop( st );
3151 char *s2 = SSPop( st );
3158 else if( !strcmp( s, "flush" ) )
3163 else if( !strcmp( s, "store" ) )
3165 char *value = SSPop( st );
3166 char *name = SSPop( st );
3168 mvar_PushNewVar( vars, name, value );
3172 else if( !strcmp( s, "value" ) )
3174 char *name = SSPop( st );
3175 char *value = mvar_GetValue( vars, name );
3177 SSPush( st, value );
3181 else if( !strcmp( s, "url_extract" ) )
3183 char *url = mvar_GetValue( vars, "url_value" );
3184 char *name = SSPop( st );
3187 uri_extract_value( url, name, value, 512 );
3188 uri_decode_url_encoded( value );
3189 SSPush( st, value );
3198 /**********************************************************************
3199 * Find_end_MRL: Find the end of the sentence :
3200 * this function parses the string psz and find the end of the item
3201 * and/or option with detecting the " and ' problems.
3202 * returns NULL if an error is detected, otherwise, returns a pointer
3203 * of the end of the sentence (after the last character)
3204 **********************************************************************/
3205 static char *Find_end_MRL( char *psz )
3215 while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) )
3217 if( *s_sent == '\'' )
3219 s_sent = Find_end_MRL( s_sent );
3221 if( s_sent == NULL )
3231 if( *s_sent == '\"' )
3235 } else /* *s_sent == '\0' , which means the number of " is incorrect */
3245 while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) )
3247 if( *s_sent == '\"' )
3249 s_sent = Find_end_MRL( s_sent );
3251 if( s_sent == NULL )
3261 if( *s_sent == '\'' )
3265 } else /* *s_sent == '\0' , which means the number of ' is incorrect */
3271 default: /* now we can look for spaces */
3273 while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) )
3275 if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) )
3277 s_sent = Find_end_MRL( s_sent );
3288 /**********************************************************************
3289 * parse_MRL: parse the MRL, find the mrl string and the options,
3290 * create an item with all information in it, and return the item.
3291 * return NULL if there is an error.
3292 **********************************************************************/
3293 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz )
3295 char **ppsz_options = NULL;
3302 playlist_item_t * p_item = NULL;
3304 /* In case there is spaces before the mrl */
3305 while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
3310 /* extract the mrl */
3311 s_temp = strstr( s_mrl , " :" );
3312 if( s_temp == NULL )
3314 s_temp = s_mrl + strlen( s_mrl );
3317 while( (*s_temp == ' ') && (s_temp != s_mrl ) )
3324 /* if the mrl is between " or ', we must remove them */
3325 if( (*s_mrl == '\'') || (*s_mrl == '\"') )
3327 mrl = (char *)malloc( (s_temp - s_mrl - 1) * sizeof( char ) );
3328 strncpy( mrl , (s_mrl + 1) , s_temp - s_mrl - 2 );
3329 mrl[ s_temp - s_mrl - 2 ] = '\0';
3332 mrl = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) );
3333 strncpy( mrl , s_mrl , s_temp - s_mrl );
3334 mrl[ s_temp - s_mrl ] = '\0';
3339 /* now we can take care of the options */
3340 while( (*s_mrl != '\0') && (i_error == 0) )
3349 case ':': /* an option */
3351 s_temp = Find_end_MRL( s_mrl );
3353 if( s_temp == NULL )
3360 ppsz_options = realloc( ppsz_options , i_options *
3362 ppsz_options[ i_options - 1 ] =
3363 malloc( (s_temp - s_mrl + 1) * sizeof(char) );
3365 strncpy( ppsz_options[ i_options - 1 ] , s_mrl ,
3368 /* don't forget to finish the string with a '\0' */
3369 (ppsz_options[ i_options - 1 ])[ s_temp - s_mrl ] = '\0';
3389 /* now create an item */
3390 p_item = playlist_ItemNew( p_intf, mrl, mrl);
3391 for( i = 0 ; i< i_options ; i++ )
3393 playlist_ItemAddOption( p_item, ppsz_options[i] );
3397 for( i = 0; i < i_options; i++ ) free( ppsz_options[i] );
3398 if( i_options ) free( ppsz_options );