summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorsr55 <[email protected]>2008-07-20 17:24:30 +0000
committersr55 <[email protected]>2008-07-20 17:24:30 +0000
commit962ce8c41433b854b5895ca4a02ec9f0fd713170 (patch)
treebd05e8a90a61f8d3dcb1cb0f5f160b9681596b31 /libhb
parenta90edee5a1097a797da9c226064d00c3d15fd2c0 (diff)
libhb:
- Updates update.c to use both appcast files. Uses nicer XML now. - This shouldn't break anything this time around. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1572 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/update.c229
1 files changed, 80 insertions, 149 deletions
diff --git a/libhb/update.c b/libhb/update.c
index 7c9f5b3b1..d19a05417 100644
--- a/libhb/update.c
+++ b/libhb/update.c
@@ -6,8 +6,7 @@
#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 * );
typedef struct
{
@@ -16,8 +15,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 +25,49 @@ hb_thread_t * hb_update_init( int * build, char * version )
HB_NORMAL_PRIORITY );
}
+
static void UpdateFunc( void * _data )
{
+
hb_update_t * data = (hb_update_t *) _data;
+
+ /* New code to handle the hb_query stuff */
+ char* hb_query;
+ if( HB_BUILD % 100 )
+ {
+ hb_query = "GET /appcast_unstable.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
+ hb_log("Using http://handbrake.fr/appcast_unstable.xml");
+ }
+ else
+ {
+ hb_query = "GET /appcast.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
+ hb_log("Using http://handbrake.fr/appcast.xml");
+ }
+ // 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_log("Error: Unable to connect to server");
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,12 +81,13 @@ 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 ) )
{
/* Something went wrong */
+ hb_log("Error: We did not get a 200 OK from the server. \n");
goto error;
}
cur += 6;
@@ -90,180 +105,96 @@ static void UpdateFunc( void * _data )
if( cur >= end )
{
+ hb_log("Error: Found the end of the buffer before the end of the HTTP header information! \n");
goto error;
}
+ // Version Checking Here
- // 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"
- */
-
- for(i=0 ; &cur[3] < end; i++, cur++ )
- {
- if( cur[0] == '<' && cur[1] == 'c' && cur[2] == 'l' && cur[3] == 'i' )
- {
+ /*
+ * Find the <cli> tag
+ * Scan though each character of the buffer until we find that the first 4 characters of "cur" are "<cli"
+ */
+ for(i=0 ; &cur[3] < end; i++, cur++ )
+ {
+ if( cur[0] == 'c' && cur[1] == 'l' && cur[2] == 'i' && cur[3] == '>' )
+ {
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;
+ // 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 ))
+ {
+ hb_log("Error: Did not find the <cli> tag in the expected maximum amount of characters into the file. \n");
+ goto error;
+ }
}
-
- /*
- * 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 )
+
+ if( cur >= end )
{
goto error;
}
- stable = strtol( cur, &cur, 10 );
+ /*
+ * Ok, The above code didn't position cur, it only found <cli so we need to shift cur along 3 places.
+ * After which, the next 10 characters are the build number
+ */
+ cur += 3;
- if( cur >= end )
+ if( cur >= end )
{
+ hb_log("Error: Unexpected end of buffer! Could not find the build information. \n");
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;
+ stable = strtol( cur, &cur, 10 );
- // 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 )
+ if( cur >= end )
{
+ hb_log("Error: Unexpected end of buffer! \n");
goto error;
}
- hb_log( "latest stable: %s, build %d", stable_str, stable );
-
- // END OF STABLE INFO ###################################################
+ /*
+ * 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;
-
- // 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"
- */
-
- 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 )
+ if( cur >= end )
{
+ hb_log("Error: Unexpected end of buffer! Could not get version number. \n");
goto error;
- }
-
- unstable = strtol( cur, &p, 10 );
-
- if( cur >= end )
+ }
+ memset( stable_str, 0, sizeof( stable_str ) );
+ for( i = 0; i < sizeof( stable_str ) - 1 && cur < end && *cur != '"'; i++, cur++ )
{
- goto error;
+ 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 ))
+ {
+ hb_log("Error: Version number too long, or end of buffer reached. \n");
+ 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 )
+ 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 );
+ hb_log( "latest stable: %s, build %d", stable_str, stable );
- // END OF UNSTABLE INFO ###################################################
-
- /*
- * Handle the update checking as normal.
- * This code is unchanged.
- */
- if( HB_BUILD % 100 )
- {
- /* We are runnning an unstable build */
- if( unstable > HB_BUILD )
- {
- memcpy( data->version, unstable_str, sizeof( unstable_str ) );
- *(data->build) = unstable;
- }
- }
- else
+ // Return the build information
+ if( stable > HB_BUILD )
{
- /* 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;
}
-