]> git.sesse.net Git - vlc/blobdiff - src/misc/update.c
Fix previous commit
[vlc] / src / misc / update.c
index dbbf3685e956699a997005088a94a51350bb958d..5e555e2a30c783da426cccb43b56f50421576d7b 100644 (file)
 # 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>
@@ -52,6 +52,7 @@
 #include <gcrypt.h>
 #include <vlc_gcrypt.h>
 
+#include "update.h"
 
 /*****************************************************************************
  * Misc defines
@@ -66,7 +67,7 @@
  *      * 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 )
@@ -1103,7 +1104,6 @@ static bool GetUpdateFile( update_t *p_update )
     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 );
@@ -1114,18 +1114,18 @@ static bool GetUpdateFile( update_t *p_update )
         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;
@@ -1139,24 +1139,35 @@ static bool GetUpdateFile( update_t *p_update )
             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;
@@ -1243,12 +1254,23 @@ static bool GetUpdateFile( update_t *p_update )
     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 )
     {
@@ -1638,6 +1660,12 @@ end:
 
     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 )
 {
@@ -1666,4 +1694,10 @@ void update_Download( update_t *p_update, char *psz_destdir )
 {
     (void)p_update; (void)psz_destdir;
 }
+
+update_release_t *update_GetRelease( update_t *p_update )
+{
+    (void)p_update;
+    return NULL;
+}
 #endif