summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorsr55 <[email protected]>2008-04-20 15:20:29 +0000
committersr55 <[email protected]>2008-04-20 15:20:29 +0000
commit900b738c3154126a25b6d1da21b073c876105805 (patch)
tree83ade33b424c6e74ce9207f5ac66159d07fd27fa /libhb
parent500e609ee627eeda225713b641338bc1567b6b70 (diff)
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. <cli-stable>2008021900 "0.9.2"</cli-stable> <cli-unstable>2008041901 "0.9.3"</cli-unstable> git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1431 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/update.c156
1 files 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 <cli-stable> tag
+ * Scan though each character of the buffer until we find that the first 4 characters of "cur" are "<cli"
+ */
- stable = strtol( cur, &p, 10 );
- if( cur == p )
+ for(i=0 ; &cur[3] < end; i++, cur++ )
+ {
+ if( cur[0] == '<' && cur[1] == 'c' && cur[2] == 'l' && cur[3] == 'i' )
+ {
+ 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 ))
+ {
+ 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 <cli so we need to shift cur along 11 places.
+ * After which, the next 10 characters are the build number
+ */
+ cur += 11;
+
+ if( cur >= 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 <cli-unstable> tag
+ * Scan though each character of the buffer until we find that the first 4 characters of "cur" are "<cli"
+ */
- unstable = strtol( cur, &p, 10 );
- if( cur == p )
+ for(i =0 ; &cur[3] < end; i++, cur++ )
+ {
+ if( cur[0] == '<' && cur[1] == 'c' && cur[2] == 'l' && cur[3] == 'i' )
+ {
+ cur += 1;
+ break;
+ }
+
+ // If the second CLI tag is more than 25 characters forward, or the end is reached, something went wrong.
+ if (( i > 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 */