*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Laurent Aimar <fenrir@via.ecp.fr>
+ * Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
static void uri_decode_url_encoded( char *psz );
-static char *Find_end_MRL( char *psz );
static playlist_item_t *parse_MRL( intf_thread_t *, char *psz, char *psz_name );
/*****************************************************************************
/*****************************************************************************
* Close: destroy interface
*****************************************************************************/
-void Close ( vlc_object_t *p_this )
+static void Close ( vlc_object_t *p_this )
{
intf_thread_t *p_intf = (intf_thread_t *)p_this;
intf_sys_t *p_sys = p_intf->p_sys;
/*****************************************************************************
* Local functions
*****************************************************************************/
-#define MAX_DIR_SIZE 10240
+#define MAX_DIR_SIZE 2560
/****************************************************************************
* FileToUrl: create a good name for an url from filename
if( ( p_dir_content->d_name[0] == '.' )
|| ( i_dirlen + strlen( p_dir_content->d_name ) > MAX_DIR_SIZE ) )
continue;
-
+
sprintf( dir, "%s/%s", psz_dir, p_dir_content->d_name );
if( ParseDirectory( p_intf, psz_root, dir ) )
{
return s;
}
+
+static mvar_t *mvar_InputVarSetNew( intf_thread_t *p_intf, char *name,
+ input_thread_t *p_input,
+ const char *psz_variable )
+{
+ intf_sys_t *p_sys = p_intf->p_sys;
+ mvar_t *s = mvar_New( name, "set" );
+ vlc_value_t val, val_list, text_list;
+ int i_type, i;
+
+ if( p_input == NULL )
+ {
+ return s;
+ }
+
+ /* Check the type of the object variable */
+ i_type = var_Type( p_sys->p_input, psz_variable );
+
+ /* Make sure we want to display the variable */
+ if( i_type & VLC_VAR_HASCHOICE )
+ {
+ var_Change( p_sys->p_input, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
+ if( val.i_int == 0 ) return s;
+ if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
+ return s;
+ }
+ else
+ {
+ return s;
+ }
+
+ switch( i_type & VLC_VAR_TYPE )
+ {
+ case VLC_VAR_VOID:
+ case VLC_VAR_BOOL:
+ case VLC_VAR_VARIABLE:
+ case VLC_VAR_STRING:
+ case VLC_VAR_INTEGER:
+ break;
+ default:
+ /* Variable doesn't exist or isn't handled */
+ return s;
+ }
+
+ if( var_Get( p_sys->p_input, psz_variable, &val ) < 0 )
+ {
+ return s;
+ }
+
+ if( var_Change( p_sys->p_input, psz_variable, VLC_VAR_GETLIST,
+ &val_list, &text_list ) < 0 )
+ {
+ if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
+ return s;
+ }
+
+ for( i = 0; i < val_list.p_list->i_count; i++ )
+ {
+ char *psz, psz_int[16];
+ mvar_t *itm;
+
+ switch( i_type & VLC_VAR_TYPE )
+ {
+ case VLC_VAR_STRING:
+ itm = mvar_New( name, "set" );
+ psz = FromUTF8( p_intf, text_list.p_list->p_values[i].psz_string );
+ mvar_AppendNewVar( itm, "name", psz );
+ psz = FromUTF8( p_intf, val_list.p_list->p_values[i].psz_string );
+ mvar_AppendNewVar( itm, "id", psz );
+ free( psz );
+ snprintf( psz_int, sizeof(psz_int), "%d",
+ ( !strcmp( val.psz_string,
+ val_list.p_list->p_values[i].psz_string )
+ && !( i_type & VLC_VAR_ISCOMMAND ) ) );
+ mvar_AppendNewVar( itm, "selected", psz_int );
+ mvar_AppendVar( s, itm );
+ break;
+
+ case VLC_VAR_INTEGER:
+ itm = mvar_New( name, "set" );
+ psz = FromUTF8( p_intf, text_list.p_list->p_values[i].psz_string );
+ mvar_AppendNewVar( itm, "name", psz );
+ snprintf( psz_int, sizeof(psz_int), "%d",
+ val_list.p_list->p_values[i].i_int );
+ mvar_AppendNewVar( itm, "id", psz_int );
+ snprintf( psz_int, sizeof(psz_int), "%d",
+ ( val.i_int == val_list.p_list->p_values[i].i_int )
+ && !( i_type & VLC_VAR_ISCOMMAND ) );
+ mvar_AppendNewVar( itm, "selected", psz_int );
+ mvar_AppendVar( s, itm );
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ /* clean up everything */
+ if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
+ var_Change( p_sys->p_input, psz_variable, VLC_VAR_FREELIST, &val_list,
+ &text_list );
+ return s;
+}
+
#if 0
static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
{
return VLC_TRUE;
}
+static int InsensitiveAlphasort( const struct dirent **foo1,
+ const struct dirent **foo2 )
+{
+ return strcasecmp( (*foo1)->d_name, (*foo2)->d_name );
+}
+
static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
char *psz_dir )
{
}
*p = '\0';
-
#ifdef HAVE_SYS_STAT_H
if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
{
/* parse psz_src dir */
if( ( i_dir_content = scandir( psz_dir, &pp_dir_content, Filter,
- alphasort ) ) == -1 )
+ InsensitiveAlphasort ) ) == -1 )
{
msg_Warn( p_intf, "scandir error on %s (%s)", psz_dir,
strerror(errno) );
char *param2;
} macro_t;
+static void Seek( intf_thread_t *p_intf, char *p_value )
+{
+ intf_sys_t *p_sys = p_intf->p_sys;
+ vlc_value_t val;
+ int i_stock = 0;
+ uint64_t i_length;
+ int i_value = 0;
+ int i_relative = 0;
+#define POSITION_ABSOLUTE 12
+#define POSITION_REL_FOR 13
+#define POSITION_REL_BACK 11
+#define VL_TIME_ABSOLUTE 0
+#define VL_TIME_REL_FOR 1
+#define VL_TIME_REL_BACK -1
+ if( p_sys->p_input )
+ {
+ var_Get( p_sys->p_input, "length", &val );
+ i_length = val.i_time;
+
+ while( p_value[0] != '\0' )
+ {
+ switch(p_value[0])
+ {
+ case '+':
+ {
+ i_relative = VL_TIME_REL_FOR;
+ p_value++;
+ break;
+ }
+ case '-':
+ {
+ i_relative = VL_TIME_REL_BACK;
+ p_value++;
+ break;
+ }
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ {
+ i_stock = strtol( p_value , &p_value , 10 );
+ break;
+ }
+ case '%': /* for percentage ie position */
+ {
+ i_relative += POSITION_ABSOLUTE;
+ i_value = i_stock;
+ i_stock = 0;
+ p_value[0] = '\0';
+ break;
+ }
+ case ':':
+ {
+ i_value = 60 * (i_value + i_stock) ;
+ i_stock = 0;
+ p_value++;
+ break;
+ }
+ case 'h': case 'H': /* hours */
+ {
+ i_value += 3600 * i_stock;
+ i_stock = 0;
+ /* other characters which are not numbers are not important */
+ while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
+ {
+ p_value++;
+ }
+ break;
+ }
+ case 'm': case 'M': case '\'': /* minutes */
+ {
+ i_value += 60 * i_stock;
+ i_stock = 0;
+ p_value++;
+ while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
+ {
+ p_value++;
+ }
+ break;
+ }
+ case 's': case 'S': case '"': /* seconds */
+ {
+ i_value += i_stock;
+ i_stock = 0;
+ while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
+ {
+ p_value++;
+ }
+ break;
+ }
+ default:
+ {
+ p_value++;
+ break;
+ }
+ }
+ }
+
+ /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
+ i_value += i_stock;
+
+ switch(i_relative)
+ {
+ case VL_TIME_ABSOLUTE:
+ {
+ if( (uint64_t)( i_value ) * 1000000 <= i_length )
+ val.i_time = (uint64_t)( i_value ) * 1000000;
+ else
+ val.i_time = i_length;
+
+ var_Set( p_sys->p_input, "time", val );
+ msg_Dbg( p_intf, "requested seek position: %dsec", i_value );
+ break;
+ }
+ case VL_TIME_REL_FOR:
+ {
+ var_Get( p_sys->p_input, "time", &val );
+ if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
+ {
+ val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
+ } else
+ {
+ val.i_time = i_length;
+ }
+ var_Set( p_sys->p_input, "time", val );
+ msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );
+ break;
+ }
+ case VL_TIME_REL_BACK:
+ {
+ var_Get( p_sys->p_input, "time", &val );
+ if( (int64_t)( i_value ) * 1000000 > val.i_time )
+ {
+ val.i_time = 0;
+ } else
+ {
+ val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);
+ }
+ var_Set( p_sys->p_input, "time", val );
+ msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );
+ break;
+ }
+ case POSITION_ABSOLUTE:
+ {
+ val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
+ var_Set( p_sys->p_input, "position", val );
+ msg_Dbg( p_intf, "requested seek percent: %d", i_value );
+ break;
+ }
+ case POSITION_REL_FOR:
+ {
+ var_Get( p_sys->p_input, "position", &val );
+ val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
+ var_Set( p_sys->p_input, "position", val );
+ msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
+ break;
+ }
+ case POSITION_REL_BACK:
+ {
+ var_Get( p_sys->p_input, "position", &val );
+ val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
+ var_Set( p_sys->p_input, "position", val );
+ msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
+ break;
+ }
+ default:
+ {
+ msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
+ break;
+ }
+ }
+ }
+#undef POSITION_ABSOLUTE
+#undef POSITION_REL_FOR
+#undef POSITION_REL_BACK
+#undef VL_TIME_ABSOLUTE
+#undef VL_TIME_REL_FOR
+#undef VL_TIME_REL_BACK
+}
+
static int FileLoad( FILE *f, char **pp_data, int *pi_data )
{
int i_read;
MVLC_VLM_LOAD,
MVLC_VLM_SAVE,
+ MVLC_INCLUDE,
MVLC_FOREACH,
MVLC_IF,
MVLC_RPN,
{ "rpn", MVLC_RPN },
{ "stack", MVLC_STACK },
+ { "include", MVLC_INCLUDE },
{ "foreach", MVLC_FOREACH },
{ "value", MVLC_VALUE },
msg_Dbg( p_intf, "requested playlist previous" );
break;
case MVLC_FULLSCREEN:
- {
if( p_sys->p_input )
{
vout_thread_t *p_vout;
msg_Dbg( p_intf, "requested fullscreen toggle" );
}
}
- }
- break;
+ break;
case MVLC_SEEK:
{
- vlc_value_t val;
char value[30];
- char * p_value;
- int i_stock = 0;
- uint64_t i_length;
- int i_value = 0;
- int i_relative = 0;
-#define POSITION_ABSOLUTE 12
-#define POSITION_REL_FOR 13
-#define POSITION_REL_BACK 11
-#define VL_TIME_ABSOLUTE 0
-#define VL_TIME_REL_FOR 1
-#define VL_TIME_REL_BACK -1
- if( p_sys->p_input )
- {
- uri_extract_value( p_request, "seek_value", value, 20 );
- uri_decode_url_encoded( value );
- p_value = value;
- var_Get( p_sys->p_input, "length", &val);
- i_length = val.i_time;
-
- while( p_value[0] != '\0' )
- {
- switch(p_value[0])
- {
- case '+':
- {
- i_relative = VL_TIME_REL_FOR;
- p_value++;
- break;
- }
- case '-':
- {
- i_relative = VL_TIME_REL_BACK;
- p_value++;
- break;
- }
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- {
- i_stock = strtol( p_value , &p_value , 10 );
- break;
- }
- case '%': /* for percentage ie position */
- {
- i_relative += POSITION_ABSOLUTE;
- i_value = i_stock;
- i_stock = 0;
- p_value[0] = '\0';
- break;
- }
- case ':':
- {
- i_value = 60 * (i_value + i_stock) ;
- i_stock = 0;
- p_value++;
- break;
- }
- case 'h': case 'H': /* hours */
- {
- i_value += 3600 * i_stock;
- i_stock = 0;
- /* other characters which are not numbers are not important */
- while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
- {
- p_value++;
- }
- break;
- }
- case 'm': case 'M': case '\'': /* minutes */
- {
- i_value += 60 * i_stock;
- i_stock = 0;
- p_value++;
- while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
- {
- p_value++;
- }
- break;
- }
- case 's': case 'S': case '"': /* seconds */
- {
- i_value += i_stock;
- i_stock = 0;
- while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
- {
- p_value++;
- }
- break;
- }
- default:
- {
- p_value++;
- break;
- }
- }
- }
-
- /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
- i_value += i_stock;
-
- switch(i_relative)
- {
- case VL_TIME_ABSOLUTE:
- {
- if( (uint64_t)( i_value ) * 1000000 <= i_length )
- val.i_time = (uint64_t)( i_value ) * 1000000;
- else
- val.i_time = i_length;
-
- var_Set( p_sys->p_input, "time", val );
- msg_Dbg( p_intf, "requested seek position: %dsec", i_value );
- break;
- }
- case VL_TIME_REL_FOR:
- {
- var_Get( p_sys->p_input, "time", &val );
- if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
- {
- val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
- } else
- {
- val.i_time = i_length;
- }
- var_Set( p_sys->p_input, "time", val );
- msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );
- break;
- }
- case VL_TIME_REL_BACK:
- {
- var_Get( p_sys->p_input, "time", &val );
- if( (int64_t)( i_value ) * 1000000 > val.i_time )
- {
- val.i_time = 0;
- } else
- {
- val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);
- }
- var_Set( p_sys->p_input, "time", val );
- msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );
- break;
- }
- case POSITION_ABSOLUTE:
- {
- val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
- var_Set( p_sys->p_input, "position", val );
- msg_Dbg( p_intf, "requested seek percent: %d", i_value );
- break;
- }
- case POSITION_REL_FOR:
- {
- var_Get( p_sys->p_input, "position", &val );
- val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
- var_Set( p_sys->p_input, "position", val );
- msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
- break;
- }
- case POSITION_REL_BACK:
- {
- var_Get( p_sys->p_input, "position", &val );
- val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
- var_Set( p_sys->p_input, "position", val );
- msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
- break;
- }
- default:
- {
- msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
- break;
- }
- }
- }
-#undef POSITION_ABSOLUTE
-#undef POSITION_REL_FOR
-#undef POSITION_REL_BACK
-#undef VL_TIME_ABSOLUTE
-#undef VL_TIME_REL_FOR
-#undef VL_TIME_REL_BACK
+ uri_extract_value( p_request, "seek_value", value, 30 );
+ uri_decode_url_encoded( value );
+ Seek( p_intf, value );
break;
}
case MVLC_VOLUME:
EvaluateRPN( p_intf, p_args->vars, &p_args->stack, m->param1 );
break;
-/* Usefull for learning stack management */
+ /* Useful to learn stack management */
case MVLC_STACK:
{
int i;
switch( StrToMacroType( m.id ) )
{
+ case MVLC_INCLUDE:
+ {
+ FILE *f;
+ int i_buffer;
+ char *p_buffer;
+ char psz_file[MAX_DIR_SIZE];
+ char *p;
+
+ if( m.param1[0] != '/' )
+ {
+ strcpy( psz_file, p_args->file );
+ p = strrchr( psz_file, '/' );
+ if( p != NULL )
+ strcpy( p + 1, m.param1 );
+ else
+ strcpy( psz_file, m.param1 );
+ }
+ else
+ {
+ strcpy( psz_file, m.param1 );
+ }
+
+ if( ( f = fopen( psz_file, "r" ) ) == NULL )
+ {
+ msg_Warn( p_args->p_intf,
+ "unable to include file %s (%s)",
+ psz_file, strerror(errno) );
+ break;
+ }
+
+ /* first we load in a temporary buffer */
+ FileLoad( f, &p_buffer, &i_buffer );
+
+ /* we parse executing all <vlc /> macros */
+ Execute( p_args, p_request, i_request, pp_data, pi_data,
+ &dst, &p_buffer[0], &p_buffer[i_buffer] );
+ free( p_buffer );
+ fclose(f);
+ break;
+ }
case MVLC_IF:
{
vlc_bool_t i_test;
index = mvar_InfoSetNew( p_intf, m.param1,
p_intf->p_sys->p_input );
}
+ else if( !strcmp( m.param2, "program" )
+ || !strcmp( m.param2, "title" )
+ || !strcmp( m.param2, "chapter" )
+ || !strcmp( m.param2, "audio-es" )
+ || !strcmp( m.param2, "video-es" )
+ || !strcmp( m.param2, "spu-es" ) )
+ {
+ index = mvar_InputVarSetNew( p_intf, m.param1,
+ p_intf->p_sys->p_input,
+ m.param2 );
+ }
else if( !strcmp( m.param2, "vlm" ) )
{
if( p_intf->p_sys->p_vlm == NULL )
if( val.i_int == PLAYING_S )
{
sprintf( state, "playing" );
- } else if( val.i_int == PAUSE_S )
+ }
+ else if( val.i_int == PAUSE_S )
{
sprintf( state, "paused" );
- } else
+ }
+ else
{
sprintf( state, "stop" );
}
- } else
+ }
+ else
{
sprintf( position, "%d", 0 );
sprintf( time, "%d", 0 );
while( (p = strstr( p, psz_name )) )
{
/* Verify that we are dealing with a post/get argument */
- if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
+ if( (p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n')
+ && p[strlen(psz_name)] == '=' )
{
return VLC_TRUE;
}
while( (p = strstr( p, psz_name )) )
{
/* Verify that we are dealing with a post/get argument */
- if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
+ if( (p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n')
+ && p[strlen(psz_name)] == '=' )
break;
p++;
}
free( dup );
}
+/* Since the resulting string is smaller we can work in place, so it is
+ * permitted to have psz == new. new points to the first word of the
+ * string, the function returns the remaining string. */
+static char *FirstWord( char *psz, char *new )
+{
+ vlc_bool_t b_end;
+
+ while( *psz == ' ' )
+ psz++;
+
+ while( *psz != '\0' && *psz != ' ' )
+ {
+ if( *psz == '\'' )
+ {
+ char c = *psz++;
+ while( *psz != '\0' && *psz != c )
+ {
+ if( *psz == '\\' && psz[1] != '\0' )
+ psz++;
+ *new++ = *psz++;
+ }
+ if( *psz == c )
+ psz++;
+ }
+ else
+ {
+ if( *psz == '\\' && psz[1] != '\0' )
+ psz++;
+ *new++ = *psz++;
+ }
+ }
+ b_end = !*psz;
+
+ *new++ = '\0';
+ if( !b_end )
+ return psz + 1;
+ else
+ return NULL;
+}
+
/****************************************************************************
* Light RPN evaluator
****************************************************************************/
{
intf_sys_t *p_sys = p_intf->p_sys;
- for( ;; )
+ while( exp != NULL && *exp != '\0' )
{
- char s[100], *p;
+ char *p, *s;
/* skip space */
while( *exp == ' ' )
if( *exp == '\'' )
{
/* extract string */
- p = &s[0];
- exp++;
- while( *exp && *exp != '\'' )
- {
- /* strip a level of backslashes */
- if( *exp == '\\' && exp[1] != '\0' )
- exp++;
- *p++ = *exp++;
- }
- *p = '\0';
- exp++;
- SSPush( st, s );
+ p = FirstWord( exp, exp );
+ SSPush( st, exp );
+ exp = p;
continue;
}
/* extract token */
- p = strchr( exp, ' ' );
- if( !p )
+ p = FirstWord( exp, exp );
+ s = exp;
+ if( p == NULL )
{
- strcpy( s, exp );
-
exp += strlen( exp );
}
else
{
- int i = p -exp;
- strncpy( s, exp, i );
- s[i] = '\0';
-
- exp = p + 1;
+ exp = p;
}
if( *s == '\0' )
free( s );
free( str );
}
- else if( !strcmp( s, "strlen" ) )
+ else if( !strcmp( s, "strlen" ) )
{
char *str = SSPop( st );
SSPushN( st, strlen( str ) );
free( str );
}
+ else if( !strcmp( s, "str_replace" ) )
+ {
+ char *psz_to = SSPop( st );
+ char *psz_from = SSPop( st );
+ char *psz_in = SSPop( st );
+ char *psz_in_current = psz_in;
+ char *psz_out = malloc( strlen(psz_in) * strlen(psz_to) + 1 );
+ char *psz_out_current = psz_out;
+
+ while( (p = strstr( psz_in_current, psz_from )) != NULL )
+ {
+ memcpy( psz_out_current, psz_in_current, p - psz_in_current );
+ psz_out_current += p - psz_in_current;
+ strcpy( psz_out_current, psz_to );
+ psz_out_current += strlen(psz_to);
+ psz_in_current = p + strlen(psz_from);
+ }
+ strcpy( psz_out_current, psz_in_current );
+ psz_out_current += strlen(psz_in_current);
+ *psz_out_current = '\0';
+
+ SSPush( st, psz_out );
+ free( psz_to );
+ free( psz_from );
+ free( psz_in );
+ free( psz_out );
+ }
+ else if( !strcmp( s, "url_extract" ) )
+ {
+ char *url = mvar_GetValue( vars, "url_value" );
+ char *name = SSPop( st );
+ char value[512];
+ char *tmp;
+
+ uri_extract_value( url, name, value, 512 );
+ uri_decode_url_encoded( value );
+ tmp = FromUTF8( p_intf, value );
+ SSPush( st, tmp );
+ free( tmp );
+ free( name );
+ }
+ else if( !strcmp( s, "url_encode" ) )
+ {
+ char *url = SSPop( st );
+ char *value;
+
+ value = ToUTF8( p_intf, url );
+ free( url );
+ url = value;
+ value = vlc_UrlEncode( url );
+ free( url );
+ SSPush( st, value );
+ free( value );
+ }
+ else if( !strcmp( s, "addslashes" ) )
+ {
+ char *psz_src = SSPop( st );
+ char *psz_dest;
+ char *str = psz_src;
+
+ p = psz_dest = malloc( strlen( str ) * 2 + 1 );
+
+ while( *str != '\0' )
+ {
+ if( *str == '"' || *str == '\'' )
+ {
+ *p++ = '\\';
+ }
+ *p++ = *str;
+ str++;
+ }
+ *p = '\0';
+
+ SSPush( st, psz_dest );
+ free( psz_src );
+ free( psz_dest );
+ }
+ else if( !strcmp( s, "stripslashes" ) )
+ {
+ char *psz_src = SSPop( st );
+ char *psz_dest;
+
+ p = psz_dest = strdup( psz_src );
+
+ while( *psz_src != '\0' )
+ {
+ if( *psz_src == '\\' )
+ {
+ *psz_src++;
+ }
+ *p++ = *psz_src;
+ psz_src++;
+ }
+ *p = '\0';
+
+ SSPush( st, psz_dest );
+ free( psz_src );
+ free( psz_dest );
+ }
+ else if( !strcmp( s, "htmlspecialchars" ) )
+ {
+ char *psz_src = SSPop( st );
+ char *psz_dest;
+ char *str = psz_src;
+
+ p = psz_dest = malloc( strlen( str ) * 6 + 1 );
+
+ while( *str != '\0' )
+ {
+ if( *str == '&' )
+ {
+ strcpy( p, "&" );
+ p += 5;
+ }
+ else if( *str == '\"' )
+ {
+ strcpy( p, """ );
+ p += 6;
+ }
+ else if( *str == '\'' )
+ {
+ strcpy( p, "'" );
+ p += 6;
+ }
+ else if( *str == '<' )
+ {
+ strcpy( p, "<" );
+ p += 4;
+ }
+ else if( *str == '>' )
+ {
+ strcpy( p, ">" );
+ p += 4;
+ }
+ else
+ {
+ *p++ = *str;
+ }
+ str++;
+ }
+ *p = '\0';
+
+ SSPush( st, psz_dest );
+ free( psz_src );
+ free( psz_dest );
+ }
+ else if( !strcmp( s, "realpath" ) )
+ {
+ char dir[MAX_DIR_SIZE], *src;
+ char *psz_src = SSPop( st );
+ char *psz_dir = psz_src;
+ char sep;
+
+ /* convert all / to native separator */
+#if defined( WIN32 )
+ while( (p = strchr( psz_dir, '/' )) )
+ {
+ *p = '\\';
+ }
+ sep = '\\';
+#else
+ sep = '/';
+#endif
+
+ if( *psz_dir == '~' )
+ {
+ /* This is incomplete : we should also support the ~cmassiot/ syntax. */
+ snprintf( dir, sizeof(dir), "%s/%s", p_intf->p_vlc->psz_homedir,
+ psz_dir + 1 );
+ psz_dir = dir;
+ }
+
+ /* first fix all .. dir */
+ p = src = psz_dir;
+ while( *src )
+ {
+ if( src[0] == '.' && src[1] == '.' )
+ {
+ src += 2;
+ if( p <= &psz_dir[1] )
+ {
+ continue;
+ }
+
+ p -= 2;
+
+ while( p > &psz_dir[1] && *p != sep )
+ {
+ p--;
+ }
+ }
+ else if( *src == sep )
+ {
+ if( p > psz_dir && p[-1] == sep )
+ {
+ src++;
+ }
+ else
+ {
+ *p++ = *src++;
+ }
+ }
+ else
+ {
+ do
+ {
+ *p++ = *src++;
+ } while( *src && *src != sep );
+ }
+ }
+ if( p != psz_dir + 1 && p[-1] == '/' ) p--;
+ *p = '\0';
+
+ SSPush( st, psz_dir );
+ free( psz_src );
+ }
/* 4. stack functions */
else if( !strcmp( s, "dup" ) )
{
free( name );
}
- else if( !strcmp( s, "url_extract" ) )
- {
- char *url = mvar_GetValue( vars, "url_value" );
- char *name = SSPop( st );
- char value[512];
- char *tmp;
-
- uri_extract_value( url, name, value, 512 );
- uri_decode_url_encoded( value );
- tmp = FromUTF8( p_intf, value );
- SSPush( st, tmp );
- free( tmp );
- }
- else if( !strcmp( s, "url_encode" ) )
- {
- char *url = SSPop( st );
- char *value;
-
- url = ToUTF8( p_intf, url );
- value = vlc_UrlEncode( url );
- free( url );
- SSPush( st, value );
- free( value );
- }
/* 5. player control */
else if( !strcmp( s, "vlc_play" ) )
{
playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1 );
msg_Dbg( p_intf, "requested playlist previous" );
}
+ else if( !strcmp( s, "vlc_seek" ) )
+ {
+ char *psz_value = SSPop( st );
+ Seek( p_intf, psz_value );
+ msg_Dbg( p_intf, "requested playlist seek: %s", psz_value );
+ free( psz_value );
+ }
+ else if( !strcmp( s, "vlc_set_var" ) )
+ {
+ char *psz_variable = SSPop( st );
+ char *psz_value = NULL;
+ vlc_value_t val;
+ int i_type;
+
+ if( p_sys->p_input != NULL )
+ {
+ i_type = var_Type( p_sys->p_input, psz_variable );
+
+ if( (i_type & VLC_VAR_TYPE) == VLC_VAR_INTEGER )
+ {
+ int i_value = SSPopN( st, vars );
+ val.i_int = i_value;
+ msg_Dbg( p_intf, "requested input var change: %s->%d",
+ psz_variable, i_value );
+ }
+ else
+ {
+ psz_value = SSPop( st );
+ val.psz_string = psz_value;
+ msg_Dbg( p_intf, "requested input var change: %s->%s",
+ psz_variable, psz_value );
+ }
+
+ var_Set( p_sys->p_input, psz_variable, val );
+ }
+ if( psz_value != NULL )
+ free( psz_value );
+ free( psz_variable );
+ }
/* 6. playlist functions */
else if( !strcmp( s, "playlist_add" ) )
{
char *psz_name = SSPop( st );
char *mrl = SSPop( st );
+ char *tmp;
playlist_item_t *p_item;
int i_id;
- psz_name = ToUTF8( p_intf, psz_name );
- mrl = ToUTF8( p_intf, mrl );
+ tmp = ToUTF8( p_intf, psz_name );
+ free( psz_name );
+ psz_name = tmp;
+ tmp = ToUTF8( p_intf, mrl );
+ free( mrl );
+ mrl = tmp;
if( !*psz_name )
{
}
if( p_item == NULL || p_item->input.psz_uri == NULL ||
- !*p_item->input.psz_uri )
+ !*p_item->input.psz_uri )
{
i_id = VLC_EGENERIC;
msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
}
}
-/**********************************************************************
- * 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 information in it, and return the item.
* return NULL if there is an error.
**********************************************************************/
-static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz,
+static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *_psz,
char *psz_name )
{
- char **ppsz_options = NULL;
- char *mrl;
+ char *psz = strdup( _psz );
char *s_mrl = psz;
- int i_error = 0;
char *s_temp;
- int i = 0;
- int i_options = 0;
playlist_item_t * p_item = NULL;
- /* In case there is spaces before the mrl */
- while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
- {
- s_mrl++;
- }
-
/* extract the mrl */
- s_temp = strstr( s_mrl , " :" );
+ s_temp = FirstWord( s_mrl, s_mrl );
if( s_temp == NULL )
{
s_temp = s_mrl + strlen( s_mrl );
- } else
- {
- while( (*s_temp == ' ') && (s_temp != s_mrl ) )
- {
- s_temp--;
- }
- s_temp++;
- }
-
- /* 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';
}
+ p_item = playlist_ItemNew( p_intf, s_mrl, psz_name );
s_mrl = s_temp;
/* now we can take care of the options */
- while( (*s_mrl != '\0') && (i_error == 0) )
+ while( *s_mrl != '\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 = realloc( ppsz_options , i_options *
- sizeof(char *) );
- ppsz_options[ i_options - 1 ] =
- 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 );
- }
- else
- {
- /* now create an item */
- p_item = playlist_ItemNew( p_intf, mrl, psz_name );
- for( i = 0 ; i< i_options ; i++ )
+ s_temp = FirstWord( s_mrl, s_mrl );
+ if( s_mrl == '\0' )
+ break;
+ if( s_temp == NULL )
{
- playlist_ItemAddOption( p_item, ppsz_options[i] );
+ s_temp = s_mrl + strlen( s_mrl );
}
+ if( *s_mrl != ':' )
+ msg_Warn( p_intf, "invalid MRL option: %s", s_mrl );
+ else
+ playlist_ItemAddOption( p_item, s_mrl );
+ s_mrl = s_temp;
}
- for( i = 0; i < i_options; i++ ) free( ppsz_options[i] );
- if( i_options ) free( ppsz_options );
-
+ free( psz );
return p_item;
}