# include "config.h"
#endif
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_update.h>
#ifdef UPDATE_CHECK
#include <assert.h>
-#include <vlc_update.h>
#include <vlc_pgpkey.h>
#include <vlc_stream.h>
#include <vlc_strings.h>
#include <gcrypt.h>
#include <vlc_gcrypt.h>
+#include "update.h"
+#include "../libvlc.h"
/*****************************************************************************
* Misc defines
* * e is an OPTIONAL extra letter
* * AKA "0.8.6d" or "0.9.0"
* Second line is an url of the binary for this last version
- * Third line is a description of the update (it MAY be extended to several lines, but for now it is only one line)
+ * Remaining text is a required description of the update
*/
#if defined( UNDER_CE )
p_update->release.psz_url = NULL;
p_update->release.psz_desc = NULL;
+ p_update->p_download = NULL;
+ p_update->p_check = NULL;
+
p_update->p_pkey = NULL;
vlc_gcrypt_init();
{
assert( p_update );
+ if( p_update->p_check )
+ {
+ assert( !p_update->p_download );
+ vlc_object_kill( p_update->p_check );
+ vlc_thread_join( p_update->p_check );
+ }
+ else if( p_update->p_download )
+ {
+ vlc_object_kill( p_update->p_download );
+ vlc_thread_join( p_update->p_download );
+ }
+
vlc_mutex_destroy( &p_update->lock );
free( p_update->release.psz_url );
int i_minor = 0;
int i_revision = 0;
unsigned char extra;
- char *psz_line = NULL;
char *psz_version_line = NULL;
p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL );
goto error;
}
- /* Try to read three lines */
- if( !( psz_line = stream_ReadLine( p_stream ) ) )
+ /* Start reading the status file */
+ if( !( psz_version_line = stream_ReadLine( p_stream ) ) )
{
msg_Err( p_update->p_libvlc, "Update file %s is corrupted : missing version",
UPDATE_VLC_STATUS_URL );
goto error;
}
- psz_version_line = psz_line;
/* first line : version number */
p_update->release.extra = 0;
- switch( sscanf( psz_line, "%i.%i.%i%c", &i_major, &i_minor, &i_revision, &extra ) )
+ switch( sscanf( psz_version_line, "%i.%i.%i%c",
+ &i_major, &i_minor, &i_revision, &extra ) )
{
case 4:
p_update->release.extra = extra;
goto error;
}
- /* Second line : URL */
- if( !( psz_line = stream_ReadLine( p_stream ) ) )
+ /* second line : URL */
+ if( !( p_update->release.psz_url = stream_ReadLine( p_stream ) ) )
{
msg_Err( p_update->p_libvlc, "Update file %s is corrupted : URL missing",
UPDATE_VLC_STATUS_URL );
goto error;
}
- p_update->release.psz_url = psz_line;
+ /* Remaining data : description */
+ int i_read = stream_Size( p_stream ) - stream_Tell( p_stream );
+ if( i_read <= 0 )
+ {
+ msg_Err( p_update->p_libvlc,
+ "Update file %s is corrupted: description missing",
+ UPDATE_VLC_STATUS_URL );
+ goto error;
+ }
+
+ p_update->release.psz_desc = (char*) malloc( i_read + 1 );
+ if( !p_update->release.psz_desc )
+ goto error;
- /* Third line : description */
- if( !( psz_line = stream_ReadLine( p_stream ) ) )
+ if( stream_Read( p_stream, p_update->release.psz_desc, i_read ) != i_read )
{
- msg_Err( p_update->p_libvlc, "Update file %s is corrupted : description missing",
- UPDATE_VLC_STATUS_URL );
+ msg_Err( p_update->p_libvlc, "Couldn't download update file %s",
+ UPDATE_VLC_STATUS_URL );
goto error;
}
- p_update->release.psz_desc = psz_line;
+ p_update->release.psz_desc[i_read] = '\0';
stream_Delete( p_stream );
p_stream = NULL;
if( sign.type == TEXT_SIGNATURE )
gcry_md_putc( hd, '\r' );
gcry_md_putc( hd, '\n' );
- gcry_md_write( hd, p_update->release.psz_desc,
- strlen( p_update->release.psz_desc ) );
- if( sign.type == TEXT_SIGNATURE )
- gcry_md_putc( hd, '\r' );
- gcry_md_putc( hd, '\n' );
+ char *psz_desc = p_update->release.psz_desc;
+ while( *psz_desc )
+ {
+ size_t i_len = strcspn( psz_desc, "\r\n" );
+ if( !i_len )
+ break;
+
+ gcry_md_write( hd, psz_desc, i_len );
+ if( sign.type == TEXT_SIGNATURE )
+ gcry_md_putc( hd, '\r' );
+ gcry_md_putc( hd, '\n' );
+
+ psz_desc += i_len;
+ while( *psz_desc == '\r' || *psz_desc == '\n' )
+ psz_desc++;
+ }
if( sign.version == 3 )
{
return false;
}
-
-/**
- * Struct to launch the check in an other thread
- */
-typedef struct
-{
- VLC_COMMON_MEMBERS
- update_t *p_update;
- void (*pf_callback)( void *, bool );
- void *p_data;
-} update_check_thread_t;
-
-void update_CheckReal( update_check_thread_t *p_uct );
+static void update_CheckReal( update_check_thread_t *p_uct );
/**
* Check for updates
{
assert( p_update );
- update_check_thread_t *p_uct = vlc_object_create( p_update->p_libvlc,
- sizeof( update_check_thread_t ) );
+ update_check_thread_t *p_uct =
+ vlc_custom_create( p_update->p_libvlc, sizeof( *p_uct ),
+ VLC_OBJECT_GENERIC, "update check" );
if( !p_uct ) return;
p_uct->p_update = p_update;
+ p_update->p_check = p_uct;
p_uct->pf_callback = pf_callback;
p_uct->p_data = p_data;
if( p_uct->pf_callback )
(p_uct->pf_callback)( p_uct->p_data, b_ret );
+ p_uct->p_update->p_check = NULL;
+
vlc_object_release( p_uct );
}
return i_retval == -1 ? NULL : psz_tmp;
}
-
-/**
- * Struct to launch the download in a thread
- */
-typedef struct
-{
- VLC_COMMON_MEMBERS
- update_t *p_update;
- char *psz_destdir;
-} update_download_thread_t;
-
-void update_DownloadReal( update_download_thread_t *p_udt );
+static void update_DownloadReal( update_download_thread_t *p_udt );
/**
* Download the file given in the update_t
* \param dir to store the download file
* \return nothing
*/
-void update_Download( update_t *p_update, char *psz_destdir )
+void update_Download( update_t *p_update, const char *psz_destdir )
{
assert( p_update );
- update_download_thread_t *p_udt = vlc_object_create( p_update->p_libvlc,
- sizeof( update_download_thread_t ) );
+ update_download_thread_t *p_udt =
+ vlc_custom_create( p_update->p_libvlc, sizeof( *p_udt ),
+ VLC_OBJECT_GENERIC, "update download" );
if( !p_udt )
- {
- msg_Err( p_update->p_libvlc, "out of memory" );
return;
- }
p_udt->p_update = p_update;
+ p_update->p_download = p_udt;
p_udt->psz_destdir = psz_destdir ? strdup( psz_destdir ) : NULL;
vlc_thread_create( p_udt, "download update", update_DownloadReal,
VLC_THREAD_PRIORITY_LOW, false );
}
-void update_DownloadReal( update_download_thread_t *p_udt )
+static void update_DownloadReal( update_download_thread_t *p_udt )
{
int i_progress = 0;
long int l_size;
free( psz_status );
}
- while( ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
- !intf_ProgressIsCancelled( p_udt, i_progress ) )
+ vlc_object_lock( p_udt );
+ while( vlc_object_alive( p_udt ) &&
+ ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
+ !intf_ProgressIsCancelled( p_udt, i_progress ) )
{
+ vlc_object_unlock( p_udt );
if( fwrite( p_buffer, i_read, 1, p_file ) < 1 )
{
msg_Err( p_udt, "Failed to write into %s", psz_destfile );
free( psz_status );
}
free( psz_downloaded );
+ vlc_object_lock( p_udt );
}
/* Finish the progress bar or delete the file if the user had canceled */
fclose( p_file );
p_file = NULL;
- if( !intf_ProgressIsCancelled( p_udt, i_progress ) )
+ if( vlc_object_alive( p_udt ) &&
+ !intf_ProgressIsCancelled( p_udt, i_progress ) )
{
+ vlc_object_unlock( p_udt );
if( asprintf( &psz_status, "%s\nDone %s (100.0%%)",
p_update->release.psz_url, psz_size ) != -1 )
{
}
else
{
+ vlc_object_unlock( p_udt );
utf8_unlink( psz_destfile );
goto end;
}
{
utf8_unlink( psz_destfile );
- intf_UserFatal( p_udt, true, _("File can not be verified"),
+ intf_UserFatal( p_udt, true, _("File could not be verified"),
_("It was not possible to download a cryptographic signature for "
- "downloaded file \"%s\", and so VLC deleted it."),
+ "the downloaded file \"%s\". Thus, it was deleted."),
psz_destfile );
msg_Err( p_udt, "Couldn't download signature of downloaded file" );
goto end;
utf8_unlink( psz_destfile );
msg_Err( p_udt, "Invalid signature issuer" );
intf_UserFatal( p_udt, true, _("Invalid signature"),
- _("The cryptographic signature for downloaded file \"%s\" was "
- "invalid and couldn't be used to securely verify it, and so "
- "VLC deleted it."),
+ _("The cryptographic signature for the downloaded file \"%s\" was "
+ "invalid and could not be used to securely verify it. Thus, the "
+ "file was deleted."),
psz_destfile );
goto end;
}
utf8_unlink( psz_destfile );
msg_Err( p_udt, "Invalid signature type" );
intf_UserFatal( p_udt, true, _("Invalid signature"),
- _("The cryptographic signature for downloaded file \"%s\" was "
- "invalid and couldn't be used to securely verify it, and so "
- "VLC deleted it."),
+ _("The cryptographic signature for the downloaded file \"%s\" was "
+ "invalid and could not be used to securely verify it. Thus, the "
+ "file was deleted."),
psz_destfile );
goto end;
}
msg_Err( p_udt, "Unable to hash %s", psz_destfile );
utf8_unlink( psz_destfile );
intf_UserFatal( p_udt, true, _("File not verifiable"),
- _("It was not possible to securely verify downloaded file \"%s\", "
- "and so VLC deleted it."),
+ _("It was not possible to securely verify the downloaded file"
+ " \"%s\". Thus, it was VLC deleted."),
psz_destfile );
goto end;
{
utf8_unlink( psz_destfile );
intf_UserFatal( p_udt, true, _("File corrupted"),
- _("Downloaded file \"%s\" was corrupted, and so VLC deleted it."),
+ _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
psz_destfile );
msg_Err( p_udt, "Bad SHA1 hash for %s", psz_destfile );
free( p_hash );
{
utf8_unlink( psz_destfile );
intf_UserFatal( p_udt, true, _("File corrupted"),
- _("Downloaded file \"%s\" was corrupted, and so VLC deleted it."),
+ _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
psz_destfile );
msg_Err( p_udt, "BAD SIGNATURE for %s", psz_destfile );
free( p_hash );
free( p_buffer );
free( psz_size );
+ p_udt->p_update->p_download = NULL;
+
vlc_object_release( p_udt );
}
+update_release_t *update_GetRelease( update_t *p_update )
+{
+ return &p_update->release;
+}
+
+#else
+update_t *__update_New( vlc_object_t *p_this )
+{
+ (void)p_this;
+ return NULL;
+}
+
+void update_Delete( update_t *p_update )
+{
+ (void)p_update;
+}
+
+void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ),
+ void *p_data )
+{
+ (void)p_update; (void)pf_callback; (void)p_data;
+}
+
+bool update_NeedUpgrade( update_t *p_update )
+{
+ (void)p_update;
+ return false;
+}
+
+void update_Download( update_t *p_update, const char *psz_destdir )
+{
+ (void)p_update; (void)psz_destdir;
+}
+
+update_release_t *update_GetRelease( update_t *p_update )
+{
+ (void)p_update;
+ return NULL;
+}
#endif