summaryrefslogtreecommitdiffstats
path: root/libhb/update.c
diff options
context:
space:
mode:
authorkonablend <[email protected]>2009-06-20 04:04:54 +0000
committerkonablend <[email protected]>2009-06-20 04:04:54 +0000
commite4f0be4b780b7d0986739fda3c84be7ef99c4ffa (patch)
tree5a00857165a108085b8a6d6e0a7dc678e9345ff8 /libhb/update.c
parentf1c2309090f2b764fc3cc9cf8bbce59721ba2dbd (diff)
Use new appcast URL nameing scheme for HandBrakeCLI --update.
- increase storage space hb_handle_s.version[16] to 32 to handle longer version strings; eg. "svn2500 x86_64" - reduce 2-query mechanism to 1-query and only check/notify for newer releases of same type (ie: stable or unstable) - remove hard-coded url and extract host/path components from HB_PROJECT_URL_APPCAST macro git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2586 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/update.c')
-rw-r--r--libhb/update.c223
1 files changed, 47 insertions, 176 deletions
diff --git a/libhb/update.c b/libhb/update.c
index 6b0d7af92..89909d34b 100644
--- a/libhb/update.c
+++ b/libhb/update.c
@@ -30,170 +30,56 @@ static void UpdateFunc( void * _data )
{
hb_update_t * data = (hb_update_t *) _data;
-
- char * hb_query, * hb_query_two;
+
+ char* p;
+ char* const url = HB_PROJECT_URL_APPCAST;
+ char* const urlz = url + strlen( HB_PROJECT_URL_APPCAST ); /* marks null-term */
+ char url_host[64];
+ char url_path[128];
+ char query[256];
+
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_vers;
+ char s_vers[32]; /* must be no larger than hb_handle_s.version */
int i;
-
+
/* Setup hb_query and hb_query_two with the correct appcast file */
- if( HB_PROJECT_BUILD % 100 )
- {
- hb_log("Using http://handbrake.fr/appcast_unstable.xml (primary)");
- hb_log("Using http://handbrake.fr/appcast.xml (secondary)");
- }
- else
- {
- 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";
+ hb_log( "Using %s", url );
- /* Grab the data from the web server */
- if( !( net = hb_net_open( "handbrake.fr", 80 ) ) )
- {
+ /* extract host part */
+ cur = strstr( HB_PROJECT_URL_APPCAST, "//" );
+ if( !cur || cur+2 > urlz )
goto error;
- }
+ cur += 2;
- if( hb_net_send( net, hb_query ) < 0 )
- {
- hb_log("Error: Unable to connect to server");
- hb_net_close( &net );
+ end = strstr( cur, "/" );
+ if( !end || end > urlz )
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;
- }
+ memset( url_host, 0, sizeof(url_host) );
+ strncpy( url_host, cur, (end-cur) );
- cur = buf;
- end = &buf[sizeof( buf )];
-
- /* Make sure we got it */
- cur += 9;
- if( size < 15 || strncmp( cur, "200 OK", 6 ) )
- {
- hb_log("Error: We did not get a 200 OK from the server. \n");
+ /* extract path part */
+ memset( url_path, 0, sizeof(url_path) );
+ strncpy( url_path, end, (urlz-end) );
+
+ if( !strlen( url_path ))
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;
- }
- }
+ memset( query, 0, sizeof(query) );
+ snprintf( query, sizeof(query), "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", url_path, url_host );
- 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;
- }
-
- /* Stable HB_PROJECT_BUILD */
- stable = 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( 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 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 ) ) )
+ if( !( net = hb_net_open( url_host, 80 ) ) )
{
goto error;
}
-
- if( hb_net_send( net, hb_query_two ) < 0 )
+
+ if( hb_net_send( net, query ) < 0 )
{
hb_log("Error: Unable to connect to server");
hb_net_close( &net );
@@ -220,7 +106,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;
}
@@ -255,7 +140,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");
@@ -280,12 +165,12 @@ static void UpdateFunc( void * _data )
goto error;
}
- /* UnStable HB_PROJECT_BUILD */
- unstable = strtol( cur, &cur, 10 );
-
+ /* Stable HB_PROJECT_BUILD */
+ i_vers = strtol( cur, &cur, 10 );
+
if( cur >= end )
{
- hb_log("Error: Unexpected end of buffer! \n");
+ hb_log("Error: Unexpected end of buffer! \n");
goto error;
}
@@ -300,46 +185,32 @@ static void UpdateFunc( void * _data )
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++ )
+ memset( s_vers, 0, sizeof( s_vers ) );
+ for( i = 0; i < sizeof( s_vers ) - 1 && cur < end && *cur != '"'; i++, cur++ )
{
- unstable_str[i] = *cur;
+ s_vers[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 ))
+ /* If the CLI tag has not been found in the first 768 characters, or the end is reached, something bad happened.*/
+ if (( cur >= end ))
{
hb_log("Error: Version number too long, or end of buffer reached. \n");
goto error;
}
}
-
+
if( cur >= end )
{
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 );
-
+ hb_log( "latest: %s, build %d", s_vers, i_vers );
+
/* Return the build information */
- if( HB_PROJECT_BUILD % 100 )
- {
- /* We are runnning an unstable build */
- if( unstable > HB_PROJECT_BUILD )
- {
- memcpy( data->version, unstable_str, sizeof( unstable_str ) );
- *(data->build) = unstable;
- }
- }
- else
+ if( i_vers > HB_PROJECT_BUILD )
{
- /* We are runnning an stable build */
- if( stable > HB_PROJECT_BUILD )
- {
- memcpy( data->version, stable_str, sizeof( stable_str ) );
- *(data->build) = stable;
- }
+ memcpy( data->version, s_vers, sizeof(s_vers) );
+ *(data->build) = i_vers;
}
error: