Changeset 15e6f2c9d099fac8307a8e40055886e2f11de1d5

Show
Ignore:
Timestamp:
06/01/08 19:16:56 (3 months ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1212340616 +0200
git-parent:

[53c74579305052334468d130a3f4bfcfc3757209]

git-author:
Rafaël Carré <funman@videolan.org> 1212323427 +0200
Message:

Binary updates: support arbitrarily long descriptions

Note that an upper limit should be set anyway

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/misc/update.c

    rd666030 r15e6f2c  
    6868 *      * AKA "0.8.6d" or "0.9.0" 
    6969 * Second line is an url of the binary for this last version 
    70  * Third line is a description of the update (it MAY be extended to several lines, but for now it is only one line) 
     70 * Remaining text is a required description of the update 
    7171 */ 
    7272 
     
    11051105    int i_revision = 0; 
    11061106    unsigned char extra; 
    1107     char *psz_line = NULL; 
    11081107    char *psz_version_line = NULL; 
    11091108 
     
    11161115    } 
    11171116 
    1118     /* Try to read three lines */ 
    1119     if( !( psz_line = stream_ReadLine( p_stream ) ) ) 
     1117    /* Start reading the status file */ 
     1118    if( !( psz_version_line = stream_ReadLine( p_stream ) ) ) 
    11201119    { 
    11211120        msg_Err( p_update->p_libvlc, "Update file %s is corrupted : missing version", 
     
    11241123    } 
    11251124 
    1126     psz_version_line = psz_line; 
    11271125    /* first line : version number */ 
    11281126    p_update->release.extra = 0; 
    1129     switch( sscanf( psz_line, "%i.%i.%i%c", &i_major, &i_minor, &i_revision, &extra ) ) 
     1127    switch( sscanf( psz_version_line, "%i.%i.%i%c", 
     1128                    &i_major, &i_minor, &i_revision, &extra ) ) 
    11301129    { 
    11311130        case 4: 
     
    11411140    } 
    11421141 
    1143     /* Second line : URL */ 
    1144     if( !( psz_line = stream_ReadLine( p_stream ) ) ) 
     1142    /* second line : URL */ 
     1143    if( !( p_update->release.psz_url = stream_ReadLine( p_stream ) ) ) 
    11451144    { 
    11461145        msg_Err( p_update->p_libvlc, "Update file %s is corrupted : URL missing", 
     
    11481147        goto error; 
    11491148    } 
    1150     p_update->release.psz_url = psz_line; 
    1151  
    1152  
    1153     /* Third line : description */ 
    1154     if( !( psz_line = stream_ReadLine( p_stream ) ) ) 
    1155     { 
    1156         msg_Err( p_update->p_libvlc, "Update file %s is corrupted : description missing", 
    1157                 UPDATE_VLC_STATUS_URL ); 
     1149 
     1150    /* Remaining data : description */ 
     1151    int i_read = stream_Size( p_stream ) - stream_Tell( p_stream ); 
     1152    if( i_read <= 0 ) 
     1153    { 
     1154        msg_Err( p_update->p_libvlc, 
     1155                "Update file %s is corrupted: description missing", 
     1156                UPDATE_VLC_STATUS_URL ); 
    11581157        goto error; 
    11591158    } 
    1160     p_update->release.psz_desc = psz_line; 
     1159 
     1160    p_update->release.psz_desc = (char*) malloc( i_read + 1 ); 
     1161    if( !p_update->release.psz_desc ) 
     1162        goto error; 
     1163 
     1164    if( stream_Read( p_stream, p_update->release.psz_desc, i_read ) != i_read ) 
     1165    { 
     1166        msg_Err( p_update->p_libvlc, "Couldn't download update file %s", 
     1167                UPDATE_VLC_STATUS_URL ); 
     1168        goto error; 
     1169    } 
     1170    p_update->release.psz_desc[i_read] = '\0'; 
    11611171 
    11621172    stream_Delete( p_stream ); 
     
    12451255        gcry_md_putc( hd, '\r' ); 
    12461256    gcry_md_putc( hd, '\n' ); 
    1247     gcry_md_write( hd, p_update->release.psz_desc, 
    1248                         strlen( p_update->release.psz_desc ) ); 
    1249     if( sign.type == TEXT_SIGNATURE ) 
    1250         gcry_md_putc( hd, '\r' ); 
    1251     gcry_md_putc( hd, '\n' ); 
    1252  
     1257 
     1258    char *psz_desc = p_update->release.psz_desc; 
     1259    while( *psz_desc ) 
     1260    { 
     1261        size_t i_len = strcspn( psz_desc, "\r\n" ); 
     1262        if( !i_len ) 
     1263            break; 
     1264 
     1265        gcry_md_write( hd, psz_desc, i_len ); 
     1266        if( sign.type == TEXT_SIGNATURE ) 
     1267            gcry_md_putc( hd, '\r' ); 
     1268        gcry_md_putc( hd, '\n' ); 
     1269 
     1270        psz_desc += i_len; 
     1271        while( *psz_desc == '\r' || *psz_desc == '\n' ) 
     1272            psz_desc++; 
     1273    } 
    12531274 
    12541275    if( sign.version == 3 )