#include "http.h"
#include <limits.h>
-
-#include <assert.h>
+#include <errno.h>
+#include <ctype.h>
+#include <fcntl.h>
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#include <vlc_fs.h>
+#include <vlc_services_discovery.h>
/* Utility function for scandir */
static int Filter( const char *foo )
v->value = strdup( value ? value : "" );
v->i_field = 0;
- v->field = malloc( sizeof( mvar_t * ) );
+ v->field = xmalloc( sizeof( mvar_t * ) );
v->field[0] = NULL;
return v;
void mvar_AppendVar( mvar_t *v, mvar_t *f )
{
- v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
+ v->field = xrealloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
v->field[v->i_field] = f;
v->i_field++;
}
void mvar_PushVar( mvar_t *v, mvar_t *f )
{
- v->field = realloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
+ v->field = xrealloc( v->field, sizeof( mvar_t * ) * ( v->i_field + 2 ) );
if( v->i_field > 0 )
{
memmove( &v->field[1], &v->field[0], sizeof( mvar_t * ) * v->i_field );
return NULL;
}
-char *mvar_GetValue( mvar_t *v, char *field )
+const char *mvar_GetValue( mvar_t *v, const char *field )
{
if( *field == '\0' )
{
playlist_t *p_pl )
{
mvar_t *s = mvar_New( name, "set" );
- vlc_object_lock( p_pl );
+ playlist_Lock( p_pl );
PlaylistListNode( p_intf, p_pl, p_pl->p_root_category , name, s, 0 );
- vlc_object_unlock( p_pl );
+ playlist_Unlock( p_pl );
return s;
}
return s;
}
-mvar_t *mvar_ObjectSetNew( intf_thread_t *p_intf, char *psz_name,
- const char *psz_capability )
+mvar_t *mvar_ServicesSetNew( intf_thread_t *p_intf, char *psz_name )
{
mvar_t *s = mvar_New( psz_name, "set" );
- int i;
+ char **longnames;
+ char **names = vlc_sd_GetNames( p_intf, &longnames, NULL );
+ if( names == NULL )
+ goto out;
- vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
- FIND_ANYWHERE );
-
- for( i = 0; i < p_list->i_count; i++ )
+ for( size_t i = 0; names[i]; i++ )
{
- module_t *p_parser = (module_t *)p_list->p_values[i].p_object;
- if( module_IsCapable( p_parser, psz_capability ) )
- {
- mvar_t *sd = mvar_New( "sd", module_GetObjName( p_parser ) );
- mvar_AppendNewVar( sd, "name",
- module_GetName( p_parser, true ) );
- mvar_AppendVar( s, sd );
- }
+ mvar_t *sd = mvar_New( "sd", names[i] );
+ mvar_AppendNewVar( sd, "name", longnames[i] );
+ mvar_AppendVar( s, sd );
+ free( names[i] );
+ free( longnames[i] );
}
- vlc_list_release( p_list );
-
+ free( longnames );
+ free( names );
+out:
return s;
}
for( i = 0; i < val_list.p_list->i_count; i++ )
{
- char *psz, psz_int[16];
+ char psz_int[21];
mvar_t *itm;
switch( i_type & VLC_VAR_TYPE )
{
case VLC_VAR_STRING:
itm = mvar_New( name, "set" );
- /* FIXME: Memory leak here?? (remove strdup?) */
- psz = strdup( text_list.p_list->p_values[i].psz_string );
- mvar_AppendNewVar( itm, "name", psz );
+ mvar_AppendNewVar( itm, "name", text_list.p_list->p_values[i].psz_string );
mvar_AppendNewVar( itm, "id", val_list.p_list->p_values[i].psz_string );
snprintf( psz_int, sizeof(psz_int), "%d",
( !strcmp( val.psz_string,
case VLC_VAR_INTEGER:
itm = mvar_New( name, "set" );
- psz = strdup( text_list.p_list->p_values[i].psz_string );
- mvar_AppendNewVar( itm, "name", psz );
- snprintf( psz_int, sizeof(psz_int), "%d",
+ mvar_AppendNewVar( itm, "name", text_list.p_list->p_values[i].psz_string );
+ snprintf( psz_int, sizeof(psz_int), "%"PRId64,
val_list.p_list->p_values[i].i_int );
mvar_AppendNewVar( itm, "id", psz_int );
snprintf( psz_int, sizeof(psz_int), "%d",
}
/* 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 );
+ var_FreeList( &val_list, &text_list );
return s;
}
mvar_t *s = mvar_New( name, "set" );
char **ppsz_dir_content;
int i_dir_content, i;
- psz_dir = RealPath( p_intf, psz_dir );
-
-#if defined( WIN32 )
- if( psz_dir[0] != '\0' && (psz_dir[0] != '\\' || psz_dir[1] != '\0') )
- {
- free( psz_dir );
- return s;
- }
-#endif
+ psz_dir = RealPath( psz_dir );
/* parse psz_src dir */
- if( ( i_dir_content = utf8_scandir( psz_dir, &ppsz_dir_content, Filter,
+ if( ( i_dir_content = vlc_scandir( psz_dir, &ppsz_dir_content, Filter,
InsensitiveAlphasort ) ) == -1 )
{
if( errno != ENOENT && errno != ENOTDIR )
sprintf( psz_tmp, "%s"DIR_SEP"%s", psz_dir, psz_name );
#ifdef HAVE_SYS_STAT_H
- if( utf8_stat( psz_tmp, &stat_info ) == -1 )
+ if( vlc_stat( psz_tmp, &stat_info ) == -1 )
{
free( psz_name );
continue;
else
#endif
{
- char psz_ctime[26];
+ char psz_buf[26];
char psz_tmp[strlen( psz_dir ) + 1 + strlen( psz_name ) + 1];
sprintf( psz_tmp, "%s"DIR_SEP"%s", psz_dir, psz_name );
mvar_AppendNewVar( f, "type", "unknown" );
}
- sprintf( psz_ctime, "%"PRId64, (int64_t)stat_info.st_size );
- mvar_AppendNewVar( f, "size", psz_ctime );
+ snprintf( psz_buf, sizeof( psz_buf ), "%"PRId64,
+ (int64_t)stat_info.st_size );
+ mvar_AppendNewVar( f, "size", psz_buf );
/* FIXME memory leak FIXME */
# ifdef HAVE_CTIME_R
- ctime_r( &stat_info.st_mtime, psz_ctime );
- mvar_AppendNewVar( f, "date", psz_ctime );
+ ctime_r( &stat_info.st_mtime, psz_buf );
+ mvar_AppendNewVar( f, "date", psz_buf );
# else
mvar_AppendNewVar( f, "date", ctime( &stat_info.st_mtime ) );
# endif