Patches mpeg4ip to write the compressor name correctly for h.264 (so it reads "AVC...
[HandBrake.git] / libhb / update.c
blob767807038bdfc0788cb0aa4b8dccc451cf771418
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.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
7 #include "hb.h"
9 #define HB_URL "handbrake.m0k.org"
10 #define HB_QUERY "GET /LATEST HTTP/1.0\r\nHost: " HB_URL "\r\n\r\n"
12 typedef struct
14 int * build;
15 char * version;
17 } hb_update_t;
19 static void UpdateFunc( void * );
21 hb_thread_t * hb_update_init( int * build, char * version )
23 hb_update_t * data = calloc( sizeof( hb_update_t ), 1 );
24 data->build = build;
25 data->version = version;
27 return hb_thread_init( "update", UpdateFunc, data,
28 HB_NORMAL_PRIORITY );
31 static void UpdateFunc( void * _data )
33 hb_update_t * data = (hb_update_t *) _data;
35 hb_net_t * net;
36 int ret;
37 char buf[1024];
38 char * cur, * end, * p;
39 int size;
40 int stable, unstable;
41 char stable_str[16], unstable_str[16];
42 int i;
44 if( !( net = hb_net_open( HB_URL, 80 ) ) )
46 goto error;
49 if( hb_net_send( net, HB_QUERY ) < 0 )
51 hb_net_close( &net );
52 goto error;
55 size = 0;
56 memset( buf, 0, 1024 );
57 for( ;; )
59 ret = hb_net_recv( net, &buf[size], sizeof( buf ) - size );
60 if( ret < 1 )
62 hb_net_close( &net );
63 break;
65 size += ret;
68 cur = buf;
69 end = &buf[sizeof( buf )];
71 /* Make sure we got it */
72 cur += 9;
73 if( size < 15 || strncmp( cur, "200 OK", 6 ) )
75 /* Something went wrong */
76 goto error;
78 cur += 6;
80 /* Find the end of the headers and the beginning of the content */
81 for( ; &cur[3] < end; cur++ )
83 if( cur[0] == '\r' && cur[1] == '\n' &&
84 cur[2] == '\r' && cur[3] == '\n' )
86 cur += 4;
87 break;
91 if( cur >= end )
93 goto error;
96 stable = strtol( cur, &p, 10 );
97 if( cur == p )
99 goto error;
101 cur = p + 1;
102 memset( stable_str, 0, sizeof( stable_str ) );
103 for( i = 0;
104 i < sizeof( stable_str ) - 1 && cur < end && *cur != '\n';
105 i++, cur++ )
107 stable_str[i] = *cur;
110 hb_log( "latest stable: %s, build %d", stable_str, stable );
112 cur++;
113 if( cur >= end )
115 goto error;
118 unstable = strtol( cur, &p, 10 );
119 if( cur == p )
121 goto error;
123 cur = p + 1;
124 memset( unstable_str, 0, sizeof( unstable_str ) );
125 for( i = 0;
126 i < sizeof( unstable_str ) - 1 && cur < end && *cur != '\n';
127 i++, cur++ )
129 unstable_str[i] = *cur;
132 hb_log( "latest unstable: %s, build %d", unstable_str, unstable );
134 if( HB_BUILD % 100 )
136 /* We are runnning an unstable build */
137 if( unstable > HB_BUILD )
139 memcpy( data->version, unstable_str, sizeof( unstable_str ) );
140 *(data->build) = unstable;
143 else
145 /* We are runnning an stable build */
146 if( stable > HB_BUILD )
148 memcpy( data->version, stable_str, sizeof( stable_str ) );
149 *(data->build) = stable;
153 error:
154 free( data );
155 return;