1 /*****************************************************************************
2 * http.c : http mini-server ;)
3 *****************************************************************************
4 * Copyright (C) 2001-2005 the VideoLAN team
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"
46 #ifdef HAVE_SYS_STAT_H
47 # include <sys/stat.h>
58 #elif defined( WIN32 ) && !defined( UNDER_CE )
66 /* stat() support for large files on win32 */
67 #if defined( WIN32 ) && !defined( UNDER_CE )
68 # define stat _stati64
71 /*****************************************************************************
73 *****************************************************************************/
74 static int Open ( vlc_object_t * );
75 static void Close( vlc_object_t * );
77 #define HOST_TEXT N_( "Host address" )
78 #define HOST_LONGTEXT N_( \
79 "You can set the address and port the http interface will bind to." )
80 #define SRC_TEXT N_( "Source directory" )
81 #define SRC_LONGTEXT N_( "Source directory" )
82 #define CERT_TEXT N_( "Certificate file" )
83 #define CERT_LONGTEXT N_( "HTTP interface x509 PEM certificate file " \
85 #define KEY_TEXT N_( "Private key file" )
86 #define KEY_LONGTEXT N_( "HTTP interface x509 PEM private key file" )
87 #define CA_TEXT N_( "Root CA file" )
88 #define CA_LONGTEXT N_( "HTTP interface x509 PEM trusted root CA " \
90 #define CRL_TEXT N_( "CRL file" )
91 #define CRL_LONGTEXT N_( "HTTP interace Certificates Revocation List file" )
94 set_shortname( _("HTTP"));
95 set_description( _("HTTP remote control interface") );
96 set_category( CAT_INTERFACE );
97 set_subcategory( SUBCAT_INTERFACE_GENERAL );
98 add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
99 add_string ( "http-src", NULL, NULL, SRC_TEXT, SRC_LONGTEXT, VLC_TRUE );
100 set_section( N_("HTTP SSL" ), 0 );
101 add_string ( "http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT, VLC_TRUE );
102 add_string ( "http-intf-key", NULL, NULL, KEY_TEXT, KEY_LONGTEXT, VLC_TRUE );
103 add_string ( "http-intf-ca", NULL, NULL, CA_TEXT, CA_LONGTEXT, VLC_TRUE );
104 add_string ( "http-intf-crl", NULL, NULL, CRL_TEXT, CRL_LONGTEXT, VLC_TRUE );
105 set_capability( "interface", 0 );
106 set_callbacks( Open, Close );
110 /*****************************************************************************
112 *****************************************************************************/
113 static void Run ( intf_thread_t *p_intf );
115 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
118 static int DirectoryCheck( char *psz_dir )
122 #ifdef HAVE_SYS_STAT_H
123 struct stat stat_info;
125 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
131 if( ( p_dir = opendir( psz_dir ) ) == NULL )
140 static int HttpCallback( httpd_file_sys_t *p_args,
143 uint8_t **pp_data, int *pi_data );
145 static char *uri_extract_value( char *psz_uri, const char *psz_name,
146 char *psz_value, int i_value_max );
147 static int uri_test_param( char *psz_uri, const char *psz_name );
149 static void uri_decode_url_encoded( char *psz );
151 static char *Find_end_MRL( char *psz );
152 static playlist_item_t *parse_MRL( intf_thread_t * , char *psz );
154 /*****************************************************************************
156 *****************************************************************************/
157 typedef struct mvar_s
163 struct mvar_s **field;
166 #define STACK_MAX 100
169 char *stack[STACK_MAX];
173 struct httpd_file_sys_t
175 intf_thread_t *p_intf;
176 httpd_file_t *p_file;
177 httpd_redirect_t *p_redir;
178 httpd_redirect_t *p_redir2;
185 /* inited for each access */
192 httpd_host_t *p_httpd_host;
195 httpd_file_sys_t **pp_files;
197 playlist_t *p_playlist;
198 input_thread_t *p_input;
205 /*****************************************************************************
206 * Activate: initialize and create stuff
207 *****************************************************************************/
208 static int Open( vlc_object_t *p_this )
210 intf_thread_t *p_intf = (intf_thread_t*)p_this;
213 char *psz_address = "";
214 const char *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL,
219 psz_host = config_GetPsz( p_intf, "http-host" );
223 psz_address = psz_host;
225 psz_parser = strchr( psz_host, ':' );
228 *psz_parser++ = '\0';
229 i_port = atoi( psz_parser );
233 p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
236 return( VLC_ENOMEM );
238 p_sys->p_playlist = NULL;
239 p_sys->p_input = NULL;
242 /* determine Content-Type value for HTML pages */
243 vlc_current_charset(&psz_src);
244 if( psz_src == NULL )
249 p_sys->psz_html_type = malloc( 20 + strlen( psz_src ) );
250 if( p_sys->psz_html_type == NULL )
256 sprintf( p_sys->psz_html_type, "text/html; charset=%s", psz_src );
259 /* determine SSL configuration */
260 psz_cert = config_GetPsz( p_intf, "http-intf-cert" );
261 if ( psz_cert != NULL )
263 msg_Dbg( p_intf, "enablind TLS for HTTP interface (cert file: %s)",
265 psz_key = config_GetPsz( p_intf, "http-intf-key" );
266 psz_ca = config_GetPsz( p_intf, "http-intf-ca" );
267 psz_crl = config_GetPsz( p_intf, "http-intf-crl" );
278 msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
280 p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
281 i_port, psz_cert, psz_key, psz_ca,
283 if( p_sys->p_httpd_host == NULL )
285 msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
286 free( p_sys->psz_html_type );
297 p_sys->pp_files = NULL;
299 #if defined(SYS_DARWIN) || defined(SYS_BEOS) || defined(WIN32)
300 if ( ( psz_src = config_GetPsz( p_intf, "http-src" )) == NULL )
302 char * psz_vlcpath = p_intf->p_libvlc->psz_vlcpath;
303 psz_src = malloc( strlen(psz_vlcpath) + strlen("/share/http" ) + 1 );
304 if( !psz_src ) return VLC_ENOMEM;
306 sprintf( psz_src, "%s/http", psz_vlcpath);
308 sprintf( psz_src, "%s/share/http", psz_vlcpath);
312 psz_src = config_GetPsz( p_intf, "http-src" );
314 if( !psz_src || *psz_src == '\0' )
316 if( !DirectoryCheck( "share/http" ) )
318 psz_src = strdup( "share/http" );
320 else if( !DirectoryCheck( DATA_PATH "/http" ) )
322 psz_src = strdup( DATA_PATH "/http" );
327 if( !psz_src || *psz_src == '\0' )
329 msg_Err( p_intf, "invalid src dir" );
333 /* remove trainling \ or / */
334 if( psz_src[strlen( psz_src ) - 1] == '\\' ||
335 psz_src[strlen( psz_src ) - 1] == '/' )
337 psz_src[strlen( psz_src ) - 1] = '\0';
340 ParseDirectory( p_intf, psz_src, psz_src );
343 if( p_sys->i_files <= 0 )
345 msg_Err( p_intf, "cannot find any files (%s)", psz_src );
348 p_intf->pf_run = Run;
354 if( psz_src ) free( psz_src );
355 if( p_sys->pp_files )
357 free( p_sys->pp_files );
359 httpd_HostDelete( p_sys->p_httpd_host );
360 free( p_sys->psz_html_type );
365 /*****************************************************************************
366 * CloseIntf: destroy interface
367 *****************************************************************************/
368 void Close ( vlc_object_t *p_this )
370 intf_thread_t *p_intf = (intf_thread_t *)p_this;
371 intf_sys_t *p_sys = p_intf->p_sys;
377 vlm_Delete( p_sys->p_vlm );
379 for( i = 0; i < p_sys->i_files; i++ )
381 httpd_FileDelete( p_sys->pp_files[i]->p_file );
382 if( p_sys->pp_files[i]->p_redir )
383 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir );
384 if( p_sys->pp_files[i]->p_redir2 )
385 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir2 );
387 free( p_sys->pp_files[i]->file );
388 free( p_sys->pp_files[i]->name );
389 free( p_sys->pp_files[i] );
391 if( p_sys->pp_files )
393 free( p_sys->pp_files );
395 httpd_HostDelete( p_sys->p_httpd_host );
397 free( p_sys->psz_html_type );
401 /*****************************************************************************
402 * Run: http interface thread
403 *****************************************************************************/
404 static void Run( intf_thread_t *p_intf )
406 intf_sys_t *p_sys = p_intf->p_sys;
408 while( !p_intf->b_die )
410 /* get the playlist */
411 if( p_sys->p_playlist == NULL )
413 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
416 /* Manage the input part */
417 if( p_sys->p_input == NULL )
419 if( p_sys->p_playlist )
422 vlc_object_find( p_sys->p_playlist,
427 else if( p_sys->p_input->b_dead )
429 vlc_object_release( p_sys->p_input );
430 p_sys->p_input = NULL;
435 msleep( INTF_IDLE_SLEEP );
440 vlc_object_release( p_sys->p_input );
441 p_sys->p_input = NULL;
444 if( p_sys->p_playlist )
446 vlc_object_release( p_sys->p_playlist );
447 p_sys->p_playlist = NULL;
452 /*****************************************************************************
454 *****************************************************************************/
455 #define MAX_DIR_SIZE 10240
457 /****************************************************************************
458 * FileToUrl: create a good name for an url from filename
459 ****************************************************************************/
460 static char *FileToUrl( char *name, vlc_bool_t *pb_index )
464 url = p = malloc( strlen( name ) + 1 );
466 *pb_index = VLC_FALSE;
473 while( *name == '\\' || *name == '/' )
475 while( *name == '/' )
485 /* convert '\\' into '/' */
498 if( ( p = strrchr( url, '/' ) ) != NULL )
500 if( !strncmp( p, "/index.", 7 ) )
503 *pb_index = VLC_TRUE;
509 /****************************************************************************
510 * ParseDirectory: parse recursively a directory, adding each file
511 ****************************************************************************/
512 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
515 intf_sys_t *p_sys = p_intf->p_sys;
516 char dir[MAX_DIR_SIZE];
517 #ifdef HAVE_SYS_STAT_H
518 struct stat stat_info;
521 struct dirent *p_dir_content;
526 char *password = NULL;
530 #ifdef HAVE_SYS_STAT_H
531 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
537 if( ( p_dir = opendir( psz_dir ) ) == NULL )
539 msg_Err( p_intf, "cannot open dir (%s)", psz_dir );
543 i_dirlen = strlen( psz_dir );
544 if( i_dirlen + 10 > MAX_DIR_SIZE )
546 msg_Warn( p_intf, "skipping too deep dir (%s)", psz_dir );
550 msg_Dbg( p_intf, "dir=%s", psz_dir );
552 sprintf( dir, "%s/.access", psz_dir );
553 if( ( file = fopen( dir, "r" ) ) != NULL )
558 msg_Dbg( p_intf, "find .access in dir=%s", psz_dir );
560 i_size = fread( line, 1, 1023, file );
564 while( i_size > 0 && ( line[i_size-1] == '\n' ||
565 line[i_size-1] == '\r' ) )
572 p = strchr( line, ':' );
576 user = strdup( line );
577 password = strdup( p );
580 msg_Dbg( p_intf, "using user=%s password=%s (read=%d)",
581 user, password, i_size );
586 sprintf( dir, "%s/.hosts", psz_dir );
587 p_acl = ACL_Create( p_intf, VLC_FALSE );
588 ACL_LoadFile( p_acl, dir );
593 /* parse psz_src dir */
594 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
599 if( ( p_dir_content->d_name[0] == '.' )
600 || ( i_dirlen + strlen( p_dir_content->d_name ) > MAX_DIR_SIZE ) )
603 sprintf( dir, "%s/%s", psz_dir, p_dir_content->d_name );
604 if( ParseDirectory( p_intf, psz_root, dir ) )
606 httpd_file_sys_t *f = malloc( sizeof( httpd_file_sys_t ) );
613 f->file = strdup( dir );
614 f->name = FileToUrl( &dir[strlen( psz_root )], &b_index );
615 f->b_html = strstr( &dir[strlen( psz_root )], ".htm" ) ? VLC_TRUE : VLC_FALSE;
619 msg_Err( p_intf , "unable to parse directory" );
622 return( VLC_ENOMEM );
624 msg_Dbg( p_intf, "file=%s (url=%s)",
627 f->p_file = httpd_FileNew( p_sys->p_httpd_host,
629 f->b_html ? p_sys->psz_html_type : NULL,
630 user, password, p_acl,
635 TAB_APPEND( p_sys->i_files, p_sys->pp_files, f );
637 /* for url that ends by / add
638 * - a redirect from rep to rep/
639 * - in case of index.* rep/index.html to rep/ */
640 if( f && f->name[strlen(f->name) - 1] == '/' )
642 char *psz_redir = strdup( f->name );
644 psz_redir[strlen( psz_redir ) - 1] = '\0';
646 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
647 f->p_redir = httpd_RedirectNew( p_sys->p_httpd_host, f->name, psz_redir );
650 if( b_index && ( p = strstr( f->file, "index." ) ) )
652 asprintf( &psz_redir, "%s%s", f->name, p );
654 msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
655 f->p_redir2 = httpd_RedirectNew( p_sys->p_httpd_host,
656 f->name, psz_redir );
673 ACL_Destroy( p_acl );
679 /****************************************************************************
680 * var and set handling
681 ****************************************************************************/
683 static mvar_t *mvar_New( char *name, char *value )
685 mvar_t *v = malloc( sizeof( mvar_t ) );
687 if( !v ) return NULL;
688 v->name = strdup( name );
689 v->value = strdup( value ? value : "" );
692 v->field = malloc( sizeof( mvar_t * ) );
698 static void mvar_Delete( mvar_t *v )
705 for( i = 0; i < v->i_field; i++ )
707 mvar_Delete( v->field[i] );
713 static void mvar_AppendVar( mvar_t *v, mvar_t *f )
715 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
716 v->field[v->i_field] = f;
720 static mvar_t *mvar_Duplicate( mvar_t *v )
725 n = mvar_New( v->name, v->value );
726 for( i = 0; i < v->i_field; i++ )
728 mvar_AppendVar( n, mvar_Duplicate( v->field[i] ) );
734 static void mvar_PushVar( mvar_t *v, mvar_t *f )
736 v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
739 memmove( &v->field[1], &v->field[0], sizeof( mvar_t * ) * v->i_field );
745 static void mvar_RemoveVar( mvar_t *v, mvar_t *f )
748 for( i = 0; i < v->i_field; i++ )
750 if( v->field[i] == f )
755 if( i >= v->i_field )
760 if( i + 1 < v->i_field )
762 memmove( &v->field[i], &v->field[i+1], sizeof( mvar_t * ) * ( v->i_field - i - 1 ) );
765 /* FIXME should do a realloc */
768 static mvar_t *mvar_GetVar( mvar_t *s, char *name )
771 char base[512], *field, *p;
774 /* format: name[index].field */
776 field = strchr( name, '.' );
779 int i = field - name;
780 strncpy( base, name, i );
786 strcpy( base, name );
789 if( ( p = strchr( base, '[' ) ) )
792 sscanf( p, "%d]", &i_index );
803 for( i = 0; i < s->i_field; i++ )
805 if( !strcmp( s->field[i]->name, base ) )
815 return mvar_GetVar( s->field[i], field );
829 static char *mvar_GetValue( mvar_t *v, char *field )
837 mvar_t *f = mvar_GetVar( v, field );
849 static void mvar_PushNewVar( mvar_t *vars, char *name, char *value )
851 mvar_t *f = mvar_New( name, value );
852 mvar_PushVar( vars, f );
855 static void mvar_AppendNewVar( mvar_t *vars, char *name, char *value )
857 mvar_t *f = mvar_New( name, value );
858 mvar_AppendVar( vars, f );
862 /* arg= start[:stop[:step]],.. */
863 static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
865 char *dup = strdup( arg );
867 mvar_t *s = mvar_New( name, "set" );
873 int i_start,i_stop,i_step;
876 p = strchr( str, ',' );
883 i_match = sscanf( str, "%d:%d:%d", &i_start, &i_stop, &i_step );
890 else if( i_match == 2 )
892 i_step = i_start < i_stop ? 1 : -1;
899 if( ( i_start <= i_stop && i_step > 0 ) ||
900 ( i_start >= i_stop && i_step < 0 ) )
902 for( i = i_start; ; i += i_step )
906 if( ( i_step > 0 && i > i_stop ) ||
907 ( i_step < 0 && i < i_stop ) )
912 sprintf( value, "%d", i );
914 mvar_PushNewVar( s, name, value );
925 void PlaylistListNode( playlist_t *p_pl, playlist_item_t *p_node,
926 char *name, mvar_t *s, int i_depth )
930 if (p_node->i_children == -1)
933 mvar_t *itm = mvar_New( name, "set" );
935 sprintf( value, "%d", ( p_pl->status.p_item == p_node )? 1 : 0 );
936 mvar_AppendNewVar( itm, "current", value );
938 sprintf( value, "%d", p_node->input.i_id );
939 mvar_AppendNewVar( itm, "index", value );
941 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
943 mvar_AppendNewVar( itm, "uri", p_node->input.psz_uri );
945 sprintf( value, "Item");
946 mvar_AppendNewVar( itm, "type", value );
948 sprintf( value, "%d", i_depth );
949 mvar_AppendNewVar( itm, "depth", value );
951 mvar_AppendVar( s, itm );
957 mvar_t *itm = mvar_New( name, "set" );
959 mvar_AppendNewVar( itm, "name", p_node->input.psz_name );
960 mvar_AppendNewVar( itm, "uri", p_node->input.psz_name );
962 sprintf( value, "Node" );
963 mvar_AppendNewVar( itm, "type", value );
965 sprintf( value, "%d", p_node->input.i_id );
966 mvar_AppendNewVar( itm, "index", value );
968 sprintf( value, "%d", p_node->i_children);
969 mvar_AppendNewVar( itm, "i_children", value );
971 sprintf( value, "%d", i_depth );
972 mvar_AppendNewVar( itm, "depth", value );
974 mvar_AppendVar( s, itm );
976 for (i_child = 0 ; i_child < p_node->i_children ; i_child++)
977 PlaylistListNode( p_pl, p_node->pp_children[i_child], name, s, i_depth + 1);
983 static mvar_t *mvar_PlaylistSetNew( char *name, playlist_t *p_pl )
985 playlist_view_t *p_view;
986 mvar_t *s = mvar_New( name, "set" );
989 vlc_mutex_lock( &p_pl->object_lock );
991 p_view = playlist_ViewFind( p_pl, VIEW_CATEGORY ); /* FIXME */
994 PlaylistListNode( p_pl, p_view->p_root, name, s, 0 );
996 vlc_mutex_unlock( &p_pl->object_lock );
1001 static mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input )
1003 mvar_t *s = mvar_New( name, "set" );
1006 if( p_input == NULL )
1011 vlc_mutex_lock( &p_input->input.p_item->lock );
1012 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
1014 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1015 mvar_t *cat = mvar_New( name, "set" );
1016 mvar_t *iset = mvar_New( "info", "set" );
1018 mvar_AppendNewVar( cat, "name", p_category->psz_name );
1019 mvar_AppendVar( cat, iset );
1021 for ( j = 0; j < p_category->i_infos; j++ )
1023 info_t *p_info = p_category->pp_infos[j];
1024 mvar_t *info = mvar_New( "info", "" );
1026 msg_Dbg( p_input, "adding info name=%s value=%s",
1027 p_info->psz_name, p_info->psz_value );
1028 mvar_AppendNewVar( info, "name", p_info->psz_name );
1029 mvar_AppendNewVar( info, "value", p_info->psz_value );
1030 mvar_AppendVar( iset, info );
1032 mvar_AppendVar( s, cat );
1034 vlc_mutex_unlock( &p_input->input.p_item->lock );
1039 static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
1041 mvar_t *s = mvar_New( name, "set" );
1045 if( !p_httpd->pf_control( p_httpd, i_type, &info, NULL ) )
1047 for( i= 0; i < info.i_count; )
1051 inf = mvar_New( name, "set" );
1054 /* fprintf( stderr," mvar_HttpdInfoSetNew: append name=`%s' value=`%s'\n",
1055 info.info[i].psz_name, info.info[i].psz_value ); */
1056 mvar_AppendNewVar( inf,
1057 info.info[i].psz_name,
1058 info.info[i].psz_value );
1060 } while( i < info.i_count && strcmp( info.info[i].psz_name, "id" ) );
1061 mvar_AppendVar( s, inf );
1066 for( i = 0; i < info.i_count; i++ )
1068 free( info.info[i].psz_name );
1069 free( info.info[i].psz_value );
1071 if( info.i_count > 0 )
1080 static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
1082 mvar_t *s = mvar_New( name, "set" );
1083 char tmp[MAX_DIR_SIZE], *p, *src;
1084 #ifdef HAVE_SYS_STAT_H
1085 struct stat stat_info;
1088 struct dirent *p_dir_content;
1091 /* convert all / to native separator */
1092 #if defined( WIN32 )
1093 while( (p = strchr( psz_dir, '/' )) )
1102 /* remove trailling separator */
1103 while( strlen( psz_dir ) > 1 &&
1104 #if defined( WIN32 )
1105 !( strlen(psz_dir)==3 && psz_dir[1]==':' && psz_dir[2]==sep ) &&
1107 psz_dir[strlen( psz_dir ) -1 ] == sep )
1109 psz_dir[strlen( psz_dir ) -1 ] ='\0';
1111 /* remove double separator */
1112 for( p = src = psz_dir; *src != '\0'; src++, p++ )
1114 if( src[0] == sep && src[1] == sep )
1122 if( *psz_dir == '\0' )
1126 /* first fix all .. dir */
1130 if( src[0] == '.' && src[1] == '.' )
1133 if( p <= &psz_dir[1] )
1140 while( p > &psz_dir[1] && *p != sep )
1145 else if( *src == sep )
1147 if( p > psz_dir && p[-1] == sep )
1161 } while( *src && *src != sep );
1167 #ifdef HAVE_SYS_STAT_H
1168 if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
1174 if( ( p_dir = opendir( psz_dir ) ) == NULL )
1176 fprintf( stderr, "cannot open dir (%s)", psz_dir );
1180 /* remove traling / or \ */
1181 for( p = &psz_dir[strlen( psz_dir) - 1];
1182 p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- )
1191 /* parse psz_src dir */
1192 if( ( p_dir_content = readdir( p_dir ) ) == NULL )
1196 if( !strcmp( p_dir_content->d_name, "." ) )
1201 sprintf( tmp, "%s/%s", psz_dir, p_dir_content->d_name );
1203 #ifdef HAVE_SYS_STAT_H
1204 if( stat( tmp, &stat_info ) == -1 )
1209 f = mvar_New( name, "set" );
1210 mvar_AppendNewVar( f, "name", tmp );
1212 #ifdef HAVE_SYS_STAT_H
1213 if( S_ISDIR( stat_info.st_mode ) )
1215 mvar_AppendNewVar( f, "type", "directory" );
1217 else if( S_ISREG( stat_info.st_mode ) )
1219 mvar_AppendNewVar( f, "type", "file" );
1223 mvar_AppendNewVar( f, "type", "unknown" );
1226 sprintf( tmp, I64Fd, (int64_t)stat_info.st_size );
1227 mvar_AppendNewVar( f, "size", tmp );
1229 /* FIXME memory leak FIXME */
1231 ctime_r( &stat_info.st_mtime, tmp );
1232 mvar_AppendNewVar( f, "date", tmp );
1234 mvar_AppendNewVar( f, "date", ctime( &stat_info.st_mtime ) );
1238 mvar_AppendNewVar( f, "type", "unknown" );
1239 mvar_AppendNewVar( f, "size", "unknown" );
1240 mvar_AppendNewVar( f, "date", "unknown" );
1242 mvar_AppendVar( s, f );
1248 static mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm )
1250 mvar_t *s = mvar_New( name, "set" );
1254 if( vlm == NULL ) return s;
1256 if( vlm_ExecuteCommand( vlm, "show", &msg ) )
1261 for( i = 0; i < msg->i_child; i++ )
1263 /* Over media, schedule */
1264 vlm_message_t *ch = msg->child[i];
1267 for( j = 0; j < ch->i_child; j++ )
1270 vlm_message_t *el = ch->child[j];
1271 vlm_message_t *inf, *desc;
1276 sprintf( psz, "show %s", el->psz_name );
1277 if( vlm_ExecuteCommand( vlm, psz, &inf ) )
1279 desc = inf->child[0];
1281 /* Add a node with name and info */
1282 set = mvar_New( name, "set" );
1283 mvar_AppendNewVar( set, "name", el->psz_name );
1285 for( k = 0; k < desc->i_child; k++ )
1287 vlm_message_t *ch = desc->child[k];
1288 if( ch->i_child > 0 )
1291 mvar_t *n = mvar_New( ch->psz_name, "set" );
1293 for( c = 0; c < ch->i_child; c++ )
1295 if( ch->child[c]->psz_value )
1297 mvar_AppendNewVar( n, ch->child[c]->psz_name, ch->child[c]->psz_value );
1301 mvar_t *in = mvar_New( ch->psz_name, ch->child[c]->psz_name );
1302 mvar_AppendVar( n, in );
1305 mvar_AppendVar( set, n );
1309 mvar_AppendNewVar( set, ch->psz_name, ch->psz_value );
1312 vlm_MessageDelete( inf );
1314 mvar_AppendVar( s, set );
1317 vlm_MessageDelete( msg );
1323 static void SSInit( rpn_stack_t * );
1324 static void SSClean( rpn_stack_t * );
1325 static void EvaluateRPN( mvar_t *, rpn_stack_t *, char * );
1327 static void SSPush ( rpn_stack_t *, char * );
1328 static char *SSPop ( rpn_stack_t * );
1330 static void SSPushN ( rpn_stack_t *, int );
1331 static int SSPopN ( rpn_stack_t *, mvar_t * );
1334 /****************************************************************************
1336 ****************************************************************************/
1344 static int FileLoad( FILE *f, char **pp_data, int *pi_data )
1348 /* just load the file */
1350 *pp_data = malloc( 1025 ); /* +1 for \0 */
1351 while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 )
1354 *pp_data = realloc( *pp_data, *pi_data + 1025 );
1360 (*pp_data)[*pi_data] = '\0';
1365 static int MacroParse( macro_t *m, char *psz_src )
1367 char *dup = strdup( (char *)psz_src );
1372 #define EXTRACT( name, l ) \
1374 p = strchr( src, '"' ); \
1379 m->name = strdup( src ); \
1400 if( !strncmp( src, "id=\"", 4 ) )
1404 else if( !strncmp( src, "param1=\"", 8 ) )
1406 EXTRACT( param1, 8 );
1408 else if( !strncmp( src, "param2=\"", 8 ) )
1410 EXTRACT( param2, 8 );
1417 if( strstr( src, "/>" ) )
1419 src = strstr( src, "/>" ) + 2;
1423 src += strlen( src );
1428 m->id = strdup( "" );
1430 if( m->param1 == NULL )
1432 m->param1 = strdup( "" );
1434 if( m->param2 == NULL )
1436 m->param2 = strdup( "" );
1445 static void MacroClean( macro_t *m )
1504 StrToMacroTypeTab [] =
1506 { "control", MVLC_CONTROL },
1507 /* player control */
1508 { "play", MVLC_PLAY },
1509 { "stop", MVLC_STOP },
1510 { "pause", MVLC_PAUSE },
1511 { "next", MVLC_NEXT },
1512 { "previous", MVLC_PREVIOUS },
1513 { "seek", MVLC_SEEK },
1514 { "keep", MVLC_KEEP },
1515 { "fullscreen", MVLC_FULLSCREEN },
1516 { "volume", MVLC_VOLUME },
1518 /* playlist management */
1519 { "add", MVLC_ADD },
1520 { "delete", MVLC_DEL },
1521 { "empty", MVLC_EMPTY },
1522 { "sort", MVLC_SORT },
1523 { "move", MVLC_MOVE },
1526 { "close", MVLC_CLOSE },
1527 { "shutdown", MVLC_SHUTDOWN },
1530 { "vlm_new", MVLC_VLM_NEW },
1531 { "vlm_setup", MVLC_VLM_SETUP },
1532 { "vlm_del", MVLC_VLM_DEL },
1533 { "vlm_play", MVLC_VLM_PLAY },
1534 { "vlm_pause", MVLC_VLM_PAUSE },
1535 { "vlm_stop", MVLC_VLM_STOP },
1536 { "vlm_seek", MVLC_VLM_SEEK },
1537 { "vlm_load", MVLC_VLM_LOAD },
1538 { "vlm_save", MVLC_VLM_SAVE },
1540 { "rpn", MVLC_RPN },
1541 { "stack", MVLC_STACK },
1543 { "foreach", MVLC_FOREACH },
1544 { "value", MVLC_VALUE },
1547 { "else", MVLC_ELSE },
1548 { "end", MVLC_END },
1549 { "get", MVLC_GET },
1550 { "set", MVLC_SET },
1551 { "int", MVLC_INT },
1552 { "float", MVLC_FLOAT },
1553 { "string", MVLC_STRING },
1556 { NULL, MVLC_UNKNOWN }
1559 static int StrToMacroType( char *name )
1563 if( !name || *name == '\0')
1565 return MVLC_UNKNOWN;
1567 for( i = 0; StrToMacroTypeTab[i].psz_name != NULL; i++ )
1569 if( !strcmp( name, StrToMacroTypeTab[i].psz_name ) )
1571 return StrToMacroTypeTab[i].i_type;
1574 return MVLC_UNKNOWN;
1577 static void MacroDo( httpd_file_sys_t *p_args,
1579 char *p_request, int i_request,
1580 char **pp_data, int *pi_data,
1583 intf_thread_t *p_intf = p_args->p_intf;
1584 intf_sys_t *p_sys = p_args->p_intf->p_sys;
1587 #define ALLOC( l ) \
1589 int __i__ = *pp_dst - *pp_data; \
1591 *pp_data = realloc( *pp_data, *pi_data ); \
1592 *pp_dst = (*pp_data) + __i__; \
1594 #define PRINT( str ) \
1595 ALLOC( strlen( str ) + 1 ); \
1596 *pp_dst += sprintf( *pp_dst, str );
1598 #define PRINTS( str, s ) \
1599 ALLOC( strlen( str ) + strlen( s ) + 1 ); \
1601 char * psz_cur = *pp_dst; \
1602 *pp_dst += sprintf( *pp_dst, str, s ); \
1603 while( psz_cur && *psz_cur ) \
1605 /* Prevent script injection */ \
1606 if( *psz_cur == '<' ) *psz_cur = '*'; \
1607 if( *psz_cur == '>' ) *psz_cur = '*'; \
1612 switch( StrToMacroType( m->id ) )
1615 if( i_request <= 0 )
1619 uri_extract_value( p_request, "control", control, 512 );
1620 if( *m->param1 && !strstr( m->param1, control ) )
1622 msg_Warn( p_intf, "unauthorized control=%s", control );
1625 switch( StrToMacroType( control ) )
1632 uri_extract_value( p_request, "item", item, 512 );
1633 i_item = atoi( item );
1634 playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
1635 playlist_ItemGetById( p_sys->p_playlist,
1637 msg_Dbg( p_intf, "requested playlist item: %i", i_item );
1641 playlist_Control( p_sys->p_playlist, PLAYLIST_STOP);
1642 msg_Dbg( p_intf, "requested playlist stop" );
1645 playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
1646 msg_Dbg( p_intf, "requested playlist pause" );
1649 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
1650 msg_Dbg( p_intf, "requested playlist next" );
1653 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1);
1654 msg_Dbg( p_intf, "requested playlist next" );
1656 case MVLC_FULLSCREEN:
1658 if( p_sys->p_input )
1660 vout_thread_t *p_vout;
1661 p_vout = vlc_object_find( p_sys->p_input,
1662 VLC_OBJECT_VOUT, FIND_CHILD );
1666 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1667 vlc_object_release( p_vout );
1668 msg_Dbg( p_intf, "requested fullscreen toggle" );
1682 #define POSITION_ABSOLUTE 12
1683 #define POSITION_REL_FOR 13
1684 #define POSITION_REL_BACK 11
1685 #define VL_TIME_ABSOLUTE 0
1686 #define VL_TIME_REL_FOR 1
1687 #define VL_TIME_REL_BACK -1
1688 if( p_sys->p_input )
1690 uri_extract_value( p_request, "seek_value", value, 20 );
1691 uri_decode_url_encoded( value );
1693 var_Get( p_sys->p_input, "length", &val);
1694 i_length = val.i_time;
1696 while( p_value[0] != '\0' )
1702 i_relative = VL_TIME_REL_FOR;
1708 i_relative = VL_TIME_REL_BACK;
1712 case '0': case '1': case '2': case '3': case '4':
1713 case '5': case '6': case '7': case '8': case '9':
1715 i_stock = strtol( p_value , &p_value , 10 );
1718 case '%': /* for percentage ie position */
1720 i_relative += POSITION_ABSOLUTE;
1728 i_value = 60 * (i_value + i_stock) ;
1733 case 'h': case 'H': /* hours */
1735 i_value += 3600 * i_stock;
1737 /* other characters which are not numbers are not important */
1738 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1744 case 'm': case 'M': case '\'': /* minutes */
1746 i_value += 60 * i_stock;
1749 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1755 case 's': case 'S': case '"': /* seconds */
1759 while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
1773 /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
1778 case VL_TIME_ABSOLUTE:
1780 if( (uint64_t)( i_value ) * 1000000 <= i_length )
1781 val.i_time = (uint64_t)( i_value ) * 1000000;
1783 val.i_time = i_length;
1785 var_Set( p_sys->p_input, "time", val );
1786 msg_Dbg( p_intf, "requested seek position: %dsec", i_value );
1789 case VL_TIME_REL_FOR:
1791 var_Get( p_sys->p_input, "time", &val );
1792 if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
1794 val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
1797 val.i_time = i_length;
1799 var_Set( p_sys->p_input, "time", val );
1800 msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );
1803 case VL_TIME_REL_BACK:
1805 var_Get( p_sys->p_input, "time", &val );
1806 if( (int64_t)( i_value ) * 1000000 > val.i_time )
1811 val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);
1813 var_Set( p_sys->p_input, "time", val );
1814 msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );
1817 case POSITION_ABSOLUTE:
1819 val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1820 var_Set( p_sys->p_input, "position", val );
1821 msg_Dbg( p_intf, "requested seek percent: %d", i_value );
1824 case POSITION_REL_FOR:
1826 var_Get( p_sys->p_input, "position", &val );
1827 val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1828 var_Set( p_sys->p_input, "position", val );
1829 msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
1832 case POSITION_REL_BACK:
1834 var_Get( p_sys->p_input, "position", &val );
1835 val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
1836 var_Set( p_sys->p_input, "position", val );
1837 msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
1842 msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
1847 #undef POSITION_ABSOLUTE
1848 #undef POSITION_REL_FOR
1849 #undef POSITION_REL_BACK
1850 #undef VL_TIME_ABSOLUTE
1851 #undef VL_TIME_REL_FOR
1852 #undef VL_TIME_REL_BACK
1858 audio_volume_t i_volume;
1861 uri_extract_value( p_request, "value", vol, 8 );
1862 aout_VolumeGet( p_intf, &i_volume );
1863 uri_decode_url_encoded( vol );
1867 i_value = atoi( vol + 1 );
1868 if( (i_volume + i_value) > AOUT_VOLUME_MAX )
1870 aout_VolumeSet( p_intf , AOUT_VOLUME_MAX );
1871 msg_Dbg( p_intf, "requested volume set: max" );
1874 aout_VolumeSet( p_intf , (i_volume + i_value) );
1875 msg_Dbg( p_intf, "requested volume set: +%i", (i_volume + i_value) );
1880 i_value = atoi( vol + 1 );
1881 if( (i_volume - i_value) < AOUT_VOLUME_MIN )
1883 aout_VolumeSet( p_intf , AOUT_VOLUME_MIN );
1884 msg_Dbg( p_intf, "requested volume set: min" );
1887 aout_VolumeSet( p_intf , (i_volume - i_value) );
1888 msg_Dbg( p_intf, "requested volume set: -%i", (i_volume - i_value) );
1891 if( strstr(vol, "%") != NULL )
1893 i_value = atoi( vol );
1894 if( (i_value <= 100) && (i_value>=0) ){
1895 aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/100+AOUT_VOLUME_MIN);
1896 msg_Dbg( p_intf, "requested volume set: %i%%", atoi( vol ));
1900 i_value = atoi( vol );
1901 if( ( i_value <= AOUT_VOLUME_MAX ) && ( i_value >= AOUT_VOLUME_MIN ) )
1903 aout_VolumeSet( p_intf , atoi( vol ) );
1904 msg_Dbg( p_intf, "requested volume set: %i", atoi( vol ) );
1910 /* playlist management */
1914 playlist_item_t * p_item;
1916 uri_extract_value( p_request, "mrl", mrl, 512 );
1917 uri_decode_url_encoded( mrl );
1918 p_item = parse_MRL( p_intf, mrl );
1920 if( !p_item || !p_item->input.psz_uri ||
1921 !*p_item->input.psz_uri )
1923 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
1926 playlist_AddItem( p_sys->p_playlist , p_item ,
1927 PLAYLIST_APPEND, PLAYLIST_END );
1928 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
1935 int i_item, *p_items = NULL, i_nb_items = 0;
1936 char item[512], *p_parser = p_request;
1938 /* Get the list of items to delete */
1940 uri_extract_value( p_parser, "item", item, 512 )) )
1942 if( !*item ) continue;
1944 i_item = atoi( item );
1945 p_items = realloc( p_items, (i_nb_items + 1) *
1947 p_items[i_nb_items] = i_item;
1954 for( i = 0; i < i_nb_items; i++ )
1956 playlist_LockDelete( p_sys->p_playlist, p_items[i] );
1957 msg_Dbg( p_intf, "requested playlist delete: %d",
1963 if( p_items ) free( p_items );
1968 int i_item, *p_items = NULL, i_nb_items = 0;
1969 char item[512], *p_parser = p_request;
1972 /* Get the list of items to keep */
1974 uri_extract_value( p_parser, "item", item, 512 )) )
1976 if( !*item ) continue;
1978 i_item = atoi( item );
1979 p_items = realloc( p_items, (i_nb_items + 1) *
1981 p_items[i_nb_items] = i_item;
1985 for( i = p_sys->p_playlist->i_size - 1 ; i >= 0; i-- )
1987 /* Check if the item is in the keep list */
1988 for( j = 0 ; j < i_nb_items ; j++ )
1991 p_sys->p_playlist->pp_items[i]->input.i_id ) break;
1993 if( j == i_nb_items )
1995 playlist_LockDelete( p_sys->p_playlist, p_sys->p_playlist->pp_items[i]->input.i_id );
1996 msg_Dbg( p_intf, "requested playlist delete: %d",
2001 if( p_items ) free( p_items );
2006 playlist_LockClear( p_sys->p_playlist );
2007 msg_Dbg( p_intf, "requested playlist empty" );
2018 uri_extract_value( p_request, "type", type, 12 );
2019 uri_extract_value( p_request, "order", order, 2 );
2020 uri_extract_value( p_request, "item", item, 512 );
2021 i_item = atoi( item );
2023 if( order[0] == '0' ) i_order = ORDER_NORMAL;
2024 else i_order = ORDER_REVERSE;
2026 if( !strcmp( type , "title" ) )
2028 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2029 p_sys->p_playlist->pp_views[0]->p_root,
2030 SORT_TITLE_NODES_FIRST,
2031 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2032 msg_Dbg( p_intf, "requested playlist sort by title (%d)" , i_order );
2033 } else if( !strcmp( type , "author" ) )
2035 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2036 p_sys->p_playlist->pp_views[0]->p_root,
2038 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2039 msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
2040 } else if( !strcmp( type , "shuffle" ) )
2042 playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
2043 p_sys->p_playlist->pp_views[0]->p_root,
2045 ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
2046 msg_Dbg( p_intf, "requested playlist shuffle");
2057 uri_extract_value( p_request, "psz_pos", psz_pos, 6 );
2058 uri_extract_value( p_request, "psz_newpos", psz_newpos, 6 );
2059 i_pos = atoi( psz_pos );
2060 i_newpos = atoi( psz_newpos );
2061 if ( i_pos < i_newpos )
2063 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
2065 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
2067 msg_Dbg( p_intf, "requested move playlist item %d to %d", i_pos, i_newpos);
2071 /* admin function */
2075 uri_extract_value( p_request, "id", id, 512 );
2076 msg_Dbg( p_intf, "requested close id=%s", id );
2078 if( p_sys->p_httpd->pf_control( p_sys->p_httpd, HTTPD_SET_CLOSE, id, NULL ) )
2080 msg_Warn( p_intf, "close failed for id=%s", id );
2087 msg_Dbg( p_intf, "requested shutdown" );
2088 p_intf->p_vlc->b_die = VLC_TRUE;
2093 case MVLC_VLM_SETUP:
2095 static const char *vlm_properties[11] =
2098 "enabled", "disabled", "loop", "unloop",
2100 "input", "output", "option", "date", "period", "repeat", "append",
2102 vlm_message_t *vlm_answer;
2104 char *psz = malloc( strlen( p_request ) + 1000 );
2109 if( p_intf->p_sys->p_vlm == NULL )
2110 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2112 if( p_intf->p_sys->p_vlm == NULL ) break;
2114 uri_extract_value( p_request, "name", name, 512 );
2115 if( StrToMacroType( control ) == MVLC_VLM_NEW )
2118 uri_extract_value( p_request, "type", type, 20 );
2119 p += sprintf( psz, "new %s %s", name, type );
2123 p += sprintf( psz, "setup %s", name );
2125 /* Parse the request */
2126 for( i = 0; i < 11; i++ )
2129 uri_extract_value( p_request, vlm_properties[i], val, 512 );
2130 uri_decode_url_encoded( val );
2131 if( strlen( val ) > 0 && i >= 4 )
2133 p += sprintf( p, " %s %s", vlm_properties[i], val );
2135 else if( uri_test_param( p_request, vlm_properties[i] ) && i < 4 )
2137 p += sprintf( p, " %s", vlm_properties[i] );
2140 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2141 if( vlm_answer->psz_value == NULL ) /* there is no error */
2143 vlm_error = strdup( "" );
2147 vlm_error = malloc( strlen(vlm_answer->psz_name) +
2148 strlen(vlm_answer->psz_value) +
2149 strlen( " : ") + 1 );
2150 sprintf( vlm_error , "%s : %s" , vlm_answer->psz_name,
2151 vlm_answer->psz_value );
2154 mvar_AppendNewVar( p_args->vars, "vlm_error", vlm_error );
2156 vlm_MessageDelete( vlm_answer );
2164 vlm_message_t *vlm_answer;
2167 if( p_intf->p_sys->p_vlm == NULL )
2168 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2170 if( p_intf->p_sys->p_vlm == NULL ) break;
2172 uri_extract_value( p_request, "name", name, 512 );
2173 sprintf( psz, "del %s", name );
2175 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2176 /* FIXME do a vlm_answer -> var stack conversion */
2177 vlm_MessageDelete( vlm_answer );
2182 case MVLC_VLM_PAUSE:
2186 vlm_message_t *vlm_answer;
2189 if( p_intf->p_sys->p_vlm == NULL )
2190 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2192 if( p_intf->p_sys->p_vlm == NULL ) break;
2194 uri_extract_value( p_request, "name", name, 512 );
2195 if( StrToMacroType( control ) == MVLC_VLM_PLAY )
2196 sprintf( psz, "control %s play", name );
2197 else if( StrToMacroType( control ) == MVLC_VLM_PAUSE )
2198 sprintf( psz, "control %s pause", name );
2199 else if( StrToMacroType( control ) == MVLC_VLM_STOP )
2200 sprintf( psz, "control %s stop", name );
2201 else if( StrToMacroType( control ) == MVLC_VLM_SEEK )
2204 uri_extract_value( p_request, "percent", percent, 512 );
2205 sprintf( psz, "control %s seek %s", name, percent );
2208 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2209 /* FIXME do a vlm_answer -> var stack conversion */
2210 vlm_MessageDelete( vlm_answer );
2216 vlm_message_t *vlm_answer;
2220 if( p_intf->p_sys->p_vlm == NULL )
2221 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2223 if( p_intf->p_sys->p_vlm == NULL ) break;
2225 uri_extract_value( p_request, "file", file, 512 );
2226 uri_decode_url_encoded( file );
2228 if( StrToMacroType( control ) == MVLC_VLM_LOAD )
2229 sprintf( psz, "load %s", file );
2231 sprintf( psz, "save %s", file );
2233 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
2234 /* FIXME do a vlm_answer -> var stack conversion */
2235 vlm_MessageDelete( vlm_answer );
2242 PRINTS( "<!-- control param(%s) unsuported -->", control );
2254 if( i_request <= 0 ||
2255 *m->param1 == '\0' ||
2256 strstr( p_request, m->param1 ) == NULL )
2260 uri_extract_value( p_request, m->param1, value, 512 );
2261 uri_decode_url_encoded( value );
2263 switch( StrToMacroType( m->param2 ) )
2267 config_PutInt( p_intf, m->param1, i );
2271 config_PutFloat( p_intf, m->param1, f );
2274 config_PutPsz( p_intf, m->param1, value );
2277 PRINTS( "<!-- invalid type(%s) in set -->", m->param2 )
2288 if( *m->param1 == '\0' )
2293 switch( StrToMacroType( m->param2 ) )
2296 i = config_GetInt( p_intf, m->param1 );
2297 sprintf( value, "%d", i );
2300 f = config_GetFloat( p_intf, m->param1 );
2301 sprintf( value, "%f", f );
2304 psz = config_GetPsz( p_intf, m->param1 );
2305 snprintf( value, sizeof( value ), "%s", psz ? psz : "" );
2306 if( psz ) free( psz );
2309 snprintf( value, sizeof( value ),
2310 "invalid type(%s) in set", m->param2 );
2313 value[sizeof( value ) - 1] = '\0';
2314 msg_Dbg( p_intf, "get name=%s value=%s type=%s", m->param1, value, m->param2 );
2315 PRINTS( "%s", value );
2324 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2325 s = SSPop( &p_args->stack );
2326 v = mvar_GetValue( p_args->vars, s );
2330 v = s = SSPop( &p_args->stack );
2338 EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
2341 /* Usefull for learning stack management */
2345 msg_Dbg( p_intf, "stack" );
2346 for (i=0;i<(&p_args->stack)->i_stack;i++)
2347 msg_Dbg( p_intf, "%d -> %s", i, (&p_args->stack)->stack[i] );
2353 PRINTS( "<!-- invalid macro id=`%s' -->", m->id );
2354 msg_Dbg( p_intf, "invalid macro id=`%s'", m->id );
2362 static char *MacroSearch( char *src, char *end, int i_mvlc, vlc_bool_t b_after )
2369 if( src + 4 < end && !strncmp( (char *)src, "<vlc", 4 ) )
2374 i_skip = MacroParse( &m, src );
2376 i_id = StrToMacroType( m.id );
2393 if( ( i_mvlc == MVLC_END && i_level == -1 ) ||
2394 ( i_mvlc != MVLC_END && i_level == 0 && i_mvlc == i_id ) )
2396 return src + ( b_after ? i_skip : 0 );
2398 else if( i_level < 0 )
2414 static void Execute( httpd_file_sys_t *p_args,
2415 char *p_request, int i_request,
2416 char **pp_data, int *pi_data,
2418 char *_src, char *_end )
2420 intf_thread_t *p_intf = p_args->p_intf;
2422 char *src, *dup, *end;
2423 char *dst = *pp_dst;
2425 src = dup = malloc( _end - _src + 1 );
2426 end = src +( _end - _src );
2428 memcpy( src, _src, _end - _src );
2431 /* we parse searching <vlc */
2437 p = (char *)strstr( (char *)src, "<vlc" );
2438 if( p < end && p == src )
2442 src += MacroParse( &m, src );
2444 //msg_Dbg( p_intf, "macro_id=%s", m.id );
2446 switch( StrToMacroType( m.id ) )
2453 EvaluateRPN( p_args->vars, &p_args->stack, m.param1 );
2454 if( SSPopN( &p_args->stack, p_args->vars ) )
2462 endif = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2466 char *start = MacroSearch( src, endif, MVLC_ELSE, VLC_TRUE );
2470 char *stop = MacroSearch( start, endif, MVLC_END, VLC_FALSE );
2473 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2477 else if( i_test == 1 )
2480 if( ( stop = MacroSearch( src, endif, MVLC_ELSE, VLC_FALSE ) ) == NULL )
2482 stop = MacroSearch( src, endif, MVLC_END, VLC_FALSE );
2486 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, src, stop );
2495 char *endfor = MacroSearch( src, end, MVLC_END, VLC_TRUE );
2497 char *stop = MacroSearch( src, end, MVLC_END, VLC_FALSE );
2504 if( !strcmp( m.param2, "integer" ) )
2506 char *arg = SSPop( &p_args->stack );
2507 index = mvar_IntegerSetNew( m.param1, arg );
2510 else if( !strcmp( m.param2, "directory" ) )
2512 char *arg = SSPop( &p_args->stack );
2513 index = mvar_FileSetNew( m.param1, arg );
2516 else if( !strcmp( m.param2, "playlist" ) )
2518 index = mvar_PlaylistSetNew( m.param1, p_intf->p_sys->p_playlist );
2520 else if( !strcmp( m.param2, "information" ) )
2522 index = mvar_InfoSetNew( m.param1, p_intf->p_sys->p_input );
2524 else if( !strcmp( m.param2, "vlm" ) )
2526 if( p_intf->p_sys->p_vlm == NULL )
2527 p_intf->p_sys->p_vlm = vlm_New( p_intf );
2528 index = mvar_VlmSetNew( m.param1, p_intf->p_sys->p_vlm );
2531 else if( !strcmp( m.param2, "hosts" ) )
2533 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_HOSTS );
2535 else if( !strcmp( m.param2, "urls" ) )
2537 index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_URLS );
2539 else if( !strcmp( m.param2, "connections" ) )
2541 index = mvar_HttpdInfoSetNew(m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_CONNECTIONS);
2544 else if( ( v = mvar_GetVar( p_args->vars, m.param2 ) ) )
2546 index = mvar_Duplicate( v );
2550 msg_Dbg( p_intf, "invalid index constructor (%s)", m.param2 );
2555 for( i_idx = 0; i_idx < index->i_field; i_idx++ )
2557 mvar_t *f = mvar_Duplicate( index->field[i_idx] );
2559 //msg_Dbg( p_intf, "foreach field[%d] name=%s value=%s", i_idx, f->name, f->value );
2562 f->name = strdup( m.param1 );
2565 mvar_PushVar( p_args->vars, f );
2566 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
2567 mvar_RemoveVar( p_args->vars, f );
2571 mvar_Delete( index );
2578 MacroDo( p_args, &m, p_request, i_request, pp_data, pi_data, &dst );
2586 i_copy = ( (p == NULL || p > end ) ? end : p ) - src;
2589 int i_index = dst - *pp_data;
2592 *pp_data = realloc( *pp_data, *pi_data );
2593 dst = (*pp_data) + i_index;
2595 memcpy( dst, src, i_copy );
2605 /****************************************************************************
2607 ****************************************************************************
2608 * a file with b_html is parsed and all "macro" replaced
2609 * <vlc id="macro name" [param1="" [param2=""]] />
2612 ****************************************************************************/
2613 static int HttpCallback( httpd_file_sys_t *p_args,
2614 httpd_file_t *p_file,
2615 uint8_t *_p_request,
2616 uint8_t **_pp_data, int *pi_data )
2618 char *p_request = (char *)_p_request;
2619 char **pp_data = (char **)_pp_data;
2620 int i_request = p_request ? strlen( p_request ) : 0;
2624 if( ( f = fopen( p_args->file, "r" ) ) == NULL )
2626 p = *pp_data = malloc( 10240 );
2629 return VLC_EGENERIC;
2631 p += sprintf( p, "<html>\n" );
2632 p += sprintf( p, "<head>\n" );
2633 p += sprintf( p, "<title>Error loading %s</title>\n", p_args->file );
2634 p += sprintf( p, "</head>\n" );
2635 p += sprintf( p, "<body>\n" );
2636 p += sprintf( p, "<h1><center>Error loading %s for %s</center></h1>\n", p_args->file, p_args->name );
2637 p += sprintf( p, "<hr />\n" );
2638 p += sprintf( p, "<a href=\"http://www.videolan.org/\">VideoLAN</a>\n" );
2639 p += sprintf( p, "</body>\n" );
2640 p += sprintf( p, "</html>\n" );
2642 *pi_data = strlen( *pp_data );
2647 if( !p_args->b_html )
2649 FileLoad( f, pp_data, pi_data );
2657 char position[4]; /* percentage */
2658 char time[12]; /* in seconds */
2659 char length[12]; /* in seconds */
2660 audio_volume_t i_volume;
2664 #define p_sys p_args->p_intf->p_sys
2665 if( p_sys->p_input )
2667 var_Get( p_sys->p_input, "position", &val);
2668 sprintf( position, "%d" , (int)((val.f_float) * 100.0));
2669 var_Get( p_sys->p_input, "time", &val);
2670 sprintf( time, "%d" , (int)(val.i_time / 1000000) );
2671 var_Get( p_sys->p_input, "length", &val);
2672 sprintf( length, "%d" , (int)(val.i_time / 1000000) );
2674 var_Get( p_sys->p_input, "state", &val );
2675 if( val.i_int == PLAYING_S )
2677 sprintf( state, "playing" );
2678 } else if( val.i_int == PAUSE_S )
2680 sprintf( state, "paused" );
2683 sprintf( state, "stop" );
2687 sprintf( position, "%d", 0 );
2688 sprintf( time, "%d", 0 );
2689 sprintf( length, "%d", 0 );
2690 sprintf( state, "stop" );
2694 aout_VolumeGet( p_args->p_intf , &i_volume );
2695 sprintf( volume , "%d" , (int)i_volume );
2697 p_args->vars = mvar_New( "variables", "" );
2698 mvar_AppendNewVar( p_args->vars, "url_param", i_request > 0 ? "1" : "0" );
2699 mvar_AppendNewVar( p_args->vars, "url_value", p_request );
2700 mvar_AppendNewVar( p_args->vars, "version", VERSION_MESSAGE );
2701 mvar_AppendNewVar( p_args->vars, "copyright", COPYRIGHT_MESSAGE );
2702 mvar_AppendNewVar( p_args->vars, "stream_position", position );
2703 mvar_AppendNewVar( p_args->vars, "stream_time", time );
2704 mvar_AppendNewVar( p_args->vars, "stream_length", length );
2705 mvar_AppendNewVar( p_args->vars, "volume", volume );
2706 mvar_AppendNewVar( p_args->vars, "stream_state", state );
2708 SSInit( &p_args->stack );
2710 /* first we load in a temporary buffer */
2711 FileLoad( f, &p_buffer, &i_buffer );
2713 /* allocate output */
2714 *pi_data = i_buffer + 1000;
2715 dst = *pp_data = malloc( *pi_data );
2717 /* we parse executing all <vlc /> macros */
2718 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, &p_buffer[0], &p_buffer[i_buffer] );
2721 *pi_data = dst - *pp_data;
2723 SSClean( &p_args->stack );
2724 mvar_Delete( p_args->vars );
2733 /****************************************************************************
2735 ****************************************************************************/
2736 static int uri_test_param( char *psz_uri, const char *psz_name )
2740 while( (p = strstr( p, psz_name )) )
2742 /* Verify that we are dealing with a post/get argument */
2743 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2752 static char *uri_extract_value( char *psz_uri, const char *psz_name,
2753 char *psz_value, int i_value_max )
2757 while( (p = strstr( p, psz_name )) )
2759 /* Verify that we are dealing with a post/get argument */
2760 if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
2769 p += strlen( psz_name );
2770 if( *p == '=' ) p++;
2772 if( strchr( p, '&' ) )
2774 i_len = strchr( p, '&' ) - p;
2778 /* for POST method */
2779 if( strchr( p, '\n' ) )
2781 i_len = strchr( p, '\n' ) - p;
2782 if( i_len && *(p+i_len-1) == '\r' ) i_len--;
2786 i_len = strlen( p );
2789 i_len = __MIN( i_value_max - 1, i_len );
2792 strncpy( psz_value, p, i_len );
2793 psz_value[i_len] = '\0';
2797 strncpy( psz_value, "", i_value_max );
2803 strncpy( psz_value, "", i_value_max );
2809 static void uri_decode_url_encoded( char *psz )
2811 char *dup = strdup( psz );
2829 *psz++ = strtol( val, NULL, 16 );
2831 else if( *p == '+' )
2845 /****************************************************************************
2846 * Light RPN evaluator
2847 ****************************************************************************/
2848 static void SSInit( rpn_stack_t *st )
2853 static void SSClean( rpn_stack_t *st )
2855 while( st->i_stack > 0 )
2857 free( st->stack[--st->i_stack] );
2861 static void SSPush( rpn_stack_t *st, char *s )
2863 if( st->i_stack < STACK_MAX )
2865 st->stack[st->i_stack++] = strdup( s );
2869 static char * SSPop( rpn_stack_t *st )
2871 if( st->i_stack <= 0 )
2873 return strdup( "" );
2877 return st->stack[--st->i_stack];
2881 static int SSPopN( rpn_stack_t *st, mvar_t *vars )
2890 i = strtol( name, &end, 0 );
2893 value = mvar_GetValue( vars, name );
2901 static void SSPushN( rpn_stack_t *st, int i )
2905 sprintf( v, "%d", i );
2909 static void EvaluateRPN( mvar_t *vars, rpn_stack_t *st, char *exp )
2916 while( *exp == ' ' )
2923 /* extract string */
2926 while( *exp && *exp != '\'' )
2937 p = strchr( exp, ' ' );
2942 exp += strlen( exp );
2947 strncpy( s, exp, i );
2958 /* 1. Integer function */
2959 if( !strcmp( s, "!" ) )
2961 SSPushN( st, ~SSPopN( st, vars ) );
2963 else if( !strcmp( s, "^" ) )
2965 SSPushN( st, SSPopN( st, vars ) ^ SSPopN( st, vars ) );
2967 else if( !strcmp( s, "&" ) )
2969 SSPushN( st, SSPopN( st, vars ) & SSPopN( st, vars ) );
2971 else if( !strcmp( s, "|" ) )
2973 SSPushN( st, SSPopN( st, vars ) | SSPopN( st, vars ) );
2975 else if( !strcmp( s, "+" ) )
2977 SSPushN( st, SSPopN( st, vars ) + SSPopN( st, vars ) );
2979 else if( !strcmp( s, "-" ) )
2981 int j = SSPopN( st, vars );
2982 int i = SSPopN( st, vars );
2983 SSPushN( st, i - j );
2985 else if( !strcmp( s, "*" ) )
2987 SSPushN( st, SSPopN( st, vars ) * SSPopN( st, vars ) );
2989 else if( !strcmp( s, "/" ) )
2993 j = SSPopN( st, vars );
2994 i = SSPopN( st, vars );
2996 SSPushN( st, j != 0 ? i / j : 0 );
2998 else if( !strcmp( s, "%" ) )
3002 j = SSPopN( st, vars );
3003 i = SSPopN( st, vars );
3005 SSPushN( st, j != 0 ? i % j : 0 );
3007 /* 2. integer tests */
3008 else if( !strcmp( s, "=" ) )
3010 SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 );
3012 else if( !strcmp( s, "!=" ) )
3014 SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 );
3016 else if( !strcmp( s, "<" ) )
3018 int j = SSPopN( st, vars );
3019 int i = SSPopN( st, vars );
3021 SSPushN( st, i < j ? -1 : 0 );
3023 else if( !strcmp( s, ">" ) )
3025 int j = SSPopN( st, vars );
3026 int i = SSPopN( st, vars );
3028 SSPushN( st, i > j ? -1 : 0 );
3030 else if( !strcmp( s, "<=" ) )
3032 int j = SSPopN( st, vars );
3033 int i = SSPopN( st, vars );
3035 SSPushN( st, i <= j ? -1 : 0 );
3037 else if( !strcmp( s, ">=" ) )
3039 int j = SSPopN( st, vars );
3040 int i = SSPopN( st, vars );
3042 SSPushN( st, i >= j ? -1 : 0 );
3044 /* 3. string functions */
3045 else if( !strcmp( s, "strcat" ) )
3047 char *s2 = SSPop( st );
3048 char *s1 = SSPop( st );
3049 char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
3059 else if( !strcmp( s, "strcmp" ) )
3061 char *s2 = SSPop( st );
3062 char *s1 = SSPop( st );
3064 SSPushN( st, strcmp( s1, s2 ) );
3068 else if( !strcmp( s, "strncmp" ) )
3070 int n = SSPopN( st, vars );
3071 char *s2 = SSPop( st );
3072 char *s1 = SSPop( st );
3074 SSPushN( st, strncmp( s1, s2 , n ) );
3078 else if( !strcmp( s, "strsub" ) )
3080 int n = SSPopN( st, vars );
3081 int m = SSPopN( st, vars );
3083 char *s = SSPop( st );
3095 str = malloc( i_len + 1 );
3097 memcpy( str, s + m - 1, i_len );
3098 str[ i_len ] = '\0';
3104 else if( !strcmp( s, "strlen" ) )
3106 char *str = SSPop( st );
3108 SSPushN( st, strlen( str ) );
3111 /* 4. stack functions */
3112 else if( !strcmp( s, "dup" ) )
3114 char *str = SSPop( st );
3119 else if( !strcmp( s, "drop" ) )
3121 char *str = SSPop( st );
3124 else if( !strcmp( s, "swap" ) )
3126 char *s1 = SSPop( st );
3127 char *s2 = SSPop( st );
3134 else if( !strcmp( s, "flush" ) )
3139 else if( !strcmp( s, "store" ) )
3141 char *value = SSPop( st );
3142 char *name = SSPop( st );
3144 mvar_PushNewVar( vars, name, value );
3148 else if( !strcmp( s, "value" ) )
3150 char *name = SSPop( st );
3151 char *value = mvar_GetValue( vars, name );
3153 SSPush( st, value );
3157 else if( !strcmp( s, "url_extract" ) )
3159 char *url = mvar_GetValue( vars, "url_value" );
3160 char *name = SSPop( st );
3163 uri_extract_value( url, name, value, 512 );
3164 uri_decode_url_encoded( value );
3165 SSPush( st, value );
3174 /**********************************************************************
3175 * Find_end_MRL: Find the end of the sentence :
3176 * this function parses the string psz and find the end of the item
3177 * and/or option with detecting the " and ' problems.
3178 * returns NULL if an error is detected, otherwise, returns a pointer
3179 * of the end of the sentence (after the last character)
3180 **********************************************************************/
3181 static char *Find_end_MRL( char *psz )
3191 while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) )
3193 if( *s_sent == '\'' )
3195 s_sent = Find_end_MRL( s_sent );
3197 if( s_sent == NULL )
3207 if( *s_sent == '\"' )
3211 } else /* *s_sent == '\0' , which means the number of " is incorrect */
3221 while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) )
3223 if( *s_sent == '\"' )
3225 s_sent = Find_end_MRL( s_sent );
3227 if( s_sent == NULL )
3237 if( *s_sent == '\'' )
3241 } else /* *s_sent == '\0' , which means the number of ' is incorrect */
3247 default: /* now we can look for spaces */
3249 while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) )
3251 if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) )
3253 s_sent = Find_end_MRL( s_sent );
3264 /**********************************************************************
3265 * parse_MRL: parse the MRL, find the mrl string and the options,
3266 * create an item with all information in it, and return the item.
3267 * return NULL if there is an error.
3268 **********************************************************************/
3269 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz )
3271 char **ppsz_options = NULL;
3278 playlist_item_t * p_item = NULL;
3280 /* In case there is spaces before the mrl */
3281 while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
3286 /* extract the mrl */
3287 s_temp = strstr( s_mrl , " :" );
3288 if( s_temp == NULL )
3290 s_temp = s_mrl + strlen( s_mrl );
3293 while( (*s_temp == ' ') && (s_temp != s_mrl ) )
3300 /* if the mrl is between " or ', we must remove them */
3301 if( (*s_mrl == '\'') || (*s_mrl == '\"') )
3303 mrl = (char *)malloc( (s_temp - s_mrl - 1) * sizeof( char ) );
3304 strncpy( mrl , (s_mrl + 1) , s_temp - s_mrl - 2 );
3305 mrl[ s_temp - s_mrl - 2 ] = '\0';
3308 mrl = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) );
3309 strncpy( mrl , s_mrl , s_temp - s_mrl );
3310 mrl[ s_temp - s_mrl ] = '\0';
3315 /* now we can take care of the options */
3316 while( (*s_mrl != '\0') && (i_error == 0) )
3325 case ':': /* an option */
3327 s_temp = Find_end_MRL( s_mrl );
3329 if( s_temp == NULL )
3336 ppsz_options = realloc( ppsz_options , i_options *
3338 ppsz_options[ i_options - 1 ] =
3339 malloc( (s_temp - s_mrl + 1) * sizeof(char) );
3341 strncpy( ppsz_options[ i_options - 1 ] , s_mrl ,
3344 /* don't forget to finish the string with a '\0' */
3345 (ppsz_options[ i_options - 1 ])[ s_temp - s_mrl ] = '\0';
3365 /* now create an item */
3366 p_item = playlist_ItemNew( p_intf, mrl, mrl);
3367 for( i = 0 ; i< i_options ; i++ )
3369 playlist_ItemAddOption( p_item, ppsz_options[i] );
3373 for( i = 0; i < i_options; i++ ) free( ppsz_options[i] );
3374 if( i_options ) free( ppsz_options );