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