X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Fhttp%2Futil.c;h=7134321be87ac7ae805ed75d2c520d076aa7ac0a;hb=6688fd832c086d98a59764b65178a6c1be94c2c8;hp=69de4a65aaca76bdd93c52eccb70bc9f376e534a;hpb=0036da65250f7f6b785da2be9f68af0bb9275600;p=vlc diff --git a/modules/control/http/util.c b/modules/control/http/util.c index 69de4a65aa..7134321be8 100644 --- a/modules/control/http/util.c +++ b/modules/control/http/util.c @@ -29,7 +29,10 @@ #include #include "http.h" -#include "vlc_strings.h" +#include +#include +#include +#include /**************************************************************************** * File and directory functions @@ -90,11 +93,12 @@ int FileLoad( FILE *f, char **pp_data, int *pi_data ) /* just load the file */ *pi_data = 0; - *pp_data = malloc( 1025 ); /* +1 for \0 */ + *pp_data = xmalloc( 1025 ); /* +1 for \0 */ + while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 ) { *pi_data += 1024; - *pp_data = realloc( *pp_data, *pi_data + 1025 ); + *pp_data = xrealloc( *pp_data, *pi_data + 1025 ); } if( i_read > 0 ) { @@ -165,8 +169,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root, password = strdup( p ); } } - msg_Dbg( p_intf, "using user=%s password=%s (read=%d)", - user, password, i_size ); + msg_Dbg( p_intf, "using user=%s (read=%d)", user, i_size ); fclose( file ); } @@ -178,8 +181,10 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root, ACL_Destroy( p_acl ); struct stat st; - if( stat( dir, &st ) == 0 ) + if( utf8_stat( dir, &st ) == 0 ) { + free( user ); + free( password ); closedir( p_dir ); return VLC_EGENERIC; } @@ -231,7 +236,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root, } if( f == NULL ) { - f = malloc( sizeof( httpd_file_sys_t ) ); + f = xmalloc( sizeof( httpd_file_sys_t ) ); f->b_handler = false; } @@ -349,7 +354,7 @@ void PlaylistListNode( intf_thread_t *p_intf, playlist_t *p_pl, return; mvar_t *itm = mvar_New( name, "set" ); - if( p_item->p_input->i_id == p_node->p_input->i_id ) + if( p_item->p_input == p_node->p_input ) mvar_AppendNewVar( itm, "current", "1" ); else mvar_AppendNewVar( itm, "current", "0" ); @@ -365,8 +370,7 @@ void PlaylistListNode( intf_thread_t *p_intf, playlist_t *p_pl, mvar_AppendNewVar( itm, "uri", psz ); free( psz ); - sprintf( value, "Item"); - mvar_AppendNewVar( itm, "type", value ); + mvar_AppendNewVar( itm, "type", "Item" ); sprintf( value, "%d", i_depth ); mvar_AppendNewVar( itm, "depth", value ); @@ -383,51 +387,67 @@ void PlaylistListNode( intf_thread_t *p_intf, playlist_t *p_pl, psz = input_item_GetTitle( p_node->p_input ); mvar_AppendNewVar( itm, "title", psz ); + free( psz ); psz = input_item_GetArtist( p_node->p_input ); mvar_AppendNewVar( itm, "artist", psz ); + free( psz ); psz = input_item_GetGenre( p_node->p_input ); mvar_AppendNewVar( itm, "genre", psz ); + free( psz ); psz = input_item_GetCopyright( p_node->p_input ); mvar_AppendNewVar( itm, "copyright", psz ); + free( psz ); psz = input_item_GetAlbum( p_node->p_input ); mvar_AppendNewVar( itm, "album", psz ); + free( psz ); psz = input_item_GetTrackNum( p_node->p_input ); mvar_AppendNewVar( itm, "track", psz ); + free( psz ); psz = input_item_GetDescription( p_node->p_input ); mvar_AppendNewVar( itm, "description", psz ); + free( psz ); psz = input_item_GetRating( p_node->p_input ); mvar_AppendNewVar( itm, "rating", psz ); + free( psz ); psz = input_item_GetDate( p_node->p_input ); mvar_AppendNewVar( itm, "date", psz ); + free( psz ); psz = input_item_GetURL( p_node->p_input ); mvar_AppendNewVar( itm, "url", psz ); + free( psz ); psz = input_item_GetLanguage( p_node->p_input ); mvar_AppendNewVar( itm, "language", psz ); + free( psz ); psz = input_item_GetNowPlaying( p_node->p_input ); mvar_AppendNewVar( itm, "now_playing", psz ); + free( psz ); psz = input_item_GetPublisher( p_node->p_input ); mvar_AppendNewVar( itm, "publisher", psz ); + free( psz ); psz = input_item_GetEncodedBy( p_node->p_input ); mvar_AppendNewVar( itm, "encoded_by", psz ); + free( psz ); psz = input_item_GetArtURL( p_node->p_input ); mvar_AppendNewVar( itm, "art_url", psz ); + free( psz ); psz = input_item_GetTrackID( p_node->p_input ); mvar_AppendNewVar( itm, "track_id", psz ); + free( psz ); mvar_AppendVar( s, itm ); } @@ -440,8 +460,7 @@ void PlaylistListNode( intf_thread_t *p_intf, playlist_t *p_pl, mvar_AppendNewVar( itm, "name", p_node->p_input->psz_name ); mvar_AppendNewVar( itm, "uri", p_node->p_input->psz_name ); - sprintf( value, "Node" ); - mvar_AppendNewVar( itm, "type", value ); + mvar_AppendNewVar( itm, "type", "Node" ); sprintf( value, "%d", p_node->i_id ); mvar_AppendNewVar( itm, "index", value ); @@ -905,7 +924,7 @@ char *RealPath( const char *psz_src ) char *p; int i_len = strlen(psz_src); - psz_dir = malloc( i_len + 2 ); + psz_dir = xmalloc( i_len + 2 ); strcpy( psz_dir, psz_src ); /* Add a trailing sep to ease the .. step */ @@ -936,10 +955,13 @@ char *RealPath( const char *psz_src ) if( psz_dir[0] == '~' ) { - char *dir; - asprintf( &dir, "%s%s", config_GetHomeDir(), psz_dir + 1 ); - free( psz_dir ); - psz_dir = dir; + char *home = config_GetUserDir( VLC_HOME_DIR ), *dir; + if( asprintf( &dir, "%s%s", home, psz_dir + 1 ) != -1 ) + { + free( psz_dir ); + psz_dir = dir; + } + free( home ); } if( strlen(psz_dir) > 2 )