]> git.sesse.net Git - vlc/blob - src/misc/update.c
Update: correctly handle different line endings
[vlc] / src / misc / update.c
1 /*****************************************************************************
2  * update.c: VLC update checking and downloading
3  *****************************************************************************
4  * Copyright © 2005-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
8  *          Rémi Duraffort <ivoire at via.ecp.fr>
9             Rafaël Carré <funman@videolanorg>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either release 2 of the License, or
14  * (at your option) any later release.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /**
27  *   \file
28  *   This file contains functions related to VLC update management
29  */
30
31 /*****************************************************************************
32  * Preamble
33  *****************************************************************************/
34
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <vlc_common.h>
40 #include <vlc_update.h>
41
42 #ifdef UPDATE_CHECK
43
44 #include <assert.h>
45
46 #include <vlc_pgpkey.h>
47 #include <vlc_stream.h>
48 #include <vlc_strings.h>
49 #include <vlc_charset.h>
50 #include <vlc_dialog.h>
51
52 #include <gcrypt.h>
53 #include <vlc_gcrypt.h>
54
55 #include "update.h"
56 #include "../libvlc.h"
57
58 /*****************************************************************************
59  * Misc defines
60  *****************************************************************************/
61
62 /*
63  * Here is the format of these "status files" :
64  * First line is the last version: "X.Y.Ze" where:
65  *      * X is the major number
66  *      * Y is the minor number
67  *      * Z is the revision number
68  *      * e is an OPTIONAL extra letter
69  *      * AKA "0.8.6d" or "0.9.0"
70  * Second line is an url of the binary for this last version
71  * Remaining text is a required description of the update
72  */
73
74 #if defined( UNDER_CE )
75 #   define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-ce"
76 #elif defined( WIN32 )
77 #   define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-win-x86"
78 #elif defined( __APPLE__ )
79 #   if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
80 #       define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-ppc"
81 #   else
82 #       define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-x86"
83 #   endif
84 #elif defined( SYS_BEOS )
85 #       define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-beos-x86"
86 #else
87 #   define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status"
88 #endif
89
90
91 /*****************************************************************************
92  * Update_t functions
93  *****************************************************************************/
94
95 /**
96  * Create a new update VLC struct
97  *
98  * \param p_this the calling vlc_object
99  * \return pointer to new update_t or NULL
100  */
101 update_t *__update_New( vlc_object_t *p_this )
102 {
103     update_t *p_update;
104     assert( p_this );
105
106     p_update = (update_t *)malloc( sizeof( update_t ) );
107     if( !p_update ) return NULL;
108
109     vlc_mutex_init( &p_update->lock );
110
111     p_update->p_libvlc = p_this->p_libvlc;
112
113     p_update->release.psz_url = NULL;
114     p_update->release.psz_desc = NULL;
115
116     p_update->p_download = NULL;
117     p_update->p_check = NULL;
118
119     p_update->p_pkey = NULL;
120     vlc_gcrypt_init();
121
122     return p_update;
123 }
124
125 /**
126  * Delete an update_t struct
127  *
128  * \param p_update update_t* pointer
129  * \return nothing
130  */
131 void update_Delete( update_t *p_update )
132 {
133     assert( p_update );
134
135     if( p_update->p_check )
136     {
137         vlc_object_kill( p_update->p_check );
138         vlc_thread_join( p_update->p_check );
139         vlc_object_release( p_update->p_check );
140     }
141
142     if( p_update->p_download )
143     {
144         vlc_object_kill( p_update->p_download );
145         vlc_thread_join( p_update->p_download );
146         vlc_object_release( p_update->p_download );
147     }
148
149     vlc_mutex_destroy( &p_update->lock );
150
151     free( p_update->release.psz_url );
152     free( p_update->release.psz_desc );
153     free( p_update->p_pkey );
154
155     free( p_update );
156 }
157
158 /**
159  * Empty the release struct
160  *
161  * \param p_update update_t* pointer
162  * \return nothing
163  */
164 static void EmptyRelease( update_t *p_update )
165 {
166     p_update->release.i_major = 0;
167     p_update->release.i_minor = 0;
168     p_update->release.i_revision = 0;
169
170     FREENULL( p_update->release.psz_url );
171     FREENULL( p_update->release.psz_desc );
172 }
173
174 /**
175  * Get the update file and parse it
176  * p_update has to be locked when calling this function
177  *
178  * \param p_update pointer to update struct
179  * \return true if the update is valid and authenticated
180  */
181 static bool GetUpdateFile( update_t *p_update )
182 {
183     stream_t *p_stream = NULL;
184     int i_major = 0;
185     int i_minor = 0;
186     int i_revision = 0;
187     unsigned char extra;
188     char *psz_version_line = NULL;
189     char *psz_update_data = NULL;
190
191     p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL );
192     if( !p_stream )
193     {
194         msg_Err( p_update->p_libvlc, "Failed to open %s for reading",
195                  UPDATE_VLC_STATUS_URL );
196         goto error;
197     }
198
199     const int64_t i_read = stream_Size( p_stream );
200     psz_update_data = malloc( i_read + 1 ); /* terminating '\0' */
201     if( !psz_update_data )
202         goto error;
203
204     if( stream_Read( p_stream, psz_update_data, i_read ) != i_read )
205     {
206         msg_Err( p_update->p_libvlc, "Couldn't download update file %s",
207                 UPDATE_VLC_STATUS_URL );
208         goto error;
209     }
210     psz_update_data[i_read] = '\0';
211
212     stream_Delete( p_stream );
213     p_stream = NULL;
214
215     /* first line : version number */
216     char *psz_update_data_parser = psz_update_data;
217     size_t i_len = strcspn( psz_update_data, "\r\n" );
218     psz_update_data_parser += i_len;
219     while( *psz_update_data_parser == '\r' || *psz_update_data_parser == '\n' )
220         psz_update_data_parser++;
221
222     if( !(psz_version_line = malloc( i_len + 1)) )
223         goto error;
224     strncpy( psz_version_line, psz_update_data, i_len );
225     psz_version_line[i_len] = '\0';
226
227     p_update->release.extra = 0;
228     switch( sscanf( psz_version_line, "%i.%i.%i%c",
229                     &i_major, &i_minor, &i_revision, &extra ) )
230     {
231         case 4:
232             p_update->release.extra = extra;
233         case 3:
234             p_update->release.i_major = i_major;
235             p_update->release.i_minor = i_minor;
236             p_update->release.i_revision = i_revision;
237             break;
238         default:
239             msg_Err( p_update->p_libvlc, "Update version false formated" );
240             goto error;
241     }
242
243     /* second line : URL */
244     i_len = strcspn( psz_update_data_parser, "\r\n" );
245     if( i_len == 0 )
246     {
247         msg_Err( p_update->p_libvlc, "Update file %s is corrupted: URL missing",
248                  UPDATE_VLC_STATUS_URL );
249
250         goto error;
251     }
252
253     if( !(p_update->release.psz_url = malloc( i_len + 1)) )
254         goto error;
255     strncpy( p_update->release.psz_url, psz_update_data_parser, i_len );
256     p_update->release.psz_url[i_len] = '\0';
257
258     psz_update_data_parser += i_len;
259     while( *psz_update_data_parser == '\r' || *psz_update_data_parser == '\n' )
260         psz_update_data_parser++;
261
262     /* Remaining data : description */
263     i_len = strlen( psz_update_data_parser );
264     if( i_len == 0 )
265     {
266         msg_Err( p_update->p_libvlc,
267                 "Update file %s is corrupted: description missing",
268                 UPDATE_VLC_STATUS_URL );
269         goto error;
270     }
271
272     if( !(p_update->release.psz_desc = malloc( i_len + 1)) )
273         goto error;
274     strncpy( p_update->release.psz_desc, psz_update_data_parser, i_len );
275     p_update->release.psz_desc[i_len] = '\0';
276
277     printf("desc %s\n", p_update->release.psz_desc);
278
279     /* Now that we know the status is valid, we must download its signature
280      * to authenticate it */
281     signature_packet_t sign;
282     if( download_signature( VLC_OBJECT( p_update->p_libvlc ), &sign,
283             UPDATE_VLC_STATUS_URL ) != VLC_SUCCESS )
284     {
285         msg_Err( p_update->p_libvlc, "Couldn't download signature of status file" );
286         goto error;
287     }
288
289     if( sign.type != BINARY_SIGNATURE && sign.type != TEXT_SIGNATURE )
290     {
291         msg_Err( p_update->p_libvlc, "Invalid signature type" );
292         goto error;
293     }
294
295     p_update->p_pkey = (public_key_t*)malloc( sizeof( public_key_t ) );
296     if( !p_update->p_pkey )
297         goto error;
298
299     if( parse_public_key( videolan_public_key, sizeof( videolan_public_key ),
300                         p_update->p_pkey, NULL ) != VLC_SUCCESS )
301     {
302         msg_Err( p_update->p_libvlc, "Couldn't parse embedded public key, something went really wrong..." );
303         FREENULL( p_update->p_pkey );
304         goto error;
305     }
306
307     memcpy( p_update->p_pkey->longid, videolan_public_key_longid, 8 );
308
309     if( memcmp( sign.issuer_longid, p_update->p_pkey->longid , 8 ) != 0 )
310     {
311         msg_Dbg( p_update->p_libvlc, "Need to download the GPG key" );
312         public_key_t *p_new_pkey = download_key(
313                 VLC_OBJECT(p_update->p_libvlc),
314                 sign.issuer_longid, videolan_public_key_longid );
315         if( !p_new_pkey )
316         {
317             msg_Err( p_update->p_libvlc, "Couldn't download GPG key" );
318             FREENULL( p_update->p_pkey );
319             goto error;
320         }
321
322         uint8_t *p_hash = hash_sha1_from_public_key( p_new_pkey );
323         if( !p_hash )
324         {
325             msg_Err( p_update->p_libvlc, "Failed to hash signature" );
326             free( p_new_pkey );
327             FREENULL( p_update->p_pkey );
328             goto error;
329         }
330
331         if( verify_signature( p_new_pkey->sig.r, p_new_pkey->sig.s,
332                     &p_update->p_pkey->key, p_hash ) == VLC_SUCCESS )
333         {
334             free( p_hash );
335             msg_Info( p_update->p_libvlc, "Key authenticated" );
336             free( p_update->p_pkey );
337             p_update->p_pkey = p_new_pkey;
338         }
339         else
340         {
341             free( p_hash );
342             msg_Err( p_update->p_libvlc, "Key signature invalid !\n" );
343             goto error;
344         }
345     }
346
347     uint8_t *p_hash = hash_sha1_from_text( psz_update_data, &sign );
348     if( !p_hash )
349     {
350         msg_Warn( p_update->p_libvlc, "Can't compute SHA1 hash for status file" );
351         goto error;
352     }
353
354     else if( p_hash[0] != sign.hash_verification[0] ||
355         p_hash[1] != sign.hash_verification[1] )
356     {
357         msg_Warn( p_update->p_libvlc, "Bad SHA1 hash for status file" );
358         goto error;
359     }
360
361     else if( verify_signature( sign.r, sign.s, &p_update->p_pkey->key, p_hash )
362             != VLC_SUCCESS )
363     {
364         msg_Err( p_update->p_libvlc, "BAD SIGNATURE for status file" );
365         goto error;
366     }
367
368     else
369     {
370         msg_Info( p_update->p_libvlc, "Status file authenticated" );
371         return true;
372     }
373
374 error:
375     if( p_stream )
376         stream_Delete( p_stream );
377     free( psz_version_line );
378     free( psz_update_data );
379     return false;
380 }
381
382 static void* update_CheckReal( vlc_object_t *p_this );
383
384 /**
385  * Check for updates
386  *
387  * \param p_update pointer to update struct
388  * \param pf_callback pointer to a function to call when the update_check is finished
389  * \param p_data pointer to some datas to give to the callback
390  * \returns nothing
391  */
392 void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ), void *p_data )
393 {
394     assert( p_update );
395
396     // If the object already exist, destroy it
397     if( p_update->p_check )
398     {
399         vlc_object_kill( p_update->p_check );
400         vlc_thread_join( p_update->p_check );
401         vlc_object_release( p_update->p_check );
402     }
403
404     update_check_thread_t *p_uct =
405         vlc_custom_create( p_update->p_libvlc, sizeof( *p_uct ),
406                            VLC_OBJECT_GENERIC, "update check" );
407     if( !p_uct ) return;
408
409     p_uct->p_update = p_update;
410     p_update->p_check = p_uct;
411     p_uct->pf_callback = pf_callback;
412     p_uct->p_data = p_data;
413
414     vlc_thread_create( p_uct, "check for update", update_CheckReal,
415                        VLC_THREAD_PRIORITY_LOW );
416 }
417
418 void* update_CheckReal( vlc_object_t* p_this )
419 {
420     update_check_thread_t *p_uct = (update_check_thread_t *)p_this;
421     bool b_ret;
422     int canc;
423
424     canc = vlc_savecancel ();
425     vlc_mutex_lock( &p_uct->p_update->lock );
426
427     EmptyRelease( p_uct->p_update );
428     b_ret = GetUpdateFile( p_uct->p_update );
429     vlc_mutex_unlock( &p_uct->p_update->lock );
430
431     if( p_uct->pf_callback )
432         (p_uct->pf_callback)( p_uct->p_data, b_ret );
433
434     vlc_restorecancel (canc);
435     return NULL;
436 }
437
438 /**
439  * Compare a given release's version number to the current VLC's one
440  *
441  * \param p_update structure
442  * \return true if we have to upgrade to the given version to be up to date
443  */
444 static bool is_strictly_greater( int * a, int * b, int n)
445 {
446     if( n <= 0 ) return false;
447     if(a[0] > b[0] ) return true;
448     if(a[0] == b[0] ) return is_strictly_greater( a+1, b+1, n-1 );
449     /* a[0] < b[0] */ return false;
450 }
451
452 bool update_NeedUpgrade( update_t *p_update )
453 {
454     assert( p_update );
455
456     int current_version[] = {
457         *PACKAGE_VERSION_MAJOR - '0',
458         *PACKAGE_VERSION_MINOR - '0',
459         *PACKAGE_VERSION_REVISION - '0',
460         /* extra string of development versions is "-git", "-rc" ..
461          * so make sure version a.b.c is newer than a.b.c-XXX */
462         (*PACKAGE_VERSION_EXTRA == '-') ? -1 : *PACKAGE_VERSION_EXTRA
463     };
464     int latest_version[] = {
465         p_update->release.i_major,
466         p_update->release.i_minor,
467         p_update->release.i_revision,
468         p_update->release.extra
469     };
470
471     return is_strictly_greater( latest_version, current_version, 4 );
472 }
473
474 /**
475  * Convert a long int size in bytes to a string
476  *
477  * \param l_size the size in bytes
478  * \return the size as a string
479  */
480 static char *size_str( long int l_size )
481 {
482     char *psz_tmp = NULL;
483     int i_retval = 0;
484     if( l_size >> 30 )
485         i_retval = asprintf( &psz_tmp, _("%.1f GB"), (float)l_size/(1<<30) );
486     else if( l_size >> 20 )
487         i_retval = asprintf( &psz_tmp, _("%.1f MB"), (float)l_size/(1<<20) );
488     else if( l_size >> 10 )
489         i_retval = asprintf( &psz_tmp, _("%.1f kB"), (float)l_size/(1<<10) );
490     else
491         i_retval = asprintf( &psz_tmp, _("%ld B"), l_size );
492
493     return i_retval == -1 ? NULL : psz_tmp;
494 }
495
496 static void* update_DownloadReal( vlc_object_t *p_this );
497
498 /**
499  * Download the file given in the update_t
500  *
501  * \param p_update structure
502  * \param dir to store the download file
503  * \return nothing
504  */
505 void update_Download( update_t *p_update, const char *psz_destdir )
506 {
507     assert( p_update );
508
509     // If the object already exist, destroy it
510     if( p_update->p_download )
511     {
512         vlc_object_kill( p_update->p_download );
513         vlc_thread_join( p_update->p_download );
514         vlc_object_release( p_update->p_download );
515     }
516
517     update_download_thread_t *p_udt =
518         vlc_custom_create( p_update->p_libvlc, sizeof( *p_udt ),
519                            VLC_OBJECT_GENERIC, "update download" );
520     if( !p_udt )
521         return;
522
523     p_udt->p_update = p_update;
524     p_update->p_download = p_udt;
525     p_udt->psz_destdir = psz_destdir ? strdup( psz_destdir ) : NULL;
526
527     vlc_thread_create( p_udt, "download update", update_DownloadReal,
528                        VLC_THREAD_PRIORITY_LOW );
529 }
530
531 static void* update_DownloadReal( vlc_object_t *p_this )
532 {
533     update_download_thread_t *p_udt = (update_download_thread_t *)p_this;
534     dialog_progress_bar_t *p_progress = NULL;
535     long int l_size;
536     long int l_downloaded = 0;
537     float f_progress;
538     char *psz_status = NULL;
539     char *psz_downloaded = NULL;
540     char *psz_size = NULL;
541     char *psz_destfile = NULL;
542     char *psz_tmpdestfile = NULL;
543
544     FILE *p_file = NULL;
545     stream_t *p_stream = NULL;
546     void* p_buffer = NULL;
547     int i_read;
548     int canc;
549
550     update_t *p_update = p_udt->p_update;
551     char *psz_destdir = p_udt->psz_destdir;
552
553     msg_Dbg( p_udt, "Opening Stream '%s'", p_update->release.psz_url );
554     canc = vlc_savecancel ();
555
556     /* Open the stream */
557     p_stream = stream_UrlNew( p_udt, p_update->release.psz_url );
558     if( !p_stream )
559     {
560         msg_Err( p_udt, "Failed to open %s for reading", p_update->release.psz_url );
561         goto end;
562     }
563
564     /* Get the stream size */
565     l_size = stream_Size( p_stream );
566
567     /* Get the file name and open it*/
568     psz_tmpdestfile = strrchr( p_update->release.psz_url, '/' );
569     if( !psz_tmpdestfile )
570     {
571         msg_Err( p_udt, "The URL %s is badly formated",
572                  p_update->release.psz_url );
573         goto end;
574     }
575     psz_tmpdestfile++;
576     if( asprintf( &psz_destfile, "%s%s", psz_destdir, psz_tmpdestfile ) == -1 )
577         goto end;
578
579     p_file = utf8_fopen( psz_destfile, "w" );
580     if( !p_file )
581     {
582         msg_Err( p_udt, "Failed to open %s for writing", psz_destfile );
583         dialog_FatalWait( p_udt, _("Saving file failed"),
584             _("Failed to open \"%s\" for writing"),
585              psz_destfile );
586         goto end;
587     }
588
589     /* Create a buffer and fill it with the downloaded file */
590     p_buffer = (void *)malloc( 1 << 10 );
591     if( !p_buffer )
592     {
593         msg_Err( p_udt, "Can't malloc (1 << 10) bytes! download cancelled." );
594         goto end;
595     }
596
597     msg_Dbg( p_udt, "Downloading Stream '%s'", p_update->release.psz_url );
598
599     psz_size = size_str( l_size );
600     if( asprintf( &psz_status, _("%s\nDownloading... %s/%s %.1f%% done"),
601         p_update->release.psz_url, "0.0", psz_size, 0.0 ) != -1 )
602     {
603         p_progress = dialog_ProgressCreate( p_udt, _( "Downloading ..."),
604                                             psz_status, _("Cancel") );
605         free( psz_status );
606     }
607
608     while( vlc_object_alive( p_udt ) &&
609            ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
610            !dialog_ProgressCancelled( p_progress ) )
611     {
612         if( fwrite( p_buffer, i_read, 1, p_file ) < 1 )
613         {
614             msg_Err( p_udt, "Failed to write into %s", psz_destfile );
615             break;
616         }
617
618         l_downloaded += i_read;
619         psz_downloaded = size_str( l_downloaded );
620         f_progress = (float)l_downloaded/(float)l_size;
621
622         if( asprintf( &psz_status, _( "%s\nDownloading... %s/%s - %.1f%% done" ),
623                       p_update->release.psz_url, psz_downloaded, psz_size,
624                       f_progress*100 ) != -1 )
625         {
626             dialog_ProgressSet( p_progress, psz_status, f_progress );
627             free( psz_status );
628         }
629         free( psz_downloaded );
630     }
631
632     /* Finish the progress bar or delete the file if the user had canceled */
633     fclose( p_file );
634     p_file = NULL;
635
636     if( vlc_object_alive( p_udt ) &&
637         !dialog_ProgressCancelled( p_progress ) )
638     {
639         if( asprintf( &psz_status, _("%s\nDone %s (100.0%%)"),
640             p_update->release.psz_url, psz_size ) != -1 )
641         {
642             dialog_ProgressDestroy( p_progress );
643             p_progress = NULL;
644             free( psz_status );
645         }
646     }
647     else
648     {
649         utf8_unlink( psz_destfile );
650         goto end;
651     }
652
653     signature_packet_t sign;
654     if( download_signature( VLC_OBJECT( p_udt ), &sign,
655             p_update->release.psz_url ) != VLC_SUCCESS )
656     {
657         utf8_unlink( psz_destfile );
658
659         dialog_FatalWait( p_udt, _("File could not be verified"),
660             _("It was not possible to download a cryptographic signature for "
661               "the downloaded file \"%s\". Thus, it was deleted."),
662             psz_destfile );
663         msg_Err( p_udt, "Couldn't download signature of downloaded file" );
664         goto end;
665     }
666
667     if( memcmp( sign.issuer_longid, p_update->p_pkey->longid, 8 ) )
668     {
669         utf8_unlink( psz_destfile );
670         msg_Err( p_udt, "Invalid signature issuer" );
671         dialog_FatalWait( p_udt, _("Invalid signature"),
672             _("The cryptographic signature for the downloaded file \"%s\" was "
673               "invalid and could not be used to securely verify it. Thus, the "
674               "file was deleted."),
675             psz_destfile );
676         goto end;
677     }
678
679     if( sign.type != BINARY_SIGNATURE )
680     {
681         utf8_unlink( psz_destfile );
682         msg_Err( p_udt, "Invalid signature type" );
683         dialog_FatalWait( p_udt, _("Invalid signature"),
684             _("The cryptographic signature for the downloaded file \"%s\" was "
685               "invalid and could not be used to securely verify it. Thus, the "
686               "file was deleted."),
687             psz_destfile );
688         goto end;
689     }
690
691     uint8_t *p_hash = hash_sha1_from_file( psz_destfile, &sign );
692     if( !p_hash )
693     {
694         msg_Err( p_udt, "Unable to hash %s", psz_destfile );
695         utf8_unlink( psz_destfile );
696         dialog_FatalWait( p_udt, _("File not verifiable"),
697             _("It was not possible to securely verify the downloaded file"
698               " \"%s\". Thus, it was deleted."),
699             psz_destfile );
700
701         goto end;
702     }
703
704     if( p_hash[0] != sign.hash_verification[0] ||
705         p_hash[1] != sign.hash_verification[1] )
706     {
707         utf8_unlink( psz_destfile );
708         dialog_FatalWait( p_udt, _("File corrupted"),
709             _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
710              psz_destfile );
711         msg_Err( p_udt, "Bad SHA1 hash for %s", psz_destfile );
712         free( p_hash );
713         goto end;
714     }
715
716     if( verify_signature( sign.r, sign.s, &p_update->p_pkey->key, p_hash )
717             != VLC_SUCCESS )
718     {
719         utf8_unlink( psz_destfile );
720         dialog_FatalWait( p_udt, _("File corrupted"),
721             _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
722              psz_destfile );
723         msg_Err( p_udt, "BAD SIGNATURE for %s", psz_destfile );
724         free( p_hash );
725         goto end;
726     }
727
728     msg_Info( p_udt, "%s authenticated", psz_destfile );
729     free( p_hash );
730
731 end:
732     if( p_progress )
733         dialog_ProgressDestroy( p_progress );
734     if( p_stream )
735         stream_Delete( p_stream );
736     if( p_file )
737         fclose( p_file );
738     free( psz_destdir );
739     free( psz_destfile );
740     free( p_buffer );
741     free( psz_size );
742
743     vlc_restorecancel( canc );
744     return NULL;
745 }
746
747 update_release_t *update_GetRelease( update_t *p_update )
748 {
749     return &p_update->release;
750 }
751
752 #else
753 update_t *__update_New( vlc_object_t *p_this )
754 {
755     (void)p_this;
756     return NULL;
757 }
758
759 void update_Delete( update_t *p_update )
760 {
761     (void)p_update;
762 }
763
764 void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ),
765                    void *p_data )
766 {
767     (void)p_update; (void)pf_callback; (void)p_data;
768 }
769
770 bool update_NeedUpgrade( update_t *p_update )
771 {
772     (void)p_update;
773     return false;
774 }
775
776 void update_Download( update_t *p_update, const char *psz_destdir )
777 {
778     (void)p_update; (void)psz_destdir;
779 }
780
781 update_release_t *update_GetRelease( update_t *p_update )
782 {
783     (void)p_update;
784     return NULL;
785 }
786 #endif