summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsr55 <[email protected]>2008-07-20 19:33:04 +0000
committersr55 <[email protected]>2008-07-20 19:33:04 +0000
commit2f0bd381d554277f4fe77b915dccd0e6f77a3512 (patch)
tree639e01337239a59642074be56fdf5af48897e4f5
parent962ce8c41433b854b5895ca4a02ec9f0fd713170 (diff)
Libhb:
- parse both appcast files to display both unstable and stable update information git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1573 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--libhb/update.c196
1 files changed, 172 insertions, 24 deletions
diff --git a/libhb/update.c b/libhb/update.c
index d19a05417..599d82ece 100644
--- a/libhb/update.c
+++ b/libhb/update.c
@@ -31,29 +31,32 @@ static void UpdateFunc( void * _data )
hb_update_t * data = (hb_update_t *) _data;
- /* New code to handle the hb_query stuff */
- char* hb_query;
+ char * hb_query, * hb_query_two;
+ hb_net_t * net;
+ int ret;
+ char buf[4096];
+ char * cur, * end;
+ int size;
+ int stable, unstable;
+ char stable_str[16], unstable_str[16];
+ int i;
+
+ /* Setup hb_query and hb_query_two with the correct appcast file */
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");
+ hb_log("Using http://handbrake.fr/appcast_unstable.xml (primary)");
+ hb_log("Using http://handbrake.fr/appcast.xml (secondary)");
}
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");
+ hb_log("Using http://handbrake.fr/appcast.xml (primary)");
+ hb_log("Using http://handbrake.fr/appcast_unstable.xml (secondary)");
}
+
+ hb_query = "GET /appcast.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
+ hb_query_two = "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[4096];
- char * cur, * end;
- int size;
- int stable;
- char stable_str[16];
- int i;
-
+ /* Grab the data from the web server */
if( !( net = hb_net_open( "handbrake.fr", 80 ) ) )
{
goto error;
@@ -86,7 +89,6 @@ static void UpdateFunc( void * _data )
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;
}
@@ -109,8 +111,6 @@ static void UpdateFunc( void * _data )
goto error;
}
- // Version Checking Here
-
/*
* Find the <cli> tag
* Scan though each character of the buffer until we find that the first 4 characters of "cur" are "<cli"
@@ -123,7 +123,7 @@ static void UpdateFunc( void * _data )
break;
}
- // If the CLI tag has not been found in the first 768 characters, or the end is reached, something bad happened.
+ /* 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");
@@ -148,6 +148,7 @@ static void UpdateFunc( void * _data )
goto error;
}
+ /* Stable HB_BUILD */
stable = strtol( cur, &cur, 10 );
if( cur >= end )
@@ -172,6 +173,138 @@ static void UpdateFunc( void * _data )
{
stable_str[i] = *cur;
+ /* If the CLI tag has not been found in the first 768 characters, or the end is reached, something bad happened.*/
+ if (( i > 7) || ( cur >= end ))
+ {
+ hb_log("Error: Version number too long, or end of buffer reached. \n");
+ goto error;
+ }
+ }
+
+ if( cur >= end )
+ {
+ goto error;
+ }
+
+ /* HANDLE THE SECOND APPCAST FILE NOW */
+ /* Grab the data from the web server */
+ if( !( net = hb_net_open( "handbrake.fr", 80 ) ) )
+ {
+ goto error;
+ }
+
+ if( hb_net_send( net, hb_query_two ) < 0 )
+ {
+ hb_log("Error: Unable to connect to server");
+ hb_net_close( &net );
+ goto error;
+ }
+
+ size = 0;
+ memset( buf, 0, 4096 );
+ for( ;; )
+ {
+ ret = hb_net_recv( net, &buf[size], sizeof( buf ) - size );
+ if( ret < 1 )
+ {
+ hb_net_close( &net );
+ break;
+ }
+ size += ret;
+ }
+
+ 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;
+
+ /* Find the end of the headers and the beginning of the content */
+ for( ; &cur[3] < end; cur++ )
+ {
+ if( cur[0] == '\r' && cur[1] == '\n' &&
+ cur[2] == '\r' && cur[3] == '\n' )
+ {
+ cur += 4;
+ break;
+ }
+ }
+
+ if( cur >= end )
+ {
+ hb_log("Error: Found the end of the buffer before the end of the HTTP header information! \n");
+ goto error;
+ }
+
+ /*
+ * 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 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;
+ }
+ }
+
+ if( cur >= end )
+ {
+ goto error;
+ }
+
+ /*
+ * 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 )
+ {
+ hb_log("Error: Unexpected end of buffer! Could not find the build information. \n");
+ goto error;
+ }
+
+ /* UnStable HB_BUILD */
+ unstable = strtol( cur, &cur, 10 );
+
+ if( cur >= end )
+ {
+ hb_log("Error: Unexpected end of buffer! \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 )
+ {
+ hb_log("Error: Unexpected end of buffer! Could not get version number. \n");
+ 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 longer than 7 characters, or the end is reached, something has gone wrong.
if (( i > 7) || ( cur >= end ))
{
@@ -185,13 +318,28 @@ static void UpdateFunc( void * _data )
goto error;
}
+ /* Print the version information */
hb_log( "latest stable: %s, build %d", stable_str, stable );
+ hb_log( "latest unstable: %s, build %d", unstable_str, unstable );
- // Return the build information
- if( stable > HB_BUILD )
+ /* Return the build information */
+ if( HB_BUILD % 100 )
{
- memcpy( data->version, stable_str, sizeof( stable_str ) );
- *(data->build) = stable;
+ /* 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;
+ }
}
error: