1 /* $Id: update.c,v 1.7 2005/03/26 23:04:14 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
9 static void UpdateFunc( void * );
10 static int find_file( );
19 hb_thread_t * hb_update_init( int * build, char * version )
21 hb_update_t * data = calloc( sizeof( hb_update_t ), 1 );
23 data->version = version;
25 return hb_thread_init( "update", UpdateFunc, data,
30 * Find out which appcast we want to use, and return appcast.xml or NULL
32 static int find_file ( void )
34 return ( strstr( APPCAST_URL, "appcast.xml" ) != NULL );
37 static void UpdateFunc( void * _data )
40 hb_update_t * data = (hb_update_t *) _data;
42 /* New code to handle the hb_query stuff */
43 int file = find_file();
47 hb_query = "GET /appcast.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
49 hb_query = "GET /appcast_unstable.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
52 // ####################### Grab the data from the web server ##########################
62 if( !( net = hb_net_open( "handbrake.fr", 80 ) ) )
67 if( hb_net_send( net, hb_query ) < 0 )
74 memset( buf, 0, 4096 );
77 ret = hb_net_recv( net, &buf[size], sizeof( buf ) - size );
87 end = &buf[sizeof( buf )];
91 /* Make sure we got it */
93 if( size < 15 || strncmp( cur, "200 OK", 6 ) )
95 /* Something went wrong */
100 /* Find the end of the headers and the beginning of the content */
101 for( ; &cur[3] < end; cur++ )
103 if( cur[0] == '\r' && cur[1] == '\n' &&
104 cur[2] == '\r' && cur[3] == '\n' )
116 // ####################### Version Checking Here ##########################
120 * Scan though each character of the buffer until we find that the first 4 characters of "cur" are "<cli"
122 for(i=0 ; &cur[3] < end; i++, cur++ )
125 if( cur[0] == 'c' && cur[1] == 'l' && cur[2] == 'i' && cur[3] == '>' )
132 // If the CLI tag has not been found in the first 768 characters, or the end is reached, something bad happened.
133 if (( i > 768) || ( cur >= end ))
145 * Ok, The above code didn't position cur, it only found <cli so we need to shift cur along 3 places.
146 * After which, the next 10 characters are the build number
155 stable = strtol( cur, &cur, 10 );
163 * The Version number is 2 places after the build, so shift cur, 2 places.
164 * Get all the characters in cur until the point where " is found.
172 memset( stable_str, 0, sizeof( stable_str ) );
173 for( i = 0; i < sizeof( stable_str ) - 1 && cur < end && *cur != '"'; i++, cur++ )
175 stable_str[i] = *cur;
177 // If the version number is longer than 7 characters, or the end is reached, something has gone wrong.
178 if (( i > 7) || ( cur >= end ))
189 hb_log( "latest stable: %s, build %d", stable_str, stable );
191 // END OF STABLE INFO ###################################################
194 if( stable > HB_BUILD )
196 memcpy( data->version, stable_str, sizeof( stable_str ) );
197 *(data->build) = stable;