/*****************************************************************************
* http.c : http mini-server ;)
*****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: http.c,v 1.32 2003/11/12 02:43:33 garf Exp $
+ * Copyright (C) 2001-2004 VideoLAN
+ * $Id: http.c,v 1.49 2004/01/18 07:35:31 fenrir Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Laurent Aimar <fenrir@via.ecp.fr>
goto failed;
}
p_intf->pf_run = Run;
+ free( psz_src );
return VLC_SUCCESS;
failed:
+ if( psz_src ) free( psz_src );
free( p_sys->pp_files );
p_sys->p_httpd->pf_unregister_host( p_sys->p_httpd,
p_sys->p_httpd_host );
if( !f )
{
msg_Err( p_intf, "Out of memory" );
+ closedir( p_dir );
return( VLC_ENOMEM );
}
f->p_intf = p_intf;
if( !f->name || !f->mime )
{
msg_Err( p_intf , "Unable to parse directory" );
+ closedir( p_dir );
+ free( f );
return( VLC_ENOMEM );
}
msg_Dbg( p_intf, "file=%s (url=%s mime=%s)",
if( !f )
{
msg_Err( p_intf, "Out of memory" );
+ closedir( p_dir );
return( VLC_ENOMEM );
}
f->p_intf = p_intf;
{
free( password );
}
+
+ closedir( p_dir );
+
return VLC_SUCCESS;
}
mvar_AppendNewVar( itm, "name", p_pl->pp_items[i]->psz_name );
+ sprintf( value, "%d", p_pl->pp_items[i]->i_group );
+ mvar_AppendNewVar( itm, "group", value );
+
mvar_AppendVar( s, itm );
}
vlc_mutex_unlock( &p_pl->object_lock );
free( info.info[i].psz_name );
free( info.info[i].psz_value );
}
+ if( info.i_count > 0 )
+ {
+ free( info.info );
+ }
return s;
}
uri_decode_url_encoded( mrl );
p_item = parse_MRL( mrl );
- if( p_item == NULL )
+ if( !p_item || !p_item->psz_uri || !*p_item->psz_uri )
{
msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
} else
{
int i_item, *p_items = NULL, i_nb_items = 0;
char item[512], *p_parser = p_request;
- int i,j,temp;
+ int i,j;
/* Get the list of items to keep */
while( (p_parser =
if( !*item ) continue;
i_item = atoi( item );
- p_items = realloc( p_items, (i_nb_items + 3) *
+ p_items = realloc( p_items, (i_nb_items + 1) *
sizeof(int) );
- p_items[i_nb_items + 1] = i_item;
+ p_items[i_nb_items] = i_item;
i_nb_items++;
}
- /* sort item list */
- for( i=1 ; i < (i_nb_items + 1) ; i++)
+ /* The items need to be deleted from in reversed order */
+ for( i = p_sys->p_playlist->i_size - 1; i >= 0 ; i-- )
{
- for( j=(i+1) ; j < (i_nb_items + 1) ; j++)
+ /* Check if the item is in the keep list */
+ for( j = 0 ; j < i_nb_items ; j++ )
{
- if( p_items[j] > p_items[i] )
- {
- temp = p_items[j];
- p_items[j] = p_items[i];
- p_items[i] = temp;
- }
+ if( p_items[j] == i ) break;
}
- }
-
- p_items[0] = p_sys->p_playlist->i_size;
- p_items[ i_nb_items + 1 ] = -1;
-
- /* The items need to be deleted from in reversed order */
- for( i=0 ; i <= i_nb_items ; i++ )
+ if( j == i_nb_items )
{
- for( j = (p_items[i] - 1) ; j > p_items[i + 1] ; j-- )
- {
- playlist_Delete( p_sys->p_playlist,
- j );
- msg_Dbg( p_intf, "requested playlist delete: %d",
- j );
- }
+ playlist_Delete( p_sys->p_playlist, i );
+ msg_Dbg( p_intf, "requested playlist delete: %d",
+ i );
}
+ }
if( p_items ) free( p_items );
break;
uri_extract_value( p_request, "type", type, 12 );
uri_extract_value( p_request, "order", order, 2 );
- if( order[0] == '0' ) i_order = SORT_NORMAL;
- else i_order = SORT_REVERSE;
+ if( order[0] == '0' ) i_order = ORDER_NORMAL;
+ else i_order = ORDER_REVERSE;
if( !strcmp( type , "title" ) )
{
case MVLC_STRING:
psz = config_GetPsz( p_intf, m->param1 );
sprintf( value, "%s", psz ? psz : "" );
+ if( psz ) free( psz );
break;
default:
sprintf( value, "invalid type(%s) in set", m->param2 );
break;
}
+ MacroClean( &m );
+
if( ( i_mvlc == MVLC_END && i_level == -1 ) ||
( i_mvlc != MVLC_END && i_level == 0 && i_mvlc == i_id ) )
{
p += sprintf( p, "<body>\n" );
p += sprintf( p, "<h1><center>Error loading %s for %s</center></h1>\n", p_args->file, p_args->name );
p += sprintf( p, "<hr />\n" );
- p += sprintf( p, "<a href=\"http://www.videolan.org\">VideoLAN</a>\n" );
+ p += sprintf( p, "<a href=\"http://www.videolan.org/\">VideoLAN</a>\n" );
p += sprintf( p, "</body>\n" );
p += sprintf( p, "</html>\n" );
- *pi_data = strlen( *pp_data ) + 1;
+ *pi_data = strlen( *pp_data );
return VLC_SUCCESS;
}
/* 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] );
- *dst++ = '\0';
+ *dst = '\0';
*pi_data = dst - *pp_data;
SSClean( &p_args->stack );
mvar_Delete( p_args->vars );
+ free( p_buffer );
}
fclose( f );
static char *uri_extract_value( char *psz_uri, char *psz_name,
char *psz_value, int i_value_max )
{
- char *p;
+ char *p = psz_uri;
+
+ 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' )
+ break;
+ p++;
+ }
- p = strstr( psz_uri, psz_name );
if( p )
{
int i_len;
}
else if( !strcmp( s, "-" ) )
{
- int i = SSPopN( st, vars );
int j = SSPopN( st, vars );
+ int i = SSPopN( st, vars );
SSPushN( st, i - j );
}
else if( !strcmp( s, "*" ) )
{
int i, j;
- i = SSPopN( st, vars );
j = SSPopN( st, vars );
+ i = SSPopN( st, vars );
SSPushN( st, j != 0 ? i / j : 0 );
}
{
int i, j;
- i = SSPopN( st, vars );
j = SSPopN( st, vars );
+ i = SSPopN( st, vars );
SSPushN( st, j != 0 ? i % j : 0 );
}
}
else if( !strcmp( s, "<" ) )
{
- int i = SSPopN( st, vars );
int j = SSPopN( st, vars );
+ int i = SSPopN( st, vars );
SSPushN( st, i < j ? -1 : 0 );
}
else if( !strcmp( s, ">" ) )
{
- int i = SSPopN( st, vars );
int j = SSPopN( st, vars );
+ int i = SSPopN( st, vars );
SSPushN( st, i > j ? -1 : 0 );
}
else if( !strcmp( s, "<=" ) )
{
- int i = SSPopN( st, vars );
int j = SSPopN( st, vars );
+ int i = SSPopN( st, vars );
SSPushN( st, i <= j ? -1 : 0 );
}
else if( !strcmp( s, ">=" ) )
{
- int i = SSPopN( st, vars );
int j = SSPopN( st, vars );
+ int i = SSPopN( st, vars );
SSPushN( st, i >= j ? -1 : 0 );
}
/* 3. string functions */
else if( !strcmp( s, "strcat" ) )
{
- char *s1 = SSPop( st );
char *s2 = SSPop( st );
+ char *s1 = SSPop( st );
char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
strcpy( str, s1 );
}
else if( !strcmp( s, "strcmp" ) )
{
- char *s1 = SSPop( st );
char *s2 = SSPop( st );
+ char *s1 = SSPop( st );
SSPushN( st, strcmp( s1, s2 ) );
free( s1 );
}
else if( !strcmp( s, "strncmp" ) )
{
- char *s1 = SSPop( st );
- char *s2 = SSPop( st );
int n = SSPopN( st, vars );
+ char *s2 = SSPop( st );
+ char *s1 = SSPop( st );
SSPushN( st, strncmp( s1, s2 , n ) );
free( s1 );
}
else if( !strcmp( s, "store" ) )
{
- char *name = SSPop( st );
char *value = SSPop( st );
+ char *name = SSPop( st );
mvar_PushNewVar( vars, name, value );
free( name );
char *s_temp;
int i = 0;
int i_options = 0;
- playlist_item_t * p_item;
+ playlist_item_t * p_item = NULL;
/* In case there is spaces before the mrl */
while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
}
/* extract the mrl */
- s_temp = Find_end_MRL( s_mrl );
-
+ s_temp = strstr( s_mrl , " :" );
if( s_temp == NULL )
{
- return 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_temp == NULL )
{
i_error = 1;
- } else
+ }
+ 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 ) );
+ 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 );
- 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';
if( i_error != 0 )
{
free( mrl );
- for( i = 0 ; i < i_options ; i++ )
- {
- free( ppsz_options[i] );
- }
- free( ppsz_options );
- return NULL;
- } else
+ }
+ else
{
/* now create an item */
p_item = malloc( sizeof( playlist_item_t ) );
-
+ memset( p_item, 0, sizeof( playlist_item_t ) );
p_item->psz_name = mrl;
- p_item->psz_uri = mrl;
- p_item->psz_author = strdup( "" );
+ p_item->psz_uri = strdup( mrl );
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 )
+ for( i = 0 ; i< i_options ; i++ )
{
- p_item->ppsz_options = ppsz_options;
+ playlist_AddItemOption( p_item, ppsz_options[i] );
}
+ }
- return p_item;
+ for( i = 0 ; i < i_options ; i++ )
+ {
+ free( ppsz_options[i] );
}
+ free( ppsz_options );
+
+ return p_item;
}