From: Simon Latapie Date: Wed, 12 Nov 2003 02:43:33 +0000 (+0000) Subject: * http.c : added parsing of options in Add MRL option. In http.c is a the X-Git-Tag: 0.7.0~538 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=0caf8ce6e94bcc97e8e0f1f61fb0559d1fba743d;p=vlc * http.c : added parsing of options in Add MRL option. In http.c is a the parse_MRL function which perhaps should be somewhere else (playlist ?). * Makefile.am : forgoten style.css * index.html : little fixes * intf-http.txt : updated doc --- diff --git a/doc/intf-http.txt b/doc/intf-http.txt index 81b4328677..42eae3de86 100644 --- a/doc/intf-http.txt +++ b/doc/intf-http.txt @@ -110,6 +110,11 @@ pop them backs. It's used with the little RPN evaluator. - url_param : 1 if url_value isn't empty else 0 - version : the VLC version - copyright : the VLC copyright + - stream_position : current position of the VLC in the stream (percentage) + - stream_time : current position of the VLC in the stream (in seconds) + - stream_length : total length of the current stream (in seconds) + - volume : current volume level + - stream_state : current state of the VLC (playing, paused, stop) Variables could have fields, just use . to access them. Ex: var.field, var.field.subfield, ... @@ -171,6 +176,8 @@ You have access to : * string: strcat : push the result of 'ST(1)ST(2)' strcmp : compare ST(1) and ST(2), push -1, 0, or 1 + strncmp : compare the ST(3) first characters of ST(1) and ST(2), + push -1, 0, or 1 strlen : push the length of ST(1) * stack manipulation dup : duplicate ST(1) on the stack @@ -199,23 +206,39 @@ commands will work. Url commands are : - | Name | argument | - ----------------------------------------------------------------- - | play | item(integer)| Play the specified item - | stop | | Stop - | pause | | Pause - | next | | Go to the next playlist element - | previous | | Got to the previous playlist element - | add | mrl(string) | Add a mrl to the playlist - | delete | item(integer)| Deletes an (list of) element of the playlist - | empty | | Empty the playlist - | close | id(hexa) | Close a specific connection - | shutdown | | Quit vlc + | Name | arguments | + ------------------------------------------------------------------------------- + | play | item(integer)| Play the specified item + | stop | | Stop + | pause | | Pause + | next | | Go to the next playlist element + | previous | | Got to the previous playlist element + | fullscreen | | toggle fullscreen + | volume | value(string)| set volume level (absolute or relative) + | seek | seek_value | c.f. notes + | add | mrl(string) | Add a mrl to the playlist (with its options) + | delete | item(integer)| Deletes an (list of) element of the playlist + | keep | item(integer)| Deletes all but (list of) element of the playlist + | sort | type,order | c.f. notes + | empty | | Empty the playlist + | close | id(hexa) | Close a specific connection + | shutdown | | Quit vlc For example, you can restrict the execution of the shutdown command to protected pages (through a .access) using the control macro in all pages unprotected. +Notes: + Seek: The seek command is used to seek in current playing stream. the +seek_value argument is a string which represents a relative or absolute +position in the stream: a percentage, or a time. +For examples "+12min 42sec", "01:13:43", "-12%", "42%", or +"1 hour 12 minutes" are valid argument values. + Sort: sorts the playlist by type (string), and with the order (integer). +If order is "0", it is normal order. Otherwise it is reverse order. The +type can be "title", "group", "author". + + 2. Macro "get" -------------- @@ -285,7 +308,7 @@ variable will be displayed (instead of it name). a set of integer. The stack element should be a string like: first:last[:step][,first2:last2[:step2][,...] Ex: 1:5:2,6:8:1 will be expanded into 1,3,5,6,7,8 - + - "directory" : take the first element of the stack as the base directory and construct a set of filename and directly in it. Each element has the following fields: @@ -331,7 +354,7 @@ variable will be displayed (instead of it name). - ip : - url: - status: HTTP error code. - + - the name of a foreach variable if it's a set of set of value. Ex : diff --git a/modules/control/http.c b/modules/control/http.c index c0782bbb77..6eceff2a35 100644 --- a/modules/control/http.c +++ b/modules/control/http.c @@ -2,7 +2,7 @@ * http.c : http mini-server ;) ***************************************************************************** * Copyright (C) 2001 VideoLAN - * $Id: http.c,v 1.31 2003/11/09 05:22:56 garf Exp $ + * $Id: http.c,v 1.32 2003/11/12 02:43:33 garf Exp $ * * Authors: Gildas Bazin * Laurent Aimar @@ -124,6 +124,10 @@ static char *uri_extract_value( char *psz_uri, char *psz_name, char *psz_value, int i_value_max ); static void uri_decode_url_encoded( char *psz ); +static char *Find_end_MRL( char *psz ); + +static playlist_item_t * parse_MRL( char *psz ); + /***************************************************************************** * *****************************************************************************/ @@ -1627,7 +1631,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args, case TIME_REL_FOR: { var_Get( p_sys->p_input, "time", &val ); - if( (uint64_t)( i_value ) * 1000 + val.i_time <= i_length ) + if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length ) { val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time; } else @@ -1741,11 +1745,22 @@ static void MacroDo( httpd_file_callback_args_t *p_args, case MVLC_ADD: { char mrl[512]; + playlist_item_t * p_item; + uri_extract_value( p_request, "mrl", mrl, 512 ); uri_decode_url_encoded( mrl ); - playlist_Add( p_sys->p_playlist, mrl, NULL, 0, - PLAYLIST_APPEND, PLAYLIST_END ); - msg_Dbg( p_intf, "requested playlist add: %s", mrl ); + p_item = parse_MRL( mrl ); + + if( p_item == NULL ) + { + msg_Dbg( p_intf, "invalid requested mrl: %s", mrl ); + } else + { + playlist_AddItem( p_sys->p_playlist , p_item , + PLAYLIST_APPEND, PLAYLIST_END ); + msg_Dbg( p_intf, "requested mrl add: %s", mrl ); + } + break; } case MVLC_DEL: @@ -2297,9 +2312,9 @@ static int http_get( httpd_file_callback_args_t *p_args, var_Get( p_sys->p_input, "position", &val); sprintf( position, "%d" , (int)((val.f_float) * 100.0)); var_Get( p_sys->p_input, "time", &val); - sprintf( time, "%d" , (int)(val.i_time / 1000) ); + sprintf( time, "%d" , (int)(val.i_time / 1000000) ); var_Get( p_sys->p_input, "length", &val); - sprintf( length, "%d" , (int)(val.i_time / 1000) ); + sprintf( length, "%d" , (int)(val.i_time / 1000000) ); var_Get( p_sys->p_input, "state", &val ); if( val.i_int == PLAYING_S ) @@ -2667,6 +2682,16 @@ static void EvaluateRPN( mvar_t *vars, rpn_stack_t *st, char *exp ) free( s1 ); free( s2 ); } + else if( !strcmp( s, "strncmp" ) ) + { + char *s1 = SSPop( st ); + char *s2 = SSPop( st ); + int n = SSPopN( st, vars ); + + SSPushN( st, strncmp( s1, s2 , n ) ); + free( s1 ); + free( s2 ); + } else if( !strcmp( s, "strlen" ) ) { char *str = SSPop( st ); @@ -2736,3 +2761,213 @@ static void EvaluateRPN( mvar_t *vars, rpn_stack_t *st, char *exp ) } } } + +/********************************************************************** + * Find_end_MRL: Find the end of the sentence : + * this function parses the string psz and find the end of the item + * and/or option with detecting the " and ' problems. + * returns NULL if an error is detected, otherwise, returns a pointer + * of the end of the sentence (after the last character) + **********************************************************************/ +static char *Find_end_MRL( char *psz ) +{ + char *s_sent = psz; + + switch( *s_sent ) + { + case '\"': + { + s_sent++; + + while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) ) + { + if( *s_sent == '\'' ) + { + s_sent = Find_end_MRL( s_sent ); + + if( s_sent == NULL ) + { + return NULL; + } + } else + { + s_sent++; + } + } + + if( *s_sent == '\"' ) + { + s_sent++; + return s_sent; + } else /* *s_sent == '\0' , which means the number of " is incorrect */ + { + return NULL; + } + break; + } + case '\'': + { + s_sent++; + + while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) ) + { + if( *s_sent == '\"' ) + { + s_sent = Find_end_MRL( s_sent ); + + if( s_sent == NULL ) + { + return NULL; + } + } else + { + s_sent++; + } + } + + if( *s_sent == '\'' ) + { + s_sent++; + return s_sent; + } else /* *s_sent == '\0' , which means the number of ' is incorrect */ + { + return NULL; + } + break; + } + default: /* now we can look for spaces */ + { + while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) ) + { + if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) ) + { + s_sent = Find_end_MRL( s_sent ); + } else + { + s_sent++; + } + } + return s_sent; + } + } +} + +/********************************************************************** + * parse_MRL: parse the MRL, find the mrl string and the options, + * create an item with all informations in it, and return the item. + * return NULL if there is an error. + **********************************************************************/ +playlist_item_t * parse_MRL( char *psz ) +{ + char **ppsz_options = NULL; + char *mrl; + char *s_mrl = psz; + int i_error = 0; + char *s_temp; + int i = 0; + int i_options = 0; + playlist_item_t * p_item; + + /* In case there is spaces before the mrl */ + while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) ) + { + s_mrl++; + } + + /* extract the mrl */ + s_temp = Find_end_MRL( s_mrl ); + + if( s_temp == NULL ) + { + return NULL; + } + + /* if the mrl is between " or ', we must remove them */ + if( (*s_mrl == '\'') || (*s_mrl == '\"') ) + { + mrl = (char *)malloc( (s_temp - s_mrl - 1) * sizeof( char ) ); + strncpy( mrl , (s_mrl + 1) , s_temp - s_mrl - 2 ); + mrl[ s_temp - s_mrl - 2 ] = '\0'; + } else + { + mrl = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) ); + strncpy( mrl , s_mrl , s_temp - s_mrl ); + mrl[ s_temp - s_mrl ] = '\0'; + } + + s_mrl = s_temp; + + /* now we can take care of the options */ + while( (*s_mrl != '\0') && (i_error == 0) ) + { + switch( *s_mrl ) + { + case ' ': + { + s_mrl++; + break; + } + case ':': /* an option */ + { + s_temp = Find_end_MRL( s_mrl ); + + if( s_temp == NULL ) + { + i_error = 1; + } else + { + i_options++; + ppsz_options = (char **)realloc( ppsz_options , i_options * sizeof(char *) ); + ppsz_options[ i_options - 1 ] = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) ); + + strncpy( ppsz_options[ i_options - 1 ] , s_mrl , s_temp - s_mrl ); + /* don't forget to finish the string with a '\0' */ + (ppsz_options[ i_options - 1 ])[ s_temp - s_mrl ] = '\0'; + + s_mrl = s_temp; + } + break; + } + default: + { + i_error = 1; + break; + } + } + } + + if( i_error != 0 ) + { + free( mrl ); + for( i = 0 ; i < i_options ; i++ ) + { + free( ppsz_options[i] ); + } + free( ppsz_options ); + return NULL; + } else + { + /* now create an item */ + p_item = malloc( sizeof( playlist_item_t ) ); + + p_item->psz_name = mrl; + p_item->psz_uri = mrl; + p_item->psz_author = strdup( "" ); + p_item->i_duration = -1; + p_item->i_type = 0; + p_item->i_status = 0; + p_item->b_autodeletion = VLC_FALSE; + p_item->b_enabled = VLC_TRUE; + p_item->i_group = PLAYLIST_TYPE_MANUAL; + + p_item->ppsz_options = NULL; + p_item->i_options = i_options; + + if( i_options ) + { + p_item->ppsz_options = ppsz_options; + } + + return p_item; + } +} diff --git a/share/Makefile.am b/share/Makefile.am index 4198f5783d..91e776c84c 100644 --- a/share/Makefile.am +++ b/share/Makefile.am @@ -133,4 +133,5 @@ DIST_http = \ http/admin/index.html \ http/admin/browse.html \ http/admin/.access \ + http/style.css \ $(NULL) diff --git a/share/http/index.html b/share/http/index.html index 71f4492a95..fb68163ecf 100644 --- a/share/http/index.html +++ b/share/http/index.html @@ -20,13 +20,12 @@
- - + + - - - - - - +
Current State: Information AdministrationCurrent State: Information Administration
+ @@ -35,15 +34,30 @@
+ Current Volume:
( Seek Textbox: for example "+12min 42sec", "01:13:43", "-12%" etc... ) + + + + + + + + + + + + + +
+ ( Seek Textbox: for example "+12min 42sec", "01:13:43", "-12%" etc... ) +
+
@@ -62,44 +76,45 @@ - -
VLC Playlist
-
-
- - - ligne1ligne2"> - - -
- "> - - - - "> - - - -
- - -
- - -
- by - with - -
- - +
VLC Playlist
+
+ + +
+ by + with + +
+ + +
+ + + ligne1ligne2"> + + + +
+ "> + + + + "> - + + + +
+ + +