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;
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 )
264 msg_Dbg( p_intf, "enablind TLS for HTTP interface (cert file: %s)",
266 psz_pem = config_GetPsz( p_intf, "http-intf-key" );
268 p_tls = tls_ServerCreate( p_this, psz_cert, psz_pem );
271 msg_Err( p_intf, "TLS initialization error" );
272 free( p_sys->psz_html_type );
277 psz_pem = config_GetPsz( p_intf, "http-intf-ca" );
278 if ( ( psz_pem != NULL) && tls_ServerAddCA( p_tls, psz_pem ) )
280 msg_Err( p_intf, "TLS CA error" );
281 tls_ServerDelete( p_tls );
282 free( p_sys->psz_html_type );
287 psz_pem = config_GetPsz( p_intf, "http-intf-crl" );
288 if ( ( psz_pem != NULL) && tls_ServerAddCRL( p_tls, psz_pem ) )
290 msg_Err( p_intf, "TLS CRL error" );
291 tls_ServerDelete( p_tls );
292 free( p_sys->psz_html_type );
307 msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
309 p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
311 if( p_sys->p_httpd_host == NULL )
313 msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
315 tls_ServerDelete( p_tls );
317 free( p_sys->psz_html_type );
328 p_sys->pp_files = NULL;
330 #if defined(SYS_DARWIN) || defined(SYS_BEOS) || defined(WIN32)
331 if ( ( psz_src = config_GetPsz( p_intf, "http-src" )) == NULL )
333 char * psz_vlcpath = p_intf->p_libvlc->psz_vlcpath;
334 psz_src = malloc( strlen(psz_vlcpath) + strlen("/share/http" ) + 1 );
335 if( !psz_src ) return VLC_ENOMEM;
337 sprintf( psz_src, "%s/http", psz_vlcpath);
339 sprintf( psz_src, "%s/share/http", psz_vlcpath);
343 psz_src = config_GetPsz( p_intf, "http-src" );
345 if( !psz_src || *psz_src == '\0' )
347 if( !DirectoryCheck( "share/http" ) )
349 psz_src = strdup( "share/http" );
351 else if( !DirectoryCheck( DATA_PATH "/http" ) )
353 psz_src = strdup( DATA_PATH "/http" );
358 if( !psz_src || *psz_src == '\0' )
360 msg_Err( p_intf, "invalid src dir" );
364 /* remove trainling \ or / */
365 if( psz_src[strlen( psz_src ) - 1] == '\\' ||
366 psz_src[strlen( psz_src ) - 1] == '/' )
368 psz_src[strlen( psz_src ) - 1] = '\0';
371 ParseDirectory( p_intf, psz_src, psz_src );
374 if( p_sys->i_files <= 0 )
376 msg_Err( p_intf, "cannot find any files (%s)", psz_src );
379 p_intf->pf_run = Run;
385 if( psz_src ) free( psz_src );
386 if( p_sys->pp_files )
388 free( p_sys->pp_files );
390 httpd_HostDelete( p_sys->p_httpd_host );
391 free( p_sys->psz_html_type );
396 /*****************************************************************************
397 * CloseIntf: destroy interface
398 *****************************************************************************/
399 void Close ( vlc_object_t *p_this )
401 intf_thread_t *p_intf = (intf_thread_t *)p_this;
402 intf_sys_t *p_sys = p_intf->p_sys;
408 vlm_Delete( p_sys->p_vlm );
410 for( i = 0; i < p_sys->i_files; i++ )
412 httpd_FileDelete( p_sys->pp_files[i]->p_file );
413 if( p_sys->pp_files[i]->p_redir )
414 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir );
415 if( p_sys->pp_files[i]->p_redir2 )
416 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir2 );
418 free( p_sys->pp_files[i]->file );
419 free( p_sys->pp_files[i]->name );
420 free( p_sys->pp_files[i] );
422 if( p_sys->pp_files )
424 free( p_sys->pp_files );
426 httpd_HostDelete( p_sys->p_httpd_host );
428 free( p_sys->psz_html_type );
432 /*****************************************************************************
433 * Run: http interface thread
434 *****************************************************************************/
435 static void Run( intf_thread_t *p_intf )
437 intf_sys_t *p_sys = p_intf->p_sys;
439 while( !p_intf->b_die )
441 /* get the playlist */
442 if( p_sys->p_playlist == NULL )
444 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
447 /* Manage the input part */
448 if( p_sys->p_input == NULL )
450 if( p_sys->p_playlist )
453 vlc_object_find( p_sys->p_playlist,
458 else if( p_sys->p_input->b_dead )
460 vlc_object_release( p_sys->p_input );
461 p_sys->p_input = NULL;
466 msleep( INTF_IDLE_SLEEP );
471 vlc_object_release( p_sys->p_input );
472 p_sys->p_input = NULL;
475 if( p_sys->p_playlist )
477 vlc_object_release( p_sys->p_playlist );
478 p_sys->p_playlist = NULL;
483 /*****************************************************************************
485 *****************************************************************************/
486 #define MAX_DIR_SIZE 10240
488 /****************************************************************************
489 * FileToUrl: create a good name for an url from filename
490 ****************************************************************************/
491 static char *FileToUrl( char *name, vlc_bool_t *pb_index )
495 url = p = malloc( strlen( name ) + 1 );
503 while( *name == '\\' || *name == '/' )
505 while( *name == '/' )
515 /* convert '\\' into '/' */
527 *pb_index = VLC_FALSE;
529 if( ( p = strrchr( url, '/' ) ) != NULL )
531 if( !strncmp( p, "/index.", 7 ) )
534 *pb_index = VLC_TRUE;
540 /****************************************************************************
541 * ParseDirectory: parse recursively a directory, adding each file
542 ****************************************************************************/
543 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
546 intf_sys_t *p_sys = p_intf->p_sys;
547 char dir[MAX_DIR_SIZE];
548 #ifdef HAVE_SYS_STAT_H
549 struct stat stat_info;
552 struct dirent *p_dir_content;
556 char *password = NULL;
558 #ifdef HAVE_SYS_STAT_H
559 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
565 if( ( p_dir = opendir( psz_dir ) ) == NULL )
567 msg_Err( p_intf, "cannot open dir (%s)", psz_dir );
571 msg_Dbg( p_intf, "dir=%s", psz_dir );
573 sprintf( dir, "%s/.access", psz_dir );
574 if( ( file = fopen( dir, "r" ) ) != NULL )
579 msg_Dbg( p_intf, "find .access in dir=%s", psz_dir );
581 i_size = fread( line, 1, 1023, file );
585 while( i_size > 0 && ( line[i_size-1] == '\n' ||
586 line[i_size-1] == '\r' ) )
593 p = strchr( line, ':' );
597 user = strdup( line );
598 password = strdup( p );
601 msg_Dbg( p_intf, "using user=%s password=%s (read=%d)",
602 user, password, i_size );
609 /* parse psz_src dir */
610 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
615 if( p_dir_content->d_name[0] == '.' )
619 sprintf( dir, "%s/%s", psz_dir, p_dir_content->d_name );
620 if( ParseDirectory( p_intf, psz_root, dir ) )
622 httpd_file_sys_t *f = malloc( sizeof( httpd_file_sys_t ) );
629 f->file = strdup( dir );
630 f->name = FileToUrl( &dir[strlen( psz_root )], &b_index );
631 f->b_html = strstr( &dir[strlen( psz_root )], ".htm" ) ? VLC_TRUE : VLC_FALSE;
635 msg_Err( p_intf , "unable to parse directory" );
638 return( VLC_ENOMEM );
640 msg_Dbg( p_intf, "file=%s (url=%s)",
643 f->p_file = httpd_FileNew( p_sys->p_httpd_host,
645 f->b_html ? p_sys->psz_html_type : NULL,
651 TAB_APPEND( p_sys->i_files, p_sys->pp_files, f );
653 /* for url that ends by / add
654 * - a redirect from rep to rep/
655 * - in case of index.* rep/index.html to rep/ */
656 if( f && f->name[strlen(f->name) - 1] == '/' )
658 char *psz_redir = strdup( f->name );
660 psz_redir[strlen( psz_redir ) - 1] = '\0';
662 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
663 f->p_redir = httpd_RedirectNew( p_sys->p_httpd_host, f->name, psz_redir );
666 if( b_index && ( p = strstr( f->file, "index." ) ) )
668 asprintf( &psz_redir, "%s%s", f->name, p );
670 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
671 f->p_redir2 = httpd_RedirectNew( p_sys->p_httpd_host,
672 f->name, psz_redir );
694 /****************************************************************************
695 * var and set handling
696 ****************************************************************************/
698 static mvar_t *mvar_New( char *name, char *value )
700 mvar_t *v = malloc( sizeof( mvar_t ) );
702 if( !v ) return NULL;
703 v->name = strdup( name );
704 v->value = strdup( value ? value : "" );
707 v->field = malloc( sizeof( mvar_t * ) );
713 static void mvar_Delete( mvar_t *v )
720 for( i = 0; i < v->i_field; i++ )
722 mvar_Delete( v->field[i] );
728 static void mvar_AppendVar( mvar_t *v, mvar_t *f )
730 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
731 v->field[v->i_field] = f;
735 static mvar_t *mvar_Duplicate( mvar_t *v )
740 n = mvar_New( v->name, v->value );
741 for( i = 0; i < v->i_field; i++ )
743 mvar_AppendVar( n, mvar_Duplicate( v->field[i] ) );
749 static void mvar_PushVar( mvar_t *v, mvar_t *f )
751 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
754 memmove( &v->field[1], &v->field[0], sizeof( mvar_t * ) * v->i_field );
760 static void mvar_RemoveVar( mvar_t *v, mvar_t *f )
763 for( i = 0; i < v->i_field; i++ )
765 if( v->field[i] == f )
770 if( i >= v->i_field )
775 if( i + 1 < v->i_field )
777 memmove( &v->field[i], &v->field[i+1], sizeof( mvar_t * ) * ( v->i_field - i - 1 ) );
780 /* FIXME should do a realloc */
783 static mvar_t *mvar_GetVar( mvar_t *s, char *name )
786 char base[512], *field, *p;
789 /* format: name[index].field */
791 field = strchr( name, '.' );
794 int i = field - name;
795 strncpy( base, name, i );
801 strcpy( base, name );
804 if( ( p = strchr( base, '[' ) ) )
807 sscanf( p, "%d]", &i_index );
818 for( i = 0; i < s->i_field; i++ )
820 if( !strcmp( s->field[i]->name, base ) )
830 return mvar_GetVar( s->field[i], field );
844 static char *mvar_GetValue( mvar_t *v, char *field )
852 mvar_t *f = mvar_GetVar( v, field );
864 static void mvar_PushNewVar( mvar_t *vars, char *name, char *value )
866 mvar_t *f = mvar_New( name, value );
867 mvar_PushVar( vars, f );
870 static void mvar_AppendNewVar( mvar_t *vars, char *name, char *value )
872 mvar_t *f = mvar_New( name, value );
873 mvar_AppendVar( vars, f );
877 /* arg= start[:stop[:step]],.. */
878 static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
880 char *dup = strdup( arg );
882 mvar_t *s = mvar_New( name, "set" );
888 int i_start,i_stop,i_step;
891 p = strchr( str, ',' );
898 i_match = sscanf( str, "%d:%d:%d", &i_start, &i_stop, &i_step );
905 else if( i_match == 2 )
907 i_step = i_start < i_stop ? 1 : -1;
914 if( ( i_start <= i_stop && i_step > 0 ) ||
915 ( i_start >= i_stop && i_step < 0 ) )
917 for( i = i_start; ; i += i_step )
921 if( ( i_step > 0 && i > i_stop ) ||
922 ( i_step < 0 && i < i_stop ) )
927 sprintf( value, "%d", i );
929 mvar_PushNewVar( s, name, value );
940 void PlaylistListNode( playlist_t *p_pl, playlist_item_t *p_node,
941 char *name, mvar_t *s, int i_depth )
945 if (p_node->i_children == -1)
948 mvar_t *itm = mvar_New( name, "set" );
950 sprintf( value, "%d", ( p_pl->status.p_item == p_node )? 1 : 0 );
951 mvar_AppendNewVar( itm, "current", value );
953 sprintf( value, "%d", p_node->input.i_id );
954 mvar_AppendNewVar( itm, "index", value );
956 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
958 mvar_AppendNewVar( itm, "uri", p_node->input.psz_uri );
960 sprintf( value, "Item");
961 mvar_AppendNewVar( itm, "type", value );
963 sprintf( value, "%d", i_depth );
964 mvar_AppendNewVar( itm, "depth", value );
966 mvar_AppendVar( s, itm );
972 mvar_t *itm = mvar_New( name, "set" );
974 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
975 mvar_AppendNewVar( itm, "uri", p_node->input.psz_name );
977 sprintf( value, "Node" );
978 mvar_AppendNewVar( itm, "type", value );
980 sprintf( value, "%d", p_node->input.i_id );
981 mvar_AppendNewVar( itm, "index", value );
983 sprintf( value, "%d", p_node->i_children);
984 mvar_AppendNewVar( itm, "i_children", value );
986 sprintf( value, "%d", i_depth );
987 mvar_AppendNewVar( itm, "depth", value );
989 mvar_AppendVar( s, itm );
991 for (i_child = 0 ; i_child < p_node->i_children ; i_child++)
992 PlaylistListNode( p_pl, p_node->pp_children[i_child], name, s, i_depth + 1);
998 static mvar_t *mvar_PlaylistSetNew( char *name, playlist_t *p_pl )
1000 playlist_view_t *p_view;
1001 mvar_t *s = mvar_New( name, "set" );
1004 vlc_mutex_lock( &p_pl->object_lock );
1006 p_view = playlist_ViewFind( p_pl, VIEW_CATEGORY ); /* FIXME */
1008 if( p_view != NULL )
1009 PlaylistListNode( p_pl, p_view->p_root, name, s, 0 );
1011 vlc_mutex_unlock( &p_pl->object_lock );
1016 static mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input )
1018 mvar_t *s = mvar_New( name, "set" );
1021 if( p_input == NULL )
1026 vlc_mutex_lock( &p_input->input.p_item->lock );
1027 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
1029 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1030 mvar_t *cat = mvar_New( name, "set" );
1031 mvar_t *iset = mvar_New( "info", "set" );
1033 mvar_AppendNewVar( cat, "name", p_category->psz_name );
1034 mvar_AppendVar( cat, iset );
1036 for ( j = 0; j < p_category->i_infos; j++ )
1038 info_t *p_info = p_category->pp_infos[j];
1039 mvar_t *info = mvar_New( "info", "" );
1041 msg_Dbg( p_input, "adding info name=%s value=%s",
1042 p_info->psz_name, p_info->psz_value );
1043 mvar_AppendNewVar( info, "name", p_info->psz_name );
1044 mvar_AppendNewVar( info, "value", p_info->psz_value );
1045 mvar_AppendVar( iset, info );
1047 mvar_AppendVar( s, cat );
1049 vlc_mutex_unlock( &p_input->input.p_item->lock );
1054 static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
1056 mvar_t *s = mvar_New( name, "set" );
1060 if( !p_httpd->pf_control( p_httpd, i_type, &info, NULL ) )
1062 for( i= 0; i < info.i_count; )
1066 inf = mvar_New( name, "set" );
1069 /* fprintf( stderr," mvar_HttpdInfoSetNew: append name=`%s' value=`%s'\n",
1070 info.info[i].psz_name, info.info[i].psz_value ); */
1071 mvar_AppendNewVar( inf,
1072 info.info[i].psz_name,
1073 info.info[i].psz_value );
1075 } while( i < info.i_count && strcmp( info.info[i].psz_name, "id" ) );
1076 mvar_AppendVar( s, inf );
1081 for( i = 0; i < info.i_count; i++ )
1083 free( info.info[i].psz_name );
1084 free( info.info[i].psz_value );
1086 if( info.i_count > 0 )
1095 static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
1097 mvar_t *s = mvar_New( name, "set" );
1098 char tmp[MAX_DIR_SIZE], *p, *src;
1099 #ifdef HAVE_SYS_STAT_H
1100 struct stat stat_info;
1103 struct dirent *p_dir_content;
1106 /* convert all / to native separator */
1107 #if defined( WIN32 )
1108 while( (p = strchr( psz_dir, '/' )) )
1117 /* remove trailling separator */
1118 while( strlen( psz_dir ) > 1 &&
1119 #if defined( WIN32 )
1120 !( strlen(psz_dir)==3 && psz_dir[1]==':' && psz_dir[2]==sep ) &&
1122 psz_dir[strlen( psz_dir ) -1 ] == sep )
1124 psz_dir[strlen( psz_dir ) -1 ] ='\0';
1126 /* remove double separator */
1127 for( p = src = psz_dir; *src != '\0'; src++, p++ )
1129 if( src[0] == sep && src[1] == sep )
1137 if( *psz_dir == '\0' )
1141 /* first fix all .. dir */
1145 if( src[0] == '.' && src[1] == '.' )
1148 if( p <= &psz_dir[1] )
1155 while( p > &psz_dir[1] && *p != sep )
1160 else if( *src == sep )
1162 if( p > psz_dir && p[-1] == sep )
1176 } while( *src && *src != sep );
1182 #ifdef HAVE_SYS_STAT_H
1183 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
1189 if( ( p_dir = opendir( psz_dir ) ) == NULL )
1191 fprintf( stderr, "cannot open dir (%s)", psz_dir );
1195 /* remove traling / or \ */
1196 for( p = &psz_dir[strlen( psz_dir) - 1];
1197 p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- )
1206 /* parse psz_src dir */
1207 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
1211 if( !strcmp( p_dir_content->d_name, "." ) )
1216 sprintf( tmp, "%s/%s", psz_dir, p_dir_content->d_name );
1218 #ifdef HAVE_SYS_STAT_H
1219 if( stat( tmp, &stat_info ) == -1 )
1224 f = mvar_New( name, "set" );
1225 mvar_AppendNewVar( f, "name", tmp );
1227 #ifdef HAVE_SYS_STAT_H
1228 if( S_ISDIR( stat_info.st_mode ) )
1230 mvar_AppendNewVar( f, "type", "directory" );
1232 else if( S_ISREG( stat_info.st_mode ) )
1234 mvar_AppendNewVar( f, "type", "file" );
1238 mvar_AppendNewVar( f, "type", "unknown" );
1241 sprintf( tmp, I64Fd, (int64_t)stat_info.st_size );
1242 mvar_AppendNewVar( f, "size", tmp );
1244 /* FIXME memory leak FIXME */
1246 ctime_r( &stat_info.st_mtime, tmp );
1247 mvar_AppendNewVar( f, "date", tmp );
1249 mvar_AppendNewVar( f, "date", ctime( &stat_info.st_mtime ) );
1253 mvar_AppendNewVar( f, "type", "unknown" );
1254 mvar_AppendNewVar( f, "size", "unknown" );
1255 mvar_AppendNewVar( f, "date", "unknown" );
1257 mvar_AppendVar( s, f );
1263 static mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm )
1265 mvar_t *s = mvar_New( name, "set" );
1269 if( vlm == NULL ) return s;
1271 if( vlm_ExecuteCommand( vlm, "show", &msg ) )
1276 for( i = 0; i < msg->i_child; i++ )
1278 /* Over media, schedule */
1279 vlm_message_t *ch = msg->child[i];
1282 for( j = 0; j < ch->i_child; j++ )
1285 vlm_message_t *el = ch->child[j];
1286 vlm_message_t *inf, *desc;
1291 sprintf( psz, "show %s", el->psz_name );
1292 if( vlm_ExecuteCommand( vlm, psz, &inf ) )
1294 desc = inf->child[0];
1296 /* Add a node with name and info */
1297 set = mvar_New( name, "set" );
1298 mvar_AppendNewVar( set, "name", el->psz_name );
1300 for( k = 0; k < desc->i_child; k++ )
1302 vlm_message_t *ch = desc->child[k];
1303 if( ch->i_child > 0 )
1306 mvar_t *n = mvar_New( ch->psz_name, "set" );
1308 for( c = 0; c < ch->i_child; c++ )
1310 if( ch->child[c]->psz_value )
1312 mvar_AppendNewVar( n, ch->child[c]->psz_name, ch->child[c]->psz_value );
1316 mvar_t *in = mvar_New( ch->psz_name, ch->child[c]->psz_name );
1317 mvar_AppendVar( n, in );
1320 mvar_AppendVar( set, n );
1324 mvar_AppendNewVar( set, ch->psz_name, ch->psz_value );
1327 vlm_MessageDelete( inf );
1329 mvar_AppendVar( s, set );
1332 vlm_MessageDelete( msg );
1338 static void SSInit( rpn_stack_t * );
1339 static void SSClean( rpn_stack_t * );
1340 static void EvaluateRPN( mvar_t *, rpn_stack_t *, char * );
1342 static void SSPush ( rpn_stack_t *, char * );
1343 static char *SSPop ( rpn_stack_t * );
1345 static void SSPushN ( rpn_stack_t *, int );
1346 static int SSPopN ( rpn_stack_t *, mvar_t * );
1349 /****************************************************************************
1351 ****************************************************************************/
1359 static int FileLoad( FILE *f, uint8_t **pp_data, int *pi_data )
1363 /* just load the file */
1365 *pp_data = malloc( 1025 ); /* +1 for \0 */
1366 while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 )
1369 *pp_data = realloc( *pp_data, *pi_data + 1025 );
1375 (*pp_data)[*pi_data] = '\0';
1380 static int MacroParse( macro_t *m, uint8_t *psz_src )
1382 uint8_t *dup = strdup( psz_src );
1387 #define EXTRACT( name, l ) \
1389 p = strchr( src, '"' ); \
1394 m->name = strdup( src ); \
1415 if( !strncmp( src, "id=\"", 4 ) )
1419 else if( !strncmp( src, "param1=\"", 8 ) )
1421 EXTRACT( param1, 8 );
1423 else if( !strncmp( src, "param2=\"", 8 ) )
1425 EXTRACT( param2, 8 );
1432 if( strstr( src, "/>" ) )
1434 src = strstr( src, "/>" ) + 2;
1438 src += strlen( src );
1443 m->id = strdup( "" );
1445 if( m->param1 == NULL )
1447 m->param1 = strdup( "" );
1449 if( m->param2 == NULL )
1451 m->param2 = strdup( "" );
1460 static void MacroClean( macro_t *m )
1519 StrToMacroTypeTab [] =
1521 { "control", MVLC_CONTROL },
1522 /* player control */
1523 { "play", MVLC_PLAY },
1524 { "stop", MVLC_STOP },
1525 { "pause", MVLC_PAUSE },
1526 { "next", MVLC_NEXT },
1527 { "previous", MVLC_PREVIOUS },
1528 { "seek", MVLC_SEEK },
1529 { "keep", MVLC_KEEP },
1530 { "fullscreen", MVLC_FULLSCREEN },
1531 { "volume", MVLC_VOLUME },
1533 /* playlist management */
1534 { "add", MVLC_ADD },
1535 { "delete", MVLC_DEL },
1536 { "empty", MVLC_EMPTY },
1537 { "sort", MVLC_SORT },
1538 { "move", MVLC_MOVE },
1541 { "close", MVLC_CLOSE },
1542 { "shutdown", MVLC_SHUTDOWN },
1545 { "vlm_new", MVLC_VLM_NEW },
1546 { "vlm_setup", MVLC_VLM_SETUP },
1547 { "vlm_del", MVLC_VLM_DEL },
1548 { "vlm_play", MVLC_VLM_PLAY },
1549 { "vlm_pause", MVLC_VLM_PAUSE },
1550 { "vlm_stop", MVLC_VLM_STOP },
1551 { "vlm_seek", MVLC_VLM_SEEK },
1552 { "vlm_load", MVLC_VLM_LOAD },
1553 { "vlm_save", MVLC_VLM_SAVE },
1555 { "rpn", MVLC_RPN },
1556 { "stack", MVLC_STACK },
1558 { "foreach", MVLC_FOREACH },
1559 { "value", MVLC_VALUE },
1562 { "else", MVLC_ELSE },
1563 { "end", MVLC_END },
1564 { "get", MVLC_GET },
1565 { "set", MVLC_SET },
1566 { "int", MVLC_INT },
1567 { "float", MVLC_FLOAT },
1568 { "string", MVLC_STRING },
1571 { NULL, MVLC_UNKNOWN }
1574 static int StrToMacroType( char *name )
1578 if( !name || *name == '\0')
1580 return MVLC_UNKNOWN;
1582 for( i = 0; StrToMacroTypeTab[i].psz_name != NULL; i++ )
1584 if( !strcmp( name, StrToMacroTypeTab[i].psz_name ) )
1586 return StrToMacroTypeTab[i].i_type;
1589 return MVLC_UNKNOWN;
1592 static void MacroDo( httpd_file_sys_t *p_args,
1594 uint8_t *p_request, int i_request,
1595 uint8_t **pp_data, int *pi_data,
1598 intf_thread_t *p_intf = p_args->p_intf;
1599 intf_sys_t *p_sys = p_args->p_intf->p_sys;
1602 #define ALLOC( l ) \
1604 int __i__ = *pp_dst - *pp_data; \
1606 *pp_data = realloc( *pp_data, *pi_data ); \
1607 *pp_dst = (*pp_data) + __i__; \
1609 #define PRINT( str ) \
1610 ALLOC( strlen( str ) + 1 ); \
1611 *pp_dst += sprintf( *pp_dst, str );
1613 #define PRINTS( str, s ) \
1614 ALLOC( strlen( str ) + strlen( s ) + 1 ); \
1616 char * psz_cur = *pp_dst; \
1617 *pp_dst += sprintf( *pp_dst, str, s ); \
1618 while( psz_cur && *psz_cur ) \
1620 /* Prevent script injection */ \
1621 if( *psz_cur == '<' ) *psz_cur = '*'; \
1622 if( *psz_cur == '>' ) *psz_cur = '*'; \
1627 switch( StrToMacroType( m->id ) )
1630 if( i_request <= 0 )
1634 uri_extract_value( p_request, "control", control, 512 );
1635 if( *m->param1 && !strstr( m->param1, control ) )
1637 msg_Warn( p_intf, "unauthorized control=%s", control );
1640 switch( StrToMacroType( control ) )
1647 uri_extract_value( p_request, "item", item, 512 );
1648 i_item = atoi( item );
1649 playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
1650 playlist_ItemGetById( p_sys->p_playlist,
1652 msg_Dbg( p_intf, "requested playlist item: %i", i_item );
1656 playlist_Control( p_sys->p_playlist, PLAYLIST_STOP);
1657 msg_Dbg( p_intf, "requested playlist stop" );
1660 playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
1661 msg_Dbg( p_intf, "requested playlist pause" );
1664 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
1665 msg_Dbg( p_intf, "requested playlist next" );
1668 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1);
1669 msg_Dbg( p_intf, "requested playlist next" );
1671 case MVLC_FULLSCREEN:
1673 if( p_sys->p_input )
1675 vout_thread_t *p_vout;
1676 p_vout = vlc_object_find( p_sys->p_input,
1677 VLC_OBJECT_VOUT, FIND_CHILD );
1681 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1682 vlc_object_release( p_vout );
1683 msg_Dbg( p_intf, "requested fullscreen toggle" );
1697 #define POSITION_ABSOLUTE 12
1698 #define POSITION_REL_FOR 13
1699 #define POSITION_REL_BACK 11
1700 #define VL_TIME_ABSOLUTE 0
1701 #define VL_TIME_REL_FOR 1
1702 #define VL_TIME_REL_BACK -1
1703 if( p_sys->p_input )
1705 uri_extract_value( p_request, "seek_value", value, 20 );
1706 uri_decode_url_encoded( value );
1708 var_Get( p_sys->p_input, "length", &val);
1709 i_length = val.i_time;
1711 while( p_value[0] != '\0' )
1717 i_relative = VL_TIME_REL_FOR;
1723 i_relative = VL_TIME_REL_BACK;
1727 case '0': case '1': case '2': case '3': case '4':
1728 case '5': case '6': case '7': case '8': case '9':
1730 i_stock = strtol( p_value , &p_value , 10 );
1733 case '%': /* for percentage ie position */
1735 i_relative += POSITION_ABSOLUTE;
1743 i_value = 60 * (i_value + i_stock) ;
1748 case 'h': case 'H': /* hours */
1750 i_value += 3600 * i_stock;
1752 /* other characters which are not numbers are not important */
1753 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1759 case 'm': case 'M': case '\'': /* minutes */
1761 i_value += 60 * i_stock;
1764 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1770 case 's': case 'S': case '"': /* seconds */
1774 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1788 /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
1793 case VL_TIME_ABSOLUTE:
1795 if( (uint64_t)( i_value ) * 1000000 <= i_length )
1796 val.i_time = (uint64_t)( i_value ) * 1000000;
1798 val.i_time = i_length;
1800 var_Set( p_sys->p_input, "time", val );
1801 msg_Dbg( p_intf, "requested seek position: %dsec", i_value );
1804 case VL_TIME_REL_FOR:
1806 var_Get( p_sys->p_input, "time", &val );
1807 if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
1809 val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
1812 val.i_time = i_length;
1814 var_Set( p_sys->p_input, "time", val );
1815 msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );
1818 case VL_TIME_REL_BACK:
1820 var_Get( p_sys->p_input, "time", &val );
1821 if( (int64_t)( i_value ) * 1000000 > val.i_time )
1826 val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);
1828 var_Set( p_sys->p_input, "time", val );
1829 msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );
1832 case POSITION_ABSOLUTE:
1834 val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1835 var_Set( p_sys->p_input, "position", val );
1836 msg_Dbg( p_intf, "requested seek percent: %d", i_value );
1839 case POSITION_REL_FOR:
1841 var_Get( p_sys->p_input, "position", &val );
1842 val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1843 var_Set( p_sys->p_input, "position", val );
1844 msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
1847 case POSITION_REL_BACK:
1849 var_Get( p_sys->p_input, "position", &val );
1850 val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1851 var_Set( p_sys->p_input, "position", val );
1852 msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
1857 msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
1862 #undef POSITION_ABSOLUTE
1863 #undef POSITION_REL_FOR
1864 #undef POSITION_REL_BACK
1865 #undef VL_TIME_ABSOLUTE
1866 #undef VL_TIME_REL_FOR
1867 #undef VL_TIME_REL_BACK
1873 audio_volume_t i_volume;
1876 uri_extract_value( p_request, "value", vol, 8 );
1877 aout_VolumeGet( p_intf, &i_volume );
1878 uri_decode_url_encoded( vol );
1882 i_value = atoi( vol + 1 );
1883 if( (i_volume + i_value) > AOUT_VOLUME_MAX )
1885 aout_VolumeSet( p_intf , AOUT_VOLUME_MAX );
1886 msg_Dbg( p_intf, "requested volume set: max" );
1889 aout_VolumeSet( p_intf , (i_volume + i_value) );
1890 msg_Dbg( p_intf, "requested volume set: +%i", (i_volume + i_value) );
1895 i_value = atoi( vol + 1 );
1896 if( (i_volume - i_value) < AOUT_VOLUME_MIN )
1898 aout_VolumeSet( p_intf , AOUT_VOLUME_MIN );
1899 msg_Dbg( p_intf, "requested volume set: min" );
1902 aout_VolumeSet( p_intf , (i_volume - i_value) );
1903 msg_Dbg( p_intf, "requested volume set: -%i", (i_volume - i_value) );
1906 if( strstr(vol, "%") != NULL )
1908 i_value = atoi( vol );
1909 if( (i_value <= 100) && (i_value>=0) ){
1910 aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/100+AOUT_VOLUME_MIN);
1911 msg_Dbg( p_intf, "requested volume set: %i%%", atoi( vol ));
1915 i_value = atoi( vol );
1916 if( ( i_value <= AOUT_VOLUME_MAX ) && ( i_value >= AOUT_VOLUME_MIN ) )
1918 aout_VolumeSet( p_intf , atoi( vol ) );
1919 msg_Dbg( p_intf, "requested volume set: %i", atoi( vol ) );
1925 /* playlist management */
1929 playlist_item_t * p_item;
1931 uri_extract_value( p_request, "mrl", mrl, 512 );
1932 uri_decode_url_encoded( mrl );
1933 p_item = parse_MRL( p_intf, mrl );
1935 if( !p_item || !p_item->input.psz_uri ||
1936 !*p_item->input.psz_uri )
1938 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
1941 playlist_AddItem( p_sys->p_playlist , p_item ,
1942 PLAYLIST_APPEND, PLAYLIST_END );
1943 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
1950 int i_item, *p_items = NULL, i_nb_items = 0;
1951 char item[512], *p_parser = p_request;
1953 /* Get the list of items to delete */
1955 uri_extract_value( p_parser, "item", item, 512 )) )
1957 if( !*item ) continue;
1959 i_item = atoi( item );
1960 p_items = realloc( p_items, (i_nb_items + 1) *
1962 p_items[i_nb_items] = i_item;
1969 for( i = 0; i < i_nb_items; i++ )
1971 playlist_LockDelete( p_sys->p_playlist, p_items[i] );
1972 msg_Dbg( p_intf, "requested playlist delete: %d",
1978 if( p_items ) free( p_items );
1983 int i_item, *p_items = NULL, i_nb_items = 0;
1984 char item[512], *p_parser = p_request;
1987 /* Get the list of items to keep */
1989 uri_extract_value( p_parser, "item", item, 512 )) )
1991 if( !*item ) continue;
1993 i_item = atoi( item );
1994 p_items = realloc( p_items, (i_nb_items + 1) *
1996 p_items[i_nb_items] = i_item;
2000 for( i = p_sys->p_playlist->i_size - 1 ; i >= 0; i-- )
2002 /* Check if the item is in the keep list */
2003 for( j = 0 ; j < i_nb_items ; j++ )
2006 p_sys->p_playlist->pp_items[i]->input.i_id ) break;
2008 if( j == i_nb_items )
2010 playlist_LockDelete( p_sys->p_playlist, p_sys->p_playlist->pp_items[i]->input.i_id );
2011 msg_Dbg( p_intf, "requested playlist delete: %d",
2016 if( p_items ) free( p_items );
2021 playlist_LockClear( p_sys->p_playlist );
2022 msg_Dbg( p_intf, "requested playlist empty" );
2033 uri_extract_value( p_request, "type", type, 12 );
2034 uri_extract_value( p_request, "order", order, 2 );
2035 uri_extract_value( p_request, "item", item, 512 );
2036 i_item = atoi( item );
2038 if( order[0] == '0' ) i_order = ORDER_NORMAL;
2039 else i_order = ORDER_REVERSE;
2041 if( !strcmp( type , "title" ) )
2043 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2044 p_sys->p_playlist->pp_views[0]->p_root,
2045 SORT_TITLE_NODES_FIRST,
2046 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2047 msg_Dbg( p_intf, "requested playlist sort by title (%d)" , i_order );
2048 } else if( !strcmp( type , "author" ) )
2050 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2051 p_sys->p_playlist->pp_views[0]->p_root,
2053 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2054 msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
2055 } else if( !strcmp( type , "shuffle" ) )
2057 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2058 p_sys->p_playlist->pp_views[0]->p_root,
2060 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2061 msg_Dbg( p_intf, "requested playlist shuffle");
2072 uri_extract_value( p_request, "psz_pos", psz_pos, 6 );
2073 uri_extract_value( p_request, "psz_newpos", psz_newpos, 6 );
2074 i_pos = atoi( psz_pos );
2075 i_newpos = atoi( psz_newpos );
2076 if ( i_pos < i_newpos )
2078 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
2080 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
2082 msg_Dbg( p_intf, "requested move playlist item %d to %d", i_pos, i_newpos);
2086 /* admin function */
2090 uri_extract_value( p_request, "id", id, 512 );
2091 msg_Dbg( p_intf, "requested close id=%s", id );
2093 if( p_sys->p_httpd->pf_control( p_sys->p_httpd, HTTPD_SET_CLOSE, id, NULL ) )
2095 msg_Warn( p_intf, "close failed for id=%s", id );
2102 msg_Dbg( p_intf, "requested shutdown" );
2103 p_intf->p_vlc->b_die = VLC_TRUE;
2108 case MVLC_VLM_SETUP:
2110 static const char *vlm_properties[11] =
2113 "enabled", "disabled", "loop", "unloop",
2115 "input", "output", "option", "date", "period", "repeat", "append",
2117 vlm_message_t *vlm_answer;
2119 char *psz = malloc( strlen( p_request ) + 1000 );
2124 if( p_intf->p_sys->p_vlm == NULL )
2125 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2127 if( p_intf->p_sys->p_vlm == NULL ) break;
2129 uri_extract_value( p_request, "name", name, 512 );
2130 if( StrToMacroType( control ) == MVLC_VLM_NEW )
2133 uri_extract_value( p_request, "type", type, 20 );
2134 p += sprintf( psz, "new %s %s", name, type );
2138 p += sprintf( psz, "setup %s", name );
2140 /* Parse the request */
2141 for( i = 0; i < 11; i++ )
2144 uri_extract_value( p_request, vlm_properties[i], val, 512 );
2145 uri_decode_url_encoded( val );
2146 if( strlen( val ) > 0 && i >= 4 )
2148 p += sprintf( p, " %s %s", vlm_properties[i], val );
2150 else if( uri_test_param( p_request, vlm_properties[i] ) && i < 4 )
2152 p += sprintf( p, " %s", vlm_properties[i] );
2155 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2156 if( vlm_answer->psz_value == NULL ) /* there is no error */
2158 vlm_error = strdup( "" );
2162 vlm_error = malloc( strlen(vlm_answer->psz_name) +
2163 strlen(vlm_answer->psz_value) +
2164 strlen( " : ") + 1 );
2165 sprintf( vlm_error , "%s : %s" , vlm_answer->psz_name,
2166 vlm_answer->psz_value );
2169 mvar_AppendNewVar( p_args->vars, "vlm_error", vlm_error );
2171 vlm_MessageDelete( vlm_answer );
2179 vlm_message_t *vlm_answer;
2182 if( p_intf->p_sys->p_vlm == NULL )
2183 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2185 if( p_intf->p_sys->p_vlm == NULL ) break;
2187 uri_extract_value( p_request, "name", name, 512 );
2188 sprintf( psz, "del %s", name );
2190 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2191 /* FIXME do a vlm_answer -> var stack conversion */
2192 vlm_MessageDelete( vlm_answer );
2197 case MVLC_VLM_PAUSE:
2201 vlm_message_t *vlm_answer;
2204 if( p_intf->p_sys->p_vlm == NULL )
2205 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2207 if( p_intf->p_sys->p_vlm == NULL ) break;
2209 uri_extract_value( p_request, "name", name, 512 );
2210 if( StrToMacroType( control ) == MVLC_VLM_PLAY )
2211 sprintf( psz, "control %s play", name );
2212 else if( StrToMacroType( control ) == MVLC_VLM_PAUSE )
2213 sprintf( psz, "control %s pause", name );
2214 else if( StrToMacroType( control ) == MVLC_VLM_STOP )
2215 sprintf( psz, "control %s stop", name );
2216 else if( StrToMacroType( control ) == MVLC_VLM_SEEK )
2219 uri_extract_value( p_request, "percent", percent, 512 );
2220 sprintf( psz, "control %s seek %s", name, percent );
2223 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2224 /* FIXME do a vlm_answer -> var stack conversion */
2225 vlm_MessageDelete( vlm_answer );
2231 vlm_message_t *vlm_answer;
2235 if( p_intf->p_sys->p_vlm == NULL )
2236 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2238 if( p_intf->p_sys->p_vlm == NULL ) break;
2240 uri_extract_value( p_request, "file", file, 512 );
2241 uri_decode_url_encoded( file );
2243 if( StrToMacroType( control ) == MVLC_VLM_LOAD )
2244 sprintf( psz, "load %s", file );
2246 sprintf( psz, "save %s", file );
2248 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2249 /* FIXME do a vlm_answer -> var stack conversion */
2250 vlm_MessageDelete( vlm_answer );
2257 PRINTS( "<!-- control param(%s) unsuported -->", control );
2269 if( i_request <= 0 ||
2270 *m->param1 == '\0' ||
2271 strstr( p_request, m->param1 ) == NULL )
2275 uri_extract_value( p_request, m->param1, value, 512 );
2276 uri_decode_url_encoded( value );
2278 switch( StrToMacroType( m->param2 ) )
2282 config_PutInt( p_intf, m->param1, i );
2286 config_PutFloat( p_intf, m->param1, f );
2289 config_PutPsz( p_intf, m->param1, value );
2292 PRINTS( "<!-- invalid type(%s) in set -->", m->param2 )
2303 if( *m->param1 == '\0' )
2308 switch( StrToMacroType( m->param2 ) )
2311 i = config_GetInt( p_intf, m->param1 );
2312 sprintf( value, "%i", i );
2315 f = config_GetFloat( p_intf, m->param1 );
2316 sprintf( value, "%f", f );
2319 psz = config_GetPsz( p_intf, m->param1 );
2320 sprintf( value, "%s", psz ? psz : "" );
2321 if( psz ) free( psz );
2324 sprintf( value, "invalid type(%s) in set", m->param2 );
2327 msg_Dbg( p_intf, "get name=%s value=%s type=%s", m->param1, value, m->param2 );
2328 PRINTS( "%s", value );
2337 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2338 s = SSPop( &p_args->stack );
2339 v = mvar_GetValue( p_args->vars, s );
2343 v = s = SSPop( &p_args->stack );
2351 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2354 /* Usefull for learning stack management */
2358 msg_Dbg( p_intf, "stack" );
2359 for (i=0;i<(&p_args->stack)->i_stack;i++)
2360 msg_Dbg( p_intf, "%d -> %s", i, (&p_args->stack)->stack[i] );
2366 PRINTS( "<!-- invalid macro id=`%s' -->", m->id );
2367 msg_Dbg( p_intf, "invalid macro id=`%s'", m->id );
2375 static uint8_t *MacroSearch( uint8_t *src, uint8_t *end, int i_mvlc, vlc_bool_t b_after )
2382 if( src + 4 < end && !strncmp( src, "<vlc", 4 ) )
2387 i_skip = MacroParse( &m, src );
2389 i_id = StrToMacroType( m.id );
2406 if( ( i_mvlc == MVLC_END && i_level == -1 ) ||
2407 ( i_mvlc != MVLC_END && i_level == 0 && i_mvlc == i_id ) )
2409 return src + ( b_after ? i_skip : 0 );
2411 else if( i_level < 0 )
2427 static void Execute( httpd_file_sys_t *p_args,
2428 uint8_t *p_request, int i_request,
2429 uint8_t **pp_data, int *pi_data,
2431 uint8_t *_src, uint8_t *_end )
2433 intf_thread_t *p_intf = p_args->p_intf;
2435 uint8_t *src, *dup, *end;
2436 uint8_t *dst = *pp_dst;
2438 src = dup = malloc( _end - _src + 1 );
2439 end = src +( _end - _src );
2441 memcpy( src, _src, _end - _src );
2444 /* we parse searching <vlc */
2450 p = strstr( src, "<vlc" );
2451 if( p < end && p == src )
2455 src += MacroParse( &m, src );
2457 //msg_Dbg( p_intf, "macro_id=%s", m.id );
2459 switch( StrToMacroType( m.id ) )
2466 EvaluateRPN( p_args->vars, &p_args->stack, m.param1 );
2467 if( SSPopN( &p_args->stack, p_args->vars ) )
2475 endif = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2479 uint8_t *start = MacroSearch( src, endif, MVLC_ELSE, VLC_TRUE );
2483 uint8_t *stop = MacroSearch( start, endif, MVLC_END, VLC_FALSE );
2486 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2490 else if( i_test == 1 )
2493 if( ( stop = MacroSearch( src, endif, MVLC_ELSE, VLC_FALSE ) ) == NULL )
2495 stop = MacroSearch( src, endif, MVLC_END, VLC_FALSE );
2499 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, src, stop );
2508 uint8_t *endfor = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2509 uint8_t *start = src;
2510 uint8_t *stop = MacroSearch( src, end, MVLC_END, VLC_FALSE );
2517 if( !strcmp( m.param2, "integer" ) )
2519 char *arg = SSPop( &p_args->stack );
2520 index = mvar_IntegerSetNew( m.param1, arg );
2523 else if( !strcmp( m.param2, "directory" ) )
2525 char *arg = SSPop( &p_args->stack );
2526 index = mvar_FileSetNew( m.param1, arg );
2529 else if( !strcmp( m.param2, "playlist" ) )
2531 index = mvar_PlaylistSetNew( m.param1, p_intf->p_sys->p_playlist );
2533 else if( !strcmp( m.param2, "information" ) )
2535 index = mvar_InfoSetNew( m.param1, p_intf->p_sys->p_input );
2537 else if( !strcmp( m.param2, "vlm" ) )
2539 if( p_intf->p_sys->p_vlm == NULL )
2540 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2541 index = mvar_VlmSetNew( m.param1, p_intf->p_sys->p_vlm );
2544 else if( !strcmp( m.param2, "hosts" ) )
2546 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_HOSTS );
2548 else if( !strcmp( m.param2, "urls" ) )
2550 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_URLS );
2552 else if( !strcmp( m.param2, "connections" ) )
2554 index = mvar_HttpdInfoSetNew(m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_CONNECTIONS);
2557 else if( ( v = mvar_GetVar( p_args->vars, m.param2 ) ) )
2559 index = mvar_Duplicate( v );
2563 msg_Dbg( p_intf, "invalid index constructor (%s)", m.param2 );
2568 for( i_idx = 0; i_idx < index->i_field; i_idx++ )
2570 mvar_t *f = mvar_Duplicate( index->field[i_idx] );
2572 //msg_Dbg( p_intf, "foreach field[%d] name=%s value=%s", i_idx, f->name, f->value );
2575 f->name = strdup( m.param1 );
2578 mvar_PushVar( p_args->vars, f );
2579 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2580 mvar_RemoveVar( p_args->vars, f );
2584 mvar_Delete( index );
2591 MacroDo( p_args, &m, p_request, i_request, pp_data, pi_data, &dst );
2599 i_copy = ( (p == NULL || p > end ) ? end : p ) - src;
2602 int i_index = dst - *pp_data;
2605 *pp_data = realloc( *pp_data, *pi_data );
2606 dst = (*pp_data) + i_index;
2608 memcpy( dst, src, i_copy );
2618 /****************************************************************************
2620 ****************************************************************************
2621 * a file with b_html is parsed and all "macro" replaced
2622 * <vlc id="macro name" [param1="" [param2=""]] />
2625 ****************************************************************************/
2626 static int HttpCallback( httpd_file_sys_t *p_args,
2627 httpd_file_t *p_file,
2629 uint8_t **pp_data, int *pi_data )
2631 int i_request = p_request ? strlen( p_request ) : 0;
2635 if( ( f = fopen( p_args->file, "r" ) ) == NULL )
2637 p = *pp_data = malloc( 10240 );
2640 return VLC_EGENERIC;
2642 p += sprintf( p, "<html>\n" );
2643 p += sprintf( p, "<head>\n" );
2644 p += sprintf( p, "<title>Error loading %s</title>\n", p_args->file );
2645 p += sprintf( p, "</head>\n" );
2646 p += sprintf( p, "<body>\n" );
2647 p += sprintf( p, "<h1><center>Error loading %s for %s</center></h1>\n", p_args->file, p_args->name );
2648 p += sprintf( p, "<hr />\n" );
2649 p += sprintf( p, "<a href=\"http://www.videolan.org/\">VideoLAN</a>\n" );
2650 p += sprintf( p, "</body>\n" );
2651 p += sprintf( p, "</html>\n" );
2653 *pi_data = strlen( *pp_data );
2658 if( !p_args->b_html )
2660 FileLoad( f, pp_data, pi_data );
2668 char position[4]; /* percentage */
2669 char time[12]; /* in seconds */
2670 char length[12]; /* in seconds */
2671 audio_volume_t i_volume;
2675 #define p_sys p_args->p_intf->p_sys
2676 if( p_sys->p_input )
2678 var_Get( p_sys->p_input, "position", &val);
2679 sprintf( position, "%d" , (int)((val.f_float) * 100.0));
2680 var_Get( p_sys->p_input, "time", &val);
2681 sprintf( time, "%d" , (int)(val.i_time / 1000000) );
2682 var_Get( p_sys->p_input, "length", &val);
2683 sprintf( length, "%d" , (int)(val.i_time / 1000000) );
2685 var_Get( p_sys->p_input, "state", &val );
2686 if( val.i_int == PLAYING_S )
2688 sprintf( state, "playing" );
2689 } else if( val.i_int == PAUSE_S )
2691 sprintf( state, "paused" );
2694 sprintf( state, "stop" );
2698 sprintf( position, "%d", 0 );
2699 sprintf( time, "%d", 0 );
2700 sprintf( length, "%d", 0 );
2701 sprintf( state, "stop" );
2705 aout_VolumeGet( p_args->p_intf , &i_volume );
2706 sprintf( volume , "%d" , (int)i_volume );
2708 p_args->vars = mvar_New( "variables", "" );
2709 mvar_AppendNewVar( p_args->vars, "url_param", i_request > 0 ? "1" : "0" );
2710 mvar_AppendNewVar( p_args->vars, "url_value", p_request );
2711 mvar_AppendNewVar( p_args->vars, "version", VERSION_MESSAGE );
2712 mvar_AppendNewVar( p_args->vars, "copyright", COPYRIGHT_MESSAGE );
2713 mvar_AppendNewVar( p_args->vars, "stream_position", position );
2714 mvar_AppendNewVar( p_args->vars, "stream_time", time );
2715 mvar_AppendNewVar( p_args->vars, "stream_length", length );
2716 mvar_AppendNewVar( p_args->vars, "volume", volume );
2717 mvar_AppendNewVar( p_args->vars, "stream_state", state );
2719 SSInit( &p_args->stack );
2721 /* first we load in a temporary buffer */
2722 FileLoad( f, &p_buffer, &i_buffer );
2724 /* allocate output */
2725 *pi_data = i_buffer + 1000;
2726 dst = *pp_data = malloc( *pi_data );
2728 /* we parse executing all <vlc /> macros */
2729 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, &p_buffer[0], &p_buffer[i_buffer] );
2732 *pi_data = dst - *pp_data;
2734 SSClean( &p_args->stack );
2735 mvar_Delete( p_args->vars );
2744 /****************************************************************************
2746 ****************************************************************************/
2747 static int uri_test_param( char *psz_uri, const char *psz_name )
2751 while( (p = strstr( p, psz_name )) )
2753 /* Verify that we are dealing with a post/get argument */
2754 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2763 static char *uri_extract_value( char *psz_uri, const char *psz_name,
2764 char *psz_value, int i_value_max )
2768 while( (p = strstr( p, psz_name )) )
2770 /* Verify that we are dealing with a post/get argument */
2771 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2780 p += strlen( psz_name );
2781 if( *p == '=' ) p++;
2783 if( strchr( p, '&' ) )
2785 i_len = strchr( p, '&' ) - p;
2789 /* for POST method */
2790 if( strchr( p, '\n' ) )
2792 i_len = strchr( p, '\n' ) - p;
2793 if( i_len && *(p+i_len-1) == '\r' ) i_len--;
2797 i_len = strlen( p );
2800 i_len = __MIN( i_value_max - 1, i_len );
2803 strncpy( psz_value, p, i_len );
2804 psz_value[i_len] = '\0';
2808 strncpy( psz_value, "", i_value_max );
2814 strncpy( psz_value, "", i_value_max );
2820 static void uri_decode_url_encoded( char *psz )
2822 char *dup = strdup( psz );
2840 *psz++ = strtol( val, NULL, 16 );
2842 else if( *p == '+' )
2856 /****************************************************************************
2857 * Light RPN evaluator
2858 ****************************************************************************/
2859 static void SSInit( rpn_stack_t *st )
2864 static void SSClean( rpn_stack_t *st )
2866 while( st->i_stack > 0 )
2868 free( st->stack[--st->i_stack] );
2872 static void SSPush( rpn_stack_t *st, char *s )
2874 if( st->i_stack < STACK_MAX )
2876 st->stack[st->i_stack++] = strdup( s );
2880 static char * SSPop( rpn_stack_t *st )
2882 if( st->i_stack <= 0 )
2884 return strdup( "" );
2888 return st->stack[--st->i_stack];
2892 static int SSPopN( rpn_stack_t *st, mvar_t *vars )
2901 i = strtol( name, &end, 0 );
2904 value = mvar_GetValue( vars, name );
2912 static void SSPushN( rpn_stack_t *st, int i )
2916 sprintf( v, "%d", i );
2920 static void EvaluateRPN( mvar_t *vars, rpn_stack_t *st, char *exp )
2927 while( *exp == ' ' )
2934 /* extract string */
2937 while( *exp && *exp != '\'' )
2948 p = strchr( exp, ' ' );
2953 exp += strlen( exp );
2958 strncpy( s, exp, i );
2969 /* 1. Integer function */
2970 if( !strcmp( s, "!" ) )
2972 SSPushN( st, ~SSPopN( st, vars ) );
2974 else if( !strcmp( s, "^" ) )
2976 SSPushN( st, SSPopN( st, vars ) ^ SSPopN( st, vars ) );
2978 else if( !strcmp( s, "&" ) )
2980 SSPushN( st, SSPopN( st, vars ) & SSPopN( st, vars ) );
2982 else if( !strcmp( s, "|" ) )
2984 SSPushN( st, SSPopN( st, vars ) | SSPopN( st, vars ) );
2986 else if( !strcmp( s, "+" ) )
2988 SSPushN( st, SSPopN( st, vars ) + SSPopN( st, vars ) );
2990 else if( !strcmp( s, "-" ) )
2992 int j = SSPopN( st, vars );
2993 int i = SSPopN( st, vars );
2994 SSPushN( st, i - j );
2996 else if( !strcmp( s, "*" ) )
2998 SSPushN( st, SSPopN( st, vars ) * SSPopN( st, vars ) );
3000 else if( !strcmp( s, "/" ) )
3004 j = SSPopN( st, vars );
3005 i = SSPopN( st, vars );
3007 SSPushN( st, j != 0 ? i / j : 0 );
3009 else if( !strcmp( s, "%" ) )
3013 j = SSPopN( st, vars );
3014 i = SSPopN( st, vars );
3016 SSPushN( st, j != 0 ? i % j : 0 );
3018 /* 2. integer tests */
3019 else if( !strcmp( s, "=" ) )
3021 SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 );
3023 else if( !strcmp( s, "!=" ) )
3025 SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 );
3027 else if( !strcmp( s, "<" ) )
3029 int j = SSPopN( st, vars );
3030 int i = SSPopN( st, vars );
3032 SSPushN( st, i < j ? -1 : 0 );
3034 else if( !strcmp( s, ">" ) )
3036 int j = SSPopN( st, vars );
3037 int i = SSPopN( st, vars );
3039 SSPushN( st, i > j ? -1 : 0 );
3041 else if( !strcmp( s, "<=" ) )
3043 int j = SSPopN( st, vars );
3044 int i = SSPopN( st, vars );
3046 SSPushN( st, i <= j ? -1 : 0 );
3048 else if( !strcmp( s, ">=" ) )
3050 int j = SSPopN( st, vars );
3051 int i = SSPopN( st, vars );
3053 SSPushN( st, i >= j ? -1 : 0 );
3055 /* 3. string functions */
3056 else if( !strcmp( s, "strcat" ) )
3058 char *s2 = SSPop( st );
3059 char *s1 = SSPop( st );
3060 char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
3070 else if( !strcmp( s, "strcmp" ) )
3072 char *s2 = SSPop( st );
3073 char *s1 = SSPop( st );
3075 SSPushN( st, strcmp( s1, s2 ) );
3079 else if( !strcmp( s, "strncmp" ) )
3081 int n = SSPopN( st, vars );
3082 char *s2 = SSPop( st );
3083 char *s1 = SSPop( st );
3085 SSPushN( st, strncmp( s1, s2 , n ) );
3089 else if( !strcmp( s, "strsub" ) )
3091 int n = SSPopN( st, vars );
3092 int m = SSPopN( st, vars );
3094 char *s = SSPop( st );
3106 str = malloc( i_len + 1 );
3108 memcpy( str, s + m - 1, i_len );
3109 str[ i_len ] = '\0';
3115 else if( !strcmp( s, "strlen" ) )
3117 char *str = SSPop( st );
3119 SSPushN( st, strlen( str ) );
3122 /* 4. stack functions */
3123 else if( !strcmp( s, "dup" ) )
3125 char *str = SSPop( st );
3130 else if( !strcmp( s, "drop" ) )
3132 char *str = SSPop( st );
3135 else if( !strcmp( s, "swap" ) )
3137 char *s1 = SSPop( st );
3138 char *s2 = SSPop( st );
3145 else if( !strcmp( s, "flush" ) )
3150 else if( !strcmp( s, "store" ) )
3152 char *value = SSPop( st );
3153 char *name = SSPop( st );
3155 mvar_PushNewVar( vars, name, value );
3159 else if( !strcmp( s, "value" ) )
3161 char *name = SSPop( st );
3162 char *value = mvar_GetValue( vars, name );
3164 SSPush( st, value );
3168 else if( !strcmp( s, "url_extract" ) )
3170 char *url = mvar_GetValue( vars, "url_value" );
3171 char *name = SSPop( st );
3174 uri_extract_value( url, name, value, 512 );
3175 uri_decode_url_encoded( value );
3176 SSPush( st, value );
3185 /**********************************************************************
3186 * Find_end_MRL: Find the end of the sentence :
3187 * this function parses the string psz and find the end of the item
3188 * and/or option with detecting the " and ' problems.
3189 * returns NULL if an error is detected, otherwise, returns a pointer
3190 * of the end of the sentence (after the last character)
3191 **********************************************************************/
3192 static char *Find_end_MRL( char *psz )
3202 while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) )
3204 if( *s_sent == '\'' )
3206 s_sent = Find_end_MRL( s_sent );
3208 if( s_sent == NULL )
3218 if( *s_sent == '\"' )
3222 } else /* *s_sent == '\0' , which means the number of " is incorrect */
3232 while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) )
3234 if( *s_sent == '\"' )
3236 s_sent = Find_end_MRL( s_sent );
3238 if( s_sent == NULL )
3248 if( *s_sent == '\'' )
3252 } else /* *s_sent == '\0' , which means the number of ' is incorrect */
3258 default: /* now we can look for spaces */
3260 while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) )
3262 if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) )
3264 s_sent = Find_end_MRL( s_sent );
3275 /**********************************************************************
3276 * parse_MRL: parse the MRL, find the mrl string and the options,
3277 * create an item with all information in it, and return the item.
3278 * return NULL if there is an error.
3279 **********************************************************************/
3280 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz )
3282 char **ppsz_options = NULL;
3289 playlist_item_t * p_item = NULL;
3291 /* In case there is spaces before the mrl */
3292 while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
3297 /* extract the mrl */
3298 s_temp = strstr( s_mrl , " :" );
3299 if( s_temp == NULL )
3301 s_temp = s_mrl + strlen( s_mrl );
3304 while( (*s_temp == ' ') && (s_temp != s_mrl ) )
3311 /* if the mrl is between " or ', we must remove them */
3312 if( (*s_mrl == '\'') || (*s_mrl == '\"') )
3314 mrl = (char *)malloc( (s_temp - s_mrl - 1) * sizeof( char ) );
3315 strncpy( mrl , (s_mrl + 1) , s_temp - s_mrl - 2 );
3316 mrl[ s_temp - s_mrl - 2 ] = '\0';
3319 mrl = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) );
3320 strncpy( mrl , s_mrl , s_temp - s_mrl );
3321 mrl[ s_temp - s_mrl ] = '\0';
3326 /* now we can take care of the options */
3327 while( (*s_mrl != '\0') && (i_error == 0) )
3336 case ':': /* an option */
3338 s_temp = Find_end_MRL( s_mrl );
3340 if( s_temp == NULL )
3347 ppsz_options = realloc( ppsz_options , i_options *
3349 ppsz_options[ i_options - 1 ] =
3350 malloc( (s_temp - s_mrl + 1) * sizeof(char) );
3352 strncpy( ppsz_options[ i_options - 1 ] , s_mrl ,
3355 /* don't forget to finish the string with a '\0' */
3356 (ppsz_options[ i_options - 1 ])[ s_temp - s_mrl ] = '\0';
3376 /* now create an item */
3377 p_item = playlist_ItemNew( p_intf, mrl, mrl);
3378 for( i = 0 ; i< i_options ; i++ )
3380 playlist_ItemAddOption( p_item, ppsz_options[i] );
3384 for( i = 0; i < i_options; i++ ) free( ppsz_options[i] );
3385 if( i_options ) free( ppsz_options );