1 /*****************************************************************************
2 * update.c: VLC update and plugins download
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either release 2 of the License, or
12 * (at your option) any later release.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
26 * This file contains functions related to VLC and plugins update management
30 * TODO: * pgp verification of the update file
31 * binary download, and pgp verification
34 /*****************************************************************************
36 *****************************************************************************/
42 #include <ctype.h> /* tolower() */
46 #include <vlc_update.h>
48 #include <vlc_block.h>
49 #include <vlc_stream.h>
50 #include <vlc_interface.h>
51 #include <vlc_charset.h>
53 /*****************************************************************************
55 *****************************************************************************/
57 #if defined( UNDER_CE )
58 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-ce"
59 #elif defined( WIN32 )
60 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-win-x86"
61 #elif defined( __APPLE__ )
62 # define UPDATE_VLC_OS "macosx"
63 # if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
64 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-ppc"
66 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-x86"
68 #elif defined( SYS_BEOS )
69 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-beos-x86"
71 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status"
74 #define STRDUP( a ) ( a ? strdup( a ) : NULL )
77 /*****************************************************************************
79 *****************************************************************************/
80 static void EmptyRelease( update_t *p_update );
81 static void GetUpdateFile( update_t *p_update );
82 static int extracmp( char *psz_1, char *psz_2 );
83 static int CompareReleases( const struct update_release_t *p1,
84 const struct update_release_t *p2 );
86 /*****************************************************************************
88 *****************************************************************************/
90 #define packet_type( c ) ( ( c & 0x3c ) >> 2 ) /* 0x3C = 00111100 */
91 #define packet_header_len( c ) ( ( c & 0x03 ) + 1 ) /* number of bytes in a packet header */
93 static inline int scalar_number( uint8_t *p, int header_len )
97 else if( header_len == 2 )
98 return( (p[0] << 8) + p[1] );
99 else if( header_len == 4 )
100 return( (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3] );
105 /* number of data bytes in a MPI */
106 #define mpi_len( mpi ) ( ( scalar_number( mpi, 2 ) + 7 ) / 8 )
109 * fill a public_key_packet_t structure from public key packet data
110 * verify that it is a version 4 public key packet, using DSA
112 static int parse_public_key_packet( public_key_packet_t *p_key, uint8_t *p_buf,
113 size_t i_packet_len )
115 if( i_packet_len != 418 )
118 p_key->version = *p_buf++;
119 if( p_key->version != 4 )
122 /* warn when timestamp is > date ? */
123 memcpy( p_key->timestamp, p_buf, 4 ); p_buf += 4;
125 p_key->algo = *p_buf++;
126 if( p_key->algo != PUBLIC_KEY_ALGO_DSA )
129 memcpy( p_key->p, p_buf, 2+128 ); p_buf += 2+128;
130 if( mpi_len( p_key->p ) != 128 )
133 memcpy( p_key->q, p_buf, 2+20 ); p_buf += 2+20;
134 if( mpi_len( p_key->q ) != 20 )
137 memcpy( p_key->g, p_buf, 2+128 ); p_buf += 2+128;
138 if( mpi_len( p_key->g ) != 128 )
141 memcpy( p_key->y, p_buf, 2+128 ); p_buf += 2+128;
142 if( mpi_len( p_key->y ) != 128 )
149 * fill a signature_packet_v4_t from signature packet data
150 * verify that it was used with a DSA public key, using SHA-1 digest
152 static int parse_signature_v4_packet( signature_packet_v4_t *p_sig,
153 uint8_t *p_buf, size_t i_sig_len )
158 p_sig->version = *p_buf++;
159 if( p_sig->version != 4 )
162 p_sig->type = *p_buf++;
163 if( p_sig->type < GENERIC_KEY_SIGNATURE ||
164 p_sig->type > POSITIVE_KEY_SIGNATURE )
167 p_sig->public_key_algo = *p_buf++;
168 if( p_sig->public_key_algo != PUBLIC_KEY_ALGO_DSA )
171 p_sig->digest_algo = *p_buf++;
172 if( p_sig->digest_algo != DIGEST_ALGO_SHA1 )
175 memcpy( p_sig->hashed_data_len, p_buf, 2 ); p_buf += 2;
178 size_t i_hashed_data_len = scalar_number( p_sig->hashed_data_len, 2 );
179 i_pos += i_hashed_data_len;
180 if( i_pos > i_sig_len - 48 ) /* r & s are 44 bytes in total,
181 * + the unhashed data length (2 bytes)
182 * + the hash verification (2 bytes) */
185 p_sig->hashed_data = (uint8_t*) malloc( i_hashed_data_len );
186 if( !p_sig->hashed_data )
188 memcpy( p_sig->hashed_data, p_buf, i_hashed_data_len );
189 p_buf += i_hashed_data_len;
191 memcpy( p_sig->unhashed_data_len, p_buf, 2 ); p_buf += 2;
193 size_t i_unhashed_data_len = scalar_number( p_sig->unhashed_data_len, 2 );
194 i_pos += 2 + i_unhashed_data_len;
195 if( i_pos != i_sig_len - 46 )
197 free( p_sig->hashed_data );
201 p_sig->unhashed_data = (uint8_t*) malloc( i_unhashed_data_len );
202 if( !p_sig->unhashed_data )
204 free( p_sig->hashed_data );
207 memcpy( p_sig->unhashed_data, p_buf, i_unhashed_data_len );
208 p_buf += i_unhashed_data_len;
210 memcpy( p_sig->hash_verification, p_buf, 2 ); p_buf += 2;
212 memcpy( p_sig->r, p_buf, 22 ); p_buf += 22;
213 if( mpi_len( p_sig->r ) != 20 )
215 free( p_sig->hashed_data );
216 free( p_sig->unhashed_data );
220 memcpy( p_sig->s, p_buf, 22 );
221 if( mpi_len( p_sig->s ) != 20 )
223 free( p_sig->hashed_data );
224 free( p_sig->unhashed_data );
232 * crc_octets() was lamely copied from rfc 2440
233 * Copyright (C) The Internet Society (1998). All Rights Reserved.
235 #define CRC24_INIT 0xB704CEL
236 #define CRC24_POLY 0x1864CFBL
238 static long crc_octets( uint8_t *octets, size_t len )
240 long crc = CRC24_INIT;
244 crc ^= (*octets++) << 16;
245 for (i = 0; i < 8; i++)
252 return crc & 0xFFFFFFL;
256 * Transform an armored document in binary format
257 * Used on public keys and signatures
259 static int pgp_unarmor( char *p_ibuf, size_t i_ibuf_len,
260 uint8_t *p_obuf, size_t i_obuf_len )
262 char *p_ipos = p_ibuf;
263 uint8_t *p_opos = p_obuf;
266 int i_header_skipped = 0;
268 while( !i_end && p_ipos < p_ibuf + i_ibuf_len )
270 if( *p_ipos == '\r' || *p_ipos == '\n' )
276 size_t i_line_len = strcspn( p_ipos, "\r\n" );
277 if( i_line_len == 0 )
280 if( !i_header_skipped )
282 if( !strncmp( p_ipos, "-----BEGIN PGP", 14 ) )
283 i_header_skipped = 1;
285 p_ipos += i_line_len + 1;
289 if( !strncmp( p_ipos, "Version:", 8 ) )
291 p_ipos += i_line_len + 1;
295 if( p_ipos[i_line_len - 1] == '=' )
298 p_ipos[i_line_len - 1] = '\0';
301 p_ipos[i_line_len] = '\0';
303 p_opos += vlc_b64_decode_binary_to_buffer( p_opos,
304 p_obuf - p_opos + i_obuf_len,
307 p_ipos += i_line_len + 1;
310 /* XXX: the CRC is OPTIONAL, really require it ? */
311 if( p_ipos + 5 > p_ibuf + i_ibuf_len || *p_ipos++ != '=' )
315 if( vlc_b64_decode_binary_to_buffer( p_crc, 3, p_ipos ) != 3 )
318 long l_crc = crc_octets( p_obuf, p_opos - p_obuf );
319 long l_crc2 = ( 0 << 24 ) + ( p_crc[0] << 16 ) + ( p_crc[1] << 8 ) + p_crc[2];
321 return l_crc2 == l_crc ? p_opos - p_obuf : 0;
325 * Download the signature associated to a document or a binary file.
326 * We're given the file's url, we just append ".asc" to it and download
328 static int download_signature( vlc_object_t *p_this,
329 signature_packet_v3_t *p_sig, char *psz_url )
331 char *psz_sig = (char*) malloc( strlen( psz_url ) + 4 + 1 ); /* ".asc" + \0 */
335 strcpy( psz_sig, psz_url );
336 strcat( psz_sig, ".asc" );
338 stream_t *p_stream = stream_UrlNew( p_this, psz_sig );
344 int64_t i_size = stream_Size( p_stream );
347 stream_Delete( p_stream );
350 else if( i_size == 65 ) /* binary format signature */
352 int i_read = stream_Read( p_stream, p_sig, (int)i_size );
353 stream_Delete( p_stream );
354 if( i_read != i_size )
360 char *p_buf = (char*)malloc( i_size );
363 stream_Delete( p_stream );
367 int i_read = stream_Read( p_stream, p_buf, (int)i_size );
369 stream_Delete( p_stream );
371 if( i_read != i_size )
377 int i_bytes = pgp_unarmor( p_buf, i_size, (uint8_t*)p_sig, 65 );
387 * Verify an OpenPGP signature made on some SHA-1 hash, with some DSA public key
389 static int verify_signature( vlc_object_t *p_this, uint8_t *p_r, uint8_t *p_s,
390 public_key_packet_t *p_key, uint8_t *p_hash )
392 /* the data to be verified (a SHA-1 hash) */
393 const char *hash_sexp_s = "(data(flags raw)(value %m))";
395 const char *key_sexp_s = "(public-key(dsa(p %m)(q %m)(g %m)(y %m)))";
397 const char *sig_sexp_s = "(sig-val(dsa(r %m )(s %m )))";
400 gcry_mpi_t p, q, g, y, r, s, hash;
401 p = q = g = y = r = s = hash = NULL;
402 gcry_sexp_t key_sexp, hash_sexp, sig_sexp;
403 key_sexp = hash_sexp = sig_sexp = NULL;
405 if( gcry_mpi_scan( &p, GCRYMPI_FMT_USG, p_key->p + 2, 128, NULL ) ||
406 gcry_mpi_scan( &q, GCRYMPI_FMT_USG, p_key->q + 2, 20, NULL ) ||
407 gcry_mpi_scan( &g, GCRYMPI_FMT_USG, p_key->g + 2, 128, NULL ) ||
408 gcry_mpi_scan( &y, GCRYMPI_FMT_USG, p_key->y + 2, 128, NULL ) ||
409 gcry_sexp_build( &key_sexp, &erroff, key_sexp_s, p, q, g, y ) )
412 if( gcry_mpi_scan( &r, GCRYMPI_FMT_USG, p_r + 2, 20, NULL ) ||
413 gcry_mpi_scan( &s, GCRYMPI_FMT_USG, p_s + 2, 20, NULL ) ||
414 gcry_sexp_build( &sig_sexp, &erroff, sig_sexp_s, r, s ) )
417 if( gcry_mpi_scan( &hash, GCRYMPI_FMT_USG, p_hash, 20, NULL ) ||
418 gcry_sexp_build( &hash_sexp, &erroff, hash_sexp_s, hash ) )
421 if( gcry_pk_verify( sig_sexp, hash_sexp, key_sexp ) )
427 if( p ) gcry_mpi_release( p );
428 if( q ) gcry_mpi_release( q );
429 if( g ) gcry_mpi_release( g );
430 if( y ) gcry_mpi_release( y );
431 if( r ) gcry_mpi_release( r );
432 if( s ) gcry_mpi_release( s );
433 if( hash ) gcry_mpi_release( hash );
434 if( key_sexp ) gcry_sexp_release( key_sexp );
435 if( sig_sexp ) gcry_sexp_release( sig_sexp );
436 if( hash_sexp ) gcry_sexp_release( hash_sexp );
441 * Return the long id (8 bytes) of the public key used to generate a signature
443 static uint8_t *get_issuer_from_signature_v4( signature_packet_v4_t *p_sig )
445 uint8_t *p = p_sig->unhashed_data;
446 uint8_t *max_pos = p + scalar_number( p_sig->unhashed_data_len, 2 );
450 int i_subpacket_len = *p < 192 ? *p++ :
451 *p < 255 ? ((*p++ - 192) << 8) + *p++ + 192 :
452 ((*++p) << 24) + (*++p << 16) + (*++p << 8) + *++p;
454 if( p >= max_pos - 1 )
457 if( *p == ISSUER_SUBPACKET )
460 p += i_subpacket_len;
466 * fill a public_key_t with public key data, including:
467 * * public key packet
468 * * signature packet issued by key which long id is p_sig_issuer
471 static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len, public_key_t *p_key, const uint8_t *p_sig_issuer )
473 uint8_t *pos = (uint8_t*) p_key_data;
474 uint8_t *max_pos = pos + i_key_len;
477 #define PUBLIC_KEY_FOUND 0x01
478 #define USER_ID_FOUND 0x02
479 #define SIGNATURE_FOUND 0X04
481 uint8_t *p_key_unarmored = NULL;
483 signature_packet_v4_t sig;
485 p_key->psz_username = NULL;
486 p_key->sig.hashed_data = p_key->sig.unhashed_data = NULL;
488 if( !( *pos & 0x80 ) )
489 { /* first byte is ASCII, unarmoring */
490 p_key_unarmored = (uint8_t*)malloc( i_key_len );
491 if( !p_key_unarmored )
493 int i_len = pgp_unarmor( (char*)p_key_data, i_key_len,
494 p_key_unarmored, i_key_len );
499 pos = p_key_unarmored;
500 max_pos = pos + i_len;
503 while( pos < max_pos )
505 if( !(*pos & 0x80) || *pos & 0x40 )
508 int i_type = packet_type( *pos );
510 int i_header_len = packet_header_len( *pos++ );
511 if( pos + i_header_len > max_pos )
514 int i_packet_len = scalar_number( pos, i_header_len );
517 if( pos + i_packet_len > max_pos )
524 case PUBLIC_KEY_PACKET:
525 i_status |= PUBLIC_KEY_FOUND;
526 if( parse_public_key_packet( &p_key->key, pos, i_packet_len ) != VLC_SUCCESS )
530 case SIGNATURE_PACKET:
531 if( !p_sig_issuer || i_status & SIGNATURE_FOUND ||
532 parse_signature_v4_packet( &sig, pos, i_packet_len ) != VLC_SUCCESS )
534 p_issuer = get_issuer_from_signature_v4( &sig );
535 if( memcmp( p_issuer, p_sig_issuer, 8 ) == 0 )
537 memcpy( &p_key->sig, &sig, sizeof( signature_packet_v4_t ) );
538 i_status |= SIGNATURE_FOUND;
542 free( sig.hashed_data );
543 free( sig.unhashed_data );
548 if( p_key->psz_username ) /* save only the first User ID */
550 i_status |= USER_ID_FOUND;
551 p_key->psz_username = (uint8_t*)malloc( i_packet_len + 1);
552 if( !p_key->psz_username )
555 memcpy( p_key->psz_username, pos, i_packet_len );
556 p_key->psz_username[i_packet_len] = '\0';
564 free( p_key_unarmored );
566 if( !( i_status & ( PUBLIC_KEY_FOUND + USER_ID_FOUND ) ) )
569 if( p_sig_issuer && !( i_status & SIGNATURE_FOUND ) )
575 free( p_key->sig.hashed_data );
576 free( p_key->sig.unhashed_data );
577 free( p_key->psz_username );
578 free( p_key_unarmored );
583 * return a sha1 hash of a file
585 static uint8_t *hash_sha1_from_file( const char *psz_file,
586 signature_packet_v3_t *p_sig )
588 FILE *f = utf8_fopen( psz_file, "r" );
592 uint8_t buffer[4096]; //FIXME
595 if( gcry_md_open( &hd, GCRY_MD_SHA1, 0 ) )
602 while( ( i_read = fread( buffer, 1, sizeof(buffer), f ) ) > 0 )
603 gcry_md_write( hd, buffer, i_read );
605 gcry_md_putc( hd, p_sig->type );
606 gcry_md_write( hd, &p_sig->timestamp, 4 );
611 return( (uint8_t*) gcry_md_read( hd, GCRY_MD_SHA1) );
615 * download a public key (the last one) from videolan server, and parse it
617 static public_key_t *download_key( vlc_object_t *p_this, const uint8_t *p_longid, const uint8_t *p_signature_issuer )
620 if( asprintf( &psz_url, "http://download.videolan.org/pub/keys/%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x.asc",
621 p_longid[0], p_longid[1],
622 p_longid[2], p_longid[3],
623 p_longid[4], p_longid[5],
624 p_longid[6], p_longid[7] ) == -1 )
627 stream_t *p_stream = stream_UrlNew( p_this, psz_url );
632 int64_t i_size = stream_Size( p_stream );
635 stream_Delete( p_stream );
639 uint8_t *p_buf = (uint8_t*)malloc( i_size );
642 stream_Delete( p_stream );
646 int i_read = stream_Read( p_stream, p_buf, (int)i_size );
647 stream_Delete( p_stream );
649 if( i_read != (int)i_size )
655 public_key_t *p_pkey = (public_key_t*) malloc( sizeof( public_key_t ) );
662 int i_error = parse_public_key( p_buf, i_read, p_pkey, p_signature_issuer );
665 if( i_error != VLC_SUCCESS )
675 * Generate a SHA-1 hash on a public key, to verify a signature made on that hash
676 * Note that we need the signature to compute the hash
678 static uint8_t *key_sign_hash( public_key_t *p_pkey )
680 gcry_error_t error = 0;
683 error = gcry_md_open( &hd, GCRY_MD_SHA1, 0 );
687 gcry_md_putc( hd, 0x99 );
689 gcry_md_putc( hd, (418 >> 8) & 0xff );
690 gcry_md_putc( hd, 418 & 0xff );
692 gcry_md_write( hd, (uint8_t*)&p_pkey->key, 418 );
694 gcry_md_putc( hd, 0xb4 );
696 int i_len = strlen((char*)p_pkey->psz_username);
698 gcry_md_putc( hd, (i_len << 24) & 0xff );
699 gcry_md_putc( hd, (i_len << 16) & 0xff );
700 gcry_md_putc( hd, (i_len << 8) & 0xff );
701 gcry_md_putc( hd, (i_len) & 0xff );
703 gcry_md_write( hd, p_pkey->psz_username, i_len );
705 size_t i_hashed_data_len = scalar_number( p_pkey->sig.hashed_data_len, 2 );
707 gcry_md_putc( hd, p_pkey->sig.version );
708 gcry_md_putc( hd, p_pkey->sig.type );
709 gcry_md_putc( hd, p_pkey->sig.public_key_algo );
710 gcry_md_putc( hd, p_pkey->sig.digest_algo );
711 gcry_md_write( hd, p_pkey->sig.hashed_data_len, 2 );
712 gcry_md_write( hd, p_pkey->sig.hashed_data, i_hashed_data_len );
714 gcry_md_putc( hd, 0x04 );
715 gcry_md_putc( hd, 0xff );
717 i_hashed_data_len += 6; /* hashed data + 6 bytes header */
719 gcry_md_putc( hd, (i_hashed_data_len << 24) & 0xff);
720 gcry_md_putc( hd, (i_hashed_data_len << 16) &0xff );
721 gcry_md_putc( hd, (i_hashed_data_len << 8) & 0xff );
722 gcry_md_putc( hd, (i_hashed_data_len) & 0xff );
726 uint8_t *p_hash = gcry_md_read( hd, GCRY_MD_SHA1);
728 if( p_hash[0] != p_pkey->sig.hash_verification[0] ||
729 p_hash[1] != p_pkey->sig.hash_verification[1] )
739 /*****************************************************************************
741 *****************************************************************************/
744 * Create a new update VLC struct
746 * \param p_this the calling vlc_object
747 * \return pointer to new update_t or NULL
749 update_t *__update_New( vlc_object_t *p_this )
753 if( p_this == NULL ) return NULL;
755 p_update = (update_t *)malloc( sizeof( update_t ) );
756 if( !p_update ) return NULL;
758 vlc_mutex_init( p_this, &p_update->lock );
760 p_update->p_libvlc = p_this->p_libvlc;
762 p_update->release.psz_svnrev = NULL;
763 p_update->release.psz_extra = NULL;
764 p_update->release.psz_url = NULL;
765 p_update->release.psz_desc = NULL;
771 * Delete an update_t struct
773 * \param p_update update_t* pointer
776 void update_Delete( update_t *p_update )
780 vlc_mutex_destroy( &p_update->lock );
782 FREENULL( p_update->release.psz_svnrev );
783 FREENULL( p_update->release.psz_extra );
784 FREENULL( p_update->release.psz_url );
785 FREENULL( p_update->release.psz_desc );
791 * Empty the release struct
793 * \param p_update update_t* pointer
796 static void EmptyRelease( update_t *p_update )
798 p_update->release.i_major = 0;
799 p_update->release.i_minor = 0;
800 p_update->release.i_revision = 0;
802 FREENULL( p_update->release.psz_svnrev );
803 FREENULL( p_update->release.psz_extra );
804 FREENULL( p_update->release.psz_url );
805 FREENULL( p_update->release.psz_desc );
809 * Get the update file and parse it
810 * *p_update has to be unlocked when calling this function
812 * \param p_update pointer to update struct
815 static void GetUpdateFile( update_t *p_update )
817 stream_t *p_stream = NULL;
821 char *psz_extra = NULL;
822 char *psz_svnrev = NULL;
823 char *psz_line = NULL;
825 vlc_mutex_lock( &p_update->lock );
827 p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL );
830 msg_Err( p_update->p_libvlc, "Failed to open %s for reading",
831 UPDATE_VLC_STATUS_URL );
835 /* Try to read three lines */
836 if( !( psz_line = stream_ReadLine( p_stream ) ) )
838 msg_Err( p_update->p_libvlc, "Update file %s is corrupted : missing version",
839 UPDATE_VLC_STATUS_URL );
843 /* first line : version number */
844 if( sscanf( psz_line, "%i.%i.%i%as %as", &i_major, &i_minor, &i_revision, &psz_extra, &psz_svnrev ) )
846 p_update->release.i_major = i_major;
847 p_update->release.i_minor = i_minor;
848 p_update->release.i_revision = i_revision;
850 p_update->release.psz_svnrev = psz_svnrev ? psz_svnrev : STRDUP( "" );
851 p_update->release.psz_extra = psz_extra ? psz_extra : STRDUP( "" );
855 msg_Err( p_update->p_libvlc, "Update version false formated" );
860 /* Second line : URL */
861 if( !( psz_line = stream_ReadLine( p_stream ) ) )
863 msg_Err( p_update->p_libvlc, "Update file %s is corrupted : URL missing",
864 UPDATE_VLC_STATUS_URL );
867 p_update->release.psz_url = psz_line;
870 /* Third line : description */
871 if( !( psz_line = stream_ReadLine( p_stream ) ) )
873 msg_Err( p_update->p_libvlc, "Update file %s is corrupted : description missing",
874 UPDATE_VLC_STATUS_URL );
877 p_update->release.psz_desc = psz_line;
880 vlc_mutex_unlock( &p_update->lock );
883 stream_Delete( p_stream );
889 * \param p_update pointer to update struct
892 void update_Check( update_t *p_update )
896 EmptyRelease( p_update );
898 GetUpdateFile( p_update );
904 * \param p1 first integer
905 * \param p2 second integer
906 * \return like strcmp
908 static int extracmp( char *psz_1, char *psz_2 )
910 if( psz_1[0] == '-' )
912 if( psz_2[0] == '-' )
913 return strcmp( psz_1, psz_2 );
919 if( psz_2[0] == '-' )
922 return strcmp( psz_1, psz_2 );
926 * Compare two release numbers
928 * \param p1 first release
929 * \param p2 second release
930 * \return UpdateReleaseStatus(Older|Equal|Newer)
932 static int CompareReleases( const struct update_release_t *p1,
933 const struct update_release_t *p2 )
936 d = ( p1->i_major << 24 ) + ( p1->i_minor << 16 ) + ( p1->i_revision << 8 );
937 d = d - ( p2->i_major << 24 ) - ( p2->i_minor << 16 ) - ( p2->i_revision << 8 );
938 d += extracmp( p1->psz_extra, p2->psz_extra );
941 d = strcmp( p1->psz_svnrev, p2->psz_svnrev );
944 return UpdateReleaseStatusOlder;
946 return UpdateReleaseStatusEqual;
948 return UpdateReleaseStatusNewer;
952 * Compare a given release's version number to the current VLC's one
955 * \return UpdateReleaseStatus(Older|Equal|Newer)
957 int update_CompareReleaseToCurrent( update_t *p_update )
961 struct update_release_t c;
966 int i_result = UpdateReleaseStatusOlder;
968 /* get the current version number */
969 if( sscanf( PACKAGE_VERSION, "%i.%i.%i%as", &i_major, &i_minor, &i_revision, &psz_extra ) )
973 c.i_revision = i_revision;
975 c.psz_extra = psz_extra;
977 c.psz_extra = STRDUP( "" );
978 c.psz_svnrev = STRDUP( VLC_Changeset() );
980 i_result = CompareReleases( &p_update->release, &c );
983 free( c.psz_svnrev );