]> git.sesse.net Git - vlc/blobdiff - src/misc/update.c
Remove p_playlist from p_libvlc
[vlc] / src / misc / update.c
index 513888f16c3139db77f50b66f6ac424b72610e2e..cd1cd408bfb5ea1ab4f6bb4b4887ebc0a93190c9 100644 (file)
@@ -48,6 +48,7 @@
 #include <vlc_pgpkey.h>
 #include <vlc_stream.h>
 #include <vlc_interface.h>
+#include <vlc_gcrypt.h>
 
 
 /*****************************************************************************
@@ -87,9 +88,7 @@
  * Local Prototypes
  *****************************************************************************/
 static void EmptyRelease( update_t *p_update );
-static vlc_bool_t GetUpdateFile( update_t *p_update );
-static int CompareReleases( const struct update_release_t *p1,
-                            const struct update_release_t *p2 );
+static bool GetUpdateFile( update_t *p_update );
 static char * size_str( long int l_size );
 
 
@@ -847,7 +846,7 @@ update_t *__update_New( vlc_object_t *p_this )
     p_update = (update_t *)malloc( sizeof( update_t ) );
     if( !p_update ) return NULL;
 
-    vlc_mutex_init( p_this, &p_update->lock );
+    vlc_mutex_init( &p_update->lock );
 
     p_update->p_libvlc = p_this->p_libvlc;
 
@@ -855,6 +854,7 @@ update_t *__update_New( vlc_object_t *p_this )
     p_update->release.psz_desc = NULL;
 
     p_update->p_pkey = NULL;
+    vlc_gcrypt_init();
 
     return p_update;
 }
@@ -899,9 +899,9 @@ static void EmptyRelease( update_t *p_update )
  * p_update has to be locked when calling this function
  *
  * \param p_update pointer to update struct
- * \return VLC_TRUE if the update is valid and authenticated
+ * \return true if the update is valid and authenticated
  */
-static vlc_bool_t GetUpdateFile( update_t *p_update )
+static bool GetUpdateFile( update_t *p_update )
 {
     stream_t *p_stream = NULL;
     int i_major = 0;
@@ -1076,7 +1076,7 @@ static vlc_bool_t GetUpdateFile( update_t *p_update )
     {
         msg_Info( p_update->p_libvlc, "Status file authenticated" );
         gcry_md_close( hd );
-        return VLC_TRUE;
+        return true;
     }
 
 error_hd:
@@ -1085,7 +1085,7 @@ error:
     if( p_stream )
         stream_Delete( p_stream );
     free( psz_version_line );
-    return VLC_FALSE;
+    return false;
 }
 
 
@@ -1096,7 +1096,7 @@ typedef struct
 {
     VLC_COMMON_MEMBERS
     update_t *p_update;
-    void (*pf_callback)( void *, vlc_bool_t );
+    void (*pf_callback)( void *, bool );
     void *p_data;
 } update_check_thread_t;
 
@@ -1110,7 +1110,7 @@ void update_CheckReal( update_check_thread_t *p_uct );
  * \param p_data pointer to some datas to give to the callback
  * \returns nothing
  */
-void update_Check( update_t *p_update, void (*pf_callback)( void*, vlc_bool_t ), void *p_data )
+void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ), void *p_data )
 {
     assert( p_update );
 
@@ -1127,12 +1127,12 @@ void update_Check( update_t *p_update, void (*pf_callback)( void*, vlc_bool_t ),
     p_uct->p_data = p_data;
 
     vlc_thread_create( p_uct, "check for update", update_CheckReal,
-                       VLC_THREAD_PRIORITY_LOW, VLC_FALSE );
+                       VLC_THREAD_PRIORITY_LOW, false );
 }
 
 void update_CheckReal( update_check_thread_t *p_uct )
 {
-    vlc_bool_t b_ret;
+    bool b_ret;
     vlc_mutex_lock( &p_uct->p_update->lock );
 
     EmptyRelease( p_uct->p_update );
@@ -1142,51 +1142,23 @@ void update_CheckReal( update_check_thread_t *p_uct )
     if( p_uct->pf_callback )
         (p_uct->pf_callback)( p_uct->p_data, b_ret );
 
-    vlc_object_destroy( p_uct );
-}
-
-/**
- * Compare two release numbers
- *
- * \param p1 first release
- * \param p2 second release
- * \return UpdateReleaseStatus(Older|Equal|Newer)
- */
-static int CompareReleases( const struct update_release_t *p1,
-                            const struct update_release_t *p2 )
-{
-    int32_t d;
-    d = ( p1->i_major << 24 ) + ( p1->i_minor << 16 ) + ( p1->i_revision << 8 )
-      - ( p2->i_major << 24 ) - ( p2->i_minor << 16 ) - ( p2->i_revision << 8 )
-      + ( p1->extra ) - ( p2->extra );
-
-    if( d < 0 )
-        return UpdateReleaseStatusOlder;
-    else if( d == 0 )
-        return UpdateReleaseStatusEqual;
-    else
-        return UpdateReleaseStatusNewer;
+    vlc_object_release( p_uct );
 }
 
 /**
  * Compare a given release's version number to the current VLC's one
  *
  * \param p_update structure
- * \return UpdateReleaseStatus(Older|Equal|Newer)
+ * \return true if we have to upgrade to the given version to be up to date
  */
-int update_CompareReleaseToCurrent( update_t *p_update )
+bool update_NeedUpgrade( update_t *p_update )
 {
     assert( p_update );
 
-    struct update_release_t c;
-
-    /* get the current version number */
-    c.i_major = *PACKAGE_VERSION_MAJOR - '0';
-    c.i_minor = *PACKAGE_VERSION_MINOR - '0';
-    c.i_revision = *PACKAGE_VERSION_REVISION - '0';
-    c.extra = *PACKAGE_VERSION_EXTRA;
-
-    return CompareReleases( &p_update->release, &c );
+    return  p_update->release.i_major < *PACKAGE_VERSION_MAJOR - '0' ||
+            p_update->release.i_minor < *PACKAGE_VERSION_MINOR - '0' ||
+            p_update->release.i_revision < *PACKAGE_VERSION_REVISION ||
+            p_update->release.extra < *PACKAGE_VERSION_EXTRA;
 }
 
 /**
@@ -1247,7 +1219,7 @@ void update_Download( update_t *p_update, char *psz_destdir )
     p_udt->psz_destdir = psz_destdir ? strdup( psz_destdir ) : NULL;
 
     vlc_thread_create( p_udt, "download update", update_DownloadReal,
-                       VLC_THREAD_PRIORITY_LOW, VLC_FALSE );
+                       VLC_THREAD_PRIORITY_LOW, false );
 }
 
 void update_DownloadReal( update_download_thread_t *p_udt )
@@ -1360,19 +1332,31 @@ void update_DownloadReal( update_download_thread_t *p_udt )
     {
         utf8_unlink( psz_destfile );
 
-        intf_UserFatal( p_udt, VLC_TRUE, _("File can not be verified"),
-            _("It was not possible to downlaod a cryptographic signature for "
+        intf_UserFatal( p_udt, true, _("File can not be verified"),
+            _("It was not possible to download a cryptographic signature for "
               "downloaded file \"%s\", and so VLC deleted it."),
             psz_destfile );
         msg_Err( p_udt, "Couldn't download signature of downloaded file" );
         goto end;
     }
 
+    if( memcmp( sign.issuer_longid, p_update->p_pkey->longid, 8 ) )
+    {
+        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."),
+            psz_destfile );
+        goto end;
+    }
+
     if( sign.type != BINARY_SIGNATURE )
     {
         utf8_unlink( psz_destfile );
         msg_Err( p_udt, "Invalid signature type" );
-        intf_UserFatal( p_udt, VLC_TRUE, _("Invalid signature"),
+        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."),
@@ -1385,7 +1369,7 @@ void update_DownloadReal( update_download_thread_t *p_udt )
     {
         msg_Err( p_udt, "Unable to hash %s", psz_destfile );
         utf8_unlink( psz_destfile );
-        intf_UserFatal( p_udt, VLC_TRUE, _("File not verifiable"),
+        intf_UserFatal( p_udt, true, _("File not verifiable"),
             _("It was not possible to securely verify downloaded file \"%s\", "
               "and so VLC deleted it."),
             psz_destfile );
@@ -1397,7 +1381,7 @@ void update_DownloadReal( update_download_thread_t *p_udt )
         p_hash[1] != sign.hash_verification[1] )
     {
         utf8_unlink( psz_destfile );
-        intf_UserFatal( p_udt, VLC_TRUE, _("File corrupted"),
+        intf_UserFatal( p_udt, true, _("File corrupted"),
             _("Downloaded file \"%s\" was corrupted, and so VLC deleted it."),
              psz_destfile );
         msg_Err( p_udt, "Bad SHA1 hash for %s", psz_destfile );
@@ -1409,7 +1393,7 @@ void update_DownloadReal( update_download_thread_t *p_udt )
             != VLC_SUCCESS )
     {
         utf8_unlink( psz_destfile );
-        intf_UserFatal( p_udt, VLC_TRUE, _("File corrupted"),
+        intf_UserFatal( p_udt, true, _("File corrupted"),
             _("Downloaded file \"%s\" was corrupted, and so VLC deleted it."),
              psz_destfile );
         msg_Err( p_udt, "BAD SIGNATURE for %s", psz_destfile );
@@ -1430,7 +1414,7 @@ end:
     free( p_buffer );
     free( psz_size );
 
-    vlc_object_destroy( p_udt );
+    vlc_object_release( p_udt );
 }
 
 #endif