From 900b738c3154126a25b6d1da21b073c876105805 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 20 Apr 2008 15:20:29 +0000 Subject: libhb: - Update.c updated to use appcast.xml rather than LATEST - Expects to find 2 XML tags which have been added to appcast.xml e.g. 2008021900 "0.9.2" 2008041901 "0.9.3" git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1431 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/update.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 134 insertions(+), 22 deletions(-) diff --git a/libhb/update.c b/libhb/update.c index 0aca2b5c6..7c9f5b3b1 100644 --- a/libhb/update.c +++ b/libhb/update.c @@ -7,7 +7,7 @@ #include "hb.h" #define HB_URL "handbrake.fr" -#define HB_QUERY "GET /LATEST HTTP/1.0\r\nHost: " HB_URL "\r\n\r\n" +#define HB_QUERY "GET /appcast.xml HTTP/1.0\r\nHost: " HB_URL "\r\n\r\n" typedef struct { @@ -92,45 +92,157 @@ static void UpdateFunc( void * _data ) { goto error; } + + + // FIND THE STABLE VERSION INFORMATION ################################################### + + /* + * Find the tag + * Scan though each character of the buffer until we find that the first 4 characters of "cur" are " 510) || ( cur >= end )) + { + goto error; + } + } + + if( cur >= end ) { goto error; } - cur = p + 1; - memset( stable_str, 0, sizeof( stable_str ) ); - for( i = 0; - i < sizeof( stable_str ) - 1 && cur < end && *cur != '\n'; - i++, cur++ ) + + /* + * Ok, The above code didn't position cur, it only found = end ) { - stable_str[i] = *cur; + goto error; } - - hb_log( "latest stable: %s, build %d", stable_str, stable ); - - cur++; - if( cur >= end ) + + stable = strtol( cur, &cur, 10 ); + + if( cur >= end ) + { + goto error; + } + + /* + * The Version number is 2 places after the build, so shift cur, 2 places. + * Get all the characters in cur until the point where " is found. + */ + cur += 2; + + if( cur >= end ) { goto error; } + memset( stable_str, 0, sizeof( stable_str ) ); + for( i = 0; i < sizeof( stable_str ) - 1 && cur < end && *cur != '"'; i++, cur++ ) + { + stable_str[i] = *cur; + + // If the version number is longer than 7 characters, or the end is reached, something has gone wrong. + if (( i > 7) || ( cur >= end )) + { + goto error; + } + } + + if( cur >= end ) + { + goto error; + } + + 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; } - cur = p + 1; - memset( unstable_str, 0, sizeof( unstable_str ) ); - for( i = 0; - i < sizeof( unstable_str ) - 1 && cur < end && *cur != '\n'; - i++, cur++ ) + + /* + * 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 ) { - unstable_str[i] = *cur; + 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 ) { /* We are runnning an unstable build */ -- cgit v1.2.3