From: sr55 Date: Fri, 30 May 2008 20:27:26 +0000 (+0000) Subject: update.c altered to use both appcast.xml and appcast_unstable.xml X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=a70ea1b495ab14915590b8cbd7867f80925f253a;p=handbrake-jp%2Fhandbrake-jp-git.git update.c altered to use both appcast.xml and appcast_unstable.xml now uses a single tag, for version information. git-svn-id: svn://localhost/HandBrake/trunk@1475 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/Jamrules b/Jamrules index 490aa870..5e18e3ed 100644 --- a/Jamrules +++ b/Jamrules @@ -30,6 +30,7 @@ APPCAST_URL = "http://handbrake.fr/appcast.xml" ; } DEFINES += HB_VERSION=\\\"$(HB_VERSION)\\\" HB_BUILD=$(HB_BUILD) ; +DEFINES += APPCAST_URL=\\\"$(APPCAST_URL)\\\" ; LANGUAGES = fr de it pl ru nl es pt ja ; RM = rm -rf ; diff --git a/libhb/update.c b/libhb/update.c index 7c9f5b3b..51019e26 100644 --- a/libhb/update.c +++ b/libhb/update.c @@ -6,8 +6,8 @@ #include "hb.h" -#define HB_URL "handbrake.fr" -#define HB_QUERY "GET /appcast.xml HTTP/1.0\r\nHost: " HB_URL "\r\n\r\n" +static void UpdateFunc( void * ); +static int find_file( ); typedef struct { @@ -16,8 +16,6 @@ typedef struct } hb_update_t; -static void UpdateFunc( void * ); - hb_thread_t * hb_update_init( int * build, char * version ) { hb_update_t * data = calloc( sizeof( hb_update_t ), 1 ); @@ -28,32 +26,52 @@ hb_thread_t * hb_update_init( int * build, char * version ) HB_NORMAL_PRIORITY ); } +/* + * Find out which appcast we want to use, and return appcast.xml or NULL + */ +static int find_file ( void ) +{ + return ( strstr( APPCAST_URL, "appcast.xml" ) != NULL ); +} + static void UpdateFunc( void * _data ) { - hb_update_t * data = (hb_update_t *) _data; + hb_update_t * data = (hb_update_t *) _data; + + /* New code to handle the hb_query stuff */ + int file = find_file(); + char* hb_query; + if (file != NULL) + { + hb_query = "GET /appcast.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n"; + }else { + hb_query = "GET /appcast_unstable.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n"; + } + + // ####################### Grab the data from the web server ########################## hb_net_t * net; int ret; - char buf[1024]; - char * cur, * end, * p; + char buf[4096]; + char * cur, * end; int size; - int stable, unstable; - char stable_str[16], unstable_str[16]; + int stable; + char stable_str[16]; int i; - if( !( net = hb_net_open( HB_URL, 80 ) ) ) + if( !( net = hb_net_open( "handbrake.fr", 80 ) ) ) { goto error; } - if( hb_net_send( net, HB_QUERY ) < 0 ) + if( hb_net_send( net, hb_query ) < 0 ) { hb_net_close( &net ); goto error; } size = 0; - memset( buf, 0, 1024 ); + memset( buf, 0, 4096 ); for( ;; ) { ret = hb_net_recv( net, &buf[size], sizeof( buf ) - size ); @@ -67,7 +85,9 @@ static void UpdateFunc( void * _data ) cur = buf; end = &buf[sizeof( buf )]; + + /* Make sure we got it */ cur += 9; if( size < 15 || strncmp( cur, "200 OK", 6 ) ) @@ -93,24 +113,24 @@ static void UpdateFunc( void * _data ) goto error; } - - // FIND THE STABLE VERSION INFORMATION ################################################### + // ####################### Version Checking Here ########################## /* - * Find the tag + * Find the tag * Scan though each character of the buffer until we find that the first 4 characters of "cur" are "' ) { cur += 1; break; + } - // If the CLI tag has not been found in the first 510 characters, or the end is reached, something bad happened. - if (( i > 510) || ( cur >= end )) + // If the CLI tag has not been found in the first 768 characters, or the end is reached, something bad happened. + if (( i > 768) || ( cur >= end )) { goto error; } @@ -122,10 +142,10 @@ static void UpdateFunc( void * _data ) } /* - * Ok, The above code didn't position cur, it only found = end ) { @@ -133,7 +153,7 @@ static void UpdateFunc( void * _data ) } stable = strtol( cur, &cur, 10 ); - + if( cur >= end ) { goto error; @@ -169,101 +189,15 @@ static void UpdateFunc( void * _data ) hb_log( "latest stable: %s, build %d", stable_str, stable ); // END OF STABLE INFO ################################################### - - - // FIND THE UNSTABLE INFO ############################################### - /* - * Find the tag - * Scan though each character of the buffer until we find that the first 4 characters of "cur" are " 25) || ( cur >= end )) - { - goto error; - } - } - - /* - * Now we need to handle the unstable build information - * Unstable build number is 29 Characters after the last position used. - */ - - cur += 13; - - if( cur >= end ) - { - goto error; - } - - unstable = strtol( cur, &p, 10 ); - - if( cur >= end ) - { - goto error; - } - - /* - * Now we need to get the unstable version number. - * First move the cur pointer 12 places. - * Then iterate over cur until " is found. Thats the end of the version number. - */ - cur += 12; - - if( cur >= end ) - { - goto error; - } - - memset( unstable_str, 0, sizeof( unstable_str ) ); - for( i = 0; i < sizeof( unstable_str ) - 1 && cur < end && *cur != '"'; i++, cur++ ) - { - unstable_str[i] = *cur; - - // If the version number is greater than 7 chars or the end is reached, something went wrong. - if (( i > 7) || ( cur >= end )) - { - goto error; - } - } - hb_log( "latest unstable: %s, build %d", unstable_str, unstable ); - - // END OF UNSTABLE INFO ################################################### - /* - * Handle the update checking as normal. - * This code is unchanged. - */ - if( HB_BUILD % 100 ) + if( stable > HB_BUILD ) { - /* We are runnning an unstable build */ - if( unstable > HB_BUILD ) - { - memcpy( data->version, unstable_str, sizeof( unstable_str ) ); - *(data->build) = unstable; - } - } - else - { - /* We are runnning an stable build */ - if( stable > HB_BUILD ) - { - memcpy( data->version, stable_str, sizeof( stable_str ) ); - *(data->build) = stable; - } + memcpy( data->version, stable_str, sizeof( stable_str ) ); + *(data->build) = stable; } error: free( data ); return; } -