X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fupdate.c;h=e13a66e43b954944fe5e3fc42991dffb384407e3;hb=e7bcc6803fe92f02df716b748ba0d766366e7352;hp=83e370497a64746018fc16e30ae1262ae48dacdc;hpb=638acbf817f1ad242d12808a28d9b437d4d04cb7;p=vlc diff --git a/src/misc/update.c b/src/misc/update.c index 83e370497a..e13a66e43b 100644 --- a/src/misc/update.c +++ b/src/misc/update.c @@ -34,10 +34,13 @@ /***************************************************************************** * Preamble *****************************************************************************/ + +#include + +#include #include /* malloc(), free() */ #include /* tolower() */ -#include #include "vlc_update.h" @@ -45,6 +48,7 @@ #include "vlc_stream.h" #include "vlc_xml.h" #include "vlc_interaction.h" +#include "charset.h" /***************************************************************************** * Misc defines @@ -77,7 +81,6 @@ #define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status.xml" #define UPDATE_VLC_MIRRORS_URL "http://update.videolan.org/mirrors.xml" -#define FREE( a ) free(a);a=NULL; #define STRDUP( a ) ( a ? strdup( a ) : NULL ) /***************************************************************************** @@ -121,7 +124,7 @@ update_t *__update_New( vlc_object_t *p_this ) vlc_mutex_init( p_this, &p_update->lock ); - p_update->p_vlc = p_this->p_vlc; + p_update->p_libvlc = p_this->p_libvlc; p_update->p_releases = NULL; p_update->i_releases = 0; @@ -166,7 +169,7 @@ void FreeMirrorsList( update_t *p_update ) free( p_update->p_mirrors[i].psz_type ); free( p_update->p_mirrors[i].psz_base_url ); } - FREE( p_update->p_mirrors ); + FREENULL( p_update->p_mirrors ); p_update->i_mirrors = 0; p_update->b_mirrors = VLC_FALSE; } @@ -199,7 +202,7 @@ void FreeReleasesList( update_t *p_update ) free( p_release->psz_svn_revision ); free( p_release->p_files ); } - FREE( p_update->p_releases ); + FREENULL( p_update->p_releases ); p_update->i_releases = 0; p_update->b_releases = VLC_FALSE; } @@ -218,33 +221,33 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force ) xml_t *p_xml = NULL; xml_reader_t *p_xml_reader = NULL; - char *psz_eltname = NULL; //char *psz_eltvalue = NULL; char *psz_name = NULL; char *psz_value = NULL; - - struct update_mirror_t tmp_mirror = {0}; + struct update_mirror_t tmp_mirror; vlc_mutex_lock( &p_update->lock ); + memset( &tmp_mirror, 0, sizeof(struct update_mirror_t)); + if( p_update->b_mirrors && b_force == VLC_FALSE ) { vlc_mutex_unlock( &p_update->lock ); return; } - p_xml = xml_Create( p_update->p_vlc ); + p_xml = xml_Create( p_update->p_libvlc ); if( !p_xml ) { - msg_Err( p_update->p_vlc, "Failed to open XML parser" ); + msg_Err( p_update->p_libvlc, "Failed to open XML parser" ); goto error; } - p_stream = stream_UrlNew( p_update->p_vlc, UPDATE_VLC_MIRRORS_URL ); + p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_MIRRORS_URL ); if( !p_stream ) { - msg_Err( p_update->p_vlc, "Failed to open %s for reading", + msg_Err( p_update->p_libvlc, "Failed to open %s for reading", UPDATE_VLC_MIRRORS_URL ); goto error; } @@ -253,7 +256,7 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force ) if( !p_xml_reader ) { - msg_Err( p_update->p_vlc, "Failed to open %s for parsing", + msg_Err( p_update->p_libvlc, "Failed to open %s for parsing", UPDATE_VLC_MIRRORS_URL ); goto error; } @@ -268,7 +271,7 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force ) switch( xml_ReaderNodeType( p_xml_reader ) ) { case -1: - msg_Err( p_update->p_vlc, "Error while parsing %s", + msg_Err( p_update->p_libvlc, "Error while parsing %s", UPDATE_VLC_MIRRORS_URL ); goto error; @@ -276,7 +279,7 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force ) psz_eltname = xml_ReaderName( p_xml_reader ); if( !psz_eltname ) { - msg_Err( p_update->p_vlc, "Error while parsing %s", + msg_Err( p_update->p_libvlc, "Error while parsing %s", UPDATE_VLC_MIRRORS_URL ); goto error; } @@ -288,7 +291,7 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force ) if( !psz_name || !psz_value ) { - msg_Err( p_update->p_vlc, "Error while parsing %s", + msg_Err( p_update->p_libvlc, "Error while parsing %s", UPDATE_VLC_MIRRORS_URL ); goto error; } @@ -307,8 +310,8 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force ) else if( !strcmp( psz_name, "base" ) ) tmp_mirror.psz_base_url = STRDUP( psz_value ); } - FREE( psz_name ); - FREE( psz_value ); + FREENULL( psz_name ); + FREENULL( psz_value ); } if( !strcmp( psz_eltname, "url" ) ) { @@ -324,30 +327,30 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force ) tmp_mirror.psz_type = NULL; tmp_mirror.psz_base_url = NULL; } - FREE( psz_eltname ); + FREENULL( psz_eltname ); break; case XML_READER_ENDELEM: psz_eltname = xml_ReaderName( p_xml_reader ); if( !psz_eltname ) { - msg_Err( p_update->p_vlc, "Error while parsing %s", + msg_Err( p_update->p_libvlc, "Error while parsing %s", UPDATE_VLC_MIRRORS_URL ); goto error; } if( !strcmp( psz_eltname, "mirror" ) ) { - FREE( tmp_mirror.psz_name ); - FREE( tmp_mirror.psz_location ); + FREENULL( tmp_mirror.psz_name ); + FREENULL( tmp_mirror.psz_location ); } - FREE( psz_eltname ); + FREENULL( psz_eltname ); break; /*case XML_READER_TEXT: psz_eltvalue = xml_ReaderValue( p_xml_reader ); - FREE( psz_eltvalue ); + FREENULL( psz_eltvalue ); break;*/ } } @@ -396,11 +399,14 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) char *psz_value = NULL; struct update_release_t *p_release = NULL; - struct update_release_t tmp_release = {0}; - struct update_file_t tmp_file = {0}; + struct update_release_t tmp_release; + struct update_file_t tmp_file; vlc_bool_t b_os = VLC_FALSE, b_arch = VLC_FALSE; + memset( &tmp_release, 0, sizeof(struct update_release_t) ); + memset( &tmp_file, 0, sizeof(struct update_file_t) ); + tmp_release.i_type = UPDATE_RELEASE_TYPE_STABLE; vlc_mutex_lock( &p_update->lock ); @@ -411,17 +417,17 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) return; } - p_xml = xml_Create( p_update->p_vlc ); + p_xml = xml_Create( p_update->p_libvlc ); if( !p_xml ) { - msg_Err( p_update->p_vlc, "Failed to open XML parser" ); + msg_Err( p_update->p_libvlc, "Failed to open XML parser" ); goto error; } - p_stream = stream_UrlNew( p_update->p_vlc, UPDATE_VLC_STATUS_URL ); + p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL ); if( !p_stream ) { - msg_Err( p_update->p_vlc, "Failed to open %s for reading", + msg_Err( p_update->p_libvlc, "Failed to open %s for reading", UPDATE_VLC_STATUS_URL ); goto error; } @@ -430,7 +436,7 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) if( !p_xml_reader ) { - msg_Err( p_update->p_vlc, "Failed to open %s for parsing", + msg_Err( p_update->p_libvlc, "Failed to open %s for parsing", UPDATE_VLC_STATUS_URL ); goto error; } @@ -445,7 +451,7 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) switch( xml_ReaderNodeType( p_xml_reader ) ) { case -1: - msg_Err( p_update->p_vlc, "Error while parsing %s", + msg_Err( p_update->p_libvlc, "Error while parsing %s", UPDATE_VLC_STATUS_URL ); goto error; @@ -453,7 +459,7 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) psz_eltname = xml_ReaderName( p_xml_reader ); if( !psz_eltname ) { - msg_Err( p_update->p_vlc, "Error while parsing %s", + msg_Err( p_update->p_libvlc, "Error while parsing %s", UPDATE_VLC_STATUS_URL ); goto error; } @@ -465,7 +471,7 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) if( !psz_name || !psz_value ) { - msg_Err( p_update->p_vlc, "Error while parsing %s", + msg_Err( p_update->p_libvlc, "Error while parsing %s", UPDATE_VLC_STATUS_URL ); goto error; } @@ -535,15 +541,15 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) { b_arch = VLC_TRUE; } - FREE( psz_name ); - FREE( psz_value ); + FREENULL( psz_name ); + FREENULL( psz_value ); } if( ( b_os && b_arch && strcmp( psz_eltname, "arch" ) ) ) { if( !strcmp( psz_eltname, "version" ) ) { int i; - /* look for a previous occurence of this release */ + /* look for a previous occurrence of this release */ for( i = 0; i < p_update->i_releases; i++ ) { p_release = p_update->p_releases + i; @@ -578,13 +584,13 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) } else { - FREE( tmp_release.psz_major ); - FREE( tmp_release.psz_minor ); - FREE( tmp_release.psz_revision ); - FREE( tmp_release.psz_extra ); - FREE( tmp_release.psz_svn_revision ); + FREENULL( tmp_release.psz_major ); + FREENULL( tmp_release.psz_minor ); + FREENULL( tmp_release.psz_revision ); + FREENULL( tmp_release.psz_extra ); + FREENULL( tmp_release.psz_svn_revision ); tmp_release.i_type = UPDATE_RELEASE_TYPE_STABLE; - FREE( tmp_release.p_files ); + FREENULL( tmp_release.p_files ); tmp_release.i_files = 0; } } @@ -606,14 +612,14 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) tmp_file.psz_description = NULL; } } - FREE( psz_eltname ); + FREENULL( psz_eltname ); break; case XML_READER_ENDELEM: psz_eltname = xml_ReaderName( p_xml_reader ); if( !psz_eltname ) { - msg_Err( p_update->p_vlc, "Error while parsing %s", + msg_Err( p_update->p_libvlc, "Error while parsing %s", UPDATE_VLC_STATUS_URL ); goto error; } @@ -622,7 +628,7 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) b_os = VLC_FALSE; else if( !strcmp( psz_eltname, "arch" ) ) b_arch = VLC_FALSE; - FREE( psz_eltname ); + FREENULL( psz_eltname ); break; case XML_READER_TEXT: @@ -630,7 +636,7 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force ) if( p_release && p_release->i_files ) p_release->p_files[ p_release->i_files - 1 ] .psz_description = STRDUP( psz_eltvalue ); - FREE( psz_eltvalue ); + FREENULL( psz_eltvalue ); break; } } @@ -727,8 +733,10 @@ int CompareReleases( struct update_release_t *p1, struct update_release_t *p2 ) */ int CompareReleaseToCurrent( struct update_release_t *p ) { - struct update_release_t c = {0}; + struct update_release_t c; int r; + + memset( &c, 0, sizeof(struct update_release_t) ); c.psz_major = STRDUP( PACKAGE_VERSION_MAJOR ); c.psz_minor = STRDUP( PACKAGE_VERSION_MINOR ); c.psz_revision = STRDUP( PACKAGE_VERSION_REVISION ); @@ -1114,17 +1122,17 @@ void update_iterator_GetData( update_iterator_t *p_uit ) void update_iterator_ClearData( update_iterator_t *p_uit ) { p_uit->file.i_type = UPDATE_FILE_TYPE_NONE; - FREE( p_uit->file.psz_md5 ); + FREENULL( p_uit->file.psz_md5 ); p_uit->file.l_size = 0; - FREE( p_uit->file.psz_description ); - FREE( p_uit->file.psz_url ); - FREE( p_uit->release.psz_version ); - FREE( p_uit->release.psz_svn_revision ); + FREENULL( p_uit->file.psz_description ); + FREENULL( p_uit->file.psz_url ); + FREENULL( p_uit->release.psz_version ); + FREENULL( p_uit->release.psz_svn_revision ); p_uit->release.i_type = UPDATE_RELEASE_TYPE_UNSTABLE; p_uit->release.i_status = UPDATE_RELEASE_STATUS_NONE; - FREE( p_uit->mirror.psz_name ); - FREE( p_uit->mirror.psz_location ); - FREE( p_uit->mirror.psz_type ); + FREENULL( p_uit->mirror.psz_name ); + FREENULL( p_uit->mirror.psz_location ); + FREENULL( p_uit->mirror.psz_type ); } /** @@ -1204,7 +1212,7 @@ void update_download_for_real( download_thread_t *p_this ); void update_download( update_iterator_t *p_uit, char *psz_dest ) { download_thread_t *p_dt = - vlc_object_create( p_uit->p_u->p_vlc, sizeof( download_thread_t ) ); + vlc_object_create( p_uit->p_u->p_libvlc, sizeof( download_thread_t ) ); p_dt->psz_dest = strdup( psz_dest ); p_dt->psz_src = strdup( p_uit->file.psz_url ); @@ -1248,7 +1256,7 @@ void update_download_for_real( download_thread_t *p_this ) char *psz_dest = p_this->psz_dest; char *psz_src = p_this->psz_src; stream_t *p_stream; - vlc_t *p_vlc = p_this->p_vlc; + libvlc_int_t *p_libvlc = p_this->p_libvlc; FILE *p_file = NULL; void *p_buffer; @@ -1262,27 +1270,27 @@ void update_download_for_real( download_thread_t *p_this ) asprintf( &psz_status, "%s\nDownloading... 0.0/? %.1f%% done", p_this->psz_status, 0.0 ); - i_progress = intf_UserProgress( p_vlc, "Downloading...", - psz_status, 0.0 ); + i_progress = intf_UserProgress( p_libvlc, "Downloading...", + psz_status, 0.0, 0 ); - p_stream = stream_UrlNew( p_vlc, psz_src ); + p_stream = stream_UrlNew( p_libvlc, psz_src ); if( !p_stream ) { - msg_Err( p_vlc, "Failed to open %s for reading", psz_src ); - intf_UserFatal( p_vlc, "Downloading...", - "Failed to open %s for reading", psz_src ); - intf_UserHide( p_vlc, i_progress ); + msg_Err( p_libvlc, "Failed to open %s for reading", psz_src ); + intf_UserFatal( p_libvlc, VLC_TRUE, "Error while Downloading...", + "VLC failed to open %s for reading.", psz_src ); + intf_UserHide( p_libvlc, i_progress ); } else { - p_file = fopen( psz_dest, "w" ); + p_file = utf8_fopen( psz_dest, "w" ); if( !p_file ) { - msg_Err( p_vlc, "Failed to open %s for writing", psz_dest ); - intf_UserFatal( p_vlc, "Downloading...", - "Failed to open %s for writing", psz_dest ); - intf_UserHide( p_vlc, i_progress ); + msg_Err( p_libvlc, "Failed to open %s for writing", psz_dest ); + intf_UserFatal( p_libvlc, VLC_TRUE, "Error while Downloading...", + "VLC failed to open %s for writing.", psz_dest ); + intf_UserHide( p_libvlc, i_progress ); } else { @@ -1307,8 +1315,8 @@ void update_download_for_real( download_thread_t *p_this ) p_this->psz_status, psz_s1, psz_s2, f_progress ); free( psz_s1 ); free( psz_s2 ); - intf_UserProgressUpdate( p_vlc, i_progress, - psz_status, f_progress ); + intf_ProgressUpdate( p_libvlc, i_progress, + psz_status, f_progress, 0 ); } free( p_buffer ); @@ -1320,7 +1328,7 @@ void update_download_for_real( download_thread_t *p_this ) asprintf( &psz_status, "%s\nDone %s (100.00%%)", p_this->psz_status, psz_s2 ); free( psz_s2 ); - intf_UserProgressUpdate( p_vlc, i_progress, psz_status, 100.0 ); + intf_ProgressUpdate( p_libvlc, i_progress, psz_status, 100.0, 0 ); free( psz_status ); } }